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
sourceimpl<'a> PdfFont<'a>
impl<'a> PdfFont<'a>
sourcepub fn new_built_in(document: &'a PdfDocument<'a>, font: PdfFontBuiltin) -> Self
pub fn new_built_in(document: &'a PdfDocument<'a>, font: PdfFontBuiltin) -> Self
Creates a new PdfFont from the given given built-in font argument.
sourcepub fn times_roman(document: &'a PdfDocument<'a>) -> Self
pub fn times_roman(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Times-Roman” font.
sourcepub fn times_bold(document: &'a PdfDocument<'a>) -> Self
pub fn times_bold(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Times-Bold” font.
sourcepub fn times_italic(document: &'a PdfDocument<'a>) -> Self
pub fn times_italic(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Times-Italic” font.
sourcepub fn times_bold_italic(document: &'a PdfDocument<'a>) -> Self
pub fn times_bold_italic(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Times-BoldItalic” font.
sourcepub fn helvetica(document: &'a PdfDocument<'a>) -> Self
pub fn helvetica(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Helvetica” font.
sourcepub fn helvetica_bold(document: &'a PdfDocument<'a>) -> Self
pub fn helvetica_bold(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Helvetica-Bold” font.
sourcepub fn helvetica_oblique(document: &'a PdfDocument<'a>) -> Self
pub fn helvetica_oblique(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Helvetica-Oblique” font.
sourcepub fn helvetica_bold_oblique(document: &'a PdfDocument<'a>) -> Self
pub fn helvetica_bold_oblique(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Helvetica-BoldOblique” font.
sourcepub fn courier(document: &'a PdfDocument<'a>) -> Self
pub fn courier(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Courier” font.
sourcepub fn courier_bold(document: &'a PdfDocument<'a>) -> Self
pub fn courier_bold(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Courier-Bold” font.
sourcepub fn courier_oblique(document: &'a PdfDocument<'a>) -> Self
pub fn courier_oblique(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Courier-Oblique” font.
sourcepub fn courier_bold_oblique(document: &'a PdfDocument<'a>) -> Self
pub fn courier_bold_oblique(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Courier-BoldOblique” font.
sourcepub fn symbol(document: &'a PdfDocument<'a>) -> Self
pub fn symbol(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “Symbol” font.
sourcepub fn zapf_dingbats(document: &'a PdfDocument<'a>) -> Self
pub fn zapf_dingbats(document: &'a PdfDocument<'a>) -> Self
Creates a new PdfFont for the built-in “ZapfDingbats” font.
sourcepub fn load_type1_from_file(
document: &'a PdfDocument<'a>,
path: &impl AsRef<Path> + ?Sized,
is_cid_font: bool
) -> Result<Self, PdfiumError>
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-infetch()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.
sourcepub fn load_type1_from_reader(
document: &'a PdfDocument<'a>,
reader: impl Read,
is_cid_font: bool
) -> Result<Self, PdfiumError>
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.
sourcepub fn new_type1_from_bytes(
document: &'a PdfDocument<'a>,
font_data: &[u8],
is_cid_font: bool
) -> Result<Self, PdfiumError>
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.
sourcepub fn load_true_type_from_file(
document: &'a PdfDocument<'a>,
path: &impl AsRef<Path> + ?Sized,
is_cid_font: bool
) -> Result<Self, PdfiumError>
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-infetch()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.
sourcepub fn load_true_type_from_reader(
document: &'a PdfDocument<'a>,
reader: impl Read,
is_cid_font: bool
) -> Result<Self, PdfiumError>
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.
sourcepub fn new_true_type_from_bytes(
document: &'a PdfDocument<'a>,
font_data: &[u8],
is_cid_font: bool
) -> Result<Self, PdfiumError>
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.
sourcepub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings
pub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings
Returns the PdfiumLibraryBindings used by this PdfFont.
sourcepub fn weight(&self) -> Result<PdfFontWeight, PdfiumError>
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.
sourcepub fn italic_angle(&self) -> Result<i32, PdfiumError>
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.
sourcepub fn ascent(&self, font_size: PdfPoints) -> Result<PdfPoints, PdfiumError>
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.
sourcepub fn descent(&self, font_size: PdfPoints) -> Result<PdfPoints, PdfiumError>
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.
sourcepub fn is_fixed_pitch(&self) -> bool
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.
sourcepub fn is_proportional_pitch(&self) -> bool
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.
sourcepub fn is_serif(&self) -> bool
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.
sourcepub fn is_sans_serif(&self) -> bool
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.
sourcepub fn is_symbolic(&self) -> bool
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.
sourcepub fn is_non_symbolic(&self) -> bool
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.
sourcepub fn is_cursive(&self) -> bool
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.
sourcepub fn is_italic(&self) -> bool
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.
sourcepub fn is_all_caps(&self) -> bool
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.
sourcepub fn is_small_caps(&self) -> bool
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.
sourcepub fn is_bold_reenforced(&self) -> bool
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.