TextFragmentState

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

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 {@code 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 ({@code TextFragmentState.Font} property) font size ({@code TextFragmentState.FontSize} property) font style ( {@code TextFragmentState.FontStyle} property) foreground color ( {@code TextFragmentState.ForegroundColor} property) background color ( {@code TextFragmentState.BackgroundColor} property)

Note that changing {@code TextFragmentState} properties may change inner {@code 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 {@code TextFragment.Segments} collection unchanged, please change inner segments individually.

@see TextFragmentAbsorber @see IDocument

Constructors

ConstructorDescription
TextFragmentStateInitializes new instance of the {@code TextFragmentState} object with specified {@code TextFragment} object. This {@code TextFragmentState} initialization is not supported. TextFragmentState is only available with {@code TextFragment.TextState} property.

Methods

MethodDescription
applyChangesFrom

Applies settings from another textState

applyChangesFromApplies settings from another textState
getBackgroundColorSets background color of the text, represented by the {@code TextFragment} object
getCharacterSpacingGets character spacing of the text, represented by the {@code TextFragment} object.
getCoordinateOriginGets 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.
getDrawTextRectangleBorderGets if text rectangle border drawn flag.
getFontGets font of the text, represented by the {@code TextFragment} object
getFontSizeGets font size of the text, represented by the {@code TextFragment} object
getFontStyleSets font style of the text, represented by the {@code TextFragment} object
getForegroundColorGets foreground color of the text, represented by the {@code TextFragment} object
getFormattingOptionsGets or sets formatting options. Setting of the options will be effective in generator scenarios only.
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.

getHorizontalScalingGets horizontal scaling of the text, represented by the {@code TextFragment} object.
getLineSpacing

Gets line spacing of the text.

getRenderingModeGets or sets rendering mode of the text.
getRotationGets or sets rotation angle in degrees.
getStrokingColorGets or sets color stroking operations of {@code TextFragment} rendering (stroke text, rectangle border)
getTabStops

Gets tabstops for the text.


Note that Tabstops property works in new document generation scenarios only. Tabstops may be added during {@code TextFragment} initialization. Tabstops must be constructed before the text.

getTextHeightGets text height, represented by the {@code TextFragment} object
getWordSpacingGets word spacing of the text.
isFitRectangleChecks if input string could be placed inside defined rectangle.
isInvisibleGets invisibility of the text.
isStrikeOutGets or sets strikeout for the text, represented by the {@link TextFragment} object
isSubscriptGets or sets subscript of the text, represented by the {@code TextFragment} object.
isSuperscriptGets or sets superscript of the text, represented by the {@code TextFragment} object.
isUnderlineGets or sets underline for the text, represented by the {@link TextFragment} object
measureHeightMeasures character height.
measureStringMeasures the string.
setBackgroundColorSets background color of the text, represented by the TextFragment object
setCharacterSpacingSets character spacing of the text, represented by the {@code TextFragment} object.
setCoordinateOriginGets 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.
setDrawTextRectangleBorderSets if text rectangle border drawn flag.
setFontSets font of the text, represented by the {@code TextFragment} object
setFontSizeSets font size of the text, represented by the {@code TextFragment} object
setFontStyleSets font style of the text, represented by the {@link TextFragment} object
setForegroundColorSets foreground color of the text, represented by the {@code TextFragment} object
setFormattingOptionsGets or sets formatting options. Setting of the options will be effective in generator scenarios only.
setHorizontalAlignment

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.

setHorizontalScalingSets horizontal scaling of the text, represented by the {@code TextFragment} object.
setInvisibleSets invisibility of the text.
setLineSpacing

Sets line spacing of the text.

setRenderingModeGets or sets rendering mode of the text.
setRotationGets or sets rotation angle in degrees.
setStrikeOutSets strikeout for the text, represented by the {@code TextFragment} object
setStrokingColorGets or sets color stroking operations of {@code TextFragment} rendering (stroke text, rectangle border)
setSubscriptGets or sets subscript of the text, represented by the {@code TextFragment} object.
setSuperscriptGets or sets superscript of the text, represented by the {@code TextFragment} object.
setUnderlineSets underline for the text, represented by the {@code TextFragment} object
setWordSpacingSets word spacing of the text.

TextFragmentState

Initializes new instance of the {@code TextFragmentState} object with specified {@code TextFragment} object. This {@code TextFragmentState} initialization is not supported. TextFragmentState is only available with {@code TextFragment.TextState} property.

applyChangesFrom

Applies settings from another textState

applyChangesFrom

Applies settings from another textState

getBackgroundColor

public Color getBackgroundColor()

Sets background color of the text, represented by the {@code TextFragment} object

Returns: value Color object

getCharacterSpacing

public float getCharacterSpacing()

Gets character spacing of the text, represented by the {@code TextFragment} object.

Returns: float value

getCoordinateOrigin

public CoordinateOrigin 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: CoordinateOrigin element

getDrawTextRectangleBorder

public boolean getDrawTextRectangleBorder()

Gets if text rectangle border drawn flag.

Returns: boolean value

getFont

public Font getFont()

Gets font of the text, represented by the {@code TextFragment} object

Returns: Font value

getFontSize

public float getFontSize()

Gets font size of the text, represented by the {@code TextFragment} object

Returns: float value

getFontStyle

public int getFontStyle()

Sets font style of the text, represented by the {@code TextFragment} object

Returns: FontStyles element @see FontStyles

getForegroundColor

public Color getForegroundColor()

Gets foreground color of the text, represented by the {@code TextFragment} object

Returns: Color object

getFormattingOptions

public TextFormattingOptions getFormattingOptions()

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

Returns: TextFormattingOptions instance

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 value @see HorizontalAlignment

getHorizontalScaling

public float getHorizontalScaling()

Gets horizontal scaling of the text, represented by the {@code TextFragment} object.

Returns: float value

getLineSpacing

public float getLineSpacing()

Gets line spacing of the text.

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

getRenderingMode

public TextRenderingMode getRenderingMode()

Gets or sets rendering mode of the text.

Returns: TextRenderingMode element

getRotation

public double getRotation()

Gets or sets rotation angle in degrees.

Returns: double value

getStrokingColor

public Color getStrokingColor()

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

Returns: Color instance

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 {@code TextFragment} initialization. Tabstops must be constructed before the text.

Returns: TabStops object

getTextHeight

public float getTextHeight()

Gets text height, represented by the {@code TextFragment} object

Returns: float value

getWordSpacing

public float getWordSpacing()

Gets word spacing of the text.

Returns: float value

isFitRectangle

Checks if input string could be placed inside defined rectangle.

isInvisible

public boolean isInvisible()

Gets invisibility of the text.

Returns: boolean value

isStrikeOut

public boolean isStrikeOut()

Gets or sets strikeout for the text, represented by the {@link TextFragment} object

Returns: boolean value

isSubscript

public boolean isSubscript()

Gets or sets subscript of the text, represented by the {@code TextFragment} object.

Returns: boolean value

isSuperscript

public boolean isSuperscript()

Gets or sets superscript of the text, represented by the {@code TextFragment} object.

Returns: value boolean value

isUnderline

public boolean isUnderline()

Gets or sets underline for the text, represented by the {@link TextFragment} object

Returns: boolean value

measureHeight

public final double measureHeight(char character)

Measures character height.

Parameters:

ParameterTypeDescription
characterCharacter to measure.

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

measureString

Measures the string.

setBackgroundColor

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

setCharacterSpacing

public void setCharacterSpacing(float value)

Sets character spacing of the text, represented by the {@code TextFragment} object.

Parameters:

ParameterTypeDescription
valuefloat value

setCoordinateOrigin

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.

setDrawTextRectangleBorder

public void setDrawTextRectangleBorder(boolean value)

Sets if text rectangle border drawn flag.

Parameters:

ParameterTypeDescription
valueboolean value

setFont

Sets font of the text, represented by the {@code TextFragment} object

setFontSize

public void setFontSize(float value)

Sets font size of the text, represented by the {@code TextFragment} object

Parameters:

ParameterTypeDescription
valuefloat value

setFontStyle

public void setFontStyle(int value)

Sets font style of the text, represented by the {@link TextFragment} object

Parameters:

ParameterTypeDescription
valueint value @see FontStyles

setForegroundColor

Sets foreground color of the text, represented by the {@code TextFragment} object

setFormattingOptions

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

setHorizontalAlignment

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.

setHorizontalScaling

public void setHorizontalScaling(float value)

Sets horizontal scaling of the text, represented by the {@code TextFragment} object.

Parameters:

ParameterTypeDescription
valuefloat value

setInvisible

public void setInvisible(boolean value)

Sets invisibility of the text.

Parameters:

ParameterTypeDescription
valueboolean value

setLineSpacing

public void setLineSpacing(float value)

Sets line spacing of the text.

Parameters:

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

setRenderingMode

Gets or sets rendering mode of the text.

setRotation

public void setRotation(double value)

Gets or sets rotation angle in degrees.

Parameters:

ParameterTypeDescription
valuedouble value

setStrikeOut

public void setStrikeOut(boolean value)

Sets strikeout for the text, represented by the {@code TextFragment} object

Parameters:

ParameterTypeDescription
valueboolean value

setStrokingColor

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

setSubscript

public void setSubscript(boolean value)

Gets or sets subscript of the text, represented by the {@code TextFragment} object.

Parameters:

ParameterTypeDescription
valueboolean value

setSuperscript

public void setSuperscript(boolean value)

Gets or sets superscript of the text, represented by the {@code TextFragment} object.

Parameters:

ParameterTypeDescription
valueboolean value

setUnderline

public void setUnderline(boolean value)

Sets underline for the text, represented by the {@code TextFragment} object

Parameters:

ParameterTypeDescription
valueboolean value

setWordSpacing

public void setWordSpacing(float value)

Sets word spacing of the text.

Parameters:

ParameterTypeDescription
valuefloat value