diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index f9200c4..899d499 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -4,6 +4,9 @@ Changelog for Writer2LaTeX version 1.4 -> 1.6 Items marked with * are work in progress +[all] API change: The interface OutputFile now defines an additional method containsMath() which returns true if the file + contains mathematical formulas (only implemented for XHTML, currently always returns true for LaTeX) + [w2x] The template page in the configuration now displays an error message if the template is not well-formed XML. [w2x] Added toolbar configuration dialog: Select XHTML and EPUB export format and behavior after export (do nothing, @@ -11,7 +14,7 @@ Items marked with * are work in progress [w2x] New option include_ncx to include a NCX file even if the export format is EPUB 3 -[w2x] *Added EPUB 3 as export format and changed default export format for the toolbar to EPUB 3 +[w2x] Added EPUB 3 as export format and changed default export format for the toolbar to EPUB 3 [all] Implementation detail: Moved descriptions to a separate folder within the extensions diff --git a/source/java/org/openoffice/da/comp/w2lcommon/filter/UNOPublisher.java b/source/java/org/openoffice/da/comp/w2lcommon/filter/UNOPublisher.java index b4fb1dc..eef1810 100644 --- a/source/java/org/openoffice/da/comp/w2lcommon/filter/UNOPublisher.java +++ b/source/java/org/openoffice/da/comp/w2lcommon/filter/UNOPublisher.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-04-24) + * Version 1.6 (2015-05-05) * */ package org.openoffice.da.comp.w2lcommon.filter; @@ -308,7 +308,7 @@ public class UNOPublisher { case xhtml_mathml: case html5: return "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialogMath"; case epub: return "org.openoffice.da.comp.writer2xhtml.EpubOptionsDialog"; - case epub3: return "org.openoffice.da.comp.writer2xhtml.EpubOptionsDialog"; + case epub3: return "org.openoffice.da.comp.writer2xhtml.Epub3OptionsDialog"; case latex: return "org.openoffice.da.comp.writer2latex.LaTeXOptionsDialog"; default: return null; } diff --git a/source/java/org/openoffice/da/comp/writer2xhtml/Epub3OptionsDialog.java b/source/java/org/openoffice/da/comp/writer2xhtml/Epub3OptionsDialog.java index a27b19f..536e78c 100644 --- a/source/java/org/openoffice/da/comp/writer2xhtml/Epub3OptionsDialog.java +++ b/source/java/org/openoffice/da/comp/writer2xhtml/Epub3OptionsDialog.java @@ -1,6 +1,6 @@ /************************************************************************ * - * EpubOptionsDialog.java + * Epub3OptionsDialog.java * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-04-28) + * Version 1.6 (2015-05-05) * */ package org.openoffice.da.comp.writer2xhtml; @@ -38,7 +38,7 @@ public class Epub3OptionsDialog extends EpubOptionsDialog { /** The component should also have an implementation name. */ - public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.EpubOptionsDialog3"; + public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.Epub3OptionsDialog"; /** Create a new Epub3OptionsDialog */ public Epub3OptionsDialog(XComponentContext xContext) { diff --git a/source/java/writer2latex/api/ConverterFactory.java b/source/java/writer2latex/api/ConverterFactory.java index 01d7a85..1ffcec4 100644 --- a/source/java/writer2latex/api/ConverterFactory.java +++ b/source/java/writer2latex/api/ConverterFactory.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-04-14) + * Version 1.6 (2015-05-05) * */ @@ -33,7 +33,7 @@ public class ConverterFactory { // Version information private static final String VERSION = "1.5.2"; - private static final String DATE = "2015-04-14"; + private static final String DATE = "2015-05-05"; /** Return the Writer2LaTeX version in the form * (major version).(minor version).(patch level)
diff --git a/source/java/writer2latex/api/OutputFile.java b/source/java/writer2latex/api/OutputFile.java index ae69779..a606065 100644 --- a/source/java/writer2latex/api/OutputFile.java +++ b/source/java/writer2latex/api/OutputFile.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2010 by Henrik Just + * Copyright: 2002-2015 by Henrik Just * * All Rights Reserved. * - * Version 1.2 (2010-03-28) + * Version 1.6 (2015-05-05) * */ @@ -62,4 +62,10 @@ public interface OutputFile { * @return true if this document is a master document */ public boolean isMasterDocument(); + + /** Test whether this document contains mathematical formulas + * + * @return true if the document contains formulas + */ + public boolean containsMath(); } diff --git a/source/java/writer2latex/base/BinaryGraphicsDocument.java b/source/java/writer2latex/base/BinaryGraphicsDocument.java index 20710ec..0ba56a0 100644 --- a/source/java/writer2latex/base/BinaryGraphicsDocument.java +++ b/source/java/writer2latex/base/BinaryGraphicsDocument.java @@ -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-05) + * Version 1.6 (2015-05-05) * */ @@ -150,7 +150,7 @@ public class BinaryGraphicsDocument implements OutputFile { * * @return The document name or URL */ - public String getFileName() { + @Override public String getFileName() { return sFileName; } @@ -158,7 +158,7 @@ public class BinaryGraphicsDocument implements OutputFile { * * @return The MIME type or null if this is unknown */ - public String getMIMEType() { + @Override public String getMIMEType() { return sMimeType; } @@ -166,7 +166,15 @@ public class BinaryGraphicsDocument implements OutputFile { * * @return false - a graphics file is never a master document */ - public boolean isMasterDocument() { + @Override public boolean isMasterDocument() { return false; } + + /** Does this document contain formulas? + * + * @return false - a graphics file does not contain formulas + */ + @Override public boolean containsMath() { + return false; + } } \ No newline at end of file diff --git a/source/java/writer2latex/base/DOMDocument.java b/source/java/writer2latex/base/DOMDocument.java index d952b5d..3d81b24 100644 --- a/source/java/writer2latex/base/DOMDocument.java +++ b/source/java/writer2latex/base/DOMDocument.java @@ -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-26) + * Version 1.6 (2015-05-05) * */ @@ -177,7 +177,7 @@ public class DOMDocument implements OutputFile { * * @return The file name of Document. */ - public String getFileName() { + @Override public String getFileName() { return fileName; } @@ -351,11 +351,15 @@ public class DOMDocument implements OutputFile { } // We need these because we implement OutputFile - public String getMIMEType() { + @Override public String getMIMEType() { return ""; } - public boolean isMasterDocument() { + @Override public boolean isMasterDocument() { + return false; + } + + @Override public boolean containsMath() { return false; } diff --git a/source/java/writer2latex/bibtex/BibTeXDocument.java b/source/java/writer2latex/bibtex/BibTeXDocument.java index 89affd9..463ef5f 100644 --- a/source/java/writer2latex/bibtex/BibTeXDocument.java +++ b/source/java/writer2latex/bibtex/BibTeXDocument.java @@ -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-28) + * Version 1.6 (2015-05-05) * */ @@ -86,17 +86,21 @@ public class BibTeXDocument implements OutputFile { * * @return The Document name with file extension. */ - public String getFileName() { + @Override public String getFileName() { return new String(sName + FILE_EXTENSION); } - public String getMIMEType() { + @Override public String getMIMEType() { return MIMETypes.BIBTEX; } - public boolean isMasterDocument() { + @Override public boolean isMasterDocument() { return bIsMaster; } + + @Override public boolean containsMath() { + return false; + } /** *

Writes out the Document content to the specified diff --git a/source/java/writer2latex/epub/EPUBWriter.java b/source/java/writer2latex/epub/EPUBWriter.java index 4b479f5..ab6c1a7 100644 --- a/source/java/writer2latex/epub/EPUBWriter.java +++ b/source/java/writer2latex/epub/EPUBWriter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * version 1.6 (2015-04-21) + * version 1.6 (2015-05-05) * */ @@ -40,7 +40,8 @@ import writer2latex.xhtml.XhtmlConfig; /** This class repackages an XHTML document into EPUB format. * Some filenames are hard wired in this implementation: The main directory is OEBPS and - * the OPF and NCX files are book.opf and book.ncx respectively + * the OPF and NCX files are book.opf and book.ncx respectively; finally the EPUB 3 navigation + * document is nav.xhtml */ public class EPUBWriter implements OutputFile { @@ -50,7 +51,7 @@ public class EPUBWriter implements OutputFile { private ConverterResult xhtmlResult; private String sFileName; private int nVersion; - //private XhtmlConfig config; + private XhtmlConfig config; /** Create a new EPUBWriter based on a ConverterResult. * @@ -63,7 +64,7 @@ public class EPUBWriter implements OutputFile { this.xhtmlResult = xhtmlResult; this.sFileName = Misc.removeExtension(sFileName); this.nVersion = nVersion; - //this.config = config; + this.config = config; } // Implement OutputFile @@ -79,6 +80,11 @@ public class EPUBWriter implements OutputFile { @Override public boolean isMasterDocument() { return true; } + + @Override public boolean containsMath() { + // We don't really care about this + return nVersion==3; + } @Override public void write(OutputStream os) throws IOException { ZipOutputStream zos = new ZipOutputStream(os); @@ -100,7 +106,7 @@ public class EPUBWriter implements OutputFile { zos.closeEntry(); // Then manifest - OPFWriter manifest = new OPFWriter(xhtmlResult,nVersion); + OPFWriter manifest = new OPFWriter(xhtmlResult,nVersion,config); ZipEntry manifestEntry = new ZipEntry("OEBPS/book.opf"); zos.putNextEntry(manifestEntry); writeZipEntry(manifest,zos); @@ -114,7 +120,7 @@ public class EPUBWriter implements OutputFile { writeZipEntry(navigation,zos); zos.closeEntry(); } - else { + if (nVersion!=3 || config.includeNCX()) { OutputFile ncx = new NCXWriter(xhtmlResult, manifest.getUid()); ZipEntry ncxEntry = new ZipEntry("OEBPS/book.ncx"); zos.putNextEntry(ncxEntry); diff --git a/source/java/writer2latex/epub/OPFWriter.java b/source/java/writer2latex/epub/OPFWriter.java index 942e188..d91be52 100644 --- a/source/java/writer2latex/epub/OPFWriter.java +++ b/source/java/writer2latex/epub/OPFWriter.java @@ -20,15 +20,20 @@ * * All Rights Reserved. * - * version 1.6 (2015-04-21) + * version 1.6 (2015-05-05) * */ package writer2latex.epub; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.TimeZone; import java.util.UUID; import javax.xml.parsers.DocumentBuilder; @@ -45,13 +50,14 @@ import writer2latex.api.ConverterResult; import writer2latex.api.OutputFile; import writer2latex.base.DOMDocument; import writer2latex.util.Misc; +import writer2latex.xhtml.XhtmlConfig; /** This class writes an OPF-file for an EPUB document (see http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html). */ public class OPFWriter extends DOMDocument { private String sUID=null; - public OPFWriter(ConverterResult cr, int nVersion) { + public OPFWriter(ConverterResult cr, int nVersion, XhtmlConfig config) { super("book", "opf"); // create DOM @@ -78,8 +84,6 @@ public class OPFWriter extends DOMDocument { pack.setAttribute("xmlns","http://www.idpf.org/2007/opf"); pack.setAttribute("unique-identifier", "BookId"); - // TODO: http://sketchytech.blogspot.dk/2014/03/epub2-to-epub3-lessons-learnt-in.html - // Meta data, at least dc:title, dc:language and dc:identifier are required by the specification // For EPUB 3, also dcterms:modified is required Element metadata = contentDOM.createElement("metadata"); @@ -94,9 +98,10 @@ public class OPFWriter extends DOMDocument { appendElement(contentDOM, metadata, "dc:language", cr.getMetaData().getLanguage()); // Modification (required in EPUB 3) - - appendElement(contentDOM, metadata, "meta", cr.getMetaData().getDate()) - .setAttribute("property", "dcterms:modified"); + if (nVersion==3) { + appendElement(contentDOM, metadata, "meta", getCurrentDateTime()) + .setAttribute("property", "dcterms:modified"); + } // Subject and keywords in ODF both map to Dublin core subjects if (cr.getMetaData().getSubject().length()>0) { @@ -286,7 +291,7 @@ public class OPFWriter extends DOMDocument { pack.appendChild(manifest); Element spine = contentDOM.createElement("spine"); - if (nVersion!=3) { // Use old NCX file for navigation + if (nVersion!=3 || config.includeNCX()) { // Use old NCX file for navigation spine.setAttribute("toc", "ncx"); } pack.appendChild(spine); @@ -321,6 +326,10 @@ public class OPFWriter extends DOMDocument { String sId = "text"+(++nMasterCount); item.setAttribute("id", sId); + if (nVersion==3 && file.containsMath()) { + item.setAttribute("properties","mathml"); + } + Element itemref = contentDOM.createElement("itemref"); itemref.setAttribute("idref", sId); spine.appendChild(itemref); @@ -338,7 +347,7 @@ public class OPFWriter extends DOMDocument { item.setAttribute("properties", "nav"); manifest.appendChild(item); } - else { // Include old NCX file + if (nVersion!=3 || config.includeNCX()) { // Include old NCX file Element item = contentDOM.createElement("item"); item.setAttribute("href", "book.ncx"); item.setAttribute("media-type", "application/x-dtbncx+xml"); @@ -398,5 +407,13 @@ public class OPFWriter extends DOMDocument { guide.appendChild(reference); } } + + // Get the current date and time in the required format + private String getCurrentDateTime() { + Date date = Calendar.getInstance().getTime(); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + formatter.setTimeZone(TimeZone.getTimeZone("UTC")); + return formatter.format(date); + } } diff --git a/source/java/writer2latex/latex/LaTeXDocument.java b/source/java/writer2latex/latex/LaTeXDocument.java index c662d1c..6e4f9d1 100644 --- a/source/java/writer2latex/latex/LaTeXDocument.java +++ b/source/java/writer2latex/latex/LaTeXDocument.java @@ -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-27) + * Version 1.6 (2015-05-05) * */ @@ -81,17 +81,22 @@ public class LaTeXDocument implements OutputFile { * * @return The Document name with file extension. */ - public String getFileName() { + @Override public String getFileName() { return new String(sName + FILE_EXTENSION); } - public String getMIMEType() { + @Override public String getMIMEType() { return MIMETypes.LATEX; } - public boolean isMasterDocument() { + @Override public boolean isMasterDocument() { return bIsMaster; } + + @Override public boolean containsMath() { + // We don't use this information currently + return true; + } /** *

Writes out the Document content to the specified diff --git a/source/java/writer2latex/xhtml/CssDocument.java b/source/java/writer2latex/xhtml/CssDocument.java index 6c8fb6b..7ec5a1c 100644 --- a/source/java/writer2latex/xhtml/CssDocument.java +++ b/source/java/writer2latex/xhtml/CssDocument.java @@ -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-16) + * Version 1.6 (2015-05-05) * */ @@ -54,15 +54,19 @@ public class CssDocument implements OutputFile { sContent = ""; } - public String getFileName() { + @Override public String getFileName() { return sName; } - public String getMIMEType() { + @Override public String getMIMEType() { return "text/css"; } - public boolean isMasterDocument() { + @Override public boolean isMasterDocument() { + return false; + } + + @Override public boolean containsMath() { return false; } diff --git a/source/java/writer2latex/xhtml/MathConverter.java b/source/java/writer2latex/xhtml/MathConverter.java index 2dd1b31..38cdcd0 100644 --- a/source/java/writer2latex/xhtml/MathConverter.java +++ b/source/java/writer2latex/xhtml/MathConverter.java @@ -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-11-24) + * Version 1.6 (2015-05-05) * */ @@ -187,8 +187,8 @@ public class MathConverter extends ConverterHelper { if (onode.hasAttribute("xmlns:math")) { math.setAttribute("xmlns", onode.getAttribute("xmlns:math")); } - else if (onode.hasAttribute("xmlns") && converter.nType!=XhtmlDocument.HTML5) { - // Don't include xmlns attribute in HTML5 + else if (onode.hasAttribute("xmlns") && (converter.nType!=XhtmlDocument.HTML5 || converter.isOPS())) { + // Don't include xmlns attribute in HTML5, unless we are creating EPUB 3 math.setAttribute("xmlns", onode.getAttribute("xmlns")); } if (bAllowDisplay && onode.hasAttribute("display")) { diff --git a/source/java/writer2latex/xhtml/ResourceDocument.java b/source/java/writer2latex/xhtml/ResourceDocument.java index 251fd29..68bfcb8 100644 --- a/source/java/writer2latex/xhtml/ResourceDocument.java +++ b/source/java/writer2latex/xhtml/ResourceDocument.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2010 by Henrik Just + * Copyright: 2002-2015 by Henrik Just * * All Rights Reserved. * - * Version 1.2 (2010-12-21) + * Version 1.5 (2015-05-05) * */ @@ -33,8 +33,7 @@ import java.io.OutputStream; import writer2latex.api.OutputFile; import writer2latex.util.Misc; -/** - * An implementation of OutputFile for resource documents. +/** An implementation of OutputFile for resource documents. * (A resource document is an arbitrary binary file to include in the converter result) */ public class ResourceDocument implements OutputFile { @@ -55,22 +54,33 @@ public class ResourceDocument implements OutputFile { content = new byte[0]; } - public String getFileName() { + // Implement OutputFile + + @Override public String getFileName() { return sFileName; } - public String getMIMEType() { + @Override public String getMIMEType() { return sMediaType; } - public boolean isMasterDocument() { + @Override public boolean isMasterDocument() { + return false; + } + + @Override public boolean containsMath() { return false; } - public void write(OutputStream os) throws IOException { + @Override public void write(OutputStream os) throws IOException { os.write(content); } + /** Load the resource document bytes from an arbitrary input stream + * + * @param is the input stream + * @throws IOException if any error occurs reading the input stream + */ public void read(InputStream is) throws IOException { content = Misc.inputStreamToByteArray(is); } diff --git a/source/java/writer2latex/xhtml/XhtmlDocument.java b/source/java/writer2latex/xhtml/XhtmlDocument.java index 76be3cf..b27e4f5 100644 --- a/source/java/writer2latex/xhtml/XhtmlDocument.java +++ b/source/java/writer2latex/xhtml/XhtmlDocument.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-04-21) + * Version 1.6 (2015-05-05) * */ @@ -302,6 +302,10 @@ public class XhtmlDocument extends DOMDocument { return true; } + @Override public boolean containsMath() { + return bodyNode!=null ? containsMath(bodyNode) : false; + } + public Element getHeadNode() { return headNode; } public Element getBodyNode() { return bodyNode; } @@ -959,6 +963,25 @@ public class XhtmlDocument extends DOMDocument { default: return null; } } + + private boolean containsMath(Element node) { + // First check the node itself + if (node.getTagName().equals("math")) { + return true; + } + // The check the children + Node child = node.getFirstChild(); + while (child!=null) { + if (child.getNodeType()==Node.ELEMENT_NODE) { + if (containsMath((Element)child)) { + return true; + } + } + child = child.getNextSibling(); + } + // And then look no further + return false; + } } diff --git a/source/oxt/writer2xhtml/w2x_filters.xcu b/source/oxt/writer2xhtml/w2x_filters.xcu index e88fb7c..9f98e39 100644 --- a/source/oxt/writer2xhtml/w2x_filters.xcu +++ b/source/oxt/writer2xhtml/w2x_filters.xcu @@ -105,7 +105,7 @@ 0 writer_epub3_File com.sun.star.text.TextDocument - org.openoffice.da.comp.writer2xhtml.EpubOptionsDialog + org.openoffice.da.comp.writer2xhtml.Epub3OptionsDialog org.openoffice.da.comp.writer2xhtml.W2XExportFilter unused com.sun.star.comp.Writer.XMLOasisImporter com.sun.star.comp.Writer.XMLOasisExporter staroffice/sxw epub3 com.sun.star.comp.Writer.XmlFilterAdaptor