2010-05-04 01:54:43 +02:00
|
|
|
// Copyright 2010 The Freetype-Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by your choice of either the
|
2010-08-03 03:07:23 +02:00
|
|
|
// FreeType License or the GNU General Public License version 2 (or
|
|
|
|
// any later version), both of which can be found in the LICENSE file.
|
2010-05-04 01:54:43 +02:00
|
|
|
|
2015-08-12 06:41:46 +02:00
|
|
|
// +build ignore
|
|
|
|
//
|
|
|
|
// This build tag means that "go install github.com/golang/freetype/..."
|
|
|
|
// doesn't install this example program. Use "go run main.go" to run it.
|
|
|
|
|
2010-05-04 01:54:43 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
|
2015-08-12 06:30:01 +02:00
|
|
|
"github.com/golang/freetype/truetype"
|
2015-08-18 08:30:37 +02:00
|
|
|
"golang.org/x/image/math/fixed"
|
2010-05-04 01:54:43 +02:00
|
|
|
)
|
|
|
|
|
2013-10-04 09:03:59 +02:00
|
|
|
var fontfile = flag.String("fontfile", "../../testdata/luxisr.ttf", "filename of the ttf font")
|
2010-05-04 01:54:43 +02:00
|
|
|
|
|
|
|
func printBounds(b truetype.Bounds) {
|
|
|
|
fmt.Printf("XMin:%d YMin:%d XMax:%d YMax:%d\n", b.XMin, b.YMin, b.XMax, b.YMax)
|
|
|
|
}
|
|
|
|
|
2010-05-14 05:29:53 +02:00
|
|
|
func printGlyph(g *truetype.GlyphBuf) {
|
2010-05-04 01:54:43 +02:00
|
|
|
printBounds(g.B)
|
|
|
|
fmt.Print("Points:\n---\n")
|
|
|
|
e := 0
|
|
|
|
for i, p := range g.Point {
|
|
|
|
fmt.Printf("%4d, %4d", p.X, p.Y)
|
|
|
|
if p.Flags&0x01 != 0 {
|
|
|
|
fmt.Print(" on\n")
|
|
|
|
} else {
|
|
|
|
fmt.Print(" off\n")
|
|
|
|
}
|
|
|
|
if i+1 == int(g.End[e]) {
|
|
|
|
fmt.Print("---\n")
|
|
|
|
e++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
fmt.Printf("Loading fontfile %q\n", *fontfile)
|
|
|
|
b, err := ioutil.ReadFile(*fontfile)
|
|
|
|
if err != nil {
|
2010-10-15 05:02:11 +02:00
|
|
|
log.Println(err)
|
2010-05-04 01:54:43 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
font, err := truetype.Parse(b)
|
|
|
|
if err != nil {
|
2010-10-15 05:02:11 +02:00
|
|
|
log.Println(err)
|
2010-05-04 01:54:43 +02:00
|
|
|
return
|
|
|
|
}
|
2015-08-18 08:30:37 +02:00
|
|
|
fupe := fixed.Int26_6(font.FUnitsPerEm())
|
2012-07-25 14:10:25 +02:00
|
|
|
printBounds(font.Bounds(fupe))
|
|
|
|
fmt.Printf("FUnitsPerEm:%d\n\n", fupe)
|
2010-05-04 01:54:43 +02:00
|
|
|
|
|
|
|
c0, c1 := 'A', 'V'
|
|
|
|
|
|
|
|
i0 := font.Index(c0)
|
2012-07-25 14:10:25 +02:00
|
|
|
hm := font.HMetric(fupe, i0)
|
2010-05-14 05:29:53 +02:00
|
|
|
g := truetype.NewGlyphBuf()
|
2014-02-01 04:12:48 +01:00
|
|
|
err = g.Load(font, fupe, i0, truetype.NoHinting)
|
2010-05-04 01:54:43 +02:00
|
|
|
if err != nil {
|
2010-10-15 05:02:11 +02:00
|
|
|
log.Println(err)
|
2010-05-04 01:54:43 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Printf("'%c' glyph\n", c0)
|
|
|
|
fmt.Printf("AdvanceWidth:%d LeftSideBearing:%d\n", hm.AdvanceWidth, hm.LeftSideBearing)
|
|
|
|
printGlyph(g)
|
|
|
|
i1 := font.Index(c1)
|
2012-07-25 14:10:25 +02:00
|
|
|
fmt.Printf("\n'%c', '%c' Kerning:%d\n", c0, c1, font.Kerning(fupe, i0, i1))
|
2010-05-04 01:54:43 +02:00
|
|
|
}
|