FontCache

Struct FontCache 

Source
pub struct FontCache {
    fonts: Vec<FontData>,
    pdf_fonts: Vec<IndirectFontRef>,
    default_font_family: Option<FontFamily<Font>>,
    embedded_font_cache: HashMap<*const Vec<u8>, IndirectFontRef>,
}
Expand description

Stores font data that can be referenced by a Font or FontFamily.

If you use the high-level interface provided by Document, you don’t have to access this type. See the module documentation for details on the internals.

Fields§

§fonts: Vec<FontData>§pdf_fonts: Vec<IndirectFontRef>§default_font_family: Option<FontFamily<Font>>§embedded_font_cache: HashMap<*const Vec<u8>, IndirectFontRef>

Implementations§

Source§

impl FontCache

Source

pub fn new(default_font_family: FontFamily<FontData>) -> FontCache

Creates a new font cache with the given default font family. Creates a new font cache with the given default font family.

§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.clone(), 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 _default = cache.default_font_family();
Source

pub fn add_font(&mut self, font_data: FontData) -> Font

Adds the given font to the cache and returns a reference to it. Adds the given font to the cache and returns a reference to it.

§Examples
use genpdfi_extended::fonts::FontData;
use genpdfi_extended::fonts::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 mut cache = FontCache::new(genpdfi_extended::fonts::FontFamily { regular: fd.clone(), bold: fd.clone(), italic: fd.clone(), bold_italic: fd.clone() });
let f = cache.add_font(fd.clone());
let _rt = cache.get_rt_font(f);
Source

pub fn add_font_family( &mut self, family: FontFamily<FontData>, ) -> FontFamily<Font>

Adds the given font family to the cache and returns a reference to it.

Source

pub fn load_pdf_fonts(&mut self, renderer: &mut Renderer) -> Result<(), Error>

Embeds all loaded fonts into the document generated by the given renderer and caches a reference to them. Embeds all loaded fonts into the document generated by the given renderer and caches a reference to them.

§Examples
use genpdfi_extended::fonts::{FontData, FontFamily, FontCache};
use genpdfi_extended::render::Renderer;
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 mut cache = FontCache::new(family);
let mut r = Renderer::new(genpdfi_extended::Size::new(210.0, 297.0), "ex").expect("renderer");
cache.load_pdf_fonts(&mut r).expect("load fonts");
Source

pub fn default_font_family(&self) -> FontFamily<Font>

Returns the default font family for this font cache.

Source

pub fn get_pdf_font(&self, font: Font) -> Option<&IndirectFontRef>

Returns a reference to the emebdded PDF font for the given font, if available.

This method may only be called with Font instances that have been created by this font cache. PDF fonts are only avaiable if load_pdf_fonts has been called.

Source

pub fn get_rt_font(&self, font: Font) -> &Font<'static>

Returns a reference to the Rusttype font for the given font, if available.

This method may only be called with Font instances that have been created by this font cache.

Trait Implementations§

Source§

impl Debug for FontCache

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
§

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
§

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