# MVTGlyphAtlasTexture

class in `3d-tiles-renderer/three/plugins`, extends `CanvasTexture`

```js
import { MVTGlyphAtlasTexture } from '3d-tiles-renderer/three/plugins';
```

A canvas texture that manages a grid of fixed-size slots, each holding a rendered glyph or icon.
Slots are addressed by string key and can be drawn with text, images, or paths.

## Constructor

```js
new MVTGlyphAtlasTexture( slotCount: number, slotSize: number )
```

- `slotCount`, `number`, default `32`: Maximum number of slots in the atlas.
- `slotSize`, `number`, default `64`: Width and height of each slot in pixels.

## Properties

### .isFull: boolean

Returns true when all slots are allocated.

### .capacity: number

Returns the total number of icons that can be added to the atlas.

### .count: number

Returns the number of icons currently used.

## Methods

### .keys

```js
.keys(  )
```

Returns the keys associated with all glyphs.

### .has

```js
.has( key: string ): boolean
```

Returns true if key has an allocated slot.

- `key`, `string`

### .get

```js
.get( key: string ): Object | null
```

Returns the slot bounds `{ x, y, w, h }` for key, or null if not allocated.

- `key`, `string`

### .getSlotSize

```js
.getSlotSize( target: Vector2 ): Vector2
```

Returns the UV bounds of a slot for key in GPU texture space (flipY applied),
or null if not allocated.

- `target`, `Vector2`

### .getUV

```js
.getUV( key: string ): Object | null
```

Returns the UV bounds of the slot for key in GPU texture space (flipY applied),
or null if not allocated. x/y is the top-left corner; w/h is the slot size in UV units.

- `key`, `string`

### .drawChar

```js
.drawChar( key: string, char: string, styles?: Object ): Object
```

Renders a single character in the slot, centered on its text metrics bounding box.

- `key`, `string`
- `char`, `string`: The character to draw.
- `styles`, `Object`, optional, default `{}`
  - `font`, `string`, optional, default `''`: CSS font string (e.g. `'bold 48px sans-serif'`).
  - `color`, `string`, optional, default `'white'`: CSS fill color.
  - `strokeStyle`, `string | null`, optional, default `null`: CSS stroke color drawn under the fill, or
null to skip the stroke.
  - `strokeWidth`, `number`, optional, default `1`: Stroke width in atlas pixels.

Returns `Object`: The allocated slot.

### .measureChar

```js
.measureChar( char: string, font: string ): TextMetrics
```

Function that returns a text metrics object for the given character rendered with
the provided set of styles.

- `char`, `string`
- `font`, `string`

### .drawImage

```js
.drawImage( key: string, image: HTMLImageElement | HTMLCanvasElement | ImageBitmap ): Object
```

Draws a `CanvasImageSource` into the slot, scaled to fit.

- `key`, `string`
- `image`, `HTMLImageElement | HTMLCanvasElement | ImageBitmap`

Returns `Object`: The allocated slot.

### .drawPath

```js
.drawPath( key: string, path2D: Path2D, styles?: Object ): Object
```

Renders a `Path2D` into the slot. Path coordinates are slot-local (origin at top-left).

- `key`, `string`
- `path2D`, `Path2D`
- `styles`, `Object`, optional, default `{}`
  - `fillStyle`, `string | null`, optional, default `null`: CSS fill color, or null to skip fill.
  - `strokeStyle`, `string | null`, optional, default `null`: CSS stroke color, or null to skip stroke.
  - `lineWidth`, `number`, optional, default `1`: Stroke width in pixels.

Returns `Object`: The allocated slot.

### .drawSVG

```js
.drawSVG( key: string, svgText: string, styles?: Object ): Object
```

Parses an SVG string and renders its paths into a slot, scaled to fit.

- `key`, `string`
- `svgText`, `string`
- `styles`, `Object`, optional, default `{}`
  - `fillStyle`, `string | null`, optional, default `'white'`: CSS fill color, or null to skip fill.
  - `strokeStyle`, `string | null`, optional, default `null`: CSS stroke color, or null to skip stroke.
  - `strokeWidth`, `number`, optional, default `1`: Visible stroke width in atlas pixels.
  - `iconScale`, `number`, optional, default `1`: Fraction of the slot size the icon occupies (0–1).

Returns `Object`: The allocated slot.

### .release

```js
.release( key: string )
```

Frees the slot for key, returning it to the pool for reuse.

- `key`, `string`

### .resize

```js
.resize( slotCount: number, slotSize?: number )
```

Resizes the atlas, copying existing slot content to their new positions.

- `slotCount`, `number`: New maximum slot count.
- `slotSize`, `number`, optional: New slot size in pixels. Defaults to current size.

### .clear

```js
.clear(  )
```

Clears all slots and resets the atlas to empty.
