Struct allsorts_no_std::font::Font[][src]

pub struct Font<T: FontTableProvider> {
    pub font_table_provider: T,
    pub maxp_table: MaxpTable,
    pub hhea_table: HheaTable,
    pub cmap_subtable_encoding: Encoding,
    pub glyph_table_flags: GlyphTableFlags,
    // some fields omitted
}

Fields

font_table_provider: Tmaxp_table: MaxpTablehhea_table: HheaTablecmap_subtable_encoding: Encodingglyph_table_flags: GlyphTableFlags

Implementations

impl<T: FontTableProvider> Font<T>[src]

pub fn new(provider: T) -> Result<Option<Font<T>>, ParseError>[src]

pub fn num_glyphs(&self) -> u16[src]

pub fn lookup_glyph_index(
    &mut self,
    ch: char,
    match_presentation: MatchingPresentation,
    variation_selector: Option<VariationSelector>
) -> (u16, VariationSelector)
[src]

pub fn shape(
    &mut self,
    glyphs: Vec<RawGlyph<()>>,
    script_tag: u32,
    opt_lang_tag: Option<u32>,
    features: &Features,
    kerning: bool
) -> Result<Vec<Info>, ShapingError>
[src]

Convenience method to shape the supplied glyphs.

The method maps applies glyph substitution (gsub) and glyph positioning (gpos). Use map_glyphs to turn text into glyphs that can be accepted by this method.

Arguments:

  • glyphs: the glyphs to be shaped.
  • script_tag: the OpenType script tag of the text.
  • opt_lang_tag: the OpenType language tag of the text.
  • features: the OpenType features to enable.
  • kerning: when applying gpos if this argument is true the kern OpenType feature is enabled for non-complex scripts. If it is false then the kern feature is not enabled for non-complex scripts.

Error Handling:

If gsub fails, shape will log an error (via the log crate) and continue on to gpos, returning the result of that. If you want to be able to handle gsub errors it would be better to call gsub and gpos manually. The source of this method can be used as a reference.

Example

use allsorts::binary::read::ReadScope;
use allsorts::font::MatchingPresentation;
use allsorts::font_data::FontData;
use allsorts::gsub::{self, Features, GsubFeatureMask};
use allsorts::DOTTED_CIRCLE;
use allsorts::{tag, Font};

let script = tag::LATN;
let lang = tag::DFLT;
let buffer = core::fs::read("tests/fonts/opentype/Klei.otf")
    .expect("unable to read Klei.otf");
let scope = ReadScope::new(&buffer);
let font_file = scope.read::<FontData<'_>>().expect("unable to parse font");
// Use a different index to access other fonts in a font collection (E.g. TTC)
let provider = font_file
    .table_provider(0)
    .expect("unable to create table provider");
let mut font = Font::new(provider)
    .expect("unable to load font tables")
    .expect("unable to find suitable cmap sub-table");

// Klei ligates ff
let glyphs = font.map_glyphs("Shaping in a jiffy.", MatchingPresentation::NotRequired);
let glyph_infos = font
    .shape(
        glyphs,
        script,
        Some(lang),
        &Features::Mask(GsubFeatureMask::default()),
        true,
    )
    .expect("error shaping text");
// We expect ff to be ligated so the number of glyphs (18) should be one less than the
// number of input characters (19).
assert_eq!(glyph_infos.len(), 18);

pub fn map_glyphs(
    &mut self,
    text: &str,
    match_presentation: MatchingPresentation
) -> Vec<RawGlyph<()>>
[src]

Map text to glyphs.

This method maps text into glyphs, which can then be passed to shape.

The match_presentation argument controls glyph mapping in the presence of emoji/text variation selectors. If MatchingPresentation::NotRequired is passed then glyph mapping will succeed if the font contains a mapping for a given character, regardless of whether it has the tables necessary to support the requested presentation. If MatchingPresentation::Required is passed then a character with emoji presentation, either by default or requested via variation selector will only map to a glyph if the font has mapping for the character, and it has the necessary tables for color emoji.

pub fn glyph_names<'a>(&self, ids: &[u16]) -> Vec<Cow<'a, str>>[src]

pub fn lookup_glyph_image(
    &mut self,
    glyph_index: u16,
    target_ppem: u16,
    max_bit_depth: BitDepth
) -> Result<Option<BitmapGlyph>, ParseError>
[src]

Find an image matching the supplied criteria.

  • glyph_index is the glyph to lookup.
  • target_ppem is the desired size. If an exact match can’t be found the nearest one will be returned, favouring being oversize vs. undersized.
  • max_bit_depth is the maximum accepted bit depth of the bitmap to return. If you accept all bit depths then use BitDepth::ThirtyTwo.

pub fn supports_emoji(&mut self) -> bool[src]

pub fn horizontal_advance(&mut self, glyph: u16) -> Option<u16>[src]

Returns the horizontal advance of the supplied glyph index.

Will return None if there are errors encountered reading the hmtx table or there is no entry for the glyph index.

pub fn vertical_advance(&mut self, glyph: u16) -> Option<u16>[src]

pub fn head_table(&self) -> Result<Option<HeadTable>, ParseError>[src]

pub fn os2_table(&self) -> Result<Option<Os2>, ParseError>[src]

pub fn gdef_table(&mut self) -> Result<Option<Rc<GDEFTable>>, ParseError>[src]

pub fn gsub_cache(&mut self) -> Result<Option<LayoutCache<GSUB>>, ParseError>[src]

pub fn gpos_cache(&mut self) -> Result<Option<LayoutCache<GPOS>>, ParseError>[src]

pub fn vhea_table(&mut self) -> Result<Option<Rc<HheaTable>>, ParseError>[src]

pub fn cmap_subtable_data(&self) -> &[u8][src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Font<T>

impl<T> !Send for Font<T>

impl<T> !Sync for Font<T>

impl<T> Unpin for Font<T> where
    T: Unpin

impl<T> !UnwindSafe for Font<T>

Blanket Implementations

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

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

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

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

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

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.

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.