Fix aligning pages according to headers split

This commit is contained in:
Georgy Litvinov 2020-02-10 15:23:59 +01:00
parent a77b27671a
commit 50f3cd615a
4 changed files with 19 additions and 73 deletions

View file

@ -155,7 +155,8 @@ public class DrawParser extends Parser {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String sNodeName = child.getNodeName();
if (sNodeName.equals(XMLString.DRAW_PAGE)) {
handleDrawPage((Element)child,converter.nextOutFile());
//TODO: DRAW INTO PAGE CONTAINER
handleDrawPage((Element)child,converter.nextOutFile());
}
}
}
@ -267,7 +268,7 @@ public class DrawParser extends Parser {
style.setAttribute("type", "text/css");
style.appendChild(converter.createTextNode("body { margin:0 }"));
}
currentNode = getTextCv().doMaybeSplit(hnode, 0);
//currentNode = getTextCv().doMaybeSplit(hnode, 0);
}
}
return currentNode;
@ -278,10 +279,10 @@ public class DrawParser extends Parser {
Element currentNode = hnode;
if (converter.isTopLevel() && !fullscreenFrames.isEmpty()) {
bCollectFullscreenFrames = false;
currentNode = getTextCv().doMaybeSplit(hnode, 0);
// currentNode = getTextCv().doMaybeSplit(hnode, 0);
for (Element image : fullscreenFrames) {
handleDrawElement(image,currentNode,null,FULL_SCREEN);
currentNode = getTextCv().doMaybeSplit(hnode, 0);
// currentNode = getTextCv().doMaybeSplit(hnode, 0);
}
fullscreenFrames.clear();
bCollectFullscreenFrames = true;

View file

@ -43,7 +43,6 @@ class EndnoteParser extends NoteParser {
*/
void insertEndnotes(Node hnode, String section) {
if (hasNotes()) {
if (config.getXhtmlSplitLevel()>0) { hnode = converter.nextOutFile(); }
Element sectionElement = createNoteSection(hnode, "rearnotes");
insertNoteHeading(sectionElement, config.getEndnotesHeading(), "endnotes");
flushNotes(sectionElement,"rearnote",section);

View file

@ -35,7 +35,7 @@ public class Separator {
private static String pageSeparation = "sections";
private static Converter converter = null;
private XhtmlConfig config = null;
private Node prevPageNode = null;
private Node prevPageContainer = null;
private PageContainer pageContainer = null;
public Separator(XhtmlConfig config,Converter converter) {
@ -62,7 +62,7 @@ public class Separator {
}
int curLevel = Integer.parseInt(sLevel);
if (needSplitFiles(curLevel,pageNum)){
prevPageNode = hnode;
prevPageContainer = hnode;
}
if (pageOpened) {
@ -159,8 +159,8 @@ public class Separator {
System.out.println("Error: node is null on openPageDiv");
return node;
}
if (prevPageNode != null && splitByPages) {
arrangePageDivs(node,curPageNum);
if (prevPageContainer != null && splitByPages) {
alignFilesByHeadings(node,curPageNum);
}
breakPage(node,curPageNum);
Document doc = node.getOwnerDocument();
@ -199,23 +199,22 @@ public class Separator {
}
}
private void arrangePageDivs(Node node, int pageNum) {
private void alignFilesByHeadings(Node node, int pageNum) {
Document newdoc = node.getOwnerDocument();
String prevPageNum = getAttribute(prevPageNode, "page");
Node prevPage = prevPageContainer.getParentNode();
String prevPageNum = getAttribute(prevPage, "page");
if (prevPageNum != null && prevPageNum.equals(Integer.toString(pageNum))) {
if (isElement(prevPageNode, DIV)) {
Node importedNode = newdoc.importNode(prevPageNode, true);
if (isElement(prevPage, DIV)) {
Node importedNode = newdoc.importNode(prevPage, true);
node.appendChild(importedNode);
Node prevDocContent = prevPageNode.getParentNode();
if (prevDocContent != null) {
prevDocContent.removeChild(prevPageNode);
Node prevDoc = prevPage.getParentNode();
if (prevDoc != null) {
prevDoc.removeChild(prevPage);
}
}
}
//no more arrange needed till next file separation
prevPageNode = null;
prevPageContainer = null;
}

View file

@ -158,7 +158,6 @@ public class TextParser extends Parser {
*/
public void convertDocumentContent(Element onode) {
Element hnode = converter.nextOutFile();
// Create form
if (splitResultsLevel==0) {
Element form = getDrawCv().createForm();
@ -293,7 +292,6 @@ 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 = maybeSplit(hnode, style);
nCharacterCount+=OfficeReader.getCharacterCount(child);
// is there a block element, we should use?
XhtmlStyleMap xpar = config.getXParStyleMap();
@ -341,7 +339,6 @@ public class TextParser extends Parser {
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,TEXT_STYLE_NAME));
Node rememberNode = hnode;
hnode = processPageBreaks(child, hnode, style);
//hnode = maybeSplit(hnode,style,nOutlineLevel);
nCharacterCount+=OfficeReader.getCharacterCount(child);
handleHeading((Element)child,(Element)hnode,rememberNode!=hnode);
}
@ -385,7 +382,6 @@ public class TextParser extends Parser {
}
hnode = processPageBreaks(child, hnode,style);
inList = true;
//hnode = maybeSplit(hnode,null);
if (listIsOnlyHeadings(child)) {
nDontSplitLevel--;
hnode = handleFakeList(child,nLevel+1,styleName,hnode);
@ -399,7 +395,6 @@ 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 = maybeSplit(hnode,style);
inTable = true;
getTableCv().handleTable(child,hnode);
inTable = false;
@ -409,14 +404,12 @@ public class TextParser extends Parser {
}
else if (nodeName.equals(TEXT_SECTION)) {
hnode = processPageBreaks(child, hnode,null);
// hnode = maybeSplit(hnode,null);
nDontSplitLevel--;
hnode = handleSection(child,hnode);
nDontSplitLevel++;
}
else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) {
if (!ofr.getTocReader((Element)child).isByChapter()) {
// hnode = maybeSplit(hnode,null,1);
}
tocParser.handleIndex((Element)child,(Element)hnode);
}
@ -433,11 +426,9 @@ public class TextParser extends Parser {
// TODO
}
else if (nodeName.equals(TEXT_ALPHABETICAL_INDEX)) {
//hnode = maybeSplit(hnode,null,1);
indexCv.handleIndex((Element)child,(Element)hnode);
}
else if (nodeName.equals(TEXT_BIBLIOGRAPHY)) {
//hnode = maybeSplit(hnode,null,1);
bibCv.handleIndex((Element)child,(Element)hnode);
}
else if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)) {
@ -492,51 +483,7 @@ public class TextParser extends Parser {
return false;
}
private Node maybeSplit(Node node, StyleWithProperties style) {
return maybeSplit(node,style,-1);
}
private Node maybeSplit(Node node, StyleWithProperties style, int nLevel) {
if (bPendingPageBreak) {
return doMaybeSplit(node, 0);
}
if (getPageBreak(style)) {
return doMaybeSplit(node, 0);
}
if (converter.isOPS() && nSplitAfter>0 && nCharacterCount>nSplitAfter) {
return doMaybeSplit(node, 0);
}
if (nLevel>=0) {
return doMaybeSplit(node, nLevel);
}
else {
return node;
}
}
protected Element doMaybeSplit(Node node, int nLevel) {
if (nDontSplitLevel>1) { // we cannot split due to a nested structure
return (Element) node;
}
if (!converter.isOPS() && bAfterHeading && nLevel-nLastSplitLevel<=nRepeatLevels) {
// we cannot split because we are right after a heading and the
// maximum number of parent headings on the page is not reached
// TODO: Something wrong here....nLastSplitLevel is never set???
return (Element) node;
}
if (splitResultsLevel>=nLevel && converter.outFileHasContent()) {
// No objections, this is a level that causes splitting
nCharacterCount = 0;
bPendingPageBreak = false;
if (converter.getOutFileIndex()>=0) {
insertFootnotes(node,false);
}
return converter.nextOutFile();
}
return (Element) node;
}
/* Process a text:section tag (returns current html node) */
/* Process a text:section tag (returns current html node) */
private Node handleSection(Node onode, Node hnode) {
// Unlike headings, paragraphs and spans, text:display is not attached to the style:
String lastEndnotesContext = endnotesContext;