Struct font_kit::loaders::core_text::Font

source ·
pub struct Font { /* private fields */ }
Expand description

A loader that uses Apple’s Core Text API to load and rasterize fonts.

Implementations§

source§

impl Font

source

pub fn from_bytes( font_data: Arc<Vec<u8>>, font_index: u32, ) -> Result<Font, FontLoadingError>

Loads a font from raw font data (the contents of a .ttf/.otf/etc. file).

If the data represents a collection (.ttc/.otc/etc.), font_index specifies the index of the font to load from it. If the data represents a single font, pass 0 for font_index.

source

pub fn from_file( file: &mut File, font_index: u32, ) -> Result<Font, FontLoadingError>

Loads a font from a .ttf/.otf/etc. file.

If the file is a collection (.ttc/.otc/etc.), font_index specifies the index of the font to load from it. If the file represents a single font, pass 0 for font_index.

source

pub fn from_path<P: AsRef<Path>>( path: P, font_index: u32, ) -> Result<Font, FontLoadingError>

Loads a font from the path to a .ttf/.otf/etc. file.

If the file is a collection (.ttc/.otc/etc.), font_index specifies the index of the font to load from it. If the file represents a single font, pass 0 for font_index.

source

pub unsafe fn from_native_font(core_text_font: NativeFont) -> Font

Creates a font from a native API handle.

source

pub fn from_core_graphics_font(core_graphics_font: CGFont) -> Font

Creates a font from a Core Graphics font handle.

This function is only available on the Core Text backend.

source

pub fn from_handle(handle: &Handle) -> Result<Self, FontLoadingError>

Loads the font pointed to by a handle.

source

pub fn analyze_bytes( font_data: Arc<Vec<u8>>, ) -> Result<FileType, FontLoadingError>

Determines whether a file represents a supported font, and if so, what type of font it is.

source

pub fn analyze_file(file: &mut File) -> Result<FileType, FontLoadingError>

Determines whether a file represents a supported font, and if so, what type of font it is.

source

pub fn analyze_path<P: AsRef<Path>>( path: P, ) -> Result<FileType, FontLoadingError>

Determines whether a path points to a supported font, and if so, what type of font it is.

source

pub fn native_font(&self) -> NativeFont

Returns the wrapped native font handle.

source

pub fn postscript_name(&self) -> Option<String>

Returns the PostScript name of the font. This should be globally unique.

source

pub fn full_name(&self) -> String

Returns the full name of the font (also known as “display name” on macOS).

source

pub fn family_name(&self) -> String

Returns the name of the font family.

source

pub fn style_name(&self) -> String

Returns the name of the font style, according to Core Text.

NB: This function is only available on the Core Text backend.

source

pub fn is_monospace(&self) -> bool

Returns true if and only if the font is monospace (fixed-width).

source

pub fn properties(&self) -> Properties

Returns the values of various font properties, corresponding to those defined in CSS.

source

pub fn glyph_count(&self) -> u32

Returns the number of glyphs in the font.

Glyph IDs range from 0 inclusive to this value exclusive.

source

pub fn glyph_for_char(&self, character: char) -> Option<u32>

Returns the usual glyph ID for a Unicode character.

Be careful with this function; typographically correct character-to-glyph mapping must be done using a shaper such as HarfBuzz. This function is only useful for best-effort simple use cases like “what does character X look like on its own”.

source

pub fn glyph_by_name(&self, name: &str) -> Option<u32>

Returns the glyph ID for the specified glyph name.

source

pub fn outline<S>( &self, glyph_id: u32, _: HintingOptions, sink: &mut S, ) -> Result<(), GlyphLoadingError>
where S: OutlineSink,

Sends the vector path for a glyph to a path builder.

If hinting_mode is not None, this function performs grid-fitting as requested before sending the hinding outlines to the builder.

TODO(pcwalton): What should we do for bitmap glyphs?

source

pub fn typographic_bounds( &self, glyph_id: u32, ) -> Result<RectF, GlyphLoadingError>

Returns the boundaries of a glyph in font units.

source

pub fn advance(&self, glyph_id: u32) -> Result<Vector2F, GlyphLoadingError>

Returns the distance from the origin of the glyph with the given ID to the next, in font units.

source

pub fn origin(&self, glyph_id: u32) -> Result<Vector2F, GlyphLoadingError>

Returns the amount that the given glyph should be displaced from the origin.

source

pub fn metrics(&self) -> Metrics

Retrieves various metrics that apply to the entire font.

source

pub fn handle(&self) -> Option<Handle>

Returns a handle to this font, if possible.

This is useful if you want to open the font with a different loader.

source

pub fn copy_font_data(&self) -> Option<Arc<Vec<u8>>>

Attempts to return the raw font data (contents of the font file).

If this font is a member of a collection, this function returns the data for the entire collection.

source

pub fn raster_bounds( &self, glyph_id: u32, point_size: f32, transform: Transform2F, hinting_options: HintingOptions, rasterization_options: RasterizationOptions, ) -> Result<RectI, GlyphLoadingError>

Returns the pixel boundaries that the glyph will take up when rendered using this loader’s rasterizer at the given size and transform.

source

pub fn rasterize_glyph( &self, canvas: &mut Canvas, glyph_id: u32, point_size: f32, transform: Transform2F, hinting_options: HintingOptions, rasterization_options: RasterizationOptions, ) -> Result<(), GlyphLoadingError>

Rasterizes a glyph to a canvas with the given size and origin.

Format conversion will be performed if the canvas format does not match the rasterization options. For example, if bilevel (black and white) rendering is requested to an RGBA surface, this function will automatically convert the 1-bit raster image to the 32-bit format of the canvas. Note that this may result in a performance penalty, depending on the loader.

If hinting_options is not None, the requested grid fitting is performed.

TODO(pcwalton): This is woefully incomplete. See WebRender’s code for a more complete implementation.

source

pub fn supports_hinting_options( &self, hinting_options: HintingOptions, _: bool, ) -> bool

Returns true if and only if the font loader can perform hinting in the requested way.

Some APIs support only rasterizing glyphs with hinting, not retrieving hinted outlines. If for_rasterization is false, this function returns true if and only if the loader supports retrieval of hinted outlines. If for_rasterization is true, this function returns true if and only if the loader supports rasterizing hinted glyphs.

source

pub fn load_font_table(&self, table_tag: u32) -> Option<Box<[u8]>>

Returns the raw contents of the OpenType table with the given tag.

Tags are four-character codes. A list of tags can be found in the OpenType specification.

Trait Implementations§

source§

impl Clone for Font

source§

fn clone(&self) -> Font

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 Debug for Font

source§

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

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

impl Loader for Font

§

type NativeFont = CTFont

The handle that the API natively uses to represent a font.
source§

fn from_bytes( font_data: Arc<Vec<u8>>, font_index: u32, ) -> Result<Self, FontLoadingError>

Loads a font from raw font data (the contents of a .ttf/.otf/etc. file). Read more
source§

fn from_file(file: &mut File, font_index: u32) -> Result<Font, FontLoadingError>

Loads a font from a .ttf/.otf/etc. file. Read more
source§

unsafe fn from_native_font(native_font: Self::NativeFont) -> Self

Creates a font from a native API handle.
source§

fn analyze_bytes(font_data: Arc<Vec<u8>>) -> Result<FileType, FontLoadingError>

Determines whether a blob of raw font data represents a supported font, and, if so, what type of font it is.
source§

fn analyze_file(file: &mut File) -> Result<FileType, FontLoadingError>

Determines whether a file represents a supported font, and, if so, what type of font it is.
source§

fn native_font(&self) -> Self::NativeFont

Returns the wrapped native font handle.
source§

fn postscript_name(&self) -> Option<String>

Returns the PostScript name of the font. This should be globally unique.
source§

fn full_name(&self) -> String

Returns the full name of the font (also known as “display name” on macOS).
source§

fn family_name(&self) -> String

Returns the name of the font family.
source§

fn is_monospace(&self) -> bool

Returns true if and only if the font is monospace (fixed-width).
source§

fn properties(&self) -> Properties

Returns the values of various font properties, corresponding to those defined in CSS.
source§

fn glyph_for_char(&self, character: char) -> Option<u32>

Returns the usual glyph ID for a Unicode character. Read more
source§

fn glyph_by_name(&self, name: &str) -> Option<u32>

Returns the glyph ID for the specified glyph name.
source§

fn glyph_count(&self) -> u32

Returns the number of glyphs in the font. Read more
source§

fn outline<S>( &self, glyph_id: u32, hinting_mode: HintingOptions, sink: &mut S, ) -> Result<(), GlyphLoadingError>
where S: OutlineSink,

Sends the vector path for a glyph to a sink. Read more
source§

fn typographic_bounds(&self, glyph_id: u32) -> Result<RectF, GlyphLoadingError>

Returns the boundaries of a glyph in font units. The origin of the coordinate space is at the bottom left.
source§

fn advance(&self, glyph_id: u32) -> Result<Vector2F, GlyphLoadingError>

Returns the distance from the origin of the glyph with the given ID to the next, in font units.
source§

fn origin(&self, glyph_id: u32) -> Result<Vector2F, GlyphLoadingError>

Returns the amount that the given glyph should be displaced from the origin.
source§

fn metrics(&self) -> Metrics

Retrieves various metrics that apply to the entire font.
source§

fn copy_font_data(&self) -> Option<Arc<Vec<u8>>>

Attempts to return the raw font data (contents of the font file). Read more
source§

fn supports_hinting_options( &self, hinting_options: HintingOptions, for_rasterization: bool, ) -> bool

Returns true if and only if the font loader can perform hinting in the requested way. Read more
source§

fn rasterize_glyph( &self, canvas: &mut Canvas, glyph_id: u32, point_size: f32, transform: Transform2F, hinting_options: HintingOptions, rasterization_options: RasterizationOptions, ) -> Result<(), GlyphLoadingError>

Rasterizes a glyph to a canvas with the given size and transform. Read more
source§

fn get_fallbacks(&self, text: &str, locale: &str) -> FallbackResult<Self>

Get font fallback results for the given text and locale. Read more
source§

fn load_font_table(&self, table_tag: u32) -> Option<Box<[u8]>>

Returns the OpenType font table with the given tag, if the table exists.
source§

fn from_path<P>(path: P, font_index: u32) -> Result<Self, FontLoadingError>
where P: AsRef<Path>,

Loads a font from the path to a .ttf/.otf/etc. file. Read more
source§

fn from_handle(handle: &Handle) -> Result<Self, FontLoadingError>

Loads the font pointed to by a handle.
source§

fn analyze_path<P>(path: P) -> Result<FileType, FontLoadingError>
where P: AsRef<Path>,

Determines whether a path points to a supported font, and, if so, what type of font it is.
source§

fn handle(&self) -> Option<Handle>

Returns a handle to this font, if possible. Read more
source§

fn raster_bounds( &self, glyph_id: u32, point_size: f32, transform: Transform2F, _: HintingOptions, _: RasterizationOptions, ) -> Result<RectI, GlyphLoadingError>

Returns the pixel boundaries that the glyph will take up when rendered using this loader’s rasterizer at the given point_size and transform. The origin of the coordinate space is at the top left.

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.