Refacoted paragraph splitting

This commit is contained in:
Georgy Litvinov 2020-07-24 14:59:41 +02:00
parent 50050c7de2
commit ca2b91cb4a

View file

@ -37,9 +37,8 @@ public class ODFPageSplitter {
StyleWithProperties style = null; StyleWithProperties style = null;
if ((nodeName.equals(TEXT_P) || nodeName.equals(TEXT_H))) { if ((nodeName.equals(TEXT_P) || nodeName.equals(TEXT_H))) {
//If SPB not the first node //If SPB not the first node
Node paraFirstPart = handleParagraph(child);
if (paraFirstPart != null){ if (handleParagraph(child)){
onode.insertBefore(paraFirstPart, child);
style = ofr.getParStyle(Misc.getAttribute(child, TEXT_STYLE_NAME)); style = ofr.getParStyle(Misc.getAttribute(child, TEXT_STYLE_NAME));
} }
} else if (nodeName.equals(TABLE_TABLE)) { } else if (nodeName.equals(TABLE_TABLE)) {
@ -149,9 +148,8 @@ public class ODFPageSplitter {
} else { } else {
String childName = child.getNodeName(); String childName = child.getNodeName();
if (childName.equals(TEXT_P)) { if (childName.equals(TEXT_P)) {
Node paraFirstPart = handleParagraph(child); if (handleParagraph(child)) {
if (paraFirstPart != null) { indexBodyFirstPart.appendChild(child.getPreviousSibling());
indexBodyFirstPart.appendChild(paraFirstPart);
} }
return indexBodyFirstPart; return indexBodyFirstPart;
} else } else
@ -239,7 +237,6 @@ public class ODFPageSplitter {
//Node name //Node name
String nodeName = listItemChild.getNodeName(); String nodeName = listItemChild.getNodeName();
if (containsSPB(listItemChild)){ if (containsSPB(listItemChild)){
Node listItemChildFirstPart = listItemChild.cloneNode(false);
//Break if SPB //Break if SPB
if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)) { if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)) {
//Remove SPB.Return result //Remove SPB.Return result
@ -250,9 +247,8 @@ public class ODFPageSplitter {
} }
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) { } else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
Node paraFirstPart = handleParagraph(listItemChild); if (handleParagraph(listItemChild)){
if (paraFirstPart != null){ listItemFirstPart.appendChild(listItemChild.getPreviousSibling());
listItemFirstPart.appendChild(paraFirstPart);
dataMoved=true; dataMoved=true;
} }
} }
@ -516,16 +512,14 @@ public class ODFPageSplitter {
if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){ if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){
// remove inner soft page break node // remove inner soft page break node
cellNode.removeChild(cellChildNode); cellNode.removeChild(cellChildNode);
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) { } else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
Node paraFirstPart = handleParagraph(cellChildNode); if (handleParagraph(cellChildNode)){
if (paraFirstPart != null){ cellFirstPart.appendChild(cellChildNode.getPreviousSibling());
cellFirstPart.appendChild(paraFirstPart);
dataMoved=true; dataMoved=true;
} }
} else if (nodeName.equals(TEXT_LIST)) { } else if (nodeName.equals(TEXT_LIST)) {
Node listFirstPart = cellChildNode.cloneNode(false);
if (handleList(cellChildNode)){ if (handleList(cellChildNode)){
cellFirstPart.appendChild(cellChildNode.getPreviousSibling());
dataMoved=true; dataMoved=true;
} }
} }
@ -557,15 +551,12 @@ public class ODFPageSplitter {
if ((child.getNodeType() == Node.ELEMENT_NODE)) { if ((child.getNodeType() == Node.ELEMENT_NODE)) {
String nodeName = child.getNodeName(); String nodeName = child.getNodeName();
if (containsSPB(child)){ if (containsSPB(child)){
Node childFirstPart = child.cloneNode(false);
if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){ if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){
// remove inner soft page break node // remove inner soft page break node
section.removeChild(child); section.removeChild(child);
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) { } else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
Node paraFirstPart = handleParagraph(child); if (handleParagraph(child)){
if (paraFirstPart != null){ sectionFirstPart.appendChild(child.getPreviousSibling());
sectionFirstPart.appendChild(paraFirstPart);
dataMoved=true; dataMoved=true;
} }
} else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) { } else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) {
@ -620,7 +611,8 @@ public class ODFPageSplitter {
Element sectionEl = (Element) section; Element sectionEl = (Element) section;
sectionEl.setAttribute("last", "true"); sectionEl.setAttribute("last", "true");
} }
private static Node handleParagraph(Node para) { private static boolean handleParagraph(Node para) {
Node parent = para.getParentNode();
//System.out.println("handlePara"); //System.out.println("handlePara");
Node paraFirstPart = para.cloneNode(false); Node paraFirstPart = para.cloneNode(false);
boolean dataMoved = false; boolean dataMoved = false;
@ -668,15 +660,12 @@ public class ODFPageSplitter {
} }
addHyphen(para,paraFirstPart); addHyphen(para,paraFirstPart);
if (dataMoved) { if (dataMoved) {
removeIndent(para); removeIndent(para);
return paraFirstPart; parent.insertBefore(paraFirstPart, para);
} }
return dataMoved;
return null;
} }
private static void handleSpan(Node span) { private static void handleSpan(Node span) {