Remove redundant code
This commit is contained in:
@@ -471,7 +471,7 @@ class ToDocX(Tokenizer):
|
|||||||
|
|
||||||
def _generateFootnote(self, key: str) -> ET.Element | None:
|
def _generateFootnote(self, key: str) -> ET.Element | None:
|
||||||
"""Generate a footnote XML object."""
|
"""Generate a footnote XML object."""
|
||||||
if self._footnotes.get(key):
|
if key in self._footnotes:
|
||||||
idx = len(self._usedNotes) + 1
|
idx = len(self._usedNotes) + 1
|
||||||
run = ET.Element(_wTag("r"))
|
run = ET.Element(_wTag("r"))
|
||||||
rPr = xmlSubElem(run, _wTag("rPr"))
|
rPr = xmlSubElem(run, _wTag("rPr"))
|
||||||
|
|||||||
@@ -152,10 +152,8 @@ class ToOdt(Tokenizer):
|
|||||||
self._autoPara: dict[str, ODTParagraphStyle] = {} # Auto-generated paragraph styles
|
self._autoPara: dict[str, ODTParagraphStyle] = {} # Auto-generated paragraph styles
|
||||||
self._autoText: dict[str, ODTTextStyle] = {} # Auto-generated text styles
|
self._autoText: dict[str, ODTTextStyle] = {} # Auto-generated text styles
|
||||||
|
|
||||||
# Footnotes
|
# Storage
|
||||||
self._nNote = 0
|
self._nNote = 0
|
||||||
self._etNotes: dict[str, ET.Element] = {} # Generated note elements
|
|
||||||
|
|
||||||
self._errData = [] # List of errors encountered
|
self._errData = [] # List of errors encountered
|
||||||
|
|
||||||
# Properties
|
# Properties
|
||||||
@@ -405,8 +403,6 @@ class ToOdt(Tokenizer):
|
|||||||
|
|
||||||
def doConvert(self) -> None:
|
def doConvert(self) -> None:
|
||||||
"""Convert the list of text tokens into XML elements."""
|
"""Convert the list of text tokens into XML elements."""
|
||||||
self._result = "" # Not used, but cleared just in case
|
|
||||||
|
|
||||||
xText = self._xText
|
xText = self._xText
|
||||||
for tType, _, tText, tFormat, tStyle in self._blocks:
|
for tType, _, tText, tFormat, tStyle in self._blocks:
|
||||||
|
|
||||||
@@ -678,7 +674,6 @@ class ToOdt(Tokenizer):
|
|||||||
tKey = str(hFmt)
|
tKey = str(hFmt)
|
||||||
if fClass and (color := self._classes.get(fClass)):
|
if fClass and (color := self._classes.get(fClass)):
|
||||||
tKey = f"{tKey}:{fClass}"
|
tKey = f"{tKey}:{fClass}"
|
||||||
|
|
||||||
if tKey in self._autoText:
|
if tKey in self._autoText:
|
||||||
return self._autoText[tKey].name
|
return self._autoText[tKey].name
|
||||||
|
|
||||||
@@ -1089,16 +1084,6 @@ class ODTParagraphStyle:
|
|||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
##
|
|
||||||
# Checkers
|
|
||||||
##
|
|
||||||
|
|
||||||
def isUnaligned(self) -> bool:
|
|
||||||
"""Check if paragraph has any sort of alignment or margins."""
|
|
||||||
return all(
|
|
||||||
self._pAttr[n][1] is None for n in ["text-align", "margin-left", "margin-right"]
|
|
||||||
)
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Setters
|
# Setters
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ class ToQTextDocument(Tokenizer):
|
|||||||
self._document.setUndoRedoEnabled(False)
|
self._document.setUndoRedoEnabled(False)
|
||||||
self._document.setDocumentMargin(0)
|
self._document.setDocumentMargin(0)
|
||||||
|
|
||||||
self._styles: dict[int, T_TextStyle] = {}
|
|
||||||
self._usedNotes: dict[str, int] = {}
|
self._usedNotes: dict[str, int] = {}
|
||||||
|
|
||||||
self._init = False
|
self._init = False
|
||||||
@@ -149,13 +148,13 @@ class ToQTextDocument(Tokenizer):
|
|||||||
# Text Formats
|
# Text Formats
|
||||||
# ============
|
# ============
|
||||||
|
|
||||||
|
QtPropLineHeight = QTextBlockFormat.LineHeightTypes.ProportionalHeight
|
||||||
|
|
||||||
self._blockFmt = QTextBlockFormat()
|
self._blockFmt = QTextBlockFormat()
|
||||||
self._blockFmt.setTopMargin(self._mText[0])
|
self._blockFmt.setTopMargin(self._mText[0])
|
||||||
self._blockFmt.setBottomMargin(self._mText[1])
|
self._blockFmt.setBottomMargin(self._mText[1])
|
||||||
self._blockFmt.setAlignment(QtAlignAbsolute)
|
self._blockFmt.setAlignment(QtAlignAbsolute)
|
||||||
self._blockFmt.setLineHeight(
|
self._blockFmt.setLineHeight(100.0*self._lineHeight, QtPropLineHeight)
|
||||||
100*self._lineHeight, QTextBlockFormat.LineHeightTypes.ProportionalHeight
|
|
||||||
)
|
|
||||||
|
|
||||||
self._charFmt = QTextCharFormat()
|
self._charFmt = QTextCharFormat()
|
||||||
self._charFmt.setBackground(QtTransparent)
|
self._charFmt.setBackground(QtTransparent)
|
||||||
@@ -176,7 +175,6 @@ class ToQTextDocument(Tokenizer):
|
|||||||
|
|
||||||
for tType, nHead, tText, tFormat, tStyle in self._blocks:
|
for tType, nHead, tText, tFormat, tStyle in self._blocks:
|
||||||
|
|
||||||
# Styles
|
|
||||||
bFmt = QTextBlockFormat(self._blockFmt)
|
bFmt = QTextBlockFormat(self._blockFmt)
|
||||||
if tType in (BlockTyp.COMMENT, BlockTyp.KEYWORD):
|
if tType in (BlockTyp.COMMENT, BlockTyp.KEYWORD):
|
||||||
bFmt.setTopMargin(self._mMeta[0])
|
bFmt.setTopMargin(self._mMeta[0])
|
||||||
@@ -234,7 +232,7 @@ class ToQTextDocument(Tokenizer):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def saveDocument(self, path: Path) -> None:
|
def saveDocument(self, path: Path) -> None:
|
||||||
"""Save the document to a PDF file."""
|
"""Save the document as a PDF file."""
|
||||||
m = self._pageMargins
|
m = self._pageMargins
|
||||||
|
|
||||||
printer = QPrinter(QPrinter.PrinterMode.PrinterResolution)
|
printer = QPrinter(QPrinter.PrinterMode.PrinterResolution)
|
||||||
@@ -366,9 +364,6 @@ class ToQTextDocument(Tokenizer):
|
|||||||
bFmt.setTopMargin(mTop)
|
bFmt.setTopMargin(mTop)
|
||||||
bFmt.setBottomMargin(mBottom)
|
bFmt.setBottomMargin(mBottom)
|
||||||
|
|
||||||
self._cTitle = QTextCharFormat(self._charFmt)
|
|
||||||
self._cTitle.setFontWeight(self._bold if self._boldHeads else self._normal)
|
|
||||||
|
|
||||||
hCol = self._colorHeads and hType != BlockTyp.TITLE
|
hCol = self._colorHeads and hType != BlockTyp.TITLE
|
||||||
cFmt = QTextCharFormat(self._charFmt)
|
cFmt = QTextCharFormat(self._charFmt)
|
||||||
cFmt.setForeground(self._theme.head if hCol else self._theme.text)
|
cFmt.setForeground(self._theme.head if hCol else self._theme.text)
|
||||||
|
|||||||
@@ -951,8 +951,6 @@ def testFmtToOdt_ODTParagraphStyle():
|
|||||||
assert parStyle._pAttr["text-indent"] == ["fo", None]
|
assert parStyle._pAttr["text-indent"] == ["fo", None]
|
||||||
assert parStyle._pAttr["line-height"] == ["fo", None]
|
assert parStyle._pAttr["line-height"] == ["fo", None]
|
||||||
|
|
||||||
assert parStyle.isUnaligned() is True
|
|
||||||
|
|
||||||
parStyle.setMarginTop("0.000cm")
|
parStyle.setMarginTop("0.000cm")
|
||||||
parStyle.setMarginBottom("0.000cm")
|
parStyle.setMarginBottom("0.000cm")
|
||||||
parStyle.setMarginLeft("0.000cm")
|
parStyle.setMarginLeft("0.000cm")
|
||||||
@@ -967,8 +965,6 @@ def testFmtToOdt_ODTParagraphStyle():
|
|||||||
assert parStyle._pAttr["text-indent"] == ["fo", "0.000cm"]
|
assert parStyle._pAttr["text-indent"] == ["fo", "0.000cm"]
|
||||||
assert parStyle._pAttr["line-height"] == ["fo", "1.15"]
|
assert parStyle._pAttr["line-height"] == ["fo", "1.15"]
|
||||||
|
|
||||||
assert parStyle.isUnaligned() is False
|
|
||||||
|
|
||||||
# Text Alignment
|
# Text Alignment
|
||||||
assert parStyle._pAttr["text-align"] == ["fo", None]
|
assert parStyle._pAttr["text-align"] == ["fo", None]
|
||||||
parStyle.setTextAlign("stuff")
|
parStyle.setTextAlign("stuff")
|
||||||
|
|||||||
Reference in New Issue
Block a user