From 76e786d9614212c0a0b178ecfc7eedc0991dcdea Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 22 May 2024 16:59:44 +0200 Subject: [PATCH] Update HTML handling of font --- novelwriter/core/tohtml.py | 14 ++++++++++++-- .../reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm | 2 +- .../mBuildDocBuild_HTML5_Lorem_Ipsum.json | 6 +++--- tests/test_core/test_core_docbuild.py | 3 +-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/novelwriter/core/tohtml.py b/novelwriter/core/tohtml.py index 85a91f59..ce4cc1c5 100644 --- a/novelwriter/core/tohtml.py +++ b/novelwriter/core/tohtml.py @@ -34,6 +34,7 @@ from novelwriter.common import formatTimeStamp from novelwriter.constants import nwHeadFmt, nwHtmlUnicode, nwKeyWords, nwLabels from novelwriter.core.project import NWProject from novelwriter.core.tokenizer import T_Formats, Tokenizer, stripEscape +from novelwriter.types import FONT_STRETCH, FONT_STYLE, FONT_WEIGHTS logger = logging.getLogger(__name__) @@ -373,8 +374,17 @@ class ToHtml(Tokenizer): mScale = self._lineHeight/1.15 styles = [] - styles.append("body {{font-family: '{0:s}'; font-size: {1:d}pt;}}".format( - self._textFont, self._textSize + font = self._textFont + styles.append(( + "body {{" + "font-family: '{0:s}'; font-size: {1:d}pt; font-weight: {2:d}; " + "font-stretch: {3:s}; font-style: {4:s};" + "}}" + ).format( + font.family(), font.pointSize(), + FONT_WEIGHTS.get(font.weight(), 400), + FONT_STRETCH.get(font.stretch(), "normal"), + FONT_STYLE.get(font.style(), "normal"), )) styles.append(( "p {{" diff --git a/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm b/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm index 60d3800b..0cc348c2 100644 --- a/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm +++ b/tests/reference/mBuildDocBuild_HTML5_Lorem_Ipsum.htm @@ -5,7 +5,7 @@