/************************************************************************ * * StyleConverterHelper.java * * Copyright: 2002-2011 by Henrik Just * * This file is part of Writer2LaTeX. * * Writer2LaTeX is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Writer2LaTeX is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Writer2LaTeX. If not, see . * * Version 1.2 (2011-03-10) * */ package writer2latex.xhtml.style; import writer2latex.office.OfficeReader; import writer2latex.office.OfficeStyleFamily; import writer2latex.office.StyleWithProperties; import writer2latex.office.XMLString; import writer2latex.util.Calc; import writer2latex.util.ExportNameCollection; import writer2latex.xhtml.Converter; import writer2latex.xhtml.Parser; import writer2latex.xhtml.StyleInfo; import writer2latex.xhtml.XhtmlConfig; import writer2latex.xhtml.XhtmlStyleMap; /** *

This is an abstract base class to convert an OpenDocument style family to * CSS2 styles.

*/ public abstract class StyleFamilyParser extends Parser { // Translation of OpenDocument style names to CSS class names protected ExportNameCollection styleNames = new ExportNameCollection(true); // Style map to use protected XhtmlStyleMap styleMap; // Should we convert styles resp. hard formatting? protected boolean bConvertStyles = true; protected boolean bConvertHard = true; // The type of xhtml document protected int nType; // Scaling and unit transformation to use private String sScale; private String sColScale; private boolean bConvertToPx; /** Create a new StyleConverterHelper * @param ofr an OfficeReader to read style information from * @param config the configuration to use * @param converter the main Converter class * @param nType the type of xhtml to use */ public StyleFamilyParser(OfficeReader ofr, XhtmlConfig config, Converter converter, int nType) { super(ofr,config,converter); this.nType = nType; sScale = config.getXhtmlScaling(); sColScale = config.getXhtmlColumnScaling(); bConvertToPx = config.xhtmlConvertToPx(); } public String scale(String s) { if (bConvertToPx) { return Calc.length2px(Calc.multiply(sScale,s)); } else { return Calc.length2rem(Calc.multiply(sScale,s)); } } public String colScale(String s) { return scale(Calc.multiply(sColScale,s)); } /** Apply the writing direction (ltr or rtl) attribute from a style * @param style the OpenDocument style to use * @param info the StyleInfo object to add information to */ protected static void applyDirection(StyleWithProperties style, StyleInfo info) { String sDir = style.getProperty(XMLString.STYLE_WRITING_MODE); if ("lr-tb".equals(sDir)) { info.sDir="ltr"; } else if ("rl-tb".equals(sDir)) { info.sDir="rtl"; } } /** Apply language+country from a style * @param style the OpenDocument style to use * @param info the StyleInfo object to add information to */ protected static void applyLang(StyleWithProperties style, StyleInfo info) { String sLang = style.getProperty(XMLString.FO_LANGUAGE); String sCountry = style.getProperty(XMLString.FO_COUNTRY); if (sLang!=null) { if (sCountry==null || sCountry.equals("none")) { info.sLang = sLang; } else { info.sLang = sLang+"-"+sCountry; } } } /** Get the OpenDocument style family associated with this * StyleConverterHelper * @return the style family */ public abstract OfficeStyleFamily getStyles(); /**

Convert style information for used styles

* @param sIndent a String of spaces to add before each line */ public abstract String getStyleSelectors(String sIndent); }