From 380b6363b2a7f2fac100a394cff9ca5062019f1f Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 21 Jan 2011 12:27:50 +1100 Subject: [PATCH] freetype: s/float/float64/. R=adg, r2 CC=golang-dev http://codereview.appspot.com/4040045 --- example/freetype/main.go | 4 ++-- example/gamma/main.go | 2 +- freetype/freetype.go | 10 +++++----- freetype/raster/paint.go | 7 +++---- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/example/freetype/main.go b/example/freetype/main.go index 4452286..c7e45b1 100644 --- a/example/freetype/main.go +++ b/example/freetype/main.go @@ -21,8 +21,8 @@ import ( var ( dpi = flag.Int("dpi", 72, "screen resolution in Dots Per Inch") fontfile = flag.String("fontfile", "../../luxi-fonts/luxisr.ttf", "filename of the ttf font") - size = flag.Float("size", 12, "font size in points") - spacing = flag.Float("spacing", 1.5, "line spacing (e.g. 2 means double spaced)") + size = flag.Float64("size", 12, "font size in points") + spacing = flag.Float64("spacing", 1.5, "line spacing (e.g. 2 means double spaced)") wonb = flag.Bool("whiteonblack", false, "white text on a black background") ) diff --git a/example/gamma/main.go b/example/gamma/main.go index 9db9646..b1839a3 100644 --- a/example/gamma/main.go +++ b/example/gamma/main.go @@ -55,7 +55,7 @@ func main() { draw.Draw(rgba, image.Rect(0, h/2, w, h), image.White, image.ZP) mask := image.NewAlpha(50, 50) painter := raster.NewAlphaSrcPainter(mask) - gammas := []float{1.0 / 10.0, 1.0 / 3.0, 1.0 / 2.0, 2.0 / 3.0, 4.0 / 5.0, 1.0, 5.0 / 4.0, 3.0 / 2.0, 2.0, 3.0, 10.0} + gammas := []float64{1.0 / 10.0, 1.0 / 3.0, 1.0 / 2.0, 2.0 / 3.0, 4.0 / 5.0, 1.0, 5.0 / 4.0, 3.0 / 2.0, 2.0, 3.0, 10.0} for i, g := range gammas { clear(mask) r.Rasterize(raster.NewGammaCorrectionPainter(painter, g)) diff --git a/freetype/freetype.go b/freetype/freetype.go index b35e769..d5db987 100644 --- a/freetype/freetype.go +++ b/freetype/freetype.go @@ -69,7 +69,7 @@ type Context struct { // which equals 384 fixed point units per 256 FUnits. // To check this, 1 em * 2048 FUnits per em * 384 fixed point units per 256 FUnits // equals 3072 fixed point units. - fontSize float + fontSize float64 dpi int upe int scale int @@ -97,8 +97,8 @@ func (c *Context) FUnitToPixelRU(x int) int { // PointToFix32 converts the given number of points (as in ``a 12 point font'') // into fixed point units. -func (c *Context) PointToFix32(x float) raster.Fix32 { - return raster.Fix32(x * float(c.dpi) * (256.0 / 72.0)) +func (c *Context) PointToFix32(x float64) raster.Fix32 { + return raster.Fix32(x * float64(c.dpi) * (256.0 / 72.0)) } // drawContour draws the given closed contour with the given offset. @@ -243,7 +243,7 @@ func (c *Context) DrawString(s string, p raster.Point) (raster.Point, os.Error) // recalc recalculates scale and bounds values from the font size, screen // resolution and font metrics, and invalidates the glyph cache. func (c *Context) recalc() { - c.scale = int((c.fontSize * float(c.dpi) * 256 * 256) / (float(c.upe) * 72)) + c.scale = int((c.fontSize * float64(c.dpi) * 256 * 256) / (float64(c.upe) * 72)) if c.font == nil { c.r.SetBounds(0, 0) } else { @@ -283,7 +283,7 @@ func (c *Context) SetFont(font *truetype.Font) { } // SetFontSize sets the font size in points (as in ``a 12 point font''). -func (c *Context) SetFontSize(fontSize float) { +func (c *Context) SetFontSize(fontSize float64) { if c.fontSize == fontSize { return } diff --git a/freetype/raster/paint.go b/freetype/raster/paint.go index c924115..7c0ad89 100644 --- a/freetype/raster/paint.go +++ b/freetype/raster/paint.go @@ -273,23 +273,22 @@ func (g *GammaCorrectionPainter) Paint(ss []Span, done bool) { } // SetGamma sets the gamma value. -func (g *GammaCorrectionPainter) SetGamma(gamma float) { +func (g *GammaCorrectionPainter) SetGamma(gamma float64) { if gamma == 1.0 { g.gammaIsOne = true return } g.gammaIsOne = false - gamma64 := float64(gamma) for i := 0; i < 256; i++ { a := float64(i) / 0xff - a = math.Pow(a, gamma64) + a = math.Pow(a, gamma) g.a[i] = uint16(0xffff * a) } } // NewGammaCorrectionPainter creates a new GammaCorrectionPainter that wraps // the given Painter. -func NewGammaCorrectionPainter(p Painter, gamma float) *GammaCorrectionPainter { +func NewGammaCorrectionPainter(p Painter, gamma float64) *GammaCorrectionPainter { g := &GammaCorrectionPainter{Painter: p} g.SetGamma(gamma) return g