From 6b72c6dec7fbadd61e89cae88c84cd5c8efe37bf Mon Sep 17 00:00:00 2001 From: Stani Date: Sun, 12 Jul 2015 21:17:39 +0200 Subject: [PATCH] fix horizontal alignment of text --- draw2dpdf/gc.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/draw2dpdf/gc.go b/draw2dpdf/gc.go index 9314986..b81bdbe 100644 --- a/draw2dpdf/gc.go +++ b/draw2dpdf/gc.go @@ -150,9 +150,7 @@ func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom fl } else { top = -float64(d.Ascent) * h / float64(d.Ascent-d.Descent) } - bottom = top + h - margin := gc.pdf.GetCellMargin() - return -margin, top, -margin + gc.pdf.GetStringWidth(s), bottom + return 0, top, gc.pdf.GetStringWidth(s), top + h } // 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 h := bottom - top // 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, "") return w }