Styles and Style Sets

IText uses the classes ITextStyle and ITextStyleSet to encapsulate the styling information associated with a string. ITextStyle is the abstract base class for all text styles provided by the framework. ITextStyleSet provides a mechanism for manipulating styles in groups. Most functions that take styles as parameters allow you to add styles to a range of characters in an IText object either individually (with ITextStyle) or as a group (with ITextStyleSet).

A style object is basically a wrapper for some value that gives the style meaning. The type of value differs for each style. For example, a typeface style encapsulates a string that indicates which typeface to use, such as Times or Helvetica, while the italic style encapsulates a boolean that indicates whether the associated characters are italicized or not. You can change the value of a style object at any time.

Styles can define information that controls how the text is displayed--for example, the typeface or point size--or some other metadata not related to the display of the text, such as the natural language of the text or whether it is editable. However, styles do not define display mechanisms. It is up to the rendering mechanism to interpret the information in the style objects and display the text according to the associated styling information.

IText uses ITextStyleSet to store the set of styles associated with a particular style run, and you can use it to work with groups of styles. An ITextStyleSet object can contain only one instance of any given style. It cannot, for example, contain two instances of ITextTypefaceStyle even if one style indicates "Helvetica" and another indicates "Times." If you add a style to a style set that already contains an instance of that type of style, the new style replaces the old style regardless of their values, as illustrated in this figure:


Style Classes
Style Propagation