Struct font_kit::loaders::freetype::Font [−][src]
pub struct Font { /* fields omitted */ }
A cross-platform loader that uses the FreeType library to load and rasterize fonts.
On macOS and Windows, the Cargo feature loader-freetype-default
can be used to opt into this
loader by default.
Methods
impl Font
[src]
impl Font
pub fn from_bytes(
font_data: Arc<Vec<u8>>,
font_index: u32
) -> Result<Font, FontLoadingError>
[src]
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
.
pub fn from_file(
file: &mut File,
font_index: u32
) -> Result<Font, FontLoadingError>
[src]
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
.
pub fn from_path<P>(path: P, font_index: u32) -> Result<Font, FontLoadingError> where
P: AsRef<Path>,
[src]
pub fn from_path<P>(path: P, font_index: u32) -> Result<Font, FontLoadingError> where
P: AsRef<Path>,
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
.
pub unsafe fn from_native_font(freetype_face: NativeFont) -> Font
[src]
pub unsafe fn from_native_font(freetype_face: NativeFont) -> Font
Creates a font from a native API handle.
pub fn from_handle(handle: &Handle) -> Result<Self, FontLoadingError>
[src]
pub fn from_handle(handle: &Handle) -> Result<Self, FontLoadingError>
Loads the font pointed to by a handle.
pub fn analyze_bytes(
font_data: Arc<Vec<u8>>
) -> Result<FileType, FontLoadingError>
[src]
pub 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.
pub fn analyze_file(file: &mut File) -> Result<FileType, FontLoadingError>
[src]
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.
pub fn analyze_path<P>(path: P) -> Result<FileType, FontLoadingError> where
P: AsRef<Path>,
[src]
pub 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.
pub fn native_font(&self) -> NativeFont
[src]
pub fn native_font(&self) -> NativeFont
Returns the wrapped native font handle.
This function increments the reference count of the FreeType face before returning it.
Therefore, it is the caller's responsibility to free it with FT_Done_Face
.
pub fn postscript_name(&self) -> Option<String>
[src]
pub fn postscript_name(&self) -> Option<String>
Returns the PostScript name of the font. This should be globally unique.
pub fn full_name(&self) -> String
[src]
pub fn full_name(&self) -> String
Returns the full name of the font (also known as "display name" on macOS).
pub fn family_name(&self) -> String
[src]
pub fn family_name(&self) -> String
Returns the name of the font family.
pub fn is_monospace(&self) -> bool
[src]
pub fn is_monospace(&self) -> bool
Returns true if and only if the font is monospace (fixed-width).
pub fn properties(&self) -> Properties
[src]
pub fn properties(&self) -> Properties
Returns the values of various font properties, corresponding to those defined in CSS.
pub fn glyph_for_char(&self, character: char) -> Option<u32>
[src]
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".
pub fn glyph_count(&self) -> u32
[src]
pub fn glyph_count(&self) -> u32
Returns the number of glyphs in the font.
Glyph IDs range from 0 inclusive to this value exclusive.
pub fn outline<B>(
&self,
glyph_id: u32,
hinting: HintingOptions,
path_builder: &mut B
) -> Result<(), GlyphLoadingError> where
B: PathBuilder,
[src]
pub fn outline<B>(
&self,
glyph_id: u32,
hinting: HintingOptions,
path_builder: &mut B
) -> Result<(), GlyphLoadingError> where
B: PathBuilder,
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?
pub fn typographic_bounds(
&self,
glyph_id: u32
) -> Result<Rect<f32>, GlyphLoadingError>
[src]
pub fn typographic_bounds(
&self,
glyph_id: u32
) -> Result<Rect<f32>, GlyphLoadingError>
Returns the boundaries of a glyph in font units.
pub fn advance(&self, glyph_id: u32) -> Result<Vector2D<f32>, GlyphLoadingError>
[src]
pub fn advance(&self, glyph_id: u32) -> Result<Vector2D<f32>, GlyphLoadingError>
Returns the distance from the origin of the glyph with the given ID to the next, in font units.
pub fn origin(&self, _: u32) -> Result<Point2D<f32>, GlyphLoadingError>
[src]
pub fn origin(&self, _: u32) -> Result<Point2D<f32>, GlyphLoadingError>
Returns the amount that the given glyph should be displaced from the origin.
FIXME(pcwalton): This always returns zero on FreeType.
pub fn metrics(&self) -> Metrics
[src]
pub fn metrics(&self) -> Metrics
Retrieves various metrics that apply to the entire font.
pub fn supports_hinting_options(
&self,
hinting_options: HintingOptions,
for_rasterization: bool
) -> bool
[src]
pub 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.
Some APIs support only rasterizing glyphs with hinting, not retriving 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.
pub fn raster_bounds(
&self,
glyph_id: u32,
point_size: f32,
origin: &Point2D<f32>,
hinting_options: HintingOptions,
rasterization_options: RasterizationOptions
) -> Result<Rect<i32>, GlyphLoadingError>
[src]
pub fn raster_bounds(
&self,
glyph_id: u32,
point_size: f32,
origin: &Point2D<f32>,
hinting_options: HintingOptions,
rasterization_options: RasterizationOptions
) -> Result<Rect<i32>, GlyphLoadingError>
Returns the pixel boundaries that the glyph will take up when rendered using this loader's rasterizer at the given size and origin.
pub fn rasterize_glyph(
&self,
canvas: &mut Canvas,
glyph_id: u32,
point_size: f32,
origin: &Point2D<f32>,
hinting_options: HintingOptions,
rasterization_options: RasterizationOptions
) -> Result<(), GlyphLoadingError>
[src]
pub fn rasterize_glyph(
&self,
canvas: &mut Canvas,
glyph_id: u32,
point_size: f32,
origin: &Point2D<f32>,
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.
pub fn handle(&self) -> Option<Handle>
[src]
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.
pub fn copy_font_data(&self) -> Option<Arc<Vec<u8>>>
[src]
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.
Trait Implementations
impl Clone for Font
[src]
impl Clone for Font
fn clone(&self) -> Font
[src]
fn clone(&self) -> Font
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Drop for Font
[src]
impl Drop for Font
impl Debug for Font
[src]
impl Debug for Font
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl Loader for Font
[src]
impl Loader for Font
type NativeFont = NativeFont
The handle that the API natively uses to represent a font.
fn from_bytes(
font_data: Arc<Vec<u8>>,
font_index: u32
) -> Result<Self, FontLoadingError>
[src]
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
fn from_file(file: &mut File, font_index: u32) -> Result<Font, FontLoadingError>
[src]
fn from_file(file: &mut File, font_index: u32) -> Result<Font, FontLoadingError>
Loads a font from a .ttf
/.otf
/etc. file. Read more
fn analyze_bytes(font_data: Arc<Vec<u8>>) -> Result<FileType, FontLoadingError>
[src]
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. Read more
fn analyze_file(file: &mut File) -> Result<FileType, FontLoadingError>
[src]
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.
fn native_font(&self) -> Self::NativeFont
[src]
fn native_font(&self) -> Self::NativeFont
Returns the wrapped native font handle.
unsafe fn from_native_font(native_font: Self::NativeFont) -> Self
[src]
unsafe fn from_native_font(native_font: Self::NativeFont) -> Self
Creates a font from a native API handle.
fn postscript_name(&self) -> Option<String>
[src]
fn postscript_name(&self) -> Option<String>
Returns the PostScript name of the font. This should be globally unique.
fn full_name(&self) -> String
[src]
fn full_name(&self) -> String
Returns the full name of the font (also known as "display name" on macOS).
fn family_name(&self) -> String
[src]
fn family_name(&self) -> String
Returns the name of the font family.
fn is_monospace(&self) -> bool
[src]
fn is_monospace(&self) -> bool
Returns true if and only if the font is monospace (fixed-width).
fn properties(&self) -> Properties
[src]
fn properties(&self) -> Properties
Returns the values of various font properties, corresponding to those defined in CSS.
fn glyph_for_char(&self, character: char) -> Option<u32>
[src]
fn glyph_for_char(&self, character: char) -> Option<u32>
Returns the usual glyph ID for a Unicode character. Read more
fn glyph_count(&self) -> u32
[src]
fn glyph_count(&self) -> u32
Returns the number of glyphs in the font. Read more
fn outline<B>(
&self,
glyph_id: u32,
hinting_mode: HintingOptions,
path_builder: &mut B
) -> Result<(), GlyphLoadingError> where
B: PathBuilder,
[src]
fn outline<B>(
&self,
glyph_id: u32,
hinting_mode: HintingOptions,
path_builder: &mut B
) -> Result<(), GlyphLoadingError> where
B: PathBuilder,
Sends the vector path for a glyph to a path builder. Read more
fn typographic_bounds(
&self,
glyph_id: u32
) -> Result<Rect<f32>, GlyphLoadingError>
[src]
fn typographic_bounds(
&self,
glyph_id: u32
) -> Result<Rect<f32>, GlyphLoadingError>
Returns the boundaries of a glyph in font units.
fn advance(&self, glyph_id: u32) -> Result<Vector2D<f32>, GlyphLoadingError>
[src]
fn advance(&self, glyph_id: u32) -> Result<Vector2D<f32>, GlyphLoadingError>
Returns the distance from the origin of the glyph with the given ID to the next, in font units. Read more
fn origin(&self, origin: u32) -> Result<Point2D<f32>, GlyphLoadingError>
[src]
fn origin(&self, origin: u32) -> Result<Point2D<f32>, GlyphLoadingError>
Returns the amount that the given glyph should be displaced from the origin.
fn metrics(&self) -> Metrics
[src]
fn metrics(&self) -> Metrics
Retrieves various metrics that apply to the entire font.
fn copy_font_data(&self) -> Option<Arc<Vec<u8>>>
[src]
fn copy_font_data(&self) -> Option<Arc<Vec<u8>>>
Attempts to return the raw font data (contents of the font file). Read more
fn supports_hinting_options(
&self,
hinting_options: HintingOptions,
for_rasterization: bool
) -> bool
[src]
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
fn rasterize_glyph(
&self,
canvas: &mut Canvas,
glyph_id: u32,
point_size: f32,
origin: &Point2D<f32>,
hinting_options: HintingOptions,
rasterization_options: RasterizationOptions
) -> Result<(), GlyphLoadingError>
[src]
fn rasterize_glyph(
&self,
canvas: &mut Canvas,
glyph_id: u32,
point_size: f32,
origin: &Point2D<f32>,
hinting_options: HintingOptions,
rasterization_options: RasterizationOptions
) -> Result<(), GlyphLoadingError>
Rasterizes a glyph to a canvas with the given size and origin. Read more
fn from_path<P>(path: P, font_index: u32) -> Result<Self, FontLoadingError> where
P: AsRef<Path>,
[src]
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
fn from_handle(handle: &Handle) -> Result<Self, FontLoadingError>
[src]
fn from_handle(handle: &Handle) -> Result<Self, FontLoadingError>
Loads the font pointed to by a handle.
fn analyze_path<P>(path: P) -> Result<FileType, FontLoadingError> where
P: AsRef<Path>,
[src]
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.
fn handle(&self) -> Option<Handle>
[src]
fn handle(&self) -> Option<Handle>
Returns a handle to this font, if possible. Read more
fn raster_bounds(
&self,
glyph_id: u32,
point_size: f32,
origin: &Point2D<f32>,
_: HintingOptions,
_: RasterizationOptions
) -> Result<Rect<i32>, GlyphLoadingError>
[src]
fn raster_bounds(
&self,
glyph_id: u32,
point_size: f32,
origin: &Point2D<f32>,
_: HintingOptions,
_: RasterizationOptions
) -> Result<Rect<i32>, GlyphLoadingError>
Returns the pixel boundaries that the glyph will take up when rendered using this loader's rasterizer at the given size and origin. Read more