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
impl FontCache
Sourcepub fn new(default_font_family: FontFamily<FontData>) -> FontCache
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();Sourcepub fn add_font(&mut self, font_data: FontData) -> Font
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);Sourcepub fn add_font_family(
&mut self,
family: FontFamily<FontData>,
) -> FontFamily<Font>
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.
Sourcepub fn load_pdf_fonts(&mut self, renderer: &mut Renderer) -> Result<(), Error>
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");Sourcepub fn default_font_family(&self) -> FontFamily<Font>
pub fn default_font_family(&self) -> FontFamily<Font>
Returns the default font family for this font cache.
Sourcepub fn get_pdf_font(&self, font: Font) -> Option<&IndirectFontRef>
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.
Sourcepub fn get_rt_font(&self, font: Font) -> &Font<'static>
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§
Auto Trait Implementations§
impl Freeze for FontCache
impl RefUnwindSafe for FontCache
impl !Send for FontCache
impl !Sync for FontCache
impl Unpin for FontCache
impl UnwindSafe for FontCache
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> 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.