# Font Class

> Represents a font.Defines the typeface, size, style (bold, italic), Unicode values, and other details.

- Product: Adobe PDF Library 18
- Language: Java
- Version: APDFL18.0.5PlusP2a
- HTML page: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Font
- Version index: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/llms.txt

```java
class Font
```

**Namespace:** `com::datalogics::PDFL`

## Description

Represents a font.Defines the typeface, size, style (bold, italic), Unicode values, and other details. The Font class represents a font installed on the system.

**Referenced by:** [`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Document.md), [`Font`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Font.md), [`FontVector`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/FontVector.md), [`Redaction`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Redaction.md), [`Text`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Text.md), [`TextRun`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/TextRun.md), [`WatermarkTextParams`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/WatermarkTextParams.md)

**Uses types:** [`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Document.md), [`EncodingInfo`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/EncodingInfo.md), [`Font`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Font.md), [`PDFDict`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/PDFDict.md), [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Rect.md)

## Constructors

### Font

```java
com.datalogics.PDFL.Font.Font(String fontName)
```

*constructor*

**Parameters**

- `fontName` (`String`)

Find a font with the specified name, and construct a Font object from it. Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

TrueTypes used as CID fonts must be embedded.

All CID fonts that are embedded must be subsetted.

CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

### Font

```java
com.datalogics.PDFL.Font.Font(String fontName, java.util.EnumSet< FontCreateFlags > createFlags)
```

*constructor*

**Parameters**

- `fontName` (`String`): the name of the font to create
- `createFlags` (`java.util.EnumSet< FontCreateFlags >`): flags specifying embedding and other options for the use of a font in the document

Find a font with the specified name, and construct a Font object from it. Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

TrueTypes used as CID fonts must be embedded.

All CID fonts that are embedded must be subsetted.

CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

### Font

```java
com.datalogics.PDFL.Font.Font(String fontName, java.util.EnumSet< FontCreateFlags > createFlags, WritingMode wrMode)
```

*constructor*

**Parameters**

- `fontName` (`String`): the name of the font to create
- `createFlags` (`java.util.EnumSet< FontCreateFlags >`): flags specifying embedding and other options for the use of a font in the document
- `wrMode` (`WritingMode`): determines whether text will be printed horizontally or vertically

Find a font with the specified name, and construct a Font object from it. Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H or Identity-V encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

PDFL enforces the following requirements on fonts:

TrueTypes used as CID fonts must be embedded.

All CID fonts that are embedded must be subsetted.

CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

## Methods

### delete

```java
synchronized void com.datalogics.PDFL.Font.delete(Boolean disposing)
```

*protected*

**Parameters**

- `disposing` (`Boolean`)

**Returns:** `synchronized void`

### delete

```java
synchronized void com.datalogics.PDFL.Font.delete()
```

**Returns:** `synchronized void`

Destructor.

### embedNow

```java
void com.datalogics.PDFL.Font.embedNow(Document doc)
```

**Parameters**

- `doc` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Document.md)): the Document the Font is embedded into

**Returns:** `void`

Embeds the Font.

### finalize

```java
void com.datalogics.PDFL.Font.finalize()
```

*protected*

**Returns:** `void`

Destructor.

### findIndexOfFirstUnrepresentableChar

```java
long com.datalogics.PDFL.Font.findIndexOfFirstUnrepresentableChar(String text)
```

**Parameters**

- `text` (`String`): the text to check

**Returns:** `long`

The index of the first character that cannot be represented in this font.

Find the index of the first character that cannot be represented in this font. This will return the index of the first character in the string for which the font has no glyph. If all characters can be represented (i.e. if IsTextRepresentable() would return true), this will return the length of the string.

### getAscent

```java
double com.datalogics.PDFL.Font.getAscent()
```

**Returns:** `double`

The Ascent value of the font in glyph space units.

the Ascent value from the font descriptor. This is the maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters.

### getAvgWidth

```java
double com.datalogics.PDFL.Font.getAvgWidth()
```

**Returns:** `double`

The AvgWidth value of the font in glyph space units, or 0 if not defined.

the AvgWidth value from the font descriptor. This is the average width of glyphs in the font, or 0 if the value is not defined in the font descriptor.

### getBBox

```java
Rect com.datalogics.PDFL.Font.getBBox()
```

**Returns:** [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Rect.md)

The Bounding Box rectangle of the font.

### getCapHeight

```java
double com.datalogics.PDFL.Font.getCapHeight()
```

**Returns:** `double`

The CapHeight value of the font in glyph space units, or 0 if not defined.

the CapHeight value from the font descriptor. This is the vertical coordinate of the top of flat capital letters, measured from the baseline, or 0 if the value is not defined in the font descriptor.

### getCidFontType

```java
String com.datalogics.PDFL.Font.getCidFontType()
```

**Returns:** `String`

### getDescent

```java
double com.datalogics.PDFL.Font.getDescent()
```

**Returns:** `double`

The descent value of the font. \xrefitem pdelayer_apis "PDE Layer" "PDE Layer" PDSysFont PDSysFontGetAttrs \xrefitem pdelayer_apis "PDE Layer" "PDE Layer" PDEFont PDEFontGetAttrs \xrefitem pdlayer_apis "PD Layer" "PD Layer" PDFont PDFontGetMetrics

the Descent value from the font descriptor. This is the maximum depth below the baseline reached by glyphs in this font. The value is a negative number.

### getEmbedded

```java
boolean com.datalogics.PDFL.Font.getEmbedded()
```

**Returns:** `boolean`

Tests that Font is embedded in the document it was created for returns true if the font is embedded and returns false if it is not

### getEncoding

```java
String com.datalogics.PDFL.Font.getEncoding()
```

**Returns:** `String`

The encoding of the font, eg:

WinAnsiEncoding

MacRomanEncoding

Return the encoding of the font.

### getEncodingInfo

```java
EncodingInfo com.datalogics.PDFL.Font.getEncodingInfo()
```

**Returns:** [`EncodingInfo`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/EncodingInfo.md)

Get the populated CEncoding object.

### getFlags

```java
java.util.EnumSet< FontFlags > com.datalogics.PDFL.Font.getFlags()
```

**Returns:** `java.util.EnumSet< FontFlags >`

Get the font flags for a font.

### getFontList

```java
static java.util.List< Font > com.datalogics.PDFL.Font.getFontList()
```

*static*

**Returns:** [`java.util.List< Font >`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/Font.md)

The list of available fonts.

Get a list of available fonts.

### getFullName

```java
String com.datalogics.PDFL.Font.getFullName()
```

**Returns:** `String`

The Full Name of the font. Note: This method only returns a meaningful result for TrueType-based technology fonts.

Get the Full Name of the font.

### getItalicAngle

```java
double com.datalogics.PDFL.Font.getItalicAngle()
```

**Returns:** `double`

The ItalicAngle value of the font in degrees.

the ItalicAngle value from the font descriptor. This is the angle, expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font, defined in the font descriptor.

### getLeading

```java
double com.datalogics.PDFL.Font.getLeading()
```

**Returns:** `double`

The leading value of the font, or 0 if not present.

the Leading value from the font descriptor. This is the spacing between baselines of consecutive lines of text, or 0 if the value is not defined in the font descriptor.

### getMaxWidth

```java
double com.datalogics.PDFL.Font.getMaxWidth()
```

**Returns:** `double`

The MaxWidth value of the font in glyph space units, or 0 if not present.

the MaxWidth value from the font descriptor. This is the maximum glyph width present in the font, or 0 if the value is not defined in the font descriptor.

### getMissingWidth

```java
double com.datalogics.PDFL.Font.getMissingWidth()
```

**Returns:** `double`

The MissingWidth value of the font in glyph space units, or 0 if not present.

the MissingWidth value from the font descriptor. This is the width given to characters that do not have corresponding glyphs defined in the font, or 0 if the value is not defined in the font descriptor.

### getName

```java
String com.datalogics.PDFL.Font.getName()
```

**Returns:** `String`

The name of the font.

Get the name of the font.

### getPDFDict

```java
PDFDict com.datalogics.PDFL.Font.getPDFDict()
```

**Returns:** [`PDFDict`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2a/class/PDFDict.md)

Retrieve the PDFDict representation of this object

### getStemH

```java
double com.datalogics.PDFL.Font.getStemH()
```

**Returns:** `double`

The StemH value of the font in glyph space units, or 0 if not present.

the StemH value from the font descriptor. This is the vertical thickness of the dominant horizontal stems of the font's glyphs, or 0 if the value is not defined in the font descriptor.

### getStemV

```java
double com.datalogics.PDFL.Font.getStemV()
```

**Returns:** `double`

The StemV value of the font in glyph space units, or 0 if not present.

the StemV value from the font descriptor. This is the horizontal thickness of the dominant vertical stems of the font's glyphs, or 0 if the value is not defined in the font descriptor.

### getType

```java
String com.datalogics.PDFL.Font.getType()
```

**Returns:** `String`

The type of the font.

Type0

Type1

MMType1

TrueType

Get the type of the font.

### getWritingMode

```java
WritingMode com.datalogics.PDFL.Font.getWritingMode()
```

**Returns:** `WritingMode`

The WritingMode of the font.

Get the writing mode of the font. The writing mode of the fontwhether it will place glyphs horizontally or vertically. Text written with this font will run in the direction of the writing mode.

### getXHeight

```java
double com.datalogics.PDFL.Font.getXHeight()
```

**Returns:** `double`

The XHeight value of the font in glyph space units, or 0 if not present.

the XHeight value from the font descriptor. This is the vertical coordinate of the top of flat nonascending lowercase letters in fonts that have Latin characters, as measured from the baseline, or 0 if the value is not defined in the font descriptor.

### isFromDoc

```java
boolean com.datalogics.PDFL.Font.isFromDoc()
```

**Returns:** `boolean`

### isTextRepresentable

```java
boolean com.datalogics.PDFL.Font.isTextRepresentable(String text)
```

**Parameters**

- `text` (`String`): the text to check

**Returns:** `boolean`

Is this text representable in this font?

### measureTextWidth

```java
double com.datalogics.PDFL.Font.measureTextWidth(String text, double fontSize)
```

**Parameters**

- `text` (`String`): the Text to be measured
- `fontSize` (`double`): the Font size to be used

**Returns:** `double`

Measures the width of the specified text in points, using the Font at the specified size.
