Foxit PDF SDK

Public Types | Public Member Functions | List of all members
foxit::common::Font Class Reference
Inheritance diagram for foxit::common::Font:

## Public Types
enum | Charset { e_CharsetANSI = 0, e_CharsetDefault = 1, e_CharsetSymbol = 2, e_CharsetShift_JIS = 128, e_CharsetHangeul = 129, e_CharsetGB2312 = 134, e_CharsetChineseBig5 = 136, e_CharsetThai = 222, e_CharsetEastEurope = 238, e_CharsetRussian = 204, e_CharsetGreek = 161, e_CharsetTurkish = 162, e_CharsetHebrew = 177, e_CharsetArabic = 178, e_CharsetBaltic = 186 }
| Enumeration for font charset. More...
enum | CIDCharset { e_CIDCharsetUnknown = 0, e_CIDCharsetGB1 = 1, e_CIDCharsetCNS1 = 2, e_CIDCharsetJAPAN1 = 3, e_CIDCharsetKOREA1 = 4, e_CIDCharsetUNICODE = 5 }
| Enumeration for CID font charset. More...
enum | FontTypes { e_FontTypeType1 = 1, e_FontTypeTrueType = 2, e_FontTypeType3 = 3, e_FontTypeCIDFont = 4 }
| Enumeration for font type. More...
enum | StandardID { e_StdIDCourier = 0, e_StdIDCourierB = 1, e_StdIDCourierBI = 2, e_StdIDCourierI = 3, e_StdIDHelvetica = 4, e_StdIDHelveticaB = 5, e_StdIDHelveticaBI = 6, e_StdIDHelveticaI = 7, e_StdIDTimes = 8, e_StdIDTimesB = 9, e_StdIDTimesBI = 10, e_StdIDTimesI = 11, e_StdIDSymbol = 12, e_StdIDZapfDingbats = 13 }
| Enumeration for standard font ID. More...
enum | Styles { e_StyleFixedPitch = 0x0001, e_StyleSerif = 0x0002, e_StyleSymbolic = 0x0004, e_StyleScript = 0x0008, e_StyleNonSymbolic = 0x0020, e_StyleItalic = 0x0040, e_StyleAllCap = 0x10000, e_StylesSmallCap = 0x20000, e_StylesBold = 0x40000 }
| Enumeration for font styles. More...

## Public Member Functions
| Font (const char *font_file_path, int face_index, Charset charset)
| Constructor, from a font file. More...
| Font (const Font &other)
| Constructor, with another font object. More...
| Font (const wchar_t *font_file_path, int face_index, Charset charset)
| Constructor, from a font file. More...
| Font (const wchar_t *name, uint32 styles, Charset charset, int weight)
| Constructor, with given attribute. More...
| Font (foxit::common::file::StreamCallback *stream)
| Constructor, from a font stream by using foxit::common::file::StreamCallback. More...
| Font (StandardID font_id)
| Constructor, by a standard font ID. More...
| ~Font ()
| Destructor.
UInt32Array | AddUnicodes (const pdf::PDFDoc &document, const UInt32Array &unicode_array)
| Add unicodes to current embedded font. More...
Font | Embed (pdf::PDFDoc document, bool is_add_all_unicodes=true)
| Embed current font to the specified PDF document. More...
int | GetAscent () const
| Get the ascent value, in 1/1000 of em size (PDF units). More...
String | GetBaseFontName (const pdf::PDFDoc &document)
| Get base font name. More...
RectI | GetCharBBox (foxit::uint32 unicode, const foxit::pdf::PDFDoc &document)
| Get the bounding box of a character(specified by unicode) in a PDF document. More...
RectI | GetCharBBox (uint32 unicode) const
| Get the bounding box of a character specified by unicode. More...
float | GetCharWidth (foxit::uint32 unicode, const foxit::pdf::PDFDoc &document)
| Get the width (in 1/1000 of em size, as PDF units) of a character (specified by unicode) in a PDF document. More...
float | GetCharWidth (uint32 unicode) const
| Get the width (in 1/1000 of em size (PDF units)) of a character specified by unicode. More...
CIDCharset | GetCIDCharset (const pdf::PDFDoc &document)
| Get CID font charset. More...
int | GetDescent () const
| Get the descent value, in 1/1000 of em size (PDF units). More...
String | GetEncoding (const pdf::PDFDoc &document)
| Get the current font encoding. More...
String | GetFamilyName ()
| Retrieve the famliy name. More...
FontTypes | GetFontType (const pdf::PDFDoc &document)
| Get font type. More...
WString | GetName ()
| Retrieve the postscript name. More...
StandardID | GetStandard14Font (const pdf::PDFDoc &document)
| Get standard font ID. More...
foxit::uint32 | GetStyles (const pdf::PDFDoc &document)
| Get font styles. More...
bool | IsBold () const
| Judge whether current font is bold or not. More...
bool | IsCharSupported (foxit::uint32 unicode, const pdf::PDFDoc &document) const
| Check whether the character is supported by current font. More...
bool | IsEmbedded (const pdf::PDFDoc &document)
| Judge whether current font is embedded in a specified PDF document or not. More...
bool | IsEmpty () const
| Check whether current object is empty or not. More...
bool | IsItalic () const
| Judge whether current font object is italic or not. More...
bool | IsStandardFont (const pdf::PDFDoc &document)
| Check whether current font is a standard font. More...
bool | IsSupportEmbedded (const pdf::PDFDoc &document)
| Check whether current font is supported to be embedded to the specified PDF document or not. More...
bool | IsVertWriting (const pdf::PDFDoc &document)
| Check whether current font is vertical writing. More...
bool | operator!= (const Font &other) const
| Not equal operator. More...
Font & | operator= (const Font &other)
| Assign operator. More...
bool | operator== (const Font &other) const
| Equal operator. More...
bool | SetEncoding (const pdf::PDFDoc &document, const char *value)
| Set the current font encoding. More...
Public Member Functions inherited from foxit::Base
FS_HANDLE | Handle () const
| Get the handle of current object. More...

## Detailed Description

In PDF document, font is used for drawing text in PDF page.
This class represents font used in Foxit PDF SDK. This class offers different constructor for user to construct a new font object, by specified parameters, by standard font ID, or from a font file path. A font object can also be retrieved directly from other object (such as free text annotation, a text graphics object, etc) in a PDF document. This class also offers some functions to get some basic information from a font.

## Member Enumeration Documentation

## ◆ Charset

enum foxit::common::Font::Charset

Enumeration for font charset.

Values of this enumeration should be used alone.

Enumerator
e_CharsetANSI | Font charset: ANSI (United States, Western Europe).
e_CharsetDefault | Font charset: System default, for unknown or mapping purpose.
e_CharsetSymbol | Font charset: Standard symbols.
e_CharsetShift_JIS | Font charset: Japanese (Shift-JIS).
e_CharsetHangeul | Font charset: Korean (Wansung).
e_CharsetGB2312 | Font charset: Simplified Chinese.
e_CharsetChineseBig5 | Font charset: Traditional Chinese.
e_CharsetThai | Font charset: Thai.
e_CharsetEastEurope | Font charset: Eastern European.
e_CharsetRussian | Font charset: Russian.
e_CharsetGreek | Font charset: Greek.
e_CharsetTurkish | Font charset: Turkish.
e_CharsetHebrew | Font charset: Hebrew.
e_CharsetArabic | Font charset: Arabic.
e_CharsetBaltic | Font charset: Baltic.

## ◆ CIDCharset

enum foxit::common::Font::CIDCharset

Enumeration for CID font charset.

Values of this enumeration should be used alone.

Enumerator
e_CIDCharsetUnknown | CID Font charset: Unknown.
e_CIDCharsetGB1 | CID Font charset: Adobe-GB1.
e_CIDCharsetCNS1 | CID Font charset: Adobe-CNS1.
e_CIDCharsetJAPAN1 | CID Font charset: Adobe-Japan1.
e_CIDCharsetKOREA1 | CID Font charset: Adobe-Korea1.
e_CIDCharsetUNICODE | CID Font charset: Unicode.

## ◆ FontTypes

enum foxit::common::Font::FontTypes

Enumeration for font type.

Values of this enumeration can be used alone .

Enumerator
e_FontTypeType1 | Font type: Type1.
e_FontTypeTrueType | Font type: TrueType.
e_FontTypeType3 | Font type: Type3.
e_FontTypeCIDFont | Font type: CID font.

## ◆ StandardID

enum foxit::common::Font::StandardID

Enumeration for standard font ID.

Values of this enumeration should be used alone.

Enumerator
e_StdIDCourier | Standard font: Courier.
e_StdIDCourierB | Standard font: Courier-Bold.
e_StdIDCourierBI | Standard font: Courier-BoldOblique, Bold italic.
e_StdIDCourierI | Standard font: Courier-Oblique, Italic.
e_StdIDHelvetica | Standard font: Helvetica.
e_StdIDHelveticaB | Standard font: Helvetica-Bold.
e_StdIDHelveticaBI | Standard font: Helvetica-BoldOblique, Bold italic.
e_StdIDHelveticaI | Standard font: Helvetica-Oblique, Italic.
e_StdIDTimes | Standard font: Times-Roman.
e_StdIDTimesB | Standard font: Times-Bold.
e_StdIDTimesBI | Standard font: Times-BoldItalic.
e_StdIDTimesI | Standard font: Times-Italic.
e_StdIDSymbol | Standard font: Symbol.
e_StdIDZapfDingbats | Standard font: ZapfDingbats.

## ◆ Styles

enum foxit::common::Font::Styles

Enumeration for font styles.

Values of this enumeration can be used alone or in combination.

Enumerator
e_StyleFixedPitch | Font style: fixed pitch.
e_StyleSerif | Font style: serif.
e_StyleSymbolic | Font style: symbolic.
e_StyleScript | Font style: script.
e_StyleNonSymbolic | Font style: non-symbolic.
e_StyleItalic | Font style: italic.
e_StyleAllCap | Font style: all cap.
e_StylesSmallCap | Font style: small cap.
e_StylesBold | Font style: force bold.

## Constructor & Destructor Documentation

## ◆ Font() [1/6]

foxit::common::Font::Font | ( | const wchar_t * | name,
|  | uint32 | styles,
|  | Charset | charset,
|  | int | weight
| ) |  |

Constructor, with given attribute.

This function is to construct font based on system fonts.

Parameters

  [in] | name | The PostScript name of the font to be created.
  [in] | styles | Font styles. Please refer to values starting from Font::e_StyleFixedPitch and this can be one or a combination of these values.
  [in] | charset | The charset of the font to be created. Please refer to values starting from Font::e_CharsetANSI and this should be one of these values.
  [in] | weight | Original font weight. 0 means unspecified.

## ◆ Font() [2/6]

foxit::common::Font::Font | ( | StandardID | font_id | ) |
| explicit

Constructor, by a standard font ID.

Parameters

  [in] | font_id | Standard font ID of the font to be created. Please refer to values starting from Font::e_StdIDCourier and this should be one of these values.

## ◆ Font() [3/6]

foxit::common::Font::Font | ( | const char * | font_file_path,
|  | int | face_index,
|  | Charset | charset
| ) |  |

Constructor, from a font file.

Parameters

  [in] | font_file_path | A full path to an existing font file.
  [in] | face_index | The zero-based face index. Valid range: from 0 to (face_count-1). Please call the system functions to get the face_count.
  [in] | charset | The charset of the font to be created. Please refer to values starting from Font::e_CharsetANSI and this should be one of these values.

## ◆ Font() [4/6]

foxit::common::Font::Font | ( | const wchar_t * | font_file_path,
|  | int | face_index,
|  | Charset | charset
| ) |  |

Constructor, from a font file.

Parameters

  [in] | font_file_path | A full path to an existing font file.
  [in] | face_index | The zero-based face index. Valid range: from 0 to (face_count-1). Please call the system functions to get the face_count.
  [in] | charset | The charset of the font to be created. Please refer to values starting from Font::e_CharsetANSI and this should be one of these values.

## ◆ Font() [5/6]

foxit::common::Font::Font | ( | foxit::common::file::StreamCallback * | stream | ) |

Constructor, from a font stream by using foxit::common::file::StreamCallback.

Parameters

  [in] | stream | A foxit::common::file::StreamCallback object which is implemented by user to read the font file content.

## ◆ Font() [6/6]

foxit::common::Font::Font | ( | const Font & | other | ) |

Constructor, with another font object.

Parameters

  [in] | other | Another font object.

## Member Function Documentation

## ◆ AddUnicodes()

UInt32Array foxit::common::Font::AddUnicodes | ( | const pdf::PDFDoc & | document,
|  | const UInt32Array & | unicode_array
| ) |  |

Add unicodes to current embedded font.

This function only support newly embedded font.

Parameters

  [in] | document | A valid PDF document object.
  [in] | unicode_array | The unicode array to be embedded.

Returns
  The result unicode array that is embedded to font successfully.

## ◆ Embed()

Font foxit::common::Font::Embed | ( | pdf::PDFDoc | document,
|  | bool | is_add_all_unicodes = `true`
| ) |  |

Embed current font to the specified PDF document.

Parameters

  [in] | document | A valid PDF document object.
  [in] | is_add_all_unicodes | Whether to add unicodes that are from 0x0 to 0xFFFF to current embedded font if no unicodes which are in document are added. true means embeded unicodes that are from 0x0 to 0xFFFF, while false means that just embeded one unicode. Default: true. Users can add unicodes via Font::AddUnicodes.

Returns
  The embedded font.

## ◆ GetAscent()

int foxit::common::Font::GetAscent | ( |  | ) | const

Get the ascent value, in 1/1000 of em size (PDF units).

Returns
  The ascent value, in 1/1000 of em size (PDF units).

## ◆ GetBaseFontName()

String foxit::common::Font::GetBaseFontName | ( | const pdf::PDFDoc & | document | ) |

Get base font name.

Parameters

  [in] | document | A valid PDF document object.

Returns
  Base font name.

## ◆ GetCharBBox() [1/2]

RectI foxit::common::Font::GetCharBBox | ( | foxit::uint32 | unicode,
|  | const foxit::pdf::PDFDoc & | document
| ) |  |

Get the bounding box of a character(specified by unicode) in a PDF document.

Parameters

  [in] | unicode | A character unicode value.
  [in] | document | A valid PDF document object.

Returns
  The character bounding box.

## ◆ GetCharBBox() [2/2]

RectI foxit::common::Font::GetCharBBox | ( | uint32 | unicode | ) | const

Get the bounding box of a character specified by unicode.

Parameters

  [in] | unicode | A character unicode value.

Returns
  The character bounding box.

## ◆ GetCharWidth() [1/2]

float foxit::common::Font::GetCharWidth | ( | foxit::uint32 | unicode,
|  | const foxit::pdf::PDFDoc & | document
| ) |  |

Get the width (in 1/1000 of em size, as PDF units) of a character (specified by unicode) in a PDF document.

Parameters

  [in] | unicode | A character unicode value.
  [in] | document | A valid PDF document object.

Returns
  The character width, in 1/1000 of em size (PDF units).

## ◆ GetCharWidth() [2/2]

float foxit::common::Font::GetCharWidth | ( | uint32 | unicode | ) | const

Get the width (in 1/1000 of em size (PDF units)) of a character specified by unicode.

Parameters

  [in] | unicode | A character unicode value.

Returns
  The character width, in 1/1000 of em size (PDF units).

## ◆ GetCIDCharset()

CIDCharset foxit::common::Font::GetCIDCharset | ( | const pdf::PDFDoc & | document | ) |

Get CID font charset.

Applicable for CID based fonts. For rest type of font, exception foxit::e_ErrUnsupported will be thrown.

Parameters

  [in] | document | A valid PDF document object.

Returns
  Font charset. Please refer to values starting from Font::e_CIDCharsetUnknown and this would be one of these values.

## ◆ GetDescent()

int foxit::common::Font::GetDescent | ( |  | ) | const

Get the descent value, in 1/1000 of em size (PDF units).

Returns
  The descent value, in 1/1000 of em size (PDF units).

## ◆ GetEncoding()

String foxit::common::Font::GetEncoding | ( | const pdf::PDFDoc & | document | ) |

Get the current font encoding.

Parameters

  [in] | document | A valid PDF document object.

Returns
  The value of font encoding, please refer to "TABLE 5.15 Predefined CJK CMap names" in <PDF reference 1.7> P442.

## ◆ GetFamilyName()

String foxit::common::Font::GetFamilyName | ( |  | ) |

Retrieve the famliy name.

Returns
  The famliy name.

## ◆ GetFontType()

FontTypes foxit::common::Font::GetFontType | ( | const pdf::PDFDoc & | document | ) |

Get font type.

Parameters

  [in] | document | A valid PDF document object.

Returns
  Font type. Please refer to values starting from Font::e_FontTypeType1 and this would be one of these values.

## ◆ GetName()

WString foxit::common::Font::GetName | ( |  | ) |

Retrieve the postscript name.

Returns
  The postscript name.

## ◆ GetStandard14Font()

StandardID foxit::common::Font::GetStandard14Font | ( | const pdf::PDFDoc & | document | ) |

Get standard font ID.

Applicable for standard fonts. For rest type of font, exception foxit::e_ErrUnsupported will be thrown.

Parameters

  [in] | document | A valid PDF document object.

Returns
  Standard font ID. Please refer to values starting from Font::e_StdIDCourier and this would be one of these values.

## ◆ GetStyles()

foxit::uint32 foxit::common::Font::GetStyles | ( | const pdf::PDFDoc & | document | ) |

Get font styles.

Parameters

  [in] | document | A valid PDF document object.

Returns
  Font styles. Please refer to values starting from Font::e_StyleFixedPitch and this would be one or a combination of these values.

## ◆ IsBold()

bool foxit::common::Font::IsBold | ( |  | ) | const

Judge whether current font is bold or not.

Returns
  true means current font is bold, while false means not.

## ◆ IsCharSupported()

bool foxit::common::Font::IsCharSupported | ( | foxit::uint32 | unicode,
|  | const pdf::PDFDoc & | document
| ) |  | const

Check whether the character is supported by current font.

Parameters

  [in] | unicode | A character unicode value.
  [in] | document | A PDF document object. If this font not embedded in the document, this parameter can be an empty object.

Returns
  true means the character is supported in its font, while false means not.

## ◆ IsEmbedded()

bool foxit::common::Font::IsEmbedded | ( | const pdf::PDFDoc & | document | ) |

Judge whether current font is embedded in a specified PDF document or not.

Parameters

  [in] | document | A valid PDF document object.

Returns
  true means the font is embedded in the specified PDF document, while false means not.

## ◆ IsEmpty()

bool foxit::common::Font::IsEmpty | ( |  | ) | const

Check whether current object is empty or not.

When the current object is empty, that means current object is useless.

Returns
  true means current object is empty, while false means not.

## ◆ IsItalic()

bool foxit::common::Font::IsItalic | ( |  | ) | const

Judge whether current font object is italic or not.

Returns
  true means current font is italic, while false means not.

## ◆ IsStandardFont()

bool foxit::common::Font::IsStandardFont | ( | const pdf::PDFDoc & | document | ) |

Check whether current font is a standard font.

Parameters

  [in] | document | A valid PDF document object.

Returns
  true means current font is a standard font, while false means not.

## ◆ IsSupportEmbedded()

bool foxit::common::Font::IsSupportEmbedded | ( | const pdf::PDFDoc & | document | ) |

Check whether current font is supported to be embedded to the specified PDF document or not.

Parameters

  [in] | document | A valid PDF document object.

Returns
  true means current font is supported to be embedded to the specified PDF document, while false means not.

## ◆ IsVertWriting()

bool foxit::common::Font::IsVertWriting | ( | const pdf::PDFDoc & | document | ) |

Check whether current font is vertical writing.

Parameters

  [in] | document | A valid PDF document object.

Returns
  true means current font is vertical writing, while false means current font is not vertical writing.

## ◆ operator!=()

bool foxit::common::Font::operator!= | ( | const Font & | other | ) | const

Not equal operator.

Parameters

  [in] | other | Another font object. This function will check if current object is not equal to this one.

Returns
  true means not equal, while false means equal.

## ◆ operator=()

Font& foxit::common::Font::operator= | ( | const Font & | other | ) |

Assign operator.

Parameters

  [in] | other | Another font object, whose value would be assigned to current object.

Returns
  Reference to current object itself.

## ◆ operator==()

bool foxit::common::Font::operator== | ( | const Font & | other | ) | const

Equal operator.

Parameters

  [in] | other | Another font object. This function will check if current object is equal to this one.

Returns
  true means equal, while false means not equal.

## ◆ SetEncoding()

bool foxit::common::Font::SetEncoding | ( | const pdf::PDFDoc & | document,
|  | const char * | value
| ) |  |

Set the current font encoding.

Parameters

  [in] | document | A valid PDF document object.
  [in] | value | The font encoding to be set. For encoding values, please refer to "TABLE 5.15 Predefined CJK CMap names" in <PDF reference 1.7> P442. This parameter should not be an empty string.

Returns
  true means success, while false means failed.