pub struct Font {
pub handle: PlatformFont,
pub template: FontTemplateRef,
pub metrics: FontMetrics,
pub descriptor: FontDescriptor,
data: OnceLock<FontData>,
shaper: OnceLock<Shaper>,
cached_shape_data: RwLock<CachedShapeData>,
pub font_instance_key: OnceLock<FontInstanceKey>,
pub synthesized_small_caps: Option<FontRef>,
has_color_bitmap_or_colr_table: OnceLock<bool>,
can_do_fast_shaping: OnceLock<bool>,
}
Fields§
§handle: PlatformFont
§template: FontTemplateRef
§metrics: FontMetrics
§descriptor: FontDescriptor
§data: OnceLock<FontData>
The data for this font. This might be uninitialized for system fonts.
shaper: OnceLock<Shaper>
§cached_shape_data: RwLock<CachedShapeData>
§font_instance_key: OnceLock<FontInstanceKey>
§synthesized_small_caps: Option<FontRef>
If this is a synthesized small caps font, then this font reference is for the version of the font used to replace lowercase ASCII letters. It’s up to the consumer of this font to properly use this reference.
has_color_bitmap_or_colr_table: OnceLock<bool>
Whether or not this font supports color bitmaps or a COLR table. This is essentially equivalent to whether or not we use it for emoji presentation. This is cached, because getting table data is expensive.
can_do_fast_shaping: OnceLock<bool>
Whether or not this font can do fast shaping, ie whether or not it has a kern table, but no GSUB and GPOS tables. When this is true, Servo will shape Latin horizontal left-to-right text without using Harfbuzz.
FIXME: This should be removed entirely in favor of better caching if necessary. See https://github.com/servo/servo/pull/11273#issuecomment-222332873.
Implementations§
source§impl Font
impl Font
pub fn new( template: FontTemplateRef, descriptor: FontDescriptor, data: Option<FontData>, synthesized_small_caps: Option<FontRef>, ) -> Result<Font, &'static str>
sourcepub fn identifier(&self) -> FontIdentifier
pub fn identifier(&self) -> FontIdentifier
A unique identifier for the font, allowing comparison.
pub fn webrender_font_instance_flags(&self) -> FontInstanceFlags
pub fn has_color_bitmap_or_colr_table(&self) -> bool
pub fn key(&self, font_context: &FontContext) -> FontInstanceKey
source§impl Font
impl Font
pub fn shape_text( &self, text: &str, options: &ShapingOptions, ) -> Arc<GlyphStore>
fn shape_text_harfbuzz( &self, text: &str, options: &ShapingOptions, glyphs: &mut GlyphStore, )
sourcepub fn can_do_fast_shaping(&self, text: &str, options: &ShapingOptions) -> bool
pub fn can_do_fast_shaping(&self, text: &str, options: &ShapingOptions) -> bool
Whether not a particular text and ShapingOptions
combination can use
“fast shaping” ie shaping without Harfbuzz.
Note: This will eventually be removed.
sourcefn shape_text_fast(
&self,
text: &str,
options: &ShapingOptions,
glyphs: &mut GlyphStore,
)
fn shape_text_fast( &self, text: &str, options: &ShapingOptions, glyphs: &mut GlyphStore, )
Fast path for ASCII text that only needs simple horizontal LTR kerning.
pub fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable>
pub fn glyph_index(&self, codepoint: char) -> Option<GlyphId>
pub fn has_glyph_for(&self, codepoint: char) -> bool
pub fn glyph_h_kerning( &self, first_glyph: GlyphId, second_glyph: GlyphId, ) -> FractionalPixel
pub fn glyph_h_advance(&self, glyph_id: GlyphId) -> FractionalPixel
pub fn typographic_bounds(&self, glyph_id: GlyphId) -> Rect<f32>
sourcepub fn baseline(&self) -> Option<FontBaseline>
pub fn baseline(&self) -> Option<FontBaseline>
Get the FontBaseline
for this font.
Trait Implementations§
source§impl MallocSizeOf for Font
impl MallocSizeOf for Font
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Auto Trait Implementations§
impl !Freeze for Font
impl !RefUnwindSafe for Font
impl Send for Font
impl Sync for Font
impl Unpin for Font
impl !UnwindSafe for Font
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more