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