Trait pdf_canvas::FontSource [−][src]
pub trait FontSource: PartialEq + Eq + Hash { fn write_object(&self, pdf: &mut Pdf) -> Result<usize>; fn pdf_name(&self) -> String; fn get_encoding(&self) -> &Encoding; fn get_width(&self, size: f32, text: &str) -> f32; fn get_width_raw(&self, text: &str) -> u32; fn get_metrics(&self) -> FontMetrics; }
This trait is implemented by any kind of font that the pdf library supports.
Currently, only BuiltinFont implements this. TODO Add implementation(s) for other fonts.
Required Methods
fn write_object(&self, pdf: &mut Pdf) -> Result<usize>
Write the object(s) for this font to a pdf file.
This is called automatically for each font used in a document. There should be no need to call this method from user code.
fn pdf_name(&self) -> String
Get the PDF name of this font.
Examples
use pdf_canvas::{BuiltinFont, FontSource}; assert_eq!("Times-Roman", BuiltinFont::Times_Roman.pdf_name());
fn get_encoding(&self) -> &Encoding
Get the encoding that this font uses.
fn get_width(&self, size: f32, text: &str) -> f32
Get the width of a string in this font at given size.
Examples
use pdf_canvas::{BuiltinFont, FontSource}; let proportional = BuiltinFont::Helvetica; assert_eq!(62.004, proportional.get_width(12.0, "Hello World")); let fixed = BuiltinFont::Courier; assert_eq!(60.0, fixed.get_width(10.0, "0123456789"));
fn get_width_raw(&self, text: &str) -> u32
Get the width of a string in thousands of unit of text space. This unit is what is used in some places internally in pdf files.
Examples
use pdf_canvas::{BuiltinFont, FontSource}; assert_eq!(5167, BuiltinFont::Helvetica.get_width_raw("Hello World")); assert_eq!(600, BuiltinFont::Courier.get_width_raw("A"));
fn get_metrics(&self) -> FontMetrics
Get the font metrics for font.
Implementors
impl FontSource for BuiltinFont