Struct stb_truetype::FontInfo

source ·
pub struct FontInfo<Data: Deref<Target = [u8]>> { /* private fields */ }

Implementations§

source§

impl<Data: Deref<Target = [u8]>> FontInfo<Data>

source

pub fn new(data: Data, fontstart: usize) -> Option<FontInfo<Data>>

Given an offset into the file that defines a font, this function builds the necessary cached info for the rest of the system.

source

pub fn get_num_glyphs(&self) -> u32

source

pub fn find_glyph_index(&self, unicode_codepoint: u32) -> u32

If you’re going to perform multiple operations on the same character and you want a speed-up, call this function with the character you’re going to process, then use glyph-based functions instead of the codepoint-based functions.

source

pub fn get_codepoint_shape(&self, unicode_codepoint: u32) -> Option<Vec<Vertex>>

Returns the series of vertices encoding the shape of the glyph for this codepoint.

The shape is a series of countours. Each one starts with a moveto, then consists of a series of mixed lineto and curveto segments. A lineto draws a line from previous endpoint to its x,y; a curveto draws a quadratic bezier from previous endpoint to its x,y, using cx,cy as the bezier control point.

source

pub fn get_glyph_box(&self, glyph_index: u32) -> Option<Rect<i16>>

Like get_codepoint_box, but takes a glyph index. Use this if you have cached the glyph index for a codepoint.

source

pub fn get_codepoint_box(&self, codepoint: u32) -> Option<Rect<i16>>

Gets the bounding box of the visible part of the glyph, in unscaled coordinates

source

pub fn is_glyph_empty(&self, glyph_index: u32) -> bool

returns true if nothing is drawn for this glyph

source

pub fn get_glyph_shape(&self, glyph_index: u32) -> Option<Vec<Vertex>>

Like get_codepoint_shape, but takes a glyph index instead. Use this if you have cached the glyph index for a codepoint.

source

pub fn get_glyph_h_metrics(&self, glyph_index: u32) -> HMetrics

like get_codepoint_h_metrics, but takes a glyph index instead. Use this if you have cached the glyph index for a codepoint.

source

pub fn get_glyph_kern_advance(&self, glyph_1: u32, glyph_2: u32) -> i32

like get_codepoint_kern_advance, but takes glyph indices instead. Use this if you have cached the glyph indices for the codepoints.

source

pub fn get_codepoint_kern_advance(&self, cp1: u32, cp2: u32) -> i32

an additional amount to add to the ‘advance’ value between cp1 and cp2

source

pub fn get_codepoint_h_metrics(&self, codepoint: u32) -> HMetrics

left_side_bearing is the offset from the current horizontal position to the left edge of the character advance_width is the offset from the current horizontal position to the next horizontal position these are expressed in unscaled coordinates

source

pub fn get_v_metrics(&self) -> VMetrics

ascent is the coordinate above the baseline the font extends; descent is the coordinate below the baseline the font extends (i.e. it is typically negative) line_gap is the spacing between one row’s descent and the next row’s ascent… so you should advance the vertical position by ascent - descent + line_gap these are expressed in unscaled coordinates, so you must multiply by the scale factor for a given size

source

pub fn get_bounding_box(&self) -> Rect<i16>

the bounding box around all possible characters

source

pub fn scale_for_pixel_height(&self, height: f32) -> f32

computes a scale factor to produce a font whose “height” is ‘pixels’ tall. Height is measured as the distance from the highest ascender to the lowest descender; in other words, it’s equivalent to calling GetFontVMetrics and computing: scale = pixels / (ascent - descent) so if you prefer to measure height by the ascent only, use a similar calculation.

source

pub fn units_per_em(&self) -> u16

Returns the units per EM square of this font.

source

pub fn scale_for_mapping_em_to_pixels(&self, pixels: f32) -> f32

computes a scale factor to produce a font whose EM size is mapped to pixels tall. This is probably what traditional APIs compute, but I’m not positive.

source

pub fn get_glyph_bitmap_box_subpixel( &self, glyph: u32, scale_x: f32, scale_y: f32, shift_x: f32, shift_y: f32 ) -> Option<Rect<i32>>

like get_codepoint_bitmap_box_subpixel, but takes a glyph index instead of a codepoint.

source

pub fn get_glyph_bitmap_box( &self, glyph: u32, scale_x: f32, scale_y: f32 ) -> Option<Rect<i32>>

like get_codepoint_bitmap_box, but takes a glyph index instead of a codepoint.

source

pub fn get_codepoint_bitmap_box_subpixel( &self, codepoint: u32, scale_x: f32, scale_y: f32, shift_x: f32, shift_y: f32 ) -> Option<Rect<i32>>

same as get_codepoint_bitmap_box, but you can specify a subpixel shift for the character

source

pub fn get_codepoint_bitmap_box( &self, codepoint: u32, scale_x: f32, scale_y: f32 ) -> Option<Rect<i32>>

get the bounding box of the bitmap centered around the glyph origin; so the bitmap width is x1-x0, height is y1-y0, and location to place the bitmap top left is (left_side_bearing*scale, y0). (Note that the bitmap uses y-increases-down, but the shape uses y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.)

source

pub fn get_font_name_strings(&self) -> FontNameIter<'_, Data>

Trait Implementations§

source§

impl<Data: Clone + Deref<Target = [u8]>> Clone for FontInfo<Data>

source§

fn clone(&self) -> FontInfo<Data>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Data: Debug + Deref<Target = [u8]>> Debug for FontInfo<Data>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Data: Copy + Deref<Target = [u8]>> Copy for FontInfo<Data>

Auto Trait Implementations§

§

impl<Data> RefUnwindSafe for FontInfo<Data>
where Data: RefUnwindSafe,

§

impl<Data> Send for FontInfo<Data>
where Data: Send,

§

impl<Data> Sync for FontInfo<Data>
where Data: Sync,

§

impl<Data> Unpin for FontInfo<Data>
where Data: Unpin,

§

impl<Data> UnwindSafe for FontInfo<Data>
where Data: UnwindSafe,

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.