From e1ef029a43f3dc7e77e525186a2456244bded702 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 7 May 2012 22:52:01 +1000 Subject: [PATCH] freetype: make freetype clean wrt "go vet". R=dsymonds CC=golang-dev http://codereview.appspot.com/6202052 --- example/gamma/main.go | 5 ++++- example/raster/main.go | 5 ++++- example/round/main.go | 16 ++++++++-------- freetype/freetype.go | 17 ++++++++++------- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/example/gamma/main.go b/example/gamma/main.go index aa3ce97..4bf7e33 100644 --- a/example/gamma/main.go +++ b/example/gamma/main.go @@ -18,7 +18,10 @@ import ( ) func p(x, y int) raster.Point { - return raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)} + return raster.Point{ + X: raster.Fix32(x * 256), + Y: raster.Fix32(y * 256), + } } func main() { diff --git a/example/raster/main.go b/example/raster/main.go index 8f1bb0f..5e6c981 100644 --- a/example/raster/main.go +++ b/example/raster/main.go @@ -84,7 +84,10 @@ var inside = []node{ func p(n node) raster.Point { x, y := 20+n.x/4, 380-n.y/4 - return raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)} + return raster.Point{ + X: raster.Fix32(x * 256), + Y: raster.Fix32(y * 256), + } } func contour(r *raster.Rasterizer, ns []node) { diff --git a/example/round/main.go b/example/round/main.go index bd7fb01..e2435f9 100644 --- a/example/round/main.go +++ b/example/round/main.go @@ -33,7 +33,7 @@ func main() { t := raster.Fix32(r * math.Tan(math.Pi/8)) m := image.NewRGBA(image.Rect(0, 0, 800, 600)) - draw.Draw(m, m.Bounds(), &image.Uniform{color.RGBA{63, 63, 63, 255}}, image.ZP, draw.Src) + draw.Draw(m, m.Bounds(), image.NewUniform(color.RGBA{63, 63, 63, 255}), image.ZP, draw.Src) mp := raster.NewRGBAPainter(m) mp.SetColor(image.Black) z := raster.NewRasterizer(800, 600) @@ -41,23 +41,23 @@ func main() { for i := 0; i < n; i++ { cx := raster.Fix32(25600 + 51200*(i%4)) cy := raster.Fix32(2560 + 32000*(i/4)) - c := raster.Point{cx, cy} + c := raster.Point{X: cx, Y: cy} theta := math.Pi * (0.5 + 0.5*float64(i)/(n-1)) dx := raster.Fix32(r * math.Cos(theta)) dy := raster.Fix32(r * math.Sin(theta)) - d := raster.Point{dx, dy} + d := raster.Point{X: dx, Y: dy} // Draw a quarter-circle approximated by two quadratic segments, // with each segment spanning 45 degrees. z.Start(c) - z.Add1(c.Add(raster.Point{r, 0})) - z.Add2(c.Add(raster.Point{r, t}), c.Add(raster.Point{s, s})) - z.Add2(c.Add(raster.Point{t, r}), c.Add(raster.Point{0, r})) + z.Add1(c.Add(raster.Point{X: r, Y: 0})) + z.Add2(c.Add(raster.Point{X: r, Y: t}), c.Add(raster.Point{X: s, Y: s})) + z.Add2(c.Add(raster.Point{X: t, Y: r}), c.Add(raster.Point{X: 0, Y: r})) // Add another quadratic segment whose angle ranges between 0 and 90 degrees. // For an explanation of the magic constants 22, 150, 181 and 256, read the // comments in the freetype/raster package. - dot := 256 * d.Dot(raster.Point{0, r}) / (r * r) + dot := 256 * d.Dot(raster.Point{X: 0, Y: r}) / (r * r) multiple := raster.Fix32(150 - 22*(dot-181)/(256-181)) - z.Add2(c.Add(raster.Point{dx, r + dy}.Mul(multiple)), c.Add(d)) + z.Add2(c.Add(raster.Point{X: dx, Y: r + dy}.Mul(multiple)), c.Add(d)) // Close the curve. z.Add1(c) } diff --git a/freetype/freetype.go b/freetype/freetype.go index a79964a..3755e65 100644 --- a/freetype/freetype.go +++ b/freetype/freetype.go @@ -47,7 +47,10 @@ func ParseFont(b []byte) (*truetype.Font, error) { // Pt converts from a co-ordinate pair measured in pixels to a raster.Point // co-ordinate pair measured in raster.Fix32 units. func Pt(x, y int) raster.Point { - return raster.Point{raster.Fix32(x << 8), raster.Fix32(y << 8)} + return raster.Point{ + X: raster.Fix32(x << 8), + Y: raster.Fix32(y << 8), + } } // A Context holds the state for drawing text in a given font and size. @@ -111,15 +114,15 @@ func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fix32) { // start is the same thing measured in fixed point units and positive Y // going downwards, and offset by (dx, dy) start := raster.Point{ - dx + c.FUnitToFix32(int(ps[0].X)), - dy + c.FUnitToFix32(-int(ps[0].Y)), + X: dx + c.FUnitToFix32(int(ps[0].X)), + Y: dy + c.FUnitToFix32(-int(ps[0].Y)), } c.r.Start(start) q0, on0 := start, true for _, p := range ps[1:] { q := raster.Point{ - dx + c.FUnitToFix32(int(p.X)), - dy + c.FUnitToFix32(-int(p.Y)), + X: dx + c.FUnitToFix32(int(p.X)), + Y: dy + c.FUnitToFix32(-int(p.Y)), } on := p.Flags&0x01 != 0 if on { @@ -133,8 +136,8 @@ func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fix32) { // No-op. } else { mid := raster.Point{ - (q0.X + q.X) / 2, - (q0.Y + q.Y) / 2, + X: (q0.X + q.X) / 2, + Y: (q0.Y + q.Y) / 2, } c.r.Add2(q0, mid) }