git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@627719 13f79535-47bb-0310-9956-ffa450edef68tags/fop-0_95beta
@@ -25,6 +25,7 @@ import org.apache.fop.apps.FOUserAgent; | |||
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; | |||
/** | |||
@@ -121,7 +122,7 @@ public class NumericProperty extends Property implements Numeric, Length { | |||
/** {@inheritDoc} */ | |||
public String toString() { | |||
if (dim == 1) { | |||
return (int) value + "mpt"; | |||
return (int) value + FixedLength.MPT; | |||
} else { | |||
return value + "^" + dim; | |||
} |
@@ -26,11 +26,29 @@ import org.apache.fop.datatypes.PercentBaseContext; | |||
*/ | |||
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; | |||
@@ -96,7 +114,7 @@ public final class FixedLength extends LengthProperty { | |||
* 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); | |||
} | |||
@@ -115,17 +133,17 @@ public final class FixedLength extends LengthProperty { | |||
//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 + "'"); | |||
} | |||
@@ -163,7 +181,7 @@ public final class FixedLength extends LengthProperty { | |||
/** {@inheritDoc} */ | |||
public String toString() { | |||
return millipoints + "mpt"; | |||
return millipoints + FixedLength.MPT; | |||
} | |||
/** {@inheritDoc} */ |
@@ -25,6 +25,7 @@ import java.util.Map; | |||
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; | |||
/** | |||
@@ -75,7 +76,7 @@ public class RasterFont extends AFPFont { | |||
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 | |||
@@ -83,7 +84,7 @@ public class RasterFont extends AFPFont { | |||
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); | |||
@@ -93,7 +94,7 @@ public class RasterFont extends AFPFont { | |||
} | |||
} | |||
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); |
@@ -24,6 +24,7 @@ import java.util.HashMap; | |||
//FOP | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.fo.properties.FixedLength; | |||
/** Converts XSL-FO units to RTF units | |||
@@ -51,10 +52,10 @@ final class FoUnitsConverter { | |||
/** 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 */ | |||
@@ -125,7 +126,7 @@ final class FoUnitsConverter { | |||
/** 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 + "'"); |
@@ -85,6 +85,7 @@ import org.apache.fop.fo.pagination.Region; | |||
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; | |||
@@ -578,7 +579,7 @@ public class RTFHandler extends FOEventHandler { | |||
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); | |||
@@ -1277,11 +1278,11 @@ public class RTFHandler extends FOEventHandler { | |||
} | |||
//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: |
@@ -29,6 +29,7 @@ import org.apache.fop.fo.flow.table.TableCell; | |||
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; | |||
@@ -343,7 +344,7 @@ public final class TableAttributesConverter { | |||
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)); |