Font Class Documentation

class Font

Namespace:datalogics_interface

Detailed Description

Represents a font. Defines the typeface, size, style (bold, italic), Unicode values, and other details.

The Font class represents a font installed on the system.

Constructor & Destructor Documentation

Font

Font(const std::string & font_name)

Parameters

font_name: const std::string &

Default constructor.

Direct construction is prohibited.

Font

Font(const std::string & font_name, FontCreateFlags flags)

Parameters

font_name: const std::string &

Default constructor.

Direct construction is prohibited.

~Font

~Font()

Member Function Documentation

embed_now

void embed_now(Document & doc)

Parameters

doc: Document &

the Document the Font is embedded into

Returns:

void

Embeds the Font.

find_index_of_first_unrepresentable_char

unsigned int find_index_of_first_unrepresentable_char(const std::string & text)

Parameters

text: const std::string &

the text to check

Returns:

unsigned int

The index of the first character that cannot be represented in this font.

Find the index of the first character that cannot be represented in this font. This will return the index of the first character in the string for which the font has no glyph. If all characters can be represented (i.e. if IsTextRepresentable() would return true), this will return the length of the string.

get_ascent

double get_ascent()

Returns:

double

The Ascent value of the font in glyph space units.

the Ascent value from the font descriptor. This is the maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters.

get_avg_width

double get_avg_width()

Returns:

double

The AvgWidth value of the font in glyph space units, or 0 if not defined.

the AvgWidth value from the font descriptor. This is the average width of glyphs in the font, or 0 if the value is not defined in the font descriptor.

get_bbox

Rect get_bbox()

Returns:

Rect

The bounding box of the font as a Rect, in glyph space units.

The Bounding Box rectangle of the font.

get_cap_height

double get_cap_height()

Returns:

double

The CapHeight value of the font in glyph space units, or 0 if not defined.

the CapHeight value from the font descriptor. This is the vertical coordinate of the top of flat capital letters, measured from the baseline, or 0 if the value is not defined in the font descriptor.

get_cid_font_type

std::string get_cid_font_type()

Returns:

std::string

The CID font type, or an empty string if not a CID font.

Get the CID font type of the font.

get_descent

double get_descent()

Returns:

double

The descent value of the font.

the Descent value from the font descriptor. This is the maximum depth below the baseline reached by glyphs in this font. The value is a negative number.

get_embedded

bool get_embedded()

Returns:

bool

true if the font is embedded, false if it is not.

Tests whether the font is embedded in the document it was created for.

get_encoding

std::string get_encoding()

Returns:

std::string

The encoding of the font, eg: WinAnsiEncoding MacRomanEncoding

Return the encoding of the font.

For a font created from a system font by name, this is the encoding PDFL gives the font when it is written to a document: WinAnsiEncoding on Windows and Linux, MacRomanEncoding on macOS, or Identity-H/V for a Type0 font. Symbolic fonts (Symbol, ZapfDingbats, Wingdings) use their own built-in encoding and return an empty string.

get_flags

FontFlags get_flags()

Returns:

FontFlags

The font descriptor flags as a CFontFlags bitmask.

Get the font flags for a font.

get_full_name

std::string get_full_name()

Returns:

std::string

The Full Name of the font. Note: This method only returns a meaningful result for TrueType-based technology fonts.

Get the Full Name of the font.

get_glyph_widths

std::vector< double > get_glyph_widths()

Returns:

std::vector< double >

256 glyph advances in 1000-em character-space units.

Retrieve the glyph width table for the font's single-byte encoding.

Retrieve the 256-entry glyph width table for this font's single-byte encoding. Values are in character-space units (1000 per em); for the user-space width of character code c at font size s use widths[c] * s / 1000.0. Only meaningful for simple single-byte fonts; CID/Type-0 fonts should use measure_text_width.

Returns the 256-entry glyph advance table in character-space units (1000 units per em). For the user-space width of character code c at font size s: widths[c] * s / 1000.0.

The returned vector always has 256 entries; positions outside the font's defined encoding are filled with whatever advance the font reports for unmapped codes (typically zero or the missing-glyph advance). This API is therefore only meaningful for simple single-byte fonts — Type 1, TrueType with a simple encoding, etc. CID / Type 0 fonts need per-glyph measurement via MeasureTextWidth instead.

get_italic_angle

double get_italic_angle()

Returns:

double

The ItalicAngle value of the font in degrees.

the ItalicAngle value from the font descriptor. This is the angle, expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font, defined in the font descriptor.

get_leading

double get_leading()

Returns:

double

The leading value of the font, or 0 if not present.

the Leading value from the font descriptor. This is the spacing between baselines of consecutive lines of text, or 0 if the value is not defined in the font descriptor.

get_max_width

double get_max_width()

Returns:

double

The MaxWidth value of the font in glyph space units, or 0 if not present.

the MaxWidth value from the font descriptor. This is the maximum glyph width present in the font, or 0 if the value is not defined in the font descriptor.

get_missing_width

double get_missing_width()

Returns:

double

The MissingWidth value of the font in glyph space units, or 0 if not present.

the MissingWidth value from the font descriptor. This is the width given to characters that do not have corresponding glyphs defined in the font, or 0 if the value is not defined in the font descriptor.

get_name

std::string get_name()

Returns:

std::string

The name of the font.

Get the name of the font.

get_pdf_dict

PDFDict get_pdf_dict()

Returns:

PDFDict

The PDFDict for this font's COS dictionary object.

Retrieve the PDFDict representation of this font.

get_stem_h

double get_stem_h()

Returns:

double

The StemH value of the font in glyph space units, or 0 if not present.

the StemH value from the font descriptor. This is the vertical thickness of the dominant horizontal stems of the font's glyphs, or 0 if the value is not defined in the font descriptor.

get_stem_v

double get_stem_v()

Returns:

double

The StemV value of the font in glyph space units, or 0 if not present.

the StemV value from the font descriptor. This is the horizontal thickness of the dominant vertical stems of the font's glyphs, or 0 if the value is not defined in the font descriptor.

get_type

std::string get_type()

Returns:

std::string

The type of the font. Type0 Type1 MMType1 TrueType

Get the type of the font.

get_writing_mode

WritingMode get_writing_mode()

Returns:

WritingMode

The WritingMode of the font.

Get the writing mode of the font. The writing mode of the fontwhether it will place glyphs horizontally or vertically. Text written with this font will run in the direction of the writing mode.

get_x_height

double get_x_height()

Returns:

double

The XHeight value of the font in glyph space units, or 0 if not present.

the XHeight value from the font descriptor. This is the vertical coordinate of the top of flat nonascending lowercase letters in fonts that have Latin characters, as measured from the baseline, or 0 if the value is not defined in the font descriptor.

is_from_doc

bool is_from_doc()

Returns:

bool

true if the font was loaded from a document, false if it was created from a system font.

Determine whether this font was obtained from an existing document rather than the system.

is_text_representable

bool is_text_representable(const std::string & text)

Parameters

text: const std::string &

the text to check

Returns:

bool

true if all characters in the text have corresponding glyphs in this font.

Is this text representable in this font?

measure_text_width

double measure_text_width(const std::string & text, double font_size)

Parameters

text: const std::string &

the Text to be measured

font_size: double

the Font size to be used

Returns:

double

The width of the text in points.

Measures the width of the specified text in points, using the Font at the specified size.