DIRECTORY ChoiceButtons USING [GetSelectedButton, PromptDataRef], Containers USING [ChildXBound, ChildYBound, Create], Icons USING [IconFlavor, NewIconFromFile], Imager USING [Box, Context, DoSave, MaskBox, MaskFill, MaskStrokeTrajectory, SetColor, SetStrokeEnd, SetStrokeJoint, SetStrokeWidth, SetFont, SetXY, ShowRope, StrokeJoint, StrokeEnd, black, white], ImagerBackdoor USING [GetBounds, invert], ImagerBox USING [BoxFromExtents, BoxFromRect], ImagerColor USING [ColorFromRGB, ConstantColor], ImagerFont USING [Font, RopeBoundingBox], ImagerPath USING [LineTo, MoveTo, PathProc, Trajectory], IO USING [int, PutFR], MessageWindow USING [Clear], Real USING [FixI], Rope USING [Equal, ROPE], StyleToolBuilders USING [DisplayRealInViewer], StyleToolConvert USING [GetRealFromViewer], StyleToolDefs USING [MarginType, PageBoundaryType, StyleToolHandle, ValueAndUnitsRef], StyleToolGraphics, StyleToolGraphicsMisc USING [CreateNumbersContainer, defaultInterval, HitAMargin, HitAPage, InsidePage, ScreenToLeftMargin, ScreenToRightMargin, ScreenToBindingMargin, ScreenToTopMargin, ScreenToBottomMargin, ScreenToPageWidth, ScreenToPageLength, SetUpNumbers], TIPUser USING [InstantiateNewTIPTable, TIPScreenCoords, TIPTable], VFonts USING [EstablishFont], ViewerClasses USING [NotifyProc, PaintProc, Viewer, ViewerClass, ViewerClassRec], ViewerEvents USING [EventProc, RegisterEventProc, ViewerEvent], ViewerOps USING [CreateViewer, PaintViewer, RegisterViewerClass]; StyleToolGraphicsImpl: CEDAR PROGRAM IMPORTS ChoiceButtons, Containers, Icons, Imager, ImagerBackdoor, ImagerBox, ImagerColor, ImagerFont, ImagerPath, IO, MessageWindow, Real, Rope, StyleToolBuilders, StyleToolConvert, StyleToolGraphicsMisc, TIPUser, VFonts, ViewerEvents, ViewerOps EXPORTS StyleToolGraphics = BEGIN OPEN StyleToolDefs, StyleToolGraphicsMisc; PaintInfoRef: TYPE = REF PaintInfoRec; PaintInfoRec: TYPE = RECORD [ whatToChange: Changeables, -- part of layout to change x,y: REAL -- Mouse coordinates ]; Changeables: TYPE = {all, margin, page}; gray: ImagerColor.ConstantColor = ImagerColor.ColorFromRGB[[0.5, 0.5, 0.5]]; gridThickness: REAL = 1.0; pageOutlineThickness: REAL = 2.0; marginThickness: REAL = 1.0; layoutIcon: Icons.IconFlavor = Icons.NewIconFromFile["StyleTool.icons", 3]; CreateLayoutContainer: PUBLIC PROCEDURE [handle: StyleToolHandle] = { nexty: INTEGER; handle.layoutGraphics.container _ Containers.Create[info: [name: "PAGE LAYOUT", scrollable: FALSE, iconic: FALSE, icon: layoutIcon]]; nexty _ CreateNumbersContainer[handle]; handle.layoutGraphics.interval _ defaultInterval; SetUpNumbers[handle]; CreateGraphicsViewer[handle, nexty]; ViewerOps.PaintViewer[handle.layoutGraphics.container, all]; }; DestroyProc: ViewerEvents.EventProc = { handle: StyleToolHandle _ NARROW[viewer.data]; handle.layoutGraphics.container _ NIL; handle.layoutGraphics.exists _ FALSE; }; CreateGraphicsViewer: PROCEDURE [handle: StyleToolHandle, starty: INTEGER] = { handle.layoutGraphics.viewer _ ViewerOps.CreateViewer[flavor: $LayoutViewer, info: [parent: handle.layoutGraphics.container, wx: 0, wy: starty, scrollable: FALSE, border: FALSE, data: handle]]; [] _ ViewerEvents.RegisterEventProc[proc: DestroyProc, event: destroy, filter: handle.layoutGraphics.viewer]; Containers.ChildXBound[handle.layoutGraphics.container, handle.layoutGraphics.viewer]; Containers.ChildYBound[handle.layoutGraphics.container, handle.layoutGraphics.viewer]; }; UpdateValue: PROCEDURE[displayInfo: ChoiceButtons.PromptDataRef, newValue: REAL] = INLINE { StyleToolBuilders.DisplayRealInViewer[newValue, displayInfo.textViewer]; }; LayoutPainter: ViewerClasses.PaintProc = { handle: StyleToolHandle _ NARROW[self.data]; MessageWindow.Clear[]; IF whatChanged = NIL THEN { bounds: Imager.Box _ ImagerBox.BoxFromRect[ImagerBackdoor.GetBounds[context]]; DrawGrid[handle, context, clear, bounds]; DrawPage[handle, context]; DrawNumbers[handle, context, bounds]; DrawUnits[handle, context]; DrawMargins[handle, context]; } ELSE { paintInfo: PaintInfoRef _ NARROW[whatChanged]; SELECT paintInfo.whatToChange FROM margin => ChangeMargin[handle, context, paintInfo.x, paintInfo.y]; page => ChangePage[handle, context, paintInfo.x, paintInfo.y]; all => { DrawPage[handle, context]; DrawMargins[handle, context]; }; ENDCASE => ERROR; }; }; NotifyEvents: ViewerClasses.NotifyProc = { handle: StyleToolHandle _ NARROW[self.data]; iMouse, jMouse: REAL; InterpretAtom: PROCEDURE [atom: ATOM] = { paintInfo: PaintInfoRef; SELECT atom FROM $StartMarginMode => IF InsidePage[handle, iMouse, jMouse] THEN { IF (handle.layoutGraphics.currentMargin _ HitAMargin[handle, iMouse, jMouse]) # none THEN { paintInfo _ NEW [PaintInfoRec _ [margin, iMouse, jMouse]]; ViewerOps.PaintViewer[viewer: self, hint: client, whatChanged: paintInfo, clearClient: FALSE]; }; }; $Margin => IF InsidePage[handle, iMouse, jMouse] THEN { IF handle.layoutGraphics.currentMargin = none THEN { IF (handle.layoutGraphics.currentMargin _ HitAMargin[handle, iMouse, jMouse]) # none THEN { paintInfo _ NEW [PaintInfoRec _ [margin, iMouse, jMouse]]; ViewerOps.PaintViewer[viewer: self, hint: client, whatChanged: paintInfo, clearClient: FALSE]; }; } ELSE { paintInfo _ NEW [PaintInfoRec _ [margin, iMouse, jMouse]]; ViewerOps.PaintViewer[viewer: self, hint: client, whatChanged: paintInfo, clearClient: FALSE]; }; }; $EndMarginMode => IF InsidePage[handle, iMouse, jMouse] THEN { IF handle.layoutGraphics.currentMargin # none THEN { paintInfo _ NEW [PaintInfoRec _ [margin, iMouse, jMouse]]; ViewerOps.PaintViewer[viewer: self, hint: client, whatChanged: paintInfo, clearClient: FALSE]; }; }; $StartPageMode => IF (handle.layoutGraphics.currentPage _ HitAPage[handle, iMouse, jMouse]) # none THEN { paintInfo _ NEW [PaintInfoRec _ [page, iMouse, jMouse]]; ViewerOps.PaintViewer[viewer: self, hint: client, whatChanged: paintInfo, clearClient: FALSE]; }; $Page => IF handle.layoutGraphics.currentPage = none THEN { IF (handle.layoutGraphics.currentPage _ HitAPage[handle, iMouse, jMouse]) # none THEN { paintInfo _ NEW [PaintInfoRec _ [page, iMouse, jMouse]]; ViewerOps.PaintViewer[viewer: self, hint: client, whatChanged: paintInfo, clearClient: FALSE]; }; } ELSE { paintInfo _ NEW [PaintInfoRec _ [page, iMouse, jMouse]]; ViewerOps.PaintViewer[viewer: self, hint: client, whatChanged: paintInfo, clearClient: FALSE]; }; $EndPageMode => IF handle.layoutGraphics.currentPage # none THEN { paintInfo _ NEW [PaintInfoRec _ [all, iMouse, jMouse]]; ViewerOps.PaintViewer[viewer: self, hint: client, whatChanged: paintInfo, clearClient: FALSE]; }; ENDCASE; }; FOR items: LIST OF REF ANY _ input, items.rest UNTIL items = NIL DO WITH items.first SELECT FROM x: TIPUser.TIPScreenCoords => { iMouse _ x.mouseX; jMouse _ x.mouseY; }; x: ATOM => InterpretAtom[x]; ENDCASE; ENDLOOP; }; DrawGrid: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, clear: BOOLEAN, bounds: Imager.Box] = { xpos, ypos, rem: INTEGER; path: ImagerPath.Trajectory; xpos _ Real.FixI[bounds.xmin]; rem _ (xpos MOD handle.layoutGraphics.interval); IF rem # 0 THEN xpos _ xpos + handle.layoutGraphics.interval - rem; ypos _ Real.FixI[bounds.ymin]; rem _ ypos MOD handle.layoutGraphics.interval; IF rem # 0 THEN ypos _ ypos + handle.layoutGraphics.interval - rem; IF ~clear THEN { Imager.SetColor[context, Imager.white]; Imager.MaskBox[context, bounds]; }; Imager.SetColor[context, gray]; Imager.SetStrokeWidth[context, gridThickness]; Imager.SetStrokeEnd[context, butt]; WHILE xpos <= bounds.xmax OR ypos <= bounds.ymax DO path _ ImagerPath.MoveTo[[xpos, bounds.ymin]]; path _ ImagerPath.LineTo[path, [xpos, bounds.ymax]]; Imager.MaskStrokeTrajectory[context, path]; path _ ImagerPath.MoveTo[[bounds.xmin, ypos]]; path _ ImagerPath.LineTo[path, [bounds.xmax, ypos]]; Imager.MaskStrokeTrajectory[context, path]; xpos _ xpos + handle.layoutGraphics.interval; ypos _ ypos + handle.layoutGraphics.interval; ENDLOOP; }; DrawPage: PROCEDURE [handle: StyleToolHandle, context: Imager.Context] = { OPEN handle.layoutGraphics; -- for screenPage, interval, indent, pageWidth, pageLength pageVal: REAL; path: ImagerPath.Trajectory; DetermineIndent[handle]; DetermineSkipAndIncrement[handle]; screenPage.xmin _ indent*interval; pageVal _ StyleToolConvert.GetRealFromViewer[pageWidth.textViewer]; screenPage.xmax _ ((pageVal / (increment/skip)) + indent) * interval; screenPage.ymin _ indent*interval; pageVal _ StyleToolConvert.GetRealFromViewer[pageLength.textViewer]; screenPage.ymax _ ((pageVal / (increment/skip)) + indent) * interval; Imager.SetColor[context, Imager.white]; Imager.MaskBox[context, handle.layoutGraphics.screenPage]; Imager.SetColor[context, Imager.black]; Imager.SetStrokeWidth[context, pageOutlineThickness]; Imager.SetStrokeJoint[context, mitered]; path _ ImagerPath.MoveTo[[screenPage.xmin, screenPage.ymin]]; path _ ImagerPath.LineTo[path, [screenPage.xmax, screenPage.ymin]]; path _ ImagerPath.LineTo[path, [screenPage.xmax, screenPage.ymax]]; path _ ImagerPath.LineTo[path, [screenPage.xmin, screenPage.ymax]]; path _ ImagerPath.LineTo[path, [screenPage.xmin, screenPage.ymin]]; Imager.MaskStrokeTrajectory[context, path, TRUE]; }; DetermineIndent: PROCEDURE [handle: StyleToolHandle] = { units: Rope.ROPE _ ChoiceButtons.GetSelectedButton[handle.layoutGraphics.units.ref]; SELECT TRUE FROM Rope.Equal[units, "points", FALSE] => handle.layoutGraphics.indent _ 4; Rope.Equal[units, "picas", FALSE] => handle.layoutGraphics.indent _ 4; Rope.Equal[units, "inches", FALSE] => handle.layoutGraphics.indent _ 2; Rope.Equal[units, "centimeters", FALSE] => handle.layoutGraphics.indent _ 4; Rope.Equal[units, "millimeters", FALSE] => handle.layoutGraphics.indent _ 4; Rope.Equal[units, "didot points", FALSE] => handle.layoutGraphics.indent _ 4; ENDCASE => handle.layoutGraphics.indent _ 2; }; DrawText: PROC [context: Imager.Context, x, y: REAL, rope: Rope.ROPE] = { font: ImagerFont.Font _ VFonts.EstablishFont[family: "Helvetica", size: 8, bold: TRUE]; rxmin, rxmax, rymin, rymax: REAL; x0, y0, x1, y1: REAL; Path: ImagerPath.PathProc = { moveTo[[x0, y0]]; lineTo[[x1, y0]]; lineTo[[x1, y1]]; lineTo[[x0, y1]]; }; [[rxmin, rymin, rxmax, rymax]] _ ImagerBox.BoxFromExtents[ImagerFont.RopeBoundingBox[font, rope]]; x0 _ x - (rxmax - rxmin)/2 - 2; -- bottom right corner y0 _ y - (rymax - rymin)/2; x1 _ x + (rxmax - rxmin)/2 + 2; -- top left corner plus some pixels y1 _ y + (rymax - rymin)/2; Imager.SetColor[context, Imager.white]; Imager.MaskFill[context, Path]; Imager.SetColor[context, Imager.black]; Imager.SetXY[context, [x0 + 2, y0 + 2]]; Imager.SetFont[context, font]; Imager.ShowRope[context, rope]; }; DrawNumbers: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, bounds: Imager.Box] = { OPEN handle.layoutGraphics; -- for interval xline, yline: REAL _ GetNumberLine[handle] * interval; xpos, ypos: REAL _ indent*interval; i: CARDINAL _ 0; numberRope: Rope.ROPE; WHILE xpos <= bounds.xmax DO numberRope _ IO.PutFR["%g", IO.int[i]]; DrawText[context, xpos, yline, numberRope]; xpos _ xpos + skip * interval; i _ i + increment; ENDLOOP; i _ 0; WHILE ypos <= bounds.ymax DO numberRope _ IO.PutFR["%g", IO.int[i]]; DrawText[context, xline, ypos, numberRope]; ypos _ ypos + skip * interval; i _ i + increment; ENDLOOP; }; GetNumberLine: PROCEDURE [handle: StyleToolHandle] RETURNS [INTEGER] = { units: Rope.ROPE _ ChoiceButtons.GetSelectedButton[handle.layoutGraphics.units.ref]; SELECT TRUE FROM Rope.Equal[units, "points", FALSE] => RETURN[2]; Rope.Equal[units, "picas", FALSE] => RETURN[2]; Rope.Equal[units, "inches", FALSE] => RETURN[1]; Rope.Equal[units, "centimeters", FALSE] => RETURN[2]; Rope.Equal[units, "millimeters", FALSE] => RETURN[2]; Rope.Equal[units, "didot points", FALSE] => RETURN[2]; ENDCASE => RETURN[2]; }; DetermineSkipAndIncrement: PROCEDURE [handle: StyleToolHandle] = { units: Rope.ROPE _ ChoiceButtons.GetSelectedButton[handle.layoutGraphics.units.ref]; SELECT TRUE FROM Rope.Equal[units, "points", FALSE] => {handle.layoutGraphics.skip _ 2; handle.layoutGraphics.increment _ 72}; Rope.Equal[units, "picas", FALSE] => {handle.layoutGraphics.skip _ 1; handle.layoutGraphics.increment _ 3}; Rope.Equal[units, "inches", FALSE] => {handle.layoutGraphics.skip _ 1; handle.layoutGraphics.increment _ 1}; Rope.Equal[units, "centimeters", FALSE] => {handle.layoutGraphics.skip _ 2; handle.layoutGraphics.increment _ 2}; Rope.Equal[units, "millimeters", FALSE] => {handle.layoutGraphics.skip _ 2; handle.layoutGraphics.increment _ 20}; Rope.Equal[units, "didot points", FALSE] => {handle.layoutGraphics.skip _ 2; handle.layoutGraphics.increment _ 50}; ENDCASE => {handle.layoutGraphics.skip _ 1; handle.layoutGraphics.increment _ 1}; }; DrawUnits: PROCEDURE [handle: StyleToolHandle, context: Imager.Context] = { unitsRope: Rope.ROPE; xline, yline: REAL _ GetNumberLine[handle] * handle.layoutGraphics.interval; unitsRope _ ChoiceButtons.GetSelectedButton[handle.layoutGraphics.units.ref]; DrawText[context, xline, yline, unitsRope]; }; DrawMargins: PROCEDURE [handle: StyleToolHandle, context: Imager.Context] = { Imager.SetColor[context, Imager.black]; Imager.SetStrokeWidth[context, marginThickness]; Imager.SetStrokeEnd[context, butt]; DrawLeftMargin[handle, context]; DrawRightMargin[handle, context]; DrawTopMargin[handle, context]; DrawBottomMargin[handle, context]; DrawBindingMargin[handle, context]; }; DrawLeftMargin: PROCEDURE [handle: StyleToolHandle, context: Imager.Context] = { OPEN handle.layoutGraphics; margin: REAL _ StyleToolConvert.GetRealFromViewer[leftMargin.textViewer]; path: ImagerPath.Trajectory; screenLeftMargin _ screenPage.xmin + ((margin / (increment/skip)) * interval); IF screenLeftMargin < screenPage.xmax THEN { path _ ImagerPath.MoveTo[[screenLeftMargin, screenPage.ymin]]; path _ ImagerPath.LineTo[path, [screenLeftMargin, screenPage.ymax]]; Imager.MaskStrokeTrajectory[context, path]; }; }; DrawRightMargin: PROCEDURE [handle: StyleToolHandle, context: Imager.Context] = { OPEN handle.layoutGraphics; -- for rightMargin, screenRightMargin, screenPage and interval margin: REAL _ StyleToolConvert.GetRealFromViewer[rightMargin.textViewer]; path: ImagerPath.Trajectory; screenRightMargin _ screenPage.xmax - ((margin / (increment/skip)) * interval); IF screenRightMargin > screenPage.xmin THEN { path _ ImagerPath.MoveTo[[screenRightMargin, screenPage.ymin]]; path _ ImagerPath.LineTo[path, [screenRightMargin, screenPage.ymax]]; Imager.MaskStrokeTrajectory[context, path]; }; }; DrawTopMargin: PROCEDURE [handle: StyleToolHandle, context: Imager.Context] = { OPEN handle.layoutGraphics; margin: REAL _ StyleToolConvert.GetRealFromViewer[topMargin.textViewer]; path: ImagerPath.Trajectory; screenTopMargin _ screenPage.ymax - ((margin / (increment/skip)) * interval); IF screenTopMargin > screenPage.ymin THEN { path _ ImagerPath.MoveTo[[screenPage.xmin, screenTopMargin]]; path _ ImagerPath.LineTo[path, [screenPage.xmax, screenTopMargin]]; Imager.MaskStrokeTrajectory[context, path]; }; }; DrawBottomMargin: PROCEDURE [handle: StyleToolHandle, context: Imager.Context] = { OPEN handle.layoutGraphics; margin: REAL _ StyleToolConvert.GetRealFromViewer[bottomMargin.textViewer]; path: ImagerPath.Trajectory; screenBottomMargin _ screenPage.ymin + ((margin / (increment/skip)) * interval); IF screenBottomMargin < screenPage.ymax THEN { path _ ImagerPath.MoveTo[[screenPage.xmin, screenBottomMargin]]; path _ ImagerPath.LineTo[path, [screenPage.xmax, screenBottomMargin]]; Imager.MaskStrokeTrajectory[context, path]; }; }; DrawBindingMargin: PROCEDURE [handle: StyleToolHandle, context: Imager.Context] = { OPEN handle.layoutGraphics; offset: REAL _ StyleToolConvert.GetRealFromViewer[bindingMargin.textViewer]; path: ImagerPath.Trajectory; screenBindingMargin _ screenLeftMargin + ((offset / (increment/skip)) * interval); IF screenBindingMargin < screenPage.xmax THEN { path _ ImagerPath.MoveTo[[screenBindingMargin, screenPage.ymin]]; path _ ImagerPath.LineTo[path, [screenBindingMargin, screenPage.ymax]]; Imager.MaskStrokeTrajectory[context, path]; }; }; ChangeMargin: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, x, y: REAL] = { OPEN handle.layoutGraphics; neverLand: REAL _ 5.0; SELECT currentMargin FROM left => IF (x + neverLand) < screenRightMargin THEN { diff: REAL _ x - screenLeftMargin; DrawVerticalMargin[handle, context, screenLeftMargin]; screenLeftMargin _ x; DrawVerticalMargin[handle, context, screenLeftMargin]; UpdateValue[leftMargin, ScreenToLeftMargin[handle]]; DrawVerticalMargin[handle, context, screenBindingMargin]; screenBindingMargin _ screenBindingMargin + diff; DrawVerticalMargin[handle, context, screenBindingMargin]; }; right => IF (x - neverLand) > screenLeftMargin THEN { DrawVerticalMargin[handle, context, screenRightMargin]; screenRightMargin _ x; DrawVerticalMargin[handle, context, screenRightMargin]; UpdateValue[rightMargin, ScreenToRightMargin[handle]]; }; binding => IF x > screenLeftMargin THEN { DrawVerticalMargin[handle, context, screenBindingMargin]; screenBindingMargin _ x; DrawVerticalMargin[handle, context, screenBindingMargin]; UpdateValue[bindingMargin, ScreenToBindingMargin[handle]]; }; top => IF (y - neverLand) > screenBottomMargin THEN { DrawHorizontalMargin[handle, context, screenTopMargin]; screenTopMargin _ y; DrawHorizontalMargin[handle, context, screenTopMargin]; UpdateValue[topMargin, ScreenToTopMargin[handle]]; }; bottom => IF (y + neverLand) < screenTopMargin THEN { DrawHorizontalMargin[handle, context, screenBottomMargin]; screenBottomMargin _ y; DrawHorizontalMargin[handle, context, screenBottomMargin]; UpdateValue[bottomMargin, ScreenToBottomMargin[handle]]; }; ENDCASE; }; DrawVerticalMargin: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, x: REAL] = { inner: PROC = { path: ImagerPath.Trajectory; Imager.SetColor[context, ImagerBackdoor.invert]; Imager.SetStrokeEnd[context, butt]; Imager.SetStrokeWidth[context, marginThickness]; path _ ImagerPath.MoveTo[[x, handle.layoutGraphics.screenPage.ymin]]; path _ ImagerPath.LineTo[path, [x, handle.layoutGraphics.screenPage.ymax]]; Imager.MaskStrokeTrajectory[context, path]; }; Imager.DoSave[context, inner]; }; DrawHorizontalMargin: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, y: REAL] = { inner: PROC = { path: ImagerPath.Trajectory; Imager.SetColor[context, ImagerBackdoor.invert]; Imager.SetStrokeEnd[context, butt]; Imager.SetStrokeWidth[context, marginThickness]; path _ ImagerPath.MoveTo[[handle.layoutGraphics.screenPage.xmin, y]]; path _ ImagerPath.LineTo[path, [handle.layoutGraphics.screenPage.xmax, y]]; Imager.MaskStrokeTrajectory[context, path]; }; Imager.DoSave[context, inner]; }; ChangePage: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, x, y: REAL] = { neverLand: REAL _ 5.0; SELECT handle.layoutGraphics.currentPage FROM side => IF (x - neverLand) > handle.layoutGraphics.screenPage.xmin THEN { IF x < handle.layoutGraphics.screenPage.xmax THEN DrawSmallerPageFromRight[handle, context, x] ELSE DrawLargerPageFromRight[handle, context, x]; handle.layoutGraphics.screenPage.xmax _ x; UpdateValue[handle.layoutGraphics.pageWidth, ScreenToPageWidth[handle]]; }; top => IF (y - neverLand) > handle.layoutGraphics.screenPage.ymin THEN { IF y < handle.layoutGraphics.screenPage.ymax THEN DrawSmallerPageFromTop[handle, context, y] ELSE DrawLargerPageFromTop[handle, context, y]; handle.layoutGraphics.screenPage.ymax _ y; UpdateValue[handle.layoutGraphics.pageLength, ScreenToPageLength[handle]]; }; ENDCASE; }; DrawSmallerPageFromRight: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, x: REAL] = { OPEN handle.layoutGraphics; tempBox, gridBox: Imager.Box; path: ImagerPath.Trajectory; tempBox.xmin _ x; tempBox.xmax _ screenPage.xmax; tempBox.ymin _ screenPage.ymin; tempBox.ymax _ screenPage.ymax; Imager.SetColor[context, Imager.white]; DrawThreePageSides[context, tempBox]; gridBox _ tempBox; gridBox.xmax _ tempBox.xmax + 1; -- since the page outline is 2 units wide gridBox.ymax _ tempBox.ymax + 1; DrawGrid[handle, context, FALSE, gridBox]; Imager.SetColor[context, Imager.black]; Imager.SetStrokeEnd[context, butt]; Imager.SetStrokeWidth[context, pageOutlineThickness]; path _ ImagerPath.MoveTo[[tempBox.xmin, tempBox.ymin]]; path _ ImagerPath.LineTo[path, [tempBox.xmin, tempBox.ymax]]; Imager.MaskStrokeTrajectory[context, path]; IF (screenRightMargin - (tempBox.xmax - tempBox.xmin)) > screenPage.xmin THEN { DrawVerticalMargin[handle, context, screenRightMargin]; -- erase old one screenRightMargin _ screenRightMargin - (tempBox.xmax - tempBox.xmin); DrawVerticalMargin[handle, context, screenRightMargin]; }; }; DrawSmallerPageFromTop: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, y: REAL] = { OPEN handle.layoutGraphics; tempBox, gridBox: Imager.Box; path: ImagerPath.Trajectory; tempBox.xmin _ screenPage.xmin; tempBox.xmax _ screenPage.xmax; tempBox.ymin _ y; tempBox.ymax _ screenPage.ymax; Imager.SetColor[context, Imager.white]; DrawThreePageSidesFromTop[context, tempBox]; gridBox _ tempBox; gridBox.xmax _ tempBox.xmax + 1; -- since the page outline is 2 units wide gridBox.ymax _ tempBox.ymax + 1; DrawGrid[handle, context, FALSE, gridBox]; Imager.SetColor[context, Imager.black]; Imager.SetStrokeEnd[context, butt]; Imager.SetStrokeWidth[context, pageOutlineThickness]; path _ ImagerPath.MoveTo[[tempBox.xmin, tempBox.ymin]]; path _ ImagerPath.LineTo[path, [tempBox.xmax, tempBox.ymin]]; Imager.MaskStrokeTrajectory[context, path]; IF (screenTopMargin - (tempBox.ymax - tempBox.ymin)) > screenPage.ymin THEN { DrawHorizontalMargin[handle, context, screenTopMargin];-- erase old one screenTopMargin _ screenTopMargin - (tempBox.ymax - tempBox.ymin); DrawHorizontalMargin[handle, context, screenTopMargin]; }; }; DrawLargerPageFromRight: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, x: REAL] = { OPEN handle.layoutGraphics; tempBox: Imager.Box; path: ImagerPath.Trajectory; tempBox.xmin _ screenPage.xmax; tempBox.xmax _ x; tempBox.ymin _ screenPage.ymin; tempBox.ymax _ screenPage.ymax; Imager.SetColor[context, Imager.white]; Imager.MaskBox[context, tempBox]; Imager.SetColor[context, Imager.black]; DrawThreePageSides[context, tempBox]; Imager.SetStrokeEnd[context, butt]; Imager.SetStrokeWidth[context, marginThickness]; path _ ImagerPath.MoveTo[[tempBox.xmin, screenTopMargin]]; path _ ImagerPath.LineTo[path, [tempBox.xmax, screenTopMargin]]; Imager.MaskStrokeTrajectory[context, path]; path _ ImagerPath.MoveTo[[tempBox.xmin, screenBottomMargin]]; path _ ImagerPath.LineTo[path, [tempBox.xmax, screenBottomMargin]]; Imager.MaskStrokeTrajectory[context, path]; DrawVerticalMargin[handle, context, screenRightMargin]; -- erase old one screenRightMargin _ screenRightMargin + (tempBox.xmax - tempBox.xmin); DrawVerticalMargin[handle, context, handle.layoutGraphics.screenRightMargin]; }; DrawLargerPageFromTop: PROCEDURE [handle: StyleToolHandle, context: Imager.Context, y: REAL] = { OPEN handle.layoutGraphics; tempBox: Imager.Box; path: ImagerPath.Trajectory; tempBox.xmin _ screenPage.xmin; tempBox.xmax _ screenPage.xmax; tempBox.ymin _ screenPage.ymax-1; tempBox.ymax _ y; Imager.SetColor[context, Imager.white]; Imager.MaskBox[context, tempBox]; Imager.SetColor[context, Imager.black]; DrawThreePageSidesFromTop[context, tempBox]; Imager.SetStrokeEnd[context, butt]; Imager.SetStrokeWidth[context, marginThickness]; path _ ImagerPath.MoveTo[[screenRightMargin, tempBox.ymin]]; path _ ImagerPath.LineTo[path, [screenRightMargin, tempBox.ymax+1]]; Imager.MaskStrokeTrajectory[context, path]; path _ ImagerPath.MoveTo[[screenLeftMargin, tempBox.ymin]]; path _ ImagerPath.LineTo[path, [screenLeftMargin, tempBox.ymax+1]]; Imager.MaskStrokeTrajectory[context, path]; path _ ImagerPath.MoveTo[[screenBindingMargin, tempBox.ymin]]; path _ ImagerPath.LineTo[path, [screenBindingMargin, tempBox.ymax+1]]; Imager.MaskStrokeTrajectory[context, path]; DrawHorizontalMargin[handle,context, screenTopMargin]; -- erase old one screenTopMargin _ screenTopMargin + (tempBox.ymax - tempBox.ymin - 1); DrawHorizontalMargin[handle, context, screenTopMargin]; }; DrawThreePageSides: PROCEDURE [context: Imager.Context, box: Imager.Box] = { path: ImagerPath.Trajectory; Imager.SetStrokeWidth[context, pageOutlineThickness]; Imager.SetStrokeEnd[context, butt]; Imager.SetStrokeJoint[context, mitered]; path _ ImagerPath.MoveTo[[box.xmin, box.ymin]]; path _ ImagerPath.LineTo[path, [box.xmax, box.ymin]]; path _ ImagerPath.LineTo[path, [box.xmax, box.ymax]]; path _ ImagerPath.LineTo[path, [box.xmin, box.ymax]]; Imager.MaskStrokeTrajectory[context, path]; }; DrawThreePageSidesFromTop: PROCEDURE [context: Imager.Context, box: Imager.Box] = { path: ImagerPath.Trajectory; Imager.SetStrokeWidth[context, pageOutlineThickness]; Imager.SetStrokeEnd[context, butt]; Imager.SetStrokeJoint[context, mitered]; path _ ImagerPath.MoveTo[[box.xmin, box.ymin]]; path _ ImagerPath.LineTo[path, [box.xmin, box.ymax]]; path _ ImagerPath.LineTo[path, [box.xmax, box.ymax]]; path _ ImagerPath.LineTo[path, [box.xmax, box.ymin]]; Imager.MaskStrokeTrajectory[context, path]; }; graphicsTipTable: TIPUser.TIPTable = TIPUser.InstantiateNewTIPTable["StyleToolGraphics.TIP"]; layoutViewerClass: ViewerClasses.ViewerClass _ NEW[ViewerClasses.ViewerClassRec _ [ paint: LayoutPainter, notify: NotifyEvents, tipTable: graphicsTipTable ]]; ViewerOps.RegisterViewerClass[$LayoutViewer, layoutViewerClass]; END. ΪStyleToolGraphicsImpl.mesa Written by Linda Gass September 10, 1982 4:34 pm Last Edit by Linda Gass November 4, 1982 3:44 pm Last Edited by: Plass, March 28, 1983 3:03 pm Last Edited by: Beach, February 22, 1984 3:37:14 pm PST Pavel, June 26, 1985 11:28:06 pm PDT Since we have created our own viewer class, we can attach anything we want to the data field of the viewer rec. We put the handle there so that in future calls to the paint proc, we can have handle on the StyleTool. Start on an even interval boundary First clear the viewer if necessary Now draw the grid Vertical lines Horizontal lines Clear the area which is the page Now draw the outline of the page Numbers accross x axis Numbers accross the y axis Dont bother drawing a margin which lies outside of the page For each different margin we do the same procedure. First check that the new position will not cause the margin to overlap with its "opposite" margin. This means that if we are changing the right margin, we first want to check that the new right margin will not overlap the left margin, this would not make sense and it would drive the typesetter crazy. If everything is OK, then change the position of the margin. Also redraw the binding margin accordingly No need to update the value of the binding margin since it's an offset and that hasn't changed For the different page boundaries we do the same procedure. First check that the new position will not cause the boundary to overlap with its "opposite" boundary. This means that if we are changing the right boundary, we first want to check that the new right boundary will not overlap the left boundary, this would not make sense and it would drive the typesetter crazy. If everything is OK, then change the position of the page boundary. Indicates that we are making the page smaller so need to redraw the grid. Indicates that we are making the page smaller so need to redraw the grid Remove the old outline White out the area to be redrawn and redraw the grid Now redraw the right page boundary Now redraw the margin Remove the old outline White out the area to be redrawn and redraw the grid Now redraw the top page boundary Now redraw the margin Erase the old grid and old page boundary Extend old top and bottom page boundaries and draw new right boundary Now redraw the right margin and extend others. Erase the old grid and old page boundary Extend old left and right page boundaries and draw new top boundary Now redraw the top margin and extend others. Κ›˜Icodešœ™K™0K™0Kšœ-™-šœ7™7K™$—K˜šΟk ˜ Kšœœ$˜7Kšœ œ$˜4Kšœœ˜*KšœœΉ˜ΕKšœœ˜)Kšœ œ˜.Kšœ œ˜0Kšœ œ˜)Kšœ œ(˜8Kšœœ˜Kšœœ ˜Kšœœ˜Kšœœ œ˜Kšœœ˜.Kšœœ˜+KšœœC˜VK˜Kšœœλ˜†Kšœœ5˜BKšœœ˜Kšœœ>˜QKšœ œ-˜?Kšœ œ2˜A—K˜K˜KšΠbxœœ˜$K˜Kšœkœ˜υK˜Kšœ˜K˜Kšœœ&˜0˜Kšœœœ˜&—šœœœ˜KšœΟc˜7KšœœŸ˜$K˜—Kšœ œ˜(K˜KšœL˜LK˜Kšœœ˜Kšœœ˜"Kšœœ˜K˜KšœK˜KK˜K˜šΟnœœ œ˜Cšœ˜Kšœœ˜K˜Kšœ\œ œ˜…K˜K˜'K˜1K˜K˜K˜$K˜<—K˜—K˜šΟb œ˜%šœ˜Kšœœ˜.K˜Kšœ"œ˜&Kšœœ˜%—K˜—K™š œ œ#œ˜Lšœ˜˜Kšœ}œ œ˜’—K˜Kšœm˜mK˜KšœΨ™ΨK™K˜VK˜V—K˜—K˜š  œ œ5œ˜Yšœ˜K˜H—K˜—K˜š‘ œ˜(˜Kšœœ ˜,K˜K˜Kšœœ˜šœ˜KšœN˜NK˜K˜)K˜K˜%K˜K˜—K˜Kš˜šœ˜Kšœœ˜.K˜šœ˜"K˜BK˜>˜K˜K˜K˜—Kšœœ˜——K˜—K˜—K˜š‘ œ˜(šœ˜Kšœœ ˜,Kšœœ˜K˜š  œ œœ˜'šœ˜K˜šœ˜šœ˜Kšœ$˜*šœ˜KšœS˜Yšœ˜Kšœ œ+˜:KšœWœ˜^—K˜—K˜——˜šœ ˜ Kšœ$˜*šœ˜Kšœ,˜2šœ˜KšœS˜Yšœ˜Kšœ œ+˜:KšœWœ˜^—K˜—K˜Kš˜šœ˜Kšœ œ+˜:KšœWœ˜^—K˜—K˜—K˜šœ˜Kšœ$˜*šœ˜Kšœ,˜2šœ˜Kšœ œ+˜:KšœWœ˜^—K˜—K˜—K˜šœ˜KšœO˜Ušœ˜Kšœ œ)˜8KšœWœ˜^—K˜—K˜šœ˜Kšœ*˜0šœ˜KšœO˜Ušœ˜Kšœ œ)˜8KšœWœ˜^—K˜—K˜Kš˜šœ˜Kšœ œ)˜8KšœWœ˜^—K˜—K˜šœ˜Kšœ*˜0šœ˜Kšœ œ(˜7KšœWœ˜^—K˜—Kšœ˜——K˜—K˜šœœœœœœ œ˜Cšœ œ˜˜˜K˜K˜—K˜—šœœ˜ Kšœ˜—Kšœ˜—Kšœ˜——K˜—K˜š œ œ;œ˜lšœ˜Kšœœ˜Kšœ˜K™Kšœ"™"K˜Kšœ œ!˜0šœ ˜K˜3—K˜Kšœ œ ˜.šœ ˜K˜3—K™Kšœ#™#Kšœ˜šœ˜Kšœ'˜'Kšœ ˜ —K˜K™Kšœ™Kšœ˜Kšœ.˜.Kšœ#˜#K˜šœœ˜3Kšœ™Kšœ.˜.Kšœ4˜4Kšœ+˜+K™Kšœ™Kšœ.˜.Kšœ4˜4Kšœ+˜+K˜K˜-K˜-Kšœ˜——K˜—K˜š œ œ5˜Hšœ˜KšœŸ:˜XK˜Kšœ œ˜Kšœ˜K˜K˜K˜"K˜K˜"K˜CK˜EK˜K˜"K˜DK˜EK˜Kšœ ™ Kšœ'˜'Kšœ:˜:K˜Kšœ ™ Kšœ'˜'Kšœ5˜5Kšœ(˜(K˜Kšœ=˜=KšœC˜CKšœC˜CKšœC˜CKšœC˜CKšœ+œ˜1—K˜—K˜š œ œ˜8Kšœ œD˜Tšœœ˜Kšœœ*˜K——Kšœœ(˜HKšœœ(˜IKšœ!œ'˜MKšœ!œ'˜MKšœ"œ'˜Nšœ.˜5K˜—K˜š œœ!œ œ˜G˜KšœQœ˜WKšœœ˜!Kšœœ˜K˜š‘œ˜˜Kšœ˜K˜K˜K˜—K˜—K˜Kšœb˜bKšœ Ÿ˜6K˜Kšœ Ÿ#˜CK˜K˜Kšœ'˜'Kšœ˜K˜Kšœ'˜'Kšœ(˜(Kšœ˜Kšœ˜—K˜—K˜š  œ œI˜_šœ˜KšœŸ˜+K˜Kšœœ$˜6Kšœ œ˜#Kšœœ˜Kšœœ˜K˜Kšœ™šœ˜Kšœ œ œ ˜'K˜Kšœ+˜+K˜K˜K˜Kšœ˜—K™Kšœ™K˜šœ˜Kšœ œ œ ˜'K˜Kšœ+˜+K˜K˜K˜Kšœ˜——K˜—K˜š  œ œœœ˜Fšœ˜Kšœ œD˜TK˜šœœ˜Kšœœœ˜2Kšœœœ˜/Kšœœœ˜0Kšœ!œœ˜5Kšœ!œœ˜5Kšœ"œœ˜6Kšœœ˜——K˜—K˜š œ œ˜@šœ˜Kšœ œD˜TK˜šœœ˜šœœ˜%Kšœ ˜ K˜&—K˜šœœ˜$Kšœ ˜ K˜%—K˜šœœ˜%Kšœ ˜ K˜%—K˜šœ!œ˜*Kšœ ˜ K˜%—K˜šœ œ˜*Kšœ ˜ K˜&—K˜šœ"œ˜+Kšœ ˜ K˜&—K˜šœ˜ Kšœ ˜ K˜%———K˜—K˜š  œ œ6˜Jšœ˜Kšœœ˜Kšœœ:˜LK˜MK˜Kšœ+˜+—K˜—K˜š  œ œ5˜Kšœ˜Kšœ'˜'Iprocšœ0˜0Kšœ#˜#K˜Lšœ ˜ Lšœ!˜!Lšœ˜Lšœ"˜"Lšœ#˜#—K˜—K˜š œ œ5˜Nšœ˜Lšœ˜L˜Lšœœ=˜ILšœ˜LšœN˜NL™Lšœ;™;Lšœ$˜*šœ˜Kšœ>˜>LšœD˜DLšœ+˜+—Lšœ˜—Lšœ˜—K˜š œ œ5˜Ošœ˜KšœŸ>˜ZK˜Kšœœ>˜JKšœ˜K˜K˜OK˜Kšœ%˜+šœ˜Kšœ?˜?KšœE˜EKšœ+˜+—K˜—K˜—K˜š  œ œ5˜Mšœ˜Kšœ˜K˜Kšœœ<˜HKšœ˜K˜K˜MK˜Kšœ#˜)šœ˜Kšœ=˜=KšœC˜CKšœ+˜+—K˜—K˜—K˜š œ œ5˜Pšœ˜Kšœ˜K˜Kšœœ?˜KKšœ˜K˜K˜PK˜Kšœ&˜,šœ˜Kšœ@˜@KšœF˜FKšœ+˜+—K˜—K˜—K˜š œ œ5˜Qšœ˜Kšœ˜K˜Kšœœ@˜LKšœ˜K˜K˜RK˜Kšœ'˜-šœ˜KšœA˜AKšœG˜GKšœ+˜+—K˜—K˜—K˜š  œ œ:œ˜Xšœ˜Kšœ‘™‘K™Kšœ˜K˜Kšœ œ˜K˜šœ˜šœ˜Kšœ%˜+šœ˜Kšœœ˜"K˜K˜6K˜K˜6K˜4K™Kšœ*™*K˜9K˜1K˜9K™Kšœ^™^—K˜—šœ ˜ Kšœ$˜*šœ˜K˜7K˜K˜7K˜6—K˜—šœ ˜ Kšœ˜šœ˜K˜9K˜K˜9K˜:—K˜—šœ˜Kšœ&˜,šœ˜K˜7K˜K˜7K˜2—K˜—šœ ˜ Kšœ#˜)šœ˜K˜:K˜K˜:K˜8—K˜—Kšœ˜——K˜—K˜š œ œ7œ˜[šœ˜š‘œœ˜ ˜Kšœ˜K˜Kšœ0˜0Kšœ#˜#Kšœ0˜0K˜KšœE˜EKšœK˜KKšœ+˜+—K˜—K˜K˜—K˜—K˜š œ œ6œ˜]šœ˜š‘œœ˜ ˜Kšœ˜K˜Kšœ0˜0Kšœ#˜#Kšœ0˜0K˜KšœE˜EKšœK˜KKšœ+˜+—K˜—K˜K˜—K˜—K˜š  œ œ:œ˜Všœ˜KšœΊ™ΊK˜Kšœ œ˜K˜šœ#˜-šœ˜Kšœ9˜?šœ˜šœ+œ˜2KšœI™IK˜,—š˜Kšœ,˜,—K˜K˜*K˜H—K˜—šœ˜Kšœ9˜?šœ˜šœ+œ˜2KšœH™HK˜*—š˜Kšœ*˜*—K˜K˜*K˜J—K˜—Kšœ˜——K˜—K˜š œ œ7œ˜ašœ˜Kšœ˜K˜Kšœ˜Kšœ˜K˜K˜K˜K˜K˜K˜Kšœ™Kšœ'˜'K˜%K˜Kšœ4™4K˜Kšœ!Ÿ)˜JK˜ Kšœœ ˜*K˜Kšœ#™#Kšœ'˜'Kšœ#˜#Kšœ5˜5K˜Kšœ7˜7Kšœ=˜=Kšœ+˜+K˜Kšœ™KšœG˜Mšœ˜Kšœ7Ÿ˜HK˜FK˜7—K˜—K˜—K˜š œ œ7œ˜_šœ˜Kšœ˜K˜Kšœ˜Kšœ˜K˜K˜K˜K˜K˜K˜Kšœ™Kšœ'˜'K˜,K˜Kšœ4™4K˜Kšœ!Ÿ)˜JK˜ Kšœœ ˜*K˜Kšœ!™!Kšœ'˜'Kšœ#˜#Kšœ5˜5K˜Kšœ7˜7Kšœ=˜=Kšœ+˜+K˜Kšœ™KšœE˜Kšœ˜Kšœ7Ÿ˜GK˜BK˜7—K˜—K˜—K˜š œ œ7œ˜`šœ˜Kšœ˜K˜Kšœ˜Kšœ˜K˜K˜K˜K˜K˜K˜Kšœ(™(Kšœ'˜'Kšœ!˜!K˜KšœE™EKšœ'˜'K˜%K˜Kšœ.™.Kšœ#˜#Kšœ0˜0K™Kšœ:˜:Kšœ@˜@Kšœ+˜+K˜Kšœ=˜=KšœC˜CKšœ+˜+K˜Kšœ7Ÿ˜HK˜FK˜M—K˜—K˜š œ œ7œ˜^šœ˜Kšœ˜K˜Kšœ˜Kšœ˜K˜K˜K˜K˜!K˜K˜Kšœ(™(Kšœ'˜'Kšœ!˜!K˜KšœC™CKšœ'˜'K˜,K™Kšœ,™,Kšœ#˜#Kšœ0˜0K™Kšœ<˜˜>KšœF˜FKšœ+˜+K˜Kšœ6Ÿ˜GK˜FK˜7—K˜—K˜š œ œ-˜Jšœ˜Kšœ˜K˜Kšœ5˜5Kšœ#˜#Kšœ(˜(K˜Kšœ/˜/Kšœ5˜5Kšœ5˜5Kšœ5˜5Kšœ+˜+—K˜—K˜š œ œ-˜QKšœ˜Kšœ˜K˜Kšœ5˜5Kšœ#˜#Kšœ(˜(K˜Kšœ/˜/Kšœ5˜5Kšœ5˜5Kšœ5˜5Kšœ+˜+K˜—K˜K˜Kšœ]˜]K˜šœ.˜.šœ!˜$K˜K˜Kšœ˜K˜——K˜K˜@K˜Kšœ˜—…—d„u