From 06338087e7c8926e2c430bdf8fd56d8fa02f25f9 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Fri, 17 Jan 2020 15:15:35 +0100 Subject: [PATCH] refactored a bit --- .../writer2latex/xhtml/DrawConverter.java | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/java/writer2latex/xhtml/DrawConverter.java b/src/main/java/writer2latex/xhtml/DrawConverter.java index 6a0733c..e6d33ad 100644 --- a/src/main/java/writer2latex/xhtml/DrawConverter.java +++ b/src/main/java/writer2latex/xhtml/DrawConverter.java @@ -371,6 +371,7 @@ public class DrawConverter extends ConverterHelper { boolean bNoTextPar = OfficeReader.isNoTextPar(OfficeReader.getParagraph(onode)); String sHref = Misc.getAttribute(onode, XMLString.XLINK_HREF); + HashMap settings = null; String fontSize = null; if (sHref!=null) { // Embedded object in package or linked object if (ofr.isInPackage(sHref)) { // Embedded object in package @@ -380,8 +381,7 @@ public class DrawConverter extends ConverterHelper { if (MIMETypes.MATH.equals(object.getType()) || MIMETypes.ODF.equals(object.getType())) { // Formula! EmbeddedXMLObject xmlObject = (EmbeddedXMLObject) object; Document objectSettings = xmlObject.getSettingsDOM(); - fontSize = getFontSize(objectSettings); - + settings = parseSettings(objectSettings); Element replacementImage = null; if (ofr.isOpenDocument()) { // look for replacement image replacementImage = Misc.getChildByTagName(getFrame(onode),XMLString.DRAW_IMAGE); @@ -391,15 +391,7 @@ public class DrawConverter extends ConverterHelper { 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); - } - } + applySettings(settings, convertedMath); hnode.appendChild(converter.createTextNode(" ")); } @@ -457,18 +449,33 @@ public class DrawConverter extends ConverterHelper { } } } + + private void applySettings(HashMap settings, Node convertedMath) { + String fontSize; + fontSize = settings.get("BaseFontHeight"); + 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); + } + } + } - private String getFontSize(Document objectSettings) { + private HashMap parseSettings(Document objectSettings) { + HashMap settings = new HashMap(); if (objectSettings == null) { - return null; + return settings; } - String fontHeight = null; + String attrValue = 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; + return settings; } nodeName = officeSettings.getNodeName(); if (nodeName != null && nodeName.equals("office:settings")) { @@ -488,9 +495,10 @@ public class DrawConverter extends ConverterHelper { Node itemAttr = itemAttrs.getNamedItem("config:name"); if (itemAttr != null) { String attrName = itemAttr.getTextContent(); - if (attrName != null && attrName.equals("BaseFontHeight")) { - fontHeight = configItem.getTextContent(); - return fontHeight; + if (attrName != null) { + attrValue = configItem.getTextContent(); + settings.put(attrName, attrValue); + return settings; } } } @@ -501,7 +509,7 @@ public class DrawConverter extends ConverterHelper { } } - return null; + return settings; } private void handleDrawImage(Element onode, Element hnodeBlock, Element hnodeInline, int nMode) {