pub struct Font {
idx: usize,
is_builtin: bool,
scale: Scale,
line_height: Mm,
glyph_height: Mm,
ascent: Mm,
descent: Mm,
}Expand description
A reference to a font cached by a FontCache.
See the module documentation for details on the internals.
Fields§
§idx: usize§is_builtin: bool§scale: Scale§line_height: Mm§glyph_height: Mm§ascent: Mm§descent: MmImplementations§
Source§impl Font
impl Font
fn new(idx: usize, is_builtin: bool, rt_font: &Font<'static>) -> Font
Sourcepub fn is_builtin(&self) -> bool
pub fn is_builtin(&self) -> bool
Returns whether this font is a built-in PDF font.
Sourcepub fn get_line_height(&self, font_size: u8) -> Mm
pub fn get_line_height(&self, font_size: u8) -> Mm
Returns the line height for text with this font and the given font size.
Sourcepub fn glyph_height(&self, font_size: u8) -> Mm
pub fn glyph_height(&self, font_size: u8) -> Mm
Returns the glyph height for text with this font and the given font size.
Sourcepub fn ascent(&self, font_size: u8) -> Mm
pub fn ascent(&self, font_size: u8) -> Mm
Returns the ascent for text with this font and the given font size.
§Examples
use genpdfi_extended::fonts::{FontData, FontFamily, FontCache};
let data = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/fonts/NotoSans-Regular.ttf")).to_vec();
let fd = FontData::new(data, None).expect("font data");
let family = FontFamily { regular: fd.clone(), bold: fd.clone(), italic: fd.clone(), bold_italic: fd.clone() };
let cache = FontCache::new(family);
let f = cache.default_font_family().regular;
assert!(f.ascent(12) > genpdfi_extended::Mm::from(0.0));Sourcepub fn descent(&self, font_size: u8) -> Mm
pub fn descent(&self, font_size: u8) -> Mm
Returns the descent for text with this font and the given font size.
Sourcepub fn char_width(&self, font_cache: &FontCache, c: char, font_size: u8) -> Mm
pub fn char_width(&self, font_cache: &FontCache, c: char, font_size: u8) -> Mm
Returns the width of a character with this font and the given font size.
The given FontCache must be the font cache that loaded this font.
Sourcepub fn char_left_side_bearing(
&self,
font_cache: &FontCache,
c: char,
font_size: u8,
) -> Mm
pub fn char_left_side_bearing( &self, font_cache: &FontCache, c: char, font_size: u8, ) -> Mm
Returns the width of the empty space between the origin of the glyph bounding box and the leftmost edge of the character, for a given font and font size.
The given FontCache must be the font cache that loaded this font.
fn char_h_metrics(&self, font_cache: &FontCache, c: char) -> HMetrics
Sourcefn builtin_char_h_metrics(&self, c: char) -> HMetrics
fn builtin_char_h_metrics(&self, c: char) -> HMetrics
Returns standardized character metrics for built-in PDF fonts. These values are based on the Adobe Font Metrics (AFM) for standard PDF fonts.
Sourcepub fn str_width(&self, font_cache: &FontCache, s: &str, font_size: u8) -> Mm
pub fn str_width(&self, font_cache: &FontCache, s: &str, font_size: u8) -> Mm
Returns the width of a string with this font and the given font size.
The given FontCache must be the font cache that loaded this font.
Sourcepub fn kerning<I>(&self, font_cache: &FontCache, iter: I) -> Vec<f32>where
I: IntoIterator<Item = char>,
pub fn kerning<I>(&self, font_cache: &FontCache, iter: I) -> Vec<f32>where
I: IntoIterator<Item = char>,
Returns the kerning data for the given sequence of characters.
The i-th value of the returned data is the amount of kerning to insert before the i-th character of the sequence.
The given FontCache must be the font cache that loaded this font.
Trait Implementations§
impl Copy for Font
impl StructuralPartialEq for Font
Auto Trait Implementations§
impl Freeze for Font
impl RefUnwindSafe for Font
impl Send for Font
impl Sync for Font
impl Unpin for Font
impl UnwindSafe for Font
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.