Skip to content

Commit

Permalink
Refactor manuscript format text scaling and text margin settings (#2102)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo authored Nov 13, 2024
2 parents 5e7ef1d + a96ccf8 commit 1ee1912
Show file tree
Hide file tree
Showing 31 changed files with 298 additions and 280 deletions.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_dark/icons.conf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ font = nw_font.svg
forward = typ_chevron-right.svg
import = mixed_import.svg
list = typ_th-list.svg
margin_bottom = mixed_margin-bottom.svg
margin_left = mixed_margin-left.svg
margin_right = mixed_margin-right.svg
margin_top = mixed_margin-top.svg
maximise = typ_arrow-maximise.svg
menu = typ_th-dot-menu.svg
minimise = typ_arrow-minimise.svg
Expand Down Expand Up @@ -94,6 +98,8 @@ search_regex = nw_search-regex.svg
search_replace = mixed_search-replace.svg
search_word = nw_search-word.svg
settings = typ_cog.svg
size_height = mixed_size-height.svg
size_width = mixed_size-width.svg
star = typ_star.svg
status_idle = typ_media-pause-grey.svg
status_lang = typ_globe-grey.svg
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_dark/mixed_margin-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_dark/mixed_margin-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_dark/mixed_margin-top.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_dark/mixed_size-height.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_dark/mixed_size-width.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_light/icons.conf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ font = nw_font.svg
forward = typ_chevron-right.svg
import = mixed_import.svg
list = typ_th-list.svg
margin_bottom = mixed_margin-bottom.svg
margin_left = mixed_margin-left.svg
margin_right = mixed_margin-right.svg
margin_top = mixed_margin-top.svg
maximise = typ_arrow-maximise.svg
menu = typ_th-dot-menu.svg
minimise = typ_arrow-minimise.svg
Expand Down Expand Up @@ -94,6 +98,8 @@ search_regex = nw_search-regex.svg
search_replace = mixed_search-replace.svg
search_word = nw_search-word.svg
settings = typ_cog.svg
size_height = mixed_size-height.svg
size_width = mixed_size-width.svg
star = typ_star.svg
status_idle = typ_media-pause-grey.svg
status_lang = typ_globe-grey.svg
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_light/mixed_margin-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_light/mixed_margin-top.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_light/mixed_size-height.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions novelwriter/assets/icons/typicons_light/mixed_size-width.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 12 additions & 9 deletions novelwriter/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class nwStyles:
H_LEVEL = {"H0": 0, "H1": 1, "H2": 2, "H3": 3, "H4": 4}
H_SIZES = {0: 2.50, 1: 2.00, 2: 1.75, 3: 1.50, 4: 1.25}

T_NORMAL = 1.0
T_SMALL = 0.8

T_LABEL = {
"H0": QT_TRANSLATE_NOOP("Constant", "Title"),
"H1": QT_TRANSLATE_NOOP("Constant", "Heading 1 (Partition)"),
Expand All @@ -115,15 +118,15 @@ class nwStyles:
"SP": QT_TRANSLATE_NOOP("Constant", "Scene Separator"),
}
T_MARGIN = {
"H0": (1.42, 0.50), # Title margins
"H1": (1.42, 0.50), # Heading 1 margins
"H2": (1.67, 0.50), # Heading 2 margins
"H3": (1.17, 0.50), # Heading 3 margins
"H4": (1.17, 0.50), # Heading 4 margins
"TT": (0.00, 0.58), # Text margins
"SP": (1.17, 1.17), # Separator margins
"MT": (0.00, 0.58), # Meta margins
"FT": (1.42, 0.47), # Footnote margins
"H0": (1.50, 0.60), # Title margins (top, bottom)
"H1": (1.50, 0.60), # Heading 1 margins (top, bottom)
"H2": (1.50, 0.60), # Heading 2 margins (top, bottom)
"H3": (1.20, 0.60), # Heading 3 margins (top, bottom)
"H4": (1.20, 0.60), # Heading 4 margins (top, bottom)
"TT": (0.00, 0.60), # Text margins (top, bottom)
"SP": (1.20, 1.20), # Separator margins (top, bottom)
"MT": (0.00, 0.60), # Meta margins (top, bottom)
"FT": (1.40, 0.40), # Footnote margins (left, bottom)
}


Expand Down
8 changes: 6 additions & 2 deletions novelwriter/extensions/configlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"""
from __future__ import annotations

from PyQt5.QtGui import QColor, QFont, QPalette
from PyQt5.QtGui import QColor, QFont, QPalette, QPixmap
from PyQt5.QtWidgets import (
QAbstractButton, QFrame, QHBoxLayout, QLabel, QLayout, QScrollArea,
QVBoxLayout, QWidget
Expand Down Expand Up @@ -183,7 +183,7 @@ def addGroupLabel(self, label: str, identifier: int | None = None) -> None:
def addRow(
self,
label: str | None,
widget: QWidget | list[QWidget | str | int],
widget: QWidget | list[QWidget | QPixmap | str | int],
helpText: str = "",
unit: str | None = None,
button: QWidget | None = None,
Expand All @@ -200,6 +200,10 @@ def addRow(
for item in widget:
if isinstance(item, QWidget):
wBox.addWidget(item)
elif isinstance(item, QPixmap):
icon = QLabel(self)
icon.setPixmap(item)
wBox.addWidget(icon)
elif isinstance(item, str):
wBox.addWidget(QLabel(item, self))
elif isinstance(item, int):
Expand Down
40 changes: 17 additions & 23 deletions novelwriter/formats/todocx.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,6 @@ def _generateStyles(self) -> None:
hScale = self._scaleHeads
hColor = _docXCol(self._theme.head) if self._colorHeads else None
fSz = self._fontSize
fnSz = 0.8 * self._fontSize
fSz0 = (nwStyles.H_SIZES[0] * fSz) if hScale else fSz
fSz1 = (nwStyles.H_SIZES[1] * fSz) if hScale else fSz
fSz2 = (nwStyles.H_SIZES[2] * fSz) if hScale else fSz
fSz3 = (nwStyles.H_SIZES[3] * fSz) if hScale else fSz
fSz4 = (nwStyles.H_SIZES[4] * fSz) if hScale else fSz

# Add Normal Style
styles.append(DocXParStyle(
Expand All @@ -545,12 +539,12 @@ def _generateStyles(self) -> None:
styles.append(DocXParStyle(
name="Title",
styleId=S_TITLE,
size=fSz0,
size=(nwStyles.H_SIZES[0] * fSz) if hScale else fSz,
basedOn=S_NORM,
nextStyle=S_NORM,
before=fSz * self._marginTitle[0],
after=fSz * self._marginTitle[1],
line=fSz0 * self._lineHeight,
line=fSz * self._lineHeight,
level=0,
bold=self._boldHeads,
))
Expand All @@ -559,12 +553,12 @@ def _generateStyles(self) -> None:
styles.append(DocXParStyle(
name="Heading 1",
styleId=S_HEAD1,
size=fSz1,
size=(nwStyles.H_SIZES[1] * fSz) if hScale else fSz,
basedOn=S_NORM,
nextStyle=S_NORM,
before=fSz * self._marginHead1[0],
after=fSz * self._marginHead1[1],
line=fSz1 * self._lineHeight,
line=fSz * self._lineHeight,
level=0,
color=hColor,
bold=self._boldHeads,
Expand All @@ -574,12 +568,12 @@ def _generateStyles(self) -> None:
styles.append(DocXParStyle(
name="Heading 2",
styleId=S_HEAD2,
size=fSz2,
size=(nwStyles.H_SIZES[2] * fSz) if hScale else fSz,
basedOn=S_NORM,
nextStyle=S_NORM,
before=fSz * self._marginHead2[0],
after=fSz * self._marginHead2[1],
line=fSz2 * self._lineHeight,
line=fSz * self._lineHeight,
level=1,
color=hColor,
bold=self._boldHeads,
Expand All @@ -589,12 +583,12 @@ def _generateStyles(self) -> None:
styles.append(DocXParStyle(
name="Heading 3",
styleId=S_HEAD3,
size=fSz3,
size=(nwStyles.H_SIZES[3] * fSz) if hScale else fSz,
basedOn=S_NORM,
nextStyle=S_NORM,
before=fSz * self._marginHead3[0],
after=fSz * self._marginHead3[1],
line=fSz3 * self._lineHeight,
line=fSz * self._lineHeight,
level=1,
color=hColor,
bold=self._boldHeads,
Expand All @@ -604,12 +598,12 @@ def _generateStyles(self) -> None:
styles.append(DocXParStyle(
name="Heading 4",
styleId=S_HEAD4,
size=fSz4,
size=(nwStyles.H_SIZES[4] * fSz) if hScale else fSz,
basedOn=S_NORM,
nextStyle=S_NORM,
before=fSz * self._marginHead4[0],
after=fSz * self._marginHead4[1],
line=fSz4 * self._lineHeight,
line=fSz * self._lineHeight,
level=1,
color=hColor,
bold=self._boldHeads,
Expand Down Expand Up @@ -653,12 +647,12 @@ def _generateStyles(self) -> None:
styles.append(DocXParStyle(
name="Footnote Text",
styleId=S_FNOTE,
size=fnSz,
size=nwStyles.T_SMALL * fSz,
basedOn=S_NORM,
before=0.0,
after=fnSz * self._marginFoot[1],
left=fnSz * self._marginFoot[0],
line=fnSz * self._lineHeight,
after=fSz * self._marginFoot[1],
left=fSz * self._marginFoot[0],
line=fSz * self._lineHeight,
))

# Add to Cache
Expand Down Expand Up @@ -795,6 +789,7 @@ def _stylesXml(self) -> str:
_wTag("before"): str(int(20.0 * firstFloat(style.before))),
_wTag("after"): str(int(20.0 * firstFloat(style.after))),
_wTag("line"): str(int(20.0 * firstFloat(style.line, size))),
_wTag("lineRule"): "auto",
})
if style.left is not None:
xmlSubElem(pPr, _wTag("ind"), attrib={
Expand Down Expand Up @@ -860,12 +855,10 @@ def _defaultHeaderXml(self) -> str:
xR = xmlSubElem(xP, _wTag("r"))
xmlSubElem(xR, _wTag("fldChar"), attrib={wFldCT: "begin"})
xR = xmlSubElem(xP, _wTag("r"))
_wText(xR, " PAGE ")
xmlSubElem(xR, _wTag("instrText"), "PAGE", attrib={_mkTag("xml", "space"): "preserve"})
xR = xmlSubElem(xP, _wTag("r"))
xmlSubElem(xR, _wTag("fldChar"), attrib={wFldCT: "separate"})
xR = xmlSubElem(xP, _wTag("r"))
_wText(xR, "0")
xR = xmlSubElem(xP, _wTag("r"))
xmlSubElem(xR, _wTag("fldChar"), attrib={wFldCT: "end"})
if post:
xR = xmlSubElem(xP, _wTag("r"))
Expand Down Expand Up @@ -1171,6 +1164,7 @@ def toXml(self, body: ET.Element) -> None:
_wTag("before"): str(int(20.0 * firstFloat(self._topMargin, style.before))),
_wTag("after"): str(int(20.0 * firstFloat(self._bottomMargin, style.after))),
_wTag("line"): str(int(20.0 * firstFloat(style.line, style.size))),
_wTag("lineRule"): "auto",
})
if indent:
xmlSubElem(pPr, _wTag("ind"), attrib=indent)
Expand Down
Loading

0 comments on commit 1ee1912

Please sign in to comment.