RazrFalcon / rustybuzz

A complete harfbuzz's shaping algorithm port to Rust
MIT License
544 stars 34 forks source link

Misleading API in `Face::from_face`. #52

Closed wdanilo closed 1 year ago

wdanilo commented 2 years ago

The Face::from_face is defined as:

    /// Creates a new [`Face`] from [`ttf_parser::Face`].
    ///
    /// Data will be referenced, not owned.
    ///
    /// Returns `None` when face's units per EM is `None`.
    pub fn from_face(face: ttf_parser::Face<'a>) -> Option<Self> {
        Some(Face {
            units_per_em: face.units_per_em(),
            pixels_per_em: None,
            points_per_em: None,
            prefered_cmap_encoding_subtable: find_best_cmap_subtable(&face),
            gsub: face.tables().gsub.map(SubstitutionTable::new),
            gpos: face.tables().gpos.map(PositioningTable::new),
            ttfp_face: face,
        })
    }

This function always returns Some and I believe the docs are invalid, as face.units_per_em() returns u16.

RazrFalcon commented 2 years ago

Thanks, yes, this is an outdated API. face.units_per_em was returning Option at some point.