Rename Point and End slices to Points and Ends.
The slice Foos is plural; it refers to multiple elements. The element Foos[i] is the i'th Foo.
This commit is contained in:
parent
3cc748686b
commit
3ba1c0f728
|
@ -31,14 +31,14 @@ func printGlyph(g *truetype.GlyphBuf) {
|
|||
printBounds(g.Bounds)
|
||||
fmt.Print("Points:\n---\n")
|
||||
e := 0
|
||||
for i, p := range g.Point {
|
||||
for i, p := range g.Points {
|
||||
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]) {
|
||||
if i+1 == int(g.Ends[e]) {
|
||||
fmt.Print("---\n")
|
||||
e++
|
||||
}
|
||||
|
|
|
@ -182,8 +182,8 @@ func (c *Context) rasterize(glyph truetype.Index, fx, fy fixed.Int26_6) (
|
|||
// Rasterize the glyph's vectors.
|
||||
c.r.Clear()
|
||||
e0 := 0
|
||||
for _, e1 := range c.glyphBuf.End {
|
||||
c.drawContour(c.glyphBuf.Point[e0:e1], fx, fy)
|
||||
for _, e1 := range c.glyphBuf.Ends {
|
||||
c.drawContour(c.glyphBuf.Points[e0:e1], fx, fy)
|
||||
e0 = e1
|
||||
}
|
||||
a := image.NewAlpha(image.Rect(0, 0, xmax-xmin, ymax-ymin))
|
||||
|
|
|
@ -345,8 +345,8 @@ func (a *face) rasterize(index Index, fx, fy fixed.Int26_6) (v cacheVal, ok bool
|
|||
pixOffset := a.paintOffset * a.maxw
|
||||
clear(a.masks.Pix[pixOffset : pixOffset+a.maxw*a.maxh])
|
||||
e0 := 0
|
||||
for _, e1 := range a.glyphBuf.End {
|
||||
a.drawContour(a.glyphBuf.Point[e0:e1], fx, fy)
|
||||
for _, e1 := range a.glyphBuf.Ends {
|
||||
a.drawContour(a.glyphBuf.Points[e0:e1], fx, fy)
|
||||
e0 = e1
|
||||
}
|
||||
a.r.Rasterize(a.p)
|
||||
|
|
|
@ -28,16 +28,16 @@ type GlyphBuf struct {
|
|||
AdvanceWidth fixed.Int26_6
|
||||
// Bounds is the glyph's bounding box.
|
||||
Bounds fixed.Rectangle26_6
|
||||
// Point contains all Points from all contours of the glyph. If
|
||||
// hinting was used to load a glyph then Unhinted contains those
|
||||
// Points before they were hinted, and InFontUnits contains those
|
||||
// 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
|
||||
// contour consists of points Point[End[i-1]:End[i]], where End[-1]
|
||||
// is interpreted to mean zero.
|
||||
End []int
|
||||
// Points contains all Points from all contours of the glyph. If hinting
|
||||
// was used to load a glyph then Unhinted contains those Points before they
|
||||
// were hinted, and InFontUnits contains those Points before they were
|
||||
// hinted and scaled.
|
||||
Points, Unhinted, InFontUnits []Point
|
||||
// Ends is the point indexes of the end point of each contour. The length
|
||||
// of Ends is the number of contours in the glyph. The i'th contour
|
||||
// consists of points Points[Ends[i-1]:Ends[i]], where Ends[-1] is
|
||||
// interpreted to mean zero.
|
||||
Ends []int
|
||||
|
||||
font *Font
|
||||
scale fixed.Int26_6
|
||||
|
@ -83,10 +83,10 @@ const (
|
|||
// contours for this GlyphBuf. scale is the number of 26.6 fixed point units in
|
||||
// 1 em, i is the glyph index, and h is the hinting policy.
|
||||
func (g *GlyphBuf) Load(f *Font, scale fixed.Int26_6, i Index, h font.Hinting) error {
|
||||
g.Point = g.Point[:0]
|
||||
g.Points = g.Points[:0]
|
||||
g.Unhinted = g.Unhinted[:0]
|
||||
g.InFontUnits = g.InFontUnits[:0]
|
||||
g.End = g.End[:0]
|
||||
g.Ends = g.Ends[:0]
|
||||
g.font = f
|
||||
g.hinting = h
|
||||
g.scale = scale
|
||||
|
@ -110,8 +110,8 @@ func (g *GlyphBuf) Load(f *Font, scale fixed.Int26_6, i Index, h font.Hinting) e
|
|||
pp1x = g.phantomPoints[0].X
|
||||
}
|
||||
if pp1x != 0 {
|
||||
for i := range g.Point {
|
||||
g.Point[i].X -= pp1x
|
||||
for i := range g.Points {
|
||||
g.Points[i].X -= pp1x
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,15 +137,15 @@ func (g *GlyphBuf) Load(f *Font, scale fixed.Int26_6, i Index, h font.Hinting) e
|
|||
// themselves. This approach is what C Freetype does. We can't just scale
|
||||
// the nominal bounding box in the glyf data as the hinting process and
|
||||
// phantom point adjustment may move points outside of that box.
|
||||
if len(g.Point) == 0 {
|
||||
if len(g.Points) == 0 {
|
||||
g.Bounds = fixed.Rectangle26_6{}
|
||||
} else {
|
||||
p := g.Point[0]
|
||||
p := g.Points[0]
|
||||
g.Bounds.Min.X = p.X
|
||||
g.Bounds.Max.X = p.X
|
||||
g.Bounds.Min.Y = p.Y
|
||||
g.Bounds.Max.Y = p.Y
|
||||
for _, p := range g.Point[1:] {
|
||||
for _, p := range g.Points[1:] {
|
||||
if g.Bounds.Min.X > p.X {
|
||||
g.Bounds.Min.X = p.X
|
||||
} else if g.Bounds.Max.X < p.X {
|
||||
|
@ -206,9 +206,9 @@ func (g *GlyphBuf) load(recursion uint32, i Index, useMyMetrics bool) (err error
|
|||
{X: uhm.AdvanceWidth / 2, Y: boundsYMax + uvm.TopSideBearing - uvm.AdvanceHeight},
|
||||
}
|
||||
if len(glyf) == 0 {
|
||||
g.addPhantomsAndScale(len(g.Point), len(g.Point), true, true)
|
||||
copy(g.phantomPoints[:], g.Point[len(g.Point)-4:])
|
||||
g.Point = g.Point[:len(g.Point)-4]
|
||||
g.addPhantomsAndScale(len(g.Points), len(g.Points), true, true)
|
||||
copy(g.phantomPoints[:], g.Points[len(g.Points)-4:])
|
||||
g.Points = g.Points[:len(g.Points)-4]
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -224,18 +224,18 @@ func (g *GlyphBuf) load(recursion uint32, i Index, useMyMetrics bool) (err error
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
np0, ne0 := len(g.Point), len(g.End)
|
||||
np0, ne0 := len(g.Points), len(g.Ends)
|
||||
program := g.loadSimple(glyf, ne)
|
||||
g.addPhantomsAndScale(np0, np0, true, true)
|
||||
pp1x = g.Point[len(g.Point)-4].X
|
||||
pp1x = g.Points[len(g.Points)-4].X
|
||||
if g.hinting != font.HintingNone {
|
||||
if len(program) != 0 {
|
||||
err := g.hinter.run(
|
||||
program,
|
||||
g.Point[np0:],
|
||||
g.Points[np0:],
|
||||
g.Unhinted[np0:],
|
||||
g.InFontUnits[np0:],
|
||||
g.End[ne0:],
|
||||
g.Ends[ne0:],
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -246,15 +246,15 @@ func (g *GlyphBuf) load(recursion uint32, i Index, useMyMetrics bool) (err error
|
|||
g.Unhinted = g.Unhinted[:len(g.Unhinted)-4]
|
||||
}
|
||||
if useMyMetrics {
|
||||
copy(g.phantomPoints[:], g.Point[len(g.Point)-4:])
|
||||
copy(g.phantomPoints[:], g.Points[len(g.Points)-4:])
|
||||
}
|
||||
g.Point = g.Point[:len(g.Point)-4]
|
||||
g.Points = g.Points[:len(g.Points)-4]
|
||||
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
|
||||
// The hinting program expects the []Ends 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.Ends); i++ {
|
||||
g.Ends[i] += np0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ 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)))
|
||||
g.Ends = append(g.Ends, 1+int(u16(glyf, offset)))
|
||||
offset += 2
|
||||
}
|
||||
|
||||
|
@ -282,20 +282,20 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
|
|||
program = glyf[offset : offset+instrLen]
|
||||
offset += instrLen
|
||||
|
||||
np0 := len(g.Point)
|
||||
np1 := np0 + int(g.End[len(g.End)-1])
|
||||
np0 := len(g.Points)
|
||||
np1 := np0 + int(g.Ends[len(g.Ends)-1])
|
||||
|
||||
// Decode the flags.
|
||||
for i := np0; i < np1; {
|
||||
c := uint32(glyf[offset])
|
||||
offset++
|
||||
g.Point = append(g.Point, Point{Flags: c})
|
||||
g.Points = append(g.Points, Point{Flags: c})
|
||||
i++
|
||||
if c&flagRepeat != 0 {
|
||||
count := glyf[offset]
|
||||
offset++
|
||||
for ; count > 0; count-- {
|
||||
g.Point = append(g.Point, Point{Flags: c})
|
||||
g.Points = append(g.Points, Point{Flags: c})
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
|
|||
// Decode the co-ordinates.
|
||||
var x int16
|
||||
for i := np0; i < np1; i++ {
|
||||
f := g.Point[i].Flags
|
||||
f := g.Points[i].Flags
|
||||
if f&flagXShortVector != 0 {
|
||||
dx := int16(glyf[offset])
|
||||
offset++
|
||||
|
@ -317,11 +317,11 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
|
|||
x += int16(u16(glyf, offset))
|
||||
offset += 2
|
||||
}
|
||||
g.Point[i].X = fixed.Int26_6(x)
|
||||
g.Points[i].X = fixed.Int26_6(x)
|
||||
}
|
||||
var y int16
|
||||
for i := np0; i < np1; i++ {
|
||||
f := g.Point[i].Flags
|
||||
f := g.Points[i].Flags
|
||||
if f&flagYShortVector != 0 {
|
||||
dy := int16(glyf[offset])
|
||||
offset++
|
||||
|
@ -334,7 +334,7 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
|
|||
y += int16(u16(glyf, offset))
|
||||
offset += 2
|
||||
}
|
||||
g.Point[i].Y = fixed.Int26_6(y)
|
||||
g.Points[i].Y = fixed.Int26_6(y)
|
||||
}
|
||||
|
||||
return program
|
||||
|
@ -358,7 +358,7 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
|
|||
flagUseMyMetrics
|
||||
flagOverlapCompound
|
||||
)
|
||||
np0, ne0 := len(g.Point), len(g.End)
|
||||
np0, ne0 := len(g.Points), len(g.Ends)
|
||||
offset := loadOffset
|
||||
for {
|
||||
flags := u16(glyf, offset)
|
||||
|
@ -396,7 +396,7 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
|
|||
}
|
||||
}
|
||||
savedPP := g.phantomPoints
|
||||
np0 := len(g.Point)
|
||||
np0 := len(g.Points)
|
||||
componentUMM := useMyMetrics && (flags&flagUseMyMetrics != 0)
|
||||
if err := g.load(recursion+1, component, componentUMM); err != nil {
|
||||
return err
|
||||
|
@ -405,8 +405,8 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
|
|||
g.phantomPoints = savedPP
|
||||
}
|
||||
if hasTransform {
|
||||
for j := np0; j < len(g.Point); j++ {
|
||||
p := &g.Point[j]
|
||||
for j := np0; j < len(g.Points); j++ {
|
||||
p := &g.Points[j]
|
||||
newX := 0 +
|
||||
fixed.Int26_6((int64(p.X)*int64(transform[0])+1<<13)>>14) +
|
||||
fixed.Int26_6((int64(p.Y)*int64(transform[2])+1<<13)>>14)
|
||||
|
@ -422,8 +422,8 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
|
|||
dx = (dx + 32) &^ 63
|
||||
dy = (dy + 32) &^ 63
|
||||
}
|
||||
for j := np0; j < len(g.Point); j++ {
|
||||
p := &g.Point[j]
|
||||
for j := np0; j < len(g.Points); j++ {
|
||||
p := &g.Points[j]
|
||||
p.X += dx
|
||||
p.Y += dy
|
||||
}
|
||||
|
@ -439,9 +439,9 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
|
|||
offset += 2
|
||||
}
|
||||
|
||||
g.addPhantomsAndScale(np0, len(g.Point), false, instrLen > 0)
|
||||
points, ends := g.Point[np0:], g.End[ne0:]
|
||||
g.Point = g.Point[:len(g.Point)-4]
|
||||
g.addPhantomsAndScale(np0, len(g.Points), false, instrLen > 0)
|
||||
points, ends := g.Points[np0:], g.Ends[ne0:]
|
||||
g.Points = g.Points[:len(g.Points)-4]
|
||||
for j := range points {
|
||||
points[j].Flags &^= flagTouchedX | flagTouchedY
|
||||
}
|
||||
|
@ -480,13 +480,13 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
|
|||
|
||||
func (g *GlyphBuf) addPhantomsAndScale(np0, np1 int, simple, adjust bool) {
|
||||
// Add the four phantom points.
|
||||
g.Point = append(g.Point, g.phantomPoints[:]...)
|
||||
g.Points = append(g.Points, g.phantomPoints[:]...)
|
||||
// Scale the points.
|
||||
if simple && g.hinting != font.HintingNone {
|
||||
g.InFontUnits = append(g.InFontUnits, g.Point[np1:]...)
|
||||
g.InFontUnits = append(g.InFontUnits, g.Points[np1:]...)
|
||||
}
|
||||
for i := np1; i < len(g.Point); i++ {
|
||||
p := &g.Point[i]
|
||||
for i := np1; i < len(g.Points); i++ {
|
||||
p := &g.Points[i]
|
||||
p.X = g.font.scale(g.scale * p.X)
|
||||
p.Y = g.font.scale(g.scale * p.Y)
|
||||
}
|
||||
|
@ -499,19 +499,19 @@ func (g *GlyphBuf) addPhantomsAndScale(np0, np1 int, simple, adjust bool) {
|
|||
// we update the compatibility tests to C Freetype 2.5.3.
|
||||
// See http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=05c786d990390a7ca18e62962641dac740bacb06
|
||||
if adjust {
|
||||
pp1x := g.Point[len(g.Point)-4].X
|
||||
pp1x := g.Points[len(g.Points)-4].X
|
||||
if dx := ((pp1x + 32) &^ 63) - pp1x; dx != 0 {
|
||||
for i := np0; i < len(g.Point); i++ {
|
||||
g.Point[i].X += dx
|
||||
for i := np0; i < len(g.Points); i++ {
|
||||
g.Points[i].X += dx
|
||||
}
|
||||
}
|
||||
}
|
||||
if simple {
|
||||
g.Unhinted = append(g.Unhinted, g.Point[np1:]...)
|
||||
g.Unhinted = append(g.Unhinted, g.Points[np1:]...)
|
||||
}
|
||||
// Round the 2nd and 4th phantom point to the grid.
|
||||
p := &g.Point[len(g.Point)-3]
|
||||
p := &g.Points[len(g.Points)-3]
|
||||
p.X = (p.X + 32) &^ 63
|
||||
p = &g.Point[len(g.Point)-1]
|
||||
p = &g.Points[len(g.Points)-1]
|
||||
p.Y = (p.Y + 32) &^ 63
|
||||
}
|
||||
|
|
|
@ -83,12 +83,12 @@ func TestParse(t *testing.T) {
|
|||
}
|
||||
g0 := &GlyphBuf{
|
||||
Bounds: g.Bounds,
|
||||
Point: g.Point,
|
||||
End: g.End,
|
||||
Points: g.Points,
|
||||
Ends: g.Ends,
|
||||
}
|
||||
g1 := &GlyphBuf{
|
||||
Bounds: mkBounds(19, 0, 1342, 1480),
|
||||
Point: []Point{
|
||||
Points: []Point{
|
||||
{19, 0, 51},
|
||||
{581, 1480, 1},
|
||||
{789, 1480, 51},
|
||||
|
@ -101,7 +101,7 @@ func TestParse(t *testing.T) {
|
|||
{904, 566, 33},
|
||||
{667, 1200, 3},
|
||||
},
|
||||
End: []int{8, 11},
|
||||
Ends: []int{8, 11},
|
||||
}
|
||||
if got, want := fmt.Sprint(g0), fmt.Sprint(g1); got != want {
|
||||
t.Errorf("GlyphBuf:\ngot %v\nwant %v", got, want)
|
||||
|
@ -341,7 +341,7 @@ func testScaling(t *testing.T, h font.Hinting) {
|
|||
got := scalingTestData{
|
||||
advanceWidth: glyphBuf.AdvanceWidth,
|
||||
bounds: glyphBuf.Bounds,
|
||||
points: glyphBuf.Point,
|
||||
points: glyphBuf.Points,
|
||||
}
|
||||
|
||||
if got.advanceWidth != want.advanceWidth {
|
||||
|
|
Loading…
Reference in New Issue
Block a user