Manipulating fonts and font styles

Documents are modeled by Elements which are hierarchically linked according to the content structure in the document. HTML documents for instance define - with certain exceptions - an Element object for every HTML tag. As with HTML tags, each Element can have one or more attributes (bold, italic, etc.) which are assigned to an Element through class AttributeSet .

Applicable ranges for AttributeSets

How AttributeSets influence the rendering of a document depends on the context they are found in. Attributes for a paragraph for instance can be valid for a whole range of subsequent Elements. In addition, a HTML document has an associated style sheet which defines AttributeSets too. If a paragraph element or an element for a range of characters has no attributes in the document itself, attributes from the style sheet might still be relevant for rendering respective content.

Limitation to attributes on character level

In stage 3 of application SimplyHTML only manipulation of fonts and font styles on character level is implemented. There are two methods in SimplyHTML for dealing with attribute changes, one for reading attributes for a given position in a document and one for applying attributes to a given part of a document.

Method getMaxAttributes

All methods in stage 3 of SimplyHTML dealing with fonts and font styles use static method getMaxAttributes of class FrmMain to determine which attributes are assigned to a certain point inside a document. Method getMaxAttributes combines attributes from the style sheet associated to the document with attributes assigned directly to to a character element inside the document (in later stages this has to be refined to deal with style sheet styles other than <p>, paragraph styles, etc.).

The attribute sets from the style sheet and from the character element are added to a new attribute set which is returned to the calling method.

Method applyAttributes

As described in the following chapters all components manipulating fonts and font styles do their changes entirely on the basis of AttributeSets. An AttributeSet is applied to a document by method applyAttributes in class FrmMain.

Method applyAttributes determines whether or not a range of characters is selected in the given editor pane. If a selection is present, the given AttributeSet is applied to that range of text. If no selection is present, the given AttributeSet is applied as attributes for subsequent inputs.

To define attributes for subsequent inputs, class EditorKit defines a method getInputAttributes. When attributes are stored in the AttributeSet returned by this method, these attributes are applied for inputs thereafter.