Repository navigation
Font Rendering
JNode's dual font rendering system: anti-aliased BDF bitmaps and a TrueType outline renderer behind a plugin
FontManager.
JNode provides two font pipelines:
- BDF — bitmap fonts parsed by a JavaCC-generated parser, used for the default UI and console fonts.
-
TrueType (TTF) — scalable outlines rasterized through
GlyphRendererand composited to aSurface.
Both are coordinated by DefaultFontManager, which discovers FontProvider plugins through the org.jnode.font.providers extension point. The renderer is selected by the jnode.font.renderer property; the default remains bdf even though TTF is more feature-complete.
The 2026-11 font work added anti-aliased DejaVu BDF faces with style/size-aware selection and substantially fixed the TTF pipeline (cmap format 4, metrics, raster layout, glyph vector routing and CP437 box glyphs).
| Class / File | Purpose |
|---|---|
gui/src/awt/org/jnode/awt/font/FontManager.java |
Central interface coordinating providers |
gui/src/awt/org/jnode/awt/font/def/DefaultFontManager.java |
Plugin-based provider discovery; reads jnode.font.renderer (default bdf) |
gui/src/font/org/jnode/font/bdf/BDFParser.java |
JavaCC-generated BDF parser |
gui/src/font/org/jnode/font/bdf/BDFFontContainer.java |
Glyphs, metadata and glyph-name → code mapping |
gui/src/font/org/jnode/font/bdf/BDFGlyph.java |
BDF glyph bitmap and decode |
gui/src/awt/org/jnode/awt/font/bdf/BDFFontProvider.java |
Loads system fonts; bestFont() style/size scoring |
gui/src/awt/org/jnode/awt/font/bdf/BDFFontPeer.java |
Peer; delegates selection and metrics to bestFont()
|
gui/src/awt/org/jnode/awt/font/bdf/BDFTextRenderer.java |
Blits BDF glyphs with alpha |
gui/src/awt/org/jnode/awt/font/truetype/TTFFontProvider.java |
Loads system TTF fonts; bold/mono matching |
gui/src/awt/org/jnode/awt/font/truetype/TTFFontPeer.java |
Metrics, glyph vector, canDisplay |
gui/src/awt/org/jnode/awt/font/truetype/TTFTextRenderer.java |
Glyph placement and box-glyph drawing |
gui/src/awt/org/jnode/awt/font/truetype/BoxGlyphMapping.java |
CP437 → Unicode box glyph remap |
gui/src/awt/org/jnode/awt/font/renderer/GlyphRenderer.java |
Outline → anti-aliased 8-bit raster |
gui/src/awt/org/jnode/awt/font/truetype/tables/*.java |
Head, glyph, cmap, hhea, hmtx, loca, maxp, name, OS/2, post |
gui/fonts/*.bdf, gui/fonts/*.ttf
|
DejaVu Sans / Sans Mono, regular and bold |
DefaultFontManager enumerates providers and asks each for a TextRenderer/FontMetrics. Provider order comes from the plugin registry, not from the requested family. jnode.font.renderer=bdf (the default) chooses BDF; -Djnode.font.renderer=ttf chooses TrueType.
BDFFontProvider.SYSTEM_FONTS lists the anti-aliased DejaVu faces first:
DejaVuSans-{10,12,14}.bdf
DejaVuSans-Bold-{10,12,14}.bdf
DejaVuSansMono-{10,12,14}.bdf
DejaVuSansMono-Bold-{10,12,14}.bdf
These are 4-bit BDFs (SIZE n 72 72 4), so each pixel carries 16 alpha levels. The old Vera-*, VeraMono-12-8, 6x12_FixedMedium-12 and VGAMedium-19 faces remain as fallbacks.
BDFFontProvider.bestFont(Font) scores every loaded container:
- base score:
abs(container.getSize() - font.getSize()) -
1 << 20for each mismatch: bold style, italic style, mono family
The first score-0 candidate wins; otherwise the minimum score is returned. A request is treated as mono when the family contains mono, fixed or dialoginput. Style comes from the XLFD weight/slant decoded by BDFParser. BDFFontPeer uses bestFont() for canDisplay, getFontMetrics, getGlyphName, getLineMetrics, getMaxCharBounds, getNumGlyphs, getPostScriptName and getStringBounds.
BDFTextRenderer.render() skips glyphs with BBX height <= 0 but still advances by DWIDTH, preventing a divide-by-zero and preserving spacing for blank glyphs.
gui/src/font/org/jnode/font/bdf/mappings.properties adds box218…box254 mappings to Unicode box-drawing characters (U+00DA, U+00C0, …). BDFFontContainer.setGlyphs() keys the mapper by lookup(glyphName), so CP437 box codes resolve to those glyphs in BDF mode.
Contrary to the commit title ("fixed point TTF font renderer"), the renderer still uses double scaling:
double scale = fontSize / headTable.unitsPerEm;Glyph advances are rounded with (int)(scale * advance + 0.5), matching TTFFontMetrics.charWidth(). GlyphRenderer.MASTER_HEIGHT remains 128.0.
Key fixes in the 2026-11 pass:
-
CMapTable.TableFormat4.getGlyphIndex()implements segment search,idDelta,idRangeOffsetindirection and the trailing glyph-id array. -
HorizontalMetricsTable.getAdvanceWidth()clamps indices past the advance-width array to the last entry;getLeftSideBearing()falls through toleftSideBearing2. -
TableClass.create()uses a directswitchinstead of reflectivegetDeclaredConstructor/setAccessible. -
TTFFontPeer.layoutGlyphVector()returnsorg.jnode.awt.font.TGlyphVector, routing text through the provider renderer instead ofStandardGlyphVector. -
GlyphRenderer.createRaster()builds a plain single-band 8-bitDataBufferByteraster (no GRAY ICC colorspace). -
GlyphRenderer.createMaster()flattensPathIteratorcontours (quadratics in 4 steps, cubics in 7), closes them and fills with a scanline non-zero winding rule, top-down. -
AbstractTextRenderer.createAlphaRaster()allocatesfontSize * 2in both dimensions for tall glyphs. -
TTFTextRenderer.render()places the raster atGlyphRenderer.getMinLocation()(ink origin), not the font header bbox; destinations round with+0.5. -
TTFFontMetricsrounds ascent/descent/advances;getLeading()is 1 andgetHeight()is ascent+descent+leading.
TTFFontProvider.SYSTEM_FONTS is now DejaVuSans.ttf, DejaVuSans-Bold.ttf, DejaVuSansMono.ttf, DejaVuSansMono-Bold.ttf. bestFont() matches bold/mono/family but not size, because TTF is scalable.
BoxGlyphMapping remaps CP437 codes 218, 192, 191, 217, 195, 180, 193, 194, 196, 179, 197, 178 and 254 to Unicode box characters (\u250C…\u25A0). TTFTextRenderer.drawBoxGlyph() draws them itself:
- cell width
max(2, advance) - height
max(2, ascent + descent) - 178 is a checkerboard (value 8); 254 is solid
0xFF - corners and tees stroke only toward the joined panel
This gives the Swing console continuous box-drawing even when the TTF has no matching glyph.
RenderCache holds GlyphRenderer instances keyed by glyph + size. Each renderer precomputes a master shape/SAT at MASTER_HEIGHT = 128, enabling scaling to any requested size.
-
Default is still BDF (
jnode.font.renderer=bdf). Use-Djnode.font.renderer=ttfto exercise the TTF path. -
BDF glyph abstraction is not unified with TTF. BDF uses
org.jnode.font.bdf.BDFGlyph; TTF returnsorg.jnode.awt.font.spi.Glyph. -
BDF peer creation uses
match()(always true). Actual selection happens later inbestFont(). -
No 19 px DejaVu Mono. A 19 px mono request selects
DejaVuSansMono-14(size penalty 5) rather thanVGAMedium-19(mono penalty1<<20).VGAMedium-19.bdfalso declaresSIZE 18. - BDF box mappings can shadow Latin-1. U+00DA/U+00C0 etc. resolve to box glyphs in the DejaVu BDFs.
-
TTF
getMaxCharSize()returns raw font units, not scaled pixels, sogetMaxCharBounds()looks huge relative to rendered text. -
TTF peer stubs:
canDisplay()always true,getNumGlyphs()0,getGlyphName()empty. -
TTF descriptors still grant
accessDeclaredMembersalthoughTableClassno longer reflects. - No hinting. Anti-aliasing relies on the summed-area raster, not grid fitting.
- GUI-AWT — parent GUI system, theming and event queue
- AWT-Peer-Implementation — font peer integration
- Video-Driver-Architecture — surface rendering target
- JNode-Graphics2D — Graphics2D text routing