From 3e38a9641933962d57ada5e723545c88b0fb3f81 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 1 Jul 2010 09:42:43 +1000 Subject: [PATCH] freetype/raster: Rename Fixed and Fixed64 to Fix32 and Fix64. R=rsc CC=golang-dev, rog http://codereview.appspot.com/1686048 --- example/freetype/main.go | 2 +- example/gamma/main.go | 2 +- example/raster/main.go | 2 +- example/round/main.go | 22 +++++++------- freetype/freetype.go | 38 ++++++++++++------------- freetype/raster/geom.go | 60 +++++++++++++++++++-------------------- freetype/raster/raster.go | 26 ++++++++--------- 7 files changed, 76 insertions(+), 76 deletions(-) diff --git a/example/freetype/main.go b/example/freetype/main.go index d65d7a9..012591e 100644 --- a/example/freetype/main.go +++ b/example/freetype/main.go @@ -111,7 +111,7 @@ func main() { log.Stderr(err) return } - pt.Y += c.PointToFixed(*size * *spacing) + pt.Y += c.PointToFix32(*size * *spacing) } // Save that RGBA image to disk. diff --git a/example/gamma/main.go b/example/gamma/main.go index 2d5e14d..6c0d875 100644 --- a/example/gamma/main.go +++ b/example/gamma/main.go @@ -18,7 +18,7 @@ import ( ) func p(x, y int) raster.Point { - return raster.Point{raster.Fixed(x * 256), raster.Fixed(y * 256)} + return raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)} } func clear(m *image.Alpha) { diff --git a/example/raster/main.go b/example/raster/main.go index 39344ac..f656c40 100644 --- a/example/raster/main.go +++ b/example/raster/main.go @@ -83,7 +83,7 @@ var inside = []node{ func p(n node) raster.Point { x, y := 20+n.x/4, 380-n.y/4 - return raster.Point{raster.Fixed(x * 256), raster.Fixed(y * 256)} + return raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)} } func contour(r *raster.Rasterizer, ns []node) { diff --git a/example/round/main.go b/example/round/main.go index c048b3a..e77a13d 100644 --- a/example/round/main.go +++ b/example/round/main.go @@ -27,8 +27,8 @@ func main() { n = 17 r = 256 * 80 ) - s := raster.Fixed(r * math.Sqrt(2) / 2) - t := raster.Fixed(r * math.Tan(math.Pi/8)) + s := raster.Fix32(r * math.Sqrt(2) / 2) + t := raster.Fix32(r * math.Tan(math.Pi/8)) m := image.NewRGBA(800, 600) for y := 0; y < m.Height(); y++ { @@ -41,12 +41,12 @@ func main() { z := raster.NewRasterizer(800, 600) for i := 0; i < n; i++ { - cx := raster.Fixed(25600 + 51200*(i%4)) - cy := raster.Fixed(2560 + 32000*(i/4)) + cx := raster.Fix32(25600 + 51200*(i%4)) + cy := raster.Fix32(2560 + 32000*(i/4)) c := raster.Point{cx, cy} theta := math.Pi * (0.5 + 0.5*float64(i)/(n-1)) - dx := raster.Fixed(r * math.Cos(theta)) - dy := raster.Fixed(r * math.Sin(theta)) + dx := raster.Fix32(r * math.Cos(theta)) + dy := raster.Fix32(r * math.Sin(theta)) d := raster.Point{dx, dy} // Draw a quarter-circle approximated by two quadratic segments, // with each segment spanning 45 degrees. @@ -58,7 +58,7 @@ func main() { // 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) - multiple := raster.Fixed(150 - 22*(dot-181)/(256-181)) + multiple := raster.Fix32(150 - 22*(dot-181)/(256-181)) z.Add2(c.Add(raster.Point{dx, r + dy}.Mul(multiple)), c.Add(d)) // Close the curve. z.Add1(c) @@ -66,12 +66,12 @@ func main() { z.Rasterize(mp) for i := 0; i < n; i++ { - cx := raster.Fixed(25600 + 51200*(i%4)) - cy := raster.Fixed(2560 + 32000*(i/4)) + cx := raster.Fix32(25600 + 51200*(i%4)) + cy := raster.Fix32(2560 + 32000*(i/4)) for j := 0; j < n; j++ { theta := math.Pi * float64(j) / (n - 1) - dx := raster.Fixed(r * math.Cos(theta)) - dy := raster.Fixed(r * math.Sin(theta)) + dx := raster.Fix32(r * math.Cos(theta)) + dy := raster.Fix32(r * math.Sin(theta)) m.Set(int((cx+dx)/256), int((cy+dy)/256), image.Yellow) } } diff --git a/freetype/freetype.go b/freetype/freetype.go index 5534b4d..31f95d6 100644 --- a/freetype/freetype.go +++ b/freetype/freetype.go @@ -22,9 +22,9 @@ func ParseFont(b []byte) (*truetype.Font, os.Error) { } // Pt converts from a co-ordinate pair measured in pixels to a raster.Point -// co-ordinate pair measured in raster.Fixed units. +// co-ordinate pair measured in raster.Fix32 units. func Pt(x, y int) raster.Point { - return raster.Point{raster.Fixed(x << 8), raster.Fixed(y << 8)} + return raster.Point{raster.Fix32(x << 8), raster.Fix32(y << 8)} } // A Context holds the state for drawing text in a given font and size. @@ -53,10 +53,10 @@ type Context struct { scale int } -// FUnitToFixed converts the given number of FUnits into fixed point units, +// FUnitToFix32 converts the given number of FUnits into fixed point units, // rounding to nearest. -func (c *Context) FUnitToFixed(x int) raster.Fixed { - return raster.Fixed((x*c.scale + 128) >> 8) +func (c *Context) FUnitToFix32(x int) raster.Fix32 { + return raster.Fix32((x*c.scale + 128) >> 8) } // FUnitToPixelRD converts the given number of FUnits into pixel units, @@ -71,14 +71,14 @@ func (c *Context) FUnitToPixelRU(x int) int { return (x*c.scale + 0xffff) >> 16 } -// PointToFixed converts the given number of points (as in ``a 12 point font'') +// PointToFix32 converts the given number of points (as in ``a 12 point font'') // into fixed point units. -func (c *Context) PointToFixed(x float) raster.Fixed { - return raster.Fixed(x * float(c.dpi) * (256.0 / 72.0)) +func (c *Context) PointToFix32(x float) raster.Fix32 { + return raster.Fix32(x * float(c.dpi) * (256.0 / 72.0)) } // drawContour draws the given closed contour with the given offset. -func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fixed) { +func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fix32) { if len(ps) == 0 { return } @@ -86,15 +86,15 @@ func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fixed) { // 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.FUnitToFixed(int(ps[0].X)), - dy + c.FUnitToFixed(c.upe-int(ps[0].Y)), + dx + c.FUnitToFix32(int(ps[0].X)), + dy + c.FUnitToFix32(c.upe-int(ps[0].Y)), } c.r.Start(start) q0, on0 := start, true for _, p := range ps[1:] { q := raster.Point{ - dx + c.FUnitToFixed(int(p.X)), - dy + c.FUnitToFixed(c.upe-int(p.Y)), + dx + c.FUnitToFix32(int(p.X)), + dy + c.FUnitToFix32(c.upe-int(p.Y)), } on := p.Flags&0x01 != 0 if on { @@ -134,13 +134,13 @@ func (c *Context) DrawText(p raster.Painter, pt raster.Point, s string) (err os. if c.font == nil { return os.NewError("freetype: DrawText called with a nil font") } - // pt.X, pt.Y, x, y, dx, dy and x0 are measured in raster.Fixed units, + // pt.X, pt.Y, x, y, dx, dy and x0 are measured in raster.Fix32 units, // c.r.Dx, c.r.Dy, c.xmin and c.ymin are measured in pixels, and // advance is measured in FUnits. - var x, y raster.Fixed + var x, y raster.Fix32 advance, x0 := 0, pt.X - dx := raster.Fixed(-c.xmin << 8) - dy := raster.Fixed(-c.ymin << 8) + dx := raster.Fix32(-c.xmin << 8) + dy := raster.Fix32(-c.ymin << 8) c.r.Dy, y = c.ymin+int(pt.Y>>8), pt.Y&0xff y += dy prev, hasPrev := truetype.Index(0), false @@ -162,8 +162,8 @@ func (c *Context) DrawText(p raster.Painter, pt raster.Point, s string) (err os. return } } - // Convert the advance from FUnits to raster.Fixed units. - x = x0 + c.FUnitToFixed(advance) + // Convert the advance from FUnits to raster.Fix32 units. + x = x0 + c.FUnitToFix32(advance) // Break the co-ordinate down into an integer pixel part and a // sub-pixel part, making sure that the latter is non-negative. c.r.Dx, x = c.xmin+int(x>>8), x&0xff diff --git a/freetype/raster/geom.go b/freetype/raster/geom.go index 409cc9d..44753c2 100644 --- a/freetype/raster/geom.go +++ b/freetype/raster/geom.go @@ -10,15 +10,15 @@ import ( "math" ) -// A Fixed is a 24.8 fixed point number. -type Fixed int32 +// A Fix32 is a 24.8 fixed point number. +type Fix32 int32 -// A Fixed64 is a 48.16 fixed point number. -type Fixed64 int64 +// A Fix64 is a 48.16 fixed point number. +type Fix64 int64 // String returns a human-readable representation of a 24.8 fixed point number. // For example, the number one-and-a-quarter becomes "1:064". -func (x Fixed) String() string { +func (x Fix32) String() string { i, f := x/256, x%256 if f < 0 { f = -f @@ -28,7 +28,7 @@ func (x Fixed) String() string { // String returns a human-readable representation of a 48.16 fixed point number. // For example, the number one-and-a-quarter becomes "1:00064". -func (x Fixed64) String() string { +func (x Fix64) String() string { i, f := x/65536, x%65536 if f < 0 { f = -f @@ -37,7 +37,7 @@ func (x Fixed64) String() string { } // maxAbs returns the maximum of abs(a) and abs(b). -func maxAbs(a, b Fixed) Fixed { +func maxAbs(a, b Fix32) Fix32 { if a < 0 { a = -a } @@ -53,7 +53,7 @@ func maxAbs(a, b Fixed) Fixed { // A Point represents a two-dimensional point or vector, in 24.8 fixed point // format. type Point struct { - X, Y Fixed + X, Y Fix32 } // Add returns the vector p + q. @@ -67,7 +67,7 @@ func (p Point) Sub(q Point) Point { } // Mul returns the vector k * p. -func (p Point) Mul(k Fixed) Point { +func (p Point) Mul(k Fix32) Point { return Point{p.X * k / 256, p.Y * k / 256} } @@ -77,23 +77,23 @@ func (p Point) Neg() Point { } // Dot returns the dot product p·q. -func (p Point) Dot(q Point) Fixed64 { +func (p Point) Dot(q Point) Fix64 { px, py := int64(p.X), int64(p.Y) qx, qy := int64(q.X), int64(q.Y) - return Fixed64(px*qx + py*qy) + return Fix64(px*qx + py*qy) } // Len returns the length of the vector p. -func (p Point) Len() Fixed { +func (p Point) Len() Fix32 { // TODO(nigeltao): use fixed point math. x := float64(p.X) y := float64(p.Y) - return Fixed(math.Sqrt(x*x + y*y)) + return Fix32(math.Sqrt(x*x + y*y)) } // Norm returns the vector p normalized to the given length, or the zero Point // if p is degenerate. -func (p Point) Norm(length Fixed) Point { +func (p Point) Norm(length Fix32) Point { d := p.Len() if d == 0 { return Point{0, 0} @@ -101,7 +101,7 @@ func (p Point) Norm(length Fixed) Point { s, t := int64(length), int64(d) x := int64(p.X) * s / t y := int64(p.Y) * s / t - return Point{Fixed(x), Fixed(y)} + return Point{Fix32(x), Fix32(y)} } // Rot45CW returns the vector p rotated clockwise by 45 degrees. @@ -111,7 +111,7 @@ func (p Point) Rot45CW() Point { px, py := int64(p.X), int64(p.Y) qx := (+px - py) * 181 / 256 qy := (+px + py) * 181 / 256 - return Point{Fixed(qx), Fixed(qy)} + return Point{Fix32(qx), Fix32(qy)} } // Rot90CW returns the vector p rotated clockwise by 90 degrees. @@ -127,7 +127,7 @@ func (p Point) Rot135CW() Point { px, py := int64(p.X), int64(p.Y) qx := (-px - py) * 181 / 256 qy := (+px - py) * 181 / 256 - return Point{Fixed(qx), Fixed(qy)} + return Point{Fix32(qx), Fix32(qy)} } // Rot45CCW returns the vector p rotated counter-clockwise by 45 degrees. @@ -137,7 +137,7 @@ func (p Point) Rot45CCW() Point { px, py := int64(p.X), int64(p.Y) qx := (+px + py) * 181 / 256 qy := (-px + py) * 181 / 256 - return Point{Fixed(qx), Fixed(qy)} + return Point{Fix32(qx), Fix32(qy)} } // Rot90CCW returns the vector p rotated counter-clockwise by 90 degrees. @@ -153,7 +153,7 @@ func (p Point) Rot135CCW() Point { px, py := int64(p.X), int64(p.Y) qx := (-px + py) * 181 / 256 qy := (-px - py) * 181 / 256 - return Point{Fixed(qx), Fixed(qy)} + return Point{Fix32(qx), Fix32(qy)} } // An Adder accumulates points on a curve. @@ -170,7 +170,7 @@ type Adder interface { // A Path is a sequence of curves, and a curve is a start point followed by a // sequence of linear, quadratic or cubic segments. -type Path []Fixed +type Path []Fix32 // String returns a human-readable representation of a Path. func (p Path) String() string { @@ -181,16 +181,16 @@ func (p Path) String() string { } switch p[i] { case 0: - s += "S0" + fmt.Sprint([]Fixed(p[i+1:i+3])) + s += "S0" + fmt.Sprint([]Fix32(p[i+1:i+3])) i += 4 case 1: - s += "A1" + fmt.Sprint([]Fixed(p[i+1:i+3])) + s += "A1" + fmt.Sprint([]Fix32(p[i+1:i+3])) i += 4 case 2: - s += "A2" + fmt.Sprint([]Fixed(p[i+1:i+5])) + s += "A2" + fmt.Sprint([]Fix32(p[i+1:i+5])) i += 6 case 3: - s += "A3" + fmt.Sprint([]Fixed(p[i+1:i+7])) + s += "A3" + fmt.Sprint([]Fix32(p[i+1:i+7])) i += 8 default: panic("freetype/raster: bad path") @@ -204,7 +204,7 @@ func (p *Path) grow(n int) { n += len(*p) if n > cap(*p) { old := *p - *p = make([]Fixed, n, 2*n+8) + *p = make([]Fix32, n, 2*n+8) copy(*p, old) return } @@ -291,13 +291,13 @@ const ( ) // AddStroke adds a stroked Path. -func (p *Path) AddStroke(q Path, width Fixed, cap Cap, join Join) { +func (p *Path) AddStroke(q Path, width Fix32, cap Cap, join Join) { Stroke(p, q, width, cap, join) } // Stroke adds the stroked Path q to p. The resultant stroked path is typically // self-intersecting and should be rasterized with UseNonZeroWinding. -func Stroke(p Adder, q Path, width Fixed, cap Cap, join Join) { +func Stroke(p Adder, q Path, width Fix32, cap Cap, join Join) { if len(q) == 0 { return } @@ -446,17 +446,17 @@ func addArc(p Adder, pivot, n0, n1 Point) { // d is the normalized dot product between s and n1. Since the angle ranges // between 0 and 45 degrees then d ranges between 256/256 and 181/256. d := 256 * s.Dot(n1) / r2 - multiple := Fixed(150 - 22*(d-181)/(256-181)) + multiple := Fix32(150 - 22*(d-181)/(256-181)) p.Add2(pivot.Add(s.Add(n1).Mul(multiple)), pivot.Add(n1)) } // stroke adds the stroked Path q to p, where q consists of exactly one curve. -func stroke(p Adder, q Path, width Fixed, cap Cap, join Join) { +func stroke(p Adder, q Path, width Fix32, cap Cap, join Join) { // Stroking is implemented by deriving two paths each width/2 apart from q. // The left-hand-side path is added immediately to p; the right-hand-side // path is accumulated in r, and once we've finished adding the LHS to p // we add the RHS in reverse order. - r := Path(make([]Fixed, 0, len(q))) + r := Path(make([]Fix32, 0, len(q))) var start, anorm Point a := Point{q[1], q[2]} i := 4 diff --git a/freetype/raster/raster.go b/freetype/raster/raster.go index 3c678ca..2e39438 100644 --- a/freetype/raster/raster.go +++ b/freetype/raster/raster.go @@ -116,12 +116,12 @@ func (r *Rasterizer) setCell(xi, yi int) { // scan accumulates area/coverage for the yi'th scanline, going from // x0 to x1 in the horizontal direction (in 24.8 fixed point co-ordinates) // and from y0f to y1f fractional vertical units within that scanline. -func (r *Rasterizer) scan(yi int, x0, y0f, x1, y1f Fixed) { +func (r *Rasterizer) scan(yi int, x0, y0f, x1, y1f Fix32) { // Break the 24.8 fixed point X co-ordinates into integral and fractional parts. x0i := int(x0) / 256 - x0f := x0 - Fixed(256*x0i) + x0f := x0 - Fix32(256*x0i) x1i := int(x1) / 256 - x1f := x1 - Fixed(256*x1i) + x1f := x1 - Fix32(256*x1i) // A perfectly horizontal scan. if y0f == y1f { @@ -139,7 +139,7 @@ func (r *Rasterizer) scan(yi int, x0, y0f, x1, y1f Fixed) { // all intermediate cells go through the full width of the cell, // or 256 units in 24.8 fixed point format. var ( - p, q, edge0, edge1 Fixed + p, q, edge0, edge1 Fix32 xiDelta int ) if dx > 0 { @@ -201,9 +201,9 @@ func (r *Rasterizer) Add1(b Point) { dx, dy := x1-x0, y1-y0 // Break the 24.8 fixed point Y co-ordinates into integral and fractional parts. y0i := int(y0) / 256 - y0f := y0 - Fixed(256*y0i) + y0f := y0 - Fix32(256*y0i) y1i := int(y1) / 256 - y1f := y1 - Fixed(256*y1i) + y1f := y1 - Fix32(256*y1i) if y0i == y1i { // There is only one scanline. @@ -213,7 +213,7 @@ func (r *Rasterizer) Add1(b Point) { // This is a vertical line segment. We avoid calling r.scan and instead // manipulate r.area and r.cover directly. var ( - edge0, edge1 Fixed + edge0, edge1 Fix32 yiDelta int ) if dy > 0 { @@ -250,7 +250,7 @@ func (r *Rasterizer) Add1(b Point) { // all intermediate scanlines go through the full height of the row, or 256 // units in 24.8 fixed point format. var ( - p, q, edge0, edge1 Fixed + p, q, edge0, edge1 Fix32 yiDelta int ) if dy > 0 { @@ -302,7 +302,7 @@ func (r *Rasterizer) Add1(b Point) { func (r *Rasterizer) Add2(b, c Point) { // Calculate nSplit (the number of recursive decompositions) based on how `curvy' it is. // Specifically, how much the middle point b deviates from (a+c)/2. - dev := maxAbs(r.a.X-2*b.X+c.X, r.a.Y-2*b.Y+c.Y) / Fixed(r.splitScale2) + dev := maxAbs(r.a.X-2*b.X+c.X, r.a.Y-2*b.Y+c.Y) / Fix32(r.splitScale2) nsplit := 0 for dev > 0 { dev /= 4 @@ -357,8 +357,8 @@ func (r *Rasterizer) Add2(b, c Point) { // Add3 adds a cubic segment to the current curve. func (r *Rasterizer) Add3(b, c, d Point) { // Calculate nSplit (the number of recursive decompositions) based on how `curvy' it is. - dev2 := maxAbs(r.a.X-3*(b.X+c.X)+d.X, r.a.Y-3*(b.Y+c.Y)+d.Y) / Fixed(r.splitScale2) - dev3 := maxAbs(r.a.X-2*b.X+d.X, r.a.Y-2*b.Y+d.Y) / Fixed(r.splitScale3) + dev2 := maxAbs(r.a.X-3*(b.X+c.X)+d.X, r.a.Y-3*(b.Y+c.Y)+d.Y) / Fix32(r.splitScale2) + dev3 := maxAbs(r.a.X-2*b.X+d.X, r.a.Y-2*b.Y+d.Y) / Fix32(r.splitScale3) nsplit := 0 for dev2 > 0 || dev3 > 0 { dev2 /= 8 @@ -443,7 +443,7 @@ func (r *Rasterizer) AddPath(p Path) { } // AddStroke adds a stroked Path. -func (r *Rasterizer) AddStroke(q Path, width Fixed, cap Cap, join Join) { +func (r *Rasterizer) AddStroke(q Path, width Fix32, cap Cap, join Join) { Stroke(r, q, width, cap, join) } @@ -541,7 +541,7 @@ func (r *Rasterizer) Clear() { } // SetBounds sets the maximum width and height of the rasterized image and -// calls Clear. The width and height are in pixels, not Fixed units. +// calls Clear. The width and height are in pixels, not Fix32 units. func (r *Rasterizer) SetBounds(width, height int) { if width < 0 { width = 0