-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 02068c9
Showing
20 changed files
with
270,357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Copyright ©2020 The go-fonts Authors. All rights reserved. | ||
|
||
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 the go-fonts project nor the names of its authors and | ||
contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
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 HOLDER 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
Digitized data copyright (c) 2010 Google Corporation | ||
with Reserved Font Arimo, Tinos and Cousine. | ||
Copyright (c) 2012 Red Hat, Inc. | ||
with Reserved Font Name Liberation. | ||
|
||
This Font Software is licensed under the SIL Open Font License, | ||
Version 1.1. | ||
|
||
This license is copied below, and is also available with a FAQ at: | ||
http://scripts.sil.org/OFL | ||
|
||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 | ||
|
||
PREAMBLE The goals of the Open Font License (OFL) are to stimulate | ||
worldwide development of collaborative font projects, to support the font | ||
creation efforts of academic and linguistic communities, and to provide | ||
a free and open framework in which fonts may be shared and improved in | ||
partnership with others. | ||
|
||
The OFL allows the licensed fonts to be used, studied, modified and | ||
redistributed freely as long as they are not sold by themselves. | ||
The fonts, including any derivative works, can be bundled, embedded, | ||
redistributed and/or sold with any software provided that any reserved | ||
names are not used by derivative works. The fonts and derivatives, | ||
however, cannot be released under any other type of license. The | ||
requirement for fonts to remain under this license does not apply to | ||
any document created using the fonts or their derivatives. | ||
|
||
|
||
|
||
DEFINITIONS | ||
"Font Software" refers to the set of files released by the Copyright | ||
Holder(s) under this license and clearly marked as such. | ||
This may include source files, build scripts and documentation. | ||
|
||
"Reserved Font Name" refers to any names specified as such after the | ||
copyright statement(s). | ||
|
||
"Original Version" refers to the collection of Font Software components | ||
as distributed by the Copyright Holder(s). | ||
|
||
"Modified Version" refers to any derivative made by adding to, deleting, | ||
or substituting ? in part or in whole ? | ||
any of the components of the Original Version, by changing formats or | ||
by porting the Font Software to a new environment. | ||
|
||
"Author" refers to any designer, engineer, programmer, technical writer | ||
or other person who contributed to the Font Software. | ||
|
||
|
||
PERMISSION & CONDITIONS | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of the Font Software, to use, study, copy, merge, embed, modify, | ||
redistribute, and sell modified and unmodified copies of the Font | ||
Software, subject to the following conditions: | ||
|
||
1) Neither the Font Software nor any of its individual components,in | ||
Original or Modified Versions, may be sold by itself. | ||
|
||
2) Original or Modified Versions of the Font Software may be bundled, | ||
redistributed and/or sold with any software, provided that each copy | ||
contains the above copyright notice and this license. These can be | ||
included either as stand-alone text files, human-readable headers or | ||
in the appropriate machine-readable metadata fields within text or | ||
binary files as long as those fields can be easily viewed by the user. | ||
|
||
3) No Modified Version of the Font Software may use the Reserved Font | ||
Name(s) unless explicit written permission is granted by the | ||
corresponding Copyright Holder. This restriction only applies to the | ||
primary font name as presented to the users. | ||
|
||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font | ||
Software shall not be used to promote, endorse or advertise any | ||
Modified Version, except to acknowledge the contribution(s) of the | ||
Copyright Holder(s) and the Author(s) or with their explicit written | ||
permission. | ||
|
||
5) The Font Software, modified or unmodified, in part or in whole, must | ||
be distributed entirely under this license, and must not be distributed | ||
under any other license. The requirement for fonts to remain under | ||
this license does not apply to any document created using the Font | ||
Software. | ||
|
||
|
||
|
||
TERMINATION | ||
This license becomes null and void if any of the above conditions are not met. | ||
|
||
|
||
|
||
DISCLAIMER | ||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER | ||
DEALINGS IN THE FONT SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# liberation | ||
|
||
[![GitHub release](https://img.shields.io/github/release/go-fonts/liberation.svg)](https://github.com/go-fonts/liberation/releases) | ||
[![GoDoc](https://godoc.org/github.com/go-fonts/liberation?status.svg)](https://godoc.org/github.com/go-fonts/liberation) | ||
[![License](https://img.shields.io/badge/License-BSD--3-blue.svg)](https://github.com/go-fonts/liberation/raw/master/LICENSE) | ||
|
||
`liberation` provides the [liberation](https://github.com/liberationfonts/liberation-fonts/) fonts as importable Go packages. | ||
|
||
The fonts are released under the [SIL Open Font](https://github.com/go-fonts/liberation/raw/master/LICENSE-SIL) license. | ||
The Go packages under the [BSD-3](https://github.com/go-fonts/liberation/raw/master/LICENSE) license. | ||
|
||
## Example | ||
|
||
```go | ||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/go-fonts/liberation/liberationserifregular" | ||
"golang.org/x/image/font/sfnt" | ||
) | ||
|
||
func Example() { | ||
ttf, err := sfnt.Parse(liberationserifregular.TTF) | ||
if err != nil { | ||
log.Fatalf("could not parse Liberation Serif font: %+v", err) | ||
} | ||
|
||
fmt.Printf("num glyphs: %d\n", ttf.NumGlyphs()) | ||
|
||
// Output: | ||
// num glyphs: 2589 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright ©2020 The go-fonts Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package liberation_test | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/go-fonts/liberation/liberationserifregular" | ||
"golang.org/x/image/font/sfnt" | ||
) | ||
|
||
func Example() { | ||
ttf, err := sfnt.Parse(liberationserifregular.TTF) | ||
if err != nil { | ||
log.Fatalf("could not parse Liberation Serif font: %+v", err) | ||
} | ||
|
||
fmt.Printf("num glyphs: %d\n", ttf.NumGlyphs()) | ||
|
||
// Output: | ||
// num glyphs: 2589 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// Copyright ©2020 The go-fonts Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// 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 | ||
|
||
import ( | ||
"archive/tar" | ||
"bytes" | ||
"compress/gzip" | ||
"flag" | ||
"fmt" | ||
"go/format" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
log.SetPrefix("liberation-gen: ") | ||
log.SetFlags(0) | ||
|
||
var ( | ||
src = flag.String("src", "https://github.com/liberationfonts/liberation-fonts/files/4178407/liberation-fonts-ttf-2.1.0.tar.gz", "remote tar-gz file holding TTF files for Liberation fonts") | ||
) | ||
|
||
flag.Parse() | ||
|
||
tmp, err := ioutil.TempDir("", "go-fonts-liberation-") | ||
if err != nil { | ||
log.Fatalf("could not create tmp dir: %+v", err) | ||
} | ||
|
||
var ( | ||
fname string | ||
) | ||
|
||
switch { | ||
case strings.HasPrefix(*src, "http://"), | ||
strings.HasPrefix(*src, "https://"): | ||
fname, err = fetch(tmp, *src) | ||
if err != nil { | ||
log.Fatalf("could not fetch Liberation sources: %+v", err) | ||
} | ||
default: | ||
fname = *src | ||
} | ||
|
||
f, err := os.Open(fname) | ||
if err != nil { | ||
log.Fatalf("could not open tar file: %+v", err) | ||
} | ||
defer f.Close() | ||
gr, err := gzip.NewReader(f) | ||
if err != nil { | ||
log.Fatalf("could not open gzip file: %+v", err) | ||
} | ||
defer gr.Close() | ||
|
||
log.Printf("inspecting tar file...") | ||
tr := tar.NewReader(gr) | ||
for { | ||
hdr, err := tr.Next() | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
log.Fatalf("could not read tar archive: %+v", err) | ||
} | ||
if !strings.HasSuffix(hdr.Name, suffix) { | ||
continue | ||
} | ||
err = gen(path.Base(hdr.Name), tr) | ||
if err != nil { | ||
log.Fatalf("could not generate font: %+v", err) | ||
} | ||
} | ||
} | ||
|
||
func fetch(tmp, src string) (string, error) { | ||
resp, err := http.Get(src) | ||
if err != nil { | ||
return "", fmt.Errorf("could not GET %q: %w", src, err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
f, err := os.Create(path.Join(tmp, "liberation.tar.gz")) | ||
if err != nil { | ||
return "", fmt.Errorf("could not create zip file: %w", err) | ||
} | ||
defer f.Close() | ||
|
||
_, err = io.Copy(f, resp.Body) | ||
if err != nil { | ||
return "", fmt.Errorf("could not copy zip file: %w", err) | ||
} | ||
|
||
err = f.Close() | ||
if err != nil { | ||
return "", fmt.Errorf("could not save zip file: %w", err) | ||
} | ||
|
||
return f.Name(), nil | ||
} | ||
|
||
func gen(fname string, tr *tar.Reader) error { | ||
log.Printf("generating fonts package for %q...", fname) | ||
|
||
raw := new(bytes.Buffer) | ||
_, err := io.Copy(raw, tr) | ||
if err != nil { | ||
return fmt.Errorf("could not download TTF file: %w", err) | ||
} | ||
|
||
err = do(fname, raw.Bytes()) | ||
if err != nil { | ||
return fmt.Errorf("could not generate package for %q: %w", fname, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func do(ttfName string, src []byte) error { | ||
fontName := fontName(ttfName) | ||
pkgName := pkgName(ttfName) | ||
if err := os.Mkdir(pkgName, 0777); err != nil && !os.IsExist(err) { | ||
return fmt.Errorf("could not create package dir %q: %w", pkgName, err) | ||
} | ||
|
||
b := new(bytes.Buffer) | ||
fmt.Fprintf(b, "// generated by go run gen-fonts.go; DO NOT EDIT\n\n") | ||
fmt.Fprintf(b, "// Package %s provides the %q TrueType font\n", pkgName, fontName) | ||
fmt.Fprintf(b, "// from the Liberation font family.\n") | ||
fmt.Fprintf(b, "package %[1]s // import \"github.com/go-fonts/liberation/%[1]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 { | ||
return fmt.Errorf("could not format source: %w", err) | ||
} | ||
|
||
err = ioutil.WriteFile(filepath.Join(pkgName, "data.go"), dst, 0666) | ||
if err != nil { | ||
return fmt.Errorf("could not write package source file: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
const suffix = ".ttf" | ||
|
||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/go-fonts/liberation | ||
|
||
go 1.13 | ||
|
||
require golang.org/x/image v0.0.0-20200430140353-33d19683fad8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw= | ||
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= | ||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright ©2020 The go-fonts Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package liberation holds TTF data of the Liberation fonts. | ||
package liberation // import "github.com/go-fonts/liberation" | ||
|
||
//go:generate go run ./gen-fonts.go |
Oops, something went wrong.