Skip to content

Commit

Permalink
all: use embed
Browse files Browse the repository at this point in the history
Fixes #1.

Signed-off-by: Sebastien Binet <binet@cern.ch>
  • Loading branch information
sbinet committed May 4, 2023
1 parent 9754f0a commit 4719a52
Show file tree
Hide file tree
Showing 12 changed files with 6,157 additions and 145,077 deletions.
26 changes: 15 additions & 11 deletions gen-fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main
Expand All @@ -16,7 +17,6 @@ import (
"fmt"
"go/format"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand All @@ -29,7 +29,11 @@ func main() {
log.SetFlags(0)

var (
tmpl = flag.String("src", "https://github.com/stipub/stixfonts/raw/master/OTF", "remote directory holding OTF files for STIX fonts")
tmpl = flag.String(
"src",
"https://github.com/stipub/stixfonts/raw/v2.13b171/fonts/static_otf",
"remote directory holding OTF files for STIX fonts",
)
)

flag.Parse()
Expand Down Expand Up @@ -85,26 +89,26 @@ func do(ttfName string, src []byte) error {
fmt.Fprintf(b, "// Package %s provides the %q TrueType font\n", pkgName, fontName)
fmt.Fprintf(b, "// from the STIX2 font family. It is %s font.\n", desc)
fmt.Fprintf(b, "package %[1]s // import \"github.com/go-fonts/stix/%[1]s\"\n\n", pkgName)
fmt.Fprintf(b, "import _ \"embed\"\n")
fmt.Fprintf(b, "// TTF is the data for the %q TrueType font.\n", fontName)
fmt.Fprintf(b, "var TTF = []byte{")
for i, x := range src {
if i&15 == 0 {
b.WriteByte('\n')
}
fmt.Fprintf(b, "%#02x,", x)
}
fmt.Fprintf(b, "\n}\n")
fmt.Fprintf(b, "//\n//go:embed %s\n", ttfName)
fmt.Fprintf(b, "var TTF []byte\n")

dst, err := format.Source(b.Bytes())
if err != nil {
return fmt.Errorf("could not format source: %w", err)
}

err = ioutil.WriteFile(filepath.Join(pkgName, "data.go"), dst, 0666)
err = os.WriteFile(filepath.Join(pkgName, "data.go"), dst, 0666)
if err != nil {
return fmt.Errorf("could not write package source file: %w", err)
}

err = os.WriteFile(filepath.Join(pkgName, ttfName), src, 0666)
if err != nil {
return fmt.Errorf("could not write package TTF file: %w", err)
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions stix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

// Package stix holds TTF data of the STIX2 fonts.
package stix

//go:generate go run ./gen-fonts.go
1,223 changes: 1,223 additions & 0 deletions stix2math/STIX2Math.otf

Large diffs are not rendered by default.

50,521 changes: 5 additions & 50,516 deletions stix2math/data.go

Large diffs are not rendered by default.

1,223 changes: 1,223 additions & 0 deletions stix2textbold/STIX2Text-Bold.otf

Large diffs are not rendered by default.

23,025 changes: 5 additions & 23,020 deletions stix2textbold/data.go

Large diffs are not rendered by default.

1,223 changes: 1,223 additions & 0 deletions stix2textbolditalic/STIX2Text-BoldItalic.otf

Large diffs are not rendered by default.

24,439 changes: 5 additions & 24,434 deletions stix2textbolditalic/data.go

Large diffs are not rendered by default.

1,223 changes: 1,223 additions & 0 deletions stix2textitalic/STIX2Text-Italic.otf

Large diffs are not rendered by default.

24,200 changes: 5 additions & 24,195 deletions stix2textitalic/data.go

Large diffs are not rendered by default.

1,223 changes: 1,223 additions & 0 deletions stix2textregular/STIX2Text-Regular.otf

Large diffs are not rendered by default.

22,906 changes: 5 additions & 22,901 deletions stix2textregular/data.go

Large diffs are not rendered by default.

0 comments on commit 4719a52

Please sign in to comment.