summaryrefslogtreecommitdiff
path: root/pdf/create.go
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2018-12-31 17:53:02 +0100
committerJoop Kiefte <ikojba@gmail.com>2018-12-31 17:53:02 +0100
commit20be238175eecc5e68b74d0e98e5ec428610a904 (patch)
tree6332fbaa903275990a87aacd57dd31161e3b00e6 /pdf/create.go
parent22fab0a8bc6ae7f468c91ed2835a55226270afad (diff)
Beginning of the new structure under the Lexington name
Diffstat (limited to 'pdf/create.go')
-rw-r--r--pdf/create.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/pdf/create.go b/pdf/create.go
new file mode 100644
index 0000000..abf0284
--- /dev/null
+++ b/pdf/create.go
@@ -0,0 +1,52 @@
+package pdf
+
+import (
+ "github.com/lapingvino/lexington/lex"
+ "github.com/lapingvino/lexington/rules"
+
+ "github.com/jung-kurt/gofpdf"
+)
+
+var tr func(string) string
+
+type Tree struct {
+ PDF *gofpdf.Fpdf
+ Rules rules.Set
+ F lex.Screenplay
+}
+
+func (t Tree) pr(a string, text string) {
+ line(t.PDF, t.Rules.Get(a), text)
+}
+
+func (t Tree) Render() {
+ for _, row := range t.F {
+ if t.Rules.Get(row.Type).Hide {
+ continue
+ }
+ t.pr(row.Type, row.Contents)
+ }
+}
+
+func line(pdf *gofpdf.Fpdf, format rules.Format, text string) {
+ pdf.SetFont(format.Font, format.Style, format.Size)
+ pdf.SetX(format.Left)
+ pdf.MultiCell(format.Width, 0.19, tr(text), "", "aligned", false)
+}
+
+func Create(file string, format rules.Set, contents lex.Screenplay) {
+ pdf := gofpdf.New("P", "in", "Letter", "")
+ tr = pdf.UnicodeTranslatorFromDescriptor("")
+ pdf.AddPage()
+ pdf.SetMargins(1, 1, 1)
+ pdf.SetXY(1, 1)
+ f := Tree{
+ Rules: format,
+ F: contents,
+ }
+ f.Render()
+ err := pdf.OutputFileAndClose(file)
+ if err != nil {
+ panic(err)
+ }
+}