Skip to content

Commit

Permalink
Update fonts
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
  • Loading branch information
gmlewis committed Jul 8, 2024
1 parent 184f8d2 commit 75ed666
Show file tree
Hide file tree
Showing 88 changed files with 245 additions and 33 deletions.
79 changes: 77 additions & 2 deletions README.md

Large diffs are not rendered by default.

32 changes: 21 additions & 11 deletions cmd/font2go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ var (

outTemp = template.Must(template.New("out").Funcs(funcMap).Parse(goTemplate))
funcMap = template.FuncMap{
"floats": floats,
"orEmpty": orEmpty,
"viewFilter": viewFilter,
"firstLetter": firstLetter,
"floats": floats,
"orEmpty": orEmpty,
"viewFilter": viewFilter,
}
readmeTemp = template.Must(template.New("readme").Parse(readmeTemplate))
readmeTemp = template.Must(template.New("readme").Funcs(funcMap).Parse(readmeTemplate))

digitRE = regexp.MustCompile(`^\d`)
)
Expand All @@ -56,12 +57,7 @@ func main() {
}
}

fontData.Font.ID = strings.ToLower(fontData.Font.ID)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "-", "_", -1)
fontData.Font.ID = strings.TrimSuffix(fontData.Font.ID, "_")
if digitRE.MatchString(fontData.Font.ID) {
fontData.Font.ID = "f" + fontData.Font.ID
}
sanitizeFontName(fontData)

fontDir := filepath.Join(prefix, fontData.Font.ID)
if err := os.MkdirAll(fontDir, 0755); err != nil {
Expand All @@ -82,6 +78,16 @@ func main() {
fmt.Println("Done.")
}

func sanitizeFontName(fontData *webfont.FontData) {
fontData.Font.ID = strings.ToLower(fontData.Font.ID)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "'", "", -1)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "-", "_", -1)
fontData.Font.ID = strings.TrimSuffix(fontData.Font.ID, "_")
if digitRE.MatchString(fontData.Font.ID) {
fontData.Font.ID = "f" + fontData.Font.ID
}
}

// processor implements the webfont.Processor interface.
type processor struct {
gs *glyphs.Glyphs
Expand Down Expand Up @@ -227,6 +233,10 @@ func orEmpty(s *string) string {
return fmt.Sprintf("%q", *s)
}

func firstLetter(s string) string {
return s[0:1]
}

func floats(f []float64) string {
return fmt.Sprintf("%#v", f)
}
Expand All @@ -240,7 +250,7 @@ To use this font in your code, simply import it:
` + "```" + `go
import (
"github.com/gmlewis/go-fonts/fonts"
_ "github.com/gmlewis/go-fonts/fonts/{{ .ID }}"
_ "github.com/gmlewis/go-fonts-{{ .ID | firstLetter }}/fonts/{{ .ID }}"
)
func main() {
Expand Down
17 changes: 11 additions & 6 deletions cmd/font2irmf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ func main() {
}
}

fontData.Font.ID = strings.ToLower(fontData.Font.ID)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "-", "_", -1)
fontData.Font.ID = strings.TrimSuffix(fontData.Font.ID, "_")
if digitRE.MatchString(fontData.Font.ID) {
fontData.Font.ID = "f" + fontData.Font.ID
}
sanitizeFontName(fontData)

outFilename := fmt.Sprintf("%v.irmf", fontData.Font.ID)
w, err := os.Create(outFilename)
Expand All @@ -71,6 +66,16 @@ func main() {
fmt.Println("Done.")
}

func sanitizeFontName(fontData *webfont.FontData) {
fontData.Font.ID = strings.ToLower(fontData.Font.ID)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "'", "", -1)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "-", "_", -1)
fontData.Font.ID = strings.TrimSuffix(fontData.Font.ID, "_")
if digitRE.MatchString(fontData.Font.ID) {
fontData.Font.ID = "f" + fontData.Font.ID
}
}

func writeFont(w io.Writer, fontData *webfont.FontData, msg string) {
buf := &bytes.Buffer{}
rec := &recorder{f: buf, dedup: map[rune]*webfont.Glyph{}}
Expand Down
17 changes: 11 additions & 6 deletions cmd/font2lua/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,24 @@ func main() {
}
}

fontData.Font.ID = strings.ToLower(fontData.Font.ID)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "-", "_", -1)
fontData.Font.ID = strings.TrimSuffix(fontData.Font.ID, "_")
if digitRE.MatchString(fontData.Font.ID) {
fontData.Font.ID = "f" + fontData.Font.ID
}
sanitizeFontName(fontData)

writeFont(fontData)
}

fmt.Println("Done.")
}

func sanitizeFontName(fontData *webfont.FontData) {
fontData.Font.ID = strings.ToLower(fontData.Font.ID)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "'", "", -1)
fontData.Font.ID = strings.Replace(fontData.Font.ID, "-", "_", -1)
fontData.Font.ID = strings.TrimSuffix(fontData.Font.ID, "_")
if digitRE.MatchString(fontData.Font.ID) {
fontData.Font.ID = "f" + fontData.Font.ID
}
}

// processor implements the webfont.Processor interface.
type processor struct {
current *glyphT
Expand Down
4 changes: 2 additions & 2 deletions cmd/make-puzzle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/gmlewis/go-fonts/cmd/make-puzzle
go 1.22.4

require (
github.com/gmlewis/go-fonts v0.18.0
github.com/gmlewis/go-fonts v0.19.0
github.com/gmlewis/go-fonts-b/fonts/baloo v0.1.0
)

Expand All @@ -17,6 +17,6 @@ require (
google.golang.org/protobuf v1.34.2 // indirect
)

replace github.com/gmlewis/go-fonts v0.18.0 => ../../
replace github.com/gmlewis/go-fonts v0.19.0 => ../../

replace github.com/gmlewis/go-fonts-b/fonts/baloo v0.1.0 => ../../../go-fonts-b/fonts/baloo
4 changes: 2 additions & 2 deletions cmd/render-fonts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/gmlewis/go-fonts/cmd/make-puzzle
go 1.22.4

require (
github.com/gmlewis/go-fonts v0.18.0
github.com/gmlewis/go-fonts v0.19.0
github.com/gmlewis/go-fonts/fonts/latoregular v0.0.0-20240626233958-3409c190883f
)

Expand All @@ -17,6 +17,6 @@ require (
google.golang.org/protobuf v1.34.2 // indirect
)

replace github.com/gmlewis/go-fonts v0.18.0 => ../../
replace github.com/gmlewis/go-fonts v0.19.0 => ../../

replace github.com/gmlewis/go-fonts-l/fonts/latoregular v0.1.0 => ../../../go-fonts-l/fonts/latoregular
2 changes: 1 addition & 1 deletion cmd/render-fonts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"sort"
"strings"

_ "github.com/gmlewis/go-fonts-l/fonts/latoregular"
. "github.com/gmlewis/go-fonts/fonts"
_ "github.com/gmlewis/go-fonts/fonts/latoregular"
)

var (
Expand Down
115 changes: 115 additions & 0 deletions cmd/update-font-samples/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// update-font-samples is used by the maintainer of the repos to update the
// README.md and images directories of all the go-fonts* repos.
package main

import (
"bytes"
"fmt"
"log"
"os"
"path/filepath"
"strings"
"text/template"
)

const (
fontDirs = "abcdefghijklmnopqrstuvwyz" // no 'x' fonts currently
splitStr = "## Font samples\n"
)

var (
samplesTemplate = template.Must(template.New("samplesTemplateStr").Funcs(funcMap).Parse(samplesTemplateStr))
)

func main() {
masterSamples, err := filepath.Glob("images/sample_*.png")
must(err)

if len(masterSamples) == 0 {
log.Fatal("No images/sample_*.png files found. Aborting.")
}

allFonts := make([]string, 0, len(masterSamples))
for _, sample := range masterSamples {
font := strings.TrimSuffix(strings.TrimPrefix(sample, "images/sample_"), ".png")
allFonts = append(allFonts, font)
}

var allSamples bytes.Buffer
must(samplesTemplate.Execute(&allSamples, allFonts))

c := &client{
allSamples: allSamples.String(),
masterSamples: map[string]bool{},
}
for _, name := range masterSamples {
c.masterSamples[name] = true
}

c.updateReadme("README.md")

for _, r := range fontDirs {
c.updateFontDir("../go-fonts-" + string(r))
}
}

type client struct {
allSamples string
masterSamples map[string]bool
}

func (c *client) updateFontDir(dirPrefix string) {
dirName := filepath.Join(dirPrefix, "images/sample_*.png")

c.updateReadme(filepath.Join(dirPrefix, "README.md"))

fontSamples, err := filepath.Glob(dirName)
must(err)

seen := map[string]bool{}
for _, fullname := range fontSamples {
filename := strings.TrimPrefix(fullname, dirPrefix+"/")
seen[filename] = true
if _, ok := c.masterSamples[filename]; !ok {
log.Fatalf("Found %v which is missing in go-fonts directory! Please fix this.", fullname)
}
}

for filename := range c.masterSamples {
if _, ok := seen[filename]; !ok {
log.Printf("Copying %v to %v/images ...", filename, dirPrefix)
}
b, err := os.ReadFile(filename)
must(err)
outFile := filepath.Join(dirPrefix, filename)
must(os.WriteFile(outFile, b, 0644))
}
}

func (c *client) updateReadme(filename string) {
b, err := os.ReadFile(filename)
must(err)
parts := strings.Split(string(b), splitStr)
if len(parts) != 2 {
log.Fatalf("Error parsing %v, got %v parts", filename, len(parts))
}
outStr := fmt.Sprintf("%v%v%v", parts[0], splitStr, c.allSamples)
must(os.WriteFile(filename, []byte(outStr), 0644))
}

func must(err error) {
if err != nil {
log.Fatal(err)
}
}

var funcMap = map[string]any{
"firstLetter": firstLetter,
}

func firstLetter(s string) string {
return s[0:1]
}

var samplesTemplateStr = `{{ range . }}[![{{ . }}](images/sample_{{ . }}.png)](https://github.com/gmlewis/go-fonts-{{ . | firstLetter }}/tree/master/fonts/{{ . }})
{{ end }}`
4 changes: 2 additions & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.4

require (
github.com/fogleman/gg v1.3.0
github.com/gmlewis/go-fonts v0.18.0
github.com/gmlewis/go-fonts v0.19.0
github.com/gmlewis/go-fonts-c/fonts/carrelectronicdingbats v0.1.0
github.com/gmlewis/go-fonts-f/fonts/freeserif v0.1.0
github.com/gmlewis/go-fonts-l/fonts/latoregular v0.1.0
Expand All @@ -27,7 +27,7 @@ require (
google.golang.org/protobuf v1.34.2 // indirect
)

replace github.com/gmlewis/go-fonts v0.18.0 => ../
replace github.com/gmlewis/go-fonts v0.19.0 => ../

replace github.com/gmlewis/go-fonts-c/fonts/carrelectronicdingbats v0.1.0 => ../../go-fonts-c/fonts/carrelectronicdingbats

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gmlewis/go-fonts

go 1.22.4
go 1.22.5

require (
github.com/fogleman/gg v1.3.0
Expand Down
Binary file added images/sample_actionjackson.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_angstrom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_antelopeh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_antimonyblue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_boringboron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_codon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_colophondbz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_conventionalwisdom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_cosinekatie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_davis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_dissonant_fractured.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_doctorazul.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_donner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_douglasadamshand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_dysprosium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_epilog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_f32768no.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_f7hours.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_faraday.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_fresnel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_gaussjordan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_geodesic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_germs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_greenwichmeantime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_guildofprofessionalactors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sample_hockeyislif.png
Binary file added images/sample_hydrogenscore.png
Binary file added images/sample_initial.png
Binary file added images/sample_isuckatgolf.png
Binary file added images/sample_leland.png
Binary file added images/sample_lelandtext.png
Binary file added images/sample_levity.png
Binary file added images/sample_lexographer.png
Binary file added images/sample_linear.png
Binary file added images/sample_mayqueen.png
Binary file added images/sample_melaniegirly.png
Binary file added images/sample_metalanguage.png
Binary file added images/sample_musicdbz.png
Binary file added images/sample_naturallog.png
Binary file added images/sample_nonblockingsocket.png
Binary file added images/sample_nullpointer.png
Binary file added images/sample_oneconstant.png
Binary file added images/sample_opticbot.png
Binary file added images/sample_pinball_data.png
Binary file added images/sample_potassiumscandal.png
Binary file added images/sample_prefix.png
Binary file added images/sample_progbot.png
Binary file added images/sample_proteron.png
Binary file added images/sample_ransom.png
Binary file added images/sample_realbttsoief.png
Binary file added images/sample_resurgence.png
Binary file added images/sample_robotteacher.png
Binary file added images/sample_secret_labs.png
Binary file added images/sample_signaltonoise.png
Binary file added images/sample_snootorgpixel10.png
Binary file added images/sample_submerged.png
Binary file added images/sample_technetium.png
Binary file added images/sample_tetanus.png
Binary file added images/sample_thisboringparty.png
Binary file added images/sample_toast.png
Binary file added images/sample_tombats6.png
Binary file added images/sample_tombats7.png
Binary file added images/sample_tombats_one.png
Binary file added images/sample_tombatsfour.png
Binary file added images/sample_tombatssmilies.png
Binary file added images/sample_tombatsthree.png
Binary file added images/sample_tombots.png
Binary file added images/sample_tommysfirstalphabet.png
Binary file added images/sample_toms_handwriting.png
Binary file added images/sample_toms_newroman.png
Binary file added images/sample_tomsheadache.png
Binary file added images/sample_tuesday.png
Binary file added images/sample_two_turtledoves.png
Binary file added images/sample_valium.png
Binary file added images/sample_wolveslower.png
Binary file added images/sample_yikatu.png
Binary file added images/sample_zincboomerang.png
2 changes: 2 additions & 0 deletions update-font-samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash -e
go run cmd/update-font-samples/main.go

0 comments on commit 75ed666

Please sign in to comment.