import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.PercentBaseContext;
import org.apache.fop.datatypes.Numeric;
+import org.apache.fop.fo.properties.FixedLength;
import org.apache.fop.fo.properties.Property;
/**
/** {@inheritDoc} */
public String toString() {
if (dim == 1) {
- return (int) value + "mpt";
+ return (int) value + FixedLength.MPT;
} else {
return value + "^" + dim;
}
*/
public final class FixedLength extends LengthProperty {
+ /** Describes the unit pica. */
+ public static final String PICA = "pc";
+
+ /** Describes the unit point. */
+ public static final String POINT = "pt";
+
+ /** Describes the unit millimeter. */
+ public static final String MM = "mm";
+
+ /** Describes the unit centimeter. */
+ public static final String CM = "cm";
+
+ /** Describes the unit inch. */
+ public static final String INCH = "in";
+
+ /** Describes the unit millipoint. */
+ public static final String MPT = "mpt";
+
/** cache holding all canonical FixedLength instances */
private static final PropertyCache cache = new PropertyCache();
/** canonical zero-length instance */
- public static final FixedLength ZERO_FIXED_LENGTH = new FixedLength(0, "mpt", 1.0f);
+ public static final FixedLength ZERO_FIXED_LENGTH = new FixedLength(0, FixedLength.MPT, 1.0f);
private int millipoints;
* to the given number of units and unit specifier
*/
public static FixedLength getInstance(double numUnits) {
- return getInstance(numUnits, "mpt", 1.0f);
+ return getInstance(numUnits, FixedLength.MPT, 1.0f);
}
//device-dependent units, take the resolution into account
dvalue *= (res * 1000);
} else {
- if ("in".equals(unit)) {
+ if (FixedLength.INCH.equals(unit)) {
dvalue *= 72000;
- } else if ("cm".equals(unit)) {
+ } else if (FixedLength.CM.equals(unit)) {
dvalue *= 28346.4567;
- } else if ("mm".equals(unit)) {
+ } else if (FixedLength.MM.equals(unit)) {
dvalue *= 2834.64567;
- } else if ("pt".equals(unit)) {
+ } else if (FixedLength.POINT.equals(unit)) {
dvalue *= 1000;
- } else if ("pc".equals(unit)) {
+ } else if (FixedLength.PICA.equals(unit)) {
dvalue *= 12000;
- } else if (!"mpt".equals(unit)) {
+ } else if (!FixedLength.MPT.equals(unit)) {
dvalue = 0;
log.error("Unknown length unit '" + unit + "'");
}
/** {@inheritDoc} */
public String toString() {
- return millipoints + "mpt";
+ return millipoints + FixedLength.MPT;
}
/** {@inheritDoc} */
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fo.properties.FixedLength;
import org.apache.fop.render.afp.exceptions.FontRuntimeException;
/**
String pointsize = String.valueOf(size / 1000);
CharacterSet csm = (CharacterSet) charSets.get(pointsize);
if (csm == null) {
- csm = (CharacterSet) charSets.get(size + "mpt");
+ csm = (CharacterSet) charSets.get(size + FixedLength.MPT);
}
if (csm == null) {
// Get char set with nearest font size
for (Iterator it = charSets.entrySet().iterator(); it.hasNext();) {
Map.Entry me = (Map.Entry)it.next();
String key = (String)me.getKey();
- if (!key.endsWith("mpt")) {
+ if (!key.endsWith(FixedLength.MPT)) {
int mpt = Integer.parseInt(key) * 1000;
if (Math.abs(size - mpt) < distance) {
distance = Math.abs(size - mpt);
}
}
if (csm != null) {
- charSets.put(size + "mpt", csm);
+ charSets.put(size + FixedLength.MPT, csm);
String msg = "No " + (size / 1000) + "pt font " + getFontName()
+ " found, substituted with " + pointsize + "pt font";
log.warn(msg);
//FOP
import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.properties.FixedLength;
/** Converts XSL-FO units to RTF units
/** conversion factors keyed by xsl:fo units names */
private static final Map TWIP_FACTORS = new HashMap();
static {
- TWIP_FACTORS.put("mm", new Float(MM_TO_TWIPS));
- TWIP_FACTORS.put("cm", new Float(CM_TO_TWIPS));
- TWIP_FACTORS.put("pt", new Float(POINT_TO_TWIPS));
- TWIP_FACTORS.put("in", new Float(IN_TO_TWIPS));
+ TWIP_FACTORS.put(FixedLength.MM, new Float(MM_TO_TWIPS));
+ TWIP_FACTORS.put(FixedLength.CM, new Float(CM_TO_TWIPS));
+ TWIP_FACTORS.put(FixedLength.POINT, new Float(POINT_TO_TWIPS));
+ TWIP_FACTORS.put(FixedLength.INCH, new Float(IN_TO_TWIPS));
}
/** singleton pattern */
/** convert a font size given in points like "12pt" */
int convertFontSize(String size) throws FOPException {
size = size.trim();
- final String sFONTSUFFIX = "pt";
+ final String sFONTSUFFIX = FixedLength.POINT;
if (!size.endsWith(sFONTSUFFIX)) {
throw new FOPException("Invalid font size '" + size + "', must end with '"
+ sFONTSUFFIX + "'");
import org.apache.fop.fo.pagination.SimplePageMaster;
import org.apache.fop.fo.pagination.StaticContent;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
+import org.apache.fop.fo.properties.FixedLength;
import org.apache.fop.fonts.FontSetup;
import org.apache.fop.render.DefaultFontResolver;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfAfterContainer;
Integer iWidth
= new Integer(tc.getColumnWidth().getValue(context) / 1000);
- String strWidth = iWidth.toString() + "pt";
+ String strWidth = iWidth.toString() + FixedLength.POINT;
Float width = new Float(
FoUnitsConverter.getInstance().convertToTwips(strWidth));
builderContext.getTableContext().setNextColumnWidth(width);
}
//set width in rtf
- //newGraphic.setWidth((long) (contentwidth / 1000f) + "pt");
+ //newGraphic.setWidth((long) (contentwidth / 1000f) + FixedLength.POINT);
rtfGraphic.setWidth((long) (contentwidth / 50f) + "twips");
//set height in rtf
- //newGraphic.setHeight((long) (contentheight / 1000f) + "pt");
+ //newGraphic.setHeight((long) (contentheight / 1000f) + FixedLength.POINT);
rtfGraphic.setHeight((long) (contentheight / 50f) + "twips");
//TODO: make this configurable:
import org.apache.fop.fo.flow.table.TableHeader;
import org.apache.fop.fo.flow.table.TableRow;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
+import org.apache.fop.fo.properties.FixedLength;
import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
LengthProperty lengthprop = (LengthProperty)p;
Float f = new Float(lengthprop.getLength().getValue() / 1000f);
- String sValue = f.toString() + "pt";
+ String sValue = f.toString() + FixedLength.POINT;
attrib.set(BorderAttributesConverter.BORDER_WIDTH,
(int)FoUnitsConverter.getInstance().convertToTwips(sValue));