Get rid of page number parsing in break processing

This commit is contained in:
Georgy Litvinov 2021-03-13 18:56:48 +01:00
parent 187f3d1eb4
commit be7047683d

View file

@ -1201,16 +1201,14 @@ public class TextParser extends Parser {
//No breaks possible //No breaks possible
return hnode; return hnode;
} }
saveLastSectionStyle(currentNode, style); setLastSectionStyle(currentNode, style);
if (wasProcessedWithSection(currentNode, style)) { if (wasProcessedWithSection(currentNode, style)) {
return hnode; return hnode;
} }
Integer newPageNumber = null;
newPageNumber = getPageNumber(style, newPageNumber);
if (currentMasterPage == null && style != null) { if (currentMasterPage == null && style != null) {
//Document wasn't started yet. //Document wasn't started yet.
hnode = startDocument(hnode, style, newPageNumber); hnode = startDocument(hnode, style);
hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum); hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum);
} else if (isPageBreakFound(style)) { } else if (isPageBreakFound(style)) {
if (hasBreakBefore(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; return hnode;
@ -1265,13 +1263,13 @@ public class TextParser extends Parser {
return false; return false;
} }
private void saveLastSectionStyle(Node currentNode, StyleWithProperties style) { private void setLastSectionStyle(Node currentNode, StyleWithProperties style) {
if (currentNode.getNodeName().equals(TEXT_SECTION)) { if (currentNode.getNodeName().equals(TEXT_SECTION)) {
lastSectionStyle = style; lastSectionStyle = style;
} }
} }
private Node breakPage(Node currentNode, Node hnode, StyleWithProperties style, Integer newPageNumber) { private Node breakPage(Node currentNode, Node hnode, StyleWithProperties style) {
// Insert footnotes // Insert footnotes
insertFootnotes(hnode,false); insertFootnotes(hnode,false);
@ -1282,6 +1280,7 @@ public class TextParser extends Parser {
updateMasterPageWith(style); updateMasterPageWith(style);
setPageContainerStyle(); setPageContainerStyle();
// Set new page number if defined or increment if not // Set new page number if defined or increment if not
Integer newPageNumber = getPageNumberFromStyle(style);
if (newPageNumber != null) { if (newPageNumber != null) {
pageNum = newPageNumber; pageNum = newPageNumber;
} else { } else {
@ -1308,7 +1307,8 @@ public class TextParser extends Parser {
inFootnote = false; inFootnote = false;
} }
private Integer getPageNumber(StyleWithProperties style, Integer newPageNumber) { private Integer getPageNumberFromStyle(StyleWithProperties style) {
Integer pageNumber = null;
if (style != null) { if (style != null) {
// If style:paragraph-properties extists and contain // If style:paragraph-properties extists and contain
// style:page-number // style:page-number
@ -1318,21 +1318,22 @@ public class TextParser extends Parser {
newPageNumberProperty = newPageNumberProperty.replaceAll("[^0-9]", ""); newPageNumberProperty = newPageNumberProperty.replaceAll("[^0-9]", "");
if (!newPageNumberProperty.isEmpty()) { if (!newPageNumberProperty.isEmpty()) {
// Save new page number // 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); setFirstMasterPage(style);
Integer newPageNumber = getPageNumberFromStyle(style);
if (newPageNumber != null) { if (newPageNumber != null) {
pageNum = newPageNumber; pageNum = newPageNumber;
} else { } else {
pageNum = 1;
} }
//Start tagging //Start tagging
String sTitle = converter.getTitle(); String sTitle = converter.getTitle();