summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoop Kiefte <joop@kiefte.net>2016-06-03 16:37:08 +0000
committerJoop Kiefte <joop@kiefte.net>2016-06-03 16:37:08 +0000
commit42d2fb5ca3070bfc67ed0116c42b75d9cd6d8083 (patch)
tree25b90f733a43279220131f14a9a7b25478000f5e
parentff6c9ff65dfc8fed4b5420278c99db2c73351f61 (diff)
Working render system based on parsing - now just get to the parsing itself...
-rw-r--r--main.go61
1 files changed, 49 insertions, 12 deletions
diff --git a/main.go b/main.go
index c1f5211..82af60d 100644
--- a/main.go
+++ b/main.go
@@ -2,8 +2,43 @@ package main
import "github.com/jung-kurt/gofpdf"
+type Action int
+
+var action = map[string]struct {
+ Left, Width float64
+}{
+ "action": {1.5, 6},
+ "speaker": {4.2, 3.3},
+ "dialog": {2.9, 3.3},
+ "scene": {1.5, 6},
+ "parenthetical": {3.6, 2},
+ "trans": {6, 1.5},
+ "note": {1.5, 6},
+ "allcaps": {1.5, 6},
+ "parens": {1.5, 6},
+ "empty": {1.5, 6},
+}
+
var tr func(string) string
+type Tree struct {
+ PDF *gofpdf.Fpdf
+ F []struct {
+ Format string
+ Text string
+ }
+}
+
+func (t Tree) pr(a string, text string) {
+ line(t.PDF, action[a].Left, action[a].Width, text)
+}
+
+func (t Tree) Render() {
+ for _, row := range t.F {
+ t.pr(row.Format, row.Text)
+ }
+}
+
func line(pdf *gofpdf.Fpdf, jump, width float64, text string) {
pdf.SetX(jump)
pdf.MultiCell(width, 0.19, tr(text), "", "aligned", false)
@@ -11,22 +46,24 @@ func line(pdf *gofpdf.Fpdf, jump, width float64, text string) {
func main() {
pdf := gofpdf.New("P", "in", "Letter", "")
- tr = pdf.UnicodeTranslatorFromDescriptor("")
+ tr = pdf.UnicodeTranslatorFromDescriptor("")
pdf.AddPage()
pdf.SetFont("courier", "", 12)
pdf.SetMargins(1, 1, 1)
pdf.SetXY(1, 1)
- line(pdf, 1.5, 6, "FADE IN")
- line(pdf, 1.5, 6, "")
- line(pdf, 1.5, 6, "A RIVER")
- line(pdf, 1.5, 6, "")
- line(pdf, 1.5, 6, "We’re underwater, watching a fat catfish swim along.")
- line(pdf, 1.5, 6, "")
- line(pdf, 1.5, 6, "This is The Beast.")
- line(pdf, 1.5, 6, "")
- line(pdf, 4.2, 3.3, "EDWARD (V.O.)")
- line(pdf, 2.9, 3.3, "There are some fish that cannot be caught. It’s not that they’re faster or stronger than other fish. They’re just touched by something extra. Call it luck. Call it grace. One such fish was The Beast.")
- err := pdf.OutputFileAndClose("hello.pdf")
+ f := Tree{PDF: pdf}
+ f.F = []struct{ Format, Text string }{
+ {"scene", "INT. HOUSE - DAY"},
+ {"empty", ""},
+ {"speaker", "MARY"},
+ {"dialog", "I can't believe how easy it is to write in Fountain."},
+ {"empty", ""},
+ {"speaker", "TOM"},
+ {"parenthetical", "(typing)"},
+ {"dialog", "Look! I just made a parenthetical!"},
+ }
+ f.Render()
+ err := pdf.OutputFileAndClose("fountain.pdf")
if err != nil {
panic(err)
}