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
This commit is contained in:
henrikjust 2011-07-20 11:06:01 +00:00
parent e09d61f6ee
commit 755db936f2
8 changed files with 72 additions and 22 deletions

View file

@ -2,10 +2,12 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2
---------- version 1.1.8 ---------- ---------- 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 [w2x] EPUB bugfix: The meta data editor now shows the correct default creator (not the original creator)
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, 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. 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 This takes effect only if the aspect ratio is at least 3:4

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * 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 else { // Display the fall-back author
String[] sAuthors = new String[1]; 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); setListBoxStringItemList("Authors", sAuthors);
setControlEnabled("Authors", false); setControlEnabled("Authors", false);
} }

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2011-06-19) * Version 1.2 (2011-07-20)
* *
*/ */
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information // Version information
private static final String VERSION = "1.1.8"; 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 /** Return the Writer2LaTeX version in the form
* (major version).(minor version).(patch level)<br/> * (major version).(minor version).(patch level)<br/>

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * 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(); 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 * @return the entry or null if a cover image does not exist
*/ */

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * 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 lotFile;
private ContentEntry indexFile; private ContentEntry indexFile;
private ContentEntry bibliographyFile; private ContentEntry bibliographyFile;
private ContentEntry coverFile;
private ContentEntry coverImageFile; private ContentEntry coverImageFile;
private MetaData metaData = null; private MetaData metaData = null;
@ -211,6 +212,18 @@ public class ConverterResultImpl implements ConverterResult {
return bibliographyFile; 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 /** Define the entry which contains the cover image
* *
* @param entry the entry * @param entry the entry

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * 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); manifest.appendChild(item);
item.setAttribute("href",Misc.makeHref(file.getFileName())); item.setAttribute("href",Misc.makeHref(file.getFileName()));
item.setAttribute("media-type", file.getMIMEType()); 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); String sId = "text"+(++nMasterCount);
item.setAttribute("id", sId); item.setAttribute("id", sId);
@ -246,7 +263,8 @@ public class OPFWriter extends NewDOMDocument {
// The guide may contain references to some fundamental structural components // The guide may contain references to some fundamental structural components
Element guide = contentDOM.createElement("guide"); 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,"title-page",cr.getTitlePageFile());
addGuideReference(contentDOM,guide,"text",cr.getTextFile()); addGuideReference(contentDOM,guide,"text",cr.getTextFile());
addGuideReference(contentDOM,guide,"toc",cr.getTocFile()); addGuideReference(contentDOM,guide,"toc",cr.getTocFile());

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * 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.Config;
import writer2latex.api.ContentEntry; import writer2latex.api.ContentEntry;
import writer2latex.api.ConverterFactory; import writer2latex.api.ConverterFactory;
import writer2latex.api.OutputFile;
//import writer2latex.api.ConverterResult; //import writer2latex.api.ConverterResult;
import writer2latex.base.ContentEntryImpl; import writer2latex.base.ContentEntryImpl;
import writer2latex.base.ConverterBase; import writer2latex.base.ConverterBase;
@ -218,8 +219,12 @@ public class Converter extends ConverterBase {
nAlphabeticalIndex = nOutFileIndex; nAlphabeticalIndex = nOutFileIndex;
} }
protected void setCoverImageFile(String sTarget) { protected void setCoverFile(String sTarget) {
converterResult.setCoverImageFile(new ContentEntryImpl("Cover image",0,htmlDoc,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); } protected Element createElement(String s) { return htmlDOM.createElement(s); }
@ -295,9 +300,10 @@ public class Converter extends ConverterBase {
} }
else { else {
ContentEntry firstHeading = converterResult.getContent().get(0); ContentEntry firstHeading = converterResult.getContent().get(0);
// The title page is the first page, unless the first page starts with a heading // The title page is the first page after the cover, unless the first page starts with a heading
if (outFiles.get(0)!=firstHeading.getFile() || firstHeading.getTarget()!=null) { int nFirstPage = converterResult.getCoverFile()!=null ? 1 : 0;
converterResult.setTitlePageFile(new ContentEntryImpl("Title page", 1, outFiles.get(0), null)); 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 // The text page is the one containing the first heading
converterResult.setTextFile(new ContentEntryImpl("Text", 1, firstHeading.getFile(), firstHeading.getTarget())); converterResult.setTextFile(new ContentEntryImpl("Text", 1, firstHeading.getFile(), firstHeading.getTarget()));

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * 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) { if (bCoverImage) {
Element cover = ofr.getFirstImage(); Element cover = ofr.getFirstImage();
if (cover!=null) { if (cover!=null) {
converter.setCoverImageFile(null); converter.setCoverFile(null);
bCollectFullscreenFrames = false; bCollectFullscreenFrames = false;
handleDrawElement(cover,currentNode,null,FULL_SCREEN); handleDrawElement(cover,currentNode,null,FULL_SCREEN);
bCollectFullscreenFrames = true; bCollectFullscreenFrames = true;
@ -462,6 +462,10 @@ public class DrawConverter extends ConverterHelper {
if (bgd!=null) { if (bgd!=null) {
converter.addDocument(bgd); converter.addDocument(bgd);
sFileName = bgd.getFileName(); 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); String sName = Misc.getAttribute(getFrame(onode),XMLString.DRAW_NAME);
converter.addTarget(image,sName+"|graphic"); converter.addTarget(image,sName+"|graphic");
image.setAttribute("src",sFileName); image.setAttribute("src",sFileName);
// Add alternative text, using either alt.text, name or file name // Add alternative text, using either alt.text, name or file name
Element desc = Misc.getChildByTagName(frame,XMLString.SVG_DESC); Element desc = Misc.getChildByTagName(frame,XMLString.SVG_DESC);
if (desc==null) { if (desc==null) {