PoDoFo  1.0.0-dev
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
PoDoFo::PdfFont Class Referenceabstract

Before you can draw text on a PDF document, you have to create a font object first. More...

#include <PdfFont.h>

Inheritance diagram for PoDoFo::PdfFont:
PoDoFo::PdfFontCID PoDoFo::PdfFontSimple PoDoFo::PdfFontCIDCFF PoDoFo::PdfFontCIDTrueType PoDoFo::PdfFontTrueType PoDoFo::PdfFontType1 PoDoFo::PdfFontType3

Public Member Functions

bool TryCreateSubstituteFont (PdfFont *&substFont) const
 Try get a replacement font based on this font characteristics. More...
 
bool TryCreateSubstituteFont (PdfFontCreateFlags initFlags, PdfFont *&substFont) const
 
void WriteStringToStream (OutputStream &stream, const std::string_view &str) const
 Write a string to a PdfObjectStream in a format so that it can be used with this font. More...
 
unsigned GetGID (char32_t codePoint, PdfGlyphAccess access) const
 Get the GID by the codePoint. More...
 
bool TryGetGID (char32_t codePoint, PdfGlyphAccess access, unsigned &gid) const
 
double GetStringLength (const std::string_view &str, const PdfTextState &state) const
 Retrieve the width of a given text string in PDF units when drawn with the current font. More...
 
bool TryGetStringLength (const std::string_view &str, const PdfTextState &state, double &width) const
 
double GetEncodedStringLength (const PdfString &encodedStr, const PdfTextState &state) const
 Retrieve the width of a given encoded PdfString in PDF units when drawn with the current font. More...
 
bool TryGetEncodedStringLength (const PdfString &encodedStr, const PdfTextState &state, double &length) const
 
bool TryScanEncodedString (const PdfString &encodedStr, const PdfTextState &state, std::string &utf8str, std::vector< double > &lengths, std::vector< unsigned > &positions) const
 Scan string decoding unicode codepoints and obtaining glyphs lengths. More...
 
double GetWordSpacingLength (const PdfTextState &state) const
 
double GetSpaceCharLength (const PdfTextState &state) const
 
double GetCharLength (char32_t codePoint, const PdfTextState &state, bool ignoreCharSpacing=false) const
 
bool TryGetCharLength (char32_t codePoint, const PdfTextState &state, bool ignoreCharSpacing, double &width) const
 
bool TryGetCharLength (char32_t codePoint, const PdfTextState &state, double &width) const
 
double GetDefaultCharLength (const PdfTextState &state, bool ignoreCharSpacing=false) const
 
void AddSubsetGIDs (const PdfString &encodedStr)
 Split the given string by white spaces. More...
 
double GetLineSpacing (const PdfTextState &state) const
 Retrieve the line spacing for this font. More...
 
double GetUnderlineThickness (const PdfTextState &state) const
 Get the width of the underline for the current font size in PDF units. More...
 
double GetUnderlinePosition (const PdfTextState &state) const
 Return the position of the underline for the current font size in PDF units. More...
 
double GetStrikeThroughPosition (const PdfTextState &state) const
 Return the position of the strikethrough for the current font size in PDF units. More...
 
double GetStrikeThroughThickness (const PdfTextState &state) const
 Get the width of the strikethrough for the current font size in PDF units. More...
 
double GetAscent (const PdfTextState &state) const
 Get the ascent of this font in PDF units for the current font size. More...
 
double GetDescent (const PdfTextState &state) const
 Get the descent of this font in PDF units for the current font size. More...
 
virtual bool SupportsSubsetting () const
 
virtual PdfFontType GetType () const =0
 
bool IsStandard14Font () const
 
bool IsStandard14Font (PdfStandard14FontType &std14Font) const
 
bool IsCIDKeyed () const
 True if the font is CID keyed.
 
virtual bool IsObjectLoaded () const
 True if the font is loaded from a PdfObject.
 
bool IsSubsettingEnabled () const
 Check if this is a subsetting font. More...
 
bool IsEmbeddingEnabled () const
 
const std::string & GetSubsetPrefix () const
 
const PdfEncodingGetEncoding () const
 Returns a reference to the fonts encoding. More...
 
const PdfFontMetricsGetMetrics () const
 Returns a handle to the fontmetrics object of this font. More...
 
const std::string & GetName () const
 Get the base font name of this font. More...
 
const UsedGIDsMap & GetUsedGIDs () const
 
PdfObjectGetDescendantFontObject ()
 

Static Public Member Functions

static bool TryCreateFromObject (PdfObject &obj, std::unique_ptr< PdfFont > &font)
 Create a new PdfFont from an existing font in a PDF file. More...
 
static bool TryCreateFromObject (const PdfObject &obj, std::unique_ptr< const PdfFont > &font)
 
static std::string_view GetStandard14FontName (PdfStandard14FontType stdFont)
 
static bool IsStandard14Font (const std::string_view &fontName, PdfStandard14FontType &stdFont)
 Determine if font name is a Standard14 font. More...
 
static bool IsStandard14Font (const std::string_view &fontName, bool useAltNames, PdfStandard14FontType &stdFont)
 Determine if font name is a Standard14 font. More...
 

Protected Member Functions

void EmbedFontFile (PdfObject &descriptor)
 
void EmbedFontFileType1 (PdfObject &descriptor, const bufferview &data, unsigned length1, unsigned length2, unsigned length3)
 
void EmbedFontFileCFF (PdfObject &descriptor, const bufferview &data)
 
void EmbedFontFileTrueType (PdfObject &descriptor, const bufferview &data)
 
void EmbedFontFileOpenType (PdfObject &descriptor, const bufferview &data)
 
virtual bool tryMapCIDToGID (unsigned cid, unsigned &gid) const
 
double GetCIDLengthRaw (unsigned cid) const
 Get the raw width of a CID identifier.
 
void GetBoundingBox (PdfArray &arr) const
 
void FillDescriptor (PdfDictionary &dict) const
 Fill the /FontDescriptor object dictionary.
 
virtual PdfObjectgetDescendantFontObject ()
 
virtual void initImported ()
 Initialization tasks for imported/created from scratch fonts.
 
virtual void embedFont ()
 
virtual void embedFontSubset ()
 

Protected Attributes

PdfFontMetricsConstPtr m_Metrics
 
std::unique_ptr< PdfEncodingm_Encoding
 
std::shared_ptr< PdfCharCodeMapm_DynamicCIDMap
 
std::shared_ptr< PdfCharCodeMapm_DynamicToUnicodeMap
 

Friends

class PdfFontSimple
 
class PdfFontCID
 
class PdfFontFactory
 
class PdfFontObject
 
class PdfEncoding
 
class PdfFontManager
 

Detailed Description

Before you can draw text on a PDF document, you have to create a font object first.

You can reuse this font object as often as you want.

Use methods in PdfFontManager, which you can access with PdfDocument::GetFonts(), to retrieve a font object.

This is only an abstract base class which is implemented for different font formats.

Member Function Documentation

◆ AddSubsetGIDs()

void PdfFont::AddSubsetGIDs ( const PdfString encodedStr)

Split the given string by white spaces.

Remarks
Also return separator chunks Add used GIDs to this font for subsetting from an encoded string

If the subsetting is not enabled it's a no-op

◆ GetAscent()

double PdfFont::GetAscent ( const PdfTextState &  state) const

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

Returns
the ascender for this font
See also
GetAscent

◆ GetCharLength()

double PdfFont::GetCharLength ( char32_t  codePoint,
const PdfTextState &  state,
bool  ignoreCharSpacing = false 
) const
Remarks
Doesn't throw if character glyph could not be found

◆ GetDescent()

double PdfFont::GetDescent ( const PdfTextState &  state) const

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

◆ GetEncodedStringLength()

double PdfFont::GetEncodedStringLength ( const PdfString encodedStr,
const PdfTextState &  state 
) const

Retrieve the width of a given encoded PdfString in PDF units when drawn with the current font.

Parameters
viewa text string of which the width should be calculated
Returns
the width in PDF units
Remarks
Doesn't throw if string glyphs could not be partially or totally found

◆ GetEncoding()

const PdfEncoding& PoDoFo::PdfFont::GetEncoding ( ) const
inline

Returns a reference to the fonts encoding.

Returns
a PdfEncoding object.

◆ GetGID()

unsigned PdfFont::GetGID ( char32_t  codePoint,
PdfGlyphAccess  access 
) const

Get the GID by the codePoint.

Parameters
codePointunicode codepoint
Returns
the GID
Remarks
throw if not found

◆ GetLineSpacing()

double PdfFont::GetLineSpacing ( const PdfTextState &  state) const

Retrieve the line spacing for this font.

Returns
the linespacing in PDF units

◆ GetMetrics()

const PdfFontMetrics& PoDoFo::PdfFont::GetMetrics ( ) const
inline

Returns a handle to the fontmetrics object of this font.

This can be used for size calculations of text strings when drawn using this font.

Returns
a handle to the font metrics object

◆ GetName()

const std::string& PoDoFo::PdfFont::GetName ( ) const
inline

Get the base font name of this font.

Returns
the font name, usually the /BaseFont key of a type1 or type0 font, or the /FontName in a font descriptor

◆ GetSpaceCharLength()

double PdfFont::GetSpaceCharLength ( const PdfTextState &  state) const
Returns
The space char length
Remarks
This differs from GetWordSpacingLength() as this will be used to visually represent a space, while word spacing length will be used to determine words splitting

◆ GetStrikeThroughPosition()

double PdfFont::GetStrikeThroughPosition ( const PdfTextState &  state) const

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

Returns
the strikethrough position in PDF units

◆ GetStrikeThroughThickness()

double PdfFont::GetStrikeThroughThickness ( const PdfTextState &  state) const

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

Returns
the thickness of the strikethrough in PDF units

◆ GetStringLength()

double PdfFont::GetStringLength ( const std::string_view &  str,
const PdfTextState &  state 
) const

Retrieve the width of a given text string in PDF units when drawn with the current font.

Parameters
stra utf8 string of which the width should be calculated
Returns
the width in PDF units
Remarks
Doesn't throw if string glyphs could not be partially or totally found

◆ GetSubsetPrefix()

const std::string& PoDoFo::PdfFont::GetSubsetPrefix ( ) const
inline
Returns
empty string or a 6 uppercase letter and "+" sign prefix used for font subsets

◆ GetUnderlinePosition()

double PdfFont::GetUnderlinePosition ( const PdfTextState &  state) const

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

Returns
the underline position in PDF units

◆ GetUnderlineThickness()

double PdfFont::GetUnderlineThickness ( const PdfTextState &  state) const

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

Returns
the thickness of the underline in PDF units

◆ GetWordSpacingLength()

double PdfFont::GetWordSpacingLength ( const PdfTextState &  state) const
Returns
The word spacing length
Remarks
This differs from GetSpaceCharLength() as this will be used to determine words splitting, while space char length will be used to visually represent a space

◆ IsStandard14Font() [1/2]

static bool PoDoFo::PdfFont::IsStandard14Font ( const std::string_view &  fontName,
bool  useAltNames,
PdfStandard14FontType &  stdFont 
)
static

Determine if font name is a Standard14 font.

Parameters
fontNamethe unprocessed font name

◆ IsStandard14Font() [2/2]

static bool PoDoFo::PdfFont::IsStandard14Font ( const std::string_view &  fontName,
PdfStandard14FontType &  stdFont 
)
static

Determine if font name is a Standard14 font.

By default use both standard names and alternative ones (Arial, TimesNewRoman, CourierNew)

Parameters
fontNamethe unprocessed font name

◆ IsSubsettingEnabled()

bool PoDoFo::PdfFont::IsSubsettingEnabled ( ) const
inline

Check if this is a subsetting font.

Returns
true if this is a subsetting font

◆ TryCreateFromObject()

static bool PoDoFo::PdfFont::TryCreateFromObject ( PdfObject obj,
std::unique_ptr< PdfFont > &  font 
)
static

Create a new PdfFont from an existing font in a PDF file.

Parameters
obja PDF font object
fontthe created font object

◆ TryCreateSubstituteFont()

bool PdfFont::TryCreateSubstituteFont ( PdfFont *&  substFont) const

Try get a replacement font based on this font characteristics.

Parameters
substFontthe created substitute font

◆ TryGetEncodedStringLength()

bool PdfFont::TryGetEncodedStringLength ( const PdfString encodedStr,
const PdfTextState &  state,
double &  length 
) const
Remarks
Produces a partial result also in case of failures

◆ TryGetStringLength()

bool PdfFont::TryGetStringLength ( const std::string_view &  str,
const PdfTextState &  state,
double &  width 
) const
Parameters
stra utf8 string of which the width should be calculated
Remarks
Produces a partial result also in case of failures

◆ TryScanEncodedString()

bool PdfFont::TryScanEncodedString ( const PdfString encodedStr,
const PdfTextState &  state,
std::string &  utf8str,
std::vector< double > &  lengths,
std::vector< unsigned > &  positions 
) const

Scan string decoding unicode codepoints and obtaining glyphs lengths.

Parameters
lengthslengths of the glyphs
positionsposition of the CIDs in the utf8string
Remarks
Produces a partial result also in case of failures

◆ WriteStringToStream()

void PdfFont::WriteStringToStream ( OutputStream stream,
const std::string_view &  str 
) const

Write a string to a PdfObjectStream in a format so that it can be used with this font.

This is used by PdfPainter::DrawText to display a text string. The following PDF operator will be Tj

Parameters
streamthe string will be appended to stream without any leading or following whitespaces.
stra unicode or ansi string which will be displayed

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