public class TextSequenceUtil extends Object
| Constructor and Description |
|---|
TextSequenceUtil() |
| Modifier and Type | Method and Description |
|---|---|
protected static TextFragment |
deriveFromExisting(TextFragment toDeriveFrom,
String text,
float leftMargin,
float rightMargin)
Derive a new TextFragment from an existing one, means use attributes like
font, color etc.
|
static TextFlow |
deWrap(TextSequence text)
De-wraps the given text, means any new lines introduced by wrapping will
be removed.
|
static Dividable.Divided |
divide(TextSequence text,
float maxWidth,
float maxHeight)
Word-wraps and divides the given text sequence.
|
static void |
drawText(TextSequence text,
org.apache.pdfbox.pdmodel.PDPageContentStream contentStream,
Position upperLeft,
DrawListener drawListener,
Alignment alignment,
float maxWidth,
float lineSpacing,
boolean applyLineSpacingToFirstLine)
Draws the given text sequence to the PDPageContentStream at the given
position.
|
static float |
getEmWidth(FontDescriptor fontDescriptor)
Returns the width of the character
M in the given font. |
static float |
getHeight(TextSequence textSequence,
float maxWidth,
float lineSpacing,
boolean applyLineSpacingToFirstLine)
Calculates the height of the text
|
static List<TextLine> |
getLines(TextSequence text)
Dissects the given sequence into
TextLines. |
static float |
getMaxWidth(Iterable<TextLine> lines)
Calculates the max width of all text lines.
|
static float |
getOffset(TextSequence textLine,
float targetWidth,
Alignment alignment)
Gets the (left) offset of the line with respect to the target width and
alignment.
|
static float |
getStringWidth(String text,
FontDescriptor fontDescriptor)
Returns the width of the given text in the given font.
|
static float |
getWidth(TextSequence textSequence,
float maxWidth)
Calculates the width of the text
|
static TextFlow |
splitWords(TextFragment text)
Splits the fragment into words.
|
static TextFlow |
wordWrap(TextSequence text,
float maxWidth)
Word-wraps the given text sequence in order to fit the max width.
|
static List<TextLine> |
wordWrapToLines(TextSequence text,
float maxWidth)
Convencience function that
word-wraps into getLines(TextSequence). |
public static List<TextLine> getLines(TextSequence text) throws IOException
TextLines.text - the text to extract the lines from.IOException - by pdfboxpublic static Dividable.Divided divide(TextSequence text, float maxWidth, float maxHeight) throws IOException
text - the text to divide.maxWidth - the max width used for word-wrapping.maxHeight - the max height for divide.IOException - by pdfboxpublic static TextFlow wordWrap(TextSequence text, float maxWidth) throws IOException
text - the text to word-wrap.maxWidth - the max width to fit.IOException - by pdfboxpublic static TextFlow deWrap(TextSequence text) throws IOException
text - the text to de-wrap.IOException - by PDFBoxpublic static List<TextLine> wordWrapToLines(TextSequence text, float maxWidth) throws IOException
word-wraps into getLines(TextSequence).text - the text to word-wrap.maxWidth - the max width to fit.IOException - by pdfboxpublic static TextFlow splitWords(TextFragment text)
text - the text to split.protected static TextFragment deriveFromExisting(TextFragment toDeriveFrom, String text, float leftMargin, float rightMargin)
toDeriveFrom - the fragment to derive from.text - the new text.leftMargin - the new left margin.rightMargin - the new right margin.public static float getEmWidth(FontDescriptor fontDescriptor) throws IOException
M in the given font.fontDescriptor - font and size.M.IOException - by pdfboxpublic static float getStringWidth(String text, FontDescriptor fontDescriptor) throws IOException
text - the text to measure.fontDescriptor - font and size.IOException - by pdfboxpublic static void drawText(TextSequence text, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, Position upperLeft, DrawListener drawListener, Alignment alignment, float maxWidth, float lineSpacing, boolean applyLineSpacingToFirstLine) throws IOException
text - the text to draw.contentStream - the stream to draw toupperLeft - the position of the start of the first line.drawListener - the listener to
notify on drawn objects.alignment - how to align the text lines.maxWidth - if > 0, the text may be word-wrapped to match the width.lineSpacing - the line spacing factor.applyLineSpacingToFirstLine - indicates if the line spacing should be applied to the first
line also. Makes sense in most cases to do so.IOException - by pdfboxpublic static float getOffset(TextSequence textLine, float targetWidth, Alignment alignment) throws IOException
textLine - the texttargetWidth - the target widthalignment - the alignment of the line.IOException - by pdfboxpublic static float getMaxWidth(Iterable<TextLine> lines) throws IOException
lines - the lines for which to calculate the max width.IOException - by pdfbox.public static float getWidth(TextSequence textSequence, float maxWidth) throws IOException
textSequence - the text.maxWidth - if > 0, the text may be word-wrapped to match the width.IOException - by pdfbox.public static float getHeight(TextSequence textSequence, float maxWidth, float lineSpacing, boolean applyLineSpacingToFirstLine) throws IOException
textSequence - the text.maxWidth - if > 0, the text may be word-wrapped to match the width.lineSpacing - the line spacing factor.applyLineSpacingToFirstLine - indicates if the line spacing should be applied to the first
line also. Makes sense in most cases to do so.IOException - by pdfboxCopyright © 2022. All rights reserved.