<> <> <> DIRECTORY Vector2, Imager, ImagerFont, Rope, ImagerPath, Interpress, ImagerColor, ImagerViewer, ImagerInterpress, ImagerPixelArray, ImagerColorOperator, ImagerTransformation; ImagerExamplesImpl: CEDAR PROGRAM IMPORTS Imager, ImagerColor, ImagerFont, ImagerPath, ImagerViewer, ImagerInterpress, ImagerPixelArray, ImagerColorOperator, ImagerTransformation ~ BEGIN Context: TYPE ~ Imager.Context; VEC: TYPE ~ Vector2.VEC; Font: TYPE ~ ImagerFont.Font; ROPE: TYPE ~ Rope.ROPE; helveticaI: Imager.Font ~ ImagerFont.Scale[ImagerFont.Find["xerox/pressfonts/helvetica-mir"], 0.01]; timesRomanBI: Imager.Font ~ ImagerFont.Scale[ImagerFont.Find["xerox/pressfonts/timesroman-bir"], 0.01]; <Fonts>Xerox>* The filename extension (.sd, .ks, etc.) of these files tell the Imager what kind of file to expect and are not part of the font name. The PressFonts end in three-letter suffixes to designate the face, i.e., -mrr Medium Roman -mir Medium Italic -brr Bold Roman -bir Bold Italic (The third letter can designate condensed or expanded fonts, but we don't have any of these.) A PressFont is by default one unit high in whatever coordinate system your program is working in; in this case, we will be working in the initial meters coordinate system, so we scale it by a factor of 0.01 to get a font 1 cm high.>> <<>> <> <<>> <> <<>> Text: PROC [context: Imager.Context] ~ { <> Imager.SetFont[context, timesRomanBI]; Imager.SetXY[context, [0.02, 0.0375]]; Imager.ShowRope[context, "Here is some "]; Imager.SetFont[context, helveticaI]; Imager.ShowRope[context, "text"]; }; Rectangles: PROC [context: Imager.Context] ~ { <> Imager.MaskRectangle[context, [x: 0.04, y: 0.06, w: 0.03, h: 0.01]]; Imager.MaskBox[context, [xmin: 0.04, ymin: 0.06, xmax: 0.07, ymax: 0.07]]; {proc: PROC ~ { Imager.ScaleT[context, 0.01]; Imager.MaskRectangleI[context, 4, 6, 3, 1]; }; Imager.DoSaveAll[context, proc]}; }; Path: Imager.PathProc ~ { <> moveTo[[0,0]]; lineTo[[100, 0]]; arcTo[[70.7, 70.7], [0,100]]; moveTo[[60, 60]]; lineTo[[100, 80]]; lineTo[[90, 100]]; }; Fills: PROC [context: Imager.Context] ~ { <> p: Vector2.VEC _ [0,0]; proc: PROC ~ { Imager.ScaleT[context, 0.0005]; Imager.TranslateT[context, p]; Imager.MaskFill[context, Path]; }; p _ [200, 75]; Imager.DoSave[context, proc]; }; joints: Imager.StrokeJoint _ mitered; Strokes: PROC [context: Imager.Context] ~ { <> p: Vector2.VEC _ [0,0]; closed: BOOL _ FALSE; proc: PROC ~ { Imager.ScaleT[context, 0.0005]; Imager.TranslateT[context, p]; Imager.MaskStroke[context, Path, closed]; }; p _ [50, 200]; Imager.SetStrokeJoint[context, joints]; Imager.SetStrokeWidth[context, 8]; Imager.SetStrokeEnd[context, butt]; Imager.DoSave[context, proc]; p _ [200, 200]; Imager.SetStrokeEnd[context, round]; Imager.DoSave[context, proc]; p _ [50, 325]; Imager.SetStrokeEnd[context, square]; Imager.DoSave[context, proc]; p _ [200, 325]; closed _ TRUE; Imager.DoSave[context, proc]; }; Bits: PROC [context: Imager.Context] ~ { <> <> <> <> proc: PROC ~ { o: [0..1] ~ 0; x, X: [0..1] ~ 1; <> bits: ARRAY [0..10) OF PACKED ARRAY [0..16) OF [0..1] _ [ [ x, x, x, x, o, o, o, o, o, o, o, o, o, o, o, x ], [ x, x, x, x, o, o, o, o, o, o, o, o, o, o, o, x ], [ x, X, o, o, o, o, o, o, o, o, o, o, o, o, o, x ], [ x, o, x, x, x, o, o, x, o, o, x, o, o, o, o, x ], [ x, o, x, o, o, x, o, o, o, x, x, x, o, o, o, x ], [ o, o, x, o, x, o, x, x, o, o, x, o, o, x, x, o ], [ o, o, x, x, x, o, o, x, o, o, x, o, x, o, o, o ], [ o, o, x, o, o, x, o, x, o, o, x, o, o, x, o, o ], [ o, o, x, o, o, x, o, x, o, o, x, o, o, o, x, o ], [ o, o, x, x, x, o, x, x, x, o, o, x, x, x, x, o ] ]; Imager.ScaleT[context, 0.0254/72]; -- 72-per-inch points; Imager.TranslateT[context, [72, (11-1)*72]]; -- origin at 1 inch in from top and left margins Imager.ScaleT[context, 5]; -- talk in 5 point units Imager.MaskRectangleI[context, 0, 0, 3, -2]; -- put down a rectangle as a reference TRUSTED { base: LONG POINTER ~ @bits; Imager.MaskBits[ context: context, base: base, wordsPerLine: SIZE[PACKED ARRAY [0..16) OF [0..1]], sMin: 2, -- The number of lines to skip (from the top) fMin: 1, -- The number of bits to skip (from the left) sSize: 8, -- The number of lines to use fSize: 14, -- The number of bits to use tx: 3, ty: -2 -- tells where the reference point of the bitmap goes, in client coordinates ]; }; }; Imager.DoSave[context, proc]; }; Masks: PROC [context: Imager.Context] ~ { <> <Plass>6.0>ImagerExamples.ip!13 scale: 0.2>> <<>> <<(Say "ArtworkInterpress on" to a command tool if the above just looks like text).>> font: Font ~ ImagerFont.Find["xerox/pressfonts/helvetica-brr"]; inner1: PROC ~ { rope: ROPE ~ "Mask Examples"; scaledFont: Font ~ ImagerFont.Scale[font, 0.3]; ropeWidth: VEC ~ ImagerFont.RopeWidth[scaledFont, rope]; Imager.ScaleT[context, 0.0254]; Imager.SetColor[context, Imager.black]; Imager.SetXY[context, [8.5/2-ropeWidth.x/2, 9.5]]; Imager.SetFont[context, scaledFont]; Imager.ShowRope[context, rope]; }; inner2: PROC ~ { Imager.TranslateT[context, [8.5*0.0254/2-0.0005*(50+300)/2, 0]]; Text[context]; Rectangles[context]; Fills[context]; Strokes[context]; Bits[context]; }; Imager.DoSave[context, inner1]; Imager.DoSave[context, inner2]; }; TriangleX: PROC [context: Context, p0, p1, p2: VEC, w: REAL] ~ { <> t: ImagerPath.Trajectory _ ImagerPath.MoveTo[p0]; t _ ImagerPath.LineTo[t, p1]; t _ ImagerPath.LineTo[t, p2]; Imager.SetStrokeWidth[context, w]; Imager.MaskStrokeTrajectory[context: context, trajectory: t, closed: TRUE]; }; Triangle: PROC [context: Context, p0, p1, p2: VEC, w: REAL] ~ { <> Path: Imager.PathProc ~ {moveTo[p0]; lineTo[p1]; lineTo[p2]}; Imager.SetStrokeWidth[context, w]; Imager.MaskStroke[context: context, path: Path, closed: TRUE]; }; TriangleSpiral: PROC [context: Context, p0, p1, p2, center: VEC, w: REAL] ~ { <> inner: PROC ~ { Imager.TranslateT[context, center]; FOR i: NAT IN [0..10) DO Triangle[context, p0, p1, p2, w]; Imager.RotateT[context, -40]; Imager.ScaleT[context, 0.8]; w _ w/0.8; ENDLOOP; }; Imager.DoSave[context, inner]; }; TitledSpiral: PROC [context: Imager.Context] ~ { <> <Plass>6.0>ImagerExamples.ip!1 scale: 0.2>> <<>> font: Font ~ ImagerFont.Find["xerox/pressfonts/helvetica-brr"]; inner: PROC ~ { rope: ROPE ~ "Spiral of Triangles"; scaledFont: Font ~ ImagerFont.Scale[font, 0.3]; ropeWidth: VEC ~ ImagerFont.RopeWidth[scaledFont, rope]; Imager.ScaleT[context, 0.0254]; Imager.SetColor[context, Imager.black]; TriangleSpiral[context, [1.0, 0.25], [1.25, -0.5], [1.75, 2.0], [8.5/2, 11.0/2], 0.05]; Imager.SetXY[context, [8.5/2-ropeWidth.x/2, 9.5]]; Imager.SetFont[context, scaledFont]; Imager.ShowRope[context, rope]; }; Imager.DoSave[context, inner]; }; ColorSpiral: PROC [context: Imager.Context] ~ { <> <<>> inner: PROC ~ { w: REAL _ 0.1; Imager.ScaleT[context, 0.0254]; Imager.TranslateT[context, [8.5/2, 11.0/2]]; FOR i: NAT IN [0..10) DO hsv: ImagerColor.HSV ~ [H: i/9.0, S: 0.8, V: 1.0]; rgb: ImagerColor.RGB ~ ImagerColor.RGBFromHSV[hsv]; Imager.SetColor[context, ImagerColor.ColorFromRGB[rgb]]; Triangle[context, [1.0, 0.25], [1.25, -0.5], [1.75, 2.0], w]; Imager.RotateT[context, -40]; Imager.ScaleT[context, 0.8]; w _ w/0.8; ENDLOOP; }; Imager.DoSave[context, inner]; }; rgbLinear: Imager.ColorOperator ~ ImagerColorOperator.RGBLinearColorModel[255]; Drip: PROC [context: Imager.Context] ~ { inner: PROC ~ { Imager.ScaleT[context, 0.0254/72]; Imager.SetSampledColor[context: context, pa: dripPA, m: ImagerTransformation.Scale[2], colorOperator: rgbLinear]; Imager.ScaleT[context, 72]; Imager.MaskBox[context, [1, 1, 7.5, 10]]; }; Imager.DoSave[context, inner]; }; dripPA: Imager.PixelArray _ ImagerPixelArray.Join3AIS["Umbrella-red.ais", "Umbrella-grn.ais", "Umbrella-blu.ais"]; Run: PROC ~ { viewerContext: Context _ ImagerViewer.Create[[name: "Imager Example", column: left, iconic: FALSE], meters]; <> interpress: ImagerInterpress.Ref _ ImagerInterpress.Create["ImagerExamples.ip"]; <> ImagerInterpress.DeclareColorOperator[interpress, rgbLinear]; ImagerInterpress.DeclarePixelArray[interpress, dripPA]; <> joints _ mitered; ImagerViewer.Erase[viewerContext]; Masks[viewerContext]; ImagerInterpress.DoPage[interpress, Masks]; joints _ round; ImagerViewer.Erase[viewerContext]; Masks[viewerContext]; ImagerInterpress.DoPage[interpress, Masks]; ImagerViewer.Erase[viewerContext]; TitledSpiral[viewerContext]; ImagerInterpress.DoPage[interpress, TitledSpiral]; ImagerViewer.Erase[viewerContext]; ColorSpiral[viewerContext]; ImagerInterpress.DoPage[interpress, ColorSpiral]; ImagerViewer.Erase[viewerContext]; Drip[viewerContext]; ImagerInterpress.DoPage[interpress, Drip]; ImagerInterpress.Close[interpress]; }; END.