Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小雨青年
freetype
提交
97ddbbf4
F
freetype
项目概览
小雨青年
/
freetype
通知
14
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
freetype
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
97ddbbf4
编写于
11月 08, 2011
作者:
N
Nigel Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
freetype: gofix errors.
R=rsc, r CC=golang-dev
http://codereview.appspot.com/5339048
上级
7b867fea
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
19 addition
and
20 deletion
+19
-20
freetype/freetype.go
freetype/freetype.go
+7
-7
freetype/truetype/truetype.go
freetype/truetype/truetype.go
+12
-13
未找到文件。
freetype/freetype.go
浏览文件 @
97ddbbf4
...
...
@@ -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
.
E
rror
)
{
func
ParseFont
(
b
[]
byte
)
(
*
truetype
.
Font
,
e
rror
)
{
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
.
E
rror
)
{
func
(
c
*
Context
)
rasterize
(
glyph
truetype
.
Index
,
fx
,
fy
raster
.
Fix32
)
(
*
image
.
Alpha
,
image
.
Point
,
e
rror
)
{
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
.
E
rror
)
{
func
(
c
*
Context
)
glyph
(
glyph
truetype
.
Index
,
p
raster
.
Point
)
(
*
image
.
Alpha
,
image
.
Point
,
e
rror
)
{
// 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
.
E
rror
)
{
func
(
c
*
Context
)
DrawString
(
s
string
,
p
raster
.
Point
)
(
raster
.
Point
,
e
rror
)
{
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
{
...
...
freetype/truetype/truetype.go
浏览文件 @
97ddbbf4
...
...
@@ -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
.
E
rror
)
{
func
readTable
(
ttf
[]
byte
,
offsetLength
[]
byte
)
([]
byte
,
e
rror
)
{
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
.
E
rror
{
func
(
f
*
Font
)
parseCmap
()
e
rror
{
const
(
cmapFormat4
=
4
languageIndependent
=
0
...
...
@@ -192,7 +191,7 @@ func (f *Font) parseCmap() os.Error {
return
nil
}
func
(
f
*
Font
)
parseHead
()
os
.
E
rror
{
func
(
f
*
Font
)
parseHead
()
e
rror
{
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
.
E
rror
{
func
(
f
*
Font
)
parseHhea
()
e
rror
{
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
.
E
rror
{
func
(
f
*
Font
)
parseKern
()
e
rror
{
// 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
.
E
rror
{
func
(
f
*
Font
)
parseMaxp
()
e
rror
{
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
.
E
rror
)
{
func
Parse
(
ttf
[]
byte
)
(
font
*
Font
,
err
e
rror
)
{
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
.
E
rror
{
func
(
g
*
GlyphBuf
)
Load
(
f
*
Font
,
i
Index
)
e
rror
{
// 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
.
E
rror
{
func
(
g
*
GlyphBuf
)
loadCompound
(
f
*
Font
,
d
data
,
recursion
int
)
e
rror
{
// 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
.
E
rror
{
func
(
g
*
GlyphBuf
)
load
(
f
*
Font
,
i
Index
,
recursion
int
)
e
rror
{
if
recursion
>=
4
{
return
UnsupportedError
(
"excessive compound glyph recursion"
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录