提交 3ba1c0f7 编写于 作者: N Nigel Tao

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.
上级 3cc74868
...@@ -31,14 +31,14 @@ func printGlyph(g *truetype.GlyphBuf) { ...@@ -31,14 +31,14 @@ func printGlyph(g *truetype.GlyphBuf) {
printBounds(g.Bounds) printBounds(g.Bounds)
fmt.Print("Points:\n---\n") fmt.Print("Points:\n---\n")
e := 0 e := 0
for i, p := range g.Point { for i, p := range g.Points {
fmt.Printf("%4d, %4d", p.X, p.Y) fmt.Printf("%4d, %4d", p.X, p.Y)
if p.Flags&0x01 != 0 { if p.Flags&0x01 != 0 {
fmt.Print(" on\n") fmt.Print(" on\n")
} else { } else {
fmt.Print(" off\n") fmt.Print(" off\n")
} }
if i+1 == int(g.End[e]) { if i+1 == int(g.Ends[e]) {
fmt.Print("---\n") fmt.Print("---\n")
e++ e++
} }
......
...@@ -182,8 +182,8 @@ func (c *Context) rasterize(glyph truetype.Index, fx, fy fixed.Int26_6) ( ...@@ -182,8 +182,8 @@ func (c *Context) rasterize(glyph truetype.Index, fx, fy fixed.Int26_6) (
// Rasterize the glyph's vectors. // Rasterize the glyph's vectors.
c.r.Clear() c.r.Clear()
e0 := 0 e0 := 0
for _, e1 := range c.glyphBuf.End { for _, e1 := range c.glyphBuf.Ends {
c.drawContour(c.glyphBuf.Point[e0:e1], fx, fy) c.drawContour(c.glyphBuf.Points[e0:e1], fx, fy)
e0 = e1 e0 = e1
} }
a := image.NewAlpha(image.Rect(0, 0, xmax-xmin, ymax-ymin)) 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 ...@@ -345,8 +345,8 @@ func (a *face) rasterize(index Index, fx, fy fixed.Int26_6) (v cacheVal, ok bool
pixOffset := a.paintOffset * a.maxw pixOffset := a.paintOffset * a.maxw
clear(a.masks.Pix[pixOffset : pixOffset+a.maxw*a.maxh]) clear(a.masks.Pix[pixOffset : pixOffset+a.maxw*a.maxh])
e0 := 0 e0 := 0
for _, e1 := range a.glyphBuf.End { for _, e1 := range a.glyphBuf.Ends {
a.drawContour(a.glyphBuf.Point[e0:e1], fx, fy) a.drawContour(a.glyphBuf.Points[e0:e1], fx, fy)
e0 = e1 e0 = e1
} }
a.r.Rasterize(a.p) a.r.Rasterize(a.p)
......
...@@ -28,16 +28,16 @@ type GlyphBuf struct { ...@@ -28,16 +28,16 @@ type GlyphBuf struct {
AdvanceWidth fixed.Int26_6 AdvanceWidth fixed.Int26_6
// Bounds is the glyph's bounding box. // Bounds is the glyph's bounding box.
Bounds fixed.Rectangle26_6 Bounds fixed.Rectangle26_6
// Point contains all Points from all contours of the glyph. If // Points contains all Points from all contours of the glyph. If hinting
// hinting was used to load a glyph then Unhinted contains those // was used to load a glyph then Unhinted contains those Points before they
// Points before they were hinted, and InFontUnits contains those // were hinted, and InFontUnits contains those Points before they were
// Points before they were hinted and scaled. // hinted and scaled.
Point, Unhinted, InFontUnits []Point Points, Unhinted, InFontUnits []Point
// End is the point indexes of the end point of each countour. The // Ends is the point indexes of the end point of each contour. The length
// length of End is the number of contours in the glyph. The i'th // of Ends is the number of contours in the glyph. The i'th contour
// contour consists of points Point[End[i-1]:End[i]], where End[-1] // consists of points Points[Ends[i-1]:Ends[i]], where Ends[-1] is
// is interpreted to mean zero. // interpreted to mean zero.
End []int Ends []int
font *Font font *Font
scale fixed.Int26_6 scale fixed.Int26_6
...@@ -83,10 +83,10 @@ const ( ...@@ -83,10 +83,10 @@ const (
// contours for this GlyphBuf. scale is the number of 26.6 fixed point units in // 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. // 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 { 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.Unhinted = g.Unhinted[:0]
g.InFontUnits = g.InFontUnits[:0] g.InFontUnits = g.InFontUnits[:0]
g.End = g.End[:0] g.Ends = g.Ends[:0]
g.font = f g.font = f
g.hinting = h g.hinting = h
g.scale = scale g.scale = scale
...@@ -110,8 +110,8 @@ func (g *GlyphBuf) Load(f *Font, scale fixed.Int26_6, i Index, h font.Hinting) e ...@@ -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 pp1x = g.phantomPoints[0].X
} }
if pp1x != 0 { if pp1x != 0 {
for i := range g.Point { for i := range g.Points {
g.Point[i].X -= pp1x 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 ...@@ -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 // 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 // the nominal bounding box in the glyf data as the hinting process and
// phantom point adjustment may move points outside of that box. // 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{} g.Bounds = fixed.Rectangle26_6{}
} else { } else {
p := g.Point[0] p := g.Points[0]
g.Bounds.Min.X = p.X g.Bounds.Min.X = p.X
g.Bounds.Max.X = p.X g.Bounds.Max.X = p.X
g.Bounds.Min.Y = p.Y g.Bounds.Min.Y = p.Y
g.Bounds.Max.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 { if g.Bounds.Min.X > p.X {
g.Bounds.Min.X = p.X g.Bounds.Min.X = p.X
} else if g.Bounds.Max.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 ...@@ -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}, {X: uhm.AdvanceWidth / 2, Y: boundsYMax + uvm.TopSideBearing - uvm.AdvanceHeight},
} }
if len(glyf) == 0 { if len(glyf) == 0 {
g.addPhantomsAndScale(len(g.Point), len(g.Point), true, true) g.addPhantomsAndScale(len(g.Points), len(g.Points), true, true)
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]
return nil return nil
} }
...@@ -224,18 +224,18 @@ func (g *GlyphBuf) load(recursion uint32, i Index, useMyMetrics bool) (err error ...@@ -224,18 +224,18 @@ func (g *GlyphBuf) load(recursion uint32, i Index, useMyMetrics bool) (err error
return err return err
} }
} else { } else {
np0, ne0 := len(g.Point), len(g.End) np0, ne0 := len(g.Points), len(g.Ends)
program := g.loadSimple(glyf, ne) program := g.loadSimple(glyf, ne)
g.addPhantomsAndScale(np0, np0, true, true) 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 g.hinting != font.HintingNone {
if len(program) != 0 { if len(program) != 0 {
err := g.hinter.run( err := g.hinter.run(
program, program,
g.Point[np0:], g.Points[np0:],
g.Unhinted[np0:], g.Unhinted[np0:],
g.InFontUnits[np0:], g.InFontUnits[np0:],
g.End[ne0:], g.Ends[ne0:],
) )
if err != nil { if err != nil {
return err return err
...@@ -246,15 +246,15 @@ func (g *GlyphBuf) load(recursion uint32, i Index, useMyMetrics bool) (err error ...@@ -246,15 +246,15 @@ func (g *GlyphBuf) load(recursion uint32, i Index, useMyMetrics bool) (err error
g.Unhinted = g.Unhinted[:len(g.Unhinted)-4] g.Unhinted = g.Unhinted[:len(g.Unhinted)-4]
} }
if useMyMetrics { 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 { if np0 != 0 {
// The hinting program expects the []End values to be indexed relative // The hinting program expects the []Ends values to be indexed
// to the inner glyph, not the outer glyph, so we delay adding np0 until // relative to the inner glyph, not the outer glyph, so we delay
// after the hinting program (if any) has run. // adding np0 until after the hinting program (if any) has run.
for i := ne0; i < len(g.End); i++ { for i := ne0; i < len(g.Ends); i++ {
g.End[i] += np0 g.Ends[i] += np0
} }
} }
} }
...@@ -272,7 +272,7 @@ const loadOffset = 10 ...@@ -272,7 +272,7 @@ const loadOffset = 10
func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) { func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
offset := loadOffset offset := loadOffset
for i := 0; i < ne; i++ { 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 offset += 2
} }
...@@ -282,20 +282,20 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) { ...@@ -282,20 +282,20 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
program = glyf[offset : offset+instrLen] program = glyf[offset : offset+instrLen]
offset += instrLen offset += instrLen
np0 := len(g.Point) np0 := len(g.Points)
np1 := np0 + int(g.End[len(g.End)-1]) np1 := np0 + int(g.Ends[len(g.Ends)-1])
// Decode the flags. // Decode the flags.
for i := np0; i < np1; { for i := np0; i < np1; {
c := uint32(glyf[offset]) c := uint32(glyf[offset])
offset++ offset++
g.Point = append(g.Point, Point{Flags: c}) g.Points = append(g.Points, Point{Flags: c})
i++ i++
if c&flagRepeat != 0 { if c&flagRepeat != 0 {
count := glyf[offset] count := glyf[offset]
offset++ offset++
for ; count > 0; count-- { for ; count > 0; count-- {
g.Point = append(g.Point, Point{Flags: c}) g.Points = append(g.Points, Point{Flags: c})
i++ i++
} }
} }
...@@ -304,7 +304,7 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) { ...@@ -304,7 +304,7 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
// Decode the co-ordinates. // Decode the co-ordinates.
var x int16 var x int16
for i := np0; i < np1; i++ { for i := np0; i < np1; i++ {
f := g.Point[i].Flags f := g.Points[i].Flags
if f&flagXShortVector != 0 { if f&flagXShortVector != 0 {
dx := int16(glyf[offset]) dx := int16(glyf[offset])
offset++ offset++
...@@ -317,11 +317,11 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) { ...@@ -317,11 +317,11 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
x += int16(u16(glyf, offset)) x += int16(u16(glyf, offset))
offset += 2 offset += 2
} }
g.Point[i].X = fixed.Int26_6(x) g.Points[i].X = fixed.Int26_6(x)
} }
var y int16 var y int16
for i := np0; i < np1; i++ { for i := np0; i < np1; i++ {
f := g.Point[i].Flags f := g.Points[i].Flags
if f&flagYShortVector != 0 { if f&flagYShortVector != 0 {
dy := int16(glyf[offset]) dy := int16(glyf[offset])
offset++ offset++
...@@ -334,7 +334,7 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) { ...@@ -334,7 +334,7 @@ func (g *GlyphBuf) loadSimple(glyf []byte, ne int) (program []byte) {
y += int16(u16(glyf, offset)) y += int16(u16(glyf, offset))
offset += 2 offset += 2
} }
g.Point[i].Y = fixed.Int26_6(y) g.Points[i].Y = fixed.Int26_6(y)
} }
return program return program
...@@ -358,7 +358,7 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index, ...@@ -358,7 +358,7 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
flagUseMyMetrics flagUseMyMetrics
flagOverlapCompound flagOverlapCompound
) )
np0, ne0 := len(g.Point), len(g.End) np0, ne0 := len(g.Points), len(g.Ends)
offset := loadOffset offset := loadOffset
for { for {
flags := u16(glyf, offset) flags := u16(glyf, offset)
...@@ -396,7 +396,7 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index, ...@@ -396,7 +396,7 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
} }
} }
savedPP := g.phantomPoints savedPP := g.phantomPoints
np0 := len(g.Point) np0 := len(g.Points)
componentUMM := useMyMetrics && (flags&flagUseMyMetrics != 0) componentUMM := useMyMetrics && (flags&flagUseMyMetrics != 0)
if err := g.load(recursion+1, component, componentUMM); err != nil { if err := g.load(recursion+1, component, componentUMM); err != nil {
return err return err
...@@ -405,8 +405,8 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index, ...@@ -405,8 +405,8 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
g.phantomPoints = savedPP g.phantomPoints = savedPP
} }
if hasTransform { if hasTransform {
for j := np0; j < len(g.Point); j++ { for j := np0; j < len(g.Points); j++ {
p := &g.Point[j] p := &g.Points[j]
newX := 0 + newX := 0 +
fixed.Int26_6((int64(p.X)*int64(transform[0])+1<<13)>>14) + fixed.Int26_6((int64(p.X)*int64(transform[0])+1<<13)>>14) +
fixed.Int26_6((int64(p.Y)*int64(transform[2])+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, ...@@ -422,8 +422,8 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
dx = (dx + 32) &^ 63 dx = (dx + 32) &^ 63
dy = (dy + 32) &^ 63 dy = (dy + 32) &^ 63
} }
for j := np0; j < len(g.Point); j++ { for j := np0; j < len(g.Points); j++ {
p := &g.Point[j] p := &g.Points[j]
p.X += dx p.X += dx
p.Y += dy p.Y += dy
} }
...@@ -439,9 +439,9 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index, ...@@ -439,9 +439,9 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
offset += 2 offset += 2
} }
g.addPhantomsAndScale(np0, len(g.Point), false, instrLen > 0) g.addPhantomsAndScale(np0, len(g.Points), false, instrLen > 0)
points, ends := g.Point[np0:], g.End[ne0:] points, ends := g.Points[np0:], g.Ends[ne0:]
g.Point = g.Point[:len(g.Point)-4] g.Points = g.Points[:len(g.Points)-4]
for j := range points { for j := range points {
points[j].Flags &^= flagTouchedX | flagTouchedY points[j].Flags &^= flagTouchedX | flagTouchedY
} }
...@@ -480,13 +480,13 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index, ...@@ -480,13 +480,13 @@ func (g *GlyphBuf) loadCompound(recursion uint32, uhm HMetric, i Index,
func (g *GlyphBuf) addPhantomsAndScale(np0, np1 int, simple, adjust bool) { func (g *GlyphBuf) addPhantomsAndScale(np0, np1 int, simple, adjust bool) {
// Add the four phantom points. // Add the four phantom points.
g.Point = append(g.Point, g.phantomPoints[:]...) g.Points = append(g.Points, g.phantomPoints[:]...)
// Scale the points. // Scale the points.
if simple && g.hinting != font.HintingNone { 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++ { for i := np1; i < len(g.Points); i++ {
p := &g.Point[i] p := &g.Points[i]
p.X = g.font.scale(g.scale * p.X) p.X = g.font.scale(g.scale * p.X)
p.Y = g.font.scale(g.scale * p.Y) p.Y = g.font.scale(g.scale * p.Y)
} }
...@@ -499,19 +499,19 @@ func (g *GlyphBuf) addPhantomsAndScale(np0, np1 int, simple, adjust bool) { ...@@ -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. // we update the compatibility tests to C Freetype 2.5.3.
// See http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=05c786d990390a7ca18e62962641dac740bacb06 // See http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=05c786d990390a7ca18e62962641dac740bacb06
if adjust { 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 { if dx := ((pp1x + 32) &^ 63) - pp1x; dx != 0 {
for i := np0; i < len(g.Point); i++ { for i := np0; i < len(g.Points); i++ {
g.Point[i].X += dx g.Points[i].X += dx
} }
} }
} }
if simple { 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. // 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.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 p.Y = (p.Y + 32) &^ 63
} }
...@@ -83,12 +83,12 @@ func TestParse(t *testing.T) { ...@@ -83,12 +83,12 @@ func TestParse(t *testing.T) {
} }
g0 := &GlyphBuf{ g0 := &GlyphBuf{
Bounds: g.Bounds, Bounds: g.Bounds,
Point: g.Point, Points: g.Points,
End: g.End, Ends: g.Ends,
} }
g1 := &GlyphBuf{ g1 := &GlyphBuf{
Bounds: mkBounds(19, 0, 1342, 1480), Bounds: mkBounds(19, 0, 1342, 1480),
Point: []Point{ Points: []Point{
{19, 0, 51}, {19, 0, 51},
{581, 1480, 1}, {581, 1480, 1},
{789, 1480, 51}, {789, 1480, 51},
...@@ -101,7 +101,7 @@ func TestParse(t *testing.T) { ...@@ -101,7 +101,7 @@ func TestParse(t *testing.T) {
{904, 566, 33}, {904, 566, 33},
{667, 1200, 3}, {667, 1200, 3},
}, },
End: []int{8, 11}, Ends: []int{8, 11},
} }
if got, want := fmt.Sprint(g0), fmt.Sprint(g1); got != want { if got, want := fmt.Sprint(g0), fmt.Sprint(g1); got != want {
t.Errorf("GlyphBuf:\ngot %v\nwant %v", got, want) t.Errorf("GlyphBuf:\ngot %v\nwant %v", got, want)
...@@ -341,7 +341,7 @@ func testScaling(t *testing.T, h font.Hinting) { ...@@ -341,7 +341,7 @@ func testScaling(t *testing.T, h font.Hinting) {
got := scalingTestData{ got := scalingTestData{
advanceWidth: glyphBuf.AdvanceWidth, advanceWidth: glyphBuf.AdvanceWidth,
bounds: glyphBuf.Bounds, bounds: glyphBuf.Bounds,
points: glyphBuf.Point, points: glyphBuf.Points,
} }
if got.advanceWidth != want.advanceWidth { if got.advanceWidth != want.advanceWidth {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册