From 755db936f2968569f743c445d7772b1b4c1a3630 Mon Sep 17 00:00:00 2001 From: henrikjust Date: Wed, 20 Jul 2011 11:06:01 +0000 Subject: [PATCH] Support cover images in EPUB export + a bugfix in the meta data editor git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@113 f0f2a975-2e09-46c8-9428-3b39399b9f3c --- source/distro/changelog.txt | 8 ++++--- .../comp/writer2xhtml/EpubMetadataDialog.java | 5 ++-- .../writer2latex/api/ConverterFactory.java | 4 ++-- .../writer2latex/api/ConverterResult.java | 10 ++++++-- .../base/ConverterResultImpl.java | 15 +++++++++++- source/java/writer2latex/epub/OPFWriter.java | 24 ++++++++++++++++--- source/java/writer2latex/xhtml/Converter.java | 18 +++++++++----- .../writer2latex/xhtml/DrawConverter.java | 10 +++++--- 8 files changed, 72 insertions(+), 22 deletions(-) diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index 4ddc128..7d6b920 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -2,10 +2,12 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2 ---------- version 1.1.8 ---------- -[w2x] New option cover_image with values true and false (default). In EPUB export, if this option is set the true the very - first image found in the document is used as cover image +[w2x] EPUB bugfix: The meta data editor now shows the correct default creator (not the original creator) -[w2x] New option image_split with values "none" or a percentage. In EPUB export, if image_size is "relative", an image +[w2x] New option cover_image with values true and false (default). In EPUB export, if this option is set the true the very + first image found in the document is used as cover image. + +[w2x] New option image_split with values "none" or a percentage. In EPUB export an image of width greater than or equal to this percentage is placed in a separate file as a full screen image. This takes effect only if the aspect ratio is at least 3:4 diff --git a/source/java/org/openoffice/da/comp/writer2xhtml/EpubMetadataDialog.java b/source/java/org/openoffice/da/comp/writer2xhtml/EpubMetadataDialog.java index 7c74c3e..287082f 100644 --- a/source/java/org/openoffice/da/comp/writer2xhtml/EpubMetadataDialog.java +++ b/source/java/org/openoffice/da/comp/writer2xhtml/EpubMetadataDialog.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2011-03-05) + * Version 1.2 (2011-07-20) * */ @@ -606,7 +606,8 @@ public class EpubMetadataDialog extends DialogBase { } else { // Display the fall-back author String[] sAuthors = new String[1]; - sAuthors[0] = xDocumentProperties.getAuthor()+" (default creator)"; + //sAuthors[0] = xDocumentProperties.getAuthor()+" (default creator)"; + sAuthors[0] = xDocumentProperties.getModifiedBy()+" (default creator)"; setListBoxStringItemList("Authors", sAuthors); setControlEnabled("Authors", false); } diff --git a/source/java/writer2latex/api/ConverterFactory.java b/source/java/writer2latex/api/ConverterFactory.java index ec62e41..685cbe4 100644 --- a/source/java/writer2latex/api/ConverterFactory.java +++ b/source/java/writer2latex/api/ConverterFactory.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2011-06-19) + * Version 1.2 (2011-07-20) * */ @@ -33,7 +33,7 @@ public class ConverterFactory { // Version information private static final String VERSION = "1.1.8"; - private static final String DATE = "2011-06-19"; + private static final String DATE = "2011-07-20"; /** Return the Writer2LaTeX version in the form * (major version).(minor version).(patch level)
diff --git a/source/java/writer2latex/api/ConverterResult.java b/source/java/writer2latex/api/ConverterResult.java index e38af10..5f990de 100644 --- a/source/java/writer2latex/api/ConverterResult.java +++ b/source/java/writer2latex/api/ConverterResult.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2011-06-19) + * Version 1.2 (2011-07-20) * */ @@ -105,7 +105,13 @@ public interface ConverterResult { */ public ContentEntry getBibliographyFile(); - /** Get the entry which contains the cover image + /** Get the entry which contains the cover (which usually will contain a cover image) + * + * @return the entry or null if a cover does not exist + */ + public ContentEntry getCoverFile(); + + /** Get the entry which contains the actual cover image * * @return the entry or null if a cover image does not exist */ diff --git a/source/java/writer2latex/base/ConverterResultImpl.java b/source/java/writer2latex/base/ConverterResultImpl.java index e55a519..c308edb 100644 --- a/source/java/writer2latex/base/ConverterResultImpl.java +++ b/source/java/writer2latex/base/ConverterResultImpl.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * -* Version 1.2 (2011-06-19) +* Version 1.2 (2011-07-20) * */ @@ -53,6 +53,7 @@ public class ConverterResultImpl implements ConverterResult { private ContentEntry lotFile; private ContentEntry indexFile; private ContentEntry bibliographyFile; + private ContentEntry coverFile; private ContentEntry coverImageFile; private MetaData metaData = null; @@ -211,6 +212,18 @@ public class ConverterResultImpl implements ConverterResult { return bibliographyFile; } + /** Define the entry which contains the cover + * + * @param entry the entry + */ + public void setCoverFile(ContentEntry entry) { + coverFile = entry; + } + + public ContentEntry getCoverFile() { + return coverFile; + } + /** Define the entry which contains the cover image * * @param entry the entry diff --git a/source/java/writer2latex/epub/OPFWriter.java b/source/java/writer2latex/epub/OPFWriter.java index 2018004..283c19a 100644 --- a/source/java/writer2latex/epub/OPFWriter.java +++ b/source/java/writer2latex/epub/OPFWriter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * version 1.2 (2011-03-04) + * version 1.2 (2011-07-20) * */ @@ -225,7 +225,24 @@ public class OPFWriter extends NewDOMDocument { manifest.appendChild(item); item.setAttribute("href",Misc.makeHref(file.getFileName())); item.setAttribute("media-type", file.getMIMEType()); - if (file.isMasterDocument()) { + // Treat cover as recommended by Threepress consulting (http://blog.threepress.org/2009/11/20/best-practices-in-epub-cover-images/) + if (cr.getCoverFile()!=null && cr.getCoverFile().getFile()==file) { + item.setAttribute("id", "cover"); + + Element itemref = contentDOM.createElement("itemref"); + itemref.setAttribute("idref", "cover"); + itemref.setAttribute("linear", "no"); // maybe problematic + spine.appendChild(itemref); + } + else if (cr.getCoverImageFile()!=null && cr.getCoverImageFile().getFile()==file) { + item.setAttribute("id", "cover-image"); + + Element meta = contentDOM.createElement("meta"); + meta.setAttribute("name", "cover"); + meta.setAttribute("content", "cover-image"); + metadata.appendChild(meta); + } + else if (file.isMasterDocument()) { String sId = "text"+(++nMasterCount); item.setAttribute("id", sId); @@ -246,7 +263,8 @@ public class OPFWriter extends NewDOMDocument { // The guide may contain references to some fundamental structural components Element guide = contentDOM.createElement("guide"); - pack.appendChild(guide); + pack.appendChild(guide); + addGuideReference(contentDOM,guide,"cover",cr.getCoverFile()); addGuideReference(contentDOM,guide,"title-page",cr.getTitlePageFile()); addGuideReference(contentDOM,guide,"text",cr.getTextFile()); addGuideReference(contentDOM,guide,"toc",cr.getTocFile()); diff --git a/source/java/writer2latex/xhtml/Converter.java b/source/java/writer2latex/xhtml/Converter.java index 862042f..b2cacab 100644 --- a/source/java/writer2latex/xhtml/Converter.java +++ b/source/java/writer2latex/xhtml/Converter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2011-06-19) + * Version 1.2 (2011-07-20) * */ @@ -48,6 +48,7 @@ import org.w3c.dom.Text; 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; @@ -218,8 +219,12 @@ public class Converter extends ConverterBase { nAlphabeticalIndex = nOutFileIndex; } - protected void setCoverImageFile(String sTarget) { - converterResult.setCoverImageFile(new ContentEntryImpl("Cover image",0,htmlDoc,sTarget)); + protected void setCoverFile(String sTarget) { + converterResult.setCoverFile(new ContentEntryImpl("Cover",0,htmlDoc,sTarget)); + } + + protected void setCoverImageFile(OutputFile file, String sTarget) { + converterResult.setCoverImageFile(new ContentEntryImpl("Cover image",0,file,sTarget)); } protected Element createElement(String s) { return htmlDOM.createElement(s); } @@ -295,9 +300,10 @@ public class Converter extends ConverterBase { } else { ContentEntry firstHeading = converterResult.getContent().get(0); - // The title page is the first page, unless the first page starts with a heading - if (outFiles.get(0)!=firstHeading.getFile() || firstHeading.getTarget()!=null) { - converterResult.setTitlePageFile(new ContentEntryImpl("Title page", 1, outFiles.get(0), null)); + // The title page is the first page after the cover, unless the first page starts with a heading + int nFirstPage = converterResult.getCoverFile()!=null ? 1 : 0; + if (outFiles.get(nFirstPage)!=firstHeading.getFile() || firstHeading.getTarget()!=null) { + converterResult.setTitlePageFile(new ContentEntryImpl("Title page", 1, outFiles.get(nFirstPage), null)); } // The text page is the one containing the first heading converterResult.setTextFile(new ContentEntryImpl("Text", 1, firstHeading.getFile(), firstHeading.getTarget())); diff --git a/source/java/writer2latex/xhtml/DrawConverter.java b/source/java/writer2latex/xhtml/DrawConverter.java index 5a96d2a..1fc68e2 100644 --- a/source/java/writer2latex/xhtml/DrawConverter.java +++ b/source/java/writer2latex/xhtml/DrawConverter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2011-06-19) + * Version 1.2 (2011-07-20) * */ @@ -238,7 +238,7 @@ public class DrawConverter extends ConverterHelper { if (bCoverImage) { Element cover = ofr.getFirstImage(); if (cover!=null) { - converter.setCoverImageFile(null); + converter.setCoverFile(null); bCollectFullscreenFrames = false; handleDrawElement(cover,currentNode,null,FULL_SCREEN); bCollectFullscreenFrames = true; @@ -462,6 +462,10 @@ public class DrawConverter extends ConverterHelper { if (bgd!=null) { converter.addDocument(bgd); sFileName = bgd.getFileName(); + // If this is the cover image, add it to the converter result + if (bCoverImage && onode==ofr.getFirstImage()) { + converter.setCoverImageFile(bgd,null); + } } } @@ -472,7 +476,7 @@ public class DrawConverter extends ConverterHelper { 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) {