> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/code/files-and-fonts/bitmapfont.md).

# BitmapFont

## Introduction

`BitmapFont` is the runtime representation of a .fnt file and its accompanying textures (usually loaded from .png). A `BitmapFont` includes an array of `BitmapCharacterInfo`, where each represents one character in the font. A `BitmapFont` also includes an array of `Texture2Ds`, each of which represents one page from the exported .pngs.

For information on loading and assigning fonts, see the [Fonts](/gum/code/files-and-fonts/fonts.md) page.

## Construction Sources

A `BitmapFont` can be built from several sources:

* **A `.fnt` file path** — `new BitmapFont("path/to/font.fnt")` loads the descriptor from disk and resolves the page textures relative to it.
* **A `Texture2D[]` plus an `.fnt` text string** — `new BitmapFont(textures, fntText)` skips disk I/O entirely. This is the constructor used when generating fonts via KernSmith, where the page textures and `.fnt` metadata both live in memory.
* **Embedded resources, network responses, or custom pipelines** — load the bytes yourself, then feed the resulting textures and `.fnt` text into the in-memory constructor above.

A single `BitmapFont` instance can be assigned to any number of `TextRuntime`s via `TextRuntime.BitmapFont`. The atlas textures are shared, so reuse costs nothing extra at draw time.

For the full strategy comparison — when to assign a `BitmapFont` directly vs. drive fonts through `TextRuntime` properties — see [Font Strategies — Direct BitmapFont Assignment](/gum/code/files-and-fonts/fonts/font-strategies.md#direct-bitmapfont-assignment). Baked drop shadow is available on the property path ([TextRuntime Fonts](/gum/code/standard-visuals/textruntime/fonts.md#baked-drop-shadow)); for outline color, gradients, SDF, color fonts, and other KernSmith-only extras, see [Advanced Font Effects](/gum/code/files-and-fonts/fonts/advanced-font-effects.md).

## Measuring Text

The BitmapFont class is ultimately responsible for measuring text. Although the TextRuntime instance does provide many functions for measurement and positioning, the BitmapFont class can give more detailed information if necessary.

The following properties provide information about the font:

<table><thead><tr><th width="189">Property</th><th>Details</th></tr></thead><tbody><tr><td><code>BaselineY</code></td><td>Returns the number of pixels from the top of a line to the baseline.</td></tr><tr><td><code>Characters</code></td><td>Provides information about each individual character in the font.</td></tr><tr><td><code>DescenderHeight</code></td><td>The number of pixels from the baseline to the bottom of the line.</td></tr><tr><td><code>LineHeightInPixels</code></td><td>Returns the number of pixels from the top of a line to the bottom, including ascenders and descenders.</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/code/files-and-fonts/bitmapfont.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
