Trees | Indices | Toggle frames |
---|
Formatted and unformatted document interfaces used by text layout.
Styled text in pyglet is represented by one of the AbstractDocument classes, which manage the state representation of text and style independently of how it is loaded or rendered.
A document consists of the document text (a Unicode string) and a set of named style ranges. For example, consider the following (artificial) example:
0 5 10 15 20 The cat sat on the mat. +++++++ +++++++ "bold" ++++++ "italic"
If this example were to be rendered, "The cat" and "the mat" would be in bold, and "on the" in italics. Note that the second "the" is both bold and italic.
The document styles recorded for this example would be "bold" over ranges (0-7, 15-22) and "italic" over range (12-18). Overlapping styles are permitted; unlike HTML and other structured markup, the ranges need not be nested.
The document has no knowledge of the semantics of "bold" or "italic", it stores only the style names. The pyglet layout classes give meaning to these style names in the way they are rendered; but you are also free to invent your own style names (which will be ignored by the layout classes). This can be useful to tag areas of interest in a document, or maintain references back to the source material.
As well as text, the document can contain arbitrary elements represented by InlineElement. An inline element behaves like a single character in the documented, but can be rendered by the application.
Paragraph breaks are marked with a "newline" character (U+0010). The Unicode paragraph break (U+2029) can also be used.
Line breaks (U+2028) can be used to force a line break within a paragraph.
See Unicode recommendation UTR #13 for more information: http://unicode.org/reports/tr13/tr13-5.html.
Any class implementing AbstractDocument provides a an interface to a document model as described above. In theory a structured document such as HTML or XML could export this model, though the classes provided by pyglet implement only unstructured documents.
The UnformattedDocument class assumes any styles set are set over the entire document. So, regardless of the range specified when setting a "bold" style attribute, for example, the entire document will receive that style.
The FormattedDocument class implements the document model directly, using the RunList class to represent style runs efficiently.
The following character style attribute names are recognised by pyglet:
The following paragraph style attribute names are recognised by pyglet. Note that paragraph styles are handled no differently from character styles by the document: it is the application's responsibility to set the style over an entire paragraph, otherwise results are undefined.
Other attributes can be used to store additional style information within the document; it will be ignored by the built-in text classes.
All style attributes (including those not present in a document) default to None (including the so-called "boolean" styles listed above). The meaning of a None style is style- and application-dependent.
Since: pyglet 1.1
InlineElement
Arbitrary inline element positioned within a formatted document.
|
|
AbstractDocument
Abstract document interface used by all pyglet.text classes.
|
|
UnformattedDocument
A document having uniform style over all text.
|
|
FormattedDocument
Simple implementation of a document that maintains text formatting.
|
STYLE_INDETERMINATE =
|
__package__ =
|
Trees | Indices | Toggle frames |
---|
Generated by Epydoc 3.0beta1 on Thu Dec 31 17:58:18 2009 | http://epydoc.sourceforge.net |