Struct rich_sdl2_rust::ttf::font::Font

source ·
pub struct Font<'ttf> { /* private fields */ }
Expand description

A font data structure.

Implementations§

source§

impl<'ttf> Font<'ttf>

source

pub fn new( _ttf: &'ttf Ttf, file_name: &str, point: u32, index: Option<usize> ) -> Result<Self>

Constructs a font data from file name and point size. The font face in the font file can be selected by an optional index, which will be 0 if None.

§Panics

Panics if file_name is empty.

source

pub fn glyph(&self, ch: char) -> Option<Glyph<'_>>

Returns the glyph of the font if exists.

source

pub fn rendered_size(&self, text: &str) -> Result<Size>

Calculates the rendered size of the text, or Err on failure. The height will be same as MetricExt::height.

source

pub fn rendered_width( &self, text: &str, expected_width: u32 ) -> Result<(u32, usize)>

Returns the rendered width in pixels and the numbers of characters until reaching expected_width. Err will be returned on out of memory.

Trait Implementations§

source§

impl AttributeExt for Font<'_>

source§

fn faces(&self) -> usize

Returns the numbers of the faces, the sub-font in the font.
source§

fn is_fixed_width(&self) -> bool

Returns whether the font is fixed width.
source§

fn family_name(&self) -> Option<Cow<'_, str>>

Returns the family name of the font.
source§

fn style_name(&self) -> Option<Cow<'_, str>>

Returns the style name of the font.
source§

impl Drop for Font<'_>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl FontSetting for Font<'_>

source§

fn hinting(&self) -> FontHinting

Returns the current hinting of the font.
source§

fn set_hinting(&self, hinting: FontHinting)

Sets the hinting of the font.
source§

fn disable_kerning(&self) -> KerningDisabler<'_>

Disables the font kerning.
source§

fn is_sdf(&self) -> bool

Returns whether the font supports Singed Distance Field.
source§

fn set_sdf(&self, value: bool) -> Result<()>

Sets whether the font supports Singed Distance Field.
source§

impl MetricExt for Font<'_>

source§

fn height(&self) -> u32

Returns the maximum height of the glyph in the font, in pixels.
source§

fn ascent(&self) -> u32

Returns the maximum ascent, the hight above baseline of the glyph in the font, in pixels.
source§

fn descent(&self) -> u32

Returns the maximum ascent, the hight below baseline of the glyph in the font, in pixels.
source§

fn line_skip(&self) -> u32

Returns the line skip height of the font, the recommended height of a rendered line of text, in pixels. It is usually larger than MetricExt::height().
source§

impl RenderExt for Font<'_>

source§

fn render(&self, text: &str, mode: RenderMode) -> Result<TtfSurface>

Renders the text into the TtfSurface, or Err on failure.
source§

fn render_wrapped( &self, text: &str, wrap_length: u32, mode: RenderMode ) -> Result<TtfSurface>

Renders the wrapped text into the TtfSurface, or Err on failure.
source§

fn render_glyph(&self, ch: char, mode: RenderMode) -> Result<TtfSurface>

Renders the character into the TtfSurface, or Err on failure.
source§

impl StyleExt for Font<'_>

source§

fn font_style(&self) -> FontStyle

Returns the current font style.
source§

fn set_font_style(&self, style: FontStyle)

Sets the font style.
source§

fn outline_width(&self) -> u32

Returns the current outline width in pixels.
source§

fn set_outline_width(&self, pixels: u32)

Sets the outline width in pixels.
source§

fn set_font_size(&self, points: u32) -> Result<()>

Sets the font size in points, or Err on failure.
source§

fn set_font_size_dpi(&self, points: u32, dpi: Dpi) -> Result<()>

Sets the font size in points and dpi, or Err on failure.

Auto Trait Implementations§

§

impl<'ttf> !RefUnwindSafe for Font<'ttf>

§

impl<'ttf> !Send for Font<'ttf>

§

impl<'ttf> !Sync for Font<'ttf>

§

impl<'ttf> Unpin for Font<'ttf>

§

impl<'ttf> !UnwindSafe for Font<'ttf>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.