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().
|
||||
// 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) {
|
||||
if len(line) == 0 {
|
||||
return
|
||||
}
|
||||
first := line[0]
|
||||
// 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
|
||||
// (x, y) and let the shaper handle the rest.
|
||||
// first.Y is the baseline; we subtract it so the top of the text is at y.
|
||||
offX := float32(gtx.Dp(x))
|
||||
offY := float32(gtx.Dp(y)) - float32(first.Y)
|
||||
// the first glyph. Offset by (x + first.X, y + first.Y) to place the line
|
||||
// at the desired document position. Matches Gio's paintGlyph:
|
||||
// lineOff = (glyph.X, glyph.Y) - viewport.Min
|
||||
// op.Affine(f32.Affine2D{}.Offset(lineOff))
|
||||
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)
|
||||
|
||||
// Draw vector glyphs
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user