pub struct FontFace<'a>(/* private fields */);Expand description
A font face is an object that represents a single face from within a font family.
More precisely, a font face represents a single face in a binary font file. Font faces are typically built from a binary blob and a face index. Font faces are used to create fonts.
Implementations§
Source§impl<'a> FontFace<'a>
impl<'a> FontFace<'a>
Sourcepub fn new(blob: Blob<'a>) -> Result<Self, FontFaceExtractionError>
pub fn new(blob: Blob<'a>) -> Result<Self, FontFaceExtractionError>
Constructs a new face object from the specified blob.
This defaults to taking the first face in the blob. If you need to specify which font face to load, you can use
new_with_index instead.
Sourcepub fn new_with_index(
blob: Blob<'a>,
index: u32,
) -> Result<Self, FontFaceExtractionError>
pub fn new_with_index( blob: Blob<'a>, index: u32, ) -> Result<Self, FontFaceExtractionError>
Constructs a new face object from the specified blob and a face index into that blob.
The face index is used for blobs of file formats such as TTC and DFont that can contain more than one face. Face indices within such collections are zero-based.
Sourcepub fn underlying_blob(&self) -> Blob<'_>
pub fn underlying_blob(&self) -> Blob<'_>
Gets the blob underlying this font face.
Useful when you want to output the font face to a file.
Returns an empty blob if referencing face data is not possible.
Sourcepub fn glyph_count(&self) -> usize
pub fn glyph_count(&self) -> usize
Fetches the glyph-count value of the specified face object.
Sourcepub fn covered_codepoints(&self) -> Result<CharSet<'_>, AllocationError>
pub fn covered_codepoints(&self) -> Result<CharSet<'_>, AllocationError>
Collects all of the Unicode characters covered by the font face.
Sourcepub fn nominal_glyph_mapping(
&self,
) -> Result<Map<'static, char, u32>, AllocationError>
pub fn nominal_glyph_mapping( &self, ) -> Result<Map<'static, char, u32>, AllocationError>
Collects the mapping from Unicode characters to nominal glyphs of the face.
Sourcepub fn preprocess_for_subsetting(&self) -> PreprocessedFontFace<'a>
pub fn preprocess_for_subsetting(&self) -> PreprocessedFontFace<'a>
Preprocesses the face and attaches data that will be needed by the subsetter.
Future subsetting operations can use the precomputed data to speed up the subsetting operation. The preprocessing operation may take longer than the time it takes to produce a subset from the source font. Thus the main performance gains are made when a preprocessed face is reused for multiple subsetting operations.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
let processed = font.preprocess_for_subsetting();
for subset in subsets() {
subset.subset_font(&processed)?;
}Source§impl<'a> FontFace<'a>
impl<'a> FontFace<'a>
Sourcepub fn into_raw(self) -> *mut hb_face_t
pub fn into_raw(self) -> *mut hb_face_t
Converts the font face into raw sys::hb_face_t pointer.
This method transfers the ownership of the font face to the caller. It is up to the caller to call
sys::hb_face_destroy to free the pointer, or call Self::from_raw to convert it back into FontFace.
Sourcepub fn as_raw(&self) -> *mut hb_face_t
pub fn as_raw(&self) -> *mut hb_face_t
Exposes the raw inner pointer without transferring the ownership.
Unlike Self::into_raw, this method does not transfer the ownership of the pointer to the caller.
Sourcepub unsafe fn from_raw(font_face: *mut hb_face_t) -> Self
pub unsafe fn from_raw(font_face: *mut hb_face_t) -> Self
Constructs a font face from raw sys::hb_face_t pointer.
§Safety
The given font_face pointer must either be constructed by some Harfbuzz function, or be returned from
Self::into_raw.
Source§impl<'a> FontFace<'a>
Functions for fetching name strings from OpenType fonts.
impl<'a> FontFace<'a>
Functions for fetching name strings from OpenType fonts.
See OpenType spec for more information on these strings.
Sourcepub fn ot_name(
&self,
name: impl Into<hb_ot_name_id_t>,
language: Language,
) -> String
pub fn ot_name( &self, name: impl Into<hb_ot_name_id_t>, language: Language, ) -> String
Gets value from OpenType name table for given language.
Instead of using this method directly, consider using one of the convenience methods for getting the correct string directly.
If language is null(), English is assumed.
Sourcepub fn copyright(&self) -> String
pub fn copyright(&self) -> String
Gets copyright notice.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.copyright(), "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/latin-greek-cyrillic)");Sourcepub fn font_family(&self) -> String
pub fn font_family(&self) -> String
Gets font family name.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.font_family(), "Noto Sans");Sourcepub fn font_subfamily(&self) -> String
pub fn font_subfamily(&self) -> String
Gets font subfamily name.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.font_subfamily(), "Regular");Sourcepub fn unique_id(&self) -> String
pub fn unique_id(&self) -> String
Gets unique font identifier.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.unique_id(), "2.013;GOOG;NotoSans-Regular");Sourcepub fn full_name(&self) -> String
pub fn full_name(&self) -> String
Gets full font name that reflects all family and relevant subfamily descriptors.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.full_name(), "Noto Sans Regular");Sourcepub fn version_string(&self) -> String
pub fn version_string(&self) -> String
Gets version string.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.version_string(), "Version 2.013; ttfautohint (v1.8.4.7-5d5b)");Sourcepub fn postscript_name(&self) -> String
pub fn postscript_name(&self) -> String
Gets PostScript name for the font.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.postscript_name(), "NotoSans-Regular");Sourcepub fn trademark(&self) -> String
pub fn trademark(&self) -> String
Gets trademark information.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.trademark(), "Noto is a trademark of Google LLC.");Sourcepub fn manufacturer(&self) -> String
pub fn manufacturer(&self) -> String
Gets manufacturer name.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.manufacturer(), "Monotype Imaging Inc.");Sourcepub fn designer(&self) -> String
pub fn designer(&self) -> String
Gets designer name.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.designer(), "Monotype Design Team");Sourcepub fn description(&self) -> String
pub fn description(&self) -> String
Gets description.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.description(), "Designed by Monotype design team, Irene Vlachou.");Sourcepub fn vendor_url(&self) -> String
pub fn vendor_url(&self) -> String
Gets URL of font vendor.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.vendor_url(), "http://www.google.com/get/noto/");Sourcepub fn designer_url(&self) -> String
pub fn designer_url(&self) -> String
Gets URL of typeface designer.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.designer_url(), "http://www.monotype.com/studio");Sourcepub fn license(&self) -> String
pub fn license(&self) -> String
Gets license description.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.license(), "This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is available with a FAQ at: https://scripts.sil.org/OFL");Sourcepub fn license_url(&self) -> String
pub fn license_url(&self) -> String
Gets URL where additional licensing information can be found.
§Example
let font = FontFace::new(Blob::from_file("tests/fonts/NotoSans.ttf")?)?;
assert_eq!(font.license_url(), "https://scripts.sil.org/OFL");Sourcepub fn typographic_family(&self) -> String
pub fn typographic_family(&self) -> String
Gets typographic family name.
Sourcepub fn typographic_subfamily(&self) -> String
pub fn typographic_subfamily(&self) -> String
Gets typographic subfamily name.
Sourcepub fn mac_full_name(&self) -> String
pub fn mac_full_name(&self) -> String
Gets compatible full name for MacOS.
Sourcepub fn sample_text(&self) -> String
pub fn sample_text(&self) -> String
Gets sample text.
Sourcepub fn cid_findfont_name(&self) -> String
pub fn cid_findfont_name(&self) -> String
Gets PostScript CID findfont name.
Sourcepub fn wws_family(&self) -> String
pub fn wws_family(&self) -> String
Gets WWS family Name.
Sourcepub fn wws_subfamily(&self) -> String
pub fn wws_subfamily(&self) -> String
Gets WWS subfamily Name.
Sourcepub fn light_background(&self) -> String
pub fn light_background(&self) -> String
Gets light background palette.
Sourcepub fn dark_background(&self) -> String
pub fn dark_background(&self) -> String
Gets dark background palette.
Sourcepub fn variations_ps_prefix(&self) -> String
pub fn variations_ps_prefix(&self) -> String
Gets variations PostScript name prefix.