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
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();