Class PlainText.Paragraph
java.lang.Object
org.apache.pdfbox.pdmodel.interactive.form.PlainText.Paragraph
- Enclosing class:
PlainText
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static float[]buildPrefixWidths(String word, PDFont font, float scale) Build the prefix-sum array of scaled character widths for the given word.private static intfindMaxFittingChars(float[] prefixWidth, float width) Find the maximum number of Java chars from a prefix-width array that fit within the given available width.(package private) List<PlainText.Line> Break the paragraph into individual lines.(package private) StringgetText()Get the paragraph text.
-
Field Details
-
textContent
-
-
Constructor Details
-
Paragraph
Paragraph(String text)
-
-
Method Details
-
getText
String getText()Get the paragraph text.- Returns:
- the text.
-
getLines
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
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
prefixWidtharray. The result is always at least1so that the caller is guaranteed to make forward progress (PDFBOX-6082).- Parameters:
prefixWidth- array as returned bybuildPrefixWidths(java.lang.String, org.apache.pdfbox.pdmodel.font.PDFont, float); length iswordLength + 1.width- the available line width in the same unit as the widths stored inprefixWidth.- Returns:
- the largest index
k >= 1such thatprefixWidth[k] < width, or1if even a single character exceeds the available width.
-