2012-05-07 04:04:52 +02:00
|
|
|
// Copyright 2010 The Freetype-Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by your choice of either the
|
|
|
|
// FreeType License or the GNU General Public License version 2 (or
|
|
|
|
// any later version), both of which can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package truetype
|
|
|
|
|
|
|
|
// A Point is a co-ordinate pair plus whether it is ``on'' a contour or an
|
|
|
|
// ``off'' control point.
|
|
|
|
type Point struct {
|
2012-07-25 14:10:25 +02:00
|
|
|
X, Y int32
|
2012-05-07 04:04:52 +02:00
|
|
|
// The Flags' LSB means whether or not this Point is ``on'' the contour.
|
|
|
|
// Other bits are reserved for internal use.
|
2012-07-25 14:10:25 +02:00
|
|
|
Flags uint32
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// A GlyphBuf holds a glyph's contours. A GlyphBuf can be re-used to load a
|
|
|
|
// series of glyphs from a Font.
|
|
|
|
type GlyphBuf struct {
|
2013-09-24 14:06:47 +02:00
|
|
|
// B is the glyph's bounding box.
|
2012-05-07 04:04:52 +02:00
|
|
|
B Bounds
|
2013-08-31 08:08:40 +02:00
|
|
|
// Point contains all Points from all contours of the glyph. If a
|
|
|
|
// Hinter was used to load a glyph then Unhinted contains those
|
|
|
|
// Points before they were hinted, and InFontUnits contains those
|
2013-09-24 14:06:47 +02:00
|
|
|
// Points before they were hinted and scaled.
|
|
|
|
Point, Unhinted, InFontUnits []Point
|
|
|
|
// End is the point indexes of the end point of each countour. The
|
|
|
|
// length of End is the number of contours in the glyph. The i'th
|
2012-05-07 04:04:52 +02:00
|
|
|
// contour consists of points Point[End[i-1]:End[i]], where End[-1]
|
|
|
|
// is interpreted to mean zero.
|
|
|
|
End []int
|
2013-10-16 09:54:54 +02:00
|
|
|
|
|
|
|
font *Font
|
|
|
|
hinter *Hinter
|
|
|
|
scale int32
|
|
|
|
// pp1x is the X co-ordinate of the first phantom point.
|
2013-11-04 23:58:40 +01:00
|
|
|
pp1x int32
|
|
|
|
// metricsSet is whether the glyph's metrics have been set yet. For a
|
|
|
|
// compound glyph, a sub-glyph may override the outer glyph's metrics.
|
2013-10-16 09:54:54 +02:00
|
|
|
metricsSet bool
|
2013-11-04 23:58:40 +01:00
|
|
|
// tmp is a scratch buffer.
|
|
|
|
tmp []Point
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Flags for decoding a glyph's contours. These flags are documented at
|
|
|
|
// http://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html.
|
|
|
|
const (
|
|
|
|
flagOnCurve = 1 << iota
|
|
|
|
flagXShortVector
|
|
|
|
flagYShortVector
|
|
|
|
flagRepeat
|
|
|
|
flagPositiveXShortVector
|
|
|
|
flagPositiveYShortVector
|
2013-08-31 08:08:40 +02:00
|
|
|
|
|
|
|
// The remaining flags are for internal use.
|
|
|
|
flagTouchedX
|
|
|
|
flagTouchedY
|
2012-05-07 04:04:52 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// The same flag bits (0x10 and 0x20) are overloaded to have two meanings,
|
|
|
|
// dependent on the value of the flag{X,Y}ShortVector bits.
|
|
|
|
const (
|
|
|
|
flagThisXIsSame = flagPositiveXShortVector
|
|
|
|
flagThisYIsSame = flagPositiveYShortVector
|
|
|
|
)
|
|
|
|
|
2013-10-16 09:54:54 +02:00
|
|
|
// Load loads a glyph's contours from a Font, overwriting any previously
|
|
|
|
// loaded contours for this GlyphBuf. scale is the number of 26.6 fixed point
|
|
|
|
// units in 1 em. The Hinter is optional; if non-nil, then the resulting glyph
|
|
|
|
// will be hinted by the Font's bytecode instructions.
|
|
|
|
func (g *GlyphBuf) Load(f *Font, scale int32, i Index, h *Hinter) error {
|
|
|
|
g.B = Bounds{}
|
|
|
|
g.Point = g.Point[:0]
|
|
|
|
g.Unhinted = g.Unhinted[:0]
|
|
|
|
g.InFontUnits = g.InFontUnits[:0]
|
|
|
|
g.End = g.End[:0]
|
|
|
|
g.font = f
|
|
|
|
g.hinter = h
|
|
|
|
g.scale = scale
|
|
|
|
g.pp1x = 0
|
|
|
|
g.metricsSet = false
|
|
|
|
|
|
|
|
if h != nil {
|
|
|
|
if err := h.init(f, scale); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := g.load(0, i, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if g.pp1x != 0 {
|
|
|
|
for i := range g.Point {
|
|
|
|
g.Point[i].X -= g.pp1x
|
|
|
|
}
|
|
|
|
// TODO: also adjust g.B?
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GlyphBuf) load(recursion int32, i Index, useMyMetrics bool) (err error) {
|
2013-10-17 01:21:20 +02:00
|
|
|
// The recursion limit here is arbitrary, but defends against malformed glyphs.
|
|
|
|
if recursion >= 32 {
|
2013-10-16 09:54:54 +02:00
|
|
|
return UnsupportedError("excessive compound glyph recursion")
|
|
|
|
}
|
|
|
|
// Find the relevant slice of g.font.glyf.
|
|
|
|
var g0, g1 uint32
|
|
|
|
if g.font.locaOffsetFormat == locaOffsetFormatShort {
|
|
|
|
g0 = 2 * uint32(u16(g.font.loca, 2*int(i)))
|
|
|
|
g1 = 2 * uint32(u16(g.font.loca, 2*int(i)+2))
|
|
|
|
} else {
|
|
|
|
g0 = u32(g.font.loca, 4*int(i))
|
|
|
|
g1 = u32(g.font.loca, 4*int(i)+4)
|
|
|
|
}
|
|
|
|
if g0 == g1 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
glyf := g.font.glyf[g0:g1]
|
|
|
|
// Decode the contour end indices.
|
|
|
|
ne := int(int16(u16(glyf, 0)))
|
|
|
|
b := Bounds{
|
|
|
|
XMin: int32(int16(u16(glyf, 2))),
|
|
|
|
YMin: int32(int16(u16(glyf, 4))),
|
|
|
|
XMax: int32(int16(u16(glyf, 6))),
|
|
|
|
YMax: int32(int16(u16(glyf, 8))),
|
|
|
|
}
|
|
|
|
uhm, pp1x := g.font.unscaledHMetric(i), int32(0)
|
|
|
|
if ne < 0 {
|
|
|
|
if ne != -1 {
|
|
|
|
// http://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html says that
|
|
|
|
// "the values -2, -3, and so forth, are reserved for future use."
|
|
|
|
return UnsupportedError("negative number of contours")
|
|
|
|
}
|
|
|
|
pp1x = g.font.scale(g.scale * (b.XMin - uhm.LeftSideBearing))
|
2013-11-04 23:58:40 +01:00
|
|
|
if err := g.loadCompound(recursion, b, uhm, i, glyf, useMyMetrics); err != nil {
|
2013-10-16 09:54:54 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
np0, ne0 := len(g.Point), len(g.End)
|
|
|
|
program := g.loadSimple(glyf, ne)
|
2013-11-04 23:58:40 +01:00
|
|
|
g.addPhantomsAndScale(b, uhm, i, np0, g.hinter != nil)
|
2013-10-16 09:54:54 +02:00
|
|
|
if g.hinter != nil {
|
|
|
|
if len(program) != 0 {
|
|
|
|
err := g.hinter.run(
|
|
|
|
program,
|
|
|
|
g.Point[np0:],
|
|
|
|
g.Unhinted[np0:],
|
|
|
|
g.InFontUnits[np0:],
|
|
|
|
g.End[ne0:],
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Drop the four phantom points.
|
|
|
|
pp1x = g.Point[len(g.Point)-4].X
|
|
|
|
if g.hinter != nil {
|
2013-10-29 10:59:39 +01:00
|
|
|
if dx := ((pp1x + 32) &^ 63) - pp1x; dx != 0 {
|
|
|
|
for i := np0; i < len(g.Point); i++ {
|
|
|
|
g.Point[i].X += dx
|
|
|
|
}
|
2013-10-29 21:50:48 +01:00
|
|
|
pp1x = g.Point[len(g.Point)-4].X
|
2013-10-29 10:59:39 +01:00
|
|
|
}
|
2013-10-29 21:50:48 +01:00
|
|
|
g.InFontUnits = g.InFontUnits[:len(g.InFontUnits)-4]
|
|
|
|
g.Unhinted = g.Unhinted[:len(g.Unhinted)-4]
|
2013-10-16 09:54:54 +02:00
|
|
|
}
|
2013-10-29 21:50:48 +01:00
|
|
|
g.Point = g.Point[:len(g.Point)-4]
|
2013-10-16 09:54:54 +02:00
|
|
|
if np0 != 0 {
|
|
|
|
// The hinting program expects the []End values to be indexed relative
|
|
|
|
// to the inner glyph, not the outer glyph, so we delay adding np0 until
|
|
|
|
// after the hinting program (if any) has run.
|
|
|
|
for i := ne0; i < len(g.End); i++ {
|
|
|
|
g.End[i] += np0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if useMyMetrics && !g.metricsSet {
|
|
|
|
g.metricsSet = true
|
|
|
|
g.B.XMin = g.font.scale(g.scale * b.XMin)
|
|
|
|
g.B.YMin = g.font.scale(g.scale * b.YMin)
|
|
|
|
g.B.XMax = g.font.scale(g.scale * b.XMax)
|
|
|
|
g.B.YMax = g.font.scale(g.scale * b.YMax)
|
|
|
|
g.pp1x = pp1x
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// loadOffset is the initial offset for loadSimple and loadCompound. The first
|
|
|
|
// 10 bytes are the number of contours and the bounding box.
|
|
|
|
const loadOffset = 10
|
|
|
|
|
|
|
|
func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
|
|
|
|
offset := loadOffset
|
|
|
|
for i := 0; i < ne; i++ {
|
|
|
|
g.End = append(g.End, 1+int(u16(glyf, offset)))
|
|
|
|
offset += 2
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note the TrueType hinting instructions.
|
|
|
|
instrLen := int(u16(glyf, offset))
|
|
|
|
offset += 2
|
|
|
|
program = glyf[offset : offset+instrLen]
|
|
|
|
offset += instrLen
|
|
|
|
|
|
|
|
np0 := len(g.Point)
|
|
|
|
np1 := np0 + int(g.End[len(g.End)-1])
|
|
|
|
|
|
|
|
// Decode the flags.
|
|
|
|
for i := np0; i < np1; {
|
|
|
|
c := uint32(glyf[offset])
|
2012-06-16 04:19:07 +02:00
|
|
|
offset++
|
2013-10-16 09:54:54 +02:00
|
|
|
g.Point = append(g.Point, Point{Flags: c})
|
2012-05-07 04:04:52 +02:00
|
|
|
i++
|
|
|
|
if c&flagRepeat != 0 {
|
2013-10-16 09:54:54 +02:00
|
|
|
count := glyf[offset]
|
2012-06-16 04:19:07 +02:00
|
|
|
offset++
|
2012-05-07 04:04:52 +02:00
|
|
|
for ; count > 0; count-- {
|
2013-10-16 09:54:54 +02:00
|
|
|
g.Point = append(g.Point, Point{Flags: c})
|
2012-05-07 04:04:52 +02:00
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 09:54:54 +02:00
|
|
|
// Decode the co-ordinates.
|
2012-05-07 04:04:52 +02:00
|
|
|
var x int16
|
2013-10-16 09:54:54 +02:00
|
|
|
for i := np0; i < np1; i++ {
|
2012-05-07 04:04:52 +02:00
|
|
|
f := g.Point[i].Flags
|
|
|
|
if f&flagXShortVector != 0 {
|
2013-10-16 09:54:54 +02:00
|
|
|
dx := int16(glyf[offset])
|
2012-06-16 04:19:07 +02:00
|
|
|
offset++
|
2012-05-07 04:04:52 +02:00
|
|
|
if f&flagPositiveXShortVector == 0 {
|
|
|
|
x -= dx
|
|
|
|
} else {
|
|
|
|
x += dx
|
|
|
|
}
|
|
|
|
} else if f&flagThisXIsSame == 0 {
|
2013-10-16 09:54:54 +02:00
|
|
|
x += int16(u16(glyf, offset))
|
2012-06-16 04:19:07 +02:00
|
|
|
offset += 2
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
2012-07-25 14:10:25 +02:00
|
|
|
g.Point[i].X = int32(x)
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
|
|
|
var y int16
|
2013-10-16 09:54:54 +02:00
|
|
|
for i := np0; i < np1; i++ {
|
2012-05-07 04:04:52 +02:00
|
|
|
f := g.Point[i].Flags
|
|
|
|
if f&flagYShortVector != 0 {
|
2013-10-16 09:54:54 +02:00
|
|
|
dy := int16(glyf[offset])
|
2012-06-16 04:19:07 +02:00
|
|
|
offset++
|
2012-05-07 04:04:52 +02:00
|
|
|
if f&flagPositiveYShortVector == 0 {
|
|
|
|
y -= dy
|
|
|
|
} else {
|
|
|
|
y += dy
|
|
|
|
}
|
|
|
|
} else if f&flagThisYIsSame == 0 {
|
2013-10-16 09:54:54 +02:00
|
|
|
y += int16(u16(glyf, offset))
|
2012-06-16 04:19:07 +02:00
|
|
|
offset += 2
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
2012-07-25 14:10:25 +02:00
|
|
|
g.Point[i].Y = int32(y)
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
|
|
|
|
2013-10-16 09:54:54 +02:00
|
|
|
return program
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 23:58:40 +01:00
|
|
|
func (g *GlyphBuf) loadCompound(recursion int32, b Bounds, uhm HMetric, i Index,
|
|
|
|
glyf []byte, useMyMetrics bool) error {
|
|
|
|
|
2012-05-07 04:04:52 +02:00
|
|
|
// Flags for decoding a compound glyph. These flags are documented at
|
|
|
|
// http://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html.
|
|
|
|
const (
|
|
|
|
flagArg1And2AreWords = 1 << iota
|
|
|
|
flagArgsAreXYValues
|
|
|
|
flagRoundXYToGrid
|
|
|
|
flagWeHaveAScale
|
|
|
|
flagUnused
|
|
|
|
flagMoreComponents
|
|
|
|
flagWeHaveAnXAndYScale
|
|
|
|
flagWeHaveATwoByTwo
|
|
|
|
flagWeHaveInstructions
|
|
|
|
flagUseMyMetrics
|
|
|
|
flagOverlapCompound
|
|
|
|
)
|
2013-11-04 23:58:40 +01:00
|
|
|
np0, ne0 := len(g.Point), len(g.End)
|
|
|
|
offset := loadOffset
|
|
|
|
for {
|
2012-06-16 04:19:07 +02:00
|
|
|
flags := u16(glyf, offset)
|
2013-08-31 08:08:40 +02:00
|
|
|
component := Index(u16(glyf, offset+2))
|
2013-10-16 12:39:06 +02:00
|
|
|
dx, dy, transform, hasTransform := int32(0), int32(0), [4]int32{}, false
|
2012-05-07 04:04:52 +02:00
|
|
|
if flags&flagArg1And2AreWords != 0 {
|
2013-10-16 09:54:54 +02:00
|
|
|
dx = int32(int16(u16(glyf, offset+4)))
|
|
|
|
dy = int32(int16(u16(glyf, offset+6)))
|
2012-06-16 04:19:07 +02:00
|
|
|
offset += 8
|
2012-05-07 04:04:52 +02:00
|
|
|
} else {
|
2013-10-16 09:54:54 +02:00
|
|
|
dx = int32(int16(int8(glyf[offset+4])))
|
|
|
|
dy = int32(int16(int8(glyf[offset+5])))
|
2012-06-16 04:19:07 +02:00
|
|
|
offset += 6
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
|
|
|
if flags&flagArgsAreXYValues == 0 {
|
2013-10-16 09:54:54 +02:00
|
|
|
return UnsupportedError("compound glyph transform vector")
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
|
|
|
if flags&(flagWeHaveAScale|flagWeHaveAnXAndYScale|flagWeHaveATwoByTwo) != 0 {
|
2013-10-16 12:39:06 +02:00
|
|
|
hasTransform = true
|
|
|
|
switch {
|
|
|
|
case flags&flagWeHaveAScale != 0:
|
|
|
|
transform[0] = int32(int16(u16(glyf, offset+0)))
|
|
|
|
transform[3] = transform[0]
|
|
|
|
offset += 2
|
|
|
|
case flags&flagWeHaveAnXAndYScale != 0:
|
|
|
|
transform[0] = int32(int16(u16(glyf, offset+0)))
|
|
|
|
transform[3] = int32(int16(u16(glyf, offset+2)))
|
|
|
|
offset += 4
|
|
|
|
case flags&flagWeHaveATwoByTwo != 0:
|
|
|
|
transform[0] = int32(int16(u16(glyf, offset+0)))
|
|
|
|
transform[1] = int32(int16(u16(glyf, offset+2)))
|
|
|
|
transform[2] = int32(int16(u16(glyf, offset+4)))
|
|
|
|
transform[3] = int32(int16(u16(glyf, offset+6)))
|
|
|
|
offset += 8
|
|
|
|
}
|
2013-10-09 22:43:32 +02:00
|
|
|
}
|
2013-10-16 09:54:54 +02:00
|
|
|
np0 := len(g.Point)
|
2013-10-17 01:21:20 +02:00
|
|
|
componentUMM := useMyMetrics && (flags&flagUseMyMetrics != 0)
|
|
|
|
if err := g.load(recursion+1, component, componentUMM); err != nil {
|
2013-10-16 09:54:54 +02:00
|
|
|
return err
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
2013-10-16 12:39:06 +02:00
|
|
|
if hasTransform {
|
2013-11-04 23:58:40 +01:00
|
|
|
for j := np0; j < len(g.Point); j++ {
|
|
|
|
p := &g.Point[j]
|
2013-10-16 12:39:06 +02:00
|
|
|
newX := int32((int64(p.X)*int64(transform[0])+1<<13)>>14) +
|
|
|
|
int32((int64(p.Y)*int64(transform[2])+1<<13)>>14)
|
|
|
|
newY := int32((int64(p.X)*int64(transform[1])+1<<13)>>14) +
|
|
|
|
int32((int64(p.Y)*int64(transform[3])+1<<13)>>14)
|
|
|
|
p.X, p.Y = newX, newY
|
|
|
|
}
|
|
|
|
}
|
2013-10-16 09:54:54 +02:00
|
|
|
dx = g.font.scale(g.scale * dx)
|
|
|
|
dy = g.font.scale(g.scale * dy)
|
|
|
|
if flags&flagRoundXYToGrid != 0 {
|
|
|
|
dx = (dx + 32) &^ 63
|
|
|
|
dy = (dy + 32) &^ 63
|
|
|
|
}
|
2013-11-04 23:58:40 +01:00
|
|
|
for j := np0; j < len(g.Point); j++ {
|
|
|
|
p := &g.Point[j]
|
2013-10-16 09:54:54 +02:00
|
|
|
p.X += dx
|
|
|
|
p.Y += dy
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
2013-10-16 09:54:54 +02:00
|
|
|
// TODO: also adjust g.InFontUnits and g.Unhinted?
|
2012-05-07 04:04:52 +02:00
|
|
|
if flags&flagMoreComponents == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 23:58:40 +01:00
|
|
|
|
|
|
|
// Hint the compound glyph.
|
|
|
|
if g.hinter == nil || offset+2 > len(glyf) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
instrLen := int(u16(glyf, offset))
|
|
|
|
offset += 2
|
|
|
|
if instrLen == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
program := glyf[offset : offset+instrLen]
|
|
|
|
g.addPhantomsAndScale(b, uhm, i, len(g.Point), false)
|
2013-11-06 22:53:15 +01:00
|
|
|
points, ends := g.Point[np0:], g.End[ne0:]
|
2013-11-04 23:58:40 +01:00
|
|
|
g.Point = g.Point[:len(g.Point)-4]
|
|
|
|
for j := range points {
|
|
|
|
points[j].Flags &^= flagTouchedX | flagTouchedY
|
|
|
|
}
|
2013-11-06 22:53:15 +01:00
|
|
|
// Temporarily adjust the ends to be relative to this compound glyph.
|
|
|
|
if np0 != 0 {
|
|
|
|
for i := range ends {
|
|
|
|
ends[i] -= np0
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 23:58:40 +01:00
|
|
|
// Hinting instructions of a composite glyph completely refer to the
|
|
|
|
// (already) hinted subglyphs.
|
|
|
|
g.tmp = append(g.tmp[:0], points...)
|
2013-11-06 22:53:15 +01:00
|
|
|
if err := g.hinter.run(program, points, g.tmp, g.tmp, ends); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if np0 != 0 {
|
|
|
|
for i := range ends {
|
|
|
|
ends[i] += np0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2013-11-04 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GlyphBuf) addPhantomsAndScale(b Bounds, uhm HMetric, i Index, np0 int, appendOther bool) {
|
|
|
|
// Add the four phantom points.
|
|
|
|
uvm := g.font.unscaledVMetric(i)
|
|
|
|
g.Point = append(g.Point,
|
|
|
|
Point{X: b.XMin - uhm.LeftSideBearing},
|
|
|
|
Point{X: b.XMin - uhm.LeftSideBearing + uhm.AdvanceWidth},
|
|
|
|
Point{Y: b.YMax + uvm.TopSideBearing},
|
|
|
|
Point{Y: b.YMax + uvm.TopSideBearing - uvm.AdvanceHeight},
|
|
|
|
)
|
|
|
|
// Scale the points.
|
|
|
|
if appendOther {
|
|
|
|
g.InFontUnits = append(g.InFontUnits, g.Point[np0:]...)
|
|
|
|
}
|
|
|
|
for i := np0; i < len(g.Point); i++ {
|
|
|
|
p := &g.Point[i]
|
|
|
|
p.X = g.font.scale(g.scale * p.X)
|
|
|
|
p.Y = g.font.scale(g.scale * p.Y)
|
|
|
|
}
|
|
|
|
if appendOther {
|
|
|
|
g.Unhinted = append(g.Unhinted, g.Point[np0:]...)
|
|
|
|
}
|
|
|
|
// Round the 2nd and 4th phantom point to the grid.
|
|
|
|
p := &g.Point[len(g.Point)-3]
|
|
|
|
p.X = (p.X + 32) &^ 63
|
|
|
|
p = &g.Point[len(g.Point)-1]
|
|
|
|
p.Y = (p.Y + 32) &^ 63
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|
|
|
|
|
2013-10-16 09:54:54 +02:00
|
|
|
// TODO: is this necessary? The zero-valued GlyphBuf is perfectly usable.
|
2012-05-07 04:04:52 +02:00
|
|
|
|
|
|
|
// NewGlyphBuf returns a newly allocated GlyphBuf.
|
|
|
|
func NewGlyphBuf() *GlyphBuf {
|
2013-10-16 09:54:54 +02:00
|
|
|
return &GlyphBuf{
|
|
|
|
Point: make([]Point, 0, 256),
|
|
|
|
End: make([]int, 0, 32),
|
|
|
|
}
|
2012-05-07 04:04:52 +02:00
|
|
|
}
|