Experimental support for embedded SVG in HTML5
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@146 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
d1ef4d8f8c
commit
71bff7e653
13 changed files with 187 additions and 115 deletions
|
@ -20,12 +20,10 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2012-03-30)
|
||||
* Version 1.4 (2012-04-03)
|
||||
*
|
||||
*/
|
||||
|
||||
// TODO: When polyglot markup uses either a textarea or pre element, the text within the element does not begin with a newline.
|
||||
|
||||
package writer2latex.xhtml;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -51,11 +49,8 @@ import writer2latex.api.Config;
|
|||
import writer2latex.api.ContentEntry;
|
||||
import writer2latex.api.ConverterFactory;
|
||||
import writer2latex.api.OutputFile;
|
||||
//import writer2latex.api.ConverterResult;
|
||||
import writer2latex.base.ContentEntryImpl;
|
||||
import writer2latex.base.ConverterBase;
|
||||
//import writer2latex.latex.LaTeXDocumentPortion;
|
||||
//import writer2latex.latex.util.Context;
|
||||
import writer2latex.office.MIMETypes;
|
||||
import writer2latex.office.OfficeReader;
|
||||
import writer2latex.office.StyleWithProperties;
|
||||
|
@ -266,6 +261,10 @@ public class Converter extends ConverterBase {
|
|||
imageLoader.setDefaultFormat(MIMETypes.PNG);
|
||||
imageLoader.addAcceptedFormat(MIMETypes.JPEG);
|
||||
imageLoader.addAcceptedFormat(MIMETypes.GIF);
|
||||
|
||||
if (nType==XhtmlDocument.HTML5 && config.useSVG()) { // HTML supports (inline) SVG as well
|
||||
imageLoader.setDefaultVectorFormat(MIMETypes.SVG);
|
||||
}
|
||||
|
||||
styleCv = new StyleConverter(ofr,config,this,nType);
|
||||
textCv = new TextConverter(ofr,config,this);
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
* Copyright: 2002-2012 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2011-07-20)
|
||||
* Version 1.4 (2012-04-03)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -44,10 +44,12 @@ package writer2latex.xhtml;
|
|||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Element;
|
||||
|
@ -56,6 +58,7 @@ import org.w3c.dom.Element;
|
|||
|
||||
import writer2latex.util.Misc;
|
||||
import writer2latex.util.CSVList;
|
||||
import writer2latex.util.SimpleXMLParser;
|
||||
import writer2latex.xmerge.BinaryGraphicsDocument;
|
||||
import writer2latex.office.EmbeddedObject;
|
||||
import writer2latex.office.EmbeddedXMLObject;
|
||||
|
@ -98,6 +101,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
private int nImageSize;
|
||||
private String sImageSplit;
|
||||
private boolean bCoverImage;
|
||||
private boolean bUseSVG;
|
||||
|
||||
// Frames in spreadsheet documents are collected here
|
||||
private Vector<Element> frames = new Vector<Element>();
|
||||
|
@ -124,6 +128,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
nImageSize = config.imageSize();
|
||||
sImageSplit = config.imageSplit();
|
||||
bCoverImage = config.coverImage();
|
||||
bUseSVG = config.useSVG();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -451,6 +456,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
}
|
||||
|
||||
// Get the image from the ImageLoader
|
||||
BinaryGraphicsDocument bgd = null;
|
||||
String sFileName = null;
|
||||
String sHref = Misc.getAttribute(onode,XMLString.XLINK_HREF);
|
||||
if (sHref!=null && sHref.length()>0 && !ofr.isInPackage(sHref)) {
|
||||
|
@ -466,11 +472,10 @@ public class DrawConverter extends ConverterHelper {
|
|||
}
|
||||
}
|
||||
else { // embedded or base64 encoded image
|
||||
BinaryGraphicsDocument bgd = converter.getImageLoader().getImage(onode);
|
||||
bgd = converter.getImageLoader().getImage(onode);
|
||||
if (bgd!=null) {
|
||||
converter.addDocument(bgd);
|
||||
sFileName = bgd.getFileName();
|
||||
// If this is the cover image, add it to the converter result
|
||||
// If this is the cover image, add it to the converter result
|
||||
if (bCoverImage && onode==ofr.getFirstImage()) {
|
||||
converter.setCoverImageFile(bgd,null);
|
||||
}
|
||||
|
@ -480,30 +485,49 @@ public class DrawConverter extends ConverterHelper {
|
|||
if (sFileName==null) { return; } // TODO: Add warning?
|
||||
|
||||
// Create the image (sFileName contains the file name)
|
||||
Element image = converter.createElement("img");
|
||||
String sName = Misc.getAttribute(getFrame(onode),XMLString.DRAW_NAME);
|
||||
converter.addTarget(image,sName+"|graphic");
|
||||
image.setAttribute("src",sFileName);
|
||||
|
||||
// Add alternative text, using either alt.text, name or file name
|
||||
Element desc = Misc.getChildByTagName(frame,XMLString.SVG_DESC);
|
||||
if (desc==null) {
|
||||
desc = Misc.getChildByTagName(frame,XMLString.SVG_TITLE);
|
||||
Element imageElement = null;
|
||||
if (converter.nType==XhtmlDocument.HTML5 && bUseSVG && 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));
|
||||
Element elm = hnodeInline!=null ? hnodeInline : hnodeBlock;
|
||||
imageElement = (Element) elm.getOwnerDocument().importNode(dom.getDocumentElement(), true);
|
||||
} catch (IOException e) {
|
||||
// Will not happen with a byte array
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
String sAltText = desc!=null ? Misc.getPCDATA(desc) : (sName!=null ? sName : sFileName);
|
||||
image.setAttribute("alt",sAltText);
|
||||
else {
|
||||
// In all other cases, create an img element
|
||||
if (bgd!=null) { converter.addDocument(bgd); }
|
||||
Element image = converter.createElement("img");
|
||||
String sName = Misc.getAttribute(getFrame(onode),XMLString.DRAW_NAME);
|
||||
converter.addTarget(image,sName+"|graphic");
|
||||
image.setAttribute("src",sFileName);
|
||||
|
||||
// Add alternative text, using either alt.text, name or file name
|
||||
Element desc = Misc.getChildByTagName(frame,XMLString.SVG_DESC);
|
||||
if (desc==null) {
|
||||
desc = Misc.getChildByTagName(frame,XMLString.SVG_TITLE);
|
||||
}
|
||||
String sAltText = desc!=null ? Misc.getPCDATA(desc) : (sName!=null ? sName : sFileName);
|
||||
image.setAttribute("alt",sAltText);
|
||||
imageElement = image;
|
||||
}
|
||||
|
||||
// Now style it
|
||||
StyleInfo info = new StyleInfo();
|
||||
String sStyleName = Misc.getAttribute(frame, XMLString.DRAW_STYLE_NAME);
|
||||
if (nMode!=FULL_SCREEN) { getFrameSc().applyStyle(sStyleName,info); }
|
||||
applyImageSize(frame,info.props,nMode,false);
|
||||
|
||||
// Now style it
|
||||
StyleInfo info = new StyleInfo();
|
||||
String sStyleName = Misc.getAttribute(frame, XMLString.DRAW_STYLE_NAME);
|
||||
if (nMode!=FULL_SCREEN) { getFrameSc().applyStyle(sStyleName,info); }
|
||||
applyImageSize(frame,info.props,nMode,false);
|
||||
// Apply placement
|
||||
applyPlacement(frame, hnodeBlock, hnodeInline, nMode, imageElement, info);
|
||||
|
||||
// Apply placement
|
||||
applyPlacement(frame, hnodeBlock, hnodeInline, nMode, image, info);
|
||||
|
||||
applyStyle(info,image);
|
||||
addLink(onode,image);
|
||||
applyStyle(info,imageElement);
|
||||
addLink(onode,imageElement);
|
||||
}
|
||||
|
||||
private void handleDrawTextBox(Element onode, Element hnodeBlock, Element hnodeInline, int nMode) {
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
* Copyright: 2002-2012 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2011-06-16)
|
||||
* Version 1.4 (2012-04-03)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -41,7 +41,7 @@ import writer2latex.util.Misc;
|
|||
|
||||
public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
||||
// Implement configuration methods
|
||||
protected int getOptionCount() { return 56; }
|
||||
protected int getOptionCount() { return 57; }
|
||||
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
|
||||
|
||||
// Override setOption: To be backwards compatible, we must accept options
|
||||
|
@ -137,19 +137,20 @@ 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 CALC_SPLIT = 43;
|
||||
private static final int DISPLAY_HIDDEN_SHEETS = 44;
|
||||
private static final int DISPLAY_HIDDEN_ROWS_COLS = 45;
|
||||
private static final int DISPLAY_FILTERED_ROWS_COLS = 46;
|
||||
private static final int APPLY_PRINT_RANGES = 47;
|
||||
private static final int USE_TITLE_AS_HEADING = 48;
|
||||
private static final int USE_SHEET_NAMES_AS_HEADINGS = 49;
|
||||
private static final int XSLT_PATH = 50;
|
||||
private static final int SAVE_IMAGES_IN_SUBDIR = 51;
|
||||
private static final int UPLINK = 52;
|
||||
private static final int DIRECTORY_ICON = 53;
|
||||
private static final int DOCUMENT_ICON = 54;
|
||||
private static final int ZEN_HACK = 55; // temporary hack for ePub Zen Garden styles
|
||||
private static final int USE_SVG = 43;
|
||||
private static final int CALC_SPLIT = 44;
|
||||
private static final int DISPLAY_HIDDEN_SHEETS = 45;
|
||||
private static final int DISPLAY_HIDDEN_ROWS_COLS = 46;
|
||||
private static final int DISPLAY_FILTERED_ROWS_COLS = 47;
|
||||
private static final int APPLY_PRINT_RANGES = 48;
|
||||
private static final int USE_TITLE_AS_HEADING = 49;
|
||||
private static final int USE_SHEET_NAMES_AS_HEADINGS = 50;
|
||||
private static final int XSLT_PATH = 51;
|
||||
private static final int SAVE_IMAGES_IN_SUBDIR = 52;
|
||||
private static final int UPLINK = 53;
|
||||
private static final int DIRECTORY_ICON = 54;
|
||||
private static final int DOCUMENT_ICON = 55;
|
||||
private static final int ZEN_HACK = 56; // temporary hack for ePub Zen Garden styles
|
||||
|
||||
protected ComplexOption xheading = addComplexOption("heading-map");
|
||||
protected ComplexOption xpar = addComplexOption("paragraph-map");
|
||||
|
@ -260,6 +261,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[USE_SVG] = new BooleanOption("use_svg","false");
|
||||
options[CALC_SPLIT] = new BooleanOption("calc_split","false");
|
||||
options[DISPLAY_HIDDEN_SHEETS] = new BooleanOption("display_hidden_sheets", "false");
|
||||
options[DISPLAY_HIDDEN_ROWS_COLS] = new BooleanOption("display_hidden_rows_cols","false");
|
||||
|
@ -386,6 +388,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 useSVG() { return ((BooleanOption) options[USE_SVG]).getValue(); }
|
||||
public boolean xhtmlCalcSplit() { return ((BooleanOption) options[CALC_SPLIT]).getValue(); }
|
||||
public boolean xhtmlDisplayHiddenSheets() { return ((BooleanOption) options[DISPLAY_HIDDEN_SHEETS]).getValue(); }
|
||||
public boolean displayHiddenRowsCols() { return ((BooleanOption) options[DISPLAY_HIDDEN_ROWS_COLS]).getValue(); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue