From 7a598da6def50b7891ed3abae20642c78650a530 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 30 Aug 2015 21:35:58 +1000 Subject: [PATCH] Delete the truetype.NewGlyphBuf function. The zero value of a GlyphBuf is already perfectly usable. --- example/truetype/main.go | 2 +- freetype.go | 3 +-- truetype/glyph.go | 10 ---------- truetype/truetype_test.go | 4 ++-- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/example/truetype/main.go b/example/truetype/main.go index 6ab93fc..d188d9b 100644 --- a/example/truetype/main.go +++ b/example/truetype/main.go @@ -66,7 +66,7 @@ func main() { i0 := f.Index(c0) hm := f.HMetric(fupe, i0) - g := truetype.NewGlyphBuf() + g := &truetype.GlyphBuf{} err = g.Load(f, fupe, i0, font.HintingNone) if err != nil { log.Println(err) diff --git a/freetype.go b/freetype.go index 885de24..a1d4ad1 100644 --- a/freetype.go +++ b/freetype.go @@ -60,7 +60,7 @@ func Pt(x, y int) fixed.Point26_6 { type Context struct { r *raster.Rasterizer f *truetype.Font - glyphBuf *truetype.GlyphBuf + glyphBuf truetype.GlyphBuf // clip is the clip rectangle for drawing. clip image.Rectangle // dst and src are the destination and source images for drawing. @@ -334,7 +334,6 @@ func (c *Context) SetClip(clip image.Rectangle) { func NewContext() *Context { return &Context{ r: raster.NewRasterizer(0, 0), - glyphBuf: truetype.NewGlyphBuf(), fontSize: 12, dpi: 72, scale: 12 << 6, diff --git a/truetype/glyph.go b/truetype/glyph.go index 1d549de..7a4946f 100644 --- a/truetype/glyph.go +++ b/truetype/glyph.go @@ -515,13 +515,3 @@ func (g *GlyphBuf) addPhantomsAndScale(np0, np1 int, simple, adjust bool) { p = &g.Point[len(g.Point)-1] p.Y = (p.Y + 32) &^ 63 } - -// TODO: is this necessary? The zero-valued GlyphBuf is perfectly usable. - -// NewGlyphBuf returns a newly allocated GlyphBuf. -func NewGlyphBuf() *GlyphBuf { - return &GlyphBuf{ - Point: make([]Point, 0, 256), - End: make([]int, 0, 32), - } -} diff --git a/truetype/truetype_test.go b/truetype/truetype_test.go index 0f3253d..53b81dc 100644 --- a/truetype/truetype_test.go +++ b/truetype/truetype_test.go @@ -63,7 +63,7 @@ func TestParse(t *testing.T) { t.Errorf("Kern: got %v, want %v", got, want) } - g := NewGlyphBuf() + g := &GlyphBuf{} err = g.Load(f, fupe, i0, font.HintingNone) if err != nil { t.Fatalf("Load: %v", err) @@ -319,7 +319,7 @@ func testScaling(t *testing.T, h font.Hinting) { continue } - glyphBuf := NewGlyphBuf() + glyphBuf := &GlyphBuf{} for i, want := range wants { if err = glyphBuf.Load(f, fixed.I(tc.size), Index(i), h); err != nil { t.Errorf("%s: glyph #%d: Load: %v", tc.name, i, err)