<> <> <> <> <> <> 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.