ws-arch2: docs/guide sections (archive: LHA / ARJ / Zoo, encodings, disk images; font: bitmap fonts, Type 1 / EOT / Hershey) with tested snippets; tools/fixtures/docs_arch2.py inputs
This commit is contained in:
1 parent
53b41c7275
commit
cb5237aaa9
3 files changed
+189
-1
No files matched your search
+49
-1
@@ -232,6 +232,46 @@ local bm = assert(F.font.load(fnt, { loadPage = function(file) return pages[file
|
||||
assert(bm:rasterize(bm:glyphIndex(string.byte("H"))))
|
||||
```
|
||||
|
||||
## Bitmap fonts
|
||||
|
||||
BDF, PCF, PSF (Linux console) and Windows FNT / FON fonts load as the same Font, with their glyph bitmaps in
|
||||
`font.bitmap` (`size`, `ascent`, `descent`, `glyphs[i] = { codepoint, name, width, height, left, top, advance,
|
||||
pixels }`, one byte per pixel, 0 or 255). Units are pixels: `unitsPerEm` is the pixel size, `rasterize` returns the
|
||||
glyph as stored (its `px` argument only sets `img.meta.scale`), `outline` is nil. `.pcf.gz` and `.psfu.gz` load
|
||||
through the gzip. BDF and PSF also write, from any Font: a bitmap font as it is, an outline font rasterized at `px`.
|
||||
|
||||
```luau
|
||||
local bdf = assert(F.font.load(bdfText))
|
||||
assert(bdf.unitsPerEm == 8 and bdf.bitmap.glyphs[1].pixels)
|
||||
local g = bdf:rasterize(bdf:glyphIndex(65), 8)
|
||||
assert(g.format == "alpha8" and g.meta.advance == 5)
|
||||
local pcf = assert(F.font.load(pcfBytes))
|
||||
assert(pcf:glyphIndex(65) == bdf:glyphIndex(65))
|
||||
local psf = assert(F.font.load(psfBytes))
|
||||
assert(psf.meta.width == 8 and psf.meta.height == 16 and psf:glyphIndex(65) > 0)
|
||||
local fnt = assert(F.font.load(fntBytes))
|
||||
assert(fnt.unitsPerEm == 16)
|
||||
local console = assert(F.save(bdf, nil, { format = "psf" })) -- BDF -> PSF 2
|
||||
assert(F.font.load(console).meta.source.format == "psf")
|
||||
```
|
||||
|
||||
## Type 1, EOT and Hershey
|
||||
|
||||
PostScript Type 1 fonts (PFB and PFA) decrypt and run their charstrings into the same outlines as TrueType ones
|
||||
(glyph names map to Unicode through the Adobe Glyph List). EOT files unwrap the TrueType font inside (MTX-compressed
|
||||
ones are unsupported) and write. Hershey JHF fonts are stroke fonts: `outline` gives open paths (`meta.strokes`),
|
||||
`rasterize` strokes them.
|
||||
|
||||
```luau
|
||||
local t1 = assert(F.font.load(pfbBytes))
|
||||
assert(t1.unitsPerEm == 1000 and t1.info.family == "LMRoman10")
|
||||
assert(t1:rasterize(t1:glyphIndex(string.byte("g")), 32).width > 5)
|
||||
local eot = assert(F.font.load(eotBytes))
|
||||
assert(eot.meta.eot.familyName == "DejaVu Sans Mono" and eot:glyphIndex(65) > 0)
|
||||
local jhf = assert(F.font.load(jhfText))
|
||||
assert(jhf.meta.strokes and jhf:outline(1)[1].op == "moveTo")
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Notes |
|
||||
@@ -240,13 +280,21 @@ assert(bm:rasterize(bm:glyphIndex(string.byte("H"))))
|
||||
| woff | yes | - | |
|
||||
| woff2 | yes | - | |
|
||||
| bmfont (`.fnt`) | yes | yes | text, XML and binary descriptors; `bake` from any outline font |
|
||||
| bdf (`.bdf`) | yes | yes | BDF 2.1; writes Unicode BDF from any font |
|
||||
| pcf (`.pcf`, `.pcf.gz`) | yes | - | every glyph pad / bit / byte order |
|
||||
| psf (`.psf`, `.psfu`) | yes | yes | PSF 1 / 2 with Unicode tables |
|
||||
| fon (`.fon`, `.fnt`) | yes | - | Windows raster FNT 2 / 3, NE / PE .fon with several sizes |
|
||||
| type1 (`.pfb`, `.pfa`) | yes | - | Type 1 charstrings (flex, seac), StandardEncoding / custom encodings |
|
||||
| eot (`.eot`) | yes | yes | EOT 1.0 / 2.1 / 2.2, XOR; no MTX |
|
||||
| hershey (`.jhf`) | yes | - | stroke fonts |
|
||||
|
||||
See [FORMATS.md](../FORMATS.md) for the capability matrix.
|
||||
|
||||
## Gotchas
|
||||
|
||||
- **No hinting, no shaping.** Glyphs are rendered from the outlines without hinting; there is no GSUB (ligatures,
|
||||
contextual forms), no variable fonts (CFF2 / gvar return `UNSUPPORTED`) and no colour or bitmap glyphs.
|
||||
contextual forms), no variable fonts (CFF2 / gvar return `UNSUPPORTED`) and no colour glyphs or embedded bitmap
|
||||
strikes in TrueType fonts (bitmap font formats are separate: see above).
|
||||
- **`px` is the em size**, not the line height. The line height is `(ascent - descent + lineGap) * px / unitsPerEm`.
|
||||
- **Units differ by kind.** Outline fonts measure in font units; BMFont in pixels at its baked size. Use
|
||||
`font.unitsPerEm` for both: for a BMFont, `px / unitsPerEm` is the scale relative to the baked size.
|
||||
|
||||
Reference in new issue
Block a user