Font

Struct Font 

Source
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: Mm

Implementations§

Source§

impl Font

Source

fn new(idx: usize, is_builtin: bool, rt_font: &Font<'static>) -> Font

Source

pub fn is_builtin(&self) -> bool

Returns whether this font is a built-in PDF font.

Source

pub fn get_line_height(&self, font_size: u8) -> Mm

Returns the line height for text with this font and the given font size.

Source

pub fn glyph_height(&self, font_size: u8) -> Mm

Returns the glyph height for text with this font and the given font size.

Source

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));
Source

pub fn descent(&self, font_size: u8) -> Mm

Returns the descent for text with this font and the given font size.

Source

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.

Source

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.

Source

fn char_h_metrics(&self, font_cache: &FontCache, c: char) -> HMetrics

Source

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.

Source

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.

Source

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.

Source

pub fn glyph_ids<I>(&self, font_cache: &FontCache, iter: I) -> Vec<u16>
where I: IntoIterator<Item = char>,

Returns the glyphs IDs for the given sequence of characters.

The given FontCache must be the font cache that loaded this font.

Source

pub fn metrics(&self, font_size: u8) -> Metrics

Calculate the metrics of a given font size for this font.

Trait Implementations§

Source§

impl Clone for Font

Source§

fn clone(&self) -> Font

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Font

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Font

Source§

fn eq(&self, other: &Font) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Font

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V