Skip page breaking on inner elements and inner sections if BREAK_BEFORE already processed on outer section

This commit is contained in:
Georgy Litvinov 2021-02-11 18:03:49 +01:00
parent 121ef193e4
commit 0dd5fd9c05

View file

@ -45,7 +45,6 @@ import w2phtml.office.XMLString;
import w2phtml.pageSplitters.SplitFactory;
import w2phtml.util.Misc;
import w2phtml.xhtml.Converter;
import w2phtml.xhtml.ODFPageSplitter;
import w2phtml.xhtml.Parser;
import w2phtml.xhtml.StyleInfo;
import w2phtml.xhtml.XhtmlConfig;
@ -122,6 +121,7 @@ public class TextParser extends Parser {
private String footnotesContext = null;
PageContainer pageContainer = null;
private boolean applyAnnotationMetadata;
private boolean breakBeforeSectionHappened = false;
public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) {
super(ofr,config,converter);
@ -168,9 +168,10 @@ public class TextParser extends Parser {
if (pagination) {
//ODFPageSplitter.splitOfficeText(onode, ofr);
//Debug.prettyPrintXml(onode);
SplitFactory splitters = new SplitFactory(ofr);
splitters.split(onode);
//Debug.printNode(onode);
//Debug.prettyPrintXml(onode);
}
hnode = (Element)traverseBlockText(onode,hnode);
@ -266,8 +267,6 @@ public class TextParser extends Parser {
Node child = nList.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
String nodeName = child.getNodeName();
// Block splitting
// System.out.println("CURNODE " + nodeName);
if (OfficeReader.isDrawElement(child)) {
getDrawParser().handleDrawElement((Element)child,(Element)hnode,null,nFloatMode);
}
@ -1190,29 +1189,25 @@ public class TextParser extends Parser {
hnode = startDocument(hnode, style, newPageNumber);
hnode = docSep.processOutlineLevel(currentNode, hnode, pageNum);
} else if (hasMasterPage(style) || hasBreakBefore(style) || breakBeforeNextNode) {
// Insert footnotes
insertFootnotes(hnode,false);
if (hasBreakBefore(style)) {
// Add previous MP footer
//hnode = exitPageContainer((Element) hnode);
addFooter(hnode);
// Update MP
updateMasterPageWith(style);
setPageContainerStyle();
// Set new page number if defined or increment if not
if (newPageNumber != null) {
pageNum = newPageNumber;
} else {
pageNum++;
fitPageNumberToMasterPageStyle();
}
hnode = docSep.breaksOrOutline(currentNode, hnode, pageNum);
if (currentNode.getNodeName() == TEXT_SECTION) {
if (breakBeforeSectionHappened) {
//skip one more section;
return hnode;
} else {
breakBeforeSectionHappened = true;
}
} else {
//assume in inner element, break happened, skip break.
if (breakBeforeSectionHappened) {
breakBeforeSectionHappened = false;
return hnode;
}
}
}
hnode = breakPage(currentNode, hnode, style, newPageNumber);
// Print new header
addHeader(hnode);
//hnode = enterPageContainer(hnode);
breakBeforeNextNode = false;
return hnode;
} else {
@ -1228,6 +1223,33 @@ public class TextParser extends Parser {
return hnode;
}
private Node breakPage(Node currentNode, Node hnode, StyleWithProperties style, Integer newPageNumber) {
// Insert footnotes
insertFootnotes(hnode,false);
// Add previous MP footer
//hnode = exitPageContainer((Element) hnode);
addFooter(hnode);
// Update MP
updateMasterPageWith(style);
setPageContainerStyle();
// Set new page number if defined or increment if not
if (newPageNumber != null) {
pageNum = newPageNumber;
} else {
pageNum++;
fitPageNumberToMasterPageStyle();
}
hnode = docSep.breaksOrOutline(currentNode, hnode, pageNum);
// Print new header
addHeader(hnode);
//hnode = enterPageContainer(hnode);
breakBeforeNextNode = false;
return hnode;
}
private boolean inUnreakableElement() {
return inHeader || inFooter || inTable || inList || inFootnote || inEndnote;
}