Class Element

java.lang.Object
com.teamten.typeset.element.Element
All Implemented Interfaces:
Dimensions
Direct Known Subclasses:
DiscardableElement, NonDiscardableElement

public abstract class Element extends Object implements Dimensions
An element that can be stacked horizontally to make a line or vertically to make a page.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract long
    Return the depth (below the baseline) of the element.
    abstract long
    Return the height (above the baseline) of the element.
    final long
    Convenience method for adding the height and depth.
    abstract long
    Return the width of the element.
    abstract long
    layOutHorizontally(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents)
    Add the element to the contents as part of a horizontal sequence.
    abstract long
    layOutVertically(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents)
    Add the element to the contents as part of a vertical sequence.
    void
    println(PrintStream stream, String indent)
    Pretty prints the element to the PrintWriter with the given indent.
    static void
    println(Iterable<? extends Element> elements, PrintStream stream, String indent)
    Convenience method for implementing println(PrintStream, String) from a list of elements.
    boolean
    Returns whether this element, at the beginning of a line or page, should be skipped.
    Return a text version of the element, ideally containing only the text of the element and its children.
    protected static String
    Convenience method for implementing toTextString() from a list of elements.
    void
    visit(Consumer<Element> consumer)
    Calls the consumer on this element and all child elements in pre-order.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Element

      public Element()
  • Method Details

    • getWidth

      public abstract long getWidth()
      Return the width of the element.
      Specified by:
      getWidth in interface Dimensions
    • getHeight

      public abstract long getHeight()
      Return the height (above the baseline) of the element.
      Specified by:
      getHeight in interface Dimensions
    • getDepth

      public abstract long getDepth()
      Return the depth (below the baseline) of the element.
      Specified by:
      getDepth in interface Dimensions
    • visit

      public void visit(Consumer<Element> consumer)
      Calls the consumer on this element and all child elements in pre-order. The default implementation just calls the consumer on this element.
    • layOutHorizontally

      public abstract long layOutHorizontally(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException
      Add the element to the contents as part of a horizontal sequence.
      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 abstract long layOutVertically(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException
      Add the element to the contents as part of a vertical sequence.
      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)
      Pretty prints the element to the PrintWriter with the given indent. The method must print its own newline.
    • println

      public static void println(Iterable<? extends Element> elements, PrintStream stream, String indent)
      Convenience method for implementing println(PrintStream, String) from a list of elements.
    • toTextString

      public String toTextString()
      Return a text version of the element, ideally containing only the text of the element and its children.
    • getVerticalSize

      public final long getVerticalSize()
      Convenience method for adding the height and depth.
    • toTextString

      protected static String toTextString(List<Element> elements)
      Convenience method for implementing toTextString() from a list of elements.
    • shouldSkipElementAtStart

      public boolean shouldSkipElementAtStart()
      Returns whether this element, at the beginning of a line or page, should be skipped.