forked from google/gxui
/
glyph.go
54 lines (46 loc) · 1.8 KB
/
glyph.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2015 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.
package gl
import (
"github.com/google/gxui/math"
"code.google.com/p/freetype-go/freetype/truetype"
)
// ╾──────w──────╼
// min╔═════════════╗
// ╿║ ▒███▒ ║ ╿
// │║ █▒ ▒█ ║ │
// │║ █░ ▒█ ║ │ ascent
// │║ █░ ░█ ║ │
// │║ █▒ ▒█ ║ │
// │ h║ ░█████▒▒█ ║ ╽
// ──┼───┼╫───────────█─╫───── +x
// origin│ │║ ▒█ ║
// │ │║ ██▒ ░██ ║
// │ ╽║ ░█████░ ║
// │ ╚═════════════╝max
// ╾────────────────────╼
// │ advance
// │
// │
// +y
//
// y-axis is flipped from freetype's.
// See: http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html#section-4
type glyph truetype.GlyphBuf
func (g *glyph) size(r Resolution) math.Size {
w := int(((g.B.XMax-g.B.XMin)*int32(r) + 0x3FFFFF) >> 22)
h := int(((g.B.YMax-g.B.YMin)*int32(r) + 0x3FFFFF) >> 22)
return math.Size{W: w, H: h}
}
func (g *glyph) rect(r Resolution) math.Rect {
x := int((g.B.XMin * int32(r)) >> 22)
y := -int((g.B.YMax * int32(r)) >> 22)
return g.size(r).Rect().Offset(math.Point{X: x, Y: y})
}
func (g *glyph) advance(r Resolution) int {
return int((g.AdvanceWidth*int32(r) + 0x3FFFFF) >> 22)
}
func (g *glyph) advanceDips() int {
return int((g.AdvanceWidth + 0x3f) >> 6)
}