Working with text in Java classes

Text includes text paragraphs and text runs, rich text styles, rich text paragraph styles, and tabs. A text run is text until the style changes or the paragraph ends.

Text paragraphs and text runs

To find text in a rich text item, use the RichTextNavigator methods in conjunction with the type RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH or RichTextItem.RTELEM_TYPE_TEXTRUN. To get text, create a RichTextRange object with createRange and delineate the text with the following methods:

  • setBegin defines the beginning of a range.
  • setEnd defines the end of a range.

For example, if you find an element of type RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH with RichTextNavigator, then call setBegin passing it the navigator, your range starts at that paragraph.

The RichTextRange class has the following properties:

Property

Data Type

Description

getNavigator

RichTextNavigator

A navigator confined to the range. This allows you, for example, to get the text runs in a text paragraph.

getStyle

RichTextStyle

The style of the first text run in the range.

getTextParagraph

String

The text of the first paragraph in the range.

getTextRun

String

The text of the first run in the range.

getType

String

The type of the first element in the range.

In addition to setBegin and setEnd, the RichTextRange class has the following methods:

  • Clone creates another RichTextRange object from the current range.
  • findAndReplace replaces the occurrence of a string in the range.
  • remove removes the elements of the range.
  • reset resets the range to its default values.
  • setStyle sets all text in the range to a specified style.

Text creation

To create text in a rich text item, use the following methods:

  • addNewLine appends one or more new lines (carriage returns) to the end of a rich text item.
  • addPageBreak places a hard page break at the end of a RichTextItem.
  • addTab appends one or more tabs to the end of a rich text item.
  • appendText appends text to the end of a rich text item. The text is rendered with the current style of the item.
  • appendRTItem appends the contents of one rich text item to the end of another rich text item.

Rich text styles

You can access rich text style properties through the RichTextStyle class. The RichTextStyle class contains the following properties:

Property

Data Type

Description

getBold and setBold

int

Bold rich text attribute

getEffects and setEffects

int

Effects (emboss, extrude, and so on)

getFont and setFont

int

Font rich text attribute

getFontSize and setFontSize

int

Font size in points

isDefault

boolean

If all attributes are in a default state

getItalic and setItalic

int

Italic rich text attribute

getColor and setColor

int

Color rich text attribute

getParent

Session

The session that contains a RichTextStyle object

getPassThruHTML and setPassThruHTML

int

HTML attribute

getStrikeThrough and setStrikeThrough

int

Strikethrough rich text attribute

getUnderline and setUnderline

int

Underline rich text attribute

The method appendStyle appends a style to the end of a rich text item. Text following the style is rendered using that styles's attributes until another style is appended.

Use getNotesFont in RichTextItem to establish font identifiers for Font.

Rich text paragraph styles

The RichTextParagraphStyle allows you to access the following attributes of a rich text paragraph object:

Property

Data type

Description

getAlignment and setAlignment

int

Alignment attribute of a rich text paragraph

getFirstLineLeftMargin and setFirstLineLeftMargin

int

First line left margin attribute of a rich text paragraph

getInterLineSpacing and setInterLineSpacing

int

Interline spacing attribute of a rich text paragraph

getLeftMargin and setLeftMargin

int

Left margin attribute of a rich text paragraph

getRightMargin and setRightMargin

int

Right margin attribute of a rich text paragraph

getSpacingAbove and setSpacingAbove

int

Spacing above attribute of a rich text paragraph

getSpacingBelow and setSpacingBelow

int

Spacing below attribute of a rich text paragraph

getTabs

Vector of RichTextTab

Tabs in a rich text paragraph style

Use the createRichTextParagraphStyle method of Session to create a new rich text paragraph style object.

Tabs

You can manipulate the tabs in a rich text paragraph style object through the clearAllTabs, setTab, and setTabs methods in RichTextParagraphStyle, and the clear method in RichTextTab.

The following table lists the properties in the RichTextTab class.

Property

Description

getPosition

Position of the tab in a rich text paragraph style

getType

Type of tab