Add page offset option to ODT build (#1505)

This commit is contained in:
Veronica Berglyd Olsen
2024-01-28 15:52:38 +01:00
parent 116409bb8d
commit 1ec0bff159
6 changed files with 28 additions and 11 deletions
+2
View File
@@ -80,6 +80,7 @@ SETTINGS_TEMPLATE = {
"format.rightMargin": (float, 2.0), "format.rightMargin": (float, 2.0),
"odt.addColours": (bool, True), "odt.addColours": (bool, True),
"odt.pageHeader": (str, nwHeadFmt.ODT_AUTO), "odt.pageHeader": (str, nwHeadFmt.ODT_AUTO),
"odt.pageCountOffset": (int, 0),
"html.addStyles": (bool, True), "html.addStyles": (bool, True),
} }
@@ -127,6 +128,7 @@ SETTINGS_LABELS = {
"odt": QT_TRANSLATE_NOOP("Builds", "Open Document (.odt)"), "odt": QT_TRANSLATE_NOOP("Builds", "Open Document (.odt)"),
"odt.addColours": QT_TRANSLATE_NOOP("Builds", "Add Highlight Colours"), "odt.addColours": QT_TRANSLATE_NOOP("Builds", "Add Highlight Colours"),
"odt.pageHeader": QT_TRANSLATE_NOOP("Builds", "Page Header"), "odt.pageHeader": QT_TRANSLATE_NOOP("Builds", "Page Header"),
"odt.pageCountOffset": QT_TRANSLATE_NOOP("Builds", "Page Counter Offset"),
"html": QT_TRANSLATE_NOOP("Builds", "HTML (.html)"), "html": QT_TRANSLATE_NOOP("Builds", "HTML (.html)"),
"html.addStyles": QT_TRANSLATE_NOOP("Builds", "Add CSS Styles"), "html.addStyles": QT_TRANSLATE_NOOP("Builds", "Add CSS Styles"),
+3 -1
View File
@@ -284,7 +284,9 @@ class NWBuildDocument:
if isinstance(bldObj, ToOdt): if isinstance(bldObj, ToOdt):
bldObj.setColourHeaders(self._build.getBool("odt.addColours")) bldObj.setColourHeaders(self._build.getBool("odt.addColours"))
bldObj.setLanguage(self._project.data.language) bldObj.setLanguage(self._project.data.language)
bldObj.setHeaderFormat(self._build.getStr("odt.pageHeader")) bldObj.setHeaderFormat(
self._build.getStr("odt.pageHeader"), self._build.getInt("odt.pageCountOffset")
)
scale = nwLabels.UNIT_SCALE.get(self._build.getStr("format.pageUnit"), 1.0) scale = nwLabels.UNIT_SCALE.get(self._build.getStr("format.pageUnit"), 1.0)
pW, pH = nwLabels.PAPER_SIZE.get(self._build.getStr("format.pageSize"), (-1.0, -1.0)) pW, pH = nwLabels.PAPER_SIZE.get(self._build.getStr("format.pageSize"), (-1.0, -1.0))
+7 -4
View File
@@ -137,6 +137,7 @@ class ToOdt(Tokenizer):
self._textFixed = False self._textFixed = False
self._colourHead = False self._colourHead = False
self._headerFormat = "" self._headerFormat = ""
self._pageOffset = 0
# Internal # Internal
self._fontFamily = "'Liberation Serif'" self._fontFamily = "'Liberation Serif'"
@@ -222,9 +223,10 @@ class ToOdt(Tokenizer):
self._mDocRight = f"{right/10.0:.3f}cm" self._mDocRight = f"{right/10.0:.3f}cm"
return return
def setHeaderFormat(self, format: str) -> None: def setHeaderFormat(self, format: str, offset: int) -> None:
"""Set the document header format.""" """Set the document header format."""
self._headerFormat = format.strip() self._headerFormat = format.strip()
self._pageOffset = offset
return return
## ##
@@ -1023,9 +1025,10 @@ class ToOdt(Tokenizer):
}) })
xPar.text = pre xPar.text = pre
if page: if page:
xTail = ET.SubElement(xPar, _mkTag("text", "page-number"), attrib={ attrib = {_mkTag("text", "select-page"): "current"}
_mkTag("text", "select-page"): "current" if self._pageOffset > 0:
}) attrib = {_mkTag("text", "page-adjust"): str(0 - self._pageOffset)}
xTail = ET.SubElement(xPar, _mkTag("text", "page-number"), attrib=attrib)
xTail.text = "2" xTail.text = "2"
xTail.tail = post xTail.tail = post
else: else:
+10
View File
@@ -1210,6 +1210,7 @@ class _OutputTab(NScrollableForm):
self._build = build self._build = build
iPx = SHARED.theme.baseIconSize iPx = SHARED.theme.baseIconSize
spW = 6*SHARED.theme.textNWidth
# Open Document # Open Document
self.addGroupLabel(self._build.getLabel("odt")) self.addGroupLabel(self._build.getLabel("odt"))
@@ -1227,6 +1228,13 @@ class _OutputTab(NScrollableForm):
button=self.btnPageHeader, stretch=(1, 1) button=self.btnPageHeader, stretch=(1, 1)
) )
self.odtPageCountOffset = QSpinBox(self)
self.odtPageCountOffset.setMinimum(0)
self.odtPageCountOffset.setMaximum(999)
self.odtPageCountOffset.setSingleStep(1)
self.odtPageCountOffset.setMinimumWidth(spW)
self.addRow(self._build.getLabel("odt.pageCountOffset"), self.odtPageCountOffset)
# HTML Document # HTML Document
self.addGroupLabel(self._build.getLabel("html")) self.addGroupLabel(self._build.getLabel("html"))
@@ -1242,6 +1250,7 @@ class _OutputTab(NScrollableForm):
"""Populate the widgets.""" """Populate the widgets."""
self.odtAddColours.setChecked(self._build.getBool("odt.addColours")) self.odtAddColours.setChecked(self._build.getBool("odt.addColours"))
self.odtPageHeader.setText(self._build.getStr("odt.pageHeader")) self.odtPageHeader.setText(self._build.getStr("odt.pageHeader"))
self.odtPageCountOffset.setValue(self._build.getInt("odt.pageCountOffset"))
self.htmlAddStyles.setChecked(self._build.getBool("html.addStyles")) self.htmlAddStyles.setChecked(self._build.getBool("html.addStyles"))
return return
@@ -1249,6 +1258,7 @@ class _OutputTab(NScrollableForm):
"""Save choices back into build object.""" """Save choices back into build object."""
self._build.setValue("odt.addColours", self.odtAddColours.isChecked()) self._build.setValue("odt.addColours", self.odtAddColours.isChecked())
self._build.setValue("odt.pageHeader", self.odtPageHeader.text()) self._build.setValue("odt.pageHeader", self.odtPageHeader.text())
self._build.setValue("odt.pageCountOffset", self.odtPageCountOffset.value())
self._build.setValue("html.addStyles", self.htmlAddStyles.isChecked()) self._build.setValue("html.addStyles", self.htmlAddStyles.isChecked())
return return
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<office:document xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> <office:document xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
<office:meta> <office:meta>
<meta:creation-date>2023-10-20T22:51:30</meta:creation-date> <meta:creation-date>2024-01-28T15:48:36</meta:creation-date>
<meta:generator>novelWriter/2.2-alpha1</meta:generator> <meta:generator>novelWriter/2.3a3</meta:generator>
<meta:initial-creator>Jane Smith</meta:initial-creator> <meta:initial-creator>Jane Smith</meta:initial-creator>
<meta:editing-cycles>1234</meta:editing-cycles> <meta:editing-cycles>1234</meta:editing-cycles>
<meta:editing-duration>P42DT12H34M56S</meta:editing-duration> <meta:editing-duration>P42DT12H34M56S</meta:editing-duration>
<dc:title>Test Project</dc:title> <dc:title>Test Project</dc:title>
<dc:date>2023-10-20T22:51:30</dc:date> <dc:date>2024-01-28T15:48:36</dc:date>
<dc:creator>Jane Smith</dc:creator> <dc:creator>Jane Smith</dc:creator>
</office:meta> </office:meta>
<office:font-face-decls> <office:font-face-decls>
@@ -76,7 +76,7 @@
<office:master-styles> <office:master-styles>
<style:master-page style:name="Standard" style:page-layout-name="PM1"> <style:master-page style:name="Standard" style:page-layout-name="PM1">
<style:header> <style:header>
<text:p text:style-name="Header">Test Project / Jane Smith / <text:page-number text:select-page="current">2</text:page-number></text:p> <text:p text:style-name="Header">Test Project / Jane Smith / <text:page-number text:page-adjust="-1">2</text:page-number></text:p>
</style:header> </style:header>
<style:header-first> <style:header-first>
<text:p text:style-name="Header" /> <text:p text:style-name="Header" />
+2 -2
View File
@@ -693,7 +693,7 @@ def testCoreToOdt_SaveFlat(mockGUI, fncPath, tstPaths):
assert odt._dLanguage == "nb" assert odt._dLanguage == "nb"
odt.setColourHeaders(True) odt.setColourHeaders(True)
assert odt._colourHead is True assert odt._colourHead is True
odt.setHeaderFormat(nwHeadFmt.ODT_AUTO) odt.setHeaderFormat(nwHeadFmt.ODT_AUTO, 1)
assert odt._headerFormat == nwHeadFmt.ODT_AUTO assert odt._headerFormat == nwHeadFmt.ODT_AUTO
odt.setPageLayout(148, 210, 20, 18, 17, 15) odt.setPageLayout(148, 210, 20, 18, 17, 15)
@@ -741,7 +741,7 @@ def testCoreToOdt_SaveFull(mockGUI, fncPath, tstPaths):
odt._isNovel = True odt._isNovel = True
# Set a format without page number # Set a format without page number
odt.setHeaderFormat(f"{nwHeadFmt.ODT_PROJECT} - {nwHeadFmt.ODT_AUTHOR}") odt.setHeaderFormat(f"{nwHeadFmt.ODT_PROJECT} - {nwHeadFmt.ODT_AUTHOR}", 0)
odt._text = ( odt._text = (
"## Chapter One\n\n" "## Chapter One\n\n"