# FontCollection

## Content

# Class: FontCollection

Represents a collection of fonts.

## Extends

- [`ObjectBase`](ObjectBase)

## Constructors

### Constructor

```ts
new FontCollection(): FontCollection;
```

Creates an empty FontCollection instance.

#### Returns

`FontCollection`

#### Overrides

```ts
ObjectBase.constructor
```

### Constructor

```ts
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

```ts
ObjectBase.constructor
```

## Accessors

### count

#### Get Signature

```ts
get count(): number;
```

Gets the number of fonts in the FontCollection.

##### Returns

`number`

***

### defaultFont

#### Get Signature

```ts
get defaultFont(): Font;
```

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

##### Returns

[`Font`](Font)

#### Set Signature

```ts
set defaultFont(font): void;
```

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

##### Parameters

###### font

[`Font`](Font)

##### Returns

`void`

***

### id

#### Get Signature

```ts
get id(): number;
```

Gets the reference to the object.

##### Returns

`number`

#### Inherited from

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

***

### om

#### Get Signature

```ts
get om(): ObjectManager;
```

Gets the owner [ObjectManager](ObjectManager) instance.

##### Returns

[`ObjectManager`](ObjectManager)

#### Inherited from

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

## Methods

### getDefaultCollection()

#### Call Signature

```ts
static getDefaultCollection(): FontCollection;
```

Gets the default FontCollection instance.

##### Returns

`FontCollection`

The default FontCollection instance.

#### Call Signature

```ts
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()

```ts
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()

```ts
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`

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

##### defaultFont?

`boolean`

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

#### Returns

`void`

***

### clear()

```ts
clear(): void;
```

Removes all fonts from the FontCollection.

#### Returns

`void`

***

### clearFallbackFonts()

```ts
clearFallbackFonts(): void;
```

Clears the list of fallback fonts in the FontCollection.

#### Returns

`void`

***

### clone()

```ts
clone(): FontCollection;
```

Creates a copy of the FontCollection.

#### Returns

`FontCollection`

***

### contains()

```ts
contains(font): boolean;
```

Determines whether the font is in the FontCollection.

#### Parameters

##### font

[`Font`](Font)

The Font to be searched.

#### Returns

`boolean`

***

### free()

```ts
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()

```ts
getAt(index): Font;
```

Gets the font with the specified index from the FontCollection.

#### Parameters

##### index

`number`

#### Returns

[`Font`](Font)

***

### indexOf()

```ts
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()

```ts
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`

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

##### defaultFont?

`boolean`

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

#### Returns

`void`

***

### rebind()

```ts
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()

```ts
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()

```ts
removeAt(index): void;
```

Removes a font at the specified index.

#### Parameters

##### index

`number`

#### Returns

`void`

***

### removeFallbackFont()

```ts
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()

```ts
searchFont(searchFontOptions): Font;
```

Searches for a font with specified options in the FontCollection.

#### Parameters

##### searchFontOptions

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

#### Returns

[`Font`](Font)

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