Package com.adobe.xfa.text
Class TextMeasurement
- java.lang.Object
-
- com.adobe.xfa.text.TextMeasurement
-
public class TextMeasurement extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_PRECISIONstatic intTYPE_EMProportional to the font em width (normally the font height).static intTYPE_LENGTHAn absolute measurement on the document.static intTYPE_PERCENTProportional to the width of the space character, but expressed as a percentage in markup.static TextMeasurementZERO
-
Constructor Summary
Constructors Constructor Description TextMeasurement()Default constructor.TextMeasurement(int eType, double dScale)Create a relative measurement.TextMeasurement(UnitSpan oLength)Create a length type measurement, given a length value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object object)Equality comparison.UnitSpanflatten(FontInstance oFontInstance)Determine the absolute value of this measurement.UnitSpanflatten(UnitSpan oBaseValue)Determine the absolute value of this measurement in the absence of font information.static TextMeasurementfromString(java.lang.String sValue)static TextMeasurementfromString(java.lang.String sValue, int eDefaultUnits)static TextMeasurementfromString(java.lang.String sValue, int eDefaultUnits, boolean bValuePerUnit)Populate this measurement from the content of a given string.UnitSpangetLength()Return the length value for this measurement object.intgetLengthValue()Return the integer value of the length.doublegetScale()Get the scale value for relative measurements.intgetType()Return the type of this measurement object.inthashCode()Returns a hash code value for the object.booleanisZero()Determine whether this measurement represents a zero value.static booleanmatch(TextMeasurement m1, TextMeasurement m2)java.lang.StringtoString()java.lang.StringtoString(int nPrecision)Generate a string from the current value of this measurement object.static TextMeasurementzero()
-
-
-
Field Detail
-
TYPE_LENGTH
public static final int TYPE_LENGTH
An absolute measurement on the document. Manifested as a UnitSpan value.- See Also:
- Constant Field Values
-
TYPE_EM
public static final int TYPE_EM
Proportional to the font em width (normally the font height). The value is a scale factor of type double. A value of 1 yields the em width.- See Also:
- Constant Field Values
-
TYPE_PERCENT
public static final int TYPE_PERCENT
Proportional to the width of the space character, but expressed as a percentage in markup. A value of 1 yields the space width, but will appear in markup as "100%".- See Also:
- Constant Field Values
-
DEFAULT_PRECISION
public static final int DEFAULT_PRECISION
- See Also:
- Constant Field Values
-
ZERO
public static final TextMeasurement ZERO
-
-
Constructor Detail
-
TextMeasurement
public TextMeasurement()
Default constructor. The measurement is of type length, with a value of zero.
-
TextMeasurement
public TextMeasurement(UnitSpan oLength)
Create a length type measurement, given a length value.- Parameters:
oLength- - Initial length value to be stored in this measurement.
-
TextMeasurement
public TextMeasurement(int eType, double dScale)Create a relative measurement.- Parameters:
eType- - Type of the measurement. Must be either TYPE_EM or TYPE_PERCENT.dScale- - Scale factor for the measurement. Note that for percentage measurement the given value is not scaled by 100 (e.g, pass 1.0 to get 100%).
-
-
Method Detail
-
flatten
public UnitSpan flatten(FontInstance oFontInstance)
Determine the absolute value of this measurement.Used at run-time, this method returns an absolute length corresponding to the measurement, irrespective of the measurement type. If the measurement is of type length, it already represents an absolute amount. Otherwise, the given font is used to scale the relative value appropriately.
- Parameters:
oFontInstance- - Font instance to use to scale relative amounts. If this is a null reference, zero is returned. If the measurement type is percent and the font has no space character, the measurement is treated as being of type em.- Returns:
- Resulting absolute measurement.
-
flatten
public UnitSpan flatten(UnitSpan oBaseValue)
Determine the absolute value of this measurement in the absence of font information.This is a sort of poor person's Flatten() method. If the font information is not available, one call call this overload, typically with the font height. If the measurement type is relative, it applies the scale to the given unit span. Otherwise it simply returns the (absolute) length.
- Parameters:
oBaseValue- - Base unit span to apply relative scales to.- Returns:
- Resulting absolute measurement.
-
getType
public int getType()
Return the type of this measurement object.- Returns:
- Measurement type.
-
getLength
public UnitSpan getLength()
Return the length value for this measurement object.- Returns:
- Absolute length value of this measurement. Return value is not predictable if the measurement type is percent or em.
-
getLengthValue
public int getLengthValue()
Return the integer value of the length. This is a convenience method for callers. Assuming that the measurement type is length, it returns the value of the length unit span.- Returns:
- Integer value of the length unit span if the type is length. Otherwise, the return value is undefined.
-
getScale
public double getScale()
Get the scale value for relative measurements.- Returns:
- Scale value. Return value is not predictable if the measurement type length.
-
isZero
public boolean isZero()
Determine whether this measurement represents a zero value. An absolute measurement is zero if its length is zero. A relative measurement is zero if its scale factor is zero.- Returns:
- True if this measurement represents a zero value; false if it does not.
-
fromString
public static TextMeasurement fromString(java.lang.String sValue, int eDefaultUnits, boolean bValuePerUnit)
Populate this measurement from the content of a given string.- Parameters:
sValue- - String value to use. This is essentially an extension of the allowable syntax for creating unit spans.- Returns:
- True if the string was valid; false if not. If this method returns false, the content of the measurement is not altered.
-
fromString
public static TextMeasurement fromString(java.lang.String sValue, int eDefaultUnits)
-
fromString
public static TextMeasurement fromString(java.lang.String sValue)
-
toString
public java.lang.String toString(int nPrecision)
Generate a string from the current value of this measurement object.- Parameters:
nPrecision- - (optional) Maximum number of decimal places in the result. Default is six.- Returns:
- String value. This can be persisted and subsequently passed to the FromString() method to populate a measurement.
-
match
public static boolean match(TextMeasurement m1, TextMeasurement m2)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
Equality comparison.Two measurements are considered equal if they have the same type and the appropriate values match (length for length types, scale for relative types).
- Overrides:
equalsin classjava.lang.Object- Parameters:
object- Measurement to compare against.- Returns:
- True if the measurements are considered equal; false if not.
-
hashCode
public int hashCode()
Returns a hash code value for the object.- Overrides:
hashCodein classjava.lang.Object
-
zero
public static TextMeasurement zero()
-
-