Struct pdfium_render::font::PdfFont

source ·
pub struct PdfFont<'a> { /* private fields */ }
Expand description

A single font used to render text in a PdfDocument.

The PDF specification defines 14 built-in fonts that can be used in any PDF file without font embedding. Additionally, custom fonts can be directly embedded into any PDF file as a data stream.

Implementations§

source§

impl<'a> PdfFont<'a>

source

pub fn new_built_in(document: &'a PdfDocument<'a>, font: PdfFontBuiltin) -> Self

Creates a new PdfFont from the given given built-in font argument.

source

pub fn times_roman(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Times-Roman” font.

source

pub fn times_bold(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Times-Bold” font.

source

pub fn times_italic(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Times-Italic” font.

source

pub fn times_bold_italic(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Times-BoldItalic” font.

source

pub fn helvetica(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Helvetica” font.

source

pub fn helvetica_bold(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Helvetica-Bold” font.

source

pub fn helvetica_oblique(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Helvetica-Oblique” font.

source

pub fn helvetica_bold_oblique(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Helvetica-BoldOblique” font.

source

pub fn courier(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Courier” font.

source

pub fn courier_bold(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Courier-Bold” font.

source

pub fn courier_oblique(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Courier-Oblique” font.

source

pub fn courier_bold_oblique(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Courier-BoldOblique” font.

source

pub fn symbol(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “Symbol” font.

source

pub fn zapf_dingbats(document: &'a PdfDocument<'a>) -> Self

Creates a new PdfFont for the built-in “ZapfDingbats” font.

source

pub fn load_type1_from_file( document: &'a PdfDocument<'a>, path: &impl AsRef<Path> + ?Sized, is_cid_font: bool ) -> Result<Self, PdfiumError>

Attempts to load a Type 1 font file from the given file path.

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

This function is not available when compiling to WASM. You have several options for loading font data in WASM:

  • Use the PdfFont::load_type1_from_fetch() function to download font data from a URL using the browser’s built-in fetch() API. This function is only available when compiling to WASM.
  • Use the PdfFont::load_type1_from_blob() function to load font data from a Javascript File or Blob object (such as a File object returned from an HTML <input type="file"> element). This function is only available when compiling to WASM.
  • Use the PdfFont::load_type1_from_reader() function to load font data from any valid Rust reader.
  • Use another method to retrieve the bytes of the target font over the network, then load those bytes into Pdfium using the PdfFont::new_type1_from_bytes() function.
  • Embed the bytes of the desired font directly into the compiled WASM module using the include_bytes!() macro.
source

pub fn load_type1_from_reader( document: &'a PdfDocument<'a>, reader: impl Read, is_cid_font: bool ) -> Result<Self, PdfiumError>

Attempts to load a Type 1 font file from the given reader.

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

source

pub async fn load_type1_from_fetch( document: &'a PdfDocument<'a>, url: impl ToString, is_cid_font: bool ) -> Result<PdfFont<'a>, PdfiumError>

Attempts to load a Type 1 font file from the given URL. The Javascript fetch() API is used to download data over the network.

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

This function is only available when compiling to WASM.

source

pub async fn load_type1_from_blob( document: &'a PdfDocument<'a>, blob: Blob, is_cid_font: bool ) -> Result<PdfFont<'a>, PdfiumError>

Attempts to load a Type 1 font from the given Blob. A File object returned from a FileList is a suitable Blob:

<input id="filePicker" type="file">

const file = document.getElementById('filePicker').files[0];

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

This function is only available when compiling to WASM.

source

pub fn new_type1_from_bytes( document: &'a PdfDocument<'a>, font_data: &[u8], is_cid_font: bool ) -> Result<Self, PdfiumError>

Attempts to load the given byte data as a Type 1 font file.

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

source

pub fn load_true_type_from_file( document: &'a PdfDocument<'a>, path: &impl AsRef<Path> + ?Sized, is_cid_font: bool ) -> Result<Self, PdfiumError>

Attempts to load a TrueType font file from the given file path.

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

This function is not available when compiling to WASM. You have several options for loading font data in WASM:

  • Use the PdfFont::load_true_type_from_fetch() function to download font data from a URL using the browser’s built-in fetch() API. This function is only available when compiling to WASM.
  • Use the PdfFont::load_true_type_from_blob() function to load font data from a Javascript File or Blob object (such as a File object returned from an HTML <input type="file"> element). This function is only available when compiling to WASM.
  • Use the PdfFont::load_true_type_from_reader() function to load font data from any valid Rust reader.
  • Use another method to retrieve the bytes of the target font over the network, then load those bytes into Pdfium using the PdfFont::new_true_type_from_bytes() function.
  • Embed the bytes of the desired font directly into the compiled WASM module using the include_bytes!() macro.
source

pub fn load_true_type_from_reader( document: &'a PdfDocument<'a>, reader: impl Read, is_cid_font: bool ) -> Result<Self, PdfiumError>

Attempts to load a TrueType font file from the given reader.

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

source

pub async fn load_true_type_from_fetch( document: &'a PdfDocument<'a>, url: impl ToString, is_cid_font: bool ) -> Result<PdfFont<'a>, PdfiumError>

Attempts to load a TrueType font file from the given URL. The Javascript fetch() API is used to download data over the network.

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

This function is only available when compiling to WASM.

source

pub async fn load_true_type_from_blob( document: &'a PdfDocument<'a>, blob: Blob, is_cid_font: bool ) -> Result<PdfFont<'a>, PdfiumError>

Attempts to load a TrueType font from the given Blob. A File object returned from a FileList is a suitable Blob:

<input id="filePicker" type="file">

const file = document.getElementById('filePicker').files[0];

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

This function is only available when compiling to WASM.

source

pub fn new_true_type_from_bytes( document: &'a PdfDocument<'a>, font_data: &[u8], is_cid_font: bool ) -> Result<Self, PdfiumError>

Attempts to load the given byte data as a TrueType font file.

Set the is_cid_font parameter to true if the given font is keyed by 16-bit character ID (CID), indicating that it supports an extended glyphset of 65,535 glyphs. This is typically the case with fonts that support Asian character sets or right-to-left languages.

source

pub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings

Returns the PdfiumLibraryBindings used by this PdfFont.

source

pub fn name(&self) -> String

Returns the name of this PdfFont.

source

pub fn weight(&self) -> Result<PdfFontWeight, PdfiumError>

Returns the weight of this PdfFont.

Pdfium may not reliably return the correct value of this property for built-in fonts.

source

pub fn italic_angle(&self) -> Result<i32, PdfiumError>

Returns the italic angle of this PdfFont. The italic angle is the angle, expressed in degrees counter-clockwise from the vertical, of the dominant vertical strokes of the font. The value is zero for non-italic fonts, and negative for fonts that slope to the right (as almost all italic fonts do).

Pdfium may not reliably return the correct value of this property for built-in fonts.

source

pub fn ascent(&self, font_size: PdfPoints) -> Result<PdfPoints, PdfiumError>

Returns the ascent of this PdfFont for the given font size. The ascent is the maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters.

source

pub fn descent(&self, font_size: PdfPoints) -> Result<PdfPoints, PdfiumError>

Returns the descent of this PdfFont for the given font size. The descent is the maximum distance below the baseline reached by glyphs in this font, expressed as a negative points value.

source

pub fn is_fixed_pitch(&self) -> bool

Returns true if all the glyphs in this PdfFont have the same width.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_proportional_pitch(&self) -> bool

Returns true if the glyphs in this PdfFont have variable widths.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_serif(&self) -> bool

Returns true if one or more glyphs in this PdfFont have serifs - short strokes drawn at an angle on the top or bottom of glyph stems to decorate the glyphs. For example, Times New Roman is a serif font.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_sans_serif(&self) -> bool

Returns true if no glyphs in this PdfFont have serifs - short strokes drawn at an angle on the top or bottom of glyph stems to decorate the glyphs. For example, Helvetica is a sans-serif font.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_symbolic(&self) -> bool

Returns true if this PdfFont contains glyphs outside the Adobe standard Latin character set.

This classification of non-symbolic and symbolic fonts is peculiar to PDF. A font may contain additional characters that are used in Latin writing systems but are outside the Adobe standard Latin character set; PDF considers such a font to be symbolic.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_non_symbolic(&self) -> bool

Returns true if this PdfFont does not contain glyphs outside the Adobe standard Latin character set.

This classification of non-symbolic and symbolic fonts is peculiar to PDF. A font may contain additional characters that are used in Latin writing systems but are outside the Adobe standard Latin character set; PDF considers such a font to be symbolic.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_cursive(&self) -> bool

Returns true if the glyphs in this PdfFont are designed to resemble cursive handwriting.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_italic(&self) -> bool

Returns true if the glyphs in this PdfFont include dominant vertical strokes that are slanted.

The designed vertical stroke angle can be retrieved using the PdfFont::italic_angle() function.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_all_caps(&self) -> bool

Returns true if this PdfFont contains no lowercase letters by design.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_small_caps(&self) -> bool

Returns true if the lowercase letters in this PdfFont have the same shapes as the corresponding uppercase letters but are sized proportionally so they have the same size and stroke weight as lowercase glyphs in the same typeface family.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn is_bold_reenforced(&self) -> bool

Returns true if bold glyphs in this PdfFont are painted with extra pixels at very small font sizes.

Typically when glyphs are painted at small sizes on low-resolution devices, individual strokes of bold glyphs may appear only one pixel wide. Because this is the minimum width of a pixel based device, individual strokes of non-bold glyphs may also appear as one pixel wide and therefore cannot be distinguished from bold glyphs. If this flag is set, individual strokes of bold glyphs may be thickened at small font sizes.

Pdfium may not reliably return the correct value of this flag for built-in fonts.

source

pub fn glyphs(&self) -> &PdfFontGlyphs<'_>

Returns a collection of all the PdfFontGlyphs defined for this PdfFont in the containing PdfDocument.

Note that documents typically include only the specific glyphs they need from any given font, not the entire font glyphset. This is a PDF feature known as font subsetting. The collection of glyphs returned by this function may therefore not cover the entire font glyphset.

Trait Implementations§

source§

impl<'a> Drop for PdfFont<'a>

source§

fn drop(&mut self)

Closes this PdfFont, releasing held memory.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for PdfFont<'a>

§

impl<'a> !Send for PdfFont<'a>

§

impl<'a> !Sync for PdfFont<'a>

§

impl<'a> Unpin for PdfFont<'a>

§

impl<'a> !UnwindSafe for PdfFont<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.