Removed list splitting hack.

This commit is contained in:
Georgy Litvinov 2020-07-24 20:27:36 +02:00
parent 457caad4fc
commit 6d14ebecaa

View file

@ -13,7 +13,7 @@ import w2phtml.office.StyleWithProperties;
import w2phtml.util.Misc;
public class ODFPageSplitter {
static Node truncatedListItemNodeContent = null;
//static Node truncatedListItemNodeContent = null;
static OfficeReader officeReader = null;
public static void splitOfficeText(Node onode, OfficeReader ofr) {
@ -75,16 +75,9 @@ public class ODFPageSplitter {
}
if (style == null || !"page".equals(style.getProperty(FO_BREAK_BEFORE))){
onode.insertBefore(softPageBreak.cloneNode(false), child);
}
//HACK!
if (truncatedListItemNodeContent != null){
NodeList itemNodeList= truncatedListItemNodeContent.getChildNodes();
while (itemNodeList.getLength() > 0){
onode.insertBefore(itemNodeList.item(0), child);
if (!nodeName.equals(TEXT_LIST)) {
onode.insertBefore(softPageBreak.cloneNode(false), child);
}
truncatedListItemNodeContent.getParentNode().removeChild(truncatedListItemNodeContent);
truncatedListItemNodeContent = null;
}
if (!child.hasChildNodes()){
onode.removeChild(child);
@ -179,6 +172,9 @@ public class ODFPageSplitter {
Node parent = list.getParentNode();
Node listFirstPart = list.cloneNode(false);
NodeList listNodes = list.getChildNodes();
Document document = list.getOwnerDocument();
Element softPageBreak = document.createElement(TEXT_SOFT_PAGE_BREAK);
Node hangingItem = null;
int i = 0;
boolean dataMoved = false;
while (listNodes.getLength() > i) {
@ -195,8 +191,6 @@ public class ODFPageSplitter {
listFirstPart.appendChild(child.cloneNode(true));
//Get next element
i++;
} else if (nodeName.equals(TEXT_LIST_ITEM)) {
if (containsSPB(child)){
@ -205,13 +199,9 @@ public class ODFPageSplitter {
dataMoved = true;
//Add first part of list item to previous list item
listFirstPart.appendChild(child.getPreviousSibling());
//Get list parent node and move cutted node
//After First Part and SPB but before this list;
//TODO!!!!!!!!!!
truncatedListItemNodeContent = child;
listFirstPart.getParentNode();
//If List item is empty - remove it
if (!child.hasChildNodes()){
if (child.hasChildNodes()){
hangingItem = child;
} else {
list.removeChild(child);
}
}
@ -224,18 +214,26 @@ public class ODFPageSplitter {
// Not with SPB yet, move node, set dataMoved=true
listFirstPart.appendChild(child);
dataMoved = true;
}
} else {
System.out.println("Error. SPB in List child node " + nodeName);
System.exit(1);
}
}
}
if (dataMoved) {
parent.insertBefore(listFirstPart, list);
parent.insertBefore(softPageBreak, list);
if (hangingItem != null) {
i = 0;
NodeList freeNodes = hangingItem.getChildNodes();
while (freeNodes.getLength() > 0 ) {
Node freeNode = freeNodes.item(i);
parent.insertBefore(freeNode, list);
}
list.removeChild(hangingItem);
}
}
return dataMoved;
@ -267,10 +265,10 @@ public class ODFPageSplitter {
if (handleParagraph(listItemChild)){
listItemFirstPart.appendChild(listItemChild.getPreviousSibling());
dataMoved=true;
} else {
System.out.println("Error. SPB in List item child node " + nodeName);
System.exit(1);
}
}
} else {
System.out.println("Error. SPB in List item child node " + nodeName);
System.exit(1);
}
break;
//Move to first part