Skip to content

Commit

Permalink
Fix doubles and silence warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <[email protected]>
  • Loading branch information
gmlewis committed Jul 8, 2024
1 parent c00b28b commit 8f1de73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
37 changes: 24 additions & 13 deletions cmd/font2mbt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import (
var (
debug = flag.String("debug", "", "Turn on debugging info for specific glyph ('all' for all glyphs)")

outTemp = template.Must(template.New("out").Parse(mbtTemplate))
outTemp = template.Must(template.New("out").Funcs(funcMap).Parse(mbtTemplate))
funcMap = template.FuncMap{
"writeDouble": writeDouble,
}

digitRE = regexp.MustCompile(`^\d`)
)
Expand Down Expand Up @@ -297,13 +300,13 @@ func writeFont(fontData *webfont.FontData) {

lines = append(lines, fmt.Sprintf(`"%v": {`, mbtChar))
lines = append(lines, fmt.Sprintf(` char: "%v",`, mbtChar))
lines = append(lines, fmt.Sprintf(" horiz_adv_x: %v,", glyph.horizAdvX))
lines = append(lines, fmt.Sprintf(" horiz_adv_x: %v,", writeDouble(glyph.horizAdvX)))
// lines = append(lines, fmt.Sprintf(` gerber_lp: "%v",`, glyph.gerberLP))
lines = append(lines, fmt.Sprintf(` d: "%v",`, glyph.d))
lines = append(lines, fmt.Sprintf(" xmin: %v,", glyph.xmin))
lines = append(lines, fmt.Sprintf(" ymin: %v,", glyph.ymin))
lines = append(lines, fmt.Sprintf(" xmax: %v,", glyph.xmax))
lines = append(lines, fmt.Sprintf(" ymax: %v,", glyph.ymax))
lines = append(lines, fmt.Sprintf(" xmin: %v,", writeDouble(glyph.xmin)))
lines = append(lines, fmt.Sprintf(" ymin: %v,", writeDouble(glyph.ymin)))
lines = append(lines, fmt.Sprintf(" xmax: %v,", writeDouble(glyph.xmax)))
lines = append(lines, fmt.Sprintf(" ymax: %v,", writeDouble(glyph.ymax)))
lines = append(lines, "},")
}

Expand All @@ -319,8 +322,16 @@ func writeFont(fontData *webfont.FontData) {
must(os.MkdirAll(fontDir, 0755))
filename := filepath.Join(fontDir, fmt.Sprintf("%v.mbt", fontData.Font.ID))
must(os.WriteFile(filename, buf.Bytes(), 0644))
filename = filepath.Join(fontDir, "mod.pkg.json")
must(os.WriteFile(filename, []byte(modPkgJSON), 0644))
filename = filepath.Join(fontDir, "moon.pkg.json")
must(os.WriteFile(filename, []byte(moonPkgJSON), 0644))
}

func writeDouble(f float64) string {
s := fmt.Sprintf("%v", f)
if strings.Contains(s, ".") {
return s
}
return s + ".0"
}

func must(err error) {
Expand All @@ -344,15 +355,15 @@ let glyphs : Map[String, @fonts.Glyph] = {
pub let font : @fonts.Font = {
id: "{{ .ID }}",
horiz_adv_x: {{ .HorizAdvX }},
units_per_em: {{ .FontFace.UnitsPerEm }},
ascent: {{ .FontFace.Ascent }},
descent: {{ .FontFace.Descent }},
horiz_adv_x: {{ .HorizAdvX | writeDouble }},
units_per_em: {{ .FontFace.UnitsPerEm | writeDouble }},
ascent: {{ .FontFace.Ascent | writeDouble }},
descent: {{ .FontFace.Descent | writeDouble }},
glyphs,
}
`

var modPkgJSON = `{
var moonPkgJSON = `{
"import": [
"gmlewis/moonbit-fonts/fonts"
]
Expand Down
2 changes: 1 addition & 1 deletion webfont/webfont.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ParseNeededGlyphs(fontData *FontData, message string, processor Processor)
}
dst++
}
log.Printf("WARNING: unicode %+q found multiple times in font. Moving code point to %+q", r, dst)
// log.Printf("WARNING: unicode %+q found multiple times in font. Moving code point to %+q", r, dst)
rs := fmt.Sprintf("%c", dst)
g.Unicode = &rs
dedup[dst] = g
Expand Down

0 comments on commit 8f1de73

Please sign in to comment.