Update HTML handling of font

This commit is contained in:
Veronica Berglyd Olsen
2024-05-22 16:59:44 +02:00
parent 7e1f1a725c
commit 76e786d961
4 changed files with 17 additions and 8 deletions
+12 -2
View File
@@ -34,6 +34,7 @@ from novelwriter.common import formatTimeStamp
from novelwriter.constants import nwHeadFmt, nwHtmlUnicode, nwKeyWords, nwLabels from novelwriter.constants import nwHeadFmt, nwHtmlUnicode, nwKeyWords, nwLabels
from novelwriter.core.project import NWProject from novelwriter.core.project import NWProject
from novelwriter.core.tokenizer import T_Formats, Tokenizer, stripEscape from novelwriter.core.tokenizer import T_Formats, Tokenizer, stripEscape
from novelwriter.types import FONT_STRETCH, FONT_STYLE, FONT_WEIGHTS
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -373,8 +374,17 @@ class ToHtml(Tokenizer):
mScale = self._lineHeight/1.15 mScale = self._lineHeight/1.15
styles = [] styles = []
styles.append("body {{font-family: '{0:s}'; font-size: {1:d}pt;}}".format( font = self._textFont
self._textFont, self._textSize 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(( styles.append((
"p {{" "p {{"
@@ -5,7 +5,7 @@
<title>Lorem Ipsum</title> <title>Lorem Ipsum</title>
</head> </head>
<style> <style>
body {font-family: 'Arial'; font-size: 12pt;} body {font-family: 'Arial'; font-size: 12pt; font-weight: 400; font-stretch: normal; font-style: normal;}
p {text-align: justify; line-height: 150%; margin-top: 0.00em; margin-bottom: 0.76em;} p {text-align: justify; line-height: 150%; margin-top: 0.00em; margin-bottom: 0.76em;}
h1 {color: rgb(66, 113, 174); page-break-after: avoid; margin-top: 1.30em; margin-bottom: 0.65em;} h1 {color: rgb(66, 113, 174); page-break-after: avoid; margin-top: 1.30em; margin-bottom: 0.65em;}
h2 {color: rgb(66, 113, 174); page-break-after: avoid; margin-top: 1.09em; margin-bottom: 0.65em;} h2 {color: rgb(66, 113, 174); page-break-after: avoid; margin-top: 1.09em; margin-bottom: 0.65em;}
@@ -2,12 +2,12 @@
"meta": { "meta": {
"projectName": "Lorem Ipsum", "projectName": "Lorem Ipsum",
"novelAuthor": "lipsum.com", "novelAuthor": "lipsum.com",
"buildTime": 1714336438, "buildTime": 1716389899,
"buildTimeStr": "2024-04-28 22:33:58" "buildTimeStr": "2024-05-22 16:58:19"
}, },
"text": { "text": {
"css": [ "css": [
"body {font-family: 'Arial'; font-size: 12pt;}", "body {font-family: 'Arial'; font-size: 12pt; font-weight: 400; font-stretch: normal; font-style: normal;}",
"p {text-align: justify; line-height: 150%; margin-top: 0.00em; margin-bottom: 0.76em;}", "p {text-align: justify; line-height: 150%; margin-top: 0.00em; margin-bottom: 0.76em;}",
"h1 {color: rgb(66, 113, 174); page-break-after: avoid; margin-top: 1.30em; margin-bottom: 0.65em;}", "h1 {color: rgb(66, 113, 174); page-break-after: avoid; margin-top: 1.30em; margin-bottom: 0.65em;}",
"h2 {color: rgb(66, 113, 174); page-break-after: avoid; margin-top: 1.09em; margin-bottom: 0.65em;}", "h2 {color: rgb(66, 113, 174); page-break-after: avoid; margin-top: 1.09em; margin-bottom: 0.65em;}",
+1 -2
View File
@@ -58,8 +58,7 @@ BUILD_CONF = {
"text.includeBodyText": True, "text.includeBodyText": True,
"text.addNoteHeadings": True, "text.addNoteHeadings": True,
"format.buildLang": "en_GB", "format.buildLang": "en_GB",
"format.textFont": "Arial", "format.textFont": "Arial,12",
"format.textSize": 12,
"format.lineHeight": 1.5, "format.lineHeight": 1.5,
"format.justifyText": True, "format.justifyText": True,
"format.stripUnicode": False, "format.stripUnicode": False,