Fixed empty page before paragraph with pageStyle in section

This commit is contained in:
Georgy Litvinov 2021-03-12 23:04:48 +01:00
parent 22ba9e1077
commit e6fbee9f67
2 changed files with 59 additions and 1 deletions

View file

@ -122,6 +122,7 @@ public class TextParser extends Parser {
PageContainer pageContainer = null;
private boolean applyAnnotationMetadata;
private boolean breakBeforeSectionHappened = false;
private StyleWithProperties lastSectionStyle;
public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) {
super(ofr,config,converter);
@ -349,7 +350,8 @@ public class TextParser extends Parser {
else if (nodeName.equals(TEXT_SECTION)) {
StyleWithProperties style = getFirstStylePageInfo(child);
hnode = processPageBreaks(child, hnode,style);
hnode = handleSection(child,hnode);
hnode = handleSection(child,hnode);
//Debug.prettyPrintXml(hnode.getOwnerDocument());
}
else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) {
if (!ofr.getTocReader((Element)child).isByChapter()) {
@ -419,6 +421,8 @@ public class TextParser extends Parser {
/* Process a text:section tag (returns current html node) */
private Node handleSection(Node onode, Node hnode) {
//Debug.prettyPrintXml(hnode.getOwnerDocument());
// Unlike headings, paragraphs and spans, text:display is not attached to the style:
String lastEndnotesContext = endnotesContext;
String lastFootnotesContext = footnotesContext;
@ -438,7 +442,10 @@ public class TextParser extends Parser {
if (pageWasOpened && !inTable) {
hnode = docSep.openPage(hnode, pageNum);
}
//Debug.prettyPrintXml(hnode.getOwnerDocument());
hnode = traverseBlockText(onode, hnode);
//Debug.prettyPrintXml(hnode.getOwnerDocument());
if (isLast) {
insertEndnotes((Element) hnode, sectionName);
}
@ -635,6 +642,8 @@ public class TextParser extends Parser {
*/
private void handleParagraph(Node onode, Node hnode) {
boolean isEmptyParagraph = OfficeReader.isWhitespaceContent(onode);
//Debug.prettyPrintXml(hnode.getOwnerDocument());
if (config.ignoreEmptyParagraphs() && isEmptyParagraph) { return; }
String styleName = Misc.getAttribute(onode,TEXT_STYLE_NAME);
StyleWithProperties style = ofr.getParStyle(styleName);
@ -1192,6 +1201,10 @@ public class TextParser extends Parser {
//No breaks possible
return hnode;
}
saveLastSectionStyle(currentNode, style);
if (wasProcessedWithSection(currentNode, style)) {
return hnode;
}
Integer newPageNumber = null;
newPageNumber = getPageNumber(style, newPageNumber);
@ -1234,6 +1247,22 @@ public class TextParser extends Parser {
return hnode;
}
private boolean wasProcessedWithSection(Node currentNode, StyleWithProperties style) {
if (!currentNode.getNodeName().equals(TEXT_SECTION)) {
if (lastSectionStyle != null && lastSectionStyle == style) {
lastSectionStyle = null;
return true;
}
}
return false;
}
private void saveLastSectionStyle(Node currentNode, StyleWithProperties style) {
if (currentNode.getNodeName().equals(TEXT_SECTION)) {
lastSectionStyle = style;
}
}
private Node breakPage(Node currentNode, Node hnode, StyleWithProperties style, Integer newPageNumber) {
// Insert footnotes
insertFootnotes(hnode,false);