TSOutputDisplayImpl.mesa
Implements TSOutput interface for the Tioga typesetter to display in a Viewer/Imager context
Created by: Beach, October 18, 1983 10:39 am
DIRECTORY
Graphics,
GraphicsColor,
Inline,
Real,
Rope,
TSFont,
TSTypes,
TSOutput,
VFonts,
ViewerClasses,
ViewerOps;
TSOutputDisplayImpl: CEDAR PROGRAM
IMPORTS Graphics, GraphicsColor, Inline, Real, TSFont, TSTypes, VFonts, ViewerOps
EXPORTS TSOutput =
BEGIN
DisplayState: TYPE = REF DisplayStateRec;
DisplayStateRec: TYPE = RECORD [
viewer: ViewerClasses.Viewer ← NIL,
color: Graphics.Color ← Graphics.black,
callBackProc: DisplayProc ← NIL,
currentFont: TSFont.Ref ← NIL,
graphicsFont: Graphics.FontRef ← NIL,
pageHeight: REAL
];
DisplayProc: TYPE = PROCEDURE [dc: Graphics.Context];
CreateViewer: PUBLIC PROCEDURE [viewerName: Rope.ROPE ← NIL] RETURNS [handle: TSOutput.Handle] = {
displayState: DisplayState ← NEW[DisplayStateRec];
v: ViewerClasses.Viewer ← ViewerOps.FindViewer[viewerName];
IF v # NIL THEN ViewerOps.DestroyViewer[v];
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 ← ViewerOps.CreateViewer[
flavor: $TSDisplay,
info: [
name: viewerName,
iconic: FALSE,
column: left,
scrollable: TRUE,
data: handle],
paint: TRUE];
};
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: Inline.BITAND[face, 2],
italic: Inline.BITAND[face, 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];
};
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]^];
containerPaint: ViewerClasses.PaintProc = tsDisplayClass.paint;
tsDisplayClass.coordSys ← bottom;
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)