TEditFormat.mesa
Copyright Ó 1985, 1986, 1991, 1992 by Xerox Corporation. All rights reserved.
Michael Plass, May 23, 1985 9:04:16 am PDT
Doug Wyatt, February 27, 1992 5:06 pm PST
DIRECTORY
Char USING [XCHAR],
Imager USING [Box, Color, Context, VEC],
ImagerFont USING [Font, Extents],
NodeStyle USING [Style, TabStop, FontUnderlining],
Scaled USING [Value],
Tioga USING [Node, Location, Looks];
Line formatting
LineInfo: TYPE = REF LineInfoRec;
LineInfoRec:
TYPE =
RECORD [
charInfo: CharInfo,
formatInfo: FormatInfo,
positionInfo: PositionInfo,
artworkClass: ArtworkClass,
artworkData: REF,
startPos, nextPos: Tioga.Location,
xOffset: Scaled.Value,
xmin, ymin, xmax, ymax:
INTEGER,
A (perhaps slightly generous) bounding box for the line.
nChars: NAT,
nBlankCharsAtEnd: NAT,
break: LineBreak,
hasBackground: BOOL,
amplifySpace: REAL,
startAmplifyIndex: CharNumber,
index: INT, -- for use by clients
data: REF, -- for use by clients
link: LineInfo
];
CharNumber: TYPE = NAT;
CharInfo: TYPE = REF CharInfoRec;
CharInfoRec:
TYPE =
RECORD [
seq: SEQUENCE maxLength: CharNumber OF CharInfoEntry
];
CharInfoEntry:
TYPE =
PACKED
RECORD [
char: Char.XCHAR,
formatNumber: FormatNumber,
alteredWidth: BOOL,
amplified: BOOL,
width: Scaled.Value
];
FormatNumber: TYPE = [0..2**30);
FormatInfo: TYPE = REF FormatInfoRec;
FormatInfoRec:
TYPE =
RECORD [
length: FormatNumber ¬ 0,
seq: SEQUENCE maxLength: FormatNumber OF FormatInfoEntry
];
FormatInfoEntry:
TYPE =
RECORD [
looks: Tioga.Looks,
font: ImagerFont.Font ¬ NIL,
color: Imager.Color ¬ NIL,
tab: NodeStyle.TabStop ¬ NIL,
vShift: REAL ¬ 0.0,
strikeout: NodeStyle.FontUnderlining ¬ None,
underlining: NodeStyle.FontUnderlining ¬ None,
extension: REF ExtraFormatInfoRep,
unique: BOOL
];
ExtraFormatInfoRep:
TYPE;
-- see TEditFormatImpl
PositionInfo: TYPE = REF PositionInfoRec;
PositionInfoRec:
TYPE =
RECORD [seq:
SEQUENCE maxLength: CharNumber
OF
INTEGER];
LineBreak:
TYPE ~ { eon, cr, wrap } ¬ eon;
FormatLine: FormatProc;
FormatProc:
TYPE ~
PROC [lineInfo: LineInfo, node: Tioga.Node, startOffset:
INT,
nodeStyle: NodeStyle.Style, lineWidth: Scaled.Value, doLigsAndKern:
BOOL ¬
FALSE];
Paint: PaintProc;
PaintProc:
TYPE ~
PROC [lineInfo: LineInfo, context: Imager.Context];
Paints the line with its origin at the current position.
Resolve: ResolveProc;
ResolveProc:
TYPE ~
PROC [lineInfo: LineInfo, x:
INTEGER]
RETURNS [loc: Tioga.Location, xmin, width:
INTEGER, rightOfLine:
BOOL];
Finds the character pointed to.
CharPosition: CharPositionProc;
CharPositionProc:
TYPE ~
PROC [lineInfo: LineInfo, offset:
INT]
RETURNS [x, width:
INTEGER];
Finds the position of the indicated character. Returns FIRST[INTEGER] or LAST[INTEGER] if the character occurs before or after the line, respectively.
BoundingBox: BoundingBoxProc;
BoundingBoxProc:
TYPE ~
PROC [lineInfo: LineInfo, start:
INT ¬ 0, length:
INT ¬
LAST[
INT]]
RETURNS [Imager.Box];
Computes a higher-precision bounding box of characters [start..start+length) of the line, relative to the line's origin.
Allocate:
PROC
RETURNS [lineInfo: LineInfo];
This is how to get working space. Keeps a cache of storage.
Release:
PROC [lineInfo: LineInfo];
A promise that the client is done with this LineInfo, and all those chained from it. Use whenever possible to save on allocations.
Character artwork
Provides a means for inserting artwork that behaves like a single character. The character artwork mechanism is invoked when a character property is detected that has the $Artwork key with a value matching one of the registered character artwork classes.
CharacterArtwork: TYPE ~ REF CharacterArtworkRep;
CharacterArtworkRep:
TYPE ~
RECORD [
paint: PROC [CharacterArtwork, Imager.Context],
extents: ImagerFont.Extents ¬ [0, 0, 0, 0],
escapement: Imager.VEC ¬ [0, 0],
amplified: BOOL ¬ FALSE,
data: REF ¬ NIL
];
CharacterFormatProc:
TYPE ~
PROC [class: CharacterArtworkClass,
loc: Tioga.Location, style: NodeStyle.Style]
RETURNS [CharacterArtwork];
CharacterArtworkClass: TYPE ~ REF CharacterArtworkClassRep;
CharacterArtworkClassRep:
TYPE ~
RECORD [
name: ATOM,
format: CharacterFormatProc,
Note: The style may change before paint is called, so the client should extract all needed style info during format call.
data: REF
];
RegisterCharacterArtwork:
PROC [class: CharacterArtworkClass];
UnregisterCharacterArtwork:
PROC [name:
ATOM];
GetCharacterArtworkClass:
PROC [
ATOM]
RETURNS [CharacterArtworkClass];
Hyphenation
maxHyph: NAT ~ 16;
HyphenationPosition: TYPE ~ [0..256) ¬ 0;
HyphenationPositions: TYPE ~ PACKED ARRAY [0..maxHyph) OF HyphenationPosition;
HyphProc:
TYPE ~
PROC [node: Tioga.Node, start, len:
INT, hyphData:
REF]
RETURNS [HyphenationPositions];
If the returned value is h, should have 0 < h[0] < h[1] < . . . < h[k-1] < len and either k = maxHyph or h[k] = 0, where k is the number of places at which it is possible to hyphenate the word. If h[j] = i is in the range (0..len), it means it's ok to hyphenate after the ith character of the word. The word is at Rope.Substr[node.rope, start, len]; the hyphenation routine may examine the context of the word in the rest of the rope. If node.hasCharSets, use TextEdit.FetchChar or equivalent to fetch extended character codes.
RegisterHyphenation:
PROC [hyphenationClass:
ATOM, hyphProc: HyphProc, hyphData:
REF]
RETURNS [oldProc: HyphProc, oldData:
REF];
Registers a HyphProc to be called; hyphenationClass identifies the language involved, as determined from style parameters. Any previously registered proc is returned (for layering, etc.) and forgotten by the registration mechanism. Note that registering a new hyphProc may invalidate line breaks on the screen; it's up to the client to refresh these viewers.