W2L display equations + W2X list numbering enhancements

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@61 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2010-05-04 08:25:15 +00:00
parent 0e243c0ad7
commit 54a7c265f2
11 changed files with 231 additions and 103 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-03-01)
* Version 1.2 (2010-05-04)
*
*/
@ -102,6 +102,18 @@ public class ListStyleConverter extends StyleConverterHelper {
buf.append(props.toString());
buf.append("}");
buf.append(config.prettyPrint() ? "\n" : " ");
if (config.useHardListNumbering()) {
// Apply left margin and text indent to the paragraphs contained in the list
CSVList parProps = new CSVList(";");
cssListParMargins(style,nLevel,parProps);
if (!parProps.isEmpty()) {
buf.append(sIndent)
.append(".listlevel")
.append(nLevel)
.append(styleNames.getExportName(sDisplayName))
.append(" p {").append(parProps.toString()).append("}").append(config.prettyPrint() ? "\n" : " ");
}
}
}
}
}
@ -125,33 +137,73 @@ public class ListStyleConverter extends StyleConverterHelper {
// so we will stick with the simpler CSS1-like list style properties
props.addValue("margin-top","0");
props.addValue("margin-bottom","0");
String sLevelType = style.getLevelType(nLevel);
if (XMLString.TEXT_LIST_LEVEL_STYLE_NUMBER.equals(sLevelType)) {
// Numbering style, get number format
String sNumFormat = style.getLevelProperty(nLevel,XMLString.STYLE_NUM_FORMAT);
if ("1".equals(sNumFormat)) { props.addValue("list-style-type","decimal"); }
else if ("i".equals(sNumFormat)) { props.addValue("list-style-type","lower-roman"); }
else if ("I".equals(sNumFormat)) { props.addValue("list-style-type","upper-roman"); }
else if ("a".equals(sNumFormat)) { props.addValue("list-style-type","lower-alpha"); }
else if ("A".equals(sNumFormat)) { props.addValue("list-style-type","upper-alpha"); }
if (!config.useHardListNumbering()) {
// Export the numbering to CSS1
String sLevelType = style.getLevelType(nLevel);
if (XMLString.TEXT_LIST_LEVEL_STYLE_NUMBER.equals(sLevelType)) {
// Numbering style, get number format
String sNumFormat = style.getLevelProperty(nLevel,XMLString.STYLE_NUM_FORMAT);
if ("1".equals(sNumFormat)) { props.addValue("list-style-type","decimal"); }
else if ("i".equals(sNumFormat)) { props.addValue("list-style-type","lower-roman"); }
else if ("I".equals(sNumFormat)) { props.addValue("list-style-type","upper-roman"); }
else if ("a".equals(sNumFormat)) { props.addValue("list-style-type","lower-alpha"); }
else if ("A".equals(sNumFormat)) { props.addValue("list-style-type","upper-alpha"); }
}
else if (XMLString.TEXT_LIST_LEVEL_STYLE_BULLET.equals(sLevelType)) {
// Bullet. We can only choose from disc, bullet and square
switch (nLevel % 3) {
case 1: props.addValue("list-style-type","disc"); break;
case 2: props.addValue("list-style-type","bullet"); break;
case 0: props.addValue("list-style-type","square"); break;
}
}
else if (XMLString.TEXT_LIST_LEVEL_STYLE_IMAGE.equals(sLevelType)) {
// Image. TODO: Handle embedded images
String sHref = style.getLevelProperty(nLevel,XMLString.XLINK_HREF);
if (sHref!=null) { props.addValue("list-style-image","url('"+sHref+"')"); }
}
}
else if (XMLString.TEXT_LIST_LEVEL_STYLE_BULLET.equals(sLevelType)) {
// Bullet. We can only choose from disc, bullet and square
switch (nLevel % 3) {
case 1: props.addValue("list-style-type","disc"); break;
case 2: props.addValue("list-style-type","bullet"); break;
case 0: props.addValue("list-style-type","square"); break;
}
}
else if (XMLString.TEXT_LIST_LEVEL_STYLE_IMAGE.equals(sLevelType)) {
// Image. TODO: Handle embedded images
String sHref = style.getLevelProperty(nLevel,XMLString.XLINK_HREF);
if (sHref!=null) { props.addValue("list-style-image","url('"+sHref+"')"); }
else {
// No numbering generated by the list; we add hard numbering to the paragraph
props.addValue("list-style-type:none");
// In this case we also set the left margin for the list
// For real styles the margins are applied to the paragraphs
// This is more tricky for hard styles, so we use a default left margin on the list
if (style.isAutomatic() && nLevel>1) {
props.addValue("margin-left", "2em");
}
else {
props.addValue("margin-left","0");
}
// Also reset the padding (some browsers use a non-zero default value)
props.addValue("padding-left", "0");
}
// We don't want floats to pass a list to the left (Mozilla and IE both
//handles this terribly!)
props.addValue("clear:left");
}
private void cssListParMargins(ListStyle style, int nLevel, CSVList props){
// Instead margin is applied to the paragraphs in the list, more precisely the list style defines a
// left margin and a text indent to *replace* the values from the paragraph style
String sMarginLeft = style.getLevelStyleProperty(nLevel, XMLString.FO_MARGIN_LEFT);
if (sMarginLeft!=null) {
props.addValue("margin-left", sMarginLeft);
}
else {
props.addValue("margin-left", "0");
}
String sTextIndent = style.getLevelStyleProperty(nLevel, XMLString.FO_TEXT_INDENT);
if (sTextIndent!=null) {
props.addValue("text-indent", sTextIndent);
}
else {
props.addValue("text-indent", "0");
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-03-29)
* Version 1.2 (2010-05-04)
*
*/
@ -91,6 +91,8 @@ public class TextConverter extends ConverterHelper {
private ListCounter outlineNumbering;
private Hashtable<String, ListCounter> listCounters = new Hashtable<String, ListCounter>();
private String sCurrentListLabel = null;
private ListStyle currentListStyle = null;
private int nCurrentListLevel = 0;
// Mode used to handle floats (depends on source doc type and config)
private int nFloatMode;
@ -555,20 +557,8 @@ public class TextConverter extends ConverterHelper {
ListCounter counter = getListCounter(listStyle);
if (bRestart) { counter.restart(nListLevel,nStartValue); }
String sLabel = counter.step(nListLevel).getLabel();
if (!bUnNumbered && sLabel.length()>0) {
Element span = converter.createElement("span");
StyleInfo info = new StyleInfo();
info.sClass = "SectionNumber";
if (listStyle!=null) {
String sTextStyleName = listStyle.getLevelProperty(
nListLevel,XMLString.TEXT_STYLE_NAME);
getTextSc().applyStyle(sTextStyleName, info);
}
getTextSc().applyStyle(info, span);
heading.appendChild(span);
span.appendChild( converter.createTextNode(sLabel) );
}
insertListLabel(listStyle,nListLevel,"SectionNumber",sLabel,heading);
// Add to toc
if (!bInToc) {
String sTarget = "toc"+(++nTocIndex);
@ -634,16 +624,20 @@ public class TextConverter extends ConverterHelper {
entry.nFileIndex = converter.getOutFileIndex();
tocEntries.add(entry);
}
sCurrentListLabel = null;
if (!bIsEmpty) {
par = createTextBackground(par, sStyleName);
if (config.useHardListNumbering()) {
insertListLabel(currentListStyle, nCurrentListLevel, "ItemNumber", sCurrentListLabel, par);
}
sCurrentListLabel = null;
traverseInlineText(onode,par);
}
else {
// An empty paragraph (this includes paragraphs that only contains
// whitespace) is ignored by the browser, hence we add &nbsp;
par.appendChild( converter.createTextNode("\u00A0") );
sCurrentListLabel = null;
}
}
@ -684,6 +678,22 @@ public class TextConverter extends ConverterHelper {
return new ListCounter();
}
}
// Helper: Insert a list label formatted with a list style
private void insertListLabel(ListStyle style, int nLevel, String sDefaultStyle, String sLabel, Element hnode) {
if (sLabel!=null && sLabel.length()>0) {
Element span = converter.createElement("span");
StyleInfo info = new StyleInfo();
info.sClass = sDefaultStyle;
if (style!=null) {
String sTextStyleName = style.getLevelProperty(nLevel,XMLString.TEXT_STYLE_NAME);
getTextSc().applyStyle(sTextStyleName, info);
}
getTextSc().applyStyle(info, span);
hnode.appendChild(span);
span.appendChild( converter.createTextNode(sLabel) );
}
}
// Helper: Check if a list contains any items
private boolean hasItems(Node onode) {
@ -765,7 +775,7 @@ public class TextConverter extends ConverterHelper {
if (!bContinueNumbering && counter!=null) {
counter.restart(nLevel);
}
if (config.xhtmlUseListHack() && counter.getValue(nLevel)>0) {
if (config.xhtmlUseListHack() && !config.useHardListNumbering() && counter.getValue(nLevel)>0) {
hnode.setAttribute("start",Integer.toString(counter.getValue(nLevel)+1));
}
}
@ -796,12 +806,14 @@ public class TextConverter extends ConverterHelper {
else {
// add an li element
sCurrentListLabel = counter.step(nLevel).getLabel();
currentListStyle = ofr.getListStyle(styleName);
nCurrentListLevel = nLevel;
Element item = converter.createElement("li");
StyleInfo info = new StyleInfo();
getPresentationSc().applyOutlineStyle(nLevel,info);
applyStyle(info,item);
hnode.appendChild(item);
if (config.xhtmlUseListHack()) {
if (config.xhtmlUseListHack() && !config.useHardListNumbering()) {
boolean bRestart = "true".equals(Misc.getAttribute(child,
XMLString.TEXT_RESTART_NUMBERING));
int nStartValue = Misc.getPosInteger(Misc.getAttribute(child,
@ -893,7 +905,7 @@ public class TextConverter extends ConverterHelper {
// A fake list is a list which is converted into a sequence of numbered
// paragraphs rather than into a list.
// Currently this is done for list which only containsheadings
// Currently this is done for list which only contains headings
// Helper: Check to see, if this list contains only headings
// (If so, we will ignore the list and apply the numbering to the headings)

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-04-09)
* Version 1.2 (2010-05-04)
*
*/
@ -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
@ -93,21 +93,22 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
private static final int FLOAT_OBJECTS = 24;
private static final int TABSTOP_STYLE = 25;
private static final int USE_LIST_HACK = 26;
private static final int FORMULAS = 27;
private static final int SPLIT_LEVEL = 28;
private static final int REPEAT_LEVELS = 29;
private static final int CALC_SPLIT = 30;
private static final int DISPLAY_HIDDEN_SHEETS = 31;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 32;
private static final int DISPLAY_FILTERED_ROWS_COLS = 33;
private static final int APPLY_PRINT_RANGES = 34;
private static final int USE_TITLE_AS_HEADING = 35;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 36;
private static final int XSLT_PATH = 37;
private static final int SAVE_IMAGES_IN_SUBDIR = 38;
private static final int UPLINK = 39;
private static final int DIRECTORY_ICON = 40;
private static final int DOCUMENT_ICON = 41;
private static final int USE_HARD_LIST_NUMBERING = 27;
private static final int FORMULAS = 28;
private static final int SPLIT_LEVEL = 29;
private static final int REPEAT_LEVELS = 30;
private static final int CALC_SPLIT = 31;
private static final int DISPLAY_HIDDEN_SHEETS = 32;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 33;
private static final int DISPLAY_FILTERED_ROWS_COLS = 34;
private static final int APPLY_PRINT_RANGES = 35;
private static final int USE_TITLE_AS_HEADING = 36;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 37;
private static final int XSLT_PATH = 38;
private static final int SAVE_IMAGES_IN_SUBDIR = 39;
private static final int UPLINK = 40;
private static final int DIRECTORY_ICON = 41;
private static final int DOCUMENT_ICON = 42;
protected ComplexOption xpar = addComplexOption("paragraph-map");
protected ComplexOption xtext = addComplexOption("text-map");
@ -145,6 +146,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
options[FLOAT_OBJECTS] = new BooleanOption("float_objects","true");
options[TABSTOP_STYLE] = new Option("tabstop_style","");
options[USE_LIST_HACK] = new BooleanOption("use_list_hack","false");
options[USE_HARD_LIST_NUMBERING] = new BooleanOption("use_hard_list_numbering","false");
options[FORMULAS] = new IntegerOption("formulas","starmath") {
public void setString(String sValue) {
super.setString(sValue);
@ -268,6 +270,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public boolean xhtmlFloatObjects() { return ((BooleanOption) options[FLOAT_OBJECTS]).getValue(); }
public String getXhtmlTabstopStyle() { return options[TABSTOP_STYLE].getString(); }
public boolean xhtmlUseListHack() { return ((BooleanOption) options[USE_LIST_HACK]).getValue(); }
public boolean useHardListNumbering() { return ((BooleanOption) options[USE_HARD_LIST_NUMBERING]).getValue(); }
public int formulas() { return ((IntegerOption) options[FORMULAS]).getValue(); }
public int getXhtmlSplitLevel() { return ((IntegerOption) options[SPLIT_LEVEL]).getValue(); }
public int getXhtmlRepeatLevels() { return ((IntegerOption) options[REPEAT_LEVELS]).getValue(); }