# FontCollection

## Content

[**DsPdfJS API v9.1.3**](../README)

***

[DsPdfJS API](../globals) / FontCollection

# Class: FontCollection

Represents a collection of fonts.

## Extends

- [`ObjectBase`](ObjectBase)

## Constructors

### Constructor

> **new FontCollection**(): `FontCollection`

Creates an empty FontCollection instance.

#### Returns

`FontCollection`

#### Overrides

`ObjectBase.constructor`

### Constructor

> **new FontCollection**(`om`): `FontCollection`

Creates an empty FontCollection instance.

#### Parameters

##### om

[`ObjectManager`](ObjectManager)

An object manager that controls the lifetime of the FontCollection object.

#### Returns

`FontCollection`

#### Overrides

`ObjectBase.constructor`

## Accessors

### count

#### Get Signature

> **get** **count**(): `number`

Gets the number of fonts in the FontCollection.

##### Returns

`number`

***

### defaultFont

#### Get Signature

> **get** **defaultFont**(): [`Font`](Font) \| `null`

Gets or sets the default font for the current font collection.

##### Returns

[`Font`](Font) \| `null`

#### Set Signature

> **set** **defaultFont**(`font`): `void`

Gets or sets the default font for the current font collection.

##### Parameters

###### font

[`Font`](Font) | `null`

##### Returns

`void`

***

### id

#### Get Signature

> **get** **id**(): `number`

Gets the reference to the object.

##### Returns

`number`

#### Inherited from

[`ObjectBase`](ObjectBase).[`id`](ObjectBase#id)

***

### om

#### Get Signature

> **get** **om**(): [`ObjectManager`](ObjectManager)

Gets the owner [ObjectManager](ObjectManager) instance.

##### Returns

[`ObjectManager`](ObjectManager)

#### Inherited from

[`ObjectBase`](ObjectBase).[`om`](ObjectBase#om)

## Methods

### getDefaultCollection()

#### Call Signature

> `static` **getDefaultCollection**(): `FontCollection`

Gets the default FontCollection instance.

##### Returns

`FontCollection`

The default FontCollection instance.

#### Call Signature

> `static` **getDefaultCollection**(`om`): `FontCollection`

Gets the default FontCollection instance.

##### Parameters

###### om

[`ObjectManager`](ObjectManager)

An object manager that controls the lifetime of the FontCollection object.

##### Returns

`FontCollection`

The default FontCollection instance.

***

### addFallbackFont()

> **addFallbackFont**(`font`): `void`

Adds the specified font as fallback to the FontCollection.

#### Parameters

##### font

[`Font`](Font)

The [Font](Font) to be added as fallback font.

#### Returns

`void`

***

### addFont()

> **addFont**(`font`, `fallbackFont?`, `defaultFont?`): `void`

Adds the specified font to the FontCollection.

#### Parameters

##### font

[`Font`](Font)

The [Font](Font) object to add, if the [Font](Font) is not yet added.

##### fallbackFont?

`boolean` = `false`

true if the font should also be added to the list of fallback fonts, false otherwise.

##### defaultFont?

`boolean` = `false`

true if the font should be set as default font, false otherwise.

#### Returns

`void`

***

### clear()

> **clear**(): `void`

Removes all fonts from the FontCollection.

#### Returns

`void`

***

### clearFallbackFonts()

> **clearFallbackFonts**(): `void`

Clears the list of fallback fonts in the FontCollection.

#### Returns

`void`

***

### clone()

> **clone**(): `FontCollection`

Creates a copy of the FontCollection.

#### Returns

`FontCollection`

***

### contains()

> **contains**(`font`): `boolean`

Determines whether the font is in the FontCollection.

#### Parameters

##### font

[`Font`](Font)

The Font to be searched.

#### Returns

`boolean`

***

### free()

> **free**(): `void`

Detaches the object from the [ObjectManager](ObjectManager) and deallocates its memory, if possible.

#### Returns

`void`

#### Inherited from

[`ObjectBase`](ObjectBase).[`free`](ObjectBase#free)

***

### getAt()

> **getAt**(`index`): [`Font`](Font)

Gets the font with the specified index from the FontCollection.

#### Parameters

##### index

`number`

#### Returns

[`Font`](Font)

***

### indexOf()

> **indexOf**(`font`): `number`

Gets the index of the font in the FontCollection, or -1 if the font is not found.

#### Parameters

##### font

[`Font`](Font)

The [Font](Font) to be searched.

#### Returns

`number`

***

### loadFont()

> **loadFont**(`fontBytes`, `fallbackFont?`, `defaultFont?`): `void`

Loads a font or font collection from the byte array.

#### Parameters

##### fontBytes

`Uint8Array`

The binary data of the font.

##### fallbackFont?

`boolean` = `false`

true if the font should be added to the list of fallback fonts, false otherwise.

##### defaultFont?

`boolean` = `false`

true if the font should be set as default font, false otherwise.

#### Returns

`void`

***

### rebind()

> **rebind**(`omTo`): `void`

Rebinds the object from the current [ObjectManager](ObjectManager) to the specified one.

#### Parameters

##### omTo

[`ObjectManager`](ObjectManager)

The new [ObjectManager](ObjectManager) for the object.

#### Returns

`void`

#### Inherited from

[`ObjectBase`](ObjectBase).[`rebind`](ObjectBase#rebind)

***

### remove()

> **remove**(`font`): `boolean`

Removes the specified font from the FontCollection.

#### Parameters

##### font

[`Font`](Font)

The [Font](Font) to be removed from the collection.

#### Returns

`boolean`

true if the font was actually removed, false otherwise.

***

### removeAt()

> **removeAt**(`index`): `void`

Removes a font at the specified index.

#### Parameters

##### index

`number`

#### Returns

`void`

***

### removeFallbackFont()

> **removeFallbackFont**(`font`): `void`

Removes the specified font from fallbacks of the FontCollection.

#### Parameters

##### font

[`Font`](Font)

The [Font](Font) to be removed from fallback fonts.

#### Returns

`void`

***

### searchFont()

> **searchFont**(`searchFontOptions`): [`Font`](Font) \| `null`

Searches for a font with specified options in the FontCollection.

#### Parameters

##### searchFontOptions

[`SearchFontOptions`](../type-aliases/SearchFontOptions)

#### Returns

[`Font`](Font) \| `null`

The [Font](Font) found, or null if not found.
