diff --git a/src/main/java/w2phtml/xhtml/content/Separator.java b/src/main/java/w2phtml/xhtml/content/Separator.java index 2eabb62..58bc7bb 100644 --- a/src/main/java/w2phtml/xhtml/content/Separator.java +++ b/src/main/java/w2phtml/xhtml/content/Separator.java @@ -240,18 +240,6 @@ public class Separator { return false; } - public Node processPageBreak(Node currentNode, Node hnode, Integer pageNum) { - if (!needPagination()) { - return hnode; - } - if (pageOpened) { - hnode = closePage(hnode); - } - hnode = openPage(hnode, pageNum); - - return hnode; - } - public boolean isPageOpened() { return pageOpened; } @@ -469,7 +457,7 @@ public class Separator { private Node exitPageContainer(Node hnode) { String className = ((Element) hnode).getAttribute("class"); if (!className.equals("pageContainer")) { - System.out.println("Can't exit not my container!"); + logger.error("Can't exit not my container!"); Debug.printNode(hnode); Debug.printStackTrace(); System.exit(1); @@ -519,12 +507,17 @@ public class Separator { } public Node breaksOrOutline(Node currentNode, Node hnode, int pageNum) { - Node outlineNode = getRealOntlineNode(currentNode); - Integer curLevel = getOutlineLevel(outlineNode); - String title = getOutlineTitle(outlineNode); - if (curLevel < 1 || title == null || title.isEmpty()) { - hnode = processPageBreak(currentNode, hnode, pageNum); + if (isBadOutlineNode(currentNode)) { + if (!needPagination()) { + return hnode; + } + if (pageOpened) { + hnode = closePage(hnode); + } + hnode = openPage(hnode, pageNum); + + return hnode; } else { hnode = whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum); } diff --git a/src/main/java/w2phtml/xhtml/content/TextParser.java b/src/main/java/w2phtml/xhtml/content/TextParser.java index 1115c13..0603996 100644 --- a/src/main/java/w2phtml/xhtml/content/TextParser.java +++ b/src/main/java/w2phtml/xhtml/content/TextParser.java @@ -110,7 +110,7 @@ public class TextParser extends Parser { private String nextMasterPage = null; private boolean pagination = config.pagination(); - private boolean breakBeforeNextNode = false; + private boolean breakPageBeforeNextNode = false; private boolean inTable = false; private boolean inList = false; private boolean inFootnote = false; @@ -121,7 +121,7 @@ public class TextParser extends Parser { private String footnotesContext = null; PageContainer pageContainer = null; private boolean applyAnnotationMetadata; - private boolean breakBeforeSectionHappened = false; + private boolean breakBeforeSectionInProcessFlag = false; private StyleWithProperties lastSectionStyle; public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) { @@ -263,7 +263,7 @@ public class TextParser extends Parser { int nLen = nList.getLength(); int i = 0; //hard Break after marker - breakBeforeNextNode = false; + breakPageBeforeNextNode = false; while (i < nLen) { Node child = nList.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { @@ -273,7 +273,7 @@ public class TextParser extends Parser { } else if (nodeName.equals(TEXT_P)) { StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,TEXT_STYLE_NAME)); - hnode = processPageBreaks(child, hnode,style); + hnode = processBreaks(child, hnode,style); // is there a block element, we should use? XhtmlStyleMap xpar = config.getXParStyleMap(); String sDisplayName = style!=null ? style.getDisplayName() : null; @@ -319,7 +319,7 @@ public class TextParser extends Parser { else if(nodeName.equals(TEXT_H)) { StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,TEXT_STYLE_NAME)); Node rememberNode = hnode; - hnode = processPageBreaks(child, hnode, style); + hnode = processBreaks(child, hnode, style); handleHeading((Element)child,(Element)hnode,rememberNode!=hnode); } else if (nodeName.equals(TEXT_LIST) || // oasis @@ -327,7 +327,7 @@ public class TextParser extends Parser { nodeName.equals(TEXT_ORDERED_LIST)) // old { StyleWithProperties style = getFirstStylePageInfo(child); - hnode = processPageBreaks(child, hnode,style); + hnode = processBreaks(child, hnode,style); inList = true; if (getListParser().listIsOnlyHeadings(child)) { hnode = getListParser().handleFakeList(child,nLevel+1,styleName,hnode); @@ -339,7 +339,7 @@ public class TextParser extends Parser { } else if (nodeName.equals(TABLE_TABLE)) { StyleWithProperties style = ofr.getTableStyle(Misc.getAttribute(child, TABLE_STYLE_NAME)); - hnode = processPageBreaks(child, hnode,style); + hnode = processBreaks(child, hnode,style); inTable = true; getTableParser().handleTable(child,hnode); inTable = false; @@ -349,7 +349,7 @@ public class TextParser extends Parser { } else if (nodeName.equals(TEXT_SECTION)) { StyleWithProperties style = getFirstStylePageInfo(child); - hnode = processPageBreaks(child, hnode,style); + hnode = processBreaks(child, hnode,style); hnode = handleSection(child,hnode); //Debug.prettyPrintXml(hnode.getOwnerDocument()); } @@ -377,7 +377,7 @@ public class TextParser extends Parser { bibCv.handleIndex((Element)child,(Element)hnode); } else if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)) { - breakBeforeNextNode = true; + breakPageBeforeNextNode = true; } else if (nodeName.equals(OFFICE_ANNOTATION)) { handleOfficeAnnotation(child,hnode); @@ -1191,7 +1191,7 @@ public class TextParser extends Parser { Misc.getPosInteger(node.getAttribute(TEXT_OUTLINE_LEVEL),0): Misc.getPosInteger(node.getAttribute(TEXT_LEVEL),0); } - private Node processPageBreaks(Node currentNode, Node hnode, StyleWithProperties style){ + private Node processBreaks(Node currentNode, Node hnode, StyleWithProperties style){ //Check for paragraph in current node in case currentNode is table // If currentNode is table //check for first para inside @@ -1212,20 +1212,20 @@ public class TextParser extends Parser { //Document wasn't started yet. hnode = startDocument(hnode, style, newPageNumber); hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum); - } else if (hasMasterPage(style) || hasBreakBefore(style) || breakBeforeNextNode) { + } else if (isPageBreakFound(style)) { if (hasBreakBefore(style)) { if (currentNode.getNodeName() == TEXT_SECTION) { - if (breakBeforeSectionHappened) { + if (breakBeforeSectionInProcessFlag) { //skip one more section; return hnode; } else { - breakBeforeSectionHappened = true; + breakBeforeSectionInProcessFlag = true; } } else { //assume in inner element, break happened, skip break. - if (breakBeforeSectionHappened) { - breakBeforeSectionHappened = false; + if (breakBeforeSectionInProcessFlag) { + breakBeforeSectionInProcessFlag = false; return hnode; } } @@ -1238,15 +1238,23 @@ public class TextParser extends Parser { hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum); } - if (checkHardBreakAfter(style)) { - breakBeforeNextNode = true; - } else { - breakBeforeNextNode = false; - } + setBreakPageBeforeNextNode(style); return hnode; } + private void setBreakPageBeforeNextNode(StyleWithProperties style) { + if (isNewHardPageBreakAfter(style)) { + breakPageBeforeNextNode = true; + } else { + breakPageBeforeNextNode = false; + } + } + + private boolean isPageBreakFound(StyleWithProperties style) { + return hasMasterPage(style) || hasBreakBefore(style) || breakPageBeforeNextNode; + } + private boolean wasProcessedWithSection(Node currentNode, StyleWithProperties style) { if (!currentNode.getNodeName().equals(TEXT_SECTION)) { if (lastSectionStyle != null && lastSectionStyle == style) { @@ -1286,7 +1294,7 @@ public class TextParser extends Parser { // Print new header addHeader(hnode); //hnode = enterPageContainer(hnode); - breakBeforeNextNode = false; + breakPageBeforeNextNode = false; return hnode; } @@ -1417,7 +1425,7 @@ public class TextParser extends Parser { return false; } - private boolean checkHardBreakAfter(StyleWithProperties style) { + private boolean isNewHardPageBreakAfter(StyleWithProperties style) { if (style != null && "page".equals(style.getProperty(FO_BREAK_AFTER))) { return true; }