W2L help content, hiding postponed features, some bugfixes

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@64 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2010-05-17 07:42:33 +00:00
parent 83f0c7d224
commit 86e0b8d693
40 changed files with 885 additions and 142 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-05-11)
* Version 1.2 (2010-05-17)
*
*/
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information
private static final String VERSION = "1.1.3";
private static final String DATE = "2010-05-11";
private static final String DATE = "2010-05-17";
/** 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 (2010-03-30)
* version 1.2 (2010-05-13)
*
*/
@ -39,6 +39,7 @@ import org.w3c.dom.Element;
import writer2latex.api.ContentEntry;
import writer2latex.api.ConverterResult;
import writer2latex.util.Misc;
import writer2latex.xmerge.NewDOMDocument;
/** This class creates the required NXC file for an EPUB document
@ -141,7 +142,7 @@ public class NCXWriter extends NewDOMDocument {
Element navPointContent = contentDOM.createElement("content");
String sHref = entry.getFile().getFileName();
if (entry.getTarget()!=null) { sHref+="#"+entry.getTarget(); }
navPointContent.setAttribute("src", sHref);
navPointContent.setAttribute("src", Misc.makeHref(sHref));
navPoint.appendChild(navPointContent);
nDepth = Math.max(nDepth, nCurrentLevel);

View file

@ -20,14 +20,13 @@
*
* All Rights Reserved.
*
* version 1.2 (2010-03-29)
* version 1.2 (2010-05-13)
*
*/
package writer2latex.epub;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -41,6 +40,7 @@ import org.w3c.dom.Element;
import writer2latex.api.ContentEntry;
import writer2latex.api.ConverterResult;
import writer2latex.api.OutputFile;
import writer2latex.util.Misc;
import writer2latex.xmerge.NewDOMDocument;
/** This class writes an OPF-file for an EPUB document (see http://www.idpf.org/2007/opf/OPF_2.0_final_spec.html).
@ -105,7 +105,7 @@ public class OPFWriter extends NewDOMDocument {
OutputFile file = iterator.next();
Element item = contentDOM.createElement("item");
manifest.appendChild(item);
item.setAttribute("href",file.getFileName());
item.setAttribute("href",Misc.makeHref(file.getFileName()));
item.setAttribute("media-type", file.getMIMEType());
if (file.isMasterDocument()) {
String sId = "text"+(++nMasterCount);
@ -147,7 +147,7 @@ public class OPFWriter extends NewDOMDocument {
reference.setAttribute("title", entry.getTitle());
String sHref = entry.getFile().getFileName();
if (entry.getTarget()!=null) { sHref+="#"+entry.getTarget(); }
reference.setAttribute("href", sHref);
reference.setAttribute("href", Misc.makeHref(sHref));
guide.appendChild(reference);
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-05-04)
* Version 1.2 (2010-05-13)
*
*/
@ -99,15 +99,25 @@ public class ListCounter {
}
public String getLabel() {
return getPrefix()+getLabelAndSuffix();
}
public String getPrefix() {
if (style.isNumber(nLevel)) {
String sPrefix = style.getLevelProperty(nLevel,XMLString.STYLE_NUM_PREFIX);
return sPrefix!=null ? sPrefix : "";
}
return "";
}
public String getLabelAndSuffix() {
if (style.isNumber(nLevel)) {
String sLabel="";
if (sNumFormat[nLevel]==null) return "";
int nLevels = Misc.getPosInteger(style.getLevelProperty(nLevel,
XMLString.TEXT_DISPLAY_LEVELS),1);
String sPrefix = style.getLevelProperty(nLevel,XMLString.STYLE_NUM_PREFIX);
String sSuffix = style.getLevelProperty(nLevel,XMLString.STYLE_NUM_SUFFIX);
String sSpace = "nothing".equals(style.getLevelStyleProperty(nLevel, XMLString.TEXT_LABEL_FOLLOWED_BY)) ? "" : " ";
String sLabel="";
if (sPrefix!=null) { sLabel+=sPrefix; }
for (int j=nLevel-nLevels+1; j<nLevel; j++) {
sLabel+=formatNumber(nCounter[j],sNumFormat[j],true)+".";
}
@ -122,7 +132,7 @@ public class ListCounter {
}
else {
return "";
}
}
}
// Utility method to generate number

View file

@ -16,17 +16,18 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-22)
* Version 1.2 (2010-05-17)
*
*/
package writer2latex.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@ -331,6 +332,22 @@ public class Misc{
}
return "error";
}
/* utility method to convert a *relative* URL to a file name
(ie. replace %20 with spaces etc.)
*/
public static String makeFileName(String sURL) {
try {
File file = new File(new java.net.URI("file:///"+sURL));
return file.getName();
}
catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/** <p>Read an <code>InputStream</code> into a <code>byte</code>array</p>
* @param is the <code>InputStream</code> to read

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-05-09)
* Version 1.2 (2010-05-17)
*
*/
@ -227,10 +227,12 @@ public class Converter extends ConverterBase {
converterResult.addContentEntry(new ContentEntryImpl("Text", 1, outFiles.get(0), null));
}
else {
// The title page is the first page
converterResult.setTitlePageFile(new ContentEntryImpl("Title page", 1, outFiles.get(0), null));
// The text page is the one containing the first heading
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 text page is the one containing the first heading
converterResult.setTextFile(new ContentEntryImpl("Text", 1, firstHeading.getFile(), firstHeading.getTarget()));
}
@ -397,7 +399,6 @@ public class Converter extends ConverterBase {
if (nIndex>=0 && nIndex<=nOutFileIndex) {
Element a = dom.createElement("a");
a.setAttribute("href",Misc.makeHref(getOutFileName(nIndex,true)));
a.setAttribute("href",getOutFileName(nIndex,true));
a.appendChild(dom.createTextNode(s));
//node.appendChild(dom.createTextNode("["));
node.appendChild(a);

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-03-03)
* Version 1.2 (2010-05-13)
*
*/
@ -376,12 +376,14 @@ public class DrawConverter extends ConverterHelper {
if (sHref!=null && sHref.length()>0 && !ofr.isInPackage(sHref)) {
// Linked image is not yet handled by ImageLoader. This is a temp.
// solution (will go away when ImageLoader is finished)
sFileName = sHref;
// In OpenDocument *package* format ../ means "leave the package"
if (ofr.isOpenDocument() && ofr.isPackageFormat() && sFileName.startsWith("../")) {
sFileName=sFileName.substring(3);
}
//String sExt = sHref.substring(sHref.lastIndexOf(".")).toLowerCase();
if (!converter.isOPS()) { // Cannot have linked images in EPUB, ignore the image
sFileName = sHref;
// In OpenDocument *package* format ../ means "leave the package"
if (ofr.isOpenDocument() && ofr.isPackageFormat() && sFileName.startsWith("../")) {
sFileName=sFileName.substring(3);
}
//String sExt = sHref.substring(sHref.lastIndexOf(".")).toLowerCase();
}
}
else { // embedded or base64 encoded image
BinaryGraphicsDocument bgd = converter.getImageLoader().getImage(onode);

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-05-09)
* Version 1.2 (2010-05-13)
*
*/
@ -80,6 +80,7 @@ public class ParStyleConverter extends StyleWithPropertiesConverterHelper {
* @param bInherit true if properties should be inherited from parent style(s)
*/
public void applyProperties(StyleWithProperties style, CSVList props, boolean bInherit) {
cssPageBreak(style,props,bInherit);
getFrameSc().cssMargins(style,props,bInherit);
getFrameSc().cssBorder(style,props,bInherit);
getFrameSc().cssPadding(style,props,bInherit);
@ -104,6 +105,15 @@ public class ParStyleConverter extends StyleWithPropertiesConverterHelper {
if (style==null || !style.isAutomatic()) { return sStyleName; }
return style.getParentName();
}
public void cssPageBreak(StyleWithProperties style, CSVList props, boolean bInherit) {
if ("page".equals(style.getProperty(XMLString.FO_BREAK_BEFORE, bInherit))) {
props.addValue("page-break-before", "always");
}
else if ("page".equals(style.getProperty(XMLString.FO_BREAK_AFTER, bInherit))) {
props.addValue("page-break-after", "always");
}
}
public void cssPar(StyleWithProperties style, CSVList props, boolean bInherit){
String s;

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-09-08)
* Version 1.2 (2010-05-13)
*
*/
@ -74,6 +74,8 @@ public class TableStyleConverter extends StyleWithPropertiesConverterHelper {
* @param bInherit true if properties should be inherited from parent style(s)
*/
public void applyProperties(StyleWithProperties style, CSVList props, boolean bInherit) {
// Page break
getParSc().cssPageBreak(style, props, bInherit);
// Apply background
getFrameSc().cssBackground(style,props,bInherit);
// Table-specific properties

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-05-09)
* Version 1.2 (2010-05-13)
*
*/
@ -470,9 +470,10 @@ public class TextConverter extends ConverterHelper {
if (nDontSplitLevel>1) { // we cannot split due to a nested structure
return node;
}
if (bAfterHeading && nLevel-nLastSplitLevel<=nRepeatLevels) {
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
// maximum number of parent headings on the page is not reached
// TODO: Something wrong here....nLastSplitLevel is never set???
return node;
}
if (nSplit>=nLevel && converter.outFileHasContent()) {
@ -562,7 +563,14 @@ public class TextConverter extends ConverterHelper {
ListCounter counter = getListCounter(listStyle);
if (bRestart) { counter.restart(nListLevel,nStartValue); }
String sLabel = counter.step(nListLevel).getLabel();
insertListLabel(listStyle,nListLevel,"SectionNumber",sLabel,heading);
if (config.zenHack() && nLevel==2) {
// Hack for ePub Zen Garden: Special style for the prefix at level 2
// TODO: Replace by some proper style map construct...
insertListLabel(listStyle,nListLevel,"SectionNumber",counter.getPrefix(),counter.getLabelAndSuffix(),heading);
}
else {
insertListLabel(listStyle,nListLevel,"SectionNumber",null,sLabel,heading);
}
// Add to toc
if (!bInToc) {
@ -642,7 +650,7 @@ public class TextConverter extends ConverterHelper {
if (!bIsEmpty) {
par = createTextBackground(par, sStyleName);
if (config.listFormatting()==XhtmlConfig.HARD_LABELS) {
insertListLabel(currentListStyle, nCurrentListLevel, "ItemNumber", sCurrentListLabel, par);
insertListLabel(currentListStyle, nCurrentListLevel, "ItemNumber", null, sCurrentListLabel, par);
}
sCurrentListLabel = null;
traverseInlineText(onode,par);
@ -694,8 +702,14 @@ public class TextConverter extends ConverterHelper {
}
// Helper: Insert a list label formatted with a list style
private void insertListLabel(ListStyle style, int nLevel, String sDefaultStyle, String sLabel, Element hnode) {
private void insertListLabel(ListStyle style, int nLevel, String sDefaultStyle, String sPrefix, String sLabel, Element hnode) {
if (sLabel!=null && sLabel.length()>0) {
if (sPrefix!=null) {
Element prefix = converter.createElement("span");
prefix.setAttribute("class", "chapter-name");
hnode.appendChild(prefix);
prefix.appendChild( converter.createTextNode(sPrefix));
}
StyleInfo info = new StyleInfo();
if (style!=null) {
String sTextStyleName = style.getLevelProperty(nLevel,XMLString.TEXT_STYLE_NAME);

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-05-09)
* Version 1.2 (2010-05-13)
*
*/
@ -41,7 +41,7 @@ import writer2latex.util.Misc;
public class XhtmlConfig extends writer2latex.base.ConfigBase {
// Implement configuration methods
protected int getOptionCount() { return 42; }
protected int getOptionCount() { return 43; }
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
// Override setOption: To be backwards compatible, we must accept options
@ -119,6 +119,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
private static final int UPLINK = 39;
private static final int DIRECTORY_ICON = 40;
private static final int DOCUMENT_ICON = 41;
private static final int ZEN_HACK = 42; // temporary hack for ePub Zen Garden styles
protected ComplexOption xheading = addComplexOption("heading-map");
protected ComplexOption xpar = addComplexOption("paragraph-map");
@ -197,6 +198,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
options[UPLINK] = new Option("uplink","");
options[DIRECTORY_ICON] = new Option("directory_icon","");
options[DOCUMENT_ICON] = new Option("document_icon","");
options[ZEN_HACK] = new BooleanOption("zen_hack", "false");
}
protected void readInner(Element elm) {
@ -309,6 +311,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public String getXhtmlUplink() { return options[UPLINK].getString(); }
public String getXhtmlDirectoryIcon() { return options[DIRECTORY_ICON].getString(); }
public String getXhtmlDocumentIcon() { return options[DOCUMENT_ICON].getString(); }
public boolean zenHack() { return ((BooleanOption) options[ZEN_HACK]).getValue(); }
public XhtmlStyleMap getXParStyleMap() { return getStyleMap(xpar); }
public XhtmlStyleMap getXHeadingStyleMap() { return getStyleMap(xheading); }