Class TextMeasurement


  • public class TextMeasurement
    extends java.lang.Object
    • 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
    • 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.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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:
        equals in class java.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:
        hashCode in class java.lang.Object