-- TATypeSetterFaceImpl.mesa
-- Michael Plass, July 20, 1982 10:52 am
-- Rick Beach, April 15, 1983 2:36 pm
-- Maureen Stone April 21, 1983 10:18 am

DIRECTORY
 Graphics USING [Box, Context],
 GraphicsToPressPrivate USING[NewContextFromSirPressHandle],
 JaMOps USING [defaultFrame, Execute, MakeString],
 NodeStyle USING [Create, Ref],
 Real,
 TAGraphicsHacks USING [BeginBox, EndBox],
 TAPrivate USING [PopDC, PushDC, PushReal, 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: PROGRAM
IMPORTS JaMOps, NodeStyle, 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;
  getDC: PROC RETURNS[Graphics.Context] = {RETURN[dc]};
  IF dc=NIL THEN
   dc ← GraphicsToPressPrivate.NewContextFromSirPressHandle[pressState.pressHandle];
  TJaMGraphicsContexts.AddContext[JaMOps.defaultFrame, getDC, $TAPress, TRUE];
  TJaMGraphicsContexts.DisableViewer[JaMOps.defaultFrame];
  TACallig.UseThisPressHandle[pressState.pressHandle];
  JaMOps.Execute[JaMOps.defaultFrame, JaMOps.MakeString["(hsvcolor) (.presshsb) .cvx .def", X]];
  { ENABLE UNWIND => {
    [] ←TJaMGraphicsContexts.RemoveContext[JaMOps.defaultFrame, $TAPress];
    TACallig.ForgetThePressHandle[];
    JaMOps.Execute[JaMOps.defaultFrame, JaMOps.MakeString["(hsvcolor) (.hsvcolor) .cvx .def", X]];
    };
   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[JaMOps.defaultFrame, $TAPress];
   TACallig.ForgetThePressHandle[];
   JaMOps.Execute[JaMOps.defaultFrame, JaMOps.MakeString["(hsvcolor) (.hsvcolor) .cvx .def", X]];
   TJaMGraphicsContexts.EnableViewer[JaMOps.defaultFrame];
   };
  outputHandle.colorProc[outputHandle, 0, 0, 0];
  }
ELSE ERROR; 
 };

useJaMGraphics: BOOLEANFALSE;

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