font/gofont: new packages for the Go font family.
See https://blog.golang.org/go-fonts for details. Change-Id: Ib7219ace9ffe49115d975439b85237472167a1c1 Reviewed-on: https://go-review.googlesource.com/33335 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
507b1a44bd
commit
b7f8df6bc0
99
font/gofont/gen.go
Normal file
99
font/gofont/gen.go
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
// Copyright 2016 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
// This program generates the subdirectories of Go packages that contain []byte
|
||||||
|
// versions of the TrueType font files under ./ttfs.
|
||||||
|
//
|
||||||
|
// Currently, "go run gen.go" needs to be run manually. This isn't done by the
|
||||||
|
// usual "go generate" mechanism as there isn't any other Go code in this
|
||||||
|
// directory (excluding sub-directories) to attach a "go:generate" line to.
|
||||||
|
//
|
||||||
|
// In any case, code generation should only need to happen when the underlying
|
||||||
|
// TTF files change, which isn't expected to happen frequently.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"go/format"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const suffix = ".ttf"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ttfs, err := os.Open("ttfs")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer ttfs.Close()
|
||||||
|
|
||||||
|
infos, err := ttfs.Readdir(-1)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, info := range infos {
|
||||||
|
ttfName := info.Name()
|
||||||
|
if !strings.HasSuffix(ttfName, suffix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
do(ttfName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func do(ttfName string) {
|
||||||
|
fontName := fontName(ttfName)
|
||||||
|
pkgName := pkgName(ttfName)
|
||||||
|
if err := os.Mkdir(pkgName, 0777); err != nil && !os.IsExist(err) {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
src, err := ioutil.ReadFile(filepath.Join("ttfs", ttfName))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
b := new(bytes.Buffer)
|
||||||
|
fmt.Fprintf(b, "// generated by go run gen.go; DO NOT EDIT\n\n")
|
||||||
|
fmt.Fprintf(b, "// Package %s provides the %q TrueType font\n// from the Go font family.\n", pkgName, fontName)
|
||||||
|
fmt.Fprintf(b, "package %s\n\n", pkgName)
|
||||||
|
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")
|
||||||
|
|
||||||
|
dst, err := format.Source(b.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(pkgName, "data.go"), dst, 0666); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fontName maps "Go-Regular.ttf" to "Go Regular".
|
||||||
|
func fontName(ttfName string) string {
|
||||||
|
s := ttfName[:len(ttfName)-len(suffix)]
|
||||||
|
s = strings.Replace(s, "-", " ", -1)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// pkgName maps "Go-Regular.ttf" to "goregular".
|
||||||
|
func pkgName(ttfName string) string {
|
||||||
|
s := ttfName[:len(ttfName)-len(suffix)]
|
||||||
|
s = strings.Replace(s, "-", "", -1)
|
||||||
|
s = strings.ToLower(s)
|
||||||
|
return s
|
||||||
|
}
|
8694
font/gofont/gobold/data.go
Normal file
8694
font/gofont/gobold/data.go
Normal file
File diff suppressed because it is too large
Load Diff
8876
font/gofont/gobolditalic/data.go
Normal file
8876
font/gofont/gobolditalic/data.go
Normal file
File diff suppressed because it is too large
Load Diff
8671
font/gofont/goitalic/data.go
Normal file
8671
font/gofont/goitalic/data.go
Normal file
File diff suppressed because it is too large
Load Diff
8907
font/gofont/gomedium/data.go
Normal file
8907
font/gofont/gomedium/data.go
Normal file
File diff suppressed because it is too large
Load Diff
9165
font/gofont/gomediumitalic/data.go
Normal file
9165
font/gofont/gomediumitalic/data.go
Normal file
File diff suppressed because it is too large
Load Diff
10057
font/gofont/gomono/data.go
Normal file
10057
font/gofont/gomono/data.go
Normal file
File diff suppressed because it is too large
Load Diff
10318
font/gofont/gomonobold/data.go
Normal file
10318
font/gofont/gomonobold/data.go
Normal file
File diff suppressed because it is too large
Load Diff
10859
font/gofont/gomonobolditalic/data.go
Normal file
10859
font/gofont/gomonobolditalic/data.go
Normal file
File diff suppressed because it is too large
Load Diff
10623
font/gofont/gomonoitalic/data.go
Normal file
10623
font/gofont/gomonoitalic/data.go
Normal file
File diff suppressed because it is too large
Load Diff
8446
font/gofont/goregular/data.go
Normal file
8446
font/gofont/goregular/data.go
Normal file
File diff suppressed because it is too large
Load Diff
BIN
font/gofont/ttfs/Go-Bold-Italic.ttf
Normal file
BIN
font/gofont/ttfs/Go-Bold-Italic.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Bold.ttf
Normal file
BIN
font/gofont/ttfs/Go-Bold.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Italic.ttf
Normal file
BIN
font/gofont/ttfs/Go-Italic.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Medium-Italic.ttf
Normal file
BIN
font/gofont/ttfs/Go-Medium-Italic.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Medium.ttf
Normal file
BIN
font/gofont/ttfs/Go-Medium.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Mono-Bold-Italic.ttf
Normal file
BIN
font/gofont/ttfs/Go-Mono-Bold-Italic.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Mono-Bold.ttf
Normal file
BIN
font/gofont/ttfs/Go-Mono-Bold.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Mono-Italic.ttf
Normal file
BIN
font/gofont/ttfs/Go-Mono-Italic.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Mono.ttf
Normal file
BIN
font/gofont/ttfs/Go-Mono.ttf
Normal file
Binary file not shown.
BIN
font/gofont/ttfs/Go-Regular.ttf
Normal file
BIN
font/gofont/ttfs/Go-Regular.ttf
Normal file
Binary file not shown.
36
font/gofont/ttfs/README
Normal file
36
font/gofont/ttfs/README
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
These fonts were created by the Bigelow & Holmes foundry specifically for the
|
||||||
|
Go project. See https://blog.golang.org/go-fonts for details.
|
||||||
|
|
||||||
|
They are licensed under the same open source license as the rest of the Go
|
||||||
|
project's software:
|
||||||
|
|
||||||
|
Copyright (c) 2016 Bigelow & Holmes Inc.. All rights reserved.
|
||||||
|
|
||||||
|
Distribution of this font is governed by the following license. If you do not
|
||||||
|
agree to this license, including the disclaimer, do not distribute or modify
|
||||||
|
this font.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of Google Inc. nor the names of its contributors may be
|
||||||
|
used to endorse or promote products derived from this software without
|
||||||
|
specific prior written permission.
|
||||||
|
|
||||||
|
DISCLAIMER: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Loading…
Reference in New Issue
Block a user