Support full screen images in EPUB export - bug fixing and adding the option image_split

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@111 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2011-06-16 20:18:47 +00:00
parent 0e45414378
commit 63e9c4c66d
11 changed files with 157 additions and 127 deletions

View file

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

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2011-06-14)
* Version 1.2 (2011-06-16)
*
*/
@ -96,6 +96,7 @@ public class DrawConverter extends ConverterHelper {
private String sScale;
private boolean bConvertToPx;
private int nImageSize;
private String sImageSplit;
// Frames in spreadsheet documents are collected here
private Vector<Element> frames = new Vector<Element>();
@ -120,6 +121,7 @@ public class DrawConverter extends ConverterHelper {
sScale = config.getXhtmlScaling();
bConvertToPx = config.xhtmlConvertToPx();
nImageSize = config.imageSize();
sImageSplit = config.imageSplit();
}
///////////////////////////////////////////////////////////////////////
@ -233,10 +235,10 @@ public class DrawConverter extends ConverterHelper {
Element currentFrame = hnode;
if (converter.isTopLevel() && !fullscreenFrames.isEmpty()) {
bCollectFullscreenFrames = false;
currentFrame = converter.nextOutFile();
currentFrame = getTextCv().doMaybeSplit(hnode, 0);
for (Element image : fullscreenFrames) {
handleDrawElement(image,currentFrame,null,FULL_SCREEN);
currentFrame = converter.nextOutFile();
currentFrame = getTextCv().doMaybeSplit(hnode, 0);
}
fullscreenFrames.clear();
bCollectFullscreenFrames = true;
@ -401,15 +403,16 @@ public class DrawConverter extends ConverterHelper {
// First check to see if we should treat this image as a "full screen" image
// This is only supported for EPUB documents with relative image size
// (Currently only images are handled like this, hence the code is here rather than in handleDrawElement)
if (bCollectFullscreenFrames && converter.isOPS() && nImageSize==XhtmlConfig.RELATIVE && converter.isTopLevel()) {
if (bCollectFullscreenFrames && converter.isOPS() && nImageSize==XhtmlConfig.RELATIVE && !"none".equals(sImageSplit)
&& converter.isTopLevel()) {
StyleWithProperties style = ofr.getFrameStyle(frame.getAttribute(XMLString.DRAW_STYLE_NAME));
String sWidth = getFrameWidth(frame, style);
String sHeight = getFrameHeight(frame, style);
// It is if the image width exceeds 30% of the current text width and the height is greater than 1.33*the width
// Values recommended by Michel "Coolmicro", should probably be configurable
// It is if the image width exceeds a certain percentage of the current text width and the height is
// greater than 1.33*the width (recommended by Michel "Coolmicro")
if (sWidth!=null && sHeight!=null &&
Misc.sub(Misc.multiply("133%",sWidth), sHeight).startsWith("-") &&
Misc.sub(Misc.multiply("30%",converter.getContentWidth()),
Misc.sub(Misc.multiply(sImageSplit,converter.getContentWidth()),
Misc.multiply(sScale,Misc.truncateLength(sWidth))).startsWith("-")) {
fullscreenFrames.add(onode);
return;
@ -458,7 +461,7 @@ public class DrawConverter extends ConverterHelper {
// Now style it
StyleInfo info = new StyleInfo();
String sStyleName = Misc.getAttribute(frame, XMLString.DRAW_STYLE_NAME);
getFrameSc().applyStyle(sStyleName,info);
if (nMode!=FULL_SCREEN) { getFrameSc().applyStyle(sStyleName,info); }
applyImageSize(frame,info.props,false);
// Apply placement
@ -511,6 +514,8 @@ public class DrawConverter extends ConverterHelper {
break;
case ABSOLUTE:
sContentWidth = applyImageSize(frame,info.props,false);
info.props.addValue("margin-left","auto");
info.props.addValue("margin-right","auto");
applyPosition(frame,info.props);
break;
case CENTERED:
@ -932,7 +937,9 @@ public class DrawConverter extends ConverterHelper {
else { // Full screen image
props.addValue("max-width","100%");
props.addValue("height","100%");
props.addValue("display","block");
props.addValue("margin-left","auto");
props.addValue("margin-right","auto");
}
return null;
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2011-06-14)
* Version 1.2 (2011-06-16)
*
*/
@ -499,8 +499,8 @@ public class TextConverter extends ConverterHelper {
// Remember if this was a heading
if (nDontSplitLevel==0) {
bAfterHeading = nodeName.equals(XMLString.TEXT_H);
hnode = getDrawCv().flushFullscreenFrames((Element)hnode);
}
hnode = getDrawCv().flushFullscreenFrames((Element)hnode);
}
i++;
}
@ -558,15 +558,15 @@ public class TextConverter extends ConverterHelper {
}
}
private Node doMaybeSplit(Node node, int nLevel) {
protected Element doMaybeSplit(Node node, int nLevel) {
if (nDontSplitLevel>1) { // we cannot split due to a nested structure
return node;
return (Element) node;
}
if (!converter.isOPS() && bAfterHeading && nLevel-nLastSplitLevel<=nRepeatLevels) {
// we cannot split because we are right after a heading and the
// maximum number of parent headings on the page is not reached
// TODO: Something wrong here....nLastSplitLevel is never set???
return node;
return (Element) node;
}
if (nSplit>=nLevel && converter.outFileHasContent()) {
// No objections, this is a level that causes splitting
@ -575,7 +575,7 @@ public class TextConverter extends ConverterHelper {
if (converter.getOutFileIndex()>=0) { insertFootnotes(node,false); }
return converter.nextOutFile();
}
return node;
return (Element) node;
}
/* Process a text:section tag (returns current html node) */
@ -817,6 +817,11 @@ public class TextConverter extends ConverterHelper {
par.appendChild( converter.createTextNode("\u00A0") );
sCurrentListLabel = null;
}
// Finally, in EPUB export, if the exported paragraph turns out to be empty, remove it
if (converter.isOPS() && !par.hasChildNodes()) {
hnode.removeChild(par);
}
}
private void prependAsapNode(Node node) {

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2011-03-16)
* Version 1.2 (2011-06-16)
*
*/
@ -41,7 +41,7 @@ import writer2latex.util.Misc;
public class XhtmlConfig extends writer2latex.base.ConfigBase {
// Implement configuration methods
protected int getOptionCount() { return 54; }
protected int getOptionCount() { return 55; }
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
// Override setOption: To be backwards compatible, we must accept options
@ -135,19 +135,20 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
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 CALC_SPLIT = 41;
private static final int DISPLAY_HIDDEN_SHEETS = 42;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 43;
private static final int DISPLAY_FILTERED_ROWS_COLS = 44;
private static final int APPLY_PRINT_RANGES = 45;
private static final int USE_TITLE_AS_HEADING = 46;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 47;
private static final int XSLT_PATH = 48;
private static final int SAVE_IMAGES_IN_SUBDIR = 49;
private static final int UPLINK = 50;
private static final int DIRECTORY_ICON = 51;
private static final int DOCUMENT_ICON = 52;
private static final int ZEN_HACK = 53; // temporary hack for ePub Zen Garden styles
private static final int IMAGE_SPLIT = 41;
private static final int CALC_SPLIT = 42;
private static final int DISPLAY_HIDDEN_SHEETS = 43;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 44;
private static final int DISPLAY_FILTERED_ROWS_COLS = 45;
private static final int APPLY_PRINT_RANGES = 46;
private static final int USE_TITLE_AS_HEADING = 47;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 48;
private static final int XSLT_PATH = 49;
private static final int SAVE_IMAGES_IN_SUBDIR = 50;
private static final int UPLINK = 51;
private static final int DIRECTORY_ICON = 52;
private static final int DOCUMENT_ICON = 53;
private static final int ZEN_HACK = 54; // temporary hack for ePub Zen Garden styles
protected ComplexOption xheading = addComplexOption("heading-map");
protected ComplexOption xpar = addComplexOption("paragraph-map");
@ -256,6 +257,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
nValue = Misc.getPosInteger(sValue, 0);
}
};
options[IMAGE_SPLIT] = new Option("image_split","none");
options[CALC_SPLIT] = new BooleanOption("calc_split","false");
options[DISPLAY_HIDDEN_SHEETS] = new BooleanOption("display_hidden_sheets", "false");
options[DISPLAY_HIDDEN_ROWS_COLS] = new BooleanOption("display_hidden_rows_cols","false");
@ -380,6 +382,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public int getXhtmlRepeatLevels() { return ((IntegerOption) options[REPEAT_LEVELS]).getValue(); }
public int pageBreakSplit() { return ((IntegerOption) options[PAGE_BREAK_SPLIT]).getValue(); }
public int splitAfter() { return ((IntegerOption) options[SPLIT_AFTER]).getValue(); }
public String imageSplit() { return options[IMAGE_SPLIT].getString(); }
public boolean xhtmlCalcSplit() { return ((BooleanOption) options[CALC_SPLIT]).getValue(); }
public boolean xhtmlDisplayHiddenSheets() { return ((BooleanOption) options[DISPLAY_HIDDEN_SHEETS]).getValue(); }
public boolean displayHiddenRowsCols() { return ((BooleanOption) options[DISPLAY_HIDDEN_ROWS_COLS]).getValue(); }