TSOutputDisplayImpl.mesa
Implements TSOutput interface for the Tioga typesetter to display in a Viewer/Imager context
Created by: Beach, December 7, 1983 5:33 pm
DIRECTORY
Graphics,
GraphicsColor,
Real,
Rope,
TSFont,
TSTypes,
TSOutput,
TSOutputDisplay,
VFonts,
ViewerClasses,
ViewerOps;
TSOutputDisplayImpl: CEDAR PROGRAM
IMPORTS Graphics, GraphicsColor, Real, TSFont, TSTypes, VFonts, ViewerOps
EXPORTS TSOutput =
BEGIN
OPEN TSOutputDisplay;
CreateViewer: PUBLIC PROCEDURE [viewerName: Rope.ROPE ← NIL] RETURNS [handle: TSOutput.Handle] = {
v: ViewerClasses.Viewer ← ViewerOps.FindViewer[viewerName];
IF v # NIL THEN ViewerOps.DestroyViewer[v];
v ← ViewerOps.CreateViewer[
flavor: $TSDisplay,
info: [
name: viewerName,
iconic: FALSE,
column: left,
scrollable: TRUE,
data: handle],
paint: TRUE];
handle ←NARROW [ViewerOps.FetchProp[v, $TSDisplayHandle]];
};
Char: TSOutput.CharProc = { -- [self: Handle, x, y: TSTypes.Dimn, char: CHAR, font: TSFont.Ref]
displayState: DisplayState ← NARROW[self.outputState];
CharPaint: DisplayProc = {
Graphics.SetColor[dc, displayState.color];
Graphics.SetCP[dc, x.DimnInt[TSTypes.pt], y.DimnInt[TSTypes.pt]];
Graphics.DrawChar[dc, char, displayState.graphicsFont];
};
SetFont[displayState, font];
Painter[CharPaint, displayState];
};
SetFont: PROCEDURE [displayState: DisplayState, font: TSFont.Ref] = {
IF displayState.currentFont # font AND font # NIL THEN {
family: Rope.ROPE;
micaSize: INTEGER;
pointsPerMica: REAL = 72.0/2540.0;
face: [0..255];
rotation: INTEGER;
[family, micaSize, face, rotation] ← TSFont.ParcFontSpecification[font];
displayState.graphicsFont ← VFonts.GraphicsFont[
VFonts.EstablishFont[
family: family,
size: Real.RoundI[micaSize * pointsPerMica],
bold: (face/2) MOD 2 = 1,
italic: face MOD 2 = 1,
defaultOnFailure: TRUE ]
];
};
displayState.currentFont ← font;
};
Rule: TSOutput.RuleProc = { -- [self: Handle, leftX, bottomY, width, height: TSTypes.Dimn]
displayState: DisplayState ← NARROW[self.outputState];
RulePaint: DisplayProc = {
Graphics.SetColor[dc, displayState.color];
Graphics.DrawBox[dc, [leftX.DimnInt[TSTypes.pt], bottomY.DimnInt[TSTypes.pt], leftX.AddDimn[width].DimnInt[TSTypes.pt], bottomY.AddDimn[height].DimnInt[TSTypes.pt]]];
};
Painter[RulePaint, displayState];
};
Color: TSOutput.ColorProc = { -- [self: Handle, hue, saturation, brightness: REAL]
displayState: DisplayState ← NARROW[self.outputState];
displayState.color ← GraphicsColor.HSVToColor[hue, saturation, brightness];
};
NewPage: TSOutput.NewPageProc = { -- [self: Handle]
displayState: DisplayState ← NARROW[self.outputState];
ViewerOps.PaintViewer[viewer: displayState.viewer, hint: all, whatChanged: NIL, clearClient: TRUE];
};
PageSize: TSOutput.PageSizeProc = { -- [self: Handle, height, width: TSTypes.Dimn]
displayState: DisplayState ← NARROW[self.outputState];
displayState.pageHeight ← height.texPts;
};
Finish: TSOutput.FinishProc = { -- [self: Handle]
displayState: DisplayState ← NARROW[self.outputState];
};
TSDisplayInitViewer: ViewerClasses.InitProc = {
displayState: DisplayState ← NEW[DisplayStateRec];
handle: TSOutput.Handle ← NEW[TSOutput.OutputRec];
handle.charProc ← Char;
handle.ruleProc ← Rule;
handle.colorProc ← Color;
handle.newPageProc ← NewPage;
handle.pageSizeProc ← PageSize;
handle.finishProc ← Finish;
handle.outputState ← displayState;
displayState.viewer ← self;
ViewerOps.AddProp[self, $TSDisplayHandle, handle];
};
TSDisplayPaint: ViewerClasses.PaintProc = { -- [self: ViewerClasses.Viewer, context: Graphics.Context, whatChanged: REF ANY, clear: BOOL]
displayState: DisplayState;
IF whatChanged # NIL AND ISTYPE[whatChanged, DisplayState] THEN {
displayState ← NARROW[whatChanged, DisplayState];
Graphics.Translate[context, 0.0, self.ch - displayState.pageHeight];
displayState.callBackProc[context];
};
};
Painter: PROCEDURE [proc: DisplayProc, displayState: DisplayState] = {
CallBack: DisplayProc = { proc[dc]; };
TRUSTED {
displayState.callBackProc ← CallBack;
ViewerOps.PaintViewer[viewer: displayState.viewer, hint: client, whatChanged: displayState, clearClient: FALSE];
};
};
tsDisplayClass: ViewerClasses.ViewerClass ~
NEW[ViewerClasses.ViewerClassRec ← ViewerOps.FetchViewerClass[$Container]^];
containerInit: ViewerClasses.InitProc ~ tsDisplayClass.init;
containerPaint: ViewerClasses.PaintProc ~ tsDisplayClass.paint;
tsDisplayClass.coordSys ← bottom;
tsDisplayClass.init ← TSDisplayInitViewer;
tsDisplayClass.paint ← TSDisplayPaint;
ViewerOps.RegisterViewerClass[$TSDisplay, tsDisplayClass];
END.
Edited on October 6, 1983 2:39 pm, by Beach
Modified TSOutputPressImpl.Mesa to get this interface, DIRECTORY, DisplayProc, Char, paint (local of Char), TSDiplayPaint, tSDisplayClass, containerPaint, tSDisplayClass, ViewerOps, Rule, RulePaint (local of Rule), Color, NewPage, PageSize, Finish, TSDiplayPaint, Painter, CallBack (local of Painter)