From 07c61450c7a53c5185e25aae329504a6db09e843 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:57:07 +0100 Subject: [PATCH] Try forcing resolution for PDF printer --- novelwriter/core/docbuild.py | 2 +- novelwriter/formats/toqdoc.py | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/novelwriter/core/docbuild.py b/novelwriter/core/docbuild.py index f21fa1b9..a98da986 100644 --- a/novelwriter/core/docbuild.py +++ b/novelwriter/core/docbuild.py @@ -178,7 +178,7 @@ class NWBuildDocument: makeObj = ToQTextDocument(self._project) makeObj.disableAnchors() filtered = self._setupBuild(makeObj) - makeObj.initDocument(resolution=1200) + makeObj.initDocument(pdf=True) yield from self._iterBuild(makeObj, filtered) makeObj.closeDocument() diff --git a/novelwriter/formats/toqdoc.py b/novelwriter/formats/toqdoc.py index 59331bac..dfd343ff 100644 --- a/novelwriter/formats/toqdoc.py +++ b/novelwriter/formats/toqdoc.py @@ -83,9 +83,9 @@ class ToQTextDocument(Tokenizer): self._dStrike = False self._dUnderline = False + self._dpi = 96 self._pageSize = QPageSize(QPageSize.PageSizeId.A4) self._pageMargins = QMarginsF(20.0, 20.0, 20.0, 20.0) - self._resolution = 96 return @@ -124,11 +124,11 @@ class ToQTextDocument(Tokenizer): # Class Methods ## - def initDocument(self, resolution: int = 96) -> None: + def initDocument(self, pdf: bool = False) -> None: """Initialise all computed values of the document.""" super().initDocument() - self._resolution = resolution + self._dpi = 72 if pdf else 96 self._document.setUndoRedoEnabled(False) self._document.blockSignals(True) self._document.clear() @@ -147,15 +147,14 @@ class ToQTextDocument(Tokenizer): # ============ fPt = self._textFont.pointSizeF() - fPx = fPt*4.0/3.0 # 1 em in pixels - fDt = fPx * self._resolution/96.0 # In dots for a given resolution + mSc = fPt * self._dpi/72.0 self._mHead = { - BlockTyp.TITLE: (fPx * self._marginTitle[0], fPx * self._marginTitle[1]), - BlockTyp.HEAD1: (fPx * self._marginHead1[0], fPx * self._marginHead1[1]), - BlockTyp.HEAD2: (fPx * self._marginHead2[0], fPx * self._marginHead2[1]), - BlockTyp.HEAD3: (fPx * self._marginHead3[0], fPx * self._marginHead3[1]), - BlockTyp.HEAD4: (fPx * self._marginHead4[0], fPx * self._marginHead4[1]), + BlockTyp.TITLE: (mSc * self._marginTitle[0], mSc * self._marginTitle[1]), + BlockTyp.HEAD1: (mSc * self._marginHead1[0], mSc * self._marginHead1[1]), + BlockTyp.HEAD2: (mSc * self._marginHead2[0], mSc * self._marginHead2[1]), + BlockTyp.HEAD3: (mSc * self._marginHead3[0], mSc * self._marginHead3[1]), + BlockTyp.HEAD4: (mSc * self._marginHead4[0], mSc * self._marginHead4[1]), } hScale = self._scaleHeads @@ -167,12 +166,12 @@ class ToQTextDocument(Tokenizer): BlockTyp.HEAD4: (nwStyles.H_SIZES.get(4, 1.0) * fPt) if hScale else fPt, } - self._mText = (fPx * self._marginText[0], fPx * self._marginText[1]) - self._mMeta = (fPx * self._marginMeta[0], fPx * self._marginMeta[1]) - self._mSep = (fPx * self._marginSep[0], fPx * self._marginSep[1]) + self._mText = (mSc * self._marginText[0], mSc * self._marginText[1]) + self._mMeta = (mSc * self._marginMeta[0], mSc * self._marginMeta[1]) + self._mSep = (mSc * self._marginSep[0], mSc * self._marginSep[1]) - self._mIndent = fDt * 2.0 - self._tIndent = fDt * self._firstWidth + self._mIndent = mSc * 2.0 + self._tIndent = mSc * self._firstWidth # Text Formats # ============ @@ -268,7 +267,7 @@ class ToQTextDocument(Tokenizer): printer = QPrinter(QPrinter.PrinterMode.HighResolution) printer.setDocName(self._project.data.name) printer.setCreator(f"novelWriter/{__version__}") - printer.setResolution(self._resolution) + printer.setResolution(self._dpi) printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat) printer.setPageSize(self._pageSize) printer.setPageMargins(m.left(), m.top(), m.right(), m.bottom(), QPrinter.Unit.Millimeter)