freetype: gofix errors.
R=rsc, r CC=golang-dev http://codereview.appspot.com/5339048
This commit is contained in:
parent
7b867fea2e
commit
97ddbbf4d0
2 changed files with 19 additions and 20 deletions
|
@ -9,11 +9,11 @@
|
|||
package freetype
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"freetype-go.googlecode.com/hg/freetype/raster"
|
||||
"freetype-go.googlecode.com/hg/freetype/truetype"
|
||||
"image"
|
||||
"image/draw"
|
||||
"os"
|
||||
)
|
||||
|
||||
// These constants determine the size of the glyph cache. The cache is keyed
|
||||
|
@ -39,7 +39,7 @@ type cacheEntry struct {
|
|||
// 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
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
// given glyph at the given sub-pixel offsets.
|
||||
// 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 {
|
||||
return nil, image.ZP, err
|
||||
}
|
||||
|
@ -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
|
||||
ymax := int(fy+c.FUnitToFix32(-int(c.glyphBuf.B.YMin))+0xff) >> 8
|
||||
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
|
||||
// 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
|
|||
// 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.
|
||||
// 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.
|
||||
ix, fx := int(p.X>>8), p.X&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
|
|||
// For example, drawing a string that starts with a 'J' in an italic font may
|
||||
// affect pixels below and left of the point.
|
||||
// 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 {
|
||||
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
|
||||
for _, rune := range s {
|
||||
|
|
|
@ -15,7 +15,6 @@ package truetype
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// An Index is a Font's index of a Unicode code point.
|
||||
|
@ -36,7 +35,7 @@ type HMetric struct {
|
|||
// A FormatError reports that the input is not a valid TrueType font.
|
||||
type FormatError string
|
||||
|
||||
func (e FormatError) String() string {
|
||||
func (e FormatError) Error() string {
|
||||
return "freetype: invalid TrueType format: " + string(e)
|
||||
}
|
||||
|
||||
|
@ -44,7 +43,7 @@ func (e FormatError) String() string {
|
|||
// TrueType feature.
|
||||
type UnsupportedError string
|
||||
|
||||
func (e UnsupportedError) String() string {
|
||||
func (e UnsupportedError) Error() string {
|
||||
return "freetype: unsupported TrueType feature: " + string(e)
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
func readTable(ttf []byte, offsetLength []byte) ([]byte, os.Error) {
|
||||
func readTable(ttf []byte, offsetLength []byte) ([]byte, error) {
|
||||
d := data(offsetLength)
|
||||
offset := int(d.u32())
|
||||
if offset < 0 || offset > 1<<24 || offset > len(ttf) {
|
||||
|
@ -117,7 +116,7 @@ type Font struct {
|
|||
bounds Bounds
|
||||
}
|
||||
|
||||
func (f *Font) parseCmap() os.Error {
|
||||
func (f *Font) parseCmap() error {
|
||||
const (
|
||||
cmapFormat4 = 4
|
||||
languageIndependent = 0
|
||||
|
@ -192,7 +191,7 @@ func (f *Font) parseCmap() os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f *Font) parseHead() os.Error {
|
||||
func (f *Font) parseHead() error {
|
||||
if len(f.head) != 54 {
|
||||
return FormatError(fmt.Sprintf("bad head length: %d", len(f.head)))
|
||||
}
|
||||
|
@ -215,7 +214,7 @@ func (f *Font) parseHead() os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f *Font) parseHhea() os.Error {
|
||||
func (f *Font) parseHhea() error {
|
||||
if len(f.hhea) != 36 {
|
||||
return FormatError(fmt.Sprintf("bad hhea length: %d", len(f.hhea)))
|
||||
}
|
||||
|
@ -227,7 +226,7 @@ func (f *Font) parseHhea() os.Error {
|
|||
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:
|
||||
// "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
|
||||
|
@ -269,7 +268,7 @@ func (f *Font) parseKern() os.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f *Font) parseMaxp() os.Error {
|
||||
func (f *Font) parseMaxp() error {
|
||||
if len(f.maxp) != 32 {
|
||||
return FormatError(fmt.Sprintf("bad maxp length: %d", len(f.maxp)))
|
||||
}
|
||||
|
@ -348,7 +347,7 @@ func (f *Font) Kerning(i0, i1 Index) int16 {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
err = FormatError("TTF data is too short")
|
||||
return
|
||||
|
@ -503,7 +502,7 @@ func (g *GlyphBuf) decodeCoords(d data, np0 int) {
|
|||
|
||||
// Load loads a glyph's contours from a Font, overwriting any previously
|
||||
// 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.
|
||||
g.B = Bounds{}
|
||||
g.Point = g.Point[0:0]
|
||||
|
@ -512,7 +511,7 @@ func (g *GlyphBuf) Load(f *Font, i Index) os.Error {
|
|||
}
|
||||
|
||||
// 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
|
||||
// http://developer.apple.com/fonts/TTRefMan/RM06/Chap6glyf.html.
|
||||
const (
|
||||
|
@ -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.
|
||||
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 {
|
||||
return UnsupportedError("excessive compound glyph recursion")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue