PoDoFo 0.9.20
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
PoDoFo::PdfFont Class Referenceabstract

#include <PdfFont.h>

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

Public Member Functions

bool TryGetSubstituteFont (PdfFont *&substFont) const
 
void WriteStringToStream (OutputStream &stream, const std::string_view &str) const
 
unsigned GetGID (char32_t codePoint, PdfGlyphAccess access) const
 
double GetStringLength (const std::string_view &str, const PdfTextState &state) const
 
bool TryGetStringLength (const std::string_view &str, const PdfTextState &state, double &width) const
 
double GetEncodedStringLength (const PdfString &encodedStr, const PdfTextState &state) const
 
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
 
double GetWordSpacingLength (const PdfTextState &state) const
 
double GetCharLength (char32_t codePoint, const PdfTextState &state, bool ignoreCharSpacing=false) const
 
void AddSubsetGIDs (const PdfString &encodedStr)
 
double GetLineSpacing (const PdfTextState &state) const
 
double GetUnderlineThickness (const PdfTextState &state) const
 
double GetUnderlinePosition (const PdfTextState &state) const
 
double GetStrikeThroughPosition (const PdfTextState &state) const
 
double GetStrikeThroughThickness (const PdfTextState &state) const
 
double GetAscent (const PdfTextState &state) const
 
double GetDescent (const PdfTextState &state) const
 
bool IsCIDKeyed () const
 
virtual bool IsObjectLoaded () const
 
bool IsSubsettingEnabled () const
 
const std::string & GetSubsetPrefix () const
 
const PdfNameGetIdentifier () const
 
const PdfEncodingGetEncoding () const
 
const PdfFontMetricsGetMetrics () const
 
const std::string & GetName () const
 

Static Public Member Functions

static bool TryCreateFromObject (PdfObject &obj, std::unique_ptr< PdfFont > &font)
 
static bool IsStandard14Font (const std::string_view &fontName, PdfStandard14FontType &stdFont)
 
static bool IsStandard14Font (const std::string_view &fontName, bool useAltNames, PdfStandard14FontType &stdFont)
 

Protected Member Functions

 PdfFont (PdfDocument &doc, const PdfFontMetricsConstPtr &metrics, const PdfEncoding &encoding)
 
double GetCIDLengthRaw (unsigned cid) const
 
void FillDescriptor (PdfDictionary &dict) const
 
virtual void initImported ()
 

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 PdfDocument::CreateFont to create a new font object. It will choose a correct subclass using PdfFontFactory.

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

Constructor & Destructor Documentation

◆ PdfFont()

PdfFont::PdfFont ( PdfDocument doc,
const PdfFontMetricsConstPtr metrics,
const PdfEncoding encoding 
)
protected

Create a new PdfFont object which will introduce itself automatically to every page object it is used on.

Parameters
parentparent of the font object
metricspointer to a font metrics object. The font in the PDF file will match this fontmetrics object. The metrics object is deleted along with the font.
encodingthe encoding of this font

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

◆ FillDescriptor()

void PdfFont::FillDescriptor ( PdfDictionary dict) const
protected

Fill the /FontDescriptor object dictionary

◆ 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 characater glyph could not be found

◆ GetCIDLengthRaw()

double PdfFont::GetCIDLengthRaw ( unsigned  cid) const
protected

Get the raw width of a CID identifier

◆ 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

◆ GetIdentifier()

const PdfName & PoDoFo::PdfFont::GetIdentifier ( ) const
inline

Returns the identifier of this font how it is known in the pages resource dictionary.

Returns
PdfName containing the identifier (e.g. /Ft13)

◆ 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

◆ 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 spacing width

◆ initImported()

void PdfFont::initImported ( )
protectedvirtual

Inititialization tasks for imported/created from scratch fonts

Reimplemented in PoDoFo::PdfFontCID, and PoDoFo::PdfFontSimple.

◆ IsCIDKeyed()

bool PdfFont::IsCIDKeyed ( ) const

True if the font is CID keyed

◆ IsObjectLoaded()

bool PdfFont::IsObjectLoaded ( ) const
virtual

True if the font is loaded from a PdfObject

◆ 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()

bool 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

◆ 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

◆ TryGetSubstituteFont()

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

Try get a replacement font based on this font characteristics

Parameters
substFontthe created substitute font

◆ 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