freetype-go: change freetype.DrawText's point to be at the baseline
instead of at 1em above the baseline. R=r CC=golang-dev http://codereview.appspot.com/2042041
This commit is contained in:
parent
29c473cb3e
commit
b8ed0a9c12
|
@ -104,7 +104,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the text.
|
// Draw the text.
|
||||||
pt := freetype.Pt(10, 10)
|
pt := freetype.Pt(10, 10+c.FUnitToPixelRU(font.UnitsPerEm()))
|
||||||
for _, s := range text {
|
for _, s := range text {
|
||||||
err = c.DrawText(gcp, pt, s)
|
err = c.DrawText(gcp, pt, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -87,14 +87,14 @@ func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fix32) {
|
||||||
// going downwards, and offset by (dx, dy)
|
// going downwards, and offset by (dx, dy)
|
||||||
start := raster.Point{
|
start := raster.Point{
|
||||||
dx + c.FUnitToFix32(int(ps[0].X)),
|
dx + c.FUnitToFix32(int(ps[0].X)),
|
||||||
dy + c.FUnitToFix32(c.upe-int(ps[0].Y)),
|
dy + c.FUnitToFix32(-int(ps[0].Y)),
|
||||||
}
|
}
|
||||||
c.r.Start(start)
|
c.r.Start(start)
|
||||||
q0, on0 := start, true
|
q0, on0 := start, true
|
||||||
for _, p := range ps[1:] {
|
for _, p := range ps[1:] {
|
||||||
q := raster.Point{
|
q := raster.Point{
|
||||||
dx + c.FUnitToFix32(int(p.X)),
|
dx + c.FUnitToFix32(int(p.X)),
|
||||||
dy + c.FUnitToFix32(c.upe-int(p.Y)),
|
dy + c.FUnitToFix32(-int(p.Y)),
|
||||||
}
|
}
|
||||||
on := p.Flags&0x01 != 0
|
on := p.Flags&0x01 != 0
|
||||||
if on {
|
if on {
|
||||||
|
@ -124,11 +124,11 @@ func (c *Context) drawContour(ps []truetype.Point, dx, dy raster.Fix32) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawText draws s at pt using p. The text is placed so that the top left of
|
// DrawText draws s at pt using p. The text is placed so that the left edge of
|
||||||
// the em square of the first character of s is equal to pt. The majority of
|
// the em square of the first character of s and the baseline intersect at pt.
|
||||||
// the affected pixels will be below and to the right of pt, but some may be
|
// The majority of the affected pixels will be above and to the right of pt,
|
||||||
// above or to the left. For example, drawing a string that starts with a 'J'
|
// but some may be below or to the left. For example, drawing a string that
|
||||||
// in an italic font may affect pixels to the left of pt.
|
// starts with a 'J' in an italic font may affect pixels below and left of pt.
|
||||||
// pt is a raster.Point and can therefore represent sub-pixel positions.
|
// pt is a raster.Point and can therefore represent sub-pixel positions.
|
||||||
func (c *Context) DrawText(p raster.Painter, pt raster.Point, s string) (err os.Error) {
|
func (c *Context) DrawText(p raster.Painter, pt raster.Point, s string) (err os.Error) {
|
||||||
if c.font == nil {
|
if c.font == nil {
|
||||||
|
@ -192,9 +192,9 @@ func (c *Context) recalc() {
|
||||||
} else {
|
} else {
|
||||||
b := c.font.Bounds()
|
b := c.font.Bounds()
|
||||||
c.xmin = c.FUnitToPixelRD(int(b.XMin))
|
c.xmin = c.FUnitToPixelRD(int(b.XMin))
|
||||||
c.ymin = c.FUnitToPixelRD(c.upe - int(b.YMax))
|
c.ymin = c.FUnitToPixelRD(-int(b.YMax))
|
||||||
xmax := c.FUnitToPixelRU(int(b.XMax))
|
xmax := c.FUnitToPixelRU(int(b.XMax))
|
||||||
ymax := c.FUnitToPixelRU(c.upe - int(b.YMin))
|
ymax := c.FUnitToPixelRU(-int(b.YMin))
|
||||||
c.r.SetBounds(xmax-c.xmin, ymax-c.ymin)
|
c.r.SetBounds(xmax-c.xmin, ymax-c.ymin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue