Class TextBaselineShift


  • public class TextBaselineShift
    extends java.lang.Object
    This class defines a text baseline shift attribute. It's loosely modelled after the proposed XSL baseline shift attribute See baseline-shift The differences in implementation from the XSL variation include:
    1. We support only baseline, <percentage> and <length> values
    2. The adjusted baseline will be calculated relative to the preceding text, rather than the parent.
    3. There is no accompanying "shift-direction" attribute, so negative percentages and lengths will shift up, and positive values will shift down.
    • Constructor Detail

      • TextBaselineShift

        public TextBaselineShift()
        Default constructor. Creates a baseline shift with a value "baseline" - No baseline shift.
      • TextBaselineShift

        public TextBaselineShift​(TextBaselineShift oSource)
        Copy constructor
        Parameters:
        oSource - the TextBaselineShift object to copy
      • TextBaselineShift

        public TextBaselineShift​(double dPercentage)
        Create a baseline shift with a percentage offset
        Parameters:
        dPercentage - the amount to shift by. Negative percentages shift up, positive values shift down. The percentage is relative to the current line height.
      • TextBaselineShift

        public TextBaselineShift​(UnitSpan oLength)
        Create a baseline shift with a fixed offset
        Parameters:
        oLength - the absolute value to shift by. Negative values shift up, positive values shift down.
      • TextBaselineShift

        public TextBaselineShift​(int eType,
                                 int nLevel)
        Create a baseline shift by type, with optional level.

        This constructor is intended primarily to create subscript and superscript baseline shifts. It can take any type code, but if that code is not for a subscript or superscript, the shift is effectively neutral.

        Parameters:
        eType - - Type code for the new shift object.
        nLevel - - Subscript or superscript level. Ignored if the type code is for something other than subscript or superscript. Defaults to one.
      • TextBaselineShift

        public TextBaselineShift​(java.lang.String sString,
                                 boolean bSuppressInversion)
        Create a baseline shift from a string
        Parameters:
        sString - a textual representation of the baseline value. Should be something like "baseline" or "15%" or "2pt".
    • Method Detail

      • flatten

        public UnitSpan[] flatten​(UnitSpan oStartingBaseline,
                                  UnitSpan oLineHeight,
                                  UnitSpan poFontSize)
        Apply this baseline shift to a baseline value and return font size
        Parameters:
        oStartingBaseline - the current baseline position
        oLineHeight - The height of the current line
        Returns:
        A two UnitSpan array with the adjusted baseline value and the new font size.
      • applyShift

        public UnitSpan applyShift​(UnitSpan oStartingBaseline,
                                   UnitSpan oLineHeight)
        Apply this baseline shift to a baseline value
        Parameters:
        oStartingBaseline - the current baseline position
        oLineHeight - The height of the current line
        Returns:
        the adjusted baseline value.
      • getString

        public java.lang.String getString​(boolean bSuppressInversion)
        Represent the value of this shift as a string
        Returns:
        a string that represents this shift. A value such as: "baseline" or "25%" or "0.15in"
      • getType

        public int getType()
        Return the type of shift.
        Returns:
        A value from the TypeCode enumeration to indicate whether this is an absolute, percentage or neutral shift.
      • getLength

        public UnitSpan getLength()
        Return the absolute shift.
        Returns:
        absolute shift amount. Value is meaningful only if this is an absolute (length) type shift.
      • getPercentage

        public double getPercentage()
        Return the percentage shift.
        Returns:
        Percentage shift amount. Value is meaningful only if this is a percentage type shift.
      • getLevel

        public int getLevel()
        Return the subscript or superscript level.
        Returns:
        Subscript or superscript level. Value is meaningful only if this is a subscript or superscript type shift.
      • isNeutral

        public boolean isNeutral()
        Find out whether this shift has no effect.
        Returns:
        Boolean indicating TRUE if the shift is neutral.
      • isDownShift

        public boolean isDownShift()
        Find out whether this shift adjusts in the positive (down/subscript) direction or not.
        Returns:
        Boolean indicating TRUE if the shift is downward.
      • equals

        public boolean equals​(java.lang.Object object)
        Equality operator
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - the object to compare
        Returns:
        one if equal
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • notEqual

        public boolean notEqual​(TextBaselineShift oCompare)
        Inequality operator
        Parameters:
        oCompare - the object to compare
        Returns:
        one if not equal