From 04e0bd700c8e33c22e277c2c4898eaf9962f461f Mon Sep 17 00:00:00 2001 From: Jelmer Snoeck Date: Fri, 25 Sep 2015 13:46:33 +0100 Subject: Fpdf: add WriteAligned. WriteAligned allows a user to write a single string and align it. Previously, Write() would only write with Left alignment. Sometimes, you want to align a specific text string to the center or the right. HTMLBasic: add
tag. This allows a user to center text within the HTML block. This way they do not have to split up their input. A new line will be created automatically before and after the centered text. --- htmlbasic.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'htmlbasic.go') diff --git a/htmlbasic.go b/htmlbasic.go index e602b7d..6998128 100644 --- a/htmlbasic.go +++ b/htmlbasic.go @@ -116,10 +116,10 @@ func (f *Fpdf) HTMLBasicNew() (html HTMLBasicType) { // Write prints text from the current position using the currently selected // font. See HTMLBasicNew() to create a receiver that is associated with the // PDF document instance. The text can be encoded with a basic subset of HTML -// that includes hyperlinks and tags for italic (I), bold (B) and underscore -// (U) attributes. When the right margin is reached a line break occurs and -// text continues from the left margin. Upon method exit, the current position -// is left at the end of the text. +// that includes hyperlinks and tags for italic (I), bold (B), underscore +// (U) and center (CENTER) attributes. When the right margin is reached a line +// break occurs and text continues from the left margin. Upon method exit, the +// current position is left at the end of the text. // // lineHt indicates the line height in the unit of measure specified in New(). func (html *HTMLBasicType) Write(lineHt float64, htmlStr string) { @@ -161,6 +161,7 @@ func (html *HTMLBasicType) Write(lineHt float64, htmlStr string) { } list := HTMLBasicTokenize(htmlStr) var ok bool + alignStr := "L" for _, el := range list { switch el.Cat { case 'T': @@ -168,7 +169,7 @@ func (html *HTMLBasicType) Write(lineHt float64, htmlStr string) { putLink(hrefStr, el.Str) hrefStr = "" } else { - html.pdf.Write(lineHt, el.Str) + html.pdf.WriteAligned(0, lineHt, el.Str, alignStr) } case 'O': switch el.Str { @@ -180,6 +181,9 @@ func (html *HTMLBasicType) Write(lineHt float64, htmlStr string) { setStyle(0, 0, 1) case "br": html.pdf.Ln(lineHt) + case "center": + html.pdf.Ln(lineHt) + alignStr = "C" case "a": hrefStr, ok = el.Attr["href"] if !ok { @@ -194,7 +198,9 @@ func (html *HTMLBasicType) Write(lineHt float64, htmlStr string) { setStyle(0, -1, 0) case "u": setStyle(0, 0, -1) - + case "center": + html.pdf.Ln(lineHt) + alignStr = "L" } } } -- cgit v1.2.1-24-ge1ad