A graphical tool for analyzing the contour structure of glyphs in TrueType/OpenType fonts. It extracts the outline curves of glyphs from a font file, performs geometric and topological analysis, and visualizes the results.

- Contour display: Draws the outer contours (solid blue lines) and inner contours (dashed red lines) of glyphs
- Optional vertex markers: Toggle the display of contour vertices
- Optional fill mode: Semi-transparent fill showing the solid area of glyphs
- Interactive navigation: Built-in matplotlib toolbar for pan/zoom
- Basic information: Number of contours, number of components, outer/inner contour counts, width and height of bounding box
- Geometric features: Area, perimeter, compactness, orientation (CW/CCW), vertex count for each contour
- Component structure: Groups contours into components (each outer contour plus its directly enclosed inner contours), identifying simple polygons vs. complex polygons with holes
- Contour topology: Nesting relationships between inner and outer contours
- Component topology: Nesting relationships between components (a glyph may contain multiple nested sub-components)
- Input any Unicode character (e.g., Chinese characters, letters) to analyze
- Previous / Next glyph navigation through the font's glyph order
- Load any
.ttf,.otf, or.ttcfont file at runtime - Toggles for outer contours, inner contours, vertices, and fill
- Python 3
- Tkinter — graphical user interface (built into Python)
- matplotlib — glyph contour visualization
- fontTools — TrueType/OpenType font parsing and contour extraction
- NumPy — numerical computation (area, orientation, geometry)
- PrecisionPen — adaptive Bézier curve sampling for high-accuracy outline extraction
pip install matplotlib fonttools numpy
tkinteris included with standard Python distributions.
python GlyphTopos.pyEntry point:
GlyphTopos.py— application entry point
- The program launches with the default
simkai.ttfin the project directory. - Enter any character (e.g., "国", "回", "A") in the input box and press Enter or click Analyze.
- Use Previous / Next to browse glyphs in the font's internal order.
- Use Browse... to load a different font file.
- Use the checkboxes to toggle outer contours, inner contours, vertex points, and the transparent fill.
- The right panel shows: basic info, per-contour geometric features, component structure, contour topology, and component topology.
/
├── GlyphTopos.py Application entry point (matplotlib config + GUI launch)
├── glyph_analyzer/ Core analysis package
│ ├── __init__.py Unified exports (PrecisionPen, GlyphAnalyzer, GlyphAnalyzerApp)
│ ├── pen.py PrecisionPen — adaptive Bézier curve sampling
│ ├── analyzer.py GlyphAnalyzer — font loading, contour extraction, geometry & topology
│ └── gui/ GUI sub-package
│ ├── __init__.py
│ ├── styles.py ttk theme and style definitions
│ ├── toolbar.py Top toolbar (font picker, character input, display toggles)
│ ├── panels.py Outline plotting panel + data display panels
│ └── app.py GlyphAnalyzerApp — main application class
├── simkai.ttf Example font file (Kai style)
└── README.md Documentation
- Contour extraction —
PrecisionPenadaptively samples each Bézier curve to form a high-precision polygon. - Type correction — Determines outer/inner contour types through the signed area and nesting depth of each polygon.
- Component grouping — Groups each outer contour with the inner contours it directly encloses into one component; components whose outer contours are not enclosed by any other component are treated as independent.
- Topology detection — Uses a ray-casting point-in-polygon test to determine nesting relationships, selecting the smallest enclosing contour (or component) as the direct parent.
Use for learning and research purposes.