TATypeSetterFaceImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, July 20, 1982 10:52 am
Rick Beach, February 11, 1985 11:54:56 am PST
Maureen Stone April 21, 1983 10:18 am
DIRECTORY
Graphics USING [Box, Context],
GraphicsToPressPrivate USING[NewContextFromSirPressHandle],
JaM USING [Execute],
NodeStyle USING [Create, Ref],
Process USING [GetCurrent],
Real,
TAGraphicsHacks USING [BeginBox, EndBox],
TAPrivate USING [PopDC, PushDC, PushReal, state, Translate],
TARender USING [RenderBranch],
TextNode USING [Ref],
TJaMGraphicsContexts USING [AddContext, RemoveContext, DisableViewer, EnableViewer],
TSArtwork,
TSGlue,
TSGraphic,
TSOutput USING [Handle],
TSOutputPress USING [PressState],
TSTypes USING [RealDimn, pt],
TACallig,
TATypeSetter;
TATypeSetterFaceImpl:
CEDAR PROGRAM
IMPORTS JaM, NodeStyle, Process, TAGraphicsHacks, TAPrivate, TARender, TJaMGraphicsContexts, TSArtwork, TSTypes, GraphicsToPressPrivate, TACallig
EXPORTS TATypeSetter =
BEGIN OPEN TSTypes;
CreateArtworkObject: TSArtwork.ObjectFromBranchProc =
CHECKED {
supply Typesetter with Paint and Layout procedures
object ← NEW[TSGraphic.ObjectRec];
object.paintProc ← ArtworkObjectPaint;
object.layoutProc ← ArtworkObjectLayout;
object.data ← NEW[ArtworkObjectRec ← [node: node]];
};
ArtworkObjectRec:
TYPE =
RECORD [
node: TextNode.Ref,
bbox: Graphics.Box ← [Real.LargestNumber, Real.LargestNumber, -Real.LargestNumber, -Real.LargestNumber]
];
ArtworkObjectLayout: TSGraphic.LayoutProc =
TRUSTED {
determine the size of the artwork in the current style state
data: REF ArtworkObjectRec ← NARROW[self.data];
nodeStyle: NodeStyle.Ref ← NodeStyle.Create[];
TAGraphicsHacks.BeginBox[];
TARender.RenderBranch[handle:
NIL,
node: data.node,
nodeStyle: nodeStyle,
kind: print,
paint: FALSE];
data.bbox ← TAGraphicsHacks.EndBox[];
extent[right] ← RealDimn[data.bbox.xmax, pt];
extent[left] ← RealDimn[data.bbox.xmin, pt];
extent[up] ← RealDimn[data.bbox.ymax, pt];
extent[down] ← RealDimn[data.bbox.ymin, pt];
};
ArtworkObjectPaint: TSGraphic.PaintProc =
TRUSTED {
paint the artwork object given the position by the Typesetter
data: REF ArtworkObjectRec ← NARROW[self.data];
nodeStyle: NodeStyle.Ref ← NodeStyle.Create[];
outputHandle: TSOutput.Handle ← NARROW[context];
IF useJaMGraphics
OR outputHandle.outputState =
NIL
THEN {
display in JaMGraphics viewer
TAPrivate.PushDC[];
TAPrivate.PushReal[originX.texPts];
TAPrivate.PushReal[originY.texPts-data.bbox.ymin];
TAPrivate.Translate[];
TARender.RenderBranch[handle: outputHandle,
node: data.node,
nodeStyle: nodeStyle,
kind: print,
paint: TRUE];
TAPrivate.PopDC[];
}
ELSE
IF
ISTYPE[outputHandle.outputState, TSOutputPress.PressState]
THEN {
pressState: TSOutputPress.PressState ← NARROW[outputHandle.outputState];
dc: Graphics.Context ← pressState.graphicsContext;
IF dc=
NIL
THEN
dc ← GraphicsToPressPrivate.NewContextFromSirPressHandle[pressState.pressHandle];
SaveDC[dc];
TJaMGraphicsContexts.AddContext[TAPrivate.state, GetDC, $TAPress, TRUE];
TJaMGraphicsContexts.DisableViewer[TAPrivate.state];
TACallig.UseThisPressHandle[pressState.pressHandle];
JaM.Execute[TAPrivate.state, "(hsvcolor) (.presshsb) .cvx .def"];
{
ENABLE
UNWIND => {
[] ←TJaMGraphicsContexts.RemoveContext[TAPrivate.state, $TAPress];
TACallig.ForgetThePressHandle[];
JaM.Execute[TAPrivate.state, "(hsvcolor) (.hsvcolor) .cvx .def"];
};
TAPrivate.PushDC[];
TAPrivate.PushReal[originX.texPts];
TAPrivate.PushReal[originY.texPts-data.bbox.ymin];
TAPrivate.Translate[];
TARender.RenderBranch[handle: outputHandle,
node: data.node,
nodeStyle: nodeStyle,
kind: print,
paint: TRUE];
TAPrivate.PopDC[];
[] ←TJaMGraphicsContexts.RemoveContext[TAPrivate.state, $TAPress];
TACallig.ForgetThePressHandle[];
JaM.Execute[TAPrivate.state, "(hsvcolor) (.hsvcolor) .cvx .def"];
TJaMGraphicsContexts.EnableViewer[TAPrivate.state];
};
outputHandle.colorProc[outputHandle, 0, 0, 0];
}
ELSE ERROR;
};
SaveDC:
PROC [dc: Graphics.Context] ~ {
globalDC ← dc;
globalDCProcess ← Process.GetCurrent[];
};
GetDC:
PROC
RETURNS [dc: Graphics.Context] ~ {
IF globalDCProcess # Process.GetCurrent[] THEN ERROR;
RETURN [globalDC]
};
globalDC: Graphics.Context;
globalDCProcess: UNSAFE PROCESS;
useJaMGraphics: BOOLEAN ← FALSE;
RegisterProcs:
PUBLIC
PROC = {
TSArtwork.Register["ArtworkNode", CreateArtworkObject];
TSArtwork.Register["ArtworkFileName", CreateArtworkObject];
TSArtwork.Register["ArtworkImage", CreateArtworkObject];
};
END.
Split from TSArtworkImpl.mesa. Micahel Plass, July 19, 1982 10:22 am