Class Penalty

All Implemented Interfaces:
Dimensions

public class Penalty extends DiscardableElement
A location where the line or page can be broken, but with a penalty.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Prevents breaking a line or page at this location.

    Fields inherited from class com.teamten.typeset.element.Element

    DRAW_DEBUG
  • Constructor Summary

    Constructors
    Constructor
    Description
    Penalty(long penalty)
    Create a penalty with the given score that is not limited to only even pages.
    Penalty(long penalty, boolean evenPageOnly)
    Create a penalty with the given score and whether to only apply the penalty at the end of even pages.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Return the depth (below the baseline) of the element.
    long
    Return the height (above the baseline) of the element.
    long
    Gets the value of the penalty.
    long
    Return the width of the element.
    boolean
    Whether this penalty should only be considered at the end of even pages.
    long
    layOutHorizontally(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents)
    Add the element to the contents as part of a horizontal sequence.
    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.

    Methods inherited from class com.teamten.typeset.element.Element

    getVerticalSize, println, shouldSkipElementAtStart, toTextString, toTextString, visit

    Methods inherited from class java.lang.Object

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

    • INFINITY

      public static final long INFINITY
      Prevents breaking a line or page at this location. When negated, forces a break.
      See Also:
  • Constructor Details

    • Penalty

      public Penalty(long penalty, boolean evenPageOnly)
      Create a penalty with the given score and whether to only apply the penalty at the end of even pages. When true, the penalty will be ignored if it's considered for breaking the end of an odd page. This is used to force the next section to start on an odd page.
    • Penalty

      public Penalty(long penalty)
      Create a penalty with the given score that is not limited to only even pages.
  • Method Details

    • getPenalty

      public long getPenalty()
      Gets the value of the penalty.
      Returns:
      the value of the penalty.
    • isEvenPageOnly

      public boolean isEvenPageOnly()
      Whether this penalty should only be considered at the end of even pages.
    • getWidth

      public long getWidth()
      Description copied from class: Element
      Return the width of the element.
      Specified by:
      getWidth in interface Dimensions
      Specified by:
      getWidth in class Element
    • getHeight

      public long getHeight()
      Description copied from class: Element
      Return the height (above the baseline) of the element.
      Specified by:
      getHeight in interface Dimensions
      Specified by:
      getHeight in class Element
    • getDepth

      public long getDepth()
      Description copied from class: Element
      Return the depth (below the baseline) of the element.
      Specified by:
      getDepth in interface Dimensions
      Specified by:
      getDepth in class Element
    • 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.
      Specified by:
      layOutHorizontally in class Element
      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.
      Specified by:
      layOutVertically in class Element
      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