diff --git a/src/main/java/writer2latex/xhtml/PageSplitter.java b/src/main/java/writer2latex/xhtml/PageSplitter.java
index 7d3b375..0872eef 100644
--- a/src/main/java/writer2latex/xhtml/PageSplitter.java
+++ b/src/main/java/writer2latex/xhtml/PageSplitter.java
@@ -521,83 +521,37 @@ public class PageSplitter {
int i = 0;
NodeList сhilds = para.getChildNodes();
while (сhilds.getLength() > i) {
- Node сhild = сhilds.item(i);
+ Node child = сhilds.item(i);
//NOT TEXT NODES
- if ((сhild.getNodeType() == Node.ELEMENT_NODE)) {
- String childName = сhild.getNodeName();
+ if ((child.getNodeType() == Node.ELEMENT_NODE)) {
+ String childName = child.getNodeName();
//SPB FOUND
- if (containsSPB(сhild)){
+ if (containsSPB(child)){
if (childName.equals(TEXT_SOFT_PAGE_BREAK)){
- //Next node in paragraph. If it is text node go further
- Node paraNextNode = сhilds.item(i+1);
- Node paraPrevNode = paraBefore.getLastChild();
- String nextText = null;
- String prevText = null;
- if (paraNextNode != null && paraPrevNode != null ){
-
- if (paraNextNode.getNodeType() == Node.TEXT_NODE) {
- nextText = paraNextNode.getTextContent();
- } else if (paraNextNode.getNodeType() == Node.ELEMENT_NODE) {
- Node nextNodeFirstChild = paraNextNode.getFirstChild();
- if (nextNodeFirstChild != null && nextNodeFirstChild.getNodeType() == Node.TEXT_NODE) {
- nextText = nextNodeFirstChild.getTextContent();
- }
- }
- if (paraPrevNode.getNodeType() == Node.TEXT_NODE){
- prevText = paraPrevNode.getTextContent();
- } else if (paraPrevNode.getNodeType() == Node.ELEMENT_NODE) {
- Node prevNodeLastChild = paraPrevNode.getLastChild();
- if (prevNodeLastChild != null && prevNodeLastChild.getNodeType() == Node.TEXT_NODE) {
- prevText = prevNodeLastChild.getTextContent();
- }
- }
- //If previous and next texts exists
- if (nextText != null && prevText != null) {
- //If first character in next text is a letter
- //And if last character in previous text is a letter or soft hyphen
- if (Character.isLetter(nextText.charAt(0))
- && (Character.isLetter(prevText.charAt(prevText.length() - 1))
- || prevText.charAt(prevText.length() - 1) == 173)) {
- paraPrevNode.setTextContent(prevText + "\u2010");
- }
- }
- }
- // In case paragraph is empty add space to prevent it's removing
- if (paraNextNode == null && paraPrevNode == null){
- Document doc = para.getOwnerDocument();
- Node space = doc.createTextNode(" ");
- para.insertBefore(space, сhild);
- }
-
- // remove inner soft page break node
- para.removeChild(сhild);
-
- /* Check if next node in para is text and first char is a letter
- * Check if last node in paraFirstPart is text and last char is a letter
- * If both true - add
- */
+ //removeSPB
+ para.removeChild(child);
} else {
System.out.println("ERROR: SPB INSIDE Paragraph Element in inner element " + childName);
- //checkSoftPageBreak(internalNode, true);
- //paraFirstPart.appendChild(internalNode);
- //dataMoved = true;
+ System.exit(1);
}
break;
- //ELEMENT WITHOUT SPB
+ //Other elements
} else if (childName.equals(TEXT_BOOKMARK_START)){
- paraBefore.appendChild(сhild.cloneNode(true));
+ paraBefore.appendChild(child.cloneNode(true));
i++;
} else {
- paraBefore.appendChild(сhild);
- dataMoved = true;
+ dataMoved = appendChild(paraBefore, child);
}
//TEXT NODES
} else {
- paraBefore.appendChild(сhild);
- dataMoved = true;
+ dataMoved = appendChild(paraBefore, child);
}
}
+ addHyphen(para,paraBefore);
+
+
+
if (dataMoved) {
removeIndent(para);
return paraBefore;
@@ -606,6 +560,62 @@ public class PageSplitter {
return null;
}
+
+ private static boolean appendChild(Node parent, Node child) {
+ boolean dataMoved;
+ parent.appendChild(child);
+ dataMoved = true;
+ return dataMoved;
+ }
+
+ private static void addHyphen(Node para, Node paraBefore) {
+ //Debug.printNode(paraBefore);
+ //Debug.printNode(para);
+ Character softHyphen = 0x00ad;
+ Character lastChar = getLastChar(paraBefore);
+ Character firstChar = getFirstChar(para);
+
+ if (lastChar == null || firstChar == null) {
+ return;
+ }
+ Node lastNode = paraBefore;
+ while (lastNode.hasChildNodes()) {
+ lastNode = lastNode.getLastChild();
+ }
+ String lineEndsWith = lastNode.getTextContent();
+ if (Character.isLetter(lastChar) && Character.isLetter(firstChar)) {
+
+ lastNode.setTextContent(lastNode.getTextContent() + "\u2010");
+ } else if (lastChar.equals(softHyphen)) {
+ lastNode.setTextContent(lineEndsWith.substring(0, lineEndsWith.length()-1) + "\u2010");
+ }
+ }
+ private static Character getLastChar(Node para) {
+ if (para == null) { return null; }
+ Node lastNode = para;
+ while (lastNode.hasChildNodes()) {
+ lastNode = lastNode.getLastChild();
+ }
+ String content = lastNode.getTextContent();
+ if (content != null && !content.isEmpty()) {
+ return content.charAt(content.length()-1);
+ }
+ return null;
+ }
+
+ private static Character getFirstChar(Node para) {
+ if (para == null) { return null; }
+ Node firstNode = para;
+ while (firstNode.hasChildNodes()) {
+ firstNode = firstNode.getFirstChild();
+ }
+ String content = firstNode.getTextContent();
+ if (content != null && !content.isEmpty()) {
+ return content.charAt(0);
+ }
+ return null;
+ }
+
private static void removeIndent(Node paraAfter) {
String baseStyleName = Misc.getAttribute(paraAfter, TEXT_STYLE_NAME);
String newStyleName = officeReader.cloneParStyle(baseStyleName);