Fix font handling in manuscript tool

This commit is contained in:
Veronica Berglyd Olsen
2024-05-20 17:13:10 +02:00
parent 774437f7bb
commit 0b999bd726
6 changed files with 19 additions and 32 deletions
+13 -26
View File
@@ -392,13 +392,14 @@ class Config:
self.textFont = QFont()
self.textFont.fromString(value)
else:
font = QFont()
fontDB = QFontDatabase()
fontFam = fontDB.families()
if self.osWindows and "Arial" in fontFam:
font = QFont()
font.setFamily("Arial")
font.setPointSize(12)
elif self.osDarwin and "Helvetica" in fontFam:
font = QFont()
font.setFamily("Helvetica")
font.setPointSize(12)
else:
@@ -587,21 +588,14 @@ class Config:
# Main
sec = "Main"
self.guiTheme = conf.rdStr(sec, "theme", self.guiTheme)
self.guiSyntax = conf.rdStr(sec, "syntax", self.guiSyntax)
guiFont = conf.rdStr(sec, "font", "")
self.guiLocale = conf.rdStr(sec, "localisation", self.guiLocale)
self.hideVScroll = conf.rdBool(sec, "hidevscroll", self.hideVScroll)
self.hideHScroll = conf.rdBool(sec, "hidehscroll", self.hideHScroll)
self.lastNotes = conf.rdStr(sec, "lastnotes", self.lastNotes)
self._lastPath = conf.rdPath(sec, "lastpath", self._lastPath)
# If we have an old config file, we have an explicit font size,
# in which case we convert the old settings.
if fontSize := conf.rdInt(sec, "fontsize", 0):
guiFont = f"{guiFont},{fontSize}"
self.setGuiFont(guiFont)
self.setGuiFont(conf.rdStr(sec, "font", ""))
self.guiTheme = conf.rdStr(sec, "theme", self.guiTheme)
self.guiSyntax = conf.rdStr(sec, "syntax", self.guiSyntax)
self.guiLocale = conf.rdStr(sec, "localisation", self.guiLocale)
self.hideVScroll = conf.rdBool(sec, "hidevscroll", self.hideVScroll)
self.hideHScroll = conf.rdBool(sec, "hidehscroll", self.hideHScroll)
self.lastNotes = conf.rdStr(sec, "lastnotes", self.lastNotes)
self._lastPath = conf.rdPath(sec, "lastpath", self._lastPath)
# Sizes
sec = "Sizes"
@@ -623,7 +617,7 @@ class Config:
# Editor
sec = "Editor"
textFont = conf.rdStr(sec, "textfont", "")
self.setTextFont(conf.rdStr(sec, "textfont", ""))
self.textWidth = conf.rdInt(sec, "width", self.textWidth)
self.textMargin = conf.rdInt(sec, "margin", self.textMargin)
self.tabWidth = conf.rdInt(sec, "tabwidth", self.tabWidth)
@@ -662,13 +656,6 @@ class Config:
self.stopWhenIdle = conf.rdBool(sec, "stopwhenidle", self.stopWhenIdle)
self.userIdleTime = conf.rdInt(sec, "useridletime", self.userIdleTime)
# If we have an old config file, we have an explicit font size,
# in which case we convert the old settings.
if textSize := conf.rdInt(sec, "textsize", 0):
textFont = f"{textFont},{textSize}"
self.setTextFont(textFont)
# State
sec = "State"
self.showViewerPanel = conf.rdBool(sec, "showviewerpanel", self.showViewerPanel)
@@ -710,9 +697,9 @@ class Config:
}
conf["Main"] = {
"font": self.guiFont.toString(),
"theme": str(self.guiTheme),
"syntax": str(self.guiSyntax),
"guifont": str(self.guiFont.toString()),
"localisation": str(self.guiLocale),
"hidevscroll": str(self.hideVScroll),
"hidehscroll": str(self.hideHScroll),
@@ -739,7 +726,7 @@ class Config:
}
conf["Editor"] = {
"textfont": str(self.textFont.toString()),
"textfont": self.textFont.toString(),
"width": str(self.textWidth),
"margin": str(self.textMargin),
"tabwidth": str(self.tabWidth),
+1 -1
View File
@@ -76,7 +76,7 @@ SETTINGS_TEMPLATE = {
"text.includeBodyText": (bool, True),
"text.ignoredKeywords": (str, ""),
"text.addNoteHeadings": (bool, True),
"format.textFont": (str, CONFIG.textFont),
"format.textFont": (str, CONFIG.textFont.family()),
"format.textSize": (int, 12),
"format.lineHeight": (float, 1.15, 0.75, 3.0),
"format.justifyText": (bool, False),
+1 -1
View File
@@ -288,7 +288,7 @@ class NWBuildDocument:
textFont = self._build.getStr("format.textFont")
textSize = self._build.getInt("format.textSize")
fontFamily = textFont or CONFIG.textFont
fontFamily = textFont or CONFIG.textFont.family()
bldFont = QFont(fontFamily, textSize)
fontInfo = QFontInfo(bldFont)
textFixed = fontInfo.fixedPitch()
+2 -2
View File
@@ -881,9 +881,9 @@ class GuiPreferences(QDialog):
CONFIG.guiLocale = guiLocale
CONFIG.guiTheme = guiTheme
CONFIG.guiFont = self._guiFont
CONFIG.hideVScroll = self.hideVScroll.isChecked()
CONFIG.hideHScroll = self.hideHScroll.isChecked()
CONFIG.setGuiFont(self._guiFont)
# Document Style
guiSyntax = self.guiSyntax.currentData()
@@ -896,7 +896,7 @@ class GuiPreferences(QDialog):
CONFIG.emphLabels = emphLabels
CONFIG.showFullPath = self.showFullPath.isChecked()
CONFIG.incNotesWCount = self.incNotesWCount.isChecked()
CONFIG.textFont = self._textFont
CONFIG.setTextFont(self._textFont)
# Auto Save
CONFIG.autoSaveDoc = self.autoSaveDoc.value()
+1 -1
View File
@@ -787,7 +787,7 @@ class _PreviewWidget(QTextBrowser):
self._updateDocMargins()
self._updateBuildAge()
self.setTextFont(CONFIG.textFont, CONFIG.textSize)
self.setTextFont(CONFIG.textFont.family(), CONFIG.textFont.pointSize())
# Age Timer
self.ageTimer = QTimer(self)
+1 -1
View File
@@ -1175,7 +1175,7 @@ class _FormatTab(NScrollableForm):
"""Populate the widgets."""
textFont = self._build.getStr("format.textFont")
if not textFont:
textFont = str(CONFIG.textFont)
textFont = str(CONFIG.textFont.family())
self.textFont.setText(textFont)
self.textSize.setValue(self._build.getInt("format.textSize"))