Skip to content

Commit

Permalink
Allow setting resolution for ToQTextDocument converter
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Nov 26, 2024
1 parent ff47002 commit 18c70ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion novelwriter/core/docbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def iterBuildDocument(self, path: Path, bFormat: nwBuildFmt) -> Iterable[tuple[i
makeObj = ToQTextDocument(self._project)
makeObj.disableAnchors()
filtered = self._setupBuild(makeObj)
makeObj.initDocument()
makeObj.initDocument(resolution=1200)
yield from self._iterBuild(makeObj, filtered)
makeObj.closeDocument()

Expand Down
9 changes: 6 additions & 3 deletions novelwriter/formats/toqdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(self, project: NWProject) -> None:

self._pageSize = QPageSize(QPageSize.PageSizeId.A4)
self._pageMargins = QMarginsF(20.0, 20.0, 20.0, 20.0)
self._resolution = 96

return

Expand Down Expand Up @@ -123,9 +124,10 @@ def disableAnchors(self) -> None:
# Class Methods
##

def initDocument(self) -> None:
def initDocument(self, resolution: int = 96) -> None:
"""Initialise all computed values of the document."""
super().initDocument()
self._resolution = resolution

self._document.setUndoRedoEnabled(False)
self._document.blockSignals(True)
Expand Down Expand Up @@ -168,8 +170,8 @@ def initDocument(self) -> None:
self._mMeta = (fPx * self._marginMeta[0], fPx * self._marginMeta[1])
self._mSep = (fPx * self._marginSep[0], fPx * self._marginSep[1])

self._mIndent = fPx * 2.0
self._tIndent = fPx * self._firstWidth
self._mIndent = fPx * self._resolution/96 * 2.0
self._tIndent = fPx * self._resolution/96 * self._firstWidth

# Text Formats
# ============
Expand Down Expand Up @@ -265,6 +267,7 @@ def saveDocument(self, path: Path) -> None:
printer = QPrinter(QPrinter.PrinterMode.HighResolution)
printer.setDocName(self._project.data.name)
printer.setCreator(f"novelWriter/{__version__}")
printer.setResolution(self._resolution)
printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat)
printer.setPageSize(self._pageSize)
printer.setPageMargins(m.left(), m.top(), m.right(), m.bottom(), QPrinter.Unit.Millimeter)
Expand Down

0 comments on commit 18c70ff

Please sign in to comment.