new Font()
A font that is used to draw text on a page. It corresponds to a Font Resource
in a PDF file. More than one page may reference the same Font object.
A Font has a number of attributes, including an array of widths, the character
encoding, and the font's resource name.
PDF document can contain several different types of fonts and Font class
represents a single, flat interface around all PDF font types.
There are two main classes of fonts in PDF: simple and composite fonts.
Simple fonts are Type1, TrueType, and Type3 fonts. All simple fonts have the
following properties:
- Glyphs in the font are selected by single-byte character codes obtained from a string that is shown by the text-showing operators. Logically, these codes index into a table of 256 glyphs; the mapping from codes to glyphs is called the font's encoding. Each font program has a built-in encoding. Under some circumstances, the encoding can be altered by means described in Section 5.5.5 "Character Encoding" in PDF Reference Manual.
- Each glyph has a single set of metrics. Therefore simple fonts support only horizontal writing mode.
A composite font is one whose glyphs are obtained from a font like object called a CIDFont (e.g. CIDType0Font and CIDType0Font). A composite font is represented by a font dictionary whose Subtype value is Type0. The Type 0 font is known as the root font, while its associated CIDFont is called its descendant. CID-keyed fonts provide a convenient and efficient method for defining multiple-byte character encodings and fonts with a large number of glyphs. These capabilities provide great flexibility for representing text in writing systems for languages with large character sets, such as Chinese, Japanese, and Korean (CJK).
- Glyphs in the font are selected by single-byte character codes obtained from a string that is shown by the text-showing operators. Logically, these codes index into a table of 256 glyphs; the mapping from codes to glyphs is called the font's encoding. Each font program has a built-in encoding. Under some circumstances, the encoding can be altered by means described in Section 5.5.5 "Character Encoding" in PDF Reference Manual.
- Each glyph has a single set of metrics. Therefore simple fonts support only horizontal writing mode.
A composite font is one whose glyphs are obtained from a font like object called a CIDFont (e.g. CIDType0Font and CIDType0Font). A composite font is represented by a font dictionary whose Subtype value is Type0. The Type 0 font is known as the root font, while its associated CIDFont is called its descendant. CID-keyed fonts provide a convenient and efficient method for defining multiple-byte character encodings and fonts with a large number of glyphs. These capabilities provide great flexibility for representing text in writing systems for languages with large character sets, such as Chinese, Japanese, and Korean (CJK).
Extends
Members
-
<static> Encoding
-
Type:
- number
Properties:
Name Type Description e_IdentityH
number e_Indices
number -
<static> StandardType1Font
-
Type:
- number
Properties:
Name Type Description e_times_roman
number e_times_bold
number e_times_italic
number e_times_bold_italic
number e_helvetica
number e_helvetica_bold
number e_helvetica_oblique
number e_helvetica_bold_oblique
number e_courier
number e_courier_bold
number e_courier_oblique
number e_courier_bold_oblique
number e_symbol
number e_zapf_dingbats
number e_null
number -
<static> Type
-
Type:
- number
Properties:
Name Type Description e_Type1
number e_TrueType
number e_MMType1
number e_Type3
number e_Type0
number e_CIDType0
number e_CIDType2
number
Methods
-
<static> create(doc, type)
-
Constructor
Parameters:
Name Type Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc Document on which to create the font on. type
number PDFNet.Font.StandardType1Font = { e_times_roman : 0 e_times_bold : 1 e_times_italic : 2 e_times_bold_italic : 3 e_helvetica : 4 e_helvetica_bold : 5 e_helvetica_oblique : 6 e_helvetica_bold_oblique : 7 e_courier : 8 e_courier_bold : 9 e_courier_oblique : 10 e_courier_bold_oblique : 11 e_symbol : 12 e_zapf_dingbats : 13 e_null : 14 }
The type of font to create.PDFNet.Font.StandardType1Font = { e_times_roman : 0 e_times_bold : 1 e_times_italic : 2 e_times_bold_italic : 3 e_helvetica : 4 e_helvetica_bold : 5 e_helvetica_oblique : 6 e_helvetica_bold_oblique : 7 e_courier : 8 e_courier_bold : 9 e_courier_oblique : 10 e_courier_bold_oblique : 11 e_symbol : 12 e_zapf_dingbats : 13 e_null : 14 }
Returns:
A promise that resolves to an object of type: "Font" (generated documentation)- Type
- Promise.<PDFNet.Font>
-
<static> createAndEmbed(doc, type)
-
Parameters:
Name Type Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc type
number PDFNet.Font.StandardType1Font = { e_times_roman : 0 e_times_bold : 1 e_times_italic : 2 e_times_bold_italic : 3 e_helvetica : 4 e_helvetica_bold : 5 e_helvetica_oblique : 6 e_helvetica_bold_oblique : 7 e_courier : 8 e_courier_bold : 9 e_courier_oblique : 10 e_courier_bold_oblique : 11 e_symbol : 12 e_zapf_dingbats : 13 e_null : 14 }
Returns:
A promise that resolves to an object of type: "PDFNet.Font"- Type
- Promise.<PDFNet.Font>
-
<static> createCIDTrueTypeFont(doc, font_path [, embed] [, subset] [, encoding] [, ttc_font_index])
-
Embed an external TrueType font in the document as a CID font. By default the function selects "Identity-H" encoding that maps 2-byte character codes ranging from 0 to 65,535 to the same Unicode value. Other predefined encodings are listed in Table 5.15 'Predefined CMap names' in PDF Reference Manual.
Parameters:
Name Type Argument Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc document in which the external font should be embedded. font_path
string path to the external font file. embed
boolean <optional>
a boolean indicating whether the font should be embedded or not. For accurate font reproduction set the embed flag to 'true'. subset
boolean <optional>
a boolean indicating whether the embedded font should be subsetted encoding
number <optional>
PDFNet.Font.Encoding = { e_IdentityH : 0 e_Indices : 1 }
the encoding type either e_IdentityH (default) or e_Indices (to write glyph indices rather than unicode)ttc_font_index
number <optional>
if a TrueTypeCollection (TTC) font is loaded this parameter controls which font is actually picked Returns:
A promise that resolves to an object of type: "PDFNet.Font"- Type
- Promise.<PDFNet.Font>
-
<static> createCIDTrueTypeFontWithBuffer(doc, font_buffer [, embed] [, subset] [, encoding] [, ttc_font_index])
-
Embed an external TrueType font in the document as a CID font. By default the function selects "Identity-H" encoding that maps 2-byte character codes ranging from 0 to 65,535 to the same Unicode value. Other predefined encodings are listed in Table 5.15 'Predefined CMap names' in PDF Reference Manual.
Parameters:
Name Type Argument Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc Document in which the external font should be embedded. font_buffer
ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray A buffer contains font data in the external font file. embed
boolean <optional>
A boolean indicating whether the font should be embedded or not. For accurate font reproduction set the embed flag to 'true'. subset
boolean <optional>
A boolean indicating whether the embedded font should be subsetted. encoding
number <optional>
PDFNet.Font.Encoding = { e_IdentityH : 0 e_Indices : 1 }
The encoding type either e_IdentityH (default) or e_Indices (to write glyph indices rather than unicode).ttc_font_index
number <optional>
if a TrueTypeCollection (TTC) font is loaded this parameter controls which font is actually picked. Returns:
A promise that resolves to An object of type: "PDFNet.Font".- Type
- Promise.<PDFNet.Font>
-
<static> createFromFontDescriptor(doc, from, char_set)
-
Create a new Unicode font based on the description of an existing PDF font.
Parameters:
Name Type Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc document in which the external font should be embedded. from
PDFNet.Font A Font object that provides the name for choosing a font. If the font with that name can be located and it covers a sufficient character set characters from that font will be used. Otherwise the font object created will be from a another font that covers the character set. char_set
string An initial character set. This provides an approach to specify any characters that are required to be included in the final font as part of a string. Note that additional characters will be added to the character set as needed, so it is not required to specify them here. (empty string is a perfectly valid and common value for this argument) Returns:
A promise that resolves to an object of type: "PDFNet.Font"- Type
- Promise.<PDFNet.Font>
-
<static> createFromName(doc, name, char_set)
-
Create a new Unicode font based on the description of an existing PDF font.
Parameters:
Name Type Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc document in which the external font should be embedded. name
string A font name that provides a hint when choosing a font. If the font with that name can be located and it covers a sufficient character set characters from that font will be used. Otherwise the font object created will be from a another font that covers the character set. char_set
string An initial character set. This provides an approach to specify any characters that are required to be included in the final font as part of a string. Note that additional characters will be added to the character set as needed, so it is not required to specify them here. (empty string is a perfectly valid and common value for this argument) Returns:
A promise that resolves to an object of type: "PDFNet.Font"- Type
- Promise.<PDFNet.Font>
-
<static> createFromObj( [font_dict])
-
Create a PDF::Font object from an existing SDF font object that is embedded in the document. If font_dict is null, a non valid font is created.
Parameters:
Name Type Argument Description font_dict
PDFNet.Obj <optional>
The Cos/SDF object to create the Font object with. Returns:
A promise that resolves to an object of type: "PDFNet.Font"- Type
- Promise.<PDFNet.Font>
-
<static> createTrueTypeFont(doc, font_path [, embed] [, subset])
-
Embed an external TrueType font in the document as a Simple font. Note: glyphs in the Simple font are selected by single-byte character codes. If you want to work with multi-byte character codes (e.g. UTF16) you need to create a CID font.
Parameters:
Name Type Argument Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc Document in which the external font should be embedded. font_path
string Path to the external font file. embed
boolean <optional>
A boolean indicating whether the font should be embedded or not. For accurate font reproduction set the embed flag to 'true'. subset
boolean <optional>
A boolean indicating whether the embedded font should be subsetted. Returns:
A promise that resolves to an object of type: "PDFNet.Font"- Type
- Promise.<PDFNet.Font>
-
<static> createTrueTypeFontWithBuffer(doc, font_buffer [, embed] [, subset])
-
Embed an external TrueType font in the document as a Simple font.
Parameters:
Name Type Argument Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc Document in which the external font should be embedded. font_buffer
ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray A buffer contains font data in the external font file. embed
boolean <optional>
A boolean indicating whether the font should be embedded or not. For accurate font reproduction set the embed flag to 'true'. subset
boolean <optional>
A boolean indicating whether the embedded font should be subsetted. Returns:
A promise that resolves to An object of type: "PDFNet.Font".- Type
- Promise.<PDFNet.Font>
-
<static> createType1Font(doc, font_path [, embed])
-
Embed an external Type1 font in the document.
Parameters:
Name Type Argument Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc document in which the external font should be embedded. font_path
string path to the external font file. embed
boolean <optional>
a boolean indicating whether the font should be embedded or not. For accurate font reproduction set the embed flag to 'true'. Returns:
A promise that resolves to an object of type: "PDFNet.Font"- Type
- Promise.<PDFNet.Font>
-
<static> createType1FontWithBuffer(doc, font_buffer [, embed])
-
Embed an external Type1 font in the document.
Parameters:
Name Type Argument Description doc
PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc Document in which the external font should be embedded. font_buffer
ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray A buffer contains font data in the external font file. embed
boolean <optional>
A boolean indicating whether the font should be embedded or not. For accurate font reproduction set the embed flag to 'true'. Returns:
A promise that resolves to An object of type: "PDFNet.Font".- Type
- Promise.<PDFNet.Font>
-
<static> getTypeFromObj(font_dict)
-
Parameters:
Name Type Description font_dict
PDFNet.Obj Returns:
A promise that resolves to the type of a given SDF/Cos font dictionary- Type
- Promise.<number>
Example
Return value enum: <pre> PDFNet.Font.Type = { e_Type1 : 0 e_TrueType : 1 e_MMType1 : 2 e_Type3 : 3 e_Type0 : 4 e_CIDType0 : 5 e_CIDType2 : 6 } </pre>
-
destroy()
-
Destructor
- Inherited From:
Returns:
- Type
- Promise.<void>
-
getAscent()
-
The face's ascender is the vertical distance from the baseline to the topmost point of any glyph in the face. This field's value is a positive number, expressed in the glyph coordinate system. For all font types except Type 3, the units of glyph space are one-thousandth of a unit of text space. Some font designs use a value different from 'bbox.yMax'. Note: Only relevant for scalable formats.
Returns:
A promise that resolves to an object of type: "number"- Type
- Promise.<number>
-
getBBox()
-
Returns:
A promise that resolves to a rectangle expressed in the glyph coordinate system, specifying the font bounding box. This is the smallest rectangle enclosing the shape that would result if all of the glyphs of the font were placed with their origins coincident and then filled.- Type
- Promise.<PDFNet.Rect>
-
getCharCodeIterator()
-
GetCharCodeIterator represents an iterator interface used to traverse a list of char codes for which there is a glyph outline in the embedded font.
Returns:
A promise that resolves to an object of type: "PDFNet.Iterator" - Type
- Promise.<PDFNet.Iterator.<number>>
-
getDescendant()
-
Returns:
A promise that resolves to descendant CIDFont. Note: Relevant only for a Type0 font.- Type
- Promise.<PDFNet.Font>
-
getDescent()
-
The face's descender is the vertical distance from the baseline to the bottommost point of any glyph in the face. This field's value is a negative number expressed in the glyph coordinate system. For all font types except Type 3, the units of glyph space are one-thousandth of a unit of text space. Some font designs use a value different from 'bbox.yMin'. Note: Only relevant for scalable formats.
Returns:
A promise that resolves to an object of type: "number"- Type
- Promise.<number>
-
getDescriptor()
-
Returns:
A promise that resolves to a SDF/Cos object representing FontDescriptor or NULL is FontDescriptor is not present.- Type
- Promise.<PDFNet.Obj>
-
getEmbeddedFont()
-
Returns:
A promise that resolves to the stream object of the embedded font or NULL if there if the font is not embedded. Note: This function is not applicable to Type3 font and will throw exception.- Type
- Promise.<PDFNet.Obj>
-
getEmbeddedFontBufSize()
-
Returns:
A promise that resolves to the size of decoded buffer containing embedded font data or 0 if this information is not known in advance. Note: The size of decoded buffer may not be known in advance for all fonts and may not be correct. Note: This function is not applicable to Type3 font and will throw exception.- Type
- Promise.<number>
-
getEmbeddedFontName()
-
Returns:
A promise that resolves to the PostScript font name for the embedded font. If the embedded font name is not available the function returns the empty string .- Type
- Promise.<string>
-
getEncoding()
-
Returns:
A promise that resolves to the font's encoding array (the mapping of character codes to glyphs). The array contains 256 pointers. If a pointer is not NULL, it points to a C string containing the name of the glyph for the code point corresponding to the index. If it is NULL, then the name of the glyph is unchanged from that specified by the font's built-in encoding. For a Type 3 font, all glyph names will be present in the encoding array, and NULL entries correspond to un-encoded code points. Note: The Font object is the owner of the array. Note: This function is not applicable to composite fonts (e_type0, e_CIDType0, and e_CIDType2) and will throw an exception.- Type
- Promise.<string>
-
getFamilyName()
-
Returns:
A promise that resolves to the face's family name. This is an ASCII string, usually in English, which describes the typeface's family (like 'Times New Roman', 'Bodoni', 'Garamond', etc). This is a least common denominator used to list fonts.- Type
- Promise.<string>
-
getMaxWidth()
-
Returns:
A promise that resolves to the maximal advance width, in font units, for all glyphs in this face.- Type
- Promise.<number>
-
getMissingWidth()
-
Returns:
A promise that resolves to the default width to use for character codes whose widths are not specified in a font dictionary's Widths array.- Type
- Promise.<number>
-
getName()
-
Returns:
A promise that resolves to the name of a font. The behavior depends on the font type; for a Type 3 font it gets the value of the Name key in a PDF Font resource. For other types it gets the value of the BaseFont key in a PDF font resource.- Type
- Promise.<string>
-
getSDFObj()
-
Returns:
A promise that resolves to a SDF/Cos object of this Font.- Type
- Promise.<PDFNet.Obj>
-
getShapedText(text_to_shape)
-
Creates a set of positioned glyphs corresponding to the visual representation of the provided text string. The shaped text will take into account any advanced positioning and substitution features provided by an underylying embedded font file. For example, these features could include kerning, ligatures, and diacritic positioning. Typically the resulting shaped text would be fed into ElementBuilder.CreateShapedTextRun()
Parameters:
Name Type Description text_to_shape
string the string to be shaped. Returns:
A promise that resolves to a ShapedText object representing the result of the shaping operation. Note: Shaping requires a Type0 font with an embedded font file which covers all the unicode codepoints in the source text. For best results, this font should use the e_Indices encoding scheme, as shaping features that combine multiple codepoints into one glyph (ligatures, for example) will not work well in non-index encoded fonts.- Type
- Promise.<PDFNet.ShapedText>
-
getStandardType1FontType()
-
Returns:
A promise that resolves to font::e_null if the font is not a standard Type1 font or some other StandardType1Font value for a standard Type1 font.- Type
- Promise.<number>
-
getType()
-
Returns:
A promise that resolves to font Type- Type
- Promise.<number>
Example
Return value enum: <pre> PDFNet.Font.Type = { e_Type1 : 0 e_TrueType : 1 e_MMType1 : 2 e_Type3 : 3 e_Type0 : 4 e_CIDType0 : 5 e_CIDType2 : 6 } </pre>
-
getType3FontMatrix()
-
Returns:
A promise that resolves to type3 font matrix, mapping glyph space to text space A common practice is to define glyphs in terms of a 1000-unit glyph coordinate system, in which case the font matrix is [0.001 0 0 0.001 0 0]. Note: Relevant only for a Type3 font.- Type
- Promise.<PDFNet.Matrix2D>
-
getType3GlyphStream(char_code)
-
Parameters:
Name Type Description char_code
number Returns:
A promise that resolves to a SDF/Cos glyph stream for the given char_code. If specified char_code is not found in the CharProcs dictionary the function returns NULL. Note: Relevant only for a Type3 font.- Type
- Promise.<PDFNet.Obj>
-
getUnitsPerEm()
-
Returns:
A promise that resolves to the number of font units per EM square for this face. This is typically 2048 for TrueType fonts, 1000 for Type1 fonts Note: Only relevant for scalable formats (such as TrueType and Type1). Note: This function is not applicable to Type3 font and will throw an exception. Use GetType3FontMatrix instead.- Type
- Promise.<number>
-
getVerticalAdvance(char_code)
-
Parameters:
Name Type Description char_code
number character to query for vertical advance Note: Use this method only for composite fonts with vertical writing mode (i.e. if Font.IsHorizontalMode() returns false). The method will return 0 as vertical advance for simple fonts or for composite fonts with only horizontal writing mode. Note: Relevant only for a Type0 font. Returns:
A promise that resolves to vertical advance. vertical advance is a displacement vector for vertical writing mode (i.e. writing mode 1); its horizontal component is always 0.- Type
- Promise.<Object>
-
getWidth(char_code)
-
Parameters:
Name Type Description char_code
number Returns:
A promise that resolves to advance width, measured in glyph space units for the glyph matching given character code. Note: 1000 glyph units = 1 text space unit Note: The width returned has NOT been scaled by the font size, text matrix, nor the CTM. The function gets the advance width of the font glyph. The advance width is the amount by which the current point advances when the glyph is drawn. The advance width may not correspond to the visible width of the glyph and for this reason, the advance width cannot be used to determine the glyphs' bounding boxes.- Type
- Promise.<number>
-
isAllCap()
-
Returns:
A promise that resolves to true if font contains no lowercase letters- Type
- Promise.<boolean>
-
isCFF()
-
Returns:
A promise that resolves to true if the embedded font is represented as CFF (Compact Font Format). Note: Only Type1 and Type1C fonts can be represented in CFF format- Type
- Promise.<boolean>
-
isEmbedded()
-
Tests whether or not the specified font is stored as a font file in a stream embedded in the PDF file.
Returns:
A promise that resolves to true if the font is embedded in the file, false otherwise.- Type
- Promise.<boolean>
-
isFixedWidth()
-
Returns:
A promise that resolves to true if all glyphs have the same width- Type
- Promise.<boolean>
-
isForceBold()
-
Returns:
A promise that resolves to true if bold glyphs should be painted with extra pixels at very small text sizes.- Type
- Promise.<boolean>
-
isHorizontalMode()
-
Returns:
A promise that resolves to true if the font uses horizontal writing mode, false for vertical writing mode.- Type
- Promise.<boolean>
-
isItalic()
-
Returns:
A promise that resolves to true if glyphs have dominant vertical strokes that are slanted.- Type
- Promise.<boolean>
-
isSerif()
-
Returns:
A promise that resolves to true if glyphs have serifs- Type
- Promise.<boolean>
-
isSimple()
-
Returns:
A promise that resolves to true for non-CID based fonts such as Type1, TrueType, and Type3 All simple fonts have the following properties:
Glyphs in the font are selected by single-byte character codes obtained from a string that is shown by the text-showing operators. Logically, these codes index into a table of 256 glyphs; the mapping from codes to glyphs is called the font's encoding. Each font program has a built-in encoding. Under some circumstances, the encoding can be altered by means described in Section 5.5.5 "Character Encoding" in PDF Reference Manual.
Each glyph has a single set of metrics. Therefore simple fonts support only horizontal writing mode.
- Type
- Promise.<boolean>
-
isSymbolic()
-
Returns:
A promise that resolves to true if font contains characters outside the Adobe standard Latin character set.- Type
- Promise.<boolean>
-
mapToCID(char_code)
-
Parameters:
Name Type Description char_code
number Returns:
A promise that resolves to a CID matching specified charcode. Note: Relevant only for a Type0 font.- Type
- Promise.<number>
-
takeOwnership()
-
Take the ownership of this object, so that PDFNet.runWithCleanup won't destroy this object.
- Inherited From:
Returns:
- Type
- void