Skip page breaking on inner elements and inner sections if BREAK_BEFORE already processed on outer section
This commit is contained in:
parent
121ef193e4
commit
0dd5fd9c05
1 changed files with 49 additions and 27 deletions
|
@ -45,7 +45,6 @@ import w2phtml.office.XMLString;
|
||||||
import w2phtml.pageSplitters.SplitFactory;
|
import w2phtml.pageSplitters.SplitFactory;
|
||||||
import w2phtml.util.Misc;
|
import w2phtml.util.Misc;
|
||||||
import w2phtml.xhtml.Converter;
|
import w2phtml.xhtml.Converter;
|
||||||
import w2phtml.xhtml.ODFPageSplitter;
|
|
||||||
import w2phtml.xhtml.Parser;
|
import w2phtml.xhtml.Parser;
|
||||||
import w2phtml.xhtml.StyleInfo;
|
import w2phtml.xhtml.StyleInfo;
|
||||||
import w2phtml.xhtml.XhtmlConfig;
|
import w2phtml.xhtml.XhtmlConfig;
|
||||||
|
@ -122,6 +121,7 @@ public class TextParser extends Parser {
|
||||||
private String footnotesContext = null;
|
private String footnotesContext = null;
|
||||||
PageContainer pageContainer = null;
|
PageContainer pageContainer = null;
|
||||||
private boolean applyAnnotationMetadata;
|
private boolean applyAnnotationMetadata;
|
||||||
|
private boolean breakBeforeSectionHappened = false;
|
||||||
|
|
||||||
public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) {
|
public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) {
|
||||||
super(ofr,config,converter);
|
super(ofr,config,converter);
|
||||||
|
@ -168,9 +168,10 @@ public class TextParser extends Parser {
|
||||||
|
|
||||||
if (pagination) {
|
if (pagination) {
|
||||||
//ODFPageSplitter.splitOfficeText(onode, ofr);
|
//ODFPageSplitter.splitOfficeText(onode, ofr);
|
||||||
|
//Debug.prettyPrintXml(onode);
|
||||||
SplitFactory splitters = new SplitFactory(ofr);
|
SplitFactory splitters = new SplitFactory(ofr);
|
||||||
splitters.split(onode);
|
splitters.split(onode);
|
||||||
//Debug.printNode(onode);
|
//Debug.prettyPrintXml(onode);
|
||||||
}
|
}
|
||||||
hnode = (Element)traverseBlockText(onode,hnode);
|
hnode = (Element)traverseBlockText(onode,hnode);
|
||||||
|
|
||||||
|
@ -266,8 +267,6 @@ public class TextParser extends Parser {
|
||||||
Node child = nList.item(i);
|
Node child = nList.item(i);
|
||||||
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
String nodeName = child.getNodeName();
|
String nodeName = child.getNodeName();
|
||||||
// Block splitting
|
|
||||||
// System.out.println("CURNODE " + nodeName);
|
|
||||||
if (OfficeReader.isDrawElement(child)) {
|
if (OfficeReader.isDrawElement(child)) {
|
||||||
getDrawParser().handleDrawElement((Element)child,(Element)hnode,null,nFloatMode);
|
getDrawParser().handleDrawElement((Element)child,(Element)hnode,null,nFloatMode);
|
||||||
}
|
}
|
||||||
|
@ -1183,36 +1182,32 @@ public class TextParser extends Parser {
|
||||||
if (inUnreakableElement() ) {
|
if (inUnreakableElement() ) {
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer newPageNumber = null;
|
Integer newPageNumber = null;
|
||||||
newPageNumber = getPageNumber(style, newPageNumber);
|
newPageNumber = getPageNumber(style, newPageNumber);
|
||||||
if (currentMasterPage == null && style != null) {
|
if (currentMasterPage == null && style != null) {
|
||||||
hnode = startDocument(hnode, style, newPageNumber);
|
hnode = startDocument(hnode, style, newPageNumber);
|
||||||
hnode = docSep.processOutlineLevel(currentNode, hnode, pageNum);
|
hnode = docSep.processOutlineLevel(currentNode, hnode, pageNum);
|
||||||
} else if (hasMasterPage(style) || hasBreakBefore(style) || breakBeforeNextNode) {
|
} else if (hasMasterPage(style) || hasBreakBefore(style) || breakBeforeNextNode) {
|
||||||
// Insert footnotes
|
if (hasBreakBefore(style)) {
|
||||||
insertFootnotes(hnode,false);
|
|
||||||
|
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);
|
||||||
|
|
||||||
// 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;
|
return hnode;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1228,6 +1223,33 @@ public class TextParser extends Parser {
|
||||||
return hnode;
|
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() {
|
private boolean inUnreakableElement() {
|
||||||
return inHeader || inFooter || inTable || inList || inFootnote || inEndnote;
|
return inHeader || inFooter || inTable || inList || inFootnote || inEndnote;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue