EPUB 3 preparations + embed HTML images as base 64
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@226 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
951bcc0f85
commit
53c84ca717
21 changed files with 209 additions and 61 deletions
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2014-08-25)
|
||||
* Version 1.6 (2015-01-09)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -54,7 +54,7 @@ import writer2latex.util.Misc;
|
|||
* <p>Where the available options are
|
||||
* <ul>
|
||||
* <li><code>-latex</code>, <code>-bibtex</code>, <code>-html5</code>, <code>-xhtml</code>,
|
||||
<code>-xhtml+mathml</code>, <code>-epub</code>
|
||||
<code>-xhtml+mathml</code>, <code>-epub</code>, <code>-epub3</code>
|
||||
* <li><code>-recurse</code>
|
||||
* <li><code>-ultraclean</code>, <code>-clean</code>, <code>-pdfscreen</code>,
|
||||
* <code>-pdfprint</code>, <code>-cleanxhtml</code>
|
||||
|
@ -330,6 +330,7 @@ public final class Application {
|
|||
System.out.println(" -xhtml+mathml");
|
||||
System.out.println(" -html5");
|
||||
System.out.println(" -epub");
|
||||
System.out.println(" -epub3");
|
||||
System.out.println(" -recurse");
|
||||
System.out.println(" -template[=]<template file>");
|
||||
System.out.println(" -stylesheet[=]<style sheet file>");
|
||||
|
@ -366,6 +367,7 @@ public final class Application {
|
|||
else if ("-xhtml11".equals(sArg)) { sTargetMIME = MIMETypes.XHTML11; }
|
||||
else if ("-xhtml+mathml".equals(sArg)) { sTargetMIME = MIMETypes.XHTML_MATHML; }
|
||||
else if ("-epub".equals(sArg)) { sTargetMIME = MIMETypes.EPUB; }
|
||||
else if ("-epub3".equals(sArg)) { sTargetMIME = MIMETypes.EPUB3; }
|
||||
else if ("-recurse".equals(sArg)) { bRecurse = true; }
|
||||
else if ("-ultraclean".equals(sArg)) { configFileNames.add("*ultraclean.xml"); }
|
||||
else if ("-clean".equals(sArg)) { configFileNames.add("*clean.xml"); }
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-11-09)
|
||||
* Version 1.6 (2015-01-14)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class ConverterFactory {
|
|||
|
||||
// Version information
|
||||
private static final String VERSION = "1.5.2";
|
||||
private static final String DATE = "2014-11-18";
|
||||
private static final String DATE = "2015-01-14";
|
||||
|
||||
/** Return the Writer2LaTeX version in the form
|
||||
* (major version).(minor version).(patch level)<br/>
|
||||
|
@ -63,7 +63,8 @@ public class ConverterFactory {
|
|||
* Note that this is <em>not</em> the recommended media type for HTML5
|
||||
* (see http://wiki.whatwg.org/), but it is used internally
|
||||
* by Writer2xhtml to distinguish from HTML5</li>
|
||||
* <li><code>application/epub+zip</code></li> for EPUB format
|
||||
* <li><code>application/epub+zip</code></li> for EPUB format</li>
|
||||
* <li><code>epub3</code> for EPUB 3 format</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param sMIME the MIME type of the target format
|
||||
|
@ -90,6 +91,9 @@ public class ConverterFactory {
|
|||
else if (MIMETypes.HTML5.equals(sMIME)) {
|
||||
converter = createInstance("writer2latex.xhtml.Html5Converter");
|
||||
}
|
||||
else if (MIMETypes.EPUB3.equals(sMIME)) {
|
||||
converter = createInstance("writer2latex.epub.EPUB3Converter");
|
||||
}
|
||||
else if (MIMETypes.EPUB.equals(sMIME)) {
|
||||
converter = createInstance("writer2latex.epub.EPUBConverter");
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2014-08-13)
|
||||
* Version 1.6 (2015-01-09)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -54,6 +54,8 @@ public class MIMETypes {
|
|||
/** This is a fake MIME type, for internal use only */
|
||||
public static final String HTML5="text/html5";
|
||||
public static final String EPUB="application/epub+zip";
|
||||
/** This is not a MIME type either */
|
||||
public static final String EPUB3="epub3";
|
||||
public static final String LATEX="application/x-latex";
|
||||
public static final String BIBTEX="application/x-bibtex";
|
||||
public static final String TEXT="text";
|
||||
|
|
65
source/java/writer2latex/epub/EPUB3Converter.java
Normal file
65
source/java/writer2latex/epub/EPUB3Converter.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* EPUB3Converter.java
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* version 1.6 (2015-01-15)
|
||||
*
|
||||
*/
|
||||
|
||||
package writer2latex.epub;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import writer2latex.api.ConverterResult;
|
||||
import writer2latex.base.ConverterResultImpl;
|
||||
import writer2latex.xhtml.Html5Converter;
|
||||
|
||||
|
||||
/** This class converts an OpenDocument file to an EPUB 3 document.
|
||||
*/
|
||||
public final class EPUB3Converter extends Html5Converter {
|
||||
|
||||
// Constructor
|
||||
public EPUB3Converter() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override public ConverterResult convert(InputStream is, String sTargetFileName) throws IOException {
|
||||
setOPS(true);
|
||||
ConverterResult xhtmlResult = super.convert(is, "chapter");
|
||||
return createPackage(xhtmlResult,sTargetFileName);
|
||||
}
|
||||
|
||||
@Override public ConverterResult convert(org.w3c.dom.Document dom, String sTargetFileName, boolean bDestructive) throws IOException {
|
||||
setOPS(true);
|
||||
ConverterResult xhtmlResult = super.convert(dom, "chapter", bDestructive);
|
||||
return createPackage(xhtmlResult,sTargetFileName);
|
||||
}
|
||||
|
||||
private ConverterResult createPackage(ConverterResult xhtmlResult, String sTargetFileName) {
|
||||
ConverterResultImpl epubResult = new ConverterResultImpl();
|
||||
epubResult.addDocument(new EPUBWriter(xhtmlResult,sTargetFileName,3,getXhtmlConfig()));
|
||||
epubResult.setMetaData(xhtmlResult.getMetaData());
|
||||
return epubResult;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2001-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* version 1.4 (2014-09-24)
|
||||
* version 1.6 (2015-01-15)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -57,7 +57,7 @@ public final class EPUBConverter extends Xhtml11Converter {
|
|||
|
||||
private ConverterResult createPackage(ConverterResult xhtmlResult, String sTargetFileName) {
|
||||
ConverterResultImpl epubResult = new ConverterResultImpl();
|
||||
epubResult.addDocument(new EPUBWriter(xhtmlResult,sTargetFileName,getXhtmlConfig()));
|
||||
epubResult.addDocument(new EPUBWriter(xhtmlResult,sTargetFileName,2,getXhtmlConfig()));
|
||||
epubResult.setMetaData(xhtmlResult.getMetaData());
|
||||
return epubResult;
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2001-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* version 1.4 (2014-09-07)
|
||||
* version 1.6 (2015-01-15)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -51,25 +51,34 @@ public class EPUBWriter implements OutputFile {
|
|||
private String sFileName;
|
||||
//private XhtmlConfig config;
|
||||
|
||||
public EPUBWriter(ConverterResult xhtmlResult, String sFileName, XhtmlConfig config) {
|
||||
/** Create a new <code>EPUBWriter</code> based on a <code>ConverterResult</code>.
|
||||
*
|
||||
* @param xhtmlResult the converter result to repackage
|
||||
* @param sFileName the file name to use for the result
|
||||
* @param nVersion the EPUB version number. Can be either 2 or 3, other values are interpreted as 2.
|
||||
* @param config the configuration to use
|
||||
*/
|
||||
public EPUBWriter(ConverterResult xhtmlResult, String sFileName, int nVersion, XhtmlConfig config) {
|
||||
this.xhtmlResult = xhtmlResult;
|
||||
this.sFileName = Misc.removeExtension(sFileName);
|
||||
//this.config = config;
|
||||
}
|
||||
|
||||
// Implement OutputFile
|
||||
|
||||
public String getFileName() {
|
||||
@Override public String getFileName() {
|
||||
return sFileName+".epub";
|
||||
}
|
||||
|
||||
public String getMIMEType() {
|
||||
@Override public String getMIMEType() {
|
||||
return "application/epub+zip";
|
||||
}
|
||||
|
||||
public boolean isMasterDocument() {
|
||||
@Override public boolean isMasterDocument() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void write(OutputStream os) throws IOException {
|
||||
@Override public void write(OutputStream os) throws IOException {
|
||||
ZipOutputStream zos = new ZipOutputStream(os);
|
||||
|
||||
// Write uncompressed MIME type as first entry
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2014-09-24)
|
||||
* Version 1.6 (2015-01-14)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -47,6 +47,8 @@ import java.util.Vector;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -100,6 +102,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
private String sImageSplit;
|
||||
private boolean bCoverImage;
|
||||
private boolean bEmbedSVG;
|
||||
private boolean bEmbedImg;
|
||||
|
||||
// Embedded SVG images for recycling are collected here
|
||||
private HashMap<String,Element> svgImages = new HashMap<String,Element>();
|
||||
|
@ -113,7 +116,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
private Vector<Element> fullscreenFrames = new Vector<Element>();
|
||||
// This flag determines whether to collect full screen images or insert them immediately
|
||||
private boolean bCollectFullscreenFrames = true;
|
||||
|
||||
|
||||
public DrawConverter(OfficeReader ofr, XhtmlConfig config, Converter converter) {
|
||||
super(ofr,config,converter);
|
||||
// We can only handle one form; pick an arbitrary one.
|
||||
|
@ -130,6 +133,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
sImageSplit = config.imageSplit();
|
||||
bCoverImage = config.coverImage();
|
||||
bEmbedSVG = config.embedSVG();
|
||||
bEmbedImg = config.embedImg();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -516,21 +520,28 @@ public class DrawConverter extends ConverterHelper {
|
|||
}
|
||||
}
|
||||
else {
|
||||
// In all other cases, create an img element
|
||||
if (bgd!=null && !bgd.isLinked() && !bgd.isRecycled()) { converter.addDocument(bgd); }
|
||||
// In all other cases, create an img element
|
||||
if (bgd!=null && !bgd.isLinked() && !bgd.isRecycled() && !bEmbedImg) { 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);
|
||||
|
||||
if (!bEmbedImg || bgd.isLinked()) {
|
||||
image.setAttribute("src",sFileName);
|
||||
}
|
||||
else {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("data:").append(bgd.getMIMEType()).append(";base64,")
|
||||
.append(DatatypeConverter.printBase64Binary(bgd.getData()));
|
||||
image.setAttribute("src", buf.toString());
|
||||
}
|
||||
// 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);
|
||||
desc = Misc.getChildByTagName(frame,XMLString.SVG_TITLE);
|
||||
}
|
||||
String sAltText = desc!=null ? Misc.getPCDATA(desc) : (sName!=null ? sName : sFileName);
|
||||
image.setAttribute("alt",sAltText);
|
||||
imageElement = image;
|
||||
imageElement = image;
|
||||
}
|
||||
|
||||
if (imageElement!=null) {
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-10-24)
|
||||
* Version 1.6 (2015-01-14)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -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
|
||||
|
@ -144,18 +144,19 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
private static final int IMAGE_SPLIT = 41;
|
||||
private static final int COVER_IMAGE = 42;
|
||||
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;
|
||||
private static final int DISPLAY_HIDDEN_ROWS_COLS = 47;
|
||||
private static final int DISPLAY_FILTERED_ROWS_COLS = 48;
|
||||
private static final int APPLY_PRINT_RANGES = 49;
|
||||
private static final int USE_TITLE_AS_HEADING = 50;
|
||||
private static final int USE_SHEET_NAMES_AS_HEADINGS = 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 EMBED_IMG = 44;
|
||||
private static final int USE_MATHJAX = 45;
|
||||
private static final int CALC_SPLIT = 46;
|
||||
private static final int DISPLAY_HIDDEN_SHEETS = 47;
|
||||
private static final int DISPLAY_HIDDEN_ROWS_COLS = 48;
|
||||
private static final int DISPLAY_FILTERED_ROWS_COLS = 49;
|
||||
private static final int APPLY_PRINT_RANGES = 50;
|
||||
private static final int USE_TITLE_AS_HEADING = 51;
|
||||
private static final int USE_SHEET_NAMES_AS_HEADINGS = 52;
|
||||
private static final int SAVE_IMAGES_IN_SUBDIR = 53;
|
||||
private static final int UPLINK = 54;
|
||||
private static final int DIRECTORY_ICON = 55;
|
||||
private static final int DOCUMENT_ICON = 56;
|
||||
|
||||
protected ComplexOption xheading = addComplexOption("heading-map");
|
||||
protected ComplexOption xpar = addComplexOption("paragraph-map");
|
||||
|
@ -274,6 +275,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[EMBED_SVG] = new BooleanOption("embed_svg","false");
|
||||
options[EMBED_IMG] = new BooleanOption("embed_img","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");
|
||||
|
@ -413,6 +415,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
public String imageSplit() { return options[IMAGE_SPLIT].getString(); }
|
||||
public boolean coverImage() { return ((BooleanOption) options[COVER_IMAGE]).getValue(); }
|
||||
public boolean embedSVG() { return ((BooleanOption) options[EMBED_SVG]).getValue(); }
|
||||
public boolean embedImg() { return ((BooleanOption) options[EMBED_IMG]).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(); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue