Generalise ODT build settings
This commit is contained in:
@@ -96,11 +96,11 @@ SETTINGS_TEMPLATE: dict[str, tuple[type, T_Basic]] = {
|
||||
"format.bottomMargin": (float, 2.0),
|
||||
"format.leftMargin": (float, 2.0),
|
||||
"format.rightMargin": (float, 2.0),
|
||||
"odt.addColours": (bool, True),
|
||||
"odt.scaleHeadings": (bool, True),
|
||||
"odt.boldHeadings": (bool, True),
|
||||
"odt.pageHeader": (str, nwHeadFmt.ODT_AUTO),
|
||||
"odt.pageCountOffset": (int, 0),
|
||||
"odt.colorHeadings": (bool, True),
|
||||
"odt.scaleHeadings": (bool, True),
|
||||
"odt.boldHeadings": (bool, True),
|
||||
"html.addStyles": (bool, True),
|
||||
"html.preserveTabs": (bool, False),
|
||||
}
|
||||
@@ -155,12 +155,12 @@ SETTINGS_LABELS = {
|
||||
"format.leftMargin": QT_TRANSLATE_NOOP("Builds", "Left Margin"),
|
||||
"format.rightMargin": QT_TRANSLATE_NOOP("Builds", "Right Margin"),
|
||||
|
||||
"odt": QT_TRANSLATE_NOOP("Builds", "ODT Options"),
|
||||
"odt.addColours": QT_TRANSLATE_NOOP("Builds", "Add Highlight Colours"),
|
||||
"odt.scaleHeadings": QT_TRANSLATE_NOOP("Builds", "Increase Size of Headings"),
|
||||
"odt.boldHeadings": QT_TRANSLATE_NOOP("Builds", "Bold Headings"),
|
||||
"odt": QT_TRANSLATE_NOOP("Builds", "Document Options"),
|
||||
"odt.pageHeader": QT_TRANSLATE_NOOP("Builds", "Page Header"),
|
||||
"odt.pageCountOffset": QT_TRANSLATE_NOOP("Builds", "Page Counter Offset"),
|
||||
"odt.colorHeadings": QT_TRANSLATE_NOOP("Builds", "Add Colours to Headings"),
|
||||
"odt.scaleHeadings": QT_TRANSLATE_NOOP("Builds", "Increase Size of Headings"),
|
||||
"odt.boldHeadings": QT_TRANSLATE_NOOP("Builds", "Bold Headings"),
|
||||
|
||||
"html": QT_TRANSLATE_NOOP("Builds", "HTML Options"),
|
||||
"html.addStyles": QT_TRANSLATE_NOOP("Builds", "Add CSS Styles"),
|
||||
|
||||
@@ -347,6 +347,11 @@ class NWBuildDocument:
|
||||
self._build.getFloat("format.firstIndentWidth"),
|
||||
self._build.getBool("format.indentFirstPar"),
|
||||
)
|
||||
bldObj.setHeadingStyles(
|
||||
self._build.getBool("odt.colorHeadings"),
|
||||
self._build.getBool("odt.scaleHeadings"),
|
||||
self._build.getBool("odt.boldHeadings"),
|
||||
)
|
||||
|
||||
bldObj.setBodyText(self._build.getBool("text.includeBodyText"))
|
||||
bldObj.setSynopsis(self._build.getBool("text.includeSynopsis"))
|
||||
@@ -359,11 +364,6 @@ class NWBuildDocument:
|
||||
bldObj.setReplaceUnicode(self._build.getBool("format.stripUnicode"))
|
||||
|
||||
if isinstance(bldObj, ToOdt):
|
||||
bldObj.setColoursEnabled(self._build.getBool("odt.addColours"))
|
||||
bldObj.setHeadingStyles(
|
||||
self._build.getBool("odt.scaleHeadings"),
|
||||
self._build.getBool("odt.boldHeadings"),
|
||||
)
|
||||
bldObj.setLanguage(self._project.data.language)
|
||||
bldObj.setHeaderFormat(
|
||||
self._build.getStr("odt.pageHeader"),
|
||||
|
||||
@@ -150,18 +150,21 @@ class Tokenizer(ABC):
|
||||
|
||||
# User Settings
|
||||
self._textFont = QFont("Serif", 11) # Output text font
|
||||
self._lineHeight = 1.15 # Line height in units of em
|
||||
self._blockIndent = 4.00 # Block indent in units of em
|
||||
self._firstIndent = False # Enable first line indent
|
||||
self._firstWidth = 1.40 # First line indent in units of em
|
||||
self._indentFirst = False # Indent first paragraph
|
||||
self._doJustify = False # Justify text
|
||||
self._doBodyText = True # Include body text
|
||||
self._doSynopsis = False # Also process synopsis comments
|
||||
self._doComments = False # Also process comments
|
||||
self._doKeywords = False # Also process keywords like tags and references
|
||||
self._skipKeywords = set() # Keywords to ignore
|
||||
self._keepBreaks = True # Keep line breaks in paragraphs
|
||||
self._lineHeight = 1.15 # Line height in units of em
|
||||
self._colorHeads = True # Colourise headings
|
||||
self._scaleHeads = True # Scale headings to larger font size
|
||||
self._boldHeads = True # Bold headings
|
||||
self._blockIndent = 4.00 # Block indent in units of em
|
||||
self._firstIndent = False # Enable first line indent
|
||||
self._firstWidth = 1.40 # First line indent in units of em
|
||||
self._indentFirst = False # Indent first paragraph
|
||||
self._doJustify = False # Justify text
|
||||
self._doBodyText = True # Include body text
|
||||
self._doSynopsis = False # Also process synopsis comments
|
||||
self._doComments = False # Also process comments
|
||||
self._doKeywords = False # Also process keywords like tags and references
|
||||
self._skipKeywords = set() # Keywords to ignore
|
||||
self._keepBreaks = True # Keep line breaks in paragraphs
|
||||
|
||||
# Margins
|
||||
self._marginTitle = (1.417, 0.500)
|
||||
@@ -346,6 +349,13 @@ class Tokenizer(ABC):
|
||||
self._lineHeight = min(max(float(height), 0.5), 5.0)
|
||||
return
|
||||
|
||||
def setHeadingStyles(self, color: bool, scale: bool, bold: bool) -> None:
|
||||
"""Set text style for headings."""
|
||||
self._colorHeads = color
|
||||
self._scaleHeads = scale
|
||||
self._boldHeads = bold
|
||||
return
|
||||
|
||||
def setBlockIndent(self, indent: float) -> None:
|
||||
"""Set the block indent between 0.0 and 10.0."""
|
||||
self._blockIndent = min(max(float(indent), 0.0), 10.0)
|
||||
|
||||
@@ -161,8 +161,6 @@ class ToOdt(Tokenizer):
|
||||
|
||||
# Properties
|
||||
self._textFont = QFont("Liberation Serif", 12)
|
||||
self._addColours = False
|
||||
self._scaleHeads = True
|
||||
self._headWeight = "bold"
|
||||
self._headerFormat = ""
|
||||
self._pageOffset = 0
|
||||
@@ -226,10 +224,10 @@ class ToOdt(Tokenizer):
|
||||
self._opaHead12 = None
|
||||
self._colHead34 = None
|
||||
self._opaHead34 = None
|
||||
self._colMetaTx = None
|
||||
self._opaMetaTx = None
|
||||
self._colDialogM = None
|
||||
self._colDialogA = None
|
||||
self._colMetaTx = "#813709"
|
||||
self._opaMetaTx = "100%"
|
||||
self._markText = "#ffffa6"
|
||||
|
||||
return
|
||||
@@ -246,17 +244,6 @@ class ToOdt(Tokenizer):
|
||||
self._dCountry = country or self._dCountry
|
||||
return
|
||||
|
||||
def setHeadingStyles(self, scale: bool, bold: bool) -> None:
|
||||
"""Set plain text style for headings."""
|
||||
self._scaleHeads = scale
|
||||
self._headWeight = self._fontBold if bold else None
|
||||
return
|
||||
|
||||
def setColoursEnabled(self, state: bool) -> None:
|
||||
"""Enable/disable coloured headings and comments."""
|
||||
self._addColours = state
|
||||
return
|
||||
|
||||
def setPageLayout(
|
||||
self, width: int | float, height: int | float,
|
||||
top: int | float, bottom: int | float, left: int | float, right: int | float
|
||||
@@ -295,6 +282,7 @@ class ToOdt(Tokenizer):
|
||||
self._fontStyle = FONT_STYLE.get(self._textFont.style(), "normal")
|
||||
self._fontPitch = "fixed" if self._textFont.fixedPitch() else "variable"
|
||||
self._fontBold = FONT_WEIGHT_MAP.get(fontBold, fontBold)
|
||||
self._headWeight = self._fontBold if self._boldHeads else None
|
||||
|
||||
hScale = self._scaleHeads
|
||||
self._fSizeTitle = f"{round((2.50 if hScale else 1.0) * self._fontSize):d}pt"
|
||||
@@ -331,13 +319,11 @@ class ToOdt(Tokenizer):
|
||||
self._mLeftFoot = self._emToCm(self._marginFoot[0])
|
||||
self._mBotFoot = self._emToCm(self._marginFoot[1])
|
||||
|
||||
if self._addColours:
|
||||
if self._colorHeads:
|
||||
self._colHead12 = "#2a6099"
|
||||
self._opaHead12 = "100%"
|
||||
self._colHead34 = "#444444"
|
||||
self._opaHead34 = "100%"
|
||||
self._colMetaTx = "#813709"
|
||||
self._opaMetaTx = "100%"
|
||||
|
||||
if self._showDialog:
|
||||
self._colDialogM = "#2a6099"
|
||||
|
||||
@@ -114,12 +114,13 @@ class ToQTextDocument(Tokenizer):
|
||||
self.T_HEAD4: (mPx * self._marginHead4[0], mPx * self._marginHead4[1]),
|
||||
}
|
||||
|
||||
hScale = self._scaleHeads
|
||||
self._sHead = {
|
||||
self.T_TITLE: nwHeaders.H_SIZES.get(0, 1.0) * fPt,
|
||||
self.T_HEAD1: nwHeaders.H_SIZES.get(1, 1.0) * fPt,
|
||||
self.T_HEAD2: nwHeaders.H_SIZES.get(2, 1.0) * fPt,
|
||||
self.T_HEAD3: nwHeaders.H_SIZES.get(3, 1.0) * fPt,
|
||||
self.T_HEAD4: nwHeaders.H_SIZES.get(4, 1.0) * fPt,
|
||||
self.T_TITLE: (nwHeaders.H_SIZES.get(0, 1.0) * fPt) if hScale else fPt,
|
||||
self.T_HEAD1: (nwHeaders.H_SIZES.get(1, 1.0) * fPt) if hScale else fPt,
|
||||
self.T_HEAD2: (nwHeaders.H_SIZES.get(2, 1.0) * fPt) if hScale else fPt,
|
||||
self.T_HEAD3: (nwHeaders.H_SIZES.get(3, 1.0) * fPt) if hScale else fPt,
|
||||
self.T_HEAD4: (nwHeaders.H_SIZES.get(4, 1.0) * fPt) if hScale else fPt,
|
||||
}
|
||||
|
||||
self._mText = (mPx * self._marginText[0], mPx * self._marginText[1])
|
||||
@@ -148,7 +149,8 @@ class ToQTextDocument(Tokenizer):
|
||||
self._cText.setForeground(self._theme.text)
|
||||
|
||||
self._cHead = QTextCharFormat(self._cText)
|
||||
self._cHead.setForeground(self._theme.head)
|
||||
self._cHead.setForeground(self._theme.head if self._colorHeads else self._theme.text)
|
||||
self._cHead.setFontWeight(self._bold if self._boldHeads else self._normal)
|
||||
|
||||
self._cComment = QTextCharFormat(self._cText)
|
||||
self._cComment.setForeground(self._theme.comment)
|
||||
@@ -410,7 +412,6 @@ class ToQTextDocument(Tokenizer):
|
||||
bFmt.setBottomMargin(mBottom)
|
||||
|
||||
cFmt = QTextCharFormat(self._cText if hType == self.T_TITLE else self._cHead)
|
||||
cFmt.setFontWeight(self._bold)
|
||||
cFmt.setFontPointSize(self._sHead.get(hType, 1.0))
|
||||
if nHead >= 0:
|
||||
cFmt.setAnchorNames([f"{self._handle}:T{nHead:04d}"])
|
||||
|
||||
@@ -1122,14 +1122,7 @@ class _FormattingTab(NScrollableForm):
|
||||
self._sidebar.addButton(title, section)
|
||||
self.addGroupLabel(title, section)
|
||||
|
||||
self.odtAddColours = NSwitch(self, height=iPx)
|
||||
self.scaleHeadings = NSwitch(self, height=iPx)
|
||||
self.boldHeadings = NSwitch(self, height=iPx)
|
||||
|
||||
self.addRow(self._build.getLabel("odt.addColours"), self.odtAddColours)
|
||||
self.addRow(self._build.getLabel("odt.scaleHeadings"), self.scaleHeadings)
|
||||
self.addRow(self._build.getLabel("odt.boldHeadings"), self.boldHeadings)
|
||||
|
||||
# Header
|
||||
self.odtPageHeader = QLineEdit(self)
|
||||
self.odtPageHeader.setMinimumWidth(CONFIG.pxInt(200))
|
||||
self.btnPageHeader = NIconToolButton(self, iSz, "revert")
|
||||
@@ -1146,6 +1139,15 @@ class _FormattingTab(NScrollableForm):
|
||||
self.odtPageCountOffset.setMinimumWidth(spW)
|
||||
self.addRow(self._build.getLabel("odt.pageCountOffset"), self.odtPageCountOffset)
|
||||
|
||||
# Headings
|
||||
self.colorHeadings = NSwitch(self, height=iPx)
|
||||
self.scaleHeadings = NSwitch(self, height=iPx)
|
||||
self.boldHeadings = NSwitch(self, height=iPx)
|
||||
|
||||
self.addRow(self._build.getLabel("odt.colorHeadings"), self.colorHeadings)
|
||||
self.addRow(self._build.getLabel("odt.scaleHeadings"), self.scaleHeadings)
|
||||
self.addRow(self._build.getLabel("odt.boldHeadings"), self.boldHeadings)
|
||||
|
||||
# HTML Document
|
||||
# =============
|
||||
|
||||
@@ -1230,7 +1232,7 @@ class _FormattingTab(NScrollableForm):
|
||||
# ODT Document
|
||||
# ============
|
||||
|
||||
self.odtAddColours.setChecked(self._build.getBool("odt.addColours"))
|
||||
self.colorHeadings.setChecked(self._build.getBool("odt.colorHeadings"))
|
||||
self.scaleHeadings.setChecked(self._build.getBool("odt.scaleHeadings"))
|
||||
self.boldHeadings.setChecked(self._build.getBool("odt.boldHeadings"))
|
||||
self.odtPageHeader.setText(self._build.getStr("odt.pageHeader"))
|
||||
@@ -1282,7 +1284,7 @@ class _FormattingTab(NScrollableForm):
|
||||
self._build.setValue("format.rightMargin", self.rightMargin.value())
|
||||
|
||||
# ODT Document
|
||||
self._build.setValue("odt.addColours", self.odtAddColours.isChecked())
|
||||
self._build.setValue("odt.colorHeadings", self.colorHeadings.isChecked())
|
||||
self._build.setValue("odt.scaleHeadings", self.scaleHeadings.isChecked())
|
||||
self._build.setValue("odt.boldHeadings", self.boldHeadings.isChecked())
|
||||
self._build.setValue("odt.pageHeader", self.odtPageHeader.text())
|
||||
|
||||
Reference in New Issue
Block a user