TEditFormat.mesa
Copyright Ó 1985, 1986, 1988 by Xerox Corporation. All rights reserved.
Michael Plass, May 23, 1985 9:04:16 am PDT
Doug Wyatt, February 15, 1988 1:11:15 pm PST
DIRECTORY
Imager USING [Box, Color, Context, VEC],
ImagerFont USING [Font, Extents, XChar],
NodeStyle USING [Ref, RealParam, TabStop, FontUnderlining],
NodeStyleOps USING [OfStyle],
Scaled USING [Value],
TEditDocument USING [LineBreak],
TextLooks USING [Looks],
TextNode USING [Location, Ref];
Line formatting
LineInfo: TYPE = REF LineInfoRec;
LineInfoRec:
TYPE =
RECORD [
charInfo: CharInfo,
formatInfo: FormatInfo,
positionInfo: PositionInfo,
artworkClass: ArtworkClass,
artworkData: REF,
startPos, nextPos: TextNode.Location,
xOffset: Scaled.Value,
xmin, ymin, xmax, ymax:
INTEGER,
A (perhaps slightly generous) bounding box for the line.
nChars: NAT,
nBlankCharsAtEnd: NAT,
break: TEditDocument.LineBreak,
hasBackground: BOOL,
amplifySpace: REAL,
startAmplifyIndex: CharNumber,
index: INT, -- for use by clients
data: REF, -- for use by clients
link: LineInfo
];
CharNumber: TYPE = [0..LAST[CARDINAL]/SIZE[CharInfoEntry]-8);
CharInfo: PUBLIC TYPE = REF CharInfoRec;
CharInfoRec:
PUBLIC
TYPE =
RECORD [
seq: SEQUENCE maxLength: CharNumber OF CharInfoEntry
];
CharInfoEntry:
TYPE =
RECORD [
char: ImagerFont.XChar,
formatNumber: FormatNumber,
alteredWidth: BOOLEAN,
amplified: BOOLEAN,
width: Scaled.Value
];
FormatNumber: TYPE = [0..LAST[CARDINAL]/SIZE[FormatInfoEntry]-16);
FormatInfo: PUBLIC TYPE = REF FormatInfoRec;
FormatInfoRec:
PUBLIC
TYPE =
RECORD [
length: FormatNumber ← 0,
seq: SEQUENCE maxLength: FormatNumber OF FormatInfoEntry
];
FormatInfoEntry:
TYPE =
RECORD [
looks: TextLooks.Looks,
font: ImagerFont.Font ← NIL,
color: Imager.Color ← NIL,
tab: NodeStyle.TabStop ← NIL,
vShift: REAL ← 0.0,
extension: REF,
strikeout: NodeStyle.FontUnderlining ← None,
underlining: NodeStyle.FontUnderlining ← None,
unique: BOOL
];
PositionInfo: PUBLIC TYPE = REF PositionInfoRec;
PositionInfoRec:
PUBLIC
TYPE =
RECORD [
seq: SEQUENCE maxLength: CharNumber OF INTEGER
];
FormatLine: FormatProc;
FormatProc:
TYPE ~
PROC [
lineInfo: LineInfo,
node: TextNode.Ref,
startOffset:
INT,
nodeStyle: NodeStyle.Ref,
lineWidth: Scaled.Value,
doLigsAndKern:
BOOLEAN ←
FALSE,
kind: NodeStyleOps.OfStyle ← screen
];
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: TextNode.Location, xmin, width:
INTEGER, rightOfLine:
BOOLEAN];
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
];
CharacterArtworkClass: TYPE ~ REF CharacterArtworkClassRep;
CharacterArtworkClassRep:
TYPE ~
RECORD [
name: ATOM,
format:
PROC [CharacterArtworkClass, TextNode.Location, NodeStyle.Ref, NodeStyleOps.OfStyle]
RETURNS [CharacterArtwork],
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];
GetFont:
PROC [style: NodeStyle.Ref]
RETURNS [ImagerFont.Font];
GetColor:
PROC [style: NodeStyle.Ref, h: NodeStyle.RealParam ← textHue, s: NodeStyle.RealParam ← textSaturation, b: NodeStyle.RealParam ← textBrightness]
RETURNS [color: Imager.Color];
Hyphenation
maxHyph: NAT ~ 16;
HyphenationPosition: TYPE ~ [0..256) ← 0;
HyphenationPositions: TYPE ~ PACKED ARRAY [0..maxHyph) OF HyphenationPosition;
HyphProc:
TYPE ~
PROC [node: TextNode.Ref, 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 16-bit 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.