w2x: New option max_width + UI for the option separate_stylesheet

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@254 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2015-06-16 06:39:12 +00:00
parent a01aea739c
commit a475b5fd42
9 changed files with 227 additions and 153 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-04-09)
* Version 1.6 (2015-06-16)
*
*/
@ -522,9 +522,10 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
checkBoxFromConfig(dlg, "IgnoreTableDimensions", "ignore_table_dimensions");
listBoxFromConfig(dlg, "ListFormatting", "list_formatting", sListExportValues, (short) 0);
//TODO: These have been postponed
//checkBoxFromConfig(dlg, "ConvertToPx", "convert_to_px");
//checkBoxFromConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
textFieldFromConfig(dlg, "MaxWidth", "max_width");
checkBoxFromConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
}
@Override protected void getControls(DialogAccess dlg) {
@ -537,9 +538,10 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
checkBoxToConfig(dlg, "IgnoreTableDimensions", "ignore_table_dimensions");
listBoxToConfig(dlg, "ListFormatting", "list_formatting", sListExportValues);
//TODO: These have been postponed
//checkBoxToConfig(dlg, "ConvertToPx", "convert_to_px");
//checkBoxToConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
textFieldToConfig(dlg, "MaxWidth", "max_width");
checkBoxToConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
}
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-06-12)
* Version 1.6 (2015-06-16)
*
*/
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information
private static final String VERSION = "1.5.3";
private static final String DATE = "2015-06-12";
private static final String DATE = "2015-06-16";
/** 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-2014 by Henrik Just
* Copyright: 2002-2015 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.4 (2014-08-13)
* Version 1.6 (2015-06-15)
*
*/
@ -30,45 +30,67 @@ import org.w3c.dom.Element;
import writer2latex.office.OfficeReader;
public class ConverterHelper {
protected OfficeReader ofr;
protected XhtmlConfig config;
protected Converter converter;
/** A <code>ConverterHelper</code> is responsible for conversion of some specific content into XHTML.
*/
class ConverterHelper {
protected StyleConverter getStyleCv() { return converter.getStyleCv(); }
protected TextStyleConverter getTextSc() { return converter.getStyleCv().getTextSc(); }
// Member variables providing our content (set in constructor)
OfficeReader ofr;
XhtmlConfig config;
Converter converter;
protected ParStyleConverter getParSc() { return converter.getStyleCv().getParSc(); }
protected HeadingStyleConverter getHeadingSc() { return converter.getStyleCv().getHeadingSc(); }
protected ListStyleConverter getListSc() { return converter.getStyleCv().getListSc(); }
protected SectionStyleConverter getSectionSc() { return converter.getStyleCv().getSectionSc(); }
protected TableStyleConverter getTableSc() { return converter.getStyleCv().getTableSc(); }
protected RowStyleConverter getRowSc() { return converter.getStyleCv().getRowSc(); }
protected CellStyleConverter getCellSc() { return converter.getStyleCv().getCellSc(); }
protected FrameStyleConverter getFrameSc() { return converter.getStyleCv().getFrameSc(); }
protected PresentationStyleConverter getPresentationSc() { return converter.getStyleCv().getPresentationSc(); }
protected PageStyleConverter getPageSc() { return converter.getStyleCv().getPageSc(); }
/** Construct a new converter helper based on a
*
* @param ofr the office reader used to access the source document
* @param config the configuration to use
* @param converter the main converter to which the helper belongs
*/
ConverterHelper(OfficeReader ofr, XhtmlConfig config, Converter converter) {
this.ofr = ofr;
this.config = config;
this.converter = converter;
}
protected TextConverter getTextCv() { return converter.getTextCv(); }
protected TableConverter getTableCv() { return converter.getTableCv(); }
// Convenience accessor methods to other converter helpers (only needed to save some typing)
protected DrawConverter getDrawCv() { return converter.getDrawCv(); }
StyleConverter getStyleCv() { return converter.getStyleCv(); }
protected MathConverter getMathCv() { return converter.getMathCv(); }
TextStyleConverter getTextSc() { return converter.getStyleCv().getTextSc(); }
// TODO: Move to StyleInfo!
protected void applyStyle(StyleInfo info, Element hnode) {
ParStyleConverter getParSc() { return converter.getStyleCv().getParSc(); }
HeadingStyleConverter getHeadingSc() { return converter.getStyleCv().getHeadingSc(); }
ListStyleConverter getListSc() { return converter.getStyleCv().getListSc(); }
SectionStyleConverter getSectionSc() { return converter.getStyleCv().getSectionSc(); }
TableStyleConverter getTableSc() { return converter.getStyleCv().getTableSc(); }
RowStyleConverter getRowSc() { return converter.getStyleCv().getRowSc(); }
CellStyleConverter getCellSc() { return converter.getStyleCv().getCellSc(); }
FrameStyleConverter getFrameSc() { return converter.getStyleCv().getFrameSc(); }
PresentationStyleConverter getPresentationSc() { return converter.getStyleCv().getPresentationSc(); }
PageStyleConverter getPageSc() { return converter.getStyleCv().getPageSc(); }
TextConverter getTextCv() { return converter.getTextCv(); }
TableConverter getTableCv() { return converter.getTableCv(); }
DrawConverter getDrawCv() { return converter.getDrawCv(); }
MathConverter getMathCv() { return converter.getMathCv(); }
/** Apply style information to an XHTML node
*
* @param info the style to apply
* @param hnode the XHTML node
*/
void applyStyle(StyleInfo info, Element hnode) {
if (info.sClass!=null) {
hnode.setAttribute("class",info.sClass);
}
@ -86,9 +108,4 @@ public class ConverterHelper {
}
}
public ConverterHelper(OfficeReader ofr, XhtmlConfig config, Converter converter) {
this.ofr = ofr;
this.config = config;
this.converter = converter;
}
}

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2014 by Henrik Just
* Copyright: 2002-2015 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.4 (2014-09-16)
* Version 1.6 (2015-06-15)
*
*/
@ -33,14 +33,11 @@ import org.w3c.dom.Node;
import writer2latex.office.*;
import writer2latex.util.*;
/**
* <p>This class converts OpenDocument styles to CSS2 styles.</p>
* <p>Note that some elements in OpenDocument has attributes that also maps
* to CSS2 properties. Example: the width of a text box.</p>
* <p>Also note, that some OpenDocument style properties cannot be mapped to
* CSS2 without creating an additional inline element.</p>
* <p>The class uses one helper class per OpenDocument style family
* (paragraph, frame etc.)</p>
/** This class converts OpenDocument styles to CSS2 styles.
* Note that some elements in OpenDocument has attributes that also maps to CSS2 properties.
* Example: the width of a text box.
* Also note, that some OpenDocument style properties cannot be mapped to CSS2 without creating an additional inline element.
* The class uses one helper class per OpenDocument style family (paragraph, frame etc.)
*/
class StyleConverter extends ConverterHelper {
@ -63,9 +60,14 @@ class StyleConverter extends ConverterHelper {
// Helper for page styles
private PageStyleConverter pageSc;
/** <p>Create a new <code>StyleConverter</code></p>
/** Create a new <code>StyleConverter</code>
*
* @param ofr the office reader used to access the source document
* @param config the configuration to use
* @param converter the main converter
* @param nType the XHTML type
*/
public StyleConverter(OfficeReader ofr, XhtmlConfig config, Converter converter, int nType) {
StyleConverter(OfficeReader ofr, XhtmlConfig config, Converter converter, int nType) {
super(ofr,config,converter);
// Create the helpers
textSc = new TextStyleConverter(ofr,config,converter,nType);
@ -81,37 +83,35 @@ class StyleConverter extends ConverterHelper {
pageSc = new PageStyleConverter(ofr,config,converter,nType);
}
// Accessor methods for helpers
protected TextStyleConverter getTextSc() { return textSc; }
// Accessor methods for helpers: We need to override the style helper accessors
TextStyleConverter getTextSc() { return textSc; }
protected ParStyleConverter getParSc() { return parSc; }
ParStyleConverter getParSc() { return parSc; }
protected HeadingStyleConverter getHeadingSc() { return headingSc; }
HeadingStyleConverter getHeadingSc() { return headingSc; }
protected ListStyleConverter getListSc() { return listSc; }
ListStyleConverter getListSc() { return listSc; }
protected SectionStyleConverter getSectionSc() { return sectionSc; }
SectionStyleConverter getSectionSc() { return sectionSc; }
protected TableStyleConverter getTableSc() { return tableSc; }
TableStyleConverter getTableSc() { return tableSc; }
protected RowStyleConverter getRowSc() { return rowSc; }
RowStyleConverter getRowSc() { return rowSc; }
protected CellStyleConverter getCellSc() { return cellSc; }
CellStyleConverter getCellSc() { return cellSc; }
protected FrameStyleConverter getFrameSc() { return frameSc; }
FrameStyleConverter getFrameSc() { return frameSc; }
protected PresentationStyleConverter getPresentationSc() { return presentationSc; }
PresentationStyleConverter getPresentationSc() { return presentationSc; }
protected PageStyleConverter getPageSc() { return pageSc; }
PageStyleConverter getPageSc() { return pageSc; }
private StyleWithProperties getDefaultStyle() {
if (ofr.isSpreadsheet()) return ofr.getDefaultCellStyle();
else if (ofr.isPresentation()) return ofr.getDefaultFrameStyle();
else return ofr.getDefaultParStyle();
}
// Apply the default language
public void applyDefaultLanguage(Element node) {
/** Apply the default language of the source document on an XHTML element
*
* @param node the XHTML element
*/
void applyDefaultLanguage(Element node) {
StyleWithProperties style = getDefaultStyle();
if (style!=null) {
StyleInfo info = new StyleInfo();
@ -120,29 +120,16 @@ class StyleConverter extends ConverterHelper {
}
}
public String exportStyles(boolean bIndent) {
/** Export style information as a string of plain CSS code
*
* @param bIndent true if the CSS code should be indented
* @return the CSS code
*/
String exportStyles(boolean bIndent) {
String sIndent = bIndent ? " " : "";
StringBuilder buf = new StringBuilder();
// Export default style
if (config.xhtmlCustomStylesheet().length()==0 &&
(config.xhtmlFormatting()==XhtmlConfig.CONVERT_ALL ||
config.xhtmlFormatting()==XhtmlConfig.IGNORE_HARD)) {
// Default paragraph/cell/frame style is applied to the body element
StyleWithProperties defaultStyle = getDefaultStyle();
if (defaultStyle!=null) {
CSVList props = new CSVList(";");
// text properties only!
getTextSc().cssTextCommon(defaultStyle,props,true);
if (config.useDefaultFont() && config.defaultFontName().length()>0) {
props.addValue("font-family", "'"+config.defaultFontName()+"'");
}
buf.append(sIndent)
.append("body {").append(props.toString()).append("}").append(config.prettyPrint() ? "\n" : " ");
}
}
exportDefaultStyle(buf,sIndent);
// Export declarations from helpers
// For OpenDocument documents created with OOo only some will generate content:
@ -162,9 +149,13 @@ class StyleConverter extends ConverterHelper {
buf.append(getPageSc().getStyleDeclarations(sIndent));
return buf.toString();
}
// Export used styles to CSS
public Node exportStyles(Document htmlDOM) {
/** Export style information as an XHTML style element
*
* @param htmlDOM the XHTML DOM to which the generated element belongs
* @return the style element
*/
Node exportStyles(Document htmlDOM) {
String sStyles = exportStyles(config.prettyPrint());
// Create node
@ -181,5 +172,48 @@ class StyleConverter extends ConverterHelper {
return null;
}
}
// Private helper methods
private void exportDefaultStyle(StringBuilder buf, String sIndent) {
// Export default style
if (config.xhtmlCustomStylesheet().length()==0 &&
(config.xhtmlFormatting()==XhtmlConfig.CONVERT_ALL ||
config.xhtmlFormatting()==XhtmlConfig.IGNORE_HARD)) {
CSVList props = new CSVList(";");
// Default paragraph/cell/frame style is applied to the body element
StyleWithProperties defaultStyle = getDefaultStyle();
if (defaultStyle!=null) {
// text properties only!
getTextSc().cssTextCommon(defaultStyle,props,true);
if (config.useDefaultFont() && config.defaultFontName().length()>0) {
props.addValue("font-family", "'"+config.defaultFontName()+"'");
}
}
// For text documents (XHTML only), also set maximum width
if (ofr.isText() && !converter.isOPS()) {
String sMaxWidth = config.getMaxWidth().trim();
if (sMaxWidth.length()>0) {
props.addValue("max-width", sMaxWidth);
props.addValue("margin-left","auto");
props.addValue("margin-right","auto");
}
}
// Apply properties to body
if (!props.isEmpty()) {
buf.append(sIndent)
.append("body {").append(props.toString()).append("}").append(config.prettyPrint() ? "\n" : " ");
}
}
}
private StyleWithProperties getDefaultStyle() {
if (ofr.isSpreadsheet()) return ofr.getDefaultCellStyle();
else if (ofr.isPresentation()) return ofr.getDefaultFrameStyle();
else return ofr.getDefaultParStyle();
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-04-28)
* Version 1.6 (2015-06-15)
*
*/
@ -41,7 +41,7 @@ import writer2latex.util.Misc;
public class XhtmlConfig extends writer2latex.base.ConfigBase {
// Implement configuration methods
protected int getOptionCount() { return 58; }
protected int getOptionCount() { return 59; }
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
// Override setOption: To be backwards compatible, we must accept options
@ -120,44 +120,45 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
private static final int TABLE_FORMATTING = 17;
private static final int TABLE_SIZE = 18;
private static final int LIST_FORMATTING = 19;
private static final int USE_DEFAULT_FONT = 20;
private static final int DEFAULT_FONT_NAME = 21;
private static final int USE_DUBLIN_CORE = 22;
private static final int NOTES = 23;
private static final int DISPLAY_HIDDEN_TEXT = 24;
private static final int CONVERT_TO_PX = 25;
private static final int SCALING = 26;
private static final int COLUMN_SCALING = 27;
private static final int RELATIVE_FONT_SIZE = 28;
private static final int FONT_SCALING = 29;
private static final int FLOAT_OBJECTS = 30;
private static final int TABSTOP_STYLE = 31;
private static final int FORMULAS = 32;
private static final int ENDNOTES_HEADING = 33;
private static final int FOOTNOTES_HEADING = 34;
private static final int EXTERNAL_TOC_DEPTH = 35;
private static final int INCLUDE_TOC = 36;
private static final int INCLUDE_NCX = 37;
private static final int SPLIT_LEVEL = 38;
private static final int REPEAT_LEVELS = 39;
private static final int PAGE_BREAK_SPLIT = 40;
private static final int SPLIT_AFTER = 41;
private static final int IMAGE_SPLIT = 42;
private static final int COVER_IMAGE = 43;
private static final int EMBED_SVG = 44;
private static final int EMBED_IMG = 45;
private static final int USE_MATHJAX = 46;
private static final int CALC_SPLIT = 47;
private static final int DISPLAY_HIDDEN_SHEETS = 48;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 49;
private static final int DISPLAY_FILTERED_ROWS_COLS = 50;
private static final int APPLY_PRINT_RANGES = 51;
private static final int USE_TITLE_AS_HEADING = 52;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 53;
private static final int SAVE_IMAGES_IN_SUBDIR = 54;
private static final int UPLINK = 55;
private static final int DIRECTORY_ICON = 56;
private static final int DOCUMENT_ICON = 57;
private static final int MAX_WIDTH = 20;
private static final int USE_DEFAULT_FONT = 21;
private static final int DEFAULT_FONT_NAME = 22;
private static final int USE_DUBLIN_CORE = 23;
private static final int NOTES = 24;
private static final int DISPLAY_HIDDEN_TEXT = 25;
private static final int CONVERT_TO_PX = 26;
private static final int SCALING = 27;
private static final int COLUMN_SCALING = 28;
private static final int RELATIVE_FONT_SIZE = 29;
private static final int FONT_SCALING = 30;
private static final int FLOAT_OBJECTS = 31;
private static final int TABSTOP_STYLE = 32;
private static final int FORMULAS = 33;
private static final int ENDNOTES_HEADING = 34;
private static final int FOOTNOTES_HEADING = 35;
private static final int EXTERNAL_TOC_DEPTH = 36;
private static final int INCLUDE_TOC = 37;
private static final int INCLUDE_NCX = 38;
private static final int SPLIT_LEVEL = 39;
private static final int REPEAT_LEVELS = 40;
private static final int PAGE_BREAK_SPLIT = 41;
private static final int SPLIT_AFTER = 42;
private static final int IMAGE_SPLIT = 43;
private static final int COVER_IMAGE = 44;
private static final int EMBED_SVG = 45;
private static final int EMBED_IMG = 46;
private static final int USE_MATHJAX = 47;
private static final int CALC_SPLIT = 48;
private static final int DISPLAY_HIDDEN_SHEETS = 49;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 50;
private static final int DISPLAY_FILTERED_ROWS_COLS = 51;
private static final int APPLY_PRINT_RANGES = 52;
private static final int USE_TITLE_AS_HEADING = 53;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 54;
private static final int SAVE_IMAGES_IN_SUBDIR = 55;
private static final int UPLINK = 56;
private static final int DIRECTORY_ICON = 57;
private static final int DOCUMENT_ICON = 58;
protected ComplexOption xheading = addComplexOption("heading-map");
protected ComplexOption xpar = addComplexOption("paragraph-map");
@ -211,6 +212,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
else { nValue = CSS1; }
}
};
options[MAX_WIDTH] = new Option("max_width","800px");
options[USE_DEFAULT_FONT] = new BooleanOption("use_default_font","false");
options[DEFAULT_FONT_NAME] = new BooleanOption("default_font_name","");
options[USE_DUBLIN_CORE] = new BooleanOption("use_dublin_core","true");
@ -393,6 +395,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public int xhtmlTableFormatting() { return ((XhtmlFormatOption) options[TABLE_FORMATTING]).getValue(); }
public int tableSize() { return ((IntegerOption) options[TABLE_SIZE]).getValue(); }
public int listFormatting() { return ((IntegerOption) options[LIST_FORMATTING]).getValue(); }
public String getMaxWidth() { return options[MAX_WIDTH].getString(); }
public boolean useDefaultFont() { return ((BooleanOption) options[USE_DEFAULT_FONT]).getValue(); }
public String defaultFontName() { return options[DEFAULT_FONT_NAME].getString(); }
public boolean xhtmlUseDublinCore() { return ((BooleanOption) options[USE_DUBLIN_CORE]).getValue(); }