From be7047683d21a5ff12e504b5324f04779b0e61f3 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Sat, 13 Mar 2021 18:56:48 +0100 Subject: [PATCH] Get rid of page number parsing in break processing --- .../w2phtml/xhtml/content/TextParser.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/w2phtml/xhtml/content/TextParser.java b/src/main/java/w2phtml/xhtml/content/TextParser.java index 0603996..6522cdf 100644 --- a/src/main/java/w2phtml/xhtml/content/TextParser.java +++ b/src/main/java/w2phtml/xhtml/content/TextParser.java @@ -1201,16 +1201,14 @@ public class TextParser extends Parser { //No breaks possible return hnode; } - saveLastSectionStyle(currentNode, style); + setLastSectionStyle(currentNode, style); if (wasProcessedWithSection(currentNode, style)) { return hnode; } - Integer newPageNumber = null; - newPageNumber = getPageNumber(style, newPageNumber); if (currentMasterPage == null && style != null) { //Document wasn't started yet. - hnode = startDocument(hnode, style, newPageNumber); + hnode = startDocument(hnode, style); hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum); } else if (isPageBreakFound(style)) { if (hasBreakBefore(style)) { @@ -1230,7 +1228,7 @@ public class TextParser extends Parser { } } } - hnode = breakPage(currentNode, hnode, style, newPageNumber); + hnode = breakPage(currentNode, hnode, style); return hnode; @@ -1265,13 +1263,13 @@ public class TextParser extends Parser { return false; } - private void saveLastSectionStyle(Node currentNode, StyleWithProperties style) { + private void setLastSectionStyle(Node currentNode, StyleWithProperties style) { if (currentNode.getNodeName().equals(TEXT_SECTION)) { lastSectionStyle = style; } } - private Node breakPage(Node currentNode, Node hnode, StyleWithProperties style, Integer newPageNumber) { + private Node breakPage(Node currentNode, Node hnode, StyleWithProperties style) { // Insert footnotes insertFootnotes(hnode,false); @@ -1282,6 +1280,7 @@ public class TextParser extends Parser { updateMasterPageWith(style); setPageContainerStyle(); // Set new page number if defined or increment if not + Integer newPageNumber = getPageNumberFromStyle(style); if (newPageNumber != null) { pageNum = newPageNumber; } else { @@ -1308,7 +1307,8 @@ public class TextParser extends Parser { inFootnote = false; } - private Integer getPageNumber(StyleWithProperties style, Integer newPageNumber) { + private Integer getPageNumberFromStyle(StyleWithProperties style) { + Integer pageNumber = null; if (style != null) { // If style:paragraph-properties extists and contain // style:page-number @@ -1318,21 +1318,22 @@ public class TextParser extends Parser { newPageNumberProperty = newPageNumberProperty.replaceAll("[^0-9]", ""); if (!newPageNumberProperty.isEmpty()) { // Save new page number - newPageNumber = Integer.parseInt(newPageNumberProperty); + pageNumber = Integer.parseInt(newPageNumberProperty); } } } - return newPageNumber; + return pageNumber; } - private Node startDocument(Node hnode, StyleWithProperties style, Integer newPageNumber) { + private Node startDocument(Node hnode, StyleWithProperties style) { setFirstMasterPage(style); - + Integer newPageNumber = getPageNumberFromStyle(style); if (newPageNumber != null) { pageNum = newPageNumber; } else { + pageNum = 1; } //Start tagging String sTitle = converter.getTitle();