Skip to content

Commit

Permalink
Only use 1200 DPI for scalable fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Nov 26, 2024
1 parent 07c6145 commit bcac05c
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions novelwriter/formats/toqdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

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

Expand Down Expand Up @@ -128,7 +128,12 @@ def initDocument(self, pdf: bool = False) -> None:
"""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()
Expand All @@ -147,14 +152,15 @@ def initDocument(self, pdf: bool = False) -> None:
# ============

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
Expand All @@ -166,12 +172,12 @@ def initDocument(self, pdf: bool = False) -> None:
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
# ============
Expand Down Expand Up @@ -263,6 +269,7 @@ def doConvert(self) -> None:
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)
Expand Down

0 comments on commit bcac05c

Please sign in to comment.