Class PlainText.Paragraph
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.interactive.form.PlainText.Paragraph
-
- Enclosing class:
- PlainText
static class PlainText.Paragraph extends java.lang.ObjectA 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 Modifier and Type Field Description private java.lang.StringtextContent
-
Constructor Summary
Constructors Constructor Description Paragraph(java.lang.String text)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static float[]buildPrefixWidths(java.lang.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) java.util.List<PlainText.Line>getLines(PDFont font, float fontSize, float width)Break the paragraph into individual lines.(package private) java.lang.StringgetText()Get the paragraph text.
-
-
-
Method Detail
-
getText
java.lang.String getText()
Get the paragraph text.- Returns:
- the text.
-
getLines
java.util.List<PlainText.Line> getLines(PDFont font, float fontSize, float width) throws java.io.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:
java.io.IOException
-
buildPrefixWidths
private static float[] buildPrefixWidths(java.lang.String word, PDFont font, float scale) throws java.io.IOExceptionBuild 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:
java.io.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.
-
-