提交 06369b10 编写于 作者: N Nigel Tao

freetype: add a clip rectangle.

R=r
CC=golang-dev
http://codereview.appspot.com/2171045
上级 570e8c24
......@@ -91,6 +91,7 @@ func main() {
c.SetDPI(*dpi)
c.SetFont(font)
c.SetFontSize(*size)
c.SetClip(rgba.Bounds())
c.SetDst(rgba)
c.SetSrc(fg)
......
......@@ -56,6 +56,8 @@ type Context struct {
glyphBuf *truetype.GlyphBuf
// pt is the location where drawing starts.
pt raster.Point
// clip is the clip rectangle for drawing.
clip image.Rectangle
// dst and src are the destination and source images for drawing.
dst draw.Image
src image.Image
......@@ -228,7 +230,12 @@ func (c *Context) DrawText(s string) os.Error {
return err
}
c.pt.X += c.FUnitToFix32(int(c.font.HMetric(index).AdvanceWidth))
draw.DrawMask(c.dst, mask.Bounds().Add(offset), c.src, image.ZP, mask, image.ZP, draw.Over)
glyphRect := mask.Bounds().Add(offset)
dr := c.clip.Intersect(glyphRect)
if !dr.Empty() {
mp := image.Point{0, dr.Min.Y - glyphRect.Min.Y}
draw.DrawMask(c.dst, dr, c.src, image.ZP, mask, mp, draw.Over)
}
prev, hasPrev = index, true
}
return nil
......@@ -302,6 +309,11 @@ func (c *Context) SetPoint(pt raster.Point) {
c.pt = pt
}
// SetClip sets the clip rectangle for drawing.
func (c *Context) SetClip(clip image.Rectangle) {
c.clip = clip
}
// TODO(nigeltao): implement Context.SetGamma.
// NewContext creates a new Context.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册