public final class TextFragmentState extends TextState
Represents a text state of a text fragment.
The example demonstrates how to change text color and font size of the text with TextState
object.
// Open document
Document doc = new Document("D:\\Tests\\input.pdf");
// Create TextFragmentAbsorber object to find all "hello world" text occurrences
TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");
// Accept the absorber for first page
doc.getPages().get(1).accept(absorber);
// Change foreground color of the first text occurrence
absorber.TgetextFragments().get(1).getTextState().setForegroundColor ( java.awt.Color.RED);
// Change font size of the first text occurrence
absorber.getTextFragments().get(1).getTextState().setFontSize ( 15);
// Save document
doc.save("D:\\Tests\\output.pdf");
Provides a way to change following properties of the text: font (TextFragmentState.Font
property) font size (TextFragmentState.FontSize
property) font style (
TextFragmentState.FontStyle
property) foreground color (
TextFragmentState.ForegroundColor
property) background color (
TextFragmentState.BackgroundColor
property)
Note that changing TextFragmentState
properties may change inner
TextFragment.Segments
collection because TextFragment is an aggregate object and it may
rearrange internal segments or merge them into single segment. If your requirement is to leave
the TextFragment.Segments
collection unchanged, please change inner segments
individually.
TextFragmentAbsorber
,
IDocument
TabstopDefaultValue, TabTag
Constructor and Description |
---|
TextFragmentState(TextFragment fragment)
Initializes new instance of the
TextFragmentState object with specified
TextFragment object. |
Modifier and Type | Method and Description |
---|---|
void |
applyChangesFrom(TextState textState)
Applies settings from another textState
|
void |
applyChangesFrom(TextState textState,
boolean groupChangesOnly)
Applies settings from another textState
|
Color |
getBackgroundColor()
Sets background color of the text, represented by the
TextFragment object
|
float |
getCharacterSpacing()
Gets character spacing of the text, represented by the
TextFragment object. |
boolean |
getDrawTextRectangleBorder() |
Font |
getFont()
Gets font of the text, represented by the
TextFragment object
|
float |
getFontSize()
Gets font size of the text, represented by the
TextFragment object
|
int |
getFontStyle()
Sets font style of the text, represented by the
TextFragment object
|
Color |
getForegroundColor()
Gets foreground color of the text, represented by the
TextFragment object
|
TextFormattingOptions |
getFormattingOptions()
Gets or sets formatting options.
|
int |
getHorizontalAlignment()
Gets horizontal alignment for the text.
|
float |
getHorizontalScaling()
Gets horizontal scaling of the text, represented by the
TextFragment object. |
float |
getLineSpacing()
Gets line spacing of the text.
|
int |
getRenderingMode()
Gets or sets rendering mode of the text.
|
double |
getRotation()
Gets or sets rotation angle in degrees.
|
Color |
getStrokingColor()
Gets or sets color stroking operations of
TextFragment rendering (stroke text, rectangle border)
|
TabStops |
getTabStops()
Gets tabstops for the text.
|
float |
getTextHeight()
Gets text height, represented by the
TextFragment object
|
boolean |
getUnderline()
Gets or sets underline for the text, represented by the
TextFragment object
|
float |
getWordSpacing()
Gets word spacing of the text.
|
boolean |
isInvisible()
Gets invisibility of the text.
|
boolean |
isSubscript()
Gets or sets subscript of the text, represented by the
TextFragment object. |
boolean |
isSuperscript()
Gets or sets superscript of the text, represented by the
TextFragment object. |
double |
measureString(String str)
Measures the string.
|
void |
setBackgroundColor(Color value)
Sets background color of the text, represented by the
TextFragment object
|
void |
setCharacterSpacing(float value)
Sets character spacing of the text, represented by the
TextFragment object. |
void |
setDrawTextRectangleBorder(boolean value) |
void |
setFont(Font value)
Sets font of the text, represented by the
TextFragment object
|
void |
setFontSize(float value)
Sets font size of the text, represented by the
TextFragment object
|
void |
setFontStyle(int value)
Sets font style of the text, represented by the
TextFragment object
|
void |
setForegroundColor(Color value)
Sets foreground color of the text, represented by the
TextFragment object
|
void |
setFormattingOptions(TextFormattingOptions value)
Gets or sets formatting options.
|
void |
setHorizontalAlignment(int value)
Sets horizontal alignment for the text.
|
void |
setHorizontalScaling(float value)
Sets horizontal scaling of the text, represented by the
TextFragment object. |
void |
setInvisible(boolean value)
Sets invisibility of the text.
|
void |
setLineSpacing(float value)
Sets line spacing of the text.
|
void |
setRenderingMode(int value)
Gets or sets rendering mode of the text.
|
void |
setRotation(double value)
Gets or sets rotation angle in degrees.
|
void |
setStrikeOut(boolean value)
Sets strikeout for the text, represented by the
TextFragment object
|
void |
setStrokingColor(Color value)
Gets or sets color stroking operations of
TextFragment rendering (stroke text, rectangle border)
|
void |
setSubscript(boolean value)
Gets or sets subscript of the text, represented by the
TextFragment object. |
void |
setSuperscript(boolean value)
Gets or sets superscript of the text, represented by the
TextFragment object. |
void |
setUnderline(boolean value)
Sets underline for the text, represented by the
TextFragment object
|
void |
setWordSpacing(float value)
Sets word spacing of the text.
|
calculateFontSize, getStrikeOut, isUnderline, measureString, setFontSizeSuppressedUpdate, setFontSuppressedUpdate
public TextFragmentState(TextFragment fragment)
Initializes new instance of the TextFragmentState
object with specified
TextFragment
object. This TextFragmentState
initialization is not supported.
TextFragmentState is only available with TextFragment.TextState
property.
fragment
- Text fragment object.public float getCharacterSpacing()
Gets character spacing of the text, represented by the TextFragment
object.
getCharacterSpacing
in class TextState
public void setCharacterSpacing(float value)
Sets character spacing of the text, represented by the TextFragment
object.
setCharacterSpacing
in class TextState
value
- float valuepublic float getHorizontalScaling()
Gets horizontal scaling of the text, represented by the TextFragment
object.
getHorizontalScaling
in class TextState
public void setHorizontalScaling(float value)
Sets horizontal scaling of the text, represented by the TextFragment
object.
setHorizontalScaling
in class TextState
value
- float valuepublic float getWordSpacing()
Gets word spacing of the text.
getWordSpacing
in class TextState
public void setWordSpacing(float value)
Sets word spacing of the text.
setWordSpacing
in class TextState
value
- float valuepublic int getRenderingMode()
Gets or sets rendering mode of the text.
getRenderingMode
in class TextState
TextRenderingMode
public void setRenderingMode(int value)
Gets or sets rendering mode of the text.
setRenderingMode
in class TextState
value
- TextRenderingMode elementTextRenderingMode
public boolean isSubscript()
Gets or sets subscript of the text, represented by the TextFragment
object.
isSubscript
in class TextState
public void setSubscript(boolean value)
Gets or sets subscript of the text, represented by the TextFragment
object.
setSubscript
in class TextState
value
- boolean valuepublic boolean isInvisible()
Gets invisibility of the text.
isInvisible
in class TextState
public void setInvisible(boolean value)
Sets invisibility of the text.
setInvisible
in class TextState
value
- boolean valuepublic boolean isSuperscript()
Gets or sets superscript of the text, represented by the TextFragment
object.
isSuperscript
in class TextState
public void setSuperscript(boolean value)
Gets or sets superscript of the text, represented by the TextFragment
object.
setSuperscript
in class TextState
value
- boolean valuepublic TabStops getTabStops()
Gets tabstops for the text.
Note that Tabstops property works in new document generation scenarios only. Tabstops may be
added during TextFragment
initialization. Tabstops must be constructed before the
text.
public float getLineSpacing()
Gets line spacing of the text.
getLineSpacing
in class TextState
Note that the value is not preserved as a text characteristic within the document. The LineSpacing property getter works for an object in case it was explicitly set previously with LineSpacing setter for those object. The property is used by runtime in context of current generation/modification process.
public void setLineSpacing(float value)
Sets line spacing of the text.
setLineSpacing
in class TextState
value
- float value
Note that the value is not preserved as a text characteristic within the document. The LineSpacing property getter works for an object in case it was explicitly set previously with LineSpacing setter for those object. The property is used by runtime in context of current generation/modification process.
public Color getForegroundColor()
Gets foreground color of the text, represented by the TextFragment
object
getForegroundColor
in class TextState
public void setForegroundColor(Color value)
Sets foreground color of the text, represented by the TextFragment
object
setForegroundColor
in class TextState
value
- Color objectpublic Color getStrokingColor()
Gets or sets color stroking operations of TextFragment
rendering (stroke text, rectangle border)
getStrokingColor
in class TextState
public void setStrokingColor(Color value)
Gets or sets color stroking operations of TextFragment
rendering (stroke text, rectangle border)
setStrokingColor
in class TextState
value
- Color instancepublic Color getBackgroundColor()
Sets background color of the text, represented by the TextFragment
object
getBackgroundColor
in class TextState
public void setBackgroundColor(Color value)
Sets background color of the text, represented by the TextFragment
object
setBackgroundColor
in class TextState
value
- Color valuepublic boolean getUnderline()
Gets or sets underline for the text, represented by the TextFragment
object
public void setUnderline(boolean value)
Sets underline for the text, represented by the TextFragment
object
setUnderline
in class TextState
value
- boolean valuepublic void setStrikeOut(boolean value)
Sets strikeout for the text, represented by the TextFragment
object
setStrikeOut
in class TextState
value
- boolean valuepublic int getFontStyle()
Sets font style of the text, represented by the TextFragment
object
getFontStyle
in class TextState
FontStyles
public void setFontStyle(int value)
Sets font style of the text, represented by the TextFragment
object
setFontStyle
in class TextState
value
- int valueFontStyles
public Font getFont()
Gets font of the text, represented by the TextFragment
object
public void setFont(Font value)
Sets font of the text, represented by the TextFragment
object
public float getFontSize()
Gets font size of the text, represented by the TextFragment
object
getFontSize
in class TextState
public void setFontSize(float value)
Sets font size of the text, represented by the TextFragment
object
setFontSize
in class TextState
value
- float valuepublic int getHorizontalAlignment()
Gets horizontal alignment for the text.
HorizontalAlignment.None is equal to HorizontalAlignment.Left. Note that TextFragmentState.VerticalAlignment property works in new document generation scenarios only.
getHorizontalAlignment
in class TextState
HorizontalAlignment
public void setHorizontalAlignment(int value)
Sets horizontal alignment for the text.
HorizontalAlignment.None is equal to HorizontalAlignment.Left. Note that TextFragmentState.VerticalAlignment property works in new document generation scenarios only.
setHorizontalAlignment
in class TextState
value
- HorizontalAlignment valueHorizontalAlignment
public TextFormattingOptions getFormattingOptions()
Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.
public void setFormattingOptions(TextFormattingOptions value)
Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.
value
- TextFormattingOptions instancepublic float getTextHeight()
Gets text height, represented by the TextFragment
object
getTextHeight
in class TextState
public double getRotation()
Gets or sets rotation angle in degrees.
public void setRotation(double value)
Gets or sets rotation angle in degrees.
value
- double valuepublic boolean getDrawTextRectangleBorder()
public void setDrawTextRectangleBorder(boolean value)
public double measureString(String str)
Measures the string.
measureString
in class TextState
str
- The string.public void applyChangesFrom(TextState textState)
Applies settings from another textState
applyChangesFrom
in class TextState
textState
- Text state object.
Only those properties will be copied that were changed explicitly.
public void applyChangesFrom(TextState textState, boolean groupChangesOnly)
Applies settings from another textState
textState
- Text state object.groupChangesOnly
- if true inherit group changes only (without isolating the segments into single segment)