diff --git a/novelwriter/formats/toqdoc.py b/novelwriter/formats/toqdoc.py index dfd343ff..f0f495e2 100644 --- a/novelwriter/formats/toqdoc.py +++ b/novelwriter/formats/toqdoc.py @@ -29,8 +29,8 @@ from pathlib import Path from PyQt5.QtCore import QMarginsF, QSizeF from PyQt5.QtGui import ( - QColor, QFont, QPageSize, QTextBlockFormat, QTextCharFormat, QTextCursor, - QTextDocument + QColor, QFont, QFontDatabase, QPageSize, QTextBlockFormat, QTextCharFormat, + QTextCursor, QTextDocument ) from PyQt5.QtPrintSupport import QPrinter @@ -128,7 +128,12 @@ class ToQTextDocument(Tokenizer): """Initialise all computed values of the document.""" super().initDocument() - self._dpi = 72 if pdf else 96 + if pdf: + fontDB = QFontDatabase() + family = self._textFont.family() + style = self._textFont.styleName() + self._dpi = 1200 if fontDB.isScalable(family, style) else 72 + self._document.setUndoRedoEnabled(False) self._document.blockSignals(True) self._document.clear() @@ -147,14 +152,15 @@ class ToQTextDocument(Tokenizer): # ============ fPt = self._textFont.pointSizeF() - mSc = fPt * self._dpi/72.0 + fPx = fPt*96.0/72.0 # 1 em in pixels + mPx = fPx * self._dpi/96.0 self._mHead = { - 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]), + 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]), } hScale = self._scaleHeads @@ -166,12 +172,12 @@ class ToQTextDocument(Tokenizer): BlockTyp.HEAD4: (nwStyles.H_SIZES.get(4, 1.0) * fPt) if hScale else fPt, } - 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._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._mIndent = mSc * 2.0 - self._tIndent = mSc * self._firstWidth + self._mIndent = mPx * 2.0 + self._tIndent = mPx * self._firstWidth # Text Formats # ============ @@ -263,6 +269,7 @@ class ToQTextDocument(Tokenizer): def saveDocument(self, path: Path) -> None: """Save the document as a PDF file.""" m = self._pageMargins + logger.info("Writing PDF at %d DPI", self._dpi) printer = QPrinter(QPrinter.PrinterMode.HighResolution) printer.setDocName(self._project.data.name)