# Class: Font

## PDFNet. Font

#### 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).

### Methods

#### <static> create(doc, type)

  Constructor

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `doc` | PDFNet.SDFDoc | Document on which to create the font on.
  `type` | number/enum |
      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
    PDFNet.Font

#### <static> createAndEmbed(doc, type)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `doc` | PDFNet.SDFDoc |
  `type` | number/enum |
      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"

  Type
    PDFNet.Font

#### <static> createFromFontDescriptor(doc, from, char_set)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `doc` | PDFNet.SDFDoc |
  `from` | PDFNet.Font |
  `char_set` | string |

  ##### Returns:

  A promise that resolves to an object of type: "Font"

  Type
    PDFNet.Font

#### <static> createFromName(doc, name, char_set)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `doc` | PDFNet.SDFDoc |
  `name` | string |
  `char_set` | string |

  ##### Returns:

  A promise that resolves to an object of type: "Font"

  Type
    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 | Description
  --- | --- | ---
  `font_dict` | PDFNet.Obj | The Cos/SDF object to create the Font object with.

  ##### Returns:

  A promise that resolves to an object of type: "Font"

  Type
    PDFNet.Font

#### <static> getTypeFromObj(font_dict)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `font_dict` | PDFNet.Obj |

  ##### Returns:

  A promise that resolves to an unknown type

#### assign(right)

  Copy Constructor

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `right` | PDFNet.Font |

#### destroy()

  Frees the native memory of the object.

#### 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'.

  ##### Returns:

  A promise that resolves to an object of type: "number"

  Type
    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
    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: "Iterator"

  Type
    PDFNet.Iterator

#### getDescendant()

  ##### Returns:

  A promise that resolves to descendant CIDFont.

  Type
    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'.

  ##### Returns:

  A promise that resolves to an object of type: "number"

  Type
    number

#### getDescriptor()

  ##### Returns:

  A promise that resolves to a SDF/Cos object representing FontDescriptor or NULL is FontDescriptor is not present.

  Type
    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.

  Type
    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.

  Type
    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
    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.

  Type
    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
    string

#### getMaxWidth()

  ##### Returns:

  A promise that resolves to the maximal advance width, in font units, for all glyphs in this face.

  Type
    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
    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
    string

#### getSDFObj()

  ##### Returns:

  A promise that resolves to a SDF/Cos object of this Font.

  Type
    PDFNet.Obj

#### 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
    number

#### getType()

  ##### Returns:

  A promise that resolves to font Type

  Type
    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].

  Type
    PDFNet.matrix2d

#### getType3GlyphStream(char_code)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `char_code` | number |

  ##### Returns:

  A promise that resolves to an object of type: "Obj"

  Type
    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

  Type
    number

#### getVerticalAdvance(char_code)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `char_code` | number | character to query for vertical advance

  ##### 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
    number

#### getWidth(char_code)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `char_code` | number |

  ##### Returns:

  A promise that resolves to an object of type: "number"

  Type
    number

#### isAllCap()

  ##### Returns:

  A promise that resolves to true if font contains no lowercase letters

  Type
    boolean

#### isCFF()

  ##### Returns:

  A promise that resolves to true if the embedded font is represented as CFF (Compact Font Format).

  Type
    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
    boolean

#### isFixedWidth()

  ##### Returns:

  A promise that resolves to true if all glyphs have the same width

  Type
    boolean

#### isForceBold()

  ##### Returns:

  A promise that resolves to true if bold glyphs should be painted with extra pixels at very small text sizes.

  Type
    boolean

#### isHorizontalMode()

  ##### Returns:

  A promise that resolves to true if the font uses horizontal writing mode, false for vertical writing mode.

  Type
    boolean

#### isItalic()

  ##### Returns:

  A promise that resolves to true if glyphs have dominant vertical strokes that are slanted.

  Type
    boolean

#### isSerif()

  ##### Returns:

  A promise that resolves to true if glyphs have serifs

  Type
    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
    boolean

#### isSymbolic()

  ##### Returns:

  A promise that resolves to true if font contains characters outside the Adobe standard Latin character set.

  Type
    boolean

#### mapToCID(char_code)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `char_code` | number |

  ##### Returns:

  A promise that resolves to an unknown type

#### mapToCID2(char_data, char_data_avail)

  The function maps charcode (out_charcode) from char_data buffer to a CID (out_cid) and return the number of bytes representing the CID in the buffer.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `char_data` | number | the input data buffer containing one or more bytes of input charcode
  `char_data_avail` | number | the number of bytes in the char_data buffer

  ##### Returns:

  A promise that resolves to the number of bytes consumed by out_cid. This number must be less than or equal to char_data_avail

  Type
    number

#### Search results