Image export improvements and bugfixes

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@177 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2014-09-24 18:15:35 +00:00
parent 2f5ab8c518
commit 0746282f26
8 changed files with 84 additions and 40 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.4 (2014-09-05)
* Version 1.4 (2014-09-24)
*
*/
@ -38,9 +38,9 @@
* export notes (part of draw-page)
* export list-style-image for image bullets!
*/
package writer2latex.xhtml;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
@ -54,8 +54,6 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
//import writer2latex.xmerge.EmbeddedBinaryObject;
import writer2latex.util.Misc;
import writer2latex.util.CSVList;
import writer2latex.util.SimpleXMLParser;
@ -101,7 +99,10 @@ public class DrawConverter extends ConverterHelper {
private int nImageSize;
private String sImageSplit;
private boolean bCoverImage;
private boolean bUseSVG;
private boolean bEmbedSVG;
// Embedded SVG images for recycling are collected here
private HashMap<String,Element> svgImages = new HashMap<String,Element>();
// Frames in spreadsheet documents are collected here
private Vector<Element> frames = new Vector<Element>();
@ -128,7 +129,7 @@ public class DrawConverter extends ConverterHelper {
nImageSize = config.imageSize();
sImageSplit = config.imageSplit();
bCoverImage = config.coverImage();
bUseSVG = config.inlineSVG();
bEmbedSVG = config.embedSVG();
}
///////////////////////////////////////////////////////////////////////
@ -486,26 +487,38 @@ public class DrawConverter extends ConverterHelper {
// Create the image (sFileName contains the file name)
Element imageElement = null;
if (converter.nType==XhtmlDocument.HTML5 && bUseSVG && bgd!=null && MIMETypes.SVG.equals(bgd.getMIMEType())) {
if (converter.nType==XhtmlDocument.HTML5 && bEmbedSVG && bgd!=null && MIMETypes.SVG.equals(bgd.getMIMEType())) {
// In HTML5 we may embed SVG images directly in the document
byte[] blob = bgd.getData();
try {
Document dom = SimpleXMLParser.parse(new ByteArrayInputStream(blob));
if (dom!=null) {
if (bgd.isRecycled()) {
// Get from the cache (actually we are certain it is there)
if (svgImages.containsKey(bgd.getFileName())) {
Element elm = hnodeInline!=null ? hnodeInline : hnodeBlock;
imageElement = (Element) elm.getOwnerDocument().importNode(dom.getDocumentElement(), true);
imageElement = (Element) elm.getOwnerDocument().importNode(svgImages.get(bgd.getFileName()), true);
}
}
else {
// Parse the data
byte[] blob = bgd.getData();
try {
Document dom = SimpleXMLParser.parse(new ByteArrayInputStream(blob));
if (dom!=null) {
Element elm = hnodeInline!=null ? hnodeInline : hnodeBlock;
imageElement = (Element) elm.getOwnerDocument().importNode(dom.getDocumentElement(), true);
// Store in cache in case we need to recycle
svgImages.put(bgd.getFileName(), imageElement);
}
else {
System.out.println("Failed to parse SVG");
}
} catch (IOException e) {
// Will not happen with a byte array
System.out.println("IOException parsing SVG");
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
System.out.println("SAXException parsing SVG");
}
else {
System.out.println("Failed to parse SVG");
}
} catch (IOException e) {
// Will not happen with a byte array
System.out.println("IOException parsing SVG");
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
System.out.println("SAXException parsing SVG");
}
}
}
else {
// In all other cases, create an img element

View file

@ -143,7 +143,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
private static final int SPLIT_AFTER = 40;
private static final int IMAGE_SPLIT = 41;
private static final int COVER_IMAGE = 42;
private static final int INLINE_SVG = 43;
private static final int EMBED_SVG = 43;
private static final int USE_MATHJAX = 44;
private static final int CALC_SPLIT = 45;
private static final int DISPLAY_HIDDEN_SHEETS = 46;
@ -273,7 +273,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
};
options[IMAGE_SPLIT] = new Option("image_split","none");
options[COVER_IMAGE] = new BooleanOption("cover_image","false");
options[INLINE_SVG] = new BooleanOption("inline_svg","true");
options[EMBED_SVG] = new BooleanOption("embed_svg","false");
options[USE_MATHJAX] = new BooleanOption("use_mathjax","false");
options[CALC_SPLIT] = new BooleanOption("calc_split","false");
options[DISPLAY_HIDDEN_SHEETS] = new BooleanOption("display_hidden_sheets", "false");
@ -399,7 +399,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public int splitAfter() { return ((IntegerOption) options[SPLIT_AFTER]).getValue(); }
public String imageSplit() { return options[IMAGE_SPLIT].getString(); }
public boolean coverImage() { return ((BooleanOption) options[COVER_IMAGE]).getValue(); }
public boolean inlineSVG() { return ((BooleanOption) options[INLINE_SVG]).getValue(); }
public boolean embedSVG() { return ((BooleanOption) options[EMBED_SVG]).getValue(); }
public boolean useMathJax() { return ((BooleanOption) options[USE_MATHJAX]).getValue(); }
public boolean xhtmlCalcSplit() { return ((BooleanOption) options[CALC_SPLIT]).getValue(); }
public boolean xhtmlDisplayHiddenSheets() { return ((BooleanOption) options[DISPLAY_HIDDEN_SHEETS]).getValue(); }