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 withTextState
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");
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
|
float |
getCharacterSpacing()
Gets character spacing of the text, represented by the
TextFragment object. |
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 |
Color |
getForegroundColor()
Gets foreground color of the text, represented by the
TextFragment object |
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.
|
TabStops |
getTabStops()
Gets tabstops for the text.
|
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. |
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 |
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 |
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 |
setStrikeOut(boolean value)
Sets strikeout for the text, represented by the
TextFragment object |
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, getBackgroundColor, getStrikeOut, isUnderline
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 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.
TextFragment
initialization. Tabstops must be constructed before the
text.
public float getLineSpacing()
Gets line spacing of the text.
getLineSpacing
in class TextState
public void setLineSpacing(float value)
Sets line spacing of the text.
setLineSpacing
in class TextState
value
- float value
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 void setBackgroundColor(Color value)
Sets background color of the text, represented by the TextFragment
object
setBackgroundColor
in class TextState
value
- Color objectpublic 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 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.
getHorizontalAlignment
in class TextState
HorizontalAlignment
public void setHorizontalAlignment(int value)
Sets horizontal alignment for the text.
setHorizontalAlignment
in class TextState
value
- HorizontalAlignment valueHorizontalAlignment
public void applyChangesFrom(TextState textState)
Applies settings from another textState
applyChangesFrom
in class TextState
textState
- Text state object.
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)Copyright © 2016 Aspose. All Rights Reserved.