Class Text

All Implemented Interfaces:
Dimensions

public class Text extends Box
A sequence of characters.
  • Constructor Details

    • Text

      public Text(@NotNull @NotNull SizedFont font, @NotNull @NotNull String text, long width, long height, long depth)
      Constructor for string of any size.
    • Text

      public Text(@NotNull @NotNull String text, @NotNull @NotNull SizedFont font)
      Constructor for a string.
    • Text

      public Text(int ch, @NotNull @NotNull SizedFont font)
      Constructor for single character.
  • Method Details

    • getText

      @NotNull public @NotNull String getText()
      The text that this element was constructed with.
    • getFont

      @NotNull public @NotNull SizedFont getFont()
      The font the text should be displayed in.
    • isCompatibleWith

      public boolean isCompatibleWith(Text other)
      Whether this text can be appended to the other text.
    • containsRightToLeftText

      public boolean containsRightToLeftText()
      Whether any character in the text is right-to-left.
    • getCharacterDirection

      public Text.CharacterDirection getCharacterDirection()
      Return the character direction of the Text. The Text must contain only a single direction throughout.
      Throws:
      IllegalStateException - if the Text contains more than one direction.
    • breakUpInto

      public void breakUpInto(Collection<Element> list)
      Add one Text object for each character in this object.
    • appendedWith

      public Text appendedWith(Text other)
      Returns a new Text object, the text of which is the concatenation of this text and the other text.
      Throws:
      IllegalArgumentException - if the two text objects are not compatible.
    • layOutHorizontally

      public long layOutHorizontally(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException
      Description copied from class: Element
      Add the element to the contents as part of a horizontal sequence.
      Overrides:
      layOutHorizontally in class Box
      Parameters:
      x - the left-most point of the element.
      y - the baseline of the element.
      contents - the stream to add the element to.
      Returns:
      how much to move right afterward.
      Throws:
      IOException
    • layOutVertically

      public long layOutVertically(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException
      Description copied from class: Element
      Add the element to the contents as part of a vertical sequence.
      Overrides:
      layOutVertically in class Box
      Parameters:
      x - the left-most point of the element.
      y - the upper-left point of the element.
      contents - the stream to add the element to.
      Returns:
      how much to move down afterward.
      Throws:
      IOException
    • println

      public void println(PrintStream stream, String indent)
      Description copied from class: Element
      Pretty prints the element to the PrintWriter with the given indent. The method must print its own newline.
      Overrides:
      println in class Element
    • toString

      public String toString()
      Overrides:
      toString in class Box
    • toTextString

      public String toTextString()
      Description copied from class: Element
      Return a text version of the element, ideally containing only the text of the element and its children.
      Overrides:
      toTextString in class Element
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object