提交 97ddbbf4 编写于 作者: N Nigel Tao

freetype: gofix errors.

R=rsc, r
CC=golang-dev
http://codereview.appspot.com/5339048
上级 7b867fea
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
package freetype package freetype
import ( import (
"errors"
"freetype-go.googlecode.com/hg/freetype/raster" "freetype-go.googlecode.com/hg/freetype/raster"
"freetype-go.googlecode.com/hg/freetype/truetype" "freetype-go.googlecode.com/hg/freetype/truetype"
"image" "image"
"image/draw" "image/draw"
"os"
) )
// These constants determine the size of the glyph cache. The cache is keyed // These constants determine the size of the glyph cache. The cache is keyed
...@@ -39,7 +39,7 @@ type cacheEntry struct { ...@@ -39,7 +39,7 @@ type cacheEntry struct {
// ParseFont just calls the Parse function from the freetype/truetype package. // ParseFont just calls the Parse function from the freetype/truetype package.
// It is provided here so that code that imports this package doesn't need // It is provided here so that code that imports this package doesn't need
// to also include the freetype/truetype package. // to also include the freetype/truetype package.
func ParseFont(b []byte) (*truetype.Font, os.Error) { func ParseFont(b []byte) (*truetype.Font, error) {
return truetype.Parse(b) return truetype.Parse(b)
} }
...@@ -151,7 +151,7 @@ func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fix32) { ...@@ -151,7 +151,7 @@ func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fix32) {
// rasterize returns the glyph mask and integer-pixel offset to render the // rasterize returns the glyph mask and integer-pixel offset to render the
// given glyph at the given sub-pixel offsets. // given glyph at the given sub-pixel offsets.
// The 24.8 fixed point arguments fx and fy must be in the range [0, 1). // The 24.8 fixed point arguments fx and fy must be in the range [0, 1).
func (c *Context) rasterize(glyph truetype.Index, fx, fy raster.Fix32) (*image.Alpha, image.Point, os.Error) { func (c *Context) rasterize(glyph truetype.Index, fx, fy raster.Fix32) (*image.Alpha, image.Point, error) {
if err := c.glyphBuf.Load(c.font, glyph); err != nil { if err := c.glyphBuf.Load(c.font, glyph); err != nil {
return nil, image.ZP, err return nil, image.ZP, err
} }
...@@ -161,7 +161,7 @@ func (c *Context) rasterize(glyph truetype.Index, fx, fy raster.Fix32) (*image.A ...@@ -161,7 +161,7 @@ func (c *Context) rasterize(glyph truetype.Index, fx, fy raster.Fix32) (*image.A
xmax := int(fx+c.FUnitToFix32(+int(c.glyphBuf.B.XMax))+0xff) >> 8 xmax := int(fx+c.FUnitToFix32(+int(c.glyphBuf.B.XMax))+0xff) >> 8
ymax := int(fy+c.FUnitToFix32(-int(c.glyphBuf.B.YMin))+0xff) >> 8 ymax := int(fy+c.FUnitToFix32(-int(c.glyphBuf.B.YMin))+0xff) >> 8
if xmin > xmax || ymin > ymax { if xmin > xmax || ymin > ymax {
return nil, image.ZP, os.NewError("freetype: negative sized glyph") return nil, image.ZP, errors.New("freetype: negative sized glyph")
} }
// A TrueType's glyph's nodes can have negative co-ordinates, but the // A TrueType's glyph's nodes can have negative co-ordinates, but the
// rasterizer clips anything left of x=0 or above y=0. xmin and ymin // rasterizer clips anything left of x=0 or above y=0. xmin and ymin
...@@ -185,7 +185,7 @@ func (c *Context) rasterize(glyph truetype.Index, fx, fy raster.Fix32) (*image.A ...@@ -185,7 +185,7 @@ func (c *Context) rasterize(glyph truetype.Index, fx, fy raster.Fix32) (*image.A
// glyph returns the glyph mask and integer-pixel offset to render the given // glyph returns the glyph mask and integer-pixel offset to render the given
// glyph at the given sub-pixel point. It is a cache for the rasterize method. // glyph at the given sub-pixel point. It is a cache for the rasterize method.
// Unlike rasterize, p's co-ordinates do not have to be in the range [0, 1). // Unlike rasterize, p's co-ordinates do not have to be in the range [0, 1).
func (c *Context) glyph(glyph truetype.Index, p raster.Point) (*image.Alpha, image.Point, os.Error) { func (c *Context) glyph(glyph truetype.Index, p raster.Point) (*image.Alpha, image.Point, error) {
// Split p.X and p.Y into their integer and fractional parts. // Split p.X and p.Y into their integer and fractional parts.
ix, fx := int(p.X>>8), p.X&0xff ix, fx := int(p.X>>8), p.X&0xff
iy, fy := int(p.Y>>8), p.Y&0xff iy, fy := int(p.Y>>8), p.Y&0xff
...@@ -214,9 +214,9 @@ func (c *Context) glyph(glyph truetype.Index, p raster.Point) (*image.Alpha, ima ...@@ -214,9 +214,9 @@ func (c *Context) glyph(glyph truetype.Index, p raster.Point) (*image.Alpha, ima
// For example, drawing a string that starts with a 'J' in an italic font may // For example, drawing a string that starts with a 'J' in an italic font may
// affect pixels below and left of the point. // affect pixels below and left of the point.
// p is a raster.Point and can therefore represent sub-pixel positions. // p is a raster.Point and can therefore represent sub-pixel positions.
func (c *Context) DrawString(s string, p raster.Point) (raster.Point, os.Error) { func (c *Context) DrawString(s string, p raster.Point) (raster.Point, error) {
if c.font == nil { if c.font == nil {
return raster.Point{}, os.NewError("freetype: DrawText called with a nil font") return raster.Point{}, errors.New("freetype: DrawText called with a nil font")
} }
prev, hasPrev := truetype.Index(0), false prev, hasPrev := truetype.Index(0), false
for _, rune := range s { for _, rune := range s {
......
...@@ -15,7 +15,6 @@ package truetype ...@@ -15,7 +15,6 @@ package truetype
import ( import (
"fmt" "fmt"
"os"
) )
// An Index is a Font's index of a Unicode code point. // An Index is a Font's index of a Unicode code point.
...@@ -36,7 +35,7 @@ type HMetric struct { ...@@ -36,7 +35,7 @@ type HMetric struct {
// A FormatError reports that the input is not a valid TrueType font. // A FormatError reports that the input is not a valid TrueType font.
type FormatError string type FormatError string
func (e FormatError) String() string { func (e FormatError) Error() string {
return "freetype: invalid TrueType format: " + string(e) return "freetype: invalid TrueType format: " + string(e)
} }
...@@ -44,7 +43,7 @@ func (e FormatError) String() string { ...@@ -44,7 +43,7 @@ func (e FormatError) String() string {
// TrueType feature. // TrueType feature.
type UnsupportedError string type UnsupportedError string
func (e UnsupportedError) String() string { func (e UnsupportedError) Error() string {
return "freetype: unsupported TrueType feature: " + string(e) return "freetype: unsupported TrueType feature: " + string(e)
} }
...@@ -78,7 +77,7 @@ func (d *data) skip(n int) { ...@@ -78,7 +77,7 @@ func (d *data) skip(n int) {
} }
// readTable returns a slice of the TTF data given by a table's directory entry. // readTable returns a slice of the TTF data given by a table's directory entry.
func readTable(ttf []byte, offsetLength []byte) ([]byte, os.Error) { func readTable(ttf []byte, offsetLength []byte) ([]byte, error) {
d := data(offsetLength) d := data(offsetLength)
offset := int(d.u32()) offset := int(d.u32())
if offset < 0 || offset > 1<<24 || offset > len(ttf) { if offset < 0 || offset > 1<<24 || offset > len(ttf) {
...@@ -117,7 +116,7 @@ type Font struct { ...@@ -117,7 +116,7 @@ type Font struct {
bounds Bounds bounds Bounds
} }
func (f *Font) parseCmap() os.Error { func (f *Font) parseCmap() error {
const ( const (
cmapFormat4 = 4 cmapFormat4 = 4
languageIndependent = 0 languageIndependent = 0
...@@ -192,7 +191,7 @@ func (f *Font) parseCmap() os.Error { ...@@ -192,7 +191,7 @@ func (f *Font) parseCmap() os.Error {
return nil return nil
} }
func (f *Font) parseHead() os.Error { func (f *Font) parseHead() error {
if len(f.head) != 54 { if len(f.head) != 54 {
return FormatError(fmt.Sprintf("bad head length: %d", len(f.head))) return FormatError(fmt.Sprintf("bad head length: %d", len(f.head)))
} }
...@@ -215,7 +214,7 @@ func (f *Font) parseHead() os.Error { ...@@ -215,7 +214,7 @@ func (f *Font) parseHead() os.Error {
return nil return nil
} }
func (f *Font) parseHhea() os.Error { func (f *Font) parseHhea() error {
if len(f.hhea) != 36 { if len(f.hhea) != 36 {
return FormatError(fmt.Sprintf("bad hhea length: %d", len(f.hhea))) return FormatError(fmt.Sprintf("bad hhea length: %d", len(f.hhea)))
} }
...@@ -227,7 +226,7 @@ func (f *Font) parseHhea() os.Error { ...@@ -227,7 +226,7 @@ func (f *Font) parseHhea() os.Error {
return nil return nil
} }
func (f *Font) parseKern() os.Error { func (f *Font) parseKern() error {
// Apple's TrueType documentation (http://developer.apple.com/fonts/TTRefMan/RM06/Chap6kern.html) says: // Apple's TrueType documentation (http://developer.apple.com/fonts/TTRefMan/RM06/Chap6kern.html) says:
// "Previous versions of the 'kern' table defined both the version and nTables fields in the header // "Previous versions of the 'kern' table defined both the version and nTables fields in the header
// as UInt16 values and not UInt32 values. Use of the older format on the Mac OS is discouraged // as UInt16 values and not UInt32 values. Use of the older format on the Mac OS is discouraged
...@@ -269,7 +268,7 @@ func (f *Font) parseKern() os.Error { ...@@ -269,7 +268,7 @@ func (f *Font) parseKern() os.Error {
return nil return nil
} }
func (f *Font) parseMaxp() os.Error { func (f *Font) parseMaxp() error {
if len(f.maxp) != 32 { if len(f.maxp) != 32 {
return FormatError(fmt.Sprintf("bad maxp length: %d", len(f.maxp))) return FormatError(fmt.Sprintf("bad maxp length: %d", len(f.maxp)))
} }
...@@ -348,7 +347,7 @@ func (f *Font) Kerning(i0, i1 Index) int16 { ...@@ -348,7 +347,7 @@ func (f *Font) Kerning(i0, i1 Index) int16 {
} }
// Parse returns a new Font for the given TTF data. // Parse returns a new Font for the given TTF data.
func Parse(ttf []byte) (font *Font, err os.Error) { func Parse(ttf []byte) (font *Font, err error) {
if len(ttf) < 12 { if len(ttf) < 12 {
err = FormatError("TTF data is too short") err = FormatError("TTF data is too short")
return return
...@@ -503,7 +502,7 @@ func (g *GlyphBuf) decodeCoords(d data, np0 int) { ...@@ -503,7 +502,7 @@ func (g *GlyphBuf) decodeCoords(d data, np0 int) {
// Load loads a glyph's contours from a Font, overwriting any previously // Load loads a glyph's contours from a Font, overwriting any previously
// loaded contours for this GlyphBuf. // loaded contours for this GlyphBuf.
func (g *GlyphBuf) Load(f *Font, i Index) os.Error { func (g *GlyphBuf) Load(f *Font, i Index) error {
// Reset the GlyphBuf. // Reset the GlyphBuf.
g.B = Bounds{} g.B = Bounds{}
g.Point = g.Point[0:0] g.Point = g.Point[0:0]
...@@ -512,7 +511,7 @@ func (g *GlyphBuf) Load(f *Font, i Index) os.Error { ...@@ -512,7 +511,7 @@ func (g *GlyphBuf) Load(f *Font, i Index) os.Error {
} }
// loadCompound loads a glyph that is composed of other glyphs. // loadCompound loads a glyph that is composed of other glyphs.
func (g *GlyphBuf) loadCompound(f *Font, d data, recursion int) os.Error { func (g *GlyphBuf) loadCompound(f *Font, d data, recursion int) error {
// Flags for decoding a compound glyph. These flags are documented at // Flags for decoding a compound glyph. These flags are documented at
// http://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html. // http://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html.
const ( const (
...@@ -562,7 +561,7 @@ func (g *GlyphBuf) loadCompound(f *Font, d data, recursion int) os.Error { ...@@ -562,7 +561,7 @@ func (g *GlyphBuf) loadCompound(f *Font, d data, recursion int) os.Error {
} }
// load appends a glyph's contours to this GlyphBuf. // load appends a glyph's contours to this GlyphBuf.
func (g *GlyphBuf) load(f *Font, i Index, recursion int) os.Error { func (g *GlyphBuf) load(f *Font, i Index, recursion int) error {
if recursion >= 4 { if recursion >= 4 {
return UnsupportedError("excessive compound glyph recursion") return UnsupportedError("excessive compound glyph recursion")
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册