W2L custom config ui refactoring + some LaTeX and EPUB fixes

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@78 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2010-12-08 09:16:49 +00:00
parent a3a6b0befc
commit 84f4d5cb20
12 changed files with 834 additions and 917 deletions

View file

@ -2,6 +2,17 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2
---------- version 1.1.9 ----------
[w2x] In EPUB export, convert_to_px=true now (despite the name) exports relative font sizes
[w2l] Custom config ui is now refactored to use ConfigurationDialogBase, fixing some minor bugs
[w2l] String replace now also works with XeTeX as backend
[w2l] Bugfix: The verbatim attribute for character style maps now also works if formatting=ignore_all
[w2x] New option external_toc_depth to set the number of levels to include in the external table of contents
in EPUB export (default value is "auto", which determines the depth from the split level)
[w2x] New option page_break_split with values none (default), styles (split on page breaks defined by a style),
explicit (split on all explicit page breaks, manual or defined by a style), all (split on all page breaks, including
soft page breaks (will not split until current paragraph, table or list is finished))

Binary file not shown.

View file

@ -577,7 +577,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
private String sCurrentStyleName = null;
// Access to display names of the styles in the current document
private StyleNameProvider styleNameProvider = null;
protected StyleNameProvider styleNameProvider = null;
// Some methods to be implemented by the subclass
protected abstract String getDefaultConfigName();

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-11-21)
* Version 1.2 (2010-12-08)
*
*/
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information
private static final String VERSION = "1.1.9";
private static final String DATE = "2010-11-22";
private static final String DATE = "2010-12-08";
/** Return the Writer2LaTeX version in the form
* (major version).(minor version).(patch level)<br/>

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-12-03)
* Version 1.2 (2010-11-28)
*
*/
@ -97,6 +97,8 @@ public class CharStyleConverter extends StyleConverter {
StyleMap sm = config.getTextStyleMap();
if (sm.contains(sDisplayName)) {
ba.add(sm.getBefore(sDisplayName),sm.getAfter(sDisplayName));
context.setVerbatim(sm.getVerbatim(sDisplayName));
context.setNoLineBreaks(sm.getVerbatim(sDisplayName));
}
return;
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-11-21)
* Version 1.2 (2010-11-30)
*
*/
@ -85,32 +85,43 @@ public class XeTeXI18n extends I18n {
/** Convert a string of characters into LaTeX
* @param s the source string
* @param bMathMode true if the string should be rendered in math mode
* @param sLang the iso language of the string
* @param sLang the ISO language of the string
* @return the LaTeX string
*/
public String convert(String s, boolean bMathMode, String sLang){
// TODO: Do we need anything special for math mode?
StringBuffer buf = new StringBuffer();
int nLen = s.length();
char c;
for (int i=0; i<nLen; i++) {
c = s.charAt(i);
switch (c) {
case '#' : buf.append("\\#"); break; // Parameter
case '$' : buf.append("\\$"); break; // Math shift
case '%' : buf.append("\\%"); break; // Comment
case '&' : buf.append("\\&"); break; // Alignment tab
case '\\' : buf.append("\\textbackslash{}"); break; // Escape
case '^' : buf.append("\\^{}"); break; // Superscript
case '_' : buf.append("\\_"); break; // Subscript
case '{' : buf.append("\\{"); break; // Begin group
case '}' : buf.append("\\}"); break; // End group
case '~' : buf.append("\\textasciitilde{}"); break; // Active (non-breaking space)
case '\u00A0' : buf.append('~'); break; // Make non-breaking spaces visible
default: buf.append(c);
}
}
char c;
int nLen = s.length();
int i = 0;
while (i<nLen) {
ReplacementTrieNode node = stringReplace.get(s,i,nLen);
if (node!=null) {
buf.append(node.getLaTeXCode());
i += node.getInputLength();
}
else {
c = s.charAt(i++);
switch (c) {
case '#' : buf.append("\\#"); break; // Parameter
case '$' : buf.append("\\$"); break; // Math shift
case '%' : buf.append("\\%"); break; // Comment
case '&' : buf.append("\\&"); break; // Alignment tab
case '\\' : buf.append("\\textbackslash{}"); break; // Escape
case '^' : buf.append("\\^{}"); break; // Superscript
case '_' : buf.append("\\_"); break; // Subscript
case '{' : buf.append("\\{"); break; // Begin group
case '}' : buf.append("\\}"); break; // End group
case '~' : buf.append("\\textasciitilde{}"); break; // Active (non-breaking space)
case '\u00A0' : buf.append('~'); break; // Make non-breaking spaces visible
default: buf.append(c);
}
}
}
return buf.toString();
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-10-30)
* Version 1.2 (2010-12-08)
*
*/
@ -159,7 +159,7 @@ public class Misc{
return n;
}
public static int min(int n, int m) { return n<m ? n : m; }
//public static int min(int n, int m) { return n<m ? n : m; }
public static String truncateLength(String sValue) {
if (sValue.endsWith("inch")) {
@ -201,6 +201,25 @@ public class Misc{
}
}
// Divide dividend by divisor and return the quotient as an integer percentage
// (never below 1% except if the dividend is zero)
public static final String divide(String sDividend, String sDivisor) {
if (sDividend.equals("0")) { return "0%"; }
if (sDivisor.equals("0")) { return "100%"; }
float fDividend=getFloat(sDividend.substring(0,sDividend.length()-2),1);
String sDividendUnit=sDividend.substring(sDividend.length()-2);
float fDivisor=getFloat(sDivisor.substring(0,sDivisor.length()-2),1);
String sDivisorUnit=sDivisor.substring(sDivisor.length()-2);
int nPercent = Math.round(100*fDividend*getUpi(sDivisorUnit)/fDivisor/getUpi(sDividendUnit));
if (nPercent>0) {
return Integer.toString(nPercent)+"%";
}
else {
return "1%";
}
}
public static final String multiply(String sPercent, String sLength){
if (sLength.equals("0")) { return "0"; }
float fPercent=getFloat(sPercent.substring(0,sPercent.length()-1),1);

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-11-22)
* Version 1.2 (2010-11-28)
*
*/
@ -86,7 +86,8 @@ public class TextConverter extends ConverterHelper {
private static final int EPUB_CHARACTER_COUNT_TRESHOLD = 150000;
private int nPageBreakSplit = XhtmlConfig.NONE; // Should we split at page breaks?
// TODO: Collect soft page breaks between table rows
private boolean bPendingPageBreak = false; // We have encountered a page break which should be inserted asap
private boolean bPendingPageBreak = false; // We have encountered a page break which should be inserted asap
private int nExternalTocDepth = 1; // The number of levels to include in the "external" table of contents
private int nSplit = 0; // The outline level at which to split files (0=no split)
private int nRepeatLevels = 5; // The number of levels to repeat when splitting (0=no repeat)
private int nLastSplitLevel = 1; // The outline level at which the last split occurred
@ -147,6 +148,10 @@ public class TextConverter extends ConverterHelper {
nPageBreakSplit = config.pageBreakSplit();
nSplit = config.getXhtmlSplitLevel();
nRepeatLevels = config.getXhtmlRepeatLevels();
nExternalTocDepth = config.externalTocDepth();
if (nExternalTocDepth==0) { // A value of zero means auto (i.e. determine from split level)
nExternalTocDepth = Math.max(nSplit,1);
}
nFloatMode = ofr.isText() && config.xhtmlFloatObjects() ?
DrawConverter.FLOATING : DrawConverter.ABSOLUTE;
outlineNumbering = new ListCounter(ofr.getOutlineStyle());
@ -674,10 +679,10 @@ public class TextConverter extends ConverterHelper {
converter.addTarget(heading,sTarget);
// Add in external content. For single file output we include all level 1 headings + their target
// For multi-file output, the included heading levels depends on the split leve, and we don't include targets
if (nLevel<=Math.max(nSplit,1)) {
// Targets are added only when the toc level is deeper than the split level
if (nLevel<=nExternalTocDepth) {
converter.addContentEntry(sLabel+(sLabel.length()>0 ? " " : "")+converter.getPlainInlineText(onode), nLevel,
nSplit==0 ? sTarget : null);
nLevel>nSplit ? sTarget : null);
}
// Add to real toc

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-03-12)
* Version 1.2 (2010-12-08)
*
*/
@ -63,6 +63,10 @@ public class TextStyleConverter extends StyleWithPropertiesConverterHelper {
private Hashtable<String, String> anchorCombinedStyleNames = new Hashtable<String, String>();
private Hashtable<String, String> orgAnchorStyleNames = new Hashtable<String, String>();
private Hashtable<String, String> orgAnchorVisitedStyleNames = new Hashtable<String, String>();
// Export font sizes as percentages?
private boolean bRelativeFontSize = false;
private String sBaseFontSize = "12pt";
/** Create a new <code>TextStyleConverter</code>
* @param ofr an <code>OfficeReader</code> to read style information from
@ -75,6 +79,14 @@ public class TextStyleConverter extends StyleWithPropertiesConverterHelper {
this.styleMap = config.getXTextStyleMap();
this.bConvertStyles = config.xhtmlFormatting()==XhtmlConfig.CONVERT_ALL || config.xhtmlFormatting()==XhtmlConfig.IGNORE_HARD;
this.bConvertHard = config.xhtmlFormatting()==XhtmlConfig.CONVERT_ALL || config.xhtmlFormatting()==XhtmlConfig.IGNORE_STYLES;
this.bRelativeFontSize = converter.isOPS() && config.xhtmlConvertToPx();
StyleWithProperties defaultStyle = ofr.getDefaultParStyle();
if (defaultStyle!=null) {
String sFontSize = defaultStyle.getProperty(XMLString.FO_FONT_SIZE,false);
if (sFontSize!=null) {
sBaseFontSize = sFontSize;
}
}
}
/** Apply a link style, using a combination of two text styles
@ -298,14 +310,30 @@ public class TextStyleConverter extends StyleWithPropertiesConverterHelper {
else { // one value
s3 = s2; s4="100%";
}
if (s!=null) { props.addValue("font-size",Misc.multiply(s4,scale(s))); }
else { props.addValue("font-size",s4); }
if (s!=null) {
if (bRelativeFontSize) {
String sFontSize = Misc.divide(Misc.multiply(s4,s), sBaseFontSize);
if (!"100%".equals(sFontSize)) props.addValue("font-size", sFontSize);
}
else {
props.addValue("font-size",Misc.multiply(s4,scale(s)));
}
}
else {
props.addValue("font-size",s4);
}
if (!"0%".equals(s3)) {
props.addValue("vertical-align",s3);
}
}
else if (s!=null) {
props.addValue("font-size",scale(s));
if (bRelativeFontSize) {
String sFontSize = Misc.divide(s,sBaseFontSize);
if (!"100%".equals(sFontSize)) props.addValue("font-size", sFontSize);
}
else {
props.addValue("font-size",scale(s));
}
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-11-22)
* Version 1.2 (2010-11-28)
*
*/
@ -41,7 +41,7 @@ import writer2latex.util.Misc;
public class XhtmlConfig extends writer2latex.base.ConfigBase {
// Implement configuration methods
protected int getOptionCount() { return 46; }
protected int getOptionCount() { return 47; }
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
// Override setOption: To be backwards compatible, we must accept options
@ -70,7 +70,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public static final int CSS1_HACK = 1;
public static final int HARD_LABELS = 2;
// Formulas (for xhtml 1.0 strict)
// Formulas (for XHTML 1.0 strict)
public static final int STARMATH = 0;
public static final int LATEX = 1;
public static final int IMAGE_STARMATH = 2;
@ -113,22 +113,23 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
private static final int TABSTOP_STYLE = 27;
private static final int FORMULAS = 28;
private static final int ENDNOTES_HEADING = 29;
private static final int SPLIT_LEVEL = 30;
private static final int REPEAT_LEVELS = 31;
private static final int PAGE_BREAK_SPLIT = 32;
private static final int CALC_SPLIT = 33;
private static final int DISPLAY_HIDDEN_SHEETS = 34;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 35;
private static final int DISPLAY_FILTERED_ROWS_COLS = 36;
private static final int APPLY_PRINT_RANGES = 37;
private static final int USE_TITLE_AS_HEADING = 38;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 39;
private static final int XSLT_PATH = 40;
private static final int SAVE_IMAGES_IN_SUBDIR = 41;
private static final int UPLINK = 42;
private static final int DIRECTORY_ICON = 43;
private static final int DOCUMENT_ICON = 44;
private static final int ZEN_HACK = 45; // temporary hack for ePub Zen Garden styles
private static final int EXTERNAL_TOC_DEPTH = 30;
private static final int SPLIT_LEVEL = 31;
private static final int REPEAT_LEVELS = 32;
private static final int PAGE_BREAK_SPLIT = 33;
private static final int CALC_SPLIT = 34;
private static final int DISPLAY_HIDDEN_SHEETS = 35;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 36;
private static final int DISPLAY_FILTERED_ROWS_COLS = 37;
private static final int APPLY_PRINT_RANGES = 38;
private static final int USE_TITLE_AS_HEADING = 39;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 40;
private static final int XSLT_PATH = 41;
private static final int SAVE_IMAGES_IN_SUBDIR = 42;
private static final int UPLINK = 43;
private static final int DIRECTORY_ICON = 44;
private static final int DOCUMENT_ICON = 45;
private static final int ZEN_HACK = 46; // temporary hack for ePub Zen Garden styles
protected ComplexOption xheading = addComplexOption("heading-map");
protected ComplexOption xpar = addComplexOption("paragraph-map");
@ -185,6 +186,17 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
else { nValue = IMAGE_STARMATH; }
}
};
options[EXTERNAL_TOC_DEPTH] = new IntegerOption("external_toc_depth","auto") {
@Override public void setString(String sValue) {
super.setString(sValue);
if ("auto".equals(sValue)) {
nValue = 0;
}
else {
nValue = Misc.getPosInteger(sValue,1);
}
}
};
options[SPLIT_LEVEL] = new IntegerOption("split_level","0") {
@Override public void setString(String sValue) {
super.setString(sValue);
@ -319,6 +331,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public String getXhtmlTabstopStyle() { return options[TABSTOP_STYLE].getString(); }
public String getEndnotesHeading() { return options[ENDNOTES_HEADING].getString(); }
public int formulas() { return ((IntegerOption) options[FORMULAS]).getValue(); }
public int externalTocDepth() { return ((IntegerOption) options[EXTERNAL_TOC_DEPTH]).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(); }

View file

@ -79,7 +79,9 @@
<paragraph role="heading" level="3" xml-lang="en-US">Convert units to px (pixels)</paragraph>
<paragraph role="paragraph" xml-lang="en-US">In %PRODUCTNAME, font sizes are usually given in points and other dimensions
in e.g. cm or inches. For XHTML it is recommended to use the unit px instead, and using this option you can require that
all dimensions are converted to px. If you choose not to check this option,the original units will always be used.</paragraph>
all dimensions are converted to px. For EPUB it is recommended to use relative font sizes, and using this option will
export all font sizes as percentages (and use px for all other dimensions).</paragraph>
<paragraph role="paragraph" xml-lang="en-US">If you choose not to check this option,the original units will always be used.</paragraph>
</section>
<bookmark xml-lang="en-US" branch="hid/org.openoffice.da.writer2xhtml.oxt:OptionsOriginalImageSize" id="bm_options_originalimagesize"/>