TextFragmentState

Inheritance: java.lang.Object, com.aspose.pdf.TextState

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.

Constructors

ConstructorDescription
TextFragmentState(TextFragment fragment)Initializes new instance of the TextFragmentState object with specified TextFragment object.

Methods

MethodDescription
getCharacterSpacing()Gets character spacing of the text, represented by the TextFragment object.
setCharacterSpacing(float value)Sets character spacing of the text, represented by the TextFragment object.
getHorizontalScaling()Gets horizontal scaling of the text, represented by the TextFragment object.
setHorizontalScaling(float value)Sets horizontal scaling of the text, represented by the TextFragment object.
getWordSpacing()Gets word spacing of the text.
setWordSpacing(float value)Sets word spacing of the text.
getRenderingMode()Gets or sets rendering mode of the text.
setRenderingMode(int value)Gets or sets rendering mode of the text.
isSubscript()Gets or sets subscript of the text, represented by the TextFragment object.
setSubscript(boolean value)Gets or sets subscript of the text, represented by the TextFragment object.
isInvisible()Gets invisibility of the text.
setInvisible(boolean value)Sets invisibility of the text.
isSuperscript()Gets or sets superscript of the text, represented by the TextFragment object.
setSuperscript(boolean value)Gets or sets superscript of the text, represented by the TextFragment object.
getTabStops()Gets tabstops for the text.
getLineSpacing()Gets line spacing of the text.
setLineSpacing(float value)Sets line spacing of the text.
getForegroundColor()Gets foreground color of the text, represented by the TextFragment object
setForegroundColor(Color value)Sets foreground color of the text, represented by the TextFragment object
getStrokingColor()Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)
setStrokingColor(Color value)Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)
getBackgroundColor()Sets background color of the text, represented by the TextFragment object
setBackgroundColor(Color value)Sets background color of the text, represented by the TextFragment object
isUnderline()Gets or sets underline for the text, represented by the TextFragment object
setUnderline(boolean value)Sets underline for the text, represented by the TextFragment object
getStrikeOut()Gets or sets strikeout for the text, represented by the TextFragment object
setStrikeOut(boolean value)Sets strikeout for the text, represented by the TextFragment object
getFontStyle()Sets font style of the text, represented by the TextFragment object
setFontStyle(int value)Sets font style of the text, represented by the TextFragment object
getFont()Gets font of the text, represented by the TextFragment object
setFont(Font value)Sets font of the text, represented by the TextFragment object
getFontSize()Gets font size of the text, represented by the TextFragment object
setFontSize(float value)Sets font size of the text, represented by the TextFragment object
getHorizontalAlignment()Gets horizontal alignment for the text.
setHorizontalAlignment(HorizontalAlignment value)Sets horizontal alignment for the text.
getFormattingOptions()Gets or sets formatting options.
setFormattingOptions(TextFormattingOptions value)Gets or sets formatting options.
getTextHeight()Gets text height, represented by the TextFragment object
getCoordinateOrigin()Gets or sets text CoordinateOrigin.
setCoordinateOrigin(int value)Gets or sets text CoordinateOrigin.
getRotation()Gets or sets rotation angle in degrees.
setRotation(double value)Gets or sets rotation angle in degrees.
getDrawTextRectangleBorder()Gets if text rectangle border drawn flag.
setDrawTextRectangleBorder(boolean value)Sets if text rectangle border drawn flag.
measureString(String str)Measures the string.
measureHeight(char character)Measures character height.
applyChangesFrom(TextState textState)Applies settings from another textState
isFitRectangle(String str, Rectangle rect)Checks if input string could be placed inside defined rectangle.
applyChangesFrom(TextState textState, boolean groupChangesOnly)Applies settings from another textState

TextFragmentState(TextFragment fragment)

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.

Parameters:

ParameterTypeDescription
fragmentTextFragmentText fragment object.

getCharacterSpacing()

public float getCharacterSpacing()

Gets character spacing of the text, represented by the TextFragment object.

Returns: float - float value

setCharacterSpacing(float value)

public void setCharacterSpacing(float value)

Sets character spacing of the text, represented by the TextFragment object.

Parameters:

ParameterTypeDescription
valuefloatfloat value

getHorizontalScaling()

public float getHorizontalScaling()

Gets horizontal scaling of the text, represented by the TextFragment object.

Returns: float - float value

setHorizontalScaling(float value)

public void setHorizontalScaling(float value)

Sets horizontal scaling of the text, represented by the TextFragment object.

Parameters:

ParameterTypeDescription
valuefloatfloat value

getWordSpacing()

public float getWordSpacing()

Gets word spacing of the text.

Returns: float - float value

setWordSpacing(float value)

public void setWordSpacing(float value)

Sets word spacing of the text.

Parameters:

ParameterTypeDescription
valuefloatfloat value

getRenderingMode()

public int getRenderingMode()

Gets or sets rendering mode of the text.

Returns: int

setRenderingMode(int value)

public void setRenderingMode(int value)

Gets or sets rendering mode of the text.

Parameters:

ParameterTypeDescription
valueint

isSubscript()

public boolean isSubscript()

Gets or sets subscript of the text, represented by the TextFragment object.

Returns: boolean - boolean value

setSubscript(boolean value)

public void setSubscript(boolean value)

Gets or sets subscript of the text, represented by the TextFragment object.

Parameters:

ParameterTypeDescription
valuebooleanboolean value

isInvisible()

public boolean isInvisible()

Gets invisibility of the text.

Returns: boolean - boolean value

setInvisible(boolean value)

public void setInvisible(boolean value)

Sets invisibility of the text.

Parameters:

ParameterTypeDescription
valuebooleanboolean value

isSuperscript()

public boolean isSuperscript()

Gets or sets superscript of the text, represented by the TextFragment object.

Returns: boolean - value boolean value

setSuperscript(boolean value)

public void setSuperscript(boolean value)

Gets or sets superscript of the text, represented by the TextFragment object.

Parameters:

ParameterTypeDescription
valuebooleanboolean value

getTabStops()

public 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.

Returns: TabStops - TabStops object

getLineSpacing()

public float getLineSpacing()

Gets line spacing of the text.

Returns: float - 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.

setLineSpacing(float value)

public void setLineSpacing(float value)

Sets line spacing of the text.

Parameters:

ParameterTypeDescription
valuefloatfloat 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. |

getForegroundColor()

public Color getForegroundColor()

Gets foreground color of the text, represented by the TextFragment object

Returns: Color - Color object

setForegroundColor(Color value)

public void setForegroundColor(Color value)

Sets foreground color of the text, represented by the TextFragment object

Parameters:

ParameterTypeDescription
valueColorColor object

getStrokingColor()

public Color getStrokingColor()

Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)

Returns: Color

setStrokingColor(Color value)

public void setStrokingColor(Color value)

Gets or sets color stroking operations of TextFragment rendering (stroke text, rectangle border)

Parameters:

ParameterTypeDescription
valueColor

getBackgroundColor()

public Color getBackgroundColor()

Sets background color of the text, represented by the TextFragment object

Returns: Color - value Color object

setBackgroundColor(Color value)

public void setBackgroundColor(Color value)

Sets background color of the text, represented by the TextFragment object

Parameters:

ParameterTypeDescription
valueColor

isUnderline()

public boolean isUnderline()

Gets or sets underline for the text, represented by the TextFragment object

Returns: boolean - boolean value

setUnderline(boolean value)

public void setUnderline(boolean value)

Sets underline for the text, represented by the TextFragment object

Parameters:

ParameterTypeDescription
valuebooleanboolean value

getStrikeOut()

public boolean getStrikeOut()

Gets or sets strikeout for the text, represented by the TextFragment object

Returns: boolean - boolean value

setStrikeOut(boolean value)

public void setStrikeOut(boolean value)

Sets strikeout for the text, represented by the TextFragment object

Parameters:

ParameterTypeDescription
valuebooleanboolean value

getFontStyle()

public int getFontStyle()

Sets font style of the text, represented by the TextFragment object

Returns: int - FontStyles element

setFontStyle(int value)

public void setFontStyle(int value)

Sets font style of the text, represented by the TextFragment object

Parameters:

ParameterTypeDescription
valueintint value

getFont()

public Font getFont()

Gets font of the text, represented by the TextFragment object

Returns: Font - Font value

setFont(Font value)

public void setFont(Font value)

Sets font of the text, represented by the TextFragment object

Parameters:

ParameterTypeDescription
valueFontFont value

getFontSize()

public float getFontSize()

Gets font size of the text, represented by the TextFragment object

Returns: float - float value

setFontSize(float value)

public void setFontSize(float value)

Sets font size of the text, represented by the TextFragment object

Parameters:

ParameterTypeDescription
valuefloatfloat value

getHorizontalAlignment()

public HorizontalAlignment 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.

Returns: HorizontalAlignment - HorizontalAlignment value

setHorizontalAlignment(HorizontalAlignment value)

public void setHorizontalAlignment(HorizontalAlignment 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.

Parameters:

ParameterTypeDescription
valueHorizontalAlignmentHorizontalAlignment value

getFormattingOptions()

public TextFormattingOptions getFormattingOptions()

Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.

Returns: TextFormattingOptions - TextFormattingOptions instance

setFormattingOptions(TextFormattingOptions value)

public void setFormattingOptions(TextFormattingOptions value)

Gets or sets formatting options. Setting of the options will be effective in generator scenarios only.

Parameters:

ParameterTypeDescription
valueTextFormattingOptionsTextFormattingOptions instance

getTextHeight()

public float getTextHeight()

Gets text height, represented by the TextFragment object

Returns: float - float value

getCoordinateOrigin()

public int getCoordinateOrigin()

Gets or sets text CoordinateOrigin. If CoordinateOrigin is Descender, the text Y coordinate corresponds to the font’s lowest point. If CoordinateOrigin is BaseLine, the text Y coordinate corresponds to the font’s baseline. The default value is Descender. If the font’s Descent value is too big, text can be rendered higher than other fonts. In this case, CoordinateOrigin BaseLine can be selected for better text rendering.

Returns: int - CoordinateOrigin element

setCoordinateOrigin(int value)

public void setCoordinateOrigin(int value)

Gets or sets text CoordinateOrigin. If CoordinateOrigin is Descender, the text Y coordinate corresponds to the font’s lowest point. If CoordinateOrigin is BaseLine, the text Y coordinate corresponds to the font’s baseline. The default value is Descender. If the font’s Descent value is too big, text can be rendered higher than other fonts. In this case, CoordinateOrigin BaseLine can be selected for better text rendering.

Parameters:

ParameterTypeDescription
valueintCoordinateOrigin element

getRotation()

public double getRotation()

Gets or sets rotation angle in degrees.

Returns: double - double value

setRotation(double value)

public void setRotation(double value)

Gets or sets rotation angle in degrees.

Parameters:

ParameterTypeDescription
valuedoubledouble value

getDrawTextRectangleBorder()

public boolean getDrawTextRectangleBorder()

Gets if text rectangle border drawn flag.

Returns: boolean - boolean value

setDrawTextRectangleBorder(boolean value)

public void setDrawTextRectangleBorder(boolean value)

Sets if text rectangle border drawn flag.

Parameters:

ParameterTypeDescription
valuebooleanboolean value

measureString(String str)

public double measureString(String str)

Measures the string.

Parameters:

ParameterTypeDescription
strjava.lang.StringThe string.

Returns: double - double value, Width of the string.

measureHeight(char character)

public final double measureHeight(char character)

Measures character height.

Parameters:

ParameterTypeDescription
charactercharCharacter to measure.

Returns: double - Height of the character if we could get it from font; otherwise 0.

applyChangesFrom(TextState textState)

public void applyChangesFrom(TextState textState)

Applies settings from another textState

Parameters:

ParameterTypeDescription
textStateTextStateText state object.

Only those properties will be copied that were changed explicitly. |

isFitRectangle(String str, Rectangle rect)

public final boolean isFitRectangle(String str, Rectangle rect)

Checks if input string could be placed inside defined rectangle.

Parameters:

ParameterTypeDescription
strjava.lang.StringString to check.
rectRectangleRectangle to check.

Returns: boolean - True if string fit rectangle; otherwise false.

applyChangesFrom(TextState textState, boolean groupChangesOnly)

public void applyChangesFrom(TextState textState, boolean groupChangesOnly)

Applies settings from another textState

Parameters:

ParameterTypeDescription
textStateTextStateText state object.
groupChangesOnlybooleanif true inherit group changes only (without isolating the segments into single segment)