Move string calculations from writer2latex.util.Misc to the separate class writer2latex.util.Calc + add JavaDoc
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@256 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
67ceaae08a
commit
6f46ed3177
19 changed files with 319 additions and 213 deletions
|
@ -56,6 +56,7 @@ import org.w3c.dom.Node;
|
|||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import writer2latex.util.Calc;
|
||||
import writer2latex.util.Misc;
|
||||
import writer2latex.util.CSVList;
|
||||
import writer2latex.util.SimpleXMLParser;
|
||||
|
@ -459,9 +460,9 @@ public class DrawConverter extends ConverterHelper {
|
|||
// It is if the image width exceeds a certain percentage of the current text width and the height is
|
||||
// greater than 1.33*the width (recommended by Michel "Coolmicro")
|
||||
if (sWidth!=null && sHeight!=null &&
|
||||
Misc.sub(Misc.multiply("133%",sWidth), sHeight).startsWith("-") &&
|
||||
Misc.sub(Misc.multiply(sImageSplit,converter.getContentWidth()),
|
||||
Misc.multiply(sScale,Misc.truncateLength(sWidth))).startsWith("-")) {
|
||||
Calc.sub(Calc.multiply("133%",sWidth), sHeight).startsWith("-") &&
|
||||
Calc.sub(Calc.multiply(sImageSplit,converter.getContentWidth()),
|
||||
Calc.multiply(sScale,Calc.truncateLength(sWidth))).startsWith("-")) {
|
||||
fullscreenFrames.add(onode);
|
||||
return;
|
||||
}
|
||||
|
@ -942,18 +943,18 @@ public class DrawConverter extends ConverterHelper {
|
|||
if (style!=null) {
|
||||
// Subtract padding
|
||||
String s = style.getProperty(XMLString.FO_PADDING_LEFT);
|
||||
if (s!=null) sWidth = Misc.sub(sWidth, s);
|
||||
if (s!=null) sWidth = Calc.sub(sWidth, s);
|
||||
s = style.getProperty(XMLString.FO_PADDING_RIGHT);
|
||||
if (s!=null) sWidth = Misc.sub(sWidth, s);
|
||||
if (s!=null) sWidth = Calc.sub(sWidth, s);
|
||||
s = style.getProperty(XMLString.FO_PADDING);
|
||||
if (s!=null) sWidth = Misc.sub(sWidth, Misc.multiply("200%", s));
|
||||
if (s!=null) sWidth = Calc.sub(sWidth, Calc.multiply("200%", s));
|
||||
// Subtract border
|
||||
s = style.getProperty(XMLString.FO_BORDER_LEFT);
|
||||
if (s!=null) sWidth = Misc.sub(sWidth, getTableCv().borderWidth(s));
|
||||
if (s!=null) sWidth = Calc.sub(sWidth, getTableCv().borderWidth(s));
|
||||
s = style.getProperty(XMLString.FO_BORDER_RIGHT);
|
||||
if (s!=null) sWidth = Misc.sub(sWidth, getTableCv().borderWidth(s));
|
||||
if (s!=null) sWidth = Calc.sub(sWidth, getTableCv().borderWidth(s));
|
||||
s = style.getProperty(XMLString.FO_BORDER);
|
||||
if (s!=null) sWidth = Misc.sub(sWidth, Misc.multiply("200%", getTableCv().borderWidth(s)));
|
||||
if (s!=null) sWidth = Calc.sub(sWidth, Calc.multiply("200%", getTableCv().borderWidth(s)));
|
||||
}
|
||||
return sWidth;
|
||||
}
|
||||
|
@ -967,18 +968,18 @@ public class DrawConverter extends ConverterHelper {
|
|||
if (style!=null) {
|
||||
// Subtract padding
|
||||
String s = style.getProperty(XMLString.FO_PADDING_TOP);
|
||||
if (s!=null) sHeight = Misc.sub(sHeight, s);
|
||||
if (s!=null) sHeight = Calc.sub(sHeight, s);
|
||||
s = style.getProperty(XMLString.FO_PADDING_BOTTOM);
|
||||
if (s!=null) sHeight = Misc.sub(sHeight, s);
|
||||
if (s!=null) sHeight = Calc.sub(sHeight, s);
|
||||
s = style.getProperty(XMLString.FO_PADDING);
|
||||
if (s!=null) sHeight = Misc.sub(sHeight, Misc.multiply("200%", s));
|
||||
if (s!=null) sHeight = Calc.sub(sHeight, Calc.multiply("200%", s));
|
||||
// Subtract border
|
||||
s = style.getProperty(XMLString.FO_BORDER_TOP);
|
||||
if (s!=null) sHeight = Misc.sub(sHeight, getTableCv().borderWidth(s));
|
||||
if (s!=null) sHeight = Calc.sub(sHeight, getTableCv().borderWidth(s));
|
||||
s = style.getProperty(XMLString.FO_BORDER_BOTTOM);
|
||||
if (s!=null) sHeight = Misc.sub(sHeight, getTableCv().borderWidth(s));
|
||||
if (s!=null) sHeight = Calc.sub(sHeight, getTableCv().borderWidth(s));
|
||||
s = style.getProperty(XMLString.FO_BORDER);
|
||||
if (s!=null) sHeight = Misc.sub(sHeight, Misc.multiply("200%", getTableCv().borderWidth(s)));
|
||||
if (s!=null) sHeight = Calc.sub(sHeight, Calc.multiply("200%", getTableCv().borderWidth(s)));
|
||||
}
|
||||
return sHeight;
|
||||
}
|
||||
|
@ -1018,7 +1019,7 @@ public class DrawConverter extends ConverterHelper {
|
|||
else {
|
||||
String sWidth = getFrameWidth(node, ofr.getFrameStyle(node.getAttribute(XMLString.DRAW_STYLE_NAME)));
|
||||
if (sWidth!=null) {
|
||||
props.addValue("width", Misc.divide(Misc.multiply(sScale,Misc.truncateLength(sWidth)),converter.getContentWidth()));
|
||||
props.addValue("width", Calc.divide(Calc.multiply(sScale,Calc.truncateLength(sWidth)),converter.getContentWidth()));
|
||||
}
|
||||
return sWidth;
|
||||
}
|
||||
|
@ -1039,9 +1040,9 @@ public class DrawConverter extends ConverterHelper {
|
|||
StyleWithProperties style = ofr.getFrameStyle(node.getAttribute(XMLString.DRAW_STYLE_NAME));
|
||||
if (style!=null) {
|
||||
String s = style.getProperty(XMLString.FO_MARGIN_TOP);
|
||||
if (s!=null) sX=Misc.sub(sX,s);
|
||||
if (s!=null) sX=Calc.sub(sX,s);
|
||||
s = style.getProperty(XMLString.FO_MARGIN_LEFT);
|
||||
if (s!=null) sY=Misc.sub(sY,s);
|
||||
if (s!=null) sY=Calc.sub(sY,s);
|
||||
}
|
||||
|
||||
props.addValue("position","absolute");
|
||||
|
@ -1159,10 +1160,10 @@ public class DrawConverter extends ConverterHelper {
|
|||
// TODO: Move to ConverterHelper.java
|
||||
private String scale(String s) {
|
||||
if (bConvertToPx) {
|
||||
return Misc.length2px(Misc.multiply(sScale,Misc.truncateLength(s)));
|
||||
return Calc.length2px(Calc.multiply(sScale,Calc.truncateLength(s)));
|
||||
}
|
||||
else {
|
||||
return Misc.multiply(sScale,Misc.truncateLength(s));
|
||||
return Calc.multiply(sScale,Calc.truncateLength(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ import writer2latex.office.OfficeStyleFamily;
|
|||
import writer2latex.office.StyleWithProperties;
|
||||
import writer2latex.office.XMLString;
|
||||
import writer2latex.util.CSVList;
|
||||
import writer2latex.util.Misc;
|
||||
import writer2latex.util.Calc;
|
||||
//import writer2latex.util.Misc;
|
||||
import writer2latex.util.SimpleInputBuffer;
|
||||
|
||||
|
@ -275,7 +275,7 @@ public class FrameStyleConverter extends StyleWithPropertiesConverterHelper {
|
|||
if ('0'<=in.peekChar() && in.peekChar()<='9') {
|
||||
String sDim = scale(in.getNumber()+in.getIdentifier());
|
||||
// Do not output a border less than 1px wide - some browsers will render it invisible
|
||||
out.append(Misc.isLessThan(sDim, "1px") ? "1px" : sDim);
|
||||
out.append(Calc.isLessThan(sDim, "1px") ? "1px" : sDim);
|
||||
}
|
||||
// skip other characters
|
||||
while (in.peekChar()!=' ' && in.peekChar()!='\0') {
|
||||
|
|
|
@ -35,7 +35,7 @@ import writer2latex.office.PageLayout;
|
|||
import writer2latex.office.StyleWithProperties;
|
||||
import writer2latex.office.XMLString;
|
||||
import writer2latex.util.CSVList;
|
||||
import writer2latex.util.Misc;
|
||||
import writer2latex.util.Calc;
|
||||
|
||||
/**
|
||||
* This class converts OpenDocument page styles to CSS2 styles.
|
||||
|
@ -74,11 +74,11 @@ public class PageStyleConverter extends StyleConverterHelper {
|
|||
if (sWidth!=null) {
|
||||
String sMarginLeft = pageLayout.getProperty(XMLString.FO_MARGIN_LEFT);
|
||||
if (sMarginLeft!=null) {
|
||||
sWidth = Misc.sub(sWidth, sMarginLeft);
|
||||
sWidth = Calc.sub(sWidth, sMarginLeft);
|
||||
}
|
||||
String sMarginRight = pageLayout.getProperty(XMLString.FO_MARGIN_RIGHT);
|
||||
if (sMarginRight!=null) {
|
||||
sWidth = Misc.sub(sWidth, sMarginRight);
|
||||
sWidth = Calc.sub(sWidth, sMarginRight);
|
||||
}
|
||||
return sWidth;
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ 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.util.Misc;
|
||||
|
||||
/**
|
||||
* <p>This is an abstract base class to convert an OpenDocument style family to
|
||||
|
@ -73,15 +73,15 @@ public abstract class StyleConverterHelper extends ConverterHelper {
|
|||
|
||||
protected String scale(String s) {
|
||||
if (bConvertToPx) {
|
||||
return Misc.length2px(Misc.multiply(sScale,s));
|
||||
return Calc.length2px(Calc.multiply(sScale,s));
|
||||
}
|
||||
else {
|
||||
return Misc.multiply(sScale,s);
|
||||
return Calc.multiply(sScale,s);
|
||||
}
|
||||
}
|
||||
|
||||
protected String colScale(String s) {
|
||||
return scale(Misc.multiply(sColScale,s));
|
||||
return scale(Calc.multiply(sColScale,s));
|
||||
}
|
||||
|
||||
/** Apply the writing direction (ltr or rtl) attribute from a style
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.w3c.dom.Node;
|
|||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import writer2latex.util.Calc;
|
||||
import writer2latex.util.Misc;
|
||||
import writer2latex.util.SimpleInputBuffer;
|
||||
import writer2latex.office.XMLString;
|
||||
|
@ -348,7 +349,7 @@ public class TableConverter extends ConverterHelper {
|
|||
if (sWidth!=null) {
|
||||
if (config.tableSize()==XhtmlConfig.RELATIVE){
|
||||
// Force relative width
|
||||
sWidth=Misc.divide(sWidth, converter.getContentWidth(), true);
|
||||
sWidth=Calc.divide(sWidth, converter.getContentWidth(), true);
|
||||
info.props.addValue("width",sWidth);
|
||||
}
|
||||
else {
|
||||
|
@ -413,31 +414,31 @@ public class TableConverter extends ConverterHelper {
|
|||
// "total cell width" - "border" - "padding"
|
||||
String s = style.getProperty(XMLString.FO_PADDING_LEFT);
|
||||
if (s!=null) {
|
||||
sEdge=Misc.add(sEdge,getTableSc().colScale(s));
|
||||
sEdge=Calc.add(sEdge,getTableSc().colScale(s));
|
||||
}
|
||||
s = style.getProperty(XMLString.FO_PADDING_RIGHT);
|
||||
if (s!=null) {
|
||||
sEdge=Misc.add(sEdge,getTableSc().colScale(s));
|
||||
sEdge=Calc.add(sEdge,getTableSc().colScale(s));
|
||||
}
|
||||
s = style.getProperty(XMLString.FO_PADDING);
|
||||
if (s!=null) {
|
||||
sEdge=Misc.add(sEdge,Misc.multiply("200%",getTableSc().colScale(s)));
|
||||
sEdge=Calc.add(sEdge,Calc.multiply("200%",getTableSc().colScale(s)));
|
||||
}
|
||||
s = style.getProperty(XMLString.FO_BORDER_LEFT);
|
||||
if (s!=null) {
|
||||
sEdge=Misc.add(sEdge,getTableSc().colScale(borderWidth(s)));
|
||||
sEdge=Calc.add(sEdge,getTableSc().colScale(borderWidth(s)));
|
||||
}
|
||||
s = style.getProperty(XMLString.FO_BORDER_RIGHT);
|
||||
if (s!=null) {
|
||||
sEdge=Misc.add(sEdge,getTableSc().colScale(borderWidth(s)));
|
||||
sEdge=Calc.add(sEdge,getTableSc().colScale(borderWidth(s)));
|
||||
}
|
||||
s = style.getProperty(XMLString.FO_BORDER);
|
||||
if (s!=null) {
|
||||
sEdge=Misc.add(sEdge,Misc.multiply("200%",getTableSc().colScale(borderWidth(s))));
|
||||
sEdge=Calc.add(sEdge,Calc.multiply("200%",getTableSc().colScale(borderWidth(s))));
|
||||
}
|
||||
|
||||
if (sTotalWidth!=null) {
|
||||
info.props.addValue("width",Misc.sub(getTableSc().colScale(sTotalWidth),sEdge));
|
||||
info.props.addValue("width",Calc.sub(getTableSc().colScale(sTotalWidth),sEdge));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ import writer2latex.office.OfficeStyleFamily;
|
|||
import writer2latex.office.StyleWithProperties;
|
||||
import writer2latex.office.XMLString;
|
||||
import writer2latex.util.CSVList;
|
||||
import writer2latex.util.Calc;
|
||||
import writer2latex.util.ExportNameCollection;
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
/**
|
||||
* This class converts OpenDocument text styles to CSS2 styles.
|
||||
|
@ -319,11 +319,11 @@ public class TextStyleConverter extends StyleWithPropertiesConverterHelper {
|
|||
}
|
||||
if (s!=null) {
|
||||
if (bRelativeFontSize) {
|
||||
String sFontSize = Misc.divide(Misc.multiply(sFontScaling, Misc.multiply(s4,s)), sBaseFontSize);
|
||||
String sFontSize = Calc.divide(Calc.multiply(sFontScaling, Calc.multiply(s4,s)), sBaseFontSize);
|
||||
if (!"100%".equals(sFontSize)) props.addValue("font-size", sFontSize);
|
||||
}
|
||||
else {
|
||||
props.addValue("font-size",Misc.multiply(s4,scale(s)));
|
||||
props.addValue("font-size",Calc.multiply(s4,scale(s)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -335,7 +335,7 @@ public class TextStyleConverter extends StyleWithPropertiesConverterHelper {
|
|||
}
|
||||
else if (s!=null) {
|
||||
if (bRelativeFontSize) {
|
||||
String sFontSize = Misc.divide(Misc.multiply(sFontScaling, s),sBaseFontSize);
|
||||
String sFontSize = Calc.divide(Calc.multiply(sFontScaling, s),sBaseFontSize);
|
||||
if (!"100%".equals(sFontSize)) props.addValue("font-size", sFontSize);
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue