freetype: make freetype clean wrt "go vet".

R=dsymonds
CC=golang-dev
http://codereview.appspot.com/6202052
This commit is contained in:
Nigel Tao 2012-05-07 22:52:01 +10:00
parent 25c2d648d0
commit e1ef029a43
4 changed files with 26 additions and 17 deletions

View file

@ -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() {

View file

@ -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) {

View file

@ -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)
}

View file

@ -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)
}