Code is working, but ugly.

This commit is contained in:
Georgy Litvinov 2020-01-09 18:36:59 +01:00
parent 525aa8de1d
commit c13cb3abce
6 changed files with 91 additions and 23 deletions

View file

@ -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();
}

View file

@ -29,7 +29,7 @@ import org.w3c.dom.Node;
import writer2latex.util.Misc;
/** <p> Abstract class representing a style in OOo </p> */
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; }

View file

@ -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

View file

@ -33,7 +33,7 @@ import java.util.Hashtable;
/** <p> Class representing a set of style properties in OOo (actually this
is simply the set of attributes of an element). </p>
*/
public class PropertySet {
public class PropertySet implements Cloneable {
private Hashtable<String, String> properties = new Hashtable<String, String>();
private String sName;
@ -41,6 +41,10 @@ public class PropertySet {
properties = new Hashtable<String, String>();
sName="";
}
public PropertySet(String name, Hashtable<String,String> properties ) {
this.properties = (Hashtable<String, String>) 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<nLen; i++){
Node attr = attrNodes.item(i);
properties.put(attr.getNodeName(),attr.getNodeValue());
// System.out.println(attr.getNodeName()+" " + attr.getNodeValue());
}
}
}

View file

@ -64,7 +64,23 @@ public class StyleWithProperties extends OfficeStyle {
properties[i] = new PropertySet();
}
}
public StyleWithProperties(PropertySet[] props) {
for (int i=0; i < props.length; i++) {
properties[i] = props[i].Clone();
}
}
public OfficeStyle Clone() {
StyleWithProperties clone = new StyleWithProperties(properties);
clone.loadFromStyle(this);
return clone;
}
public void setPropertiesFromStyle(StyleWithProperties baseStyle)
{
for (int i=0; i<COUNT; i++) {
properties[i] = new PropertySet();
}
}
public void loadStyleFromDOM(Node node) {
super.loadStyleFromDOM(node);
// read the properties of the style, if any
@ -150,6 +166,11 @@ public class StyleWithProperties extends OfficeStyle {
return null; // no value
}
protected void setProperty(int nIndex, String sName, String sValue) {
int nRealIndex = bIsOldProps ? OLDPROPS : nIndex;
properties[nRealIndex].setProperty(sName, sValue);
}
public String getTextProperty(String sName, boolean bInherit) {
return getProperty(TEXT,sName,bInherit);
}
@ -157,8 +178,12 @@ public class StyleWithProperties extends OfficeStyle {
public String getParProperty(String sName, boolean bInherit) {
return getProperty(PAR,sName,bInherit);
}
public void setParProperty(String sName, String sValue) {
setProperty(PAR,sName, sValue);
}
public String getSectionProperty(String sName, boolean bInherit) {
public String getSectionProperty(String sName, boolean bInherit) {
return getProperty(SECTION,sName,bInherit);
}