Last edited by:
Doug Wyatt, February 27, 1984 4:44:57 pm PST
DIRECTORY
Font USING [Create, CreateScaled, FONT, Name, RequestedTransformation],
Imager USING [Concat],
ImagerExtras USING [ShowChar],
IP USING [Any, Integer, MasterError, NameFromVector, OperatorRep, State, Transformation, Vector, VectorRep, VectorShape],
IPFont USING [],
Rope USING [ROPE];
IPFontImpl: CEDAR PROGRAM
IMPORTS Font, Imager, ImagerExtras, IP
EXPORTS IPFont
= BEGIN OPEN IP;
ROPE: TYPE ~ Rope.ROPE;
FONT: TYPE ~ Font.FONT;
CharData: TYPE ~ REF CharDataRep;
CharDataRep: TYPE ~ RECORD[font: FONT, code: CARDINAL];
CharDo:
PROC[self: State, data:
REF] ~ {
char: CharData ~ NARROW[data];
font: FONT ~ char.font;
ImagerExtras.ShowChar[self.imager, char.code, char.font];
};
fontShape: VectorShape ~ [l: 0, n: CARDINAL.LAST];
FontShape:
PROC[data:
REF]
RETURNS[VectorShape] ~ {
RETURN[fontShape];
};
FontGet:
PROC[data:
REF, j: Integer]
RETURNS[Any] ~ {
font: FONT ~ NARROW[data];
IF j
NOT
IN[0..
CARDINAL.
LAST]
THEN
MasterError[$boundsFault, "Font vector index out of bounds."];
RETURN[
NEW[OperatorRep ← [class: $Char, do: CharDo,
data: NEW[CharDataRep ← [font: font, code: j]]]]];
};
VectorFromFont:
PUBLIC
PROC[font:
FONT]
RETURNS[Vector] ~ {
RETURN[NEW[VectorRep ← [class: $Font, shape: FontShape, get: FontGet, data: font]]];
};
FontFromVector:
PUBLIC
PROC[v: Vector]
RETURNS[font:
FONT ←
NIL] ~ {
SELECT v.class
FROM
$Font => font ← NARROW[v.data];
ENDCASE => MasterError[$unimplemented, "Can't fabricate a FONT yet."];
};
FindFont:
PUBLIC
PROC[self: State, v: Vector]
RETURNS[Vector] ~ {
name: ROPE ~ NameFromVector[v];
font: FONT ~ Font.CreateScaled[fontName: name, scale: 1];
RETURN[VectorFromFont[font]];
};
FindFontVec:
PUBLIC
PROC[self: State, v: Vector]
RETURNS[Vector] ~ {
MasterError[$unimplemented, "FINDFONTVEC is not implemented."];
RETURN[NIL];
};
ModifyFont:
PUBLIC
PROC[v: Vector, m: Transformation]
RETURNS[Vector] ~ {
oldFont: FONT ~ FontFromVector[v];
fontName: ROPE ~ oldFont.Name[];
oldTransformation: Transformation ~ oldFont.RequestedTransformation[];
newTransformation: Transformation ~ Imager.Concat[m, oldTransformation];
newFont: FONT ~ Font.Create[fontName, newTransformation];
RETURN[VectorFromFont[newFont]];
};
END.