pub trait FontSource:
PartialEq
+ Eq
+ Hash {
// Required methods
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;
}
Expand description
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§
Sourcefn write_object(&self, pdf: &mut Pdf) -> Result<usize>
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.
Sourcefn pdf_name(&self) -> String
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());
Sourcefn get_encoding(&self) -> &Encoding
fn get_encoding(&self) -> &Encoding
Get the encoding that this font uses.
Sourcefn get_width(&self, size: f32, text: &str) -> f32
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"));
Sourcefn get_width_raw(&self, text: &str) -> u32
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"));
Sourcefn get_metrics(&self) -> FontMetrics
fn get_metrics(&self) -> FontMetrics
Get the font metrics for font.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.