diff --git a/src/main/java/writer2latex/office/OfficeReader.java b/src/main/java/writer2latex/office/OfficeReader.java index 9e73f8c..e8eca2c 100644 --- a/src/main/java/writer2latex/office/OfficeReader.java +++ b/src/main/java/writer2latex/office/OfficeReader.java @@ -432,6 +432,9 @@ public class OfficeReader { public StyleWithProperties getParStyle(String sName) { return (StyleWithProperties) par.getStyle(sName); } + public String cloneParStyle(String sName) { + return par.cloneStyle(sName); + } public StyleWithProperties getDefaultParStyle() { return (StyleWithProperties) par.getDefaultStyle(); } diff --git a/src/main/java/writer2latex/office/OfficeStyle.java b/src/main/java/writer2latex/office/OfficeStyle.java index 0203fe1..c059c11 100644 --- a/src/main/java/writer2latex/office/OfficeStyle.java +++ b/src/main/java/writer2latex/office/OfficeStyle.java @@ -29,7 +29,7 @@ import org.w3c.dom.Node; import writer2latex.util.Misc; /**

Abstract class representing a style in OOo

*/ -public abstract class OfficeStyle { +public abstract class OfficeStyle implements Cloneable { // These attributes are defined by OfficeStyleFamily upon collection of styles protected String sName; protected OfficeStyleFamily family; @@ -53,6 +53,18 @@ public abstract class OfficeStyle { public OfficeStyle getParentStyle() { return family.getStyle(sParentName); } + + public OfficeStyle Clone() { return null; } + + public void loadFromStyle(OfficeStyle original) { + sDisplayName = original.getDisplayName() + "-clone"; + sName = original.getName() + "-clone"; + family = original.family; + bAutomatic = original.isAutomatic(); + sParentName = original.getParentName(); + sListStyleName = original.getListStyleName(); + sMasterPageName = original.getMasterPageName(); + } public String getListStyleName() { return sListStyleName; } diff --git a/src/main/java/writer2latex/office/OfficeStyleFamily.java b/src/main/java/writer2latex/office/OfficeStyleFamily.java index f1ec0c9..18b132d 100644 --- a/src/main/java/writer2latex/office/OfficeStyleFamily.java +++ b/src/main/java/writer2latex/office/OfficeStyleFamily.java @@ -71,6 +71,14 @@ public class OfficeStyleFamily { if (sName==null) { return null; } else { return styles.get(sName); } } + public String cloneStyle(String sName) { + OfficeStyle origStyle = styles.get(sName); + OfficeStyle newStyle = origStyle.Clone(); + String newName = sName+"-clone"; + styles.put(sName+"-clone", newStyle); + displayNames.put(newStyle.getDisplayName(), newStyle.getName()); + return newName; + } /** Get a style by display name. Automatic styles does not have a display * name, so only common styles can be retrieved with this method diff --git a/src/main/java/writer2latex/office/PropertySet.java b/src/main/java/writer2latex/office/PropertySet.java index f8ffa2f..062d15e 100644 --- a/src/main/java/writer2latex/office/PropertySet.java +++ b/src/main/java/writer2latex/office/PropertySet.java @@ -33,7 +33,7 @@ import java.util.Hashtable; /**

Class representing a set of style properties in OOo (actually this is simply the set of attributes of an element).

*/ -public class PropertySet { +public class PropertySet implements Cloneable { private Hashtable properties = new Hashtable(); private String sName; @@ -41,6 +41,10 @@ public class PropertySet { properties = new Hashtable(); sName=""; } + public PropertySet(String name, Hashtable properties ) { + this.properties = (Hashtable) properties.clone(); + sName = new String(name); + } public String getProperty(String sPropName) { if (sPropName!=null) { @@ -57,6 +61,10 @@ public class PropertySet { return null; } } + + public PropertySet Clone() { + return new PropertySet(sName, properties); + } public String getName() { return sName; } @@ -70,6 +78,7 @@ public class PropertySet { for (int i=0; i i) { Node paraChildNode = paraChildNodes.item(i); //NOT TEXT NODES if ((paraChildNode.getNodeType() == Node.ELEMENT_NODE)) { String nodeName = paraChildNode.getNodeName(); - //System.out.println(nodeName); //SPB FOUND if (containsSPB(paraChildNode)){ if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){ - - - //Next node in paragraph. If it is text node go further Node paraNextNode = paraChildNodes.item(i+1); - Node paraPrevNode = paraFirstPart.getLastChild(); + Node paraPrevNode = paraBefore.getLastChild(); String nextText = null; String prevText = null; if (paraNextNode != null && paraPrevNode != null ){ @@ -576,13 +573,13 @@ public class PageSplitter { } // In case paragraph is empty add space to prevent it's removing if (paraNextNode == null && paraPrevNode == null){ - Document doc = paraNode.getOwnerDocument(); + Document doc = paraAfter.getOwnerDocument(); Node space = doc.createTextNode(" "); - paraNode.insertBefore(space, paraChildNode); + paraAfter.insertBefore(space, paraChildNode); } // remove inner soft page break node - paraNode.removeChild(paraChildNode); + paraAfter.removeChild(paraChildNode); /* 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 @@ -597,19 +594,33 @@ public class PageSplitter { break; //ELEMENT WITHOUT SPB } else if (nodeName.equals(XMLString.TEXT_BOOKMARK_START)){ - paraFirstPart.appendChild(paraChildNode.cloneNode(true)); + paraBefore.appendChild(paraChildNode.cloneNode(true)); i++; } else { - paraFirstPart.appendChild(paraChildNode); + paraBefore.appendChild(paraChildNode); dataMoved = true; } //TEXT NODES } else { - paraFirstPart.appendChild(paraChildNode); + paraBefore.appendChild(paraChildNode); dataMoved = true; } } + //StyleWithProperties style = officeReader.getParStyle(Misc.getAttribute(paraAfter, XMLString.TEXT_STYLE_NAME)); + String newStyleName = officeReader.cloneParStyle(Misc.getAttribute(paraAfter, XMLString.TEXT_STYLE_NAME)); + + Node styleAttr = paraAfter.getAttributes().getNamedItem(XMLString.TEXT_STYLE_NAME); + styleAttr.setTextContent(newStyleName); + StyleWithProperties newStyle = officeReader.getParStyle(Misc.getAttribute(paraAfter, XMLString.TEXT_STYLE_NAME)); + //String propVal = style.getParProperty(XMLString.FO_TEXT_INDENT, true); + //System.out.println(propVal); + newStyle.setParProperty(XMLString.FO_TEXT_INDENT, "0"); + //propVal = newStyle.getParProperty(XMLString.FO_TEXT_INDENT, true); + //System.out.println(propVal); + + + //System.out.println(Misc.getAttribute(paraAfter, XMLString.TEXT_STYLE_NAME)); return dataMoved; } // Returns true if soft-page-break found. Removes it if removeFound = true