Skip to content

Commit

Permalink
Make page breaks visible in manuscript preview (#2086)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo authored Nov 7, 2024
2 parents 04645ca + 87512eb commit 30118ec
Show file tree
Hide file tree
Showing 16 changed files with 328 additions and 160 deletions.
1 change: 1 addition & 0 deletions novelwriter/assets/i18n/project_en_GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"Objects": "Objects",
"Entities": "Entities",
"Custom": "Custom",
"New Page": "New Page",
"0": "Zero",
"1": "One",
"2": "Two",
Expand Down
30 changes: 22 additions & 8 deletions novelwriter/core/coretools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from novelwriter import CONFIG, SHARED
from novelwriter.common import isHandle, minmax, simplified
from novelwriter.constants import nwConst, nwFiles, nwItemClass
from novelwriter.constants import nwConst, nwFiles, nwItemClass, nwStats
from novelwriter.core.item import NWItem
from novelwriter.core.project import NWProject
from novelwriter.core.storage import NWStorageCreate
Expand Down Expand Up @@ -428,7 +428,6 @@ def _buildAndPopulate(self, path: Path, data: dict) -> bool:

lblNewProject = self.tr("New Project")
lblTitlePage = self.tr("Title Page")
lblByAuthors = self.tr("By")

# Settings
project.data.setUuid(None)
Expand All @@ -441,14 +440,29 @@ def _buildAndPopulate(self, path: Path, data: dict) -> bool:
# Add Root Folders
hNovelRoot = project.newRoot(nwItemClass.NOVEL)
hTitlePage = project.newFile(lblTitlePage, hNovelRoot)
novelTitle = project.data.name

titlePage = f"#! {novelTitle}\n\n"
if project.data.author:
titlePage += f">> {lblByAuthors} {project.data.author} <<\n\n"

# Generate Title Page
aDoc = project.storage.getDocument(hTitlePage)
aDoc.writeDocument(titlePage)
aDoc.writeDocument((
"{author}[br]\n"
"{address} 1[br]\n"
"{address} 2 <<\n"
"\n"
"[vspace:5]\n"
"\n"
"#! {title}\n"
"\n"
">> **{by} {author}** <<\n"
"\n"
">> {count}: [field:{field}] <<\n"
).format(
author=project.data.author or "None",
address=self.tr("Address"),
title=project.data.name or "None",
by=self.tr("By"),
count=self.tr("Word Count"),
field=nwStats.WORDS_TEXT,
))

# Create a project structure based on selected root folders
# and a number of chapters and scenes selected in the
Expand Down
33 changes: 13 additions & 20 deletions novelwriter/core/docbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,6 @@ def lastBuild(self) -> Tokenizer | None:
"""
return self._cache

##
# Setters
##

def setBuildOutline(self, state: bool) -> None:
"""Turn on/off outline for builds."""
self._outline = state
return

##
# Special Methods
##
Expand All @@ -122,11 +113,12 @@ def queueAll(self) -> None:
self._queue.append(item.itemHandle)
return

def iterBuildPreview(self) -> Iterable[tuple[int, bool]]:
def iterBuildPreview(self, newPage: bool) -> Iterable[tuple[int, bool]]:
"""Build a preview QTextDocument."""
makeObj = ToQTextDocument(self._project)
filtered = self._setupBuild(makeObj)
makeObj.initDocument()
makeObj.setShowNewPage(newPage)
self._outline = True
yield from self._iterBuild(makeObj, filtered)
makeObj.closeDocument()
Expand Down Expand Up @@ -352,14 +344,17 @@ def _doBuild(self, bldObj: Tokenizer, tHandle: str, convert: bool = True) -> boo
tItem = self._project.tree[tHandle]
if isinstance(tItem, NWItem):
try:
if tItem.isRootType() and not tItem.isNovelLike():
bldObj.addRootHeading(tHandle)
if convert:
bldObj.doConvert()
if self._count:
bldObj.countStats()
if self._outline:
bldObj.buildOutline()
if tItem.isRootType():
if tItem.isNovelLike():
bldObj.setBreakNext()
else:
bldObj.addRootHeading(tHandle)
if convert:
bldObj.doConvert()
if self._count:
bldObj.countStats()
if self._outline:
bldObj.buildOutline()
elif tItem.isFileType():
bldObj.setText(tHandle)
bldObj.doPreProcessing()
Expand All @@ -370,8 +365,6 @@ def _doBuild(self, bldObj: Tokenizer, tHandle: str, convert: bool = True) -> boo
bldObj.buildOutline()
if convert:
bldObj.doConvert()
else:
logger.info(f"Build: Skipping '{tHandle}'")

except Exception:
self._error = f"Build: Failed to build '{tHandle}'"
Expand Down
2 changes: 1 addition & 1 deletion novelwriter/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"GuiManuscript": {
"winWidth", "winHeight", "optsWidth", "viewWidth", "listHeight",
"detailsHeight", "detailsWidth", "detailsExpanded",
"detailsHeight", "detailsWidth", "detailsExpanded", "showNewPage",
},
"GuiManuscriptBuild": {
"winWidth", "winHeight", "fmtWidth", "sumWidth",
Expand Down
51 changes: 25 additions & 26 deletions novelwriter/formats/todocx.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,32 +236,31 @@ def doConvert(self) -> None:
self._pars.append(par)

# Styles
if tStyle is not None:
if tStyle & BlockFmt.LEFT:
par.setAlignment("left")
elif tStyle & BlockFmt.RIGHT:
par.setAlignment("right")
elif tStyle & BlockFmt.CENTRE:
par.setAlignment("center")
elif tStyle & BlockFmt.JUSTIFY:
par.setAlignment("both")

if tStyle & BlockFmt.PBB:
par.setPageBreakBefore(True)
if tStyle & BlockFmt.PBA:
par.setPageBreakAfter(True)

if tStyle & BlockFmt.Z_BTM:
par.setMarginBottom(0.0)
if tStyle & BlockFmt.Z_TOP:
par.setMarginTop(0.0)

if tStyle & BlockFmt.IND_T:
par.setIndentFirst(True)
if tStyle & BlockFmt.IND_L:
par.setMarginLeft(bIndent)
if tStyle & BlockFmt.IND_R:
par.setMarginRight(bIndent)
if tStyle & BlockFmt.LEFT:
par.setAlignment("left")
elif tStyle & BlockFmt.RIGHT:
par.setAlignment("right")
elif tStyle & BlockFmt.CENTRE:
par.setAlignment("center")
elif tStyle & BlockFmt.JUSTIFY:
par.setAlignment("both")

if tStyle & BlockFmt.PBB:
par.setPageBreakBefore(True)
if tStyle & BlockFmt.PBA:
par.setPageBreakAfter(True)

if tStyle & BlockFmt.Z_BTM:
par.setMarginBottom(0.0)
if tStyle & BlockFmt.Z_TOP:
par.setMarginTop(0.0)

if tStyle & BlockFmt.IND_T:
par.setIndentFirst(True)
if tStyle & BlockFmt.IND_L:
par.setMarginLeft(bIndent)
if tStyle & BlockFmt.IND_R:
par.setMarginRight(bIndent)

# Process Text Types
if tType == BlockTyp.TEXT:
Expand Down
2 changes: 1 addition & 1 deletion novelwriter/formats/tohtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def doConvert(self) -> None:

# Styles
aStyle = []
if tStyle is not None and self._cssStyles:
if self._cssStyles:
if tStyle & BlockFmt.LEFT:
aStyle.append("text-align: left;")
elif tStyle & BlockFmt.RIGHT:
Expand Down
Loading

0 comments on commit 30118ec

Please sign in to comment.