Added font-size to math formulas
This commit is contained in:
parent
e31e013789
commit
54cda34c82
4 changed files with 87 additions and 3 deletions
|
@ -43,11 +43,12 @@ public class EmbeddedXMLObject extends EmbeddedObject {
|
|||
// Byte entries for the XML streams of this object
|
||||
private byte[] contentBytes = null;
|
||||
private byte[] stylesBytes = null;
|
||||
private byte[] settingsBytes = null;
|
||||
|
||||
// DOM trees representing the XML parts of this object
|
||||
protected Document contentDOM = null;
|
||||
protected Document stylesDOM = null;
|
||||
|
||||
protected Document settingsDOM = null;
|
||||
/** Read an object from an ODF package document
|
||||
*
|
||||
* @param sName The name of the object.
|
||||
|
@ -59,6 +60,8 @@ public class EmbeddedXMLObject extends EmbeddedObject {
|
|||
// Read the bytes, but defer parsing until required (at that point, the bytes are nullified)
|
||||
contentBytes = source.getEntry(sName+"/"+OfficeDocument.CONTENTXML);
|
||||
stylesBytes = source.getEntry(sName+"/"+OfficeDocument.STYLESXML);
|
||||
settingsBytes = source.getEntry(sName+"/"+OfficeDocument.SETTINGSXML);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,6 +95,23 @@ public class EmbeddedXMLObject extends EmbeddedObject {
|
|||
}
|
||||
return stylesDOM;
|
||||
}
|
||||
public Document getSettingsDOM() {
|
||||
if (settingsDOM == null) {
|
||||
try {
|
||||
settingsDOM = getDOM(settingsBytes);
|
||||
} catch (SAXException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
settingsDOM = null;
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
settingsDOM = null;
|
||||
}
|
||||
settingsBytes = null;
|
||||
}
|
||||
return settingsDOM;
|
||||
}
|
||||
|
||||
private Document getDOM(byte[] data) throws SAXException, IOException {
|
||||
if (data!=null) {
|
||||
|
|
|
@ -51,6 +51,7 @@ public class OfficeDocument {
|
|||
// File names for the XML streams in a package document (settings.xml is ignored)
|
||||
protected final static String CONTENTXML = "content.xml";
|
||||
protected final static String STYLESXML = "styles.xml";
|
||||
protected final static String SETTINGSXML = "settings.xml";
|
||||
private final static String METAXML = "meta.xml";
|
||||
private final static String MANIFESTXML = "META-INF/manifest.xml";
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.w3c.dom.Document;
|
|||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
|
||||
import writer2latex.util.Calc;
|
||||
import writer2latex.util.Misc;
|
||||
|
@ -339,6 +340,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
// First check for TexMaths equation
|
||||
if (!getMathCv().convertTexMathsEquation(onode, hnodeBlock, hnodeInline, nMode)) {
|
||||
// OpenDocument embeds the draw element in a frame element
|
||||
|
||||
handleDrawElement(Misc.getFirstChildElement(onode),hnodeBlock,hnodeInline,nMode);
|
||||
}
|
||||
}
|
||||
|
@ -369,6 +371,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
boolean bNoTextPar = OfficeReader.isNoTextPar(OfficeReader.getParagraph(onode));
|
||||
|
||||
String sHref = Misc.getAttribute(onode, XMLString.XLINK_HREF);
|
||||
String fontSize = null;
|
||||
if (sHref!=null) { // Embedded object in package or linked object
|
||||
if (ofr.isInPackage(sHref)) { // Embedded object in package
|
||||
if (sHref.startsWith("#")) { sHref=sHref.substring(1); }
|
||||
|
@ -376,7 +379,9 @@ public class DrawConverter extends ConverterHelper {
|
|||
EmbeddedObject object = converter.getEmbeddedObject(sHref);
|
||||
if (MIMETypes.MATH.equals(object.getType()) || MIMETypes.ODF.equals(object.getType())) { // Formula!
|
||||
EmbeddedXMLObject xmlObject = (EmbeddedXMLObject) object;
|
||||
// Document settings = object.getSettingsDOM();
|
||||
Document objectSettings = xmlObject.getSettingsDOM();
|
||||
fontSize = getFontSize(objectSettings);
|
||||
|
||||
Element replacementImage = null;
|
||||
if (ofr.isOpenDocument()) { // look for replacement image
|
||||
replacementImage = Misc.getChildByTagName(getFrame(onode),XMLString.DRAW_IMAGE);
|
||||
|
@ -384,6 +389,18 @@ public class DrawConverter extends ConverterHelper {
|
|||
try {
|
||||
hnode.appendChild(converter.createTextNode(" "));
|
||||
getMathCv().convert(replacementImage,xmlObject.getContentDOM().getDocumentElement(),hnode,bNoTextPar);
|
||||
|
||||
Node convertedMath = hnode.getLastChild();
|
||||
if (fontSize != null) {
|
||||
if (convertedMath != null && convertedMath.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element elementWithFont = (Element) convertedMath;
|
||||
String styleAttr = elementWithFont.getAttribute("style");
|
||||
if (styleAttr == null) { styleAttr = "";}
|
||||
String fontValue = getStyleCv().getTextSc().scale(fontSize+"pt");
|
||||
elementWithFont.setAttribute("style", "font-size:"+ fontValue);
|
||||
}
|
||||
}
|
||||
|
||||
hnode.appendChild(converter.createTextNode(" "));
|
||||
}
|
||||
catch (SAXException e) {
|
||||
|
@ -441,6 +458,52 @@ public class DrawConverter extends ConverterHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private String getFontSize(Document objectSettings) {
|
||||
if (objectSettings == null) {
|
||||
return null;
|
||||
}
|
||||
String fontHeight = null;
|
||||
Node docSettings = objectSettings.getLastChild();
|
||||
String nodeName = docSettings.getNodeName();
|
||||
if (nodeName != null && nodeName.equals("office:document-settings")) {
|
||||
Node officeSettings = docSettings.getFirstChild();
|
||||
if (officeSettings == null) {
|
||||
return null;
|
||||
}
|
||||
nodeName = officeSettings.getNodeName();
|
||||
if (nodeName != null && nodeName.equals("office:settings")) {
|
||||
NodeList itemSets = officeSettings.getChildNodes();
|
||||
for (int i = 0; i < itemSets.getLength(); i++) {
|
||||
Node settingsNodes = itemSets.item(i);
|
||||
NamedNodeMap attrs = settingsNodes.getAttributes();
|
||||
if (attrs != null) {
|
||||
Node attr = attrs.getNamedItem("config:name");
|
||||
if (attr != null) {
|
||||
String attrText = attr.getTextContent();
|
||||
if (attrText.equals("ooo:configuration-settings")) {
|
||||
NodeList configItems = settingsNodes.getChildNodes();
|
||||
for (int j = 0; j < itemSets.getLength(); j++) {
|
||||
Node configItem = configItems.item(j);
|
||||
NamedNodeMap itemAttrs = configItem.getAttributes();
|
||||
Node itemAttr = itemAttrs.getNamedItem("config:name");
|
||||
if (itemAttr != null) {
|
||||
String attrName = itemAttr.getTextContent();
|
||||
if (attrName != null && attrName.equals("BaseFontHeight")) {
|
||||
fontHeight = configItem.getTextContent();
|
||||
return fontHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleDrawImage(Element onode, Element hnodeBlock, Element hnodeInline, int nMode) {
|
||||
Element frame = getFrame(onode);
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public class TextStyleConverter extends StyleWithPropertiesConverterHelper {
|
|||
private Hashtable<String, String> orgAnchorVisitedStyleNames = new Hashtable<String, String>();
|
||||
|
||||
// Export font sizes as percentages?
|
||||
private boolean bRelativeFontSize = false;
|
||||
protected boolean bRelativeFontSize = false;
|
||||
private String sFontScaling = "100%";
|
||||
private String sBaseFontSize = "12pt";
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue