PoDoFo 1.0.0-dev
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
PoDoFo::PdfFontMetrics Class Referenceabstract

This abstract class provides access to font metrics information. More...

#include <PdfFontMetrics.h>

Inherited by PoDoFo::PdfFontMetricsBase, and PoDoFo::PdfFontMetricsFreetype.

Public Member Functions

unsigned GetGlyphCount () const
 Get the glyph count.
 
unsigned GetGlyphCount (PdfGlyphAccess access) const
 Get the glyph count with the given glyph access.
 
double GetGlyphWidth (unsigned gid) const
 Get the width of a single glyph id.
 
bool TryGetGlyphWidth (unsigned gid, double &width) const
 
double GetGlyphWidth (unsigned gid, PdfGlyphAccess access) const
 Get the width of a single glyph id.
 
bool TryGetGlyphWidth (unsigned gid, PdfGlyphAccess access, double &width) const
 
virtual void SubstituteGIDs (std::vector< unsigned > &gids, std::vector< unsigned char > &backwardMap) const
 Some fonts provides a glyph substitution list, eg.
 
virtual bool HasUnicodeMapping () const =0
 Determines if the metrics has a valid Unicode code point to gid map.
 
virtual bool TryGetGID (char32_t codePoint, unsigned &gid) const =0
 Try to retrieve the mapped gid from Unicode code point.
 
virtual double GetLineSpacing () const =0
 Retrieve the line spacing for this font.
 
virtual double GetUnderlineThickness () const =0
 Get the width of the underline for the current font size in PDF units.
 
virtual double GetUnderlinePosition () const =0
 Return the position of the underline for the current font size in PDF units.
 
virtual double GetStrikeThroughPosition () const =0
 Return the position of the strikethrough for the current font size in PDF units.
 
virtual double GetStrikeThroughThickness () const =0
 Get the width of the strikethrough for the current font size in PDF units.
 
virtual PdfFontFileType GetFontFileType () const =0
 
bool HasFontFileData () const
 
bufferview GetOrLoadFontFileData () const
 Get an actual font data view.
 
virtual const PdfObjectGetFontFileObject () const
 Get the actual font file object from a /FontFile like key, if available.
 
virtual unsigned GetFontFileLength1 () const =0
 Get /Length1 value for the font file, if available.
 
virtual unsigned GetFontFileLength2 () const =0
 Get /Length2 value for the font file, if available.
 
virtual unsigned GetFontFileLength3 () const =0
 Get /Length3 value for the font file, if available.
 
virtual std::string_view GetFontName () const =0
 Get the actual /FontName, eg.
 
virtual std::string_view GetFontNameRaw () const
 Get the actual /FontName, eg.
 
virtual std::string_view GetFontFamilyName () const =0
 Get the actual /FontFamily, eg.
 
std::string_view GeFontFamilyNameSafe () const
 Get a family font name, either from /FontFamily or constructed from available /BaseFont, /FontName (eg.
 
virtual unsigned char GetSubsetPrefixLength () const
 Get the length of the subset prefix (eg.
 
std::string_view GetPostScriptNameRough () const
 Get a an approximate PostScript name, from available /BaseFont, /FontName (eg.
 
virtual PdfFontStretch GetFontStretch () const =0
 
unsigned GetWeight () const
 Get the weight of this font.
 
virtual int GetWeightRaw () const =0
 
virtual bool TryGetFlags (PdfFontDescriptorFlags &value) const =0
 
PdfFontDescriptorFlags GetFlags () const
 
virtual bool TryGetBoundingBox (Corners &value) const =0
 Create the bounding box vector in PDF units.
 
Corners GetBoundingBox () const
 
virtual bool TryGetItalicAngle (double &value) const =0
 Get the italic angle of this font.
 
double GetItalicAngle () const
 
virtual bool TryGetAscent (double &value) const =0
 Get the ascent of this font in PDF units for the current font size.
 
double GetAscent () const
 
virtual bool TryGetDescent (double &value) const =0
 Get the descent of this font in PDF units for the current font size.
 
double GetDescent () const
 
virtual bool TryGetCapHeight (double &value) const =0
 The vertical coordinate of the top of flat capital letters, measured from the baseline.
 
double GetCapHeight () const
 
virtual bool TryGetStemV (double &value) const =0
 The thickness, measured horizontally, of the dominant vertical stems of glyphs in the font.
 
double GetStemV () const
 
double GetLeading () const
 
virtual double GetLeadingRaw () const =0
 
double GetXHeight () const
 The font’s x height: the vertical coordinate of the top of flat nonascending lowercase letters (like the letter x), measured from the baseline, in fonts that have Latin characters (optional, default 0)
 
virtual double GetXHeightRaw () const =0
 
double GetStemH () const
 The thickness, measured vertically, of the dominant horizontal stems of glyphs in the font (optional, default 0)
 
virtual double GetStemHRaw () const =0
 
double GetAvgWidth () const
 /AvgWidth (optional, default 0)
 
virtual double GetAvgWidthRaw () const =0
 
double GetMaxWidth () const
 /MaxWidth (optional, default 0)
 
virtual double GetMaxWidthRaw () const =0
 
double GetDefaultWidth () const
 /MissingWidth or /DW in CID fonts (optional default 1000 in CID fonts, 0 otherwise)
 
virtual double GetDefaultWidthRaw () const =0
 
PdfFontStyle GetStyle () const
 Get whether the font style is bold.
 
virtual bool IsObjectLoaded () const
 
bool IsStandard14FontMetrics () const
 
virtual bool IsStandard14FontMetrics (PdfStandard14FontType &std14Font) const
 
virtual const Matrix & GetMatrix () const
 Returns the matrix mapping glyph space to text space.
 
bool IsType1Kind () const
 Determine if the metrics are for Adobe Type1 like font.
 
bool IsTrueTypeKind () const
 Determine if the metrics are TrueType like font.
 
bool IsPdfSymbolic () const
 Determine if the font is non symbolic according to the PDF definition.
 
bool IsPdfNonSymbolic () const
 Determine if the font is symbolic according to the PDF definition.
 
virtual std::unique_ptr< PdfCMapEncoding > CreateToUnicodeMap (const PdfEncodingLimits &limitHints) const
 Create a best effort /ToUnicode map based on the character unicode maps of the font.
 
bool TryGetImplicitEncoding (PdfEncodingMapConstPtr &encoding) const
 Get an implicit encoding, such as the one of standard14 fonts, or the built-in encoding of a Type1 font, if available.
 
PdfCIDToGIDMapConstPtr GetCIDToGIDMap () const
 Get a CID to font program GID map.
 
const std::string & GetFilePath () const
 
unsigned GetFaceIndex () const
 

Static Public Member Functions

static std::unique_ptr< const PdfFontMetricsCreate (const std::string_view &filepath, unsigned faceIndex=0)
 
static std::unique_ptr< const PdfFontMetricsCreateFromBuffer (const bufferview &buffer, unsigned faceIndex=0)
 

Protected Member Functions

virtual std::string_view GetBaseFontName () const =0
 Get a semantical base name for the font that can be used to compose the final name, eg.
 
virtual const PdfCIDToGIDMapConstPtr & getCIDToGIDMap () const
 
virtual bool getIsBoldHint () const =0
 
virtual bool getIsItalicHint () const =0
 
virtual const datahandleGetFontFileDataHandle () const =0
 
virtual FT_Face GetFaceHandle () const =0
 
virtual unsigned GetGlyphCountFontProgram () const
 
virtual bool TryGetGlyphWidthFontProgram (unsigned gid, double &width) const
 
bool HasParsedWidths () const
 
GlyphMetricsListConstPtr GetParsedWidths () const
 Retrieve the parsed width from a /W or /Widths entry, if available.
 
void SetParsedWidths (GlyphMetricsListConstPtr &&parsedWidths)
 

Friends

class PdfFont
 
class PdfFontManager
 
class PdfFontMetricsBase
 
class PdfFontMetricsFreetype
 

Detailed Description

This abstract class provides access to font metrics information.

The class doesn't know anything about CIDs (Character IDs), it just index glyphs, or GIDs where the terminology applies

Member Function Documentation

◆ CreateToUnicodeMap()

unique_ptr< PdfCMapEncoding > PdfFontMetrics::CreateToUnicodeMap ( const PdfEncodingLimits &  limitHints) const
virtual

Create a best effort /ToUnicode map based on the character unicode maps of the font.

This is implemented just for PdfFontMetricsFreetype This map may be unreliable because of ligatures, other kind of character substitutions, or glyphs mapping to multiple unicode codepoints.

◆ GeFontFamilyNameSafe()

string_view PdfFontMetrics::GeFontFamilyNameSafe ( ) const

Get a family font name, either from /FontFamily or constructed from available /BaseFont, /FontName (eg.

"AAAAAA+Arial,Bold" becomes "Arial")

Remarks
It doesn't correspond to /BaseFont name entry in the font

◆ GetBaseFontName()

virtual std::string_view PoDoFo::PdfFontMetrics::GetBaseFontName ( ) const
protectedpure virtual

Get a semantical base name for the font that can be used to compose the final name, eg.

from "AAAAAA+Arial,Bold" to "Arial"

Remarks
It doesn't correspond to /BaseFont name entry in the font

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetFontFamilyName()

virtual std::string_view PoDoFo::PdfFontMetrics::GetFontFamilyName ( ) const
pure virtual

Get the actual /FontFamily, eg.

"Times", if available

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetFontFileLength1()

virtual unsigned PoDoFo::PdfFontMetrics::GetFontFileLength1 ( ) const
pure virtual

Get /Length1 value for the font file, if available.

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetFontFileLength2()

virtual unsigned PoDoFo::PdfFontMetrics::GetFontFileLength2 ( ) const
pure virtual

Get /Length2 value for the font file, if available.

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetFontFileLength3()

virtual unsigned PoDoFo::PdfFontMetrics::GetFontFileLength3 ( ) const
pure virtual

Get /Length3 value for the font file, if available.

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetFontFileObject()

const PdfObject * PdfFontMetrics::GetFontFileObject ( ) const
virtual

Get the actual font file object from a /FontFile like key, if available.

For font data coming from a file imported font, see GetFontFileData()

Returns
a binary buffer of data containing the font data

◆ GetFontName()

virtual std::string_view PoDoFo::PdfFontMetrics::GetFontName ( ) const
pure virtual

Get the actual /FontName, eg.

"AAAAAA+Arial,Bold", if available

By default returns empty string

Returns
the postscript name of the font or empty string if no postscript name is available.

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetFontNameRaw()

string_view PdfFontMetrics::GetFontNameRaw ( ) const
virtual

Get the actual /FontName, eg.

"AAAAAA+Arial,Bold", if available By default returns GetFontName()

◆ GetGlyphCount() [1/2]

unsigned PdfFontMetrics::GetGlyphCount ( ) const

Get the glyph count.

Remarks
By defaults tt returns the actual number of glyphs in the font program

◆ GetGlyphCount() [2/2]

unsigned PdfFontMetrics::GetGlyphCount ( PdfGlyphAccess  access) const

Get the glyph count with the given glyph access.

Parameters
accessthe desired access for retrieving the glyph count

◆ GetGlyphWidth() [1/2]

double PdfFontMetrics::GetGlyphWidth ( unsigned  gid) const

Get the width of a single glyph id.

It tries to access parsed pdf metrics first, and if unavailable it retrieve it from available font program

Parameters
gidid of the glyph
Returns
the width of a single glyph id

◆ GetGlyphWidth() [2/2]

double PdfFontMetrics::GetGlyphWidth ( unsigned  gid,
PdfGlyphAccess  access 
) const

Get the width of a single glyph id.

Parameters
gidid of the glyph
accessthe desired access for retrieving the metrics
Returns
the width of a single glyph id

◆ GetLineSpacing()

virtual double PoDoFo::PdfFontMetrics::GetLineSpacing ( ) const
pure virtual

Retrieve the line spacing for this font.

Returns
the linespacing in PDF units

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetOrLoadFontFileData()

bufferview PdfFontMetrics::GetOrLoadFontFileData ( ) const

Get an actual font data view.

The data shall be resident. For font coming from the /FontFile keys, GetFontFileObject() may also be available.

Returns
a binary buffer of data containing the font data

◆ GetPostScriptNameRough()

string_view PdfFontMetrics::GetPostScriptNameRough ( ) const

Get a an approximate PostScript name, from available /BaseFont, /FontName (eg.

"AAAAAA+Arial-Bold" becomes "Arial-Bold") By default returns GetFontName()

◆ GetStrikeThroughPosition()

virtual double PoDoFo::PdfFontMetrics::GetStrikeThroughPosition ( ) const
pure virtual

Return the position of the strikethrough for the current font size in PDF units.

Returns
the strikethrough position in PDF units

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetStrikeThroughThickness()

virtual double PoDoFo::PdfFontMetrics::GetStrikeThroughThickness ( ) const
pure virtual

Get the width of the strikethrough for the current font size in PDF units.

Returns
the thickness of the strikethrough in PDF units

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetStyle()

PdfFontStyle PdfFontMetrics::GetStyle ( ) const

Get whether the font style is bold.

This is a logical value that can be inferred from several characteristics

◆ GetSubsetPrefixLength()

unsigned char PdfFontMetrics::GetSubsetPrefixLength ( ) const
virtual

Get the length of the subset prefix (eg.

7 for "AAAAAA+") if present

◆ GetUnderlinePosition()

virtual double PoDoFo::PdfFontMetrics::GetUnderlinePosition ( ) const
pure virtual

Return the position of the underline for the current font size in PDF units.

Returns
the underline position in PDF units

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetUnderlineThickness()

virtual double PoDoFo::PdfFontMetrics::GetUnderlineThickness ( ) const
pure virtual

Get the width of the underline for the current font size in PDF units.

Returns
the thickness of the underline in PDF units

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ GetWeight()

unsigned PdfFontMetrics::GetWeight ( ) const

Get the weight of this font.

Returns
the weight of this font (400 <= x < 700 means normal, x >= 700 means bold)

◆ HasUnicodeMapping()

virtual bool PoDoFo::PdfFontMetrics::HasUnicodeMapping ( ) const
pure virtual

Determines if the metrics has a valid Unicode code point to gid map.

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ IsPdfNonSymbolic()

bool PdfFontMetrics::IsPdfNonSymbolic ( ) const

Determine if the font is symbolic according to the PDF definition.

The font is symbolic if "uses the Standard Latin character set or a subset of it."

◆ IsPdfSymbolic()

bool PdfFontMetrics::IsPdfSymbolic ( ) const

Determine if the font is non symbolic according to the PDF definition.

The font is symbolic if "contains glyphs outside the Standard Latin character set"

◆ SubstituteGIDs()

void PdfFontMetrics::SubstituteGIDs ( std::vector< unsigned > &  gids,
std::vector< unsigned char > &  backwardMap 
) const
virtual

Some fonts provides a glyph substitution list, eg.

for ligatures. OpenType fonts for example provides GSUB "Glyph Substitution Table"

Parameters
gidsgids to be substituted
backwardMaplist of gid counts to remap back substituted gids eg. { 32, 102, 105 } gets substituted in { 32, 174 } the backward map is { 1, 2 }

◆ TryGetAscent()

virtual bool PoDoFo::PdfFontMetrics::TryGetAscent ( double value) const
pure virtual

Get the ascent of this font in PDF units for the current font size.

Returns
the ascender for this font
See also
GetAscent

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ TryGetBoundingBox()

virtual bool PoDoFo::PdfFontMetrics::TryGetBoundingBox ( Corners value) const
pure virtual

Create the bounding box vector in PDF units.

Parameters
bboxwrite the bounding box to this vector

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ TryGetCapHeight()

virtual bool PoDoFo::PdfFontMetrics::TryGetCapHeight ( double value) const
pure virtual

The vertical coordinate of the top of flat capital letters, measured from the baseline.

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ TryGetDescent()

virtual bool PoDoFo::PdfFontMetrics::TryGetDescent ( double value) const
pure virtual

Get the descent of this font in PDF units for the current font size.

This value is usually negative!

Returns
the descender for this font
See also
GetDescent

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ TryGetGID()

virtual bool PoDoFo::PdfFontMetrics::TryGetGID ( char32_t  codePoint,
unsigned gid 
) const
pure virtual

Try to retrieve the mapped gid from Unicode code point.

Remarks
don't use this method directly unless you know what you're doing: use PdfFont::TryGetGID instead

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ TryGetItalicAngle()

virtual bool PoDoFo::PdfFontMetrics::TryGetItalicAngle ( double value) const
pure virtual

Get the italic angle of this font.

Used to build the font dictionary

Returns
the italic angle of this font.

Implemented in PoDoFo::PdfFontMetricsStandard14.

◆ TryGetStemV()

virtual bool PoDoFo::PdfFontMetrics::TryGetStemV ( double value) const
pure virtual

The thickness, measured horizontally, of the dominant vertical stems of glyphs in the font.

Implemented in PoDoFo::PdfFontMetricsStandard14.


The documentation for this class was generated from the following files: