Struct fonts::Font

source ·
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

source

pub fn new( template: FontTemplateRef, descriptor: FontDescriptor, data: Option<FontData>, synthesized_small_caps: Option<FontRef>, ) -> Result<Font, &'static str>

source

pub fn identifier(&self) -> FontIdentifier

A unique identifier for the font, allowing comparison.

source

pub fn webrender_font_instance_flags(&self) -> FontInstanceFlags

source

pub fn has_color_bitmap_or_colr_table(&self) -> bool

source

pub fn key(&self, font_context: &FontContext) -> FontInstanceKey

source

pub fn data(&self) -> &FontData

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.

source§

impl Font

source

pub fn shape_text( &self, text: &str, options: &ShapingOptions, ) -> Arc<GlyphStore>

source

fn shape_text_harfbuzz( &self, text: &str, options: &ShapingOptions, glyphs: &mut GlyphStore, )

source

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.

source

fn shape_text_fast( &self, text: &str, options: &ShapingOptions, glyphs: &mut GlyphStore, )

Fast path for ASCII text that only needs simple horizontal LTR kerning.

source

pub fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable>

source

pub fn glyph_index(&self, codepoint: char) -> Option<GlyphId>

source

pub fn has_glyph_for(&self, codepoint: char) -> bool

source

pub fn glyph_h_kerning( &self, first_glyph: GlyphId, second_glyph: GlyphId, ) -> FractionalPixel

source

pub fn glyph_h_advance(&self, glyph_id: GlyphId) -> FractionalPixel

source

pub fn typographic_bounds(&self, glyph_id: GlyphId) -> Rect<f32>

source

pub fn baseline(&self) -> Option<FontBaseline>

Get the FontBaseline for this font.

Trait Implementations§

source§

impl MallocSizeOf for Font

source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.

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> 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> MaybeBoxed<Box<T>> for T

source§

fn maybe_boxed(self) -> Box<T>

Convert
source§

impl<T> MaybeBoxed<T> for T

source§

fn maybe_boxed(self) -> T

Convert
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T