summaryrefslogtreecommitdiff
path: root/htmlbasic.go
diff options
context:
space:
mode:
authorJelmer Snoeck <jelmer.snoeck@gmail.com>2015-09-25 13:46:33 +0100
committerJelmer Snoeck <jelmer.snoeck@gmail.com>2015-09-25 13:52:55 +0100
commit04e0bd700c8e33c22e277c2c4898eaf9962f461f (patch)
tree32b65db95f3537d2926f11004c4966e21c2aba00 /htmlbasic.go
parent02db05c2cda70eb7ae66c31af83b355917b9694b (diff)
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 <center> 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.
Diffstat (limited to 'htmlbasic.go')
-rw-r--r--htmlbasic.go18
1 files changed, 12 insertions, 6 deletions
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"
}
}
}