fix horizontal alignment of text
This commit is contained in:
parent
bc823442ba
commit
6b72c6dec7
1 changed files with 3 additions and 4 deletions
|
@ -150,9 +150,7 @@ func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom fl
|
||||||
} else {
|
} else {
|
||||||
top = -float64(d.Ascent) * h / float64(d.Ascent-d.Descent)
|
top = -float64(d.Ascent) * h / float64(d.Ascent-d.Descent)
|
||||||
}
|
}
|
||||||
bottom = top + h
|
return 0, top, gc.pdf.GetStringWidth(s), top + h
|
||||||
margin := gc.pdf.GetCellMargin()
|
|
||||||
return -margin, top, -margin + gc.pdf.GetStringWidth(s), bottom
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateStringPath creates a path from the string s at x, y, and returns the string width.
|
// CreateStringPath creates a path from the string s at x, y, and returns the string width.
|
||||||
|
@ -162,7 +160,8 @@ func (gc *GraphicContext) CreateStringPath(text string, x, y float64) (cursor fl
|
||||||
w := right - left
|
w := right - left
|
||||||
h := bottom - top
|
h := bottom - top
|
||||||
// gc.pdf.SetXY(x, y-h) do not use this as y-h might be negative
|
// gc.pdf.SetXY(x, y-h) do not use this as y-h might be negative
|
||||||
gc.pdf.MoveTo(x+left, y+top)
|
margin := gc.pdf.GetCellMargin()
|
||||||
|
gc.pdf.MoveTo(x-left-margin, y+top)
|
||||||
gc.pdf.CellFormat(w, h, text, "", 0, "BL", false, 0, "")
|
gc.pdf.CellFormat(w, h, text, "", 0, "BL", false, 0, "")
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue