FontData

Struct FontData 

Source
pub struct FontData {
    pub font_name: String,
    pub flags: i64,
    pub font_bbox: (i64, i64, i64, i64),
    pub italic_angle: i64,
    pub ascent: i64,
    pub descent: i64,
    pub cap_height: i64,
    pub stem_v: i64,
    pub encoding: String,
    /* private fields */
}
Expand description

This struct represents the data of a font. It contains information about the font’s bounding box, ascent, descent, cap height, italic angle, and stemV. Reference: https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.5_v6.pdf

Fields§

§font_name: String

(Required) The PostScript name of the font. This should be the same as the value of BaseFont in the font or CIDFont dictionary that refers to this font descriptor.

§flags: i64

(Required) A collection of flags defining various characteristics of the font.

§font_bbox: (i64, i64, i64, i64)

(Required, except for Type 3 fonts) A rectangle (see Section 3.8.4, “Rectangles”), expressed in the glyph coordinate system, specifying the font bounding box. This is the smallest rectangle enclosing the shape that would result if all of the glyphs of the font were placed with their origins coincident and then filled. Format as: (x_min, y_min, x_max, y_max).

§italic_angle: i64

(Required) The angle, expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font. (For example, the 9-o’clock position is 90 degrees, and the 3-o’clock position is –90 degrees.) The value is negative for fonts that slope to the right, as almost all italic fonts do.

§ascent: i64

(Required, except for Type 3 fonts) The maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accentedc haracters.

§descent: i64

(Required, except for Type 3 fonts) The maximum depth below the baseline reached by glyphs in this font. The value is a negative number.

§cap_height: i64

(Required for fonts that have Latin characters, except for Type 3 fonts) The vertical coordinate of the top of flat capital letters, measured from the baseline.

§stem_v: i64

(Required, except for Type 3 fonts) The thickness, measured horizontally, of the dominant vertical stems of glyphs in the font.

§encoding: String

(Required) The name of a predefined CMap, or a stream containing a CMap program, that maps character codes to font numbers and CIDs. If the descendant is a Type 2 CIDFont whose associated TrueType font program is not embedded in the PDF file, the Encoding entry must be a predefined CMap name Read more (page 422): https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.5_v6.pdf

Implementations§

Source§

impl FontData

This struct is used to store font metadata extracted from a TrueType Fonts (TTF) file.

§Examples

// Read a TrueType Fonts (TTF) file.
let font_file = std::fs::read("./SomeFont.ttf").unwrap();

// Create a new FontData instance.
let font_name = "SomeFont".to_string();
let font_data = lopdf::FontData::new(&font_file, font_name);

Also provides methods to set various font properties such as bounding box, italic angle, ascent, descent, and stemV.

§Examples

let font_file = std::fs::read("./SomeFont.ttf").unwrap();

// Create a new FontData instance along custome value.
let font_data = lopdf::FontData::new(&font_file, "SomeFont".to_string())
                    .set_stem_v(100)
                    .set_italic_angle(10);
Source

pub fn new(font_file: &[u8], font_name: String) -> FontData

Create a new FontData instance by parsing the provided TTF file. The TTF file is expected to be in bytes.

Source

pub fn set_flags(&mut self, flags: i64) -> &mut FontData

Source

pub fn set_font_bbox( &mut self, font_bbox: (i64, i64, i64, i64), ) -> &mut FontData

Source

pub fn set_italic_angle(&mut self, italic_angle: i64) -> &mut FontData

Source

pub fn set_ascent(&mut self, ascent: i64) -> &mut FontData

Source

pub fn set_descent(&mut self, descent: i64) -> &mut FontData

Source

pub fn set_cap_height(&mut self, cap_height: i64) -> &mut FontData

Source

pub fn set_stem_v(&mut self, stem_v: i64) -> &mut FontData

Source

pub fn set_encoding(&mut self, encoding: String) -> &mut FontData

Source

pub fn bytes(&self) -> Vec<u8>

Trait Implementations§

Source§

impl Clone for FontData

Source§

fn clone(&self) -> FontData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FontData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V