2022-01-18 19:29:53 +00:00
|
|
|
// Copyright (c) 2022 Sam Blenny
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
|
|
//
|
|
|
|
|
package lib
|
|
|
|
|
|
|
|
|
|
// Holds description of sprite sheet and character map for generating a font
|
|
|
|
|
type FontSpec struct {
|
|
|
|
|
Name string // Name of font
|
|
|
|
|
Sprites string // Which file holds the sprite sheet image with the grid of glyphs?
|
|
|
|
|
Size int // How many pixels on a side is each glyph (precondition: square glyphs)
|
|
|
|
|
Cols int // How many glyphs wide is the grid?
|
|
|
|
|
Gutter int // How many px between glyphs?
|
|
|
|
|
Border int // How many px wide are top and left borders?
|
|
|
|
|
Legal string // Credits or license notices to included in .rs font file comments
|
|
|
|
|
CSList []CharSpec // Map of grapheme clusters to glyph grid coordinates
|
|
|
|
|
RustOut string // Where should the generated rust source code go?
|
|
|
|
|
GlyphTrim string // How should bitmap glyphs be trimmed (proportional or CJK)?
|
2022-01-22 19:23:06 +00:00
|
|
|
LoaderOut string // Path to the split of the glyph data into the loader, to reduce the RAM load
|
2024-01-27 18:11:09 +00:00
|
|
|
Small bool // Is this font part of the "small" configuration set
|
2022-01-18 19:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Look up trim limits based on row & column in glyph grid
|
|
|
|
|
func (f FontSpec) TrimLimits(row int, col int) [4]int {
|
add Tall font face and support for 32x32 bitmaps
Thanks to @samblenny for getting the ball rolling on this.
This commit adds a "tall" font face which is somewhere in betwee
the Regular size (12 pts) and 2x Small size (18 pts). This is
a compromise between text density and readability that has been
missing for some time from the UI.
The 32x32 glyph support is "hacked in", in that an extra flag
has been added to support this special case, rather than either
(a) making the library more generic (e.g. supporting 8x, 16x, 32x, 64x
glyphs) or (b) adding more metadata to the font libraries so that
the bitmap pattern is automatically associated with the font (right
now the parameters are set by hand in blitstr2/fonts.rs).
This is a violation of the "zero, one, many" principle in coding,
but I'm waiving that because (a) 64x glyphs don't make sense on
our system...you're not going to be creating posters and headlines
on this device (ha ha I say this today, tomorrow I will get a PR
for a poster editor app that absolutely needs 64x glyphs) and (b)
the font subsystem is, at least for now, a fairly mature and
well-tested code base so a minor futzing seems more appropriate
than ripping everything out.
The point at which things should be greatly refactored is when
we consider supporting right-to-left scripts or scripts that
require complex ligatures. But I think for now the system as
writ covers 80% of humanity's language needs acceptably
(but not perfectly).
2023-07-05 04:43:44 +00:00
|
|
|
if f.Name == "Bold" || f.Name == "Regular" || f.Name == "Small" || f.Name == "Tall" {
|
2022-01-18 19:29:53 +00:00
|
|
|
// Space gets 4px width and 2px height
|
|
|
|
|
if col == 2 && row == 0 {
|
|
|
|
|
lr := (f.Size / 2) - 2
|
|
|
|
|
tb := (f.Size / 2) - 1
|
|
|
|
|
return [4]int{tb, lr, tb, lr}
|
|
|
|
|
}
|
|
|
|
|
} else if f.GlyphTrim == "CJK" {
|
|
|
|
|
// No trim for CJK
|
|
|
|
|
return [4]int{0, 0, 0, 0}
|
|
|
|
|
} else if f.GlyphTrim == "monospace" {
|
2022-01-20 16:34:12 +00:00
|
|
|
// Monospace gets 4 left, 4 right, none top & bottom
|
|
|
|
|
return [4]int{0, 4, 0, 4}
|
2022-01-18 19:29:53 +00:00
|
|
|
}
|
|
|
|
|
// Everything else gets max trim
|
|
|
|
|
return [4]int{f.Size, f.Size, f.Size, f.Size}
|
|
|
|
|
}
|