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