jelovirt / pdf-generator

DITA-OT PDF plug-in generator
https://dita-generator.elovirta.com/
Apache License 2.0
12 stars 5 forks source link

Template format #31

Closed jelovirt closed 3 years ago

jelovirt commented 3 years ago

Design JSON format for template/theme files. The same format can be used in YAML.

The current format is used internally by the UI code and has not been designed with hand authoring in mind.

Example with parts missing

{
  "page": {
    "height": "297mm",
    "width": "210mm",
    "top": "20mm",
    "outside": "20mm",
    "bottom": "20mm",
    "inside": "20mm"
  },
  "header": {
    "odd": ["title"], 
    "even": ["chapter"]
  },
  "footer": {
    "odd": ["folio"],
    "even": ["folio-with-total"]
  },
  "style": {
    "header": {
      "background-color": "orange",
      "font-weight": "bold",
      "start-indent": "20mm",
      "end-indent": "20mm",
      "space-before": "10mm"
    },
    "footer": {
      "background-color": "yellow",
      "text-align": "center",
      "start-indent": "20mm",
      "end-indent": "20mm",
      "space-after": "10mm"
    },
    "body": {
      // style definition can use basically any FO property
      "background-color": "transparent",
      "padding-top": "0pt",
      "padding-right": "0pt",
      "padding-bottom": "0pt",
      "padding-left": "0pt",
      "end-indent": "0pt",
      "border-before-style": "none",
      "border-before-width": "1pt",
      "border-before-color": "black",
      "border-end-style": "none",
      "border-end-width": "1pt",
      "border-end-color": "black",
      "border-after-style": "none",
      "border-after-width": "1pt",
      "border-after-color": "black",
      "border-start-style": "none",
      "border-start-width": "1pt",
      "border-start-color": "black",
      "font-family": "Times New Roman",
      "font-size": "10pt",
      "color": "black",
      "font-weight": "normal",
      "font-style": "normal",
      "text-decoration": "none",
      "space-before": "6pt",
      "space-after": "6pt",
      "text-align": "start",
      "start-indent": "25pt",
      "line-height": "1.2"
    },
    // actually topic tittle
    "topic": {
      "background-color": "pink",
      "padding-top": "0pt",
      …
      // This property is not FO, it's part of our property set
      "title-numbering": true
    },
    "ol": {
      …
      "ol-1": "1",
      "ol-2": "1",
      "ol-3": "1",
      "ol-4": "1",
      "ol-after-1": ". ",
      "ol-after-2": ". ",
      "ol-after-3": ". ",
      "ol-after-4": ". "
    },
    "link": {
      "font-family": "Times New Roman",
      "font-size": "10pt",
      "color": "blue",
      "background-color": "transparent",
      "font-weight": "normal",
      "font-style": "normal",
      "text-decoration": "none",
      "line-height": "1.2",
      "link-page-number": true
    }
  },
  // some of these are global options, but some are part of some other section. Like mirror_page_margins is part of page key, but is here for said reasons
  "mirror_page_margins": true,
  "blank_pages": true,
  "body_column_count": 1,
  "index_column_count": 2,
  "column_gap": "12pt",
  "force_page_count": "even",
  "chapter_layout": "BASIC",
  "cover_image_metadata": "cover-image",
  "bookmark_style": "COLLAPSED",
  "toc_maximum_level": 4,
  "task_label": true,
  "include_related_links": "none",
  "table_continued": true,
  "page_number": "chapter-page"
}

Refactored format with changes inline, ie. edit this code block and add comments:

{
  "page": {
    "height": "297mm",
    "width": "210mm",
    "top": "20mm",
    "outside": "20mm",
    "bottom": "20mm",
    "inside": "20mm"
  },
  "header": {
    "odd": {
      "content": ["title"]
    }, 
    "even": {
      "content": ["chapter"]
    }
  },
  "footer": {
    "odd": {
      "content": ["folio"],
    }
    "even": {
      "content": ["folio-with-total"]
    }
  },
  "style": {
    "header": {
      "background-color": "orange",
      "font-weight": "bold",
      "start-indent": "20mm",
      "end-indent": "20mm",
      "space-before": "10mm"
    },
    "footer": {
      "background-color": "yellow",
      "text-align": "center",
      "start-indent": "20mm",
      "end-indent": "20mm",
      "space-after": "10mm"
    },
    "body": {
      "background-color": "transparent",
      "padding-top": "0pt",
      "padding-right": "0pt",
      "padding-bottom": "0pt",
      "padding-left": "0pt",
      "end-indent": "0pt",
      "border-before-style": "none",
      "border-before-width": "1pt",
      "border-before-color": "black",
      "border-end-style": "none",
      "border-end-width": "1pt",
      "border-end-color": "black",
      "border-after-style": "none",
      "border-after-width": "1pt",
      "border-after-color": "black",
      "border-start-style": "none",
      "border-start-width": "1pt",
      "border-start-color": "black",
      "font-family": "Times New Roman",
      "font-size": "10pt",
      "color": "black",
      "font-weight": "normal",
      "font-style": "normal",
      "text-decoration": "none",
      "space-before": "6pt",
      "space-after": "6pt",
      "text-align": "start",
      "start-indent": "25pt",
      "line-height": "1.2"
    },
    // actually topic tittle
    "topic": {
      "background-color": "pink",
      "padding-top": "0pt",
      …
      "title-numbering": true
    },
    "ol": {
      …
      "ol-1": "1",
      "ol-2": "1",
      "ol-3": "1",
      "ol-4": "1",
      "ol-after-1": ". ",
      "ol-after-2": ". ",
      "ol-after-3": ". ",
      "ol-after-4": ". "
    },
    "link": {
      "font-family": "Times New Roman",
      "font-size": "10pt",
      "color": "blue",
      "background-color": "transparent",
      "font-weight": "normal",
      "font-style": "normal",
      "text-decoration": "none",
      "line-height": "1.2",
      "link-page-number": true
    }
  },
  "mirror_page_margins": true,
  "blank_pages": true,
  "body_column_count": 1,
  "index_column_count": 2,
  "column_gap": "12pt",
  "force_page_count": "even",
  "chapter_layout": "BASIC",
  "cover_image_metadata": "cover-image",
  "bookmark_style": "COLLAPSED",
  "toc_maximum_level": 4,
  "task_label": true,
  "include_related_links": "none",
  "table_continued": true,
  "page_number": "chapter-page"
}
jelovirt commented 3 years ago

In order to add support for both "components", variable references, and inline text, should we change

  "header": {
    "odd": ["title"], 

to something like

  "header": {
    "odd": "{title} | {#keyfromvariable}" 

Parsed data from the header in this case would be

[
  { kind: 'field, value: 'title' },
  { kind: 'text', value: ' | ' },
  { kind: 'variable', value: 'keyfromvariable' },
]
jelovirt commented 3 years ago

These are directly related to pages margins and header/footer usage

  "mirror_page_margins": true,

These are page flow related

  "blank_pages": true,
  "force_page_count": "even",

These are about page content layout related

  "body_column_count": 1,
  "index_column_count": 2,
  "column_gap": "12pt",