Struct fontdue::Font[][src]

pub struct Font { /* fields omitted */ }
Expand description

Represents a font. Fonts are immutable after creation and owns its own copy of the font data.

Implementations

impl Font[src]

pub fn from_bytes<Data: Deref<Target = [u8]>>(
    data: Data,
    settings: FontSettings
) -> FontResult<Font>
[src]

Constructs a font from an array of bytes.

pub fn horizontal_line_metrics(&self, px: f32) -> Option<LineMetrics>[src]

New line metrics for fonts that append characters to lines horizontally, and append new lines vertically (above or below the current line). Only populated for fonts with the appropriate metrics, none if it’s missing.

pub fn vertical_line_metrics(&self, px: f32) -> Option<LineMetrics>[src]

New line metrics for fonts that append characters to lines vertically, and append new lines horizontally (left or right of the current line). Only populated for fonts with the appropriate metrics, none if it’s missing.

pub fn units_per_em(&self) -> f32[src]

Gets the font’s units per em.

pub fn scale_factor(&self, px: f32) -> f32[src]

Calculates the glyph’s outline scale factor for a given px size.

pub fn metrics(&self, character: char, px: f32) -> Metrics[src]

Retrieves the layout metrics for the given character. If the character isn’t present in the font, then the layout for the font’s default character is returned instead.

Arguments

  • index - The character in the font to to generate the layout metrics for.
  • px - The size to generate the layout metrics for the character at. Cannot be negative.

Returns

  • Metrics - Sizing and positioning metadata for the glyph.

pub fn metrics_indexed(&self, index: usize, px: f32) -> Metrics[src]

Retrieves the layout metrics at the given index. You normally want to be using metrics(char, f32) instead, unless your glyphs are pre-indexed.

Arguments

  • index - The glyph index in the font to to generate the layout metrics for.
  • px - The size to generate the layout metrics for the glyph at. Cannot be negative.

Returns

  • Metrics - Sizing and positioning metadata for the glyph.

pub fn rasterize_config(&self, config: GlyphRasterConfig) -> (Metrics, Vec<u8>)[src]

Retrieves the layout rasterized bitmap for the given raster config. If the raster config’s character isn’t present in the font, then the layout and bitmap for the font’s default character’s raster is returned instead.

Arguments

  • config - The settings to render the character at.

Returns

  • Metrics - Sizing and positioning metadata for the rasterized glyph.
  • Vec<u8> - Coverage vector for the glyph. Coverage is a linear scale where 0 represents 0% coverage of that pixel by the glyph and 255 represents 100% coverage. The vec starts at the top left corner of the glyph.

pub fn rasterize(&self, character: char, px: f32) -> (Metrics, Vec<u8>)[src]

Retrieves the layout metrics and rasterized bitmap for the given character. If the character isn’t present in the font, then the layout and bitmap for the font’s default character is returned instead.

Arguments

  • character - The character to rasterize.
  • px - The size to render the character at. Cannot be negative.

Returns

  • Metrics - Sizing and positioning metadata for the rasterized glyph.
  • Vec<u8> - Coverage vector for the glyph. Coverage is a linear scale where 0 represents 0% coverage of that pixel by the glyph and 255 represents 100% coverage. The vec starts at the top left corner of the glyph.

pub fn rasterize_config_subpixel(
    &self,
    config: GlyphRasterConfig
) -> (Metrics, Vec<u8>)
[src]

Retrieves the layout rasterized bitmap for the given raster config. If the raster config’s character isn’t present in the font, then the layout and bitmap for the font’s default character’s raster is returned instead.

This will perform the operation with the width multiplied by 3, as to simulate subpixels. Taking these as RGB values will perform subpixel anti aliasing.

Arguments

  • config - The settings to render the character at.

Returns

  • Metrics - Sizing and positioning metadata for the rasterized glyph.
  • Vec<u8> - Swizzled RGB coverage vector for the glyph. Coverage is a linear scale where 0 represents 0% coverage of that subpixel by the glyph and 255 represents 100% coverage. The vec starts at the top left corner of the glyph.

pub fn rasterize_subpixel(&self, character: char, px: f32) -> (Metrics, Vec<u8>)[src]

Retrieves the layout metrics and rasterized bitmap for the given character. If the character isn’t present in the font, then the layout and bitmap for the font’s default character is returned instead.

This will perform the operation with the width multiplied by 3, as to simulate subpixels. Taking these as RGB values will perform subpixel anti aliasing.

Arguments

  • character - The character to rasterize.
  • px - The size to render the character at. Cannot be negative.

Returns

  • Metrics - Sizing and positioning metadata for the rasterized glyph.
  • Vec<u8> - Swizzled RGB coverage vector for the glyph. Coverage is a linear scale where 0 represents 0% coverage of that subpixel by the glyph and 255 represents 100% coverage. The vec starts at the top left corner of the glyph.

pub fn rasterize_indexed(&self, index: usize, px: f32) -> (Metrics, Vec<u8>)[src]

Retrieves the layout metrics and rasterized bitmap at the given index. You normally want to be using rasterize(char, f32) instead, unless your glyphs are pre-indexed.

Arguments

  • index - The glyph index in the font to rasterize.
  • px - The size to render the character at. Cannot be negative.

Returns

  • Metrics - Sizing and positioning metadata for the rasterized glyph.
  • Vec<u8> - Coverage vector for the glyph. Coverage is a linear scale where 0 represents 0% coverage of that pixel by the glyph and 255 represents 100% coverage. The vec starts at the top left corner of the glyph.

pub fn rasterize_indexed_subpixel(
    &self,
    index: usize,
    px: f32
) -> (Metrics, Vec<u8>)
[src]

Retrieves the layout metrics and rasterized bitmap at the given index. You normally want to be using rasterize(char, f32) instead, unless your glyphs are pre-indexed.

This will perform the operation with the width multiplied by 3, as to simulate subpixels. Taking these as RGB values will perform subpixel anti aliasing.

Arguments

  • index - The glyph index in the font to rasterize.
  • px - The size to render the character at. Cannot be negative.

Returns

  • Metrics - Sizing and positioning metadata for the rasterized glyph.
  • Vec<u8> - Swizzled RGB coverage vector for the glyph. Coverage is a linear scale where 0 represents 0% coverage of that subpixel by the glyph and 255 represents 100% coverage. The vec starts at the top left corner of the glyph.

pub fn lookup_glyph_index(&self, character: char) -> usize[src]

Finds the internal glyph index for the given character. If the character is not present in the font then 0 is returned.

pub fn glyph_count(&self) -> usize[src]

Gets the total glyphs in the font.

Trait Implementations

impl Clone for Font[src]

fn clone(&self) -> Font[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Font[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl RefUnwindSafe for Font

impl Send for Font

impl Sync for Font

impl Unpin for Font

impl UnwindSafe for Font

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.