Fix offset to match Gio paintGlyph exactly: (x + first.X, y + first.Y) with no subtraction
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
eb9754fde0
commit
ddd44baefd
|
|
@ -259,17 +259,19 @@ func (r *Renderer) drawLineText(gtx layout.Context, shp *text.Shaper, x, y unit.
|
||||||
}
|
}
|
||||||
|
|
||||||
// drawLine draws a line of glyphs using shaper.Shape() and shaper.Bitmaps().
|
// drawLine draws a line of glyphs using shaper.Shape() and shaper.Bitmaps().
|
||||||
|
// Matches Gio's paintGlyph exactly: offset by (x + first.X, y + first.Y).
|
||||||
func (r *Renderer) drawLine(gtx layout.Context, shp *text.Shaper, line []text.Glyph, x, y unit.Dp, col color.NRGBA) {
|
func (r *Renderer) drawLine(gtx layout.Context, shp *text.Shaper, line []text.Glyph, x, y unit.Dp, col color.NRGBA) {
|
||||||
if len(line) == 0 {
|
if len(line) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
first := line[0]
|
first := line[0]
|
||||||
// shaper.Shape(line) returns a path where glyph positions are relative to
|
// shaper.Shape(line) returns a path where glyph positions are relative to
|
||||||
// the first glyph (first.X == 0 in the returned path). So we offset by
|
// the first glyph. Offset by (x + first.X, y + first.Y) to place the line
|
||||||
// (x, y) and let the shaper handle the rest.
|
// at the desired document position. Matches Gio's paintGlyph:
|
||||||
// first.Y is the baseline; we subtract it so the top of the text is at y.
|
// lineOff = (glyph.X, glyph.Y) - viewport.Min
|
||||||
offX := float32(gtx.Dp(x))
|
// op.Affine(f32.Affine2D{}.Offset(lineOff))
|
||||||
offY := float32(gtx.Dp(y)) - float32(first.Y)
|
offX := float32(gtx.Dp(x)) + float32(first.X)/64.0
|
||||||
|
offY := float32(gtx.Dp(y)) + float32(first.Y)
|
||||||
t := op.Affine(f32.Affine2D{}.Offset(f32.Pt(offX, offY))).Push(gtx.Ops)
|
t := op.Affine(f32.Affine2D{}.Offset(f32.Pt(offX, offY))).Push(gtx.Ops)
|
||||||
|
|
||||||
// Draw vector glyphs
|
// Draw vector glyphs
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user