Class PlainText.Paragraph

java.lang.Object
org.apache.pdfbox.pdmodel.interactive.form.PlainText.Paragraph
Enclosing class:
PlainText

static class PlainText.Paragraph extends Object
A block of text to be formatted as a whole.

A block of text can contain multiple paragraphs which will be treated individually within the block placement.

  • Field Details

    • textContent

      private final String textContent
  • Constructor Details

    • Paragraph

      Paragraph(String text)
  • Method Details

    • getText

      String getText()
      Get the paragraph text.
      Returns:
      the text.
    • getLines

      List<PlainText.Line> getLines(PDFont font, float fontSize, float width) throws IOException
      Break the paragraph into individual lines.
      Parameters:
      font - the font used for rendering the text.
      fontSize - the fontSize used for rendering the text.
      width - the width of the box holding the content.
      Returns:
      the individual lines.
      Throws:
      IOException
    • buildPrefixWidths

      private static float[] buildPrefixWidths(String word, PDFont font, float scale) throws IOException
      Build the prefix-sum array of scaled character widths for the given word.
      Parameters:
      word - the word to measure.
      font - the font used to obtain glyph advance widths.
      scale - fontSize / FONTSCALE, pre-computed by the caller.
      Returns:
      the float[word.length() + 1] prefix-sum array.
      Throws:
      IOException - if the font cannot provide a glyph width.
    • findMaxFittingChars

      private static int findMaxFittingChars(float[] prefixWidth, float width)
      Find the maximum number of Java chars from a prefix-width array that fit within the given available width.

      Binary search over the pre-computed prefixWidth array. The result is always at least 1 so that the caller is guaranteed to make forward progress (PDFBOX-6082).

      Parameters:
      prefixWidth - array as returned by buildPrefixWidths(java.lang.String, org.apache.pdfbox.pdmodel.font.PDFont, float); length is wordLength + 1.
      width - the available line width in the same unit as the widths stored in prefixWidth.
      Returns:
      the largest index k >= 1 such that prefixWidth[k] < width, or 1 if even a single character exceeds the available width.