# cunha-renato/msdf_font architecture

> Architecture diagram of the GitHub repository cunha-renato/msdf_font, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cunha-renato/msdf_font
- Repository: https://github.com/cunha-renato/msdf_font

## Overview

msdf_font is a Rust MSDF/SDF glyph rasterization library with optional atlas generation. The documented workflow starts with a parsed font face, builds glyph geometry, generates a distance-field bitmap, and exposes its bytes for image output; atlas mode builds glyphs, packs them, and rasterizes them into a shared bitmap. Geometry, distance selection, and error correction are distinct internal stages. Error correction is a documented capability, but its invocation point is not established by the excerpts, so no connection to the rasterization path is asserted.

Main entry points: [`src/shape.rs`](https://github.com/cunha-renato/msdf_font/blob/main/src/shape.rs) (Shape rasterizer), [`src/atlas/mod.rs`](https://github.com/cunha-renato/msdf_font/blob/main/src/atlas/mod.rs) (Atlas builder), [`src/shape_distance_finder.rs`](https://github.com/cunha-renato/msdf_font/blob/main/src/shape_distance_finder.rs) (Distance finder), [`src/glyph.rs`](https://github.com/cunha-renato/msdf_font/blob/main/src/glyph.rs) (Glyph builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_glyph["Glyph workflow"]
  node_glyph_builder["Glyph builder<br/>[glyph.rs]"]
  node_bitmap["Bitmap storage<br/>[bitmap.rs]"]
end

subgraph group_geometry["Shape geometry"]
  node_shape["Shape rasterizer<br/>[shape.rs]"]
  node_contour["Contours<br/>[contour.rs]"]
  node_edge["Shape edges<br/>[edge.rs]"]
  node_bounds["Bounds<br/>[bounds.rs]"]
  node_edge_color["Edge coloring<br/>[edge_color.rs]"]
  node_solvers["Curve solvers<br/>[solvers.rs]"]
end

subgraph group_distance["Distance fields"]
  node_distance_finder["Distance finder"]
  node_edge_selector["Distance selectors<br/>[edge_selector.rs]"]
  node_distance_math["Distance math<br/>[distance.rs]"]
  node_error_correction["Error correction<br/>[mod.rs]"]
  node_artifact_classifier["Artifact classifier"]
end

subgraph group_atlas["Atlas generation"]
  node_atlas_builder["Atlas builder<br/>[mod.rs]"]
  node_packer["Rectangle packer<br/>[packer.rs]"]
  node_atlas_bitmap["Atlas bitmap region<br/>[bitmap.rs]"]
end

node_font_user(("Font consumer"))

node_font_user -->|"builds glyphs"| node_glyph_builder
node_glyph_builder -->|"uses shape"| node_shape
node_font_user -->|"reads output bytes"| node_bitmap
node_shape -->|"uses contours"| node_contour
node_shape -->|"uses edges"| node_edge
node_shape -->|"uses bounds"| node_bounds
node_shape -->|"colors edges"| node_edge_color
node_shape -->|"queries distances"| node_distance_finder
node_distance_finder -->|"reads shape"| node_shape
node_distance_finder -->|"uses selectors"| node_edge_selector
node_edge -->|"solves curves"| node_solvers
node_error_correction -->|"classifies artifacts"| node_artifact_classifier
node_font_user -->|"builds atlas"| node_atlas_builder
node_atlas_builder -->|"builds glyphs"| node_glyph_builder
node_atlas_builder -->|"packs glyphs"| node_packer
node_atlas_builder -->|"writes regions"| node_atlas_bitmap
node_atlas_bitmap -->|"uses bitmap data"| node_bitmap

click node_glyph_builder "https://github.com/cunha-renato/msdf_font/blob/main/src/glyph.rs"
click node_bitmap "https://github.com/cunha-renato/msdf_font/blob/main/src/bitmap.rs"
click node_shape "https://github.com/cunha-renato/msdf_font/blob/main/src/shape.rs"
click node_contour "https://github.com/cunha-renato/msdf_font/blob/main/src/contour.rs"
click node_edge "https://github.com/cunha-renato/msdf_font/blob/main/src/edge.rs"
click node_bounds "https://github.com/cunha-renato/msdf_font/blob/main/src/bounds.rs"
click node_edge_color "https://github.com/cunha-renato/msdf_font/blob/main/src/edge_color.rs"
click node_distance_finder "https://github.com/cunha-renato/msdf_font/blob/main/src/shape_distance_finder.rs"
click node_edge_selector "https://github.com/cunha-renato/msdf_font/blob/main/src/edge_selector.rs"
click node_distance_math "https://github.com/cunha-renato/msdf_font/blob/main/src/distance.rs"
click node_solvers "https://github.com/cunha-renato/msdf_font/blob/main/src/solvers.rs"
click node_error_correction "https://github.com/cunha-renato/msdf_font/blob/main/src/error_correction/mod.rs"
click node_artifact_classifier "https://github.com/cunha-renato/msdf_font/blob/main/src/error_correction/artifact_classifier.rs"
click node_atlas_builder "https://github.com/cunha-renato/msdf_font/blob/main/src/atlas/mod.rs"
click node_packer "https://github.com/cunha-renato/msdf_font/blob/main/src/atlas/packer.rs"
click node_atlas_bitmap "https://github.com/cunha-renato/msdf_font/blob/main/src/atlas/bitmap.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_glyph_builder,node_bitmap toneBlue
class node_shape,node_contour,node_edge,node_bounds,node_edge_color,node_solvers toneAmber
class node_distance_finder,node_edge_selector,node_distance_math,node_error_correction,node_artifact_classifier toneMint
class node_atlas_builder,node_packer,node_atlas_bitmap toneRose
class node_font_user toneIndigo
```

## Components

### Glyph workflow

- [Glyph builder](https://github.com/cunha-renato/msdf_font/blob/main/src/glyph.rs): `src/glyph.rs`
- [Bitmap storage](https://github.com/cunha-renato/msdf_font/blob/main/src/bitmap.rs): `src/bitmap.rs`

### Shape geometry

- [Shape rasterizer](https://github.com/cunha-renato/msdf_font/blob/main/src/shape.rs): `src/shape.rs`
- [Contours](https://github.com/cunha-renato/msdf_font/blob/main/src/contour.rs): `src/contour.rs`
- [Shape edges](https://github.com/cunha-renato/msdf_font/blob/main/src/edge.rs): `src/edge.rs`
- [Bounds](https://github.com/cunha-renato/msdf_font/blob/main/src/bounds.rs): `src/bounds.rs`
- [Edge coloring](https://github.com/cunha-renato/msdf_font/blob/main/src/edge_color.rs): `src/edge_color.rs`
- [Curve solvers](https://github.com/cunha-renato/msdf_font/blob/main/src/solvers.rs): `src/solvers.rs`

### Distance fields

- [Distance finder](https://github.com/cunha-renato/msdf_font/blob/main/src/shape_distance_finder.rs): `src/shape_distance_finder.rs`
- [Distance selectors](https://github.com/cunha-renato/msdf_font/blob/main/src/edge_selector.rs): `src/edge_selector.rs`
- [Distance math](https://github.com/cunha-renato/msdf_font/blob/main/src/distance.rs): `src/distance.rs`
- [Error correction](https://github.com/cunha-renato/msdf_font/blob/main/src/error_correction/mod.rs): `src/error_correction/mod.rs`
- [Artifact classifier](https://github.com/cunha-renato/msdf_font/blob/main/src/error_correction/artifact_classifier.rs): `src/error_correction/artifact_classifier.rs`

### Atlas generation

- [Atlas builder](https://github.com/cunha-renato/msdf_font/blob/main/src/atlas/mod.rs): `src/atlas/mod.rs`
- [Rectangle packer](https://github.com/cunha-renato/msdf_font/blob/main/src/atlas/packer.rs): `src/atlas/packer.rs`
- [Atlas bitmap region](https://github.com/cunha-renato/msdf_font/blob/main/src/atlas/bitmap.rs): `src/atlas/bitmap.rs`

### Other components

- **Font consumer**

## Connections

- Font consumer → Glyph builder: builds glyphs (evidence: `README.md`)
- Glyph builder → Shape rasterizer: uses shape (evidence: `src/glyph.rs`)
- Font consumer → Bitmap storage: reads output bytes (evidence: `README.md`)
- Shape rasterizer → Contours: uses contours (evidence: `src/shape.rs`)
- Shape rasterizer → Shape edges: uses edges (evidence: `src/shape.rs`)
- Shape rasterizer → Bounds: uses bounds (evidence: `src/shape.rs`)
- Shape rasterizer → Edge coloring: colors edges (evidence: `src/shape.rs`)
- Shape rasterizer → Distance finder: queries distances (evidence: `src/shape_distance_finder.rs`)
- Distance finder → Shape rasterizer: reads shape (evidence: `src/shape_distance_finder.rs`)
- Distance finder → Distance selectors: uses selectors (evidence: `src/shape_distance_finder.rs`)
- Shape edges → Curve solvers: solves curves (evidence: `src/edge.rs`)
- Error correction → Artifact classifier: classifies artifacts (evidence: `src/error_correction/mod.rs`)
- Font consumer → Atlas builder: builds atlas (evidence: `README.md`)
- Atlas builder → Glyph builder: builds glyphs (evidence: `src/atlas/mod.rs`)
- Atlas builder → Rectangle packer: packs glyphs (evidence: `src/atlas/mod.rs`)
- Atlas builder → Atlas bitmap region: writes regions (evidence: `src/atlas/mod.rs`)
- Atlas bitmap region → Bitmap storage: uses bitmap data (evidence: `src/atlas/bitmap.rs`)
