measuring text width no longer renders the text
This commit is contained in:
parent
8507e9ed71
commit
b32f7eeafc
2 changed files with 10 additions and 5 deletions
13
freetype.go
13
freetype.go
|
@ -136,8 +136,7 @@ func (c *frContext) drawContour(ps []truetype.Point, dx, dy fixed.Int26_6) {
|
||||||
// rasterize returns the advance width, glyph mask and integer-pixel offset
|
// rasterize returns the advance width, glyph mask and integer-pixel offset
|
||||||
// to render the given glyph at the given sub-pixel offsets.
|
// to render the given glyph at the given sub-pixel offsets.
|
||||||
// The 26.6 fixed point arguments fx and fy must be in the range [0, 1).
|
// The 26.6 fixed point arguments fx and fy must be in the range [0, 1).
|
||||||
func (c *frContext) rasterize(glyph truetype.Index, fx, fy fixed.Int26_6) (
|
func (c *frContext) rasterize(glyph truetype.Index, fx, fy fixed.Int26_6) (fixed.Int26_6, *image.Alpha, image.Point, error) {
|
||||||
fixed.Int26_6, *image.Alpha, image.Point, error) {
|
|
||||||
|
|
||||||
if err := c.glyphBuf.Load(c.f, c.scale, glyph, c.hinting); err != nil {
|
if err := c.glyphBuf.Load(c.f, c.scale, glyph, c.hinting); err != nil {
|
||||||
return 0, nil, image.Point{}, err
|
return 0, nil, image.Point{}, err
|
||||||
|
@ -173,8 +172,7 @@ func (c *frContext) rasterize(glyph truetype.Index, fx, fy fixed.Int26_6) (
|
||||||
// render the given glyph at the given sub-pixel point. It is a cache for the
|
// 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
|
// rasterize method. Unlike rasterize, p's co-ordinates do not have to be in
|
||||||
// the range [0, 1).
|
// the range [0, 1).
|
||||||
func (c *frContext) glyph(glyph truetype.Index, p fixed.Point26_6) (
|
func (c *frContext) glyph(glyph truetype.Index, p fixed.Point26_6) (fixed.Int26_6, *image.Alpha, image.Point, error) {
|
||||||
fixed.Int26_6, *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>>6), p.X&0x3f
|
ix, fx := int(p.X>>6), p.X&0x3f
|
||||||
|
@ -197,6 +195,13 @@ func (c *frContext) glyph(glyph truetype.Index, p fixed.Point26_6) (
|
||||||
return advanceWidth, mask, offset.Add(image.Point{ix, iy}), nil
|
return advanceWidth, mask, offset.Add(image.Point{ix, iy}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *frContext) glyphAdvance(glyph truetype.Index) (fixed.Int26_6, error) {
|
||||||
|
if err := c.glyphBuf.Load(c.f, c.scale, glyph, c.hinting); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return c.glyphBuf.AdvanceWidth, nil
|
||||||
|
}
|
||||||
|
|
||||||
const maxInt = int(^uint(0) >> 1)
|
const maxInt = int(^uint(0) >> 1)
|
||||||
|
|
||||||
// DrawString draws s at p and returns p advanced by the text extent. The text
|
// DrawString draws s at p and returns p advanced by the text extent. The text
|
||||||
|
|
2
text.go
2
text.go
|
@ -160,7 +160,7 @@ func (cv *Canvas) MeasureText(str string) TextMetrics {
|
||||||
}
|
}
|
||||||
x += float64(kern) / 64
|
x += float64(kern) / 64
|
||||||
}
|
}
|
||||||
advance, _, _, err := frc.glyph(idx, fixed.Point26_6{})
|
advance, err := frc.glyphAdvance(idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
prev = 0
|
prev = 0
|
||||||
hasPrev = false
|
hasPrev = false
|
||||||
|
|
Loading…
Reference in a new issue