EPUB 3 support
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@239 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
b0b61acb19
commit
d141619053
15 changed files with 413 additions and 122 deletions
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2015-04-05)
|
||||
* Version 1.6 (2015-04-24)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
@ -334,7 +334,7 @@ public class UNOPublisher {
|
|||
case xhtml_mathml: return "org.openoffice.da.writer2xhtml.mathml";
|
||||
case html5: return "org.openoffice.da.writer2xhtml5";
|
||||
case epub: return "org.openoffice.da.writer2xhtml.epub";
|
||||
case epub3: return "org.openoffice.da.writer2xhtml.epub";
|
||||
case epub3: return "org.openoffice.da.writer2xhtml.epub3";
|
||||
case latex: return "org.openoffice.da.writer2latex";
|
||||
default: return "";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* EpubOptionsDialog.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-2016 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2015-04-28)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
/** This class provides a UNO component which implements a filter UI for the
|
||||
* EPUB 3 export. In this version the option to include NCX is enabled.
|
||||
*/
|
||||
public class Epub3OptionsDialog extends EpubOptionsDialog {
|
||||
|
||||
/** The component will be registered under this name.
|
||||
*/
|
||||
public static String __serviceName = "org.openoffice.da.writer2xhtml.Epub3OptionsDialog";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
*/
|
||||
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.EpubOptionsDialog3";
|
||||
|
||||
/** Create a new Epub3OptionsDialog */
|
||||
public Epub3OptionsDialog(XComponentContext xContext) {
|
||||
super(xContext);
|
||||
}
|
||||
|
||||
}
|
|
@ -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-25)
|
||||
* Version 1.6 (2015-04-28)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -119,6 +119,7 @@ public class EpubOptionsDialog extends OptionsDialogBase {
|
|||
// Navigation table
|
||||
loadListBoxOption(xProps, "ExternalTocDepth");
|
||||
loadCheckBoxOption(xProps, "IncludeToc");
|
||||
loadCheckBoxOption(xProps, "IncludeNCX");
|
||||
|
||||
updateLockedOptions();
|
||||
enableControls();
|
||||
|
@ -204,6 +205,7 @@ public class EpubOptionsDialog extends OptionsDialogBase {
|
|||
short nExternalTocDepth = saveListBoxOption(xProps, "ExternalTocDepth");
|
||||
helper.put("external_toc_depth", Integer.toString(nExternalTocDepth+1));
|
||||
saveCheckBoxOption(xProps, helper, "IncludeToc", "include_toc");
|
||||
saveCheckBoxOption(xProps, helper, "IncludeNCX", "include_ncx");
|
||||
}
|
||||
|
||||
|
||||
|
@ -291,6 +293,7 @@ public class EpubOptionsDialog extends OptionsDialogBase {
|
|||
setControlEnabled("ExternalTocDepthLabel", !isLocked("external_toc_depth"));
|
||||
setControlEnabled("ExternalTocDepth", !isLocked("external_toc_depth"));
|
||||
setControlEnabled("IncludeToc", !isLocked("include_toc"));
|
||||
setControlEnabled("IncludeNCX", (this instanceof Epub3OptionsDialog) && !isLocked("include_ncx"));
|
||||
}
|
||||
|
||||
private void relativeFontSizeChange() {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2015-04-03)
|
||||
* Version 1.6 (2015-04-28)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -102,6 +102,12 @@ public class W2XRegistration {
|
|||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(Epub3OptionsDialog.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(Epub3OptionsDialog.class,
|
||||
Epub3OptionsDialog.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(EpubMetadataDialog.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(EpubMetadataDialog.class,
|
||||
EpubMetadataDialog.__serviceName,
|
||||
|
@ -148,6 +154,8 @@ public class W2XRegistration {
|
|||
XhtmlOptionsDialogCalc.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(EpubOptionsDialog.__implementationName,
|
||||
EpubOptionsDialog.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(Epub3OptionsDialog.__implementationName,
|
||||
Epub3OptionsDialog.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(EpubMetadataDialog.__implementationName,
|
||||
EpubMetadataDialog.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(ConfigurationDialog.__implementationName,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* XhtmlOptionsDialogXsl.java
|
||||
* XhtmlOptionsDialogMath.java
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -30,7 +30,7 @@ import com.sun.star.uno.XComponentContext;
|
|||
|
||||
/** This class provides a uno component which implements a filter ui for the
|
||||
* Xhtml export for the XHTML+MathML and HTML export.
|
||||
* This variant of the dialog has the MahtJax setting enabled
|
||||
* This variant of the dialog has the MathJax setting enabled
|
||||
*/
|
||||
public class XhtmlOptionsDialogMath extends XhtmlOptionsDialog {
|
||||
/** The component will be registered under this name.
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* version 1.6 (2015-01-15)
|
||||
* version 1.6 (2015-04-21)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -49,6 +49,7 @@ public class EPUBWriter implements OutputFile {
|
|||
|
||||
private ConverterResult xhtmlResult;
|
||||
private String sFileName;
|
||||
private int nVersion;
|
||||
//private XhtmlConfig config;
|
||||
|
||||
/** Create a new <code>EPUBWriter</code> based on a <code>ConverterResult</code>.
|
||||
|
@ -61,6 +62,7 @@ public class EPUBWriter implements OutputFile {
|
|||
public EPUBWriter(ConverterResult xhtmlResult, String sFileName, int nVersion, XhtmlConfig config) {
|
||||
this.xhtmlResult = xhtmlResult;
|
||||
this.sFileName = Misc.removeExtension(sFileName);
|
||||
this.nVersion = nVersion;
|
||||
//this.config = config;
|
||||
}
|
||||
|
||||
|
@ -98,18 +100,27 @@ public class EPUBWriter implements OutputFile {
|
|||
zos.closeEntry();
|
||||
|
||||
// Then manifest
|
||||
OPFWriter manifest = new OPFWriter(xhtmlResult);
|
||||
OPFWriter manifest = new OPFWriter(xhtmlResult,nVersion);
|
||||
ZipEntry manifestEntry = new ZipEntry("OEBPS/book.opf");
|
||||
zos.putNextEntry(manifestEntry);
|
||||
writeZipEntry(manifest,zos);
|
||||
zos.closeEntry();
|
||||
|
||||
// And content table
|
||||
OutputFile ncx = new NCXWriter(xhtmlResult, manifest.getUid());
|
||||
ZipEntry ncxEntry = new ZipEntry("OEBPS/book.ncx");
|
||||
zos.putNextEntry(ncxEntry);
|
||||
writeZipEntry(ncx,zos);
|
||||
zos.closeEntry();
|
||||
if (nVersion==3) {
|
||||
OutputFile navigation = new NavigationWriter(xhtmlResult);
|
||||
ZipEntry navigationEntry = new ZipEntry("OEBPS/nav.xhtml");
|
||||
zos.putNextEntry(navigationEntry);
|
||||
writeZipEntry(navigation,zos);
|
||||
zos.closeEntry();
|
||||
}
|
||||
else {
|
||||
OutputFile ncx = new NCXWriter(xhtmlResult, manifest.getUid());
|
||||
ZipEntry ncxEntry = new ZipEntry("OEBPS/book.ncx");
|
||||
zos.putNextEntry(ncxEntry);
|
||||
writeZipEntry(ncx,zos);
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
// Finally XHTML content
|
||||
Iterator<OutputFile> iter = xhtmlResult.iterator();
|
||||
|
|
131
source/java/writer2latex/epub/NavigationWriter.java
Normal file
131
source/java/writer2latex/epub/NavigationWriter.java
Normal file
|
@ -0,0 +1,131 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* NavigationWriter.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: 2001-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* version 1.6 (2015-04-21)
|
||||
*
|
||||
*/
|
||||
package writer2latex.epub;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.DOMImplementation;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DocumentType;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import writer2latex.api.ContentEntry;
|
||||
import writer2latex.api.ConverterResult;
|
||||
import writer2latex.base.DOMDocument;
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
/** This class writes the EPUB Navigation Document as defined in EPUB 3
|
||||
*/
|
||||
public class NavigationWriter extends DOMDocument {
|
||||
|
||||
public NavigationWriter(ConverterResult cr) {
|
||||
super("nav", "xhtml");
|
||||
|
||||
// create DOM
|
||||
Document contentDOM = null;
|
||||
try {
|
||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = builderFactory.newDocumentBuilder();
|
||||
DOMImplementation domImpl = builder.getDOMImplementation();
|
||||
DocumentType doctype = domImpl.createDocumentType("xhtml","","");
|
||||
contentDOM = domImpl.createDocument("http://www.w3.org/1999/xhtml","html",doctype);
|
||||
}
|
||||
catch (ParserConfigurationException t) { // this should never happen
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
|
||||
// Populate the DOM tree
|
||||
Element doc = contentDOM.getDocumentElement();
|
||||
doc.setAttribute("xmlns","http://www.w3.org/1999/xhtml");
|
||||
doc.setAttribute("xmlns:epub","http://www.idpf.org/2007/ops");
|
||||
doc.setAttribute("xml:lang", cr.getMetaData().getLanguage());
|
||||
doc.setAttribute("lang", cr.getMetaData().getLanguage());
|
||||
|
||||
// Create and populate the head
|
||||
Element head = contentDOM.createElement("head");
|
||||
doc.appendChild(head);
|
||||
|
||||
Element title = contentDOM.createElement("title");
|
||||
head.appendChild(title);
|
||||
title.appendChild(contentDOM.createTextNode("EPUB 3 Navigation Document"));
|
||||
// Or use the document title cr.getMetaData().getTitle()?
|
||||
|
||||
// Create the body
|
||||
Element body = contentDOM.createElement("body");
|
||||
doc.appendChild(body);
|
||||
|
||||
// Create nav element
|
||||
Element nav = contentDOM.createElement("nav");
|
||||
nav.setAttribute("epub:type", "toc");
|
||||
body.appendChild(nav);
|
||||
|
||||
// Populate the nav element from the content table in the converter result
|
||||
Element currentContainer = body;
|
||||
int nCurrentLevel = 0;
|
||||
int nCurrentEntryLevel = 0; // This may differ from nCurrentLevel if the heading levels "jump" in then document
|
||||
Iterator<ContentEntry> content = cr.getContent().iterator();
|
||||
while (content.hasNext()) {
|
||||
ContentEntry entry = content.next();
|
||||
int nEntryLevel = Math.max(entry.getLevel(), 1);
|
||||
|
||||
if (nEntryLevel<nCurrentLevel) {
|
||||
// Return to higher level
|
||||
for (int i=nEntryLevel; i<nCurrentLevel; i++) {
|
||||
currentContainer = (Element) currentContainer.getParentNode().getParentNode();
|
||||
}
|
||||
nCurrentLevel = nEntryLevel;
|
||||
}
|
||||
else if (nEntryLevel>nCurrentEntryLevel) {
|
||||
// To lower level (always one step; a jump from e.g. heading 1 to heading 3 in the document
|
||||
// is considered an error)
|
||||
currentContainer = (Element) currentContainer.getLastChild();
|
||||
Element ol = contentDOM.createElement("ol");
|
||||
currentContainer.appendChild(ol);
|
||||
currentContainer = ol;
|
||||
nCurrentLevel++;
|
||||
}
|
||||
|
||||
nCurrentEntryLevel = nEntryLevel;
|
||||
|
||||
// Create the actual toc entry
|
||||
Element li = contentDOM.createElement("li");
|
||||
currentContainer.appendChild(li);
|
||||
Element a = contentDOM.createElement("a");
|
||||
li.appendChild(a);
|
||||
String sHref = Misc.makeHref(entry.getFile().getFileName());
|
||||
if (entry.getTarget()!=null) { sHref+="#"+entry.getTarget(); }
|
||||
a.setAttribute("href", sHref);
|
||||
a.appendChild(contentDOM.createTextNode(entry.getTitle()));
|
||||
}
|
||||
|
||||
setContentDOM(contentDOM);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,11 +16,11 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2001-2014 by Henrik Just
|
||||
* Copyright: 2001-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* version 1.4 (2014-08-26)
|
||||
* version 1.6 (2015-04-21)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -51,7 +51,7 @@ import writer2latex.util.Misc;
|
|||
public class OPFWriter extends DOMDocument {
|
||||
private String sUID=null;
|
||||
|
||||
public OPFWriter(ConverterResult cr) {
|
||||
public OPFWriter(ConverterResult cr, int nVersion) {
|
||||
super("book", "opf");
|
||||
|
||||
// create DOM
|
||||
|
@ -69,20 +69,35 @@ public class OPFWriter extends DOMDocument {
|
|||
|
||||
// Populate the DOM tree
|
||||
Element pack = contentDOM.getDocumentElement();
|
||||
pack.setAttribute("version", "2.0");
|
||||
if (nVersion==3) {
|
||||
pack.setAttribute("version", "3.0");
|
||||
}
|
||||
else {
|
||||
pack.setAttribute("version", "2.0");
|
||||
}
|
||||
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");
|
||||
metadata.setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");
|
||||
metadata.setAttribute("xmlns:opf", "http://www.idpf.org/2007/opf");
|
||||
if (nVersion!=3) {
|
||||
metadata.setAttribute("xmlns:opf", "http://www.idpf.org/2007/opf");
|
||||
}
|
||||
pack.appendChild(metadata);
|
||||
|
||||
// Title and language (required)
|
||||
appendElement(contentDOM, metadata, "dc:title", cr.getMetaData().getTitle());
|
||||
appendElement(contentDOM, metadata, "dc:language", cr.getMetaData().getLanguage());
|
||||
|
||||
// Modification (required in EPUB 3)
|
||||
|
||||
appendElement(contentDOM, metadata, "meta", cr.getMetaData().getDate())
|
||||
.setAttribute("property", "dcterms:modified");
|
||||
|
||||
// Subject and keywords in ODF both map to Dublin core subjects
|
||||
if (cr.getMetaData().getSubject().length()>0) {
|
||||
appendElement(contentDOM, metadata, "dc:subject", cr.getMetaData().getSubject());
|
||||
|
@ -99,7 +114,7 @@ public class OPFWriter extends DOMDocument {
|
|||
|
||||
// User defined meta data
|
||||
// The identifier, creator, contributor and date has an optional attribute and there may be multiple instances of
|
||||
// the first three. The key must be in the form name[id][.attribute]
|
||||
// the latter three. The key must be in the form name[id][.attribute]
|
||||
// where the id is some unique id amongst the instances with the same name
|
||||
// Furthermore the instances will be sorted on the id
|
||||
// Thus you can have e.g. creator1.aut="John Doe" and creator2.aut="Jane Doe", and "John Doe" will be the first author
|
||||
|
@ -138,29 +153,72 @@ public class OPFWriter extends DOMDocument {
|
|||
sUID = sValue;
|
||||
}
|
||||
if (sAttributeValue!=null) {
|
||||
identifier.setAttribute("opf:scheme", sAttributeValue);
|
||||
if (nVersion==3) {
|
||||
Element meta = appendElement(contentDOM, metadata, "meta", sAttributeValue);
|
||||
meta.setAttribute("refines", "#BookId");
|
||||
meta.setAttribute("property", "identifier-type");
|
||||
}
|
||||
else {
|
||||
identifier.setAttribute("opf:scheme", sAttributeValue);
|
||||
}
|
||||
}
|
||||
bHasIdentifier = true;
|
||||
}
|
||||
else if (sKey.startsWith("creator")) {
|
||||
Element creator = appendElement(contentDOM, metadata, "dc:creator", sValue);
|
||||
creator.setAttribute("opf:file-as", fileAs(sValue));
|
||||
if (sAttributeValue!=null) {
|
||||
creator.setAttribute("opf:role", sAttributeValue);
|
||||
creator.setAttribute("id", sKey);
|
||||
if (nVersion==3) {
|
||||
Element fileas = appendElement(contentDOM, metadata, "meta", fileAs(sValue));
|
||||
fileas.setAttribute("refines", "#"+sKey);
|
||||
fileas.setAttribute("property", "file-as");
|
||||
if (sAttributeValue!=null) {
|
||||
Element role = appendElement(contentDOM, metadata, "meta", sAttributeValue);
|
||||
role.setAttribute("refines", "#"+sKey);
|
||||
role.setAttribute("property", "role");
|
||||
}
|
||||
}
|
||||
else {
|
||||
creator.setAttribute("opf:file-as", fileAs(sValue));
|
||||
if (sAttributeValue!=null) {
|
||||
creator.setAttribute("opf:role", sAttributeValue);
|
||||
}
|
||||
}
|
||||
bHasCreator = true;
|
||||
}
|
||||
else if (sKey.startsWith("contributor")) {
|
||||
Element contributor = appendElement(contentDOM, metadata, "dc:contributor", sValue);
|
||||
contributor.setAttribute("opf:file-as", fileAs(sValue));
|
||||
if (sAttributeValue!=null) {
|
||||
contributor.setAttribute("opf:role", sAttributeValue);
|
||||
contributor.setAttribute("id", sKey);
|
||||
if (nVersion==3) {
|
||||
Element fileas = appendElement(contentDOM, metadata, "meta", fileAs(sValue));
|
||||
fileas.setAttribute("refines", "#"+sKey);
|
||||
fileas.setAttribute("property", "file-as");
|
||||
if (sAttributeValue!=null) {
|
||||
Element role = appendElement(contentDOM, metadata, "meta", sAttributeValue);
|
||||
role.setAttribute("refines", "#"+sKey);
|
||||
role.setAttribute("property", "role");
|
||||
}
|
||||
}
|
||||
else {
|
||||
contributor.setAttribute("opf:file-as", fileAs(sValue));
|
||||
if (sAttributeValue!=null) {
|
||||
contributor.setAttribute("opf:role", sAttributeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sKey.startsWith("date")) {
|
||||
Element date = appendElement(contentDOM, metadata, "dc:date", sValue);
|
||||
if (sAttributeValue!=null) {
|
||||
date.setAttribute("opf:event", sAttributeValue);
|
||||
date.setAttribute("id", sKey);
|
||||
if (nVersion==3) {
|
||||
if (sAttributeValue!=null) {
|
||||
Element event = appendElement(contentDOM, metadata, "meta", sAttributeValue);
|
||||
event.setAttribute("refines", "#"+sKey);
|
||||
event.setAttribute("property", "event");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sAttributeValue!=null) {
|
||||
date.setAttribute("opf:event", sAttributeValue);
|
||||
}
|
||||
}
|
||||
bHasDate = true;
|
||||
}
|
||||
|
@ -196,11 +254,26 @@ public class OPFWriter extends DOMDocument {
|
|||
sUID = UUID.randomUUID().toString();
|
||||
Element identifier = appendElement(contentDOM, metadata, "dc:identifier", sUID);
|
||||
identifier.setAttribute("id", "BookId");
|
||||
identifier.setAttribute("opf:scheme", "UUID");
|
||||
if (nVersion==3) {
|
||||
Element meta = appendElement(contentDOM, metadata, "meta", "UUID");
|
||||
meta.setAttribute("refines", "#BookId");
|
||||
meta.setAttribute("property", "identifier-type");
|
||||
}
|
||||
else {
|
||||
identifier.setAttribute("opf:scheme", "UUID");
|
||||
}
|
||||
}
|
||||
if (!bHasCreator && cr.getMetaData().getCreator().length()>0) {
|
||||
appendElement(contentDOM, metadata, "dc:creator", cr.getMetaData().getCreator())
|
||||
.setAttribute("opf:file-as", fileAs(cr.getMetaData().getCreator()));
|
||||
Element creator = appendElement(contentDOM, metadata, "dc:creator", cr.getMetaData().getCreator());
|
||||
creator.setAttribute("id", "creator");
|
||||
if (nVersion==3) {
|
||||
Element fileas = appendElement(contentDOM, metadata, "meta", fileAs(cr.getMetaData().getCreator()));
|
||||
fileas.setAttribute("refines", "#creator");
|
||||
fileas.setAttribute("property", "file-as");
|
||||
}
|
||||
else {
|
||||
creator.setAttribute("opf:file-as", fileAs(cr.getMetaData().getCreator()));
|
||||
}
|
||||
}
|
||||
if (!bHasDate && cr.getMetaData().getDate().length()>0) {
|
||||
// TODO: Support meta:creation-date?
|
||||
|
@ -213,7 +286,9 @@ public class OPFWriter extends DOMDocument {
|
|||
pack.appendChild(manifest);
|
||||
|
||||
Element spine = contentDOM.createElement("spine");
|
||||
spine.setAttribute("toc", "ncx");
|
||||
if (nVersion!=3) { // Use old NCX file for navigation
|
||||
spine.setAttribute("toc", "ncx");
|
||||
}
|
||||
pack.appendChild(spine);
|
||||
|
||||
int nMasterCount = 0;
|
||||
|
@ -255,11 +330,21 @@ public class OPFWriter extends DOMDocument {
|
|||
}
|
||||
}
|
||||
|
||||
Element item = contentDOM.createElement("item");
|
||||
item.setAttribute("href", "book.ncx");
|
||||
item.setAttribute("media-type", "application/x-dtbncx+xml");
|
||||
item.setAttribute("id", "ncx");
|
||||
manifest.appendChild(item);
|
||||
if (nVersion==3) { // Include the new Navigation Document
|
||||
Element item = contentDOM.createElement("item");
|
||||
item.setAttribute("href", "nav.xhtml");
|
||||
item.setAttribute("media-type", "application/xhtml+xml");
|
||||
item.setAttribute("id", "nav");
|
||||
item.setAttribute("properties", "nav");
|
||||
manifest.appendChild(item);
|
||||
}
|
||||
else { // Include old NCX file
|
||||
Element item = contentDOM.createElement("item");
|
||||
item.setAttribute("href", "book.ncx");
|
||||
item.setAttribute("media-type", "application/x-dtbncx+xml");
|
||||
item.setAttribute("id", "ncx");
|
||||
manifest.appendChild(item);
|
||||
}
|
||||
|
||||
// The guide may contain references to some fundamental structural components
|
||||
Element guide = contentDOM.createElement("guide");
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2015-01-14)
|
||||
* Version 1.6 (2015-04-28)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -41,7 +41,7 @@ import writer2latex.util.Misc;
|
|||
|
||||
public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
||||
// Implement configuration methods
|
||||
protected int getOptionCount() { return 57; }
|
||||
protected int getOptionCount() { return 58; }
|
||||
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
|
||||
|
||||
// Override setOption: To be backwards compatible, we must accept options
|
||||
|
@ -137,26 +137,27 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
private static final int FOOTNOTES_HEADING = 34;
|
||||
private static final int EXTERNAL_TOC_DEPTH = 35;
|
||||
private static final int INCLUDE_TOC = 36;
|
||||
private static final int SPLIT_LEVEL = 37;
|
||||
private static final int REPEAT_LEVELS = 38;
|
||||
private static final int PAGE_BREAK_SPLIT = 39;
|
||||
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 EMBED_SVG = 43;
|
||||
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;
|
||||
private static final int INCLUDE_NCX = 37;
|
||||
private static final int SPLIT_LEVEL = 38;
|
||||
private static final int REPEAT_LEVELS = 39;
|
||||
private static final int PAGE_BREAK_SPLIT = 40;
|
||||
private static final int SPLIT_AFTER = 41;
|
||||
private static final int IMAGE_SPLIT = 42;
|
||||
private static final int COVER_IMAGE = 43;
|
||||
private static final int EMBED_SVG = 44;
|
||||
private static final int EMBED_IMG = 45;
|
||||
private static final int USE_MATHJAX = 46;
|
||||
private static final int CALC_SPLIT = 47;
|
||||
private static final int DISPLAY_HIDDEN_SHEETS = 48;
|
||||
private static final int DISPLAY_HIDDEN_ROWS_COLS = 49;
|
||||
private static final int DISPLAY_FILTERED_ROWS_COLS = 50;
|
||||
private static final int APPLY_PRINT_RANGES = 51;
|
||||
private static final int USE_TITLE_AS_HEADING = 52;
|
||||
private static final int USE_SHEET_NAMES_AS_HEADINGS = 53;
|
||||
private static final int SAVE_IMAGES_IN_SUBDIR = 54;
|
||||
private static final int UPLINK = 55;
|
||||
private static final int DIRECTORY_ICON = 56;
|
||||
private static final int DOCUMENT_ICON = 57;
|
||||
|
||||
protected ComplexOption xheading = addComplexOption("heading-map");
|
||||
protected ComplexOption xpar = addComplexOption("paragraph-map");
|
||||
|
@ -245,6 +246,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
}
|
||||
};
|
||||
options[INCLUDE_TOC] = new BooleanOption("include_toc","true");
|
||||
options[INCLUDE_NCX] = new BooleanOption("include_ncx","true");
|
||||
options[SPLIT_LEVEL] = new IntegerOption("split_level","0") {
|
||||
@Override public void setString(String sValue) {
|
||||
super.setString(sValue);
|
||||
|
@ -408,6 +410,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
|
|||
public int formulas() { return ((IntegerOption) options[FORMULAS]).getValue(); }
|
||||
public int externalTocDepth() { return ((IntegerOption) options[EXTERNAL_TOC_DEPTH]).getValue(); }
|
||||
public boolean includeToc() { return ((BooleanOption) options[INCLUDE_TOC]).getValue(); }
|
||||
public boolean includeNCX() { return ((BooleanOption) options[INCLUDE_NCX]).getValue(); }
|
||||
public int getXhtmlSplitLevel() { return ((IntegerOption) options[SPLIT_LEVEL]).getValue(); }
|
||||
public int getXhtmlRepeatLevels() { return ((IntegerOption) options[REPEAT_LEVELS]).getValue(); }
|
||||
public int pageBreakSplit() { return ((IntegerOption) options[PAGE_BREAK_SPLIT]).getValue(); }
|
||||
|
|
|
@ -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-23)
|
||||
* Version 1.6 (2015-04-21)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -40,7 +40,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import writer2latex.api.MIMETypes;
|
||||
import writer2latex.base.DOMDocument;
|
||||
import writer2latex.office.XMLString;
|
||||
|
||||
|
@ -294,13 +293,9 @@ public class XhtmlDocument extends DOMDocument {
|
|||
}
|
||||
|
||||
@Override public String getMIMEType() {
|
||||
switch (nType) {
|
||||
case XHTML10: return MIMETypes.XHTML;
|
||||
case XHTML11: return MIMETypes.XHTML_MATHML; // TODO: Change the constant names in MIMETypes, this is a bit confusing...
|
||||
case XHTML_MATHML: return MIMETypes.XHTML_MATHML;
|
||||
case HTML5: return MIMETypes.HTML5;
|
||||
}
|
||||
return "";
|
||||
// Get the real MIME type, not the pseudo ones used by the converter API
|
||||
// We always produce XHTML, thus
|
||||
return "application/xhtml+xml";
|
||||
}
|
||||
|
||||
@Override public boolean isMasterDocument() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue