pub struct Font {
pub(crate) handle: PlatformFont,
pub(crate) template: FontTemplateRef,
pub metrics: FontMetrics,
pub descriptor: FontDescriptor,
data_and_index: OnceLock<FontDataAndIndex>,
shaper: OnceLock<Shaper>,
cached_shape_data: RwLock<CachedShapeData>,
pub(crate) font_instance_key: OnceLock<FontInstanceKey>,
pub(crate) 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_and_index: OnceLock<FontDataAndIndex>
The data for this font. And the index of the font within the data (in case it’s a TTC) 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(crate) fn webrender_font_instance_flags(&self) -> FontInstanceFlags
pub(crate) fn has_color_bitmap_or_colr_table(&self) -> bool
pub fn key(&self, font_context: &FontContext) -> FontInstanceKey
Sourcepub fn font_data_and_index(&self) -> Result<&FontDataAndIndex, FontDataError>
pub fn font_data_and_index(&self) -> Result<&FontDataAndIndex, FontDataError>
Return the data for this Font
. Note that this is currently highly inefficient for system
fonts and should not be used except in legacy canvas code.
pub(crate) fn variations(&self) -> &[FontVariation]
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(crate) fn table_for_tag(&self, tag: Tag) -> Option<FontTable>
pub fn glyph_index(&self, codepoint: char) -> Option<u32>
pub(crate) fn has_glyph_for(&self, codepoint: char) -> bool
pub(crate) fn glyph_h_kerning(&self, first_glyph: u32, second_glyph: u32) -> f64
pub fn glyph_h_advance(&self, glyph_id: u32) -> f64
pub fn typographic_bounds(&self, glyph_id: u32) -> 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