diff options
author | Joop Kiefte <ikojba@gmail.com> | 2020-11-20 07:43:54 +0200 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2020-11-20 07:43:54 +0200 |
commit | d2102540519ea342485565845f64bb83c454cf26 (patch) | |
tree | 657f12ae7dfaf7e7c6c9ad5fd411fdec6dc6fbee /pdf/create.go | |
parent | f577a01ec42b2533ba4b894d42d3323d6d1900b5 (diff) |
Add section and scene headings in PDF
Diffstat (limited to 'pdf/create.go')
-rw-r--r-- | pdf/create.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/pdf/create.go b/pdf/create.go index 12b4662..4f41aa7 100644 --- a/pdf/create.go +++ b/pdf/create.go @@ -7,6 +7,7 @@ import ( "github.com/lapingvino/lexington/font" "strconv" + "strings" "github.com/phpdave11/gofpdf" ) @@ -27,6 +28,7 @@ func pagenumber() { func (t Tree) Render() { var block string var ln int + var lastsection int for _, row := range t.F { switch row.Type { case "newpage": @@ -46,6 +48,22 @@ func (t Tree) Render() { block = "meta" t.PDF.SetY(-2) } + + var contents string + var level int + if row.Type == "section" { + contents = strings.TrimLeft(row.Contents, "#") + level = len(row.Contents) - len(contents) + contents = strings.TrimLeft(contents, " ") + lastsection = level + } else if row.Type == "scene" { + level = lastsection + 1 + contents = row.Contents + } + if contents != "" { + t.PDF.Bookmark(contents, level, -1) + } + if t.Rules.Get(row.Type).Hide && block == "" { continue } @@ -65,6 +83,7 @@ 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.16, text, "", format.Align, false) + // TODO: create liner to do away with multicell and add inline markup support } func Create(file string, format rules.Set, contents lex.Screenplay) { |