TextModels are container models which contain sequences of attributed characters and embedded views. Characters may be drawn from the Oberon/F character set, conforming to the Unicode specification. However, the current implementation supports the ASCII character set and its Latin-1 extension, only.
CONST unicode
Signals that the read character is actually drawn from the Non-Latin-1 Unicode pages. unicode is used as a general projection value when reading a true Unicode character as a CHAR.
CONST viewcode
Signals that the read character is actually an embedded view. viewcode is used as a general projection value when reading an embedded view as a CHAR.
CONST tab
The tabulation character. When encountered by a text formatter, formatting continues at the next tab stop as defined by some tabulation raster used by the formatter (usually some kind of ruler).
CONST line
The line separation character. When encountered by a text setter, setting continues on the next line. However, line does not introduce a new paragraph (cf. para below).
CONST para
The paragraph separation character. When encountered by a text setter, setting continues on the next line and a new paragraph is opened (cf. line above).
CONST zwspace
The zero
width space character. Separates words, but takes no space in its own right.
CONST nbspace
The non
breaking space character. Has the same width as a normal space character. When encountered by a text setter, nbspace does not separate words.
CONST digitspace
A digit space has the width of digit zero (0) which is equivalent to the width of all digits in most fonts, thus can be used for number formatting. When encountered by a text setter, digitspace does not separate words.
CONST hyphen
The hyphen character. To be used for explicit and visible hyphenation. A text setter may choose to break lines just after a hyphen.
CONST nbhyphen
The non
breaking hyphen. Just as hyphen, but a text setter will not break lines just after an nbhyphen.
CONST softhyphen
The soft
hyphen. Just as hyphen, but rendered as a zero
width character unless actually used to break a line. softhyphen can be used to give hints to a text setter on where to break longer words.
CONST maskChar
Option element
Can be used as a set element of Pref.opts. Signals that the embedded view prefers to be masked to a normal character, making it behave like that character in most situations. The primary purpose of masking is to simplify the task for text scanning applications. (For example, a text ruler might be masked to behave like a para character. This would allow a text scanner to count the number of paragraphs in a text simply by counting the number of returned para characters while scanning the text.)
CONST hideable
Option element
Can be used as a set element of Pref.opts. Signals that the embedded view accepts to be hidden or revealed depending on a mode of the text view. (For example, text rulers might be hideable enabling the the user to hide or reveal the rulers in a displayed text.)
CONST offset, code
Property field selectors
Signals that the indicated field of a Prop property is known, valid, or readOnly.
CONST store
Possible value of InfoMsg.op, signalling the completed storing of the broadcasting text. This is the only value currently defined for this field.
CONST replace
Possible value of UpdateMsg.op, signalling the successful replacement of a stretch in the broadcasting text.
CONST insert
Possible value of UpdateMsg.op, signalling the successful insertion of a stretch in the broadcasting text.
CONST delete
Possible value of UpdateMsg.op, signalling the successful deletion of a stretch in the broadcasting text.
CONST char
Possible element of Reader.type. If present, it signals that the read value can be interpreted as a CHAR. (Note that this is the usual case, while long characters and embedded views have defined projection values unicode and view, respectively.)
CONST lchar
Possible element of Reader.type. If present, it signals that the read value can be interpreted as a LONGCHAR.
CONST view
Possible element of Reader.type. If present, it signals that the read value is an embedded view.
TYPE LONGCHAR
The set of all Unicode characters.
TYPE Model
Interface, Extension
Text models are container models, containing sequences of attributed characters and embedded views.
PROCEDURE (m: Model) Clone (): Model
Extension
Result type is narrowed.
PROCEDURE (m: Model) Length (): LONGINT
Length of the text m, where each character (CHAR or LONGCHAR) and each embedded view counts as one.
Returns a reader connected to m. An old reader may be passed as input parameter, if it isn't in use anymore. Note that NewReader does not reposition old if old is reused and its position is in the valid range. (NewReader may or may not use the old reader, depending on internal compatibility criteria.)
result # NIL
result = old & old'.Base() = m & old'.Pos() <= m.Length()
result.Pos() = old'.Pos()
~(result = old & old'.Base() = m & old'.Pos() <= m.Length())
Returns a writer connected to m. An old writer may be passed as input parameter, if it isn't in use anymore. Note that NewWriter does not reposition old if old is reused and its position is in the valid range. (NewWriter may or may not use the old reader, depending on internal compatibility criteria.)
result # NIL
result.attr = dir.attr
result = old & old'.Base() = m & old'.Pos() <= m.Length()
result.Pos() = old'.Pos()
~(result = old & old'.Base() = m & old'.Pos() <= m.Length())
Copy the stretch [beg, end) from text m0 and insert it into text m at position pos. In case that m0 is of a foreign implementation, rider conversion is used to project the stretch from m0 into m's implementation.
Extract the stretch [beg, end) from m0 and insert it into m at position pos. In case that m0 is of a foreign implementation, rider conversion is used to project the stretch from m0 into m's implementation.
Return a property structure describing the properties of the items in the stretch [beg, end) of m. Only properties returned by encountered attributes and those captured by Prop are considered. There is no recursion into embedded views.
The result is the intersection of the attribute
describing properties of the homogeneous substretches of [beg, end). For example, if the first half of the stretch is "bold & italic", while the second half is "italic", then Prop returns a property "italic", i.e. the homogeneous subset.
Modify the stretch [beg, end) of m according to the property structure p. If old is given, modification takes place only if the stretch is homogeneous in the properties specified in old, and if the stretch carries exactly the same property values as those specified in old.
0 <= beg 20
beg <= end 21
end <= Length(m) 22
old = NIL OR old = Intersect(m'.Prop(beg, end), old)
Retain the context of old, but replace old by new.
old # NIL 20
new # NIL 21
old.context # NIL 22
new.context = NIL OR new.context = old.context 23
new.init 24
new.context = old.context
TYPE Attributes
Extension
Every character or embedded view that forms part of a text carries a set of attributes. Such attributes are described by objects of type Attributes. The base type carries the standard attributes of every element of a text: A color, a font, and a vertical offset (in universal units).
Once created and initialized, attributes objects can no longer be modified, and hence can be freely shared among many attributed objects. Changing the attributes of an attributed object is done by changing the whole attributes object attached to the attributed object.
color-: Ports.Color
Persistent
The color to be used to render the attributed object. For characters, this is the foreground color; for embedded views, this attribute is either ignored, or used in a view
specific way by text
aware views.
font-: Fonts.Font
Persistent
The font to be used to render the attributed object. For characters, this is the font carrying the glyph to be used; for embedded views, this attribute is either ignored, or used in a view
specific way by text
aware views.
offset-: LONGINT
Persistent
The vertical offset from the base line (value in universal units) to be used for the attributed object.
Initialize new attributes object to attributes of a source object, but modified according to the property list. (Values valid in the property list are taken from it, others from the source attributes object.)
REPEAT rd.ReadPrev UNTIL (rd.attr # a) OR (rd.view # NIL) OR rd.eot;
IF rd.eot THEN attr := NIL ELSE attr := rd.attr END
~rd.eot
attr # NIL
rd.view = ViewAt(rd.Pos())
TYPE Writer
Interface
Write characters, long characters, or embed views into a text.
attr-: Attributes
The attributes object to attach to the next written element. (Attributes are immutable, thus they can be shared and need not be copied if used somewhere else.)
PROCEDURE (wr: Writer) Base (): Model
Interface
Return the rider base, i.e. the text the writer is currently attached to.
Write view with width w, height h, and attributes wr.attr.
view # NIL 20
view.context = NIL 21
TYPE InfoMsg
Extension
Message notifying about a non
destructive operation on a text.
op: INTEGER
For standard texts, there is only one op code defined: store.
TYPE UpdateMsg
Extension
Message notifying about a destructive operation on a text.
op: INTEGER
Kind of operation performed. For standard texts, op IN {replace, insert, delete}.
beg, end, delta: LONGINT
The operation was performed on the stretch [beg, end) measured in the text after the operation took place, and caused changed the length of the text by delta. For deletions of length len, end = beg + 1, delta = -l; for insertions of length l, end = beg + l, delta = l; for replacements of length l but not changing the text length, end = beg = l, delta = 0.
TYPE Directory
Interface
Directory for text models.
attr: Attributes
Default attributes, used when opening a writer on a text.
PROCEDURE ReadAttr (VAR rd: Stores.Reader; VAR a: Attributes)
Read an attributes object; in case the reader returns an alien store, the store is wrapped into an alien attributes object and the wrapper is returned.
Read an attributes object; in case the reader returns an alien store, the store is wrapped into an alien attributes object and the wrapper is returned.
a # NIL 20
a.init 21
Except for performance, equivalent to:
WITH a: AlienAttributes DO wr.WriteStore(a.store) ELSE wr.WriteStore(a) END