Struct stb_truetype::FontInfo
source · pub struct FontInfo<Data: Deref<Target = [u8]>> { /* private fields */ }
Implementations§
source§impl<Data: Deref<Target = [u8]>> FontInfo<Data>
impl<Data: Deref<Target = [u8]>> FontInfo<Data>
sourcepub fn new(data: Data, fontstart: usize) -> Option<FontInfo<Data>>
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.
pub fn get_num_glyphs(&self) -> u32
sourcepub fn find_glyph_index(&self, unicode_codepoint: u32) -> u32
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.
sourcepub fn get_codepoint_shape(&self, unicode_codepoint: u32) -> Option<Vec<Vertex>>
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.
sourcepub fn get_glyph_box(&self, glyph_index: u32) -> Option<Rect<i16>>
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.
sourcepub fn get_codepoint_box(&self, codepoint: u32) -> Option<Rect<i16>>
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
sourcepub fn is_glyph_empty(&self, glyph_index: u32) -> bool
pub fn is_glyph_empty(&self, glyph_index: u32) -> bool
returns true if nothing is drawn for this glyph
sourcepub fn get_glyph_shape(&self, glyph_index: u32) -> Option<Vec<Vertex>>
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.
sourcepub fn get_glyph_h_metrics(&self, glyph_index: u32) -> HMetrics
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.
sourcepub fn get_glyph_kern_advance(&self, glyph_1: u32, glyph_2: u32) -> i32
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.
sourcepub fn get_codepoint_kern_advance(&self, cp1: u32, cp2: u32) -> i32
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
sourcepub fn get_codepoint_h_metrics(&self, codepoint: u32) -> HMetrics
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
sourcepub fn get_v_metrics(&self) -> VMetrics
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
sourcepub fn get_bounding_box(&self) -> Rect<i16>
pub fn get_bounding_box(&self) -> Rect<i16>
the bounding box around all possible characters
sourcepub fn scale_for_pixel_height(&self, height: f32) -> f32
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.
sourcepub fn units_per_em(&self) -> u16
pub fn units_per_em(&self) -> u16
Returns the units per EM square of this font.
sourcepub fn scale_for_mapping_em_to_pixels(&self, pixels: f32) -> f32
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.
sourcepub fn get_glyph_bitmap_box_subpixel(
&self,
glyph: u32,
scale_x: f32,
scale_y: f32,
shift_x: f32,
shift_y: f32
) -> Option<Rect<i32>>
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.
sourcepub fn get_glyph_bitmap_box(
&self,
glyph: u32,
scale_x: f32,
scale_y: f32
) -> Option<Rect<i32>>
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.
sourcepub fn get_codepoint_bitmap_box_subpixel(
&self,
codepoint: u32,
scale_x: f32,
scale_y: f32,
shift_x: f32,
shift_y: f32
) -> Option<Rect<i32>>
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
sourcepub fn get_codepoint_bitmap_box(
&self,
codepoint: u32,
scale_x: f32,
scale_y: f32
) -> Option<Rect<i32>>
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.)