-- PressFontReaderJaM.mesa <<-- Written by Michael Plass on August 7, 1982 6:32 pm>> <<-- Last edit by Michael Plass on December 2, 1982 1:50 pm>> <<-- Last edit by Maureen Stone June 10, 1984 8:48:25 pm PDT>> DIRECTORY AIS, Graphics, GraphicsOps CGScreen, JaM, PressFontReader, Real, Rope, TJaMGraphics, TJaMGraphicsContexts; PressFontReaderJaM: CEDAR PROGRAM IMPORTS AIS, GraphicsOps, CGScreen, JaM, PressFontReader, Real, Rope, TJaMGraphics, TJaMGraphicsContexts = BEGIN ROPE: TYPE = Rope.ROPE; Frame: TYPE = JaM.State; fontFile: PressFontReader.Handle; font: PressFontReader.Font; OpenFontFile: PROCEDURE [f: Frame] = { fileName: ROPE _ JaM.PopRope[f]; IF fontFile # NIL THEN fontFile.Close[]; fontFile _ PressFontReader.FromFile[fileName]; font _ fontFile.FirstFont[]; }; CloseFontFile: PROCEDURE [f: Frame] = { IF fontFile # NIL THEN fontFile.Close[]; fontFile _ NIL; }; flushPathObject: Rope.ROPE _ ".flushpath"; moveToObject: Rope.ROPE _ ".movetonext"; lineToObject: Rope.ROPE _ ".lineto"; curveToObject: Rope.ROPE _ ".curveto"; drawAreaObject: Rope.ROPE _ ".draweoarea"; bboxObject: Rope.ROPE _ ".bbox"; widthObject: Rope.ROPE _ ".width"; translateObject: Rope.ROPE _ ".translate"; ExecuteRope: PROC [f: Frame, r: Rope.ROPE] = { JaM.ExecuteRope[f, r! JaM.Stop => CONTINUE]}; DrawSplineChar: PROCEDURE [f: Frame]= { moveToProc: PressFontReader.MoveToProc = { JaM.PushReal[f, x]; JaM.PushReal[f, y]; ExecuteRope[f, moveToObject]; }; lineToProc: PressFontReader.LineToProc = { JaM.PushReal[f, x]; JaM.PushReal[f, y]; ExecuteRope[f, lineToObject]; }; curveToProc: PressFontReader.CurveToProc = { JaM.PushReal[f, x1]; JaM.PushReal[f, y1]; JaM.PushReal[f, x2]; JaM.PushReal[f, y2]; JaM.PushReal[f, x3]; JaM.PushReal[f, y3]; ExecuteRope[f, curveToObject]; }; drawAreaProc: PressFontReader.DrawAreaProc = { ExecuteRope[f, drawAreaObject]; }; char: CHAR_ 0C+JaM.PopInt[f]; info: PressFontReader.CharInfo _ PressFontReader.GetCharInfo[font, char]; JaM.PushReal[f, info.widthX]; JaM.PushReal[f, info.widthY]; ExecuteRope[f, widthObject]; JaM.PushReal[f, info.minX]; JaM.PushReal[f, info.minY]; JaM.PushReal[f, info.maxX]; JaM.PushReal[f, info.maxY]; ExecuteRope[f, bboxObject]; ExecuteRope[f, flushPathObject]; PressFontReader.GetCharOutline[font, char, moveToProc, lineToProc, curveToProc, drawAreaProc]; JaM.PushReal[f, info.widthX]; JaM.PushReal[f, info.widthY]; ExecuteRope[f, translateObject]; }; DrawRasterChars: PROCEDURE [f: Frame]= { Paint: PROCEDURE [context: Graphics.Context] = { FOR i: NAT IN [0..rope.Length[]) DO PressFontReader.DrawCharRaster[context, font, rope.Fetch[i]]; ENDLOOP }; rope: ROPE _ PopRope[f]; TJaMGraphics.Painter[Paint]; }; DrawChars: PROCEDURE [f: Frame] = { Paint: PROCEDURE [context: Graphics.Context] = { FOR i: NAT IN [0..rope.Length[]) DO PressFontReader.DrawChar[context, font, rope.Fetch[i]]; ENDLOOP }; rope: ROPE _ PopRope[f]; TJaMGraphics.Painter[Paint]; }; CharDimensions: PROCEDURE [f: Frame]= { char: CHAR _ 0C+JaM.PopInt[f]; info: PressFontReader.CharInfo _ PressFontReader.GetCharInfo[font, char]; JaM.PushReal[f, info.widthX]; JaM.PushReal[f, info.widthY]; JaM.PushReal[f, info.minX]; JaM.PushReal[f, info.minY]; JaM.PushReal[f, info.maxX]; JaM.PushReal[f, info.maxY]; }; AllocateBitmap: PROCEDURE [f: Frame] = { <<-- allocates a bitmap large enough to use for the current raster font.>> minX, minY, maxX, maxY: REAL _ 0; scale: REAL _ (font.info.size*font.info.xRes)/0.0254; height, width: NAT; FOR char: CHAR IN [font.info.bc..font.info.ec] DO info: PressFontReader.CharInfo _ PressFontReader.GetCharInfo[font, char]; minX _ MIN[minX, info.minX]; minY _ MIN[minY, info.minY]; maxX _ MAX[maxX, info.maxX]; maxY _ MAX[maxY, info.maxY]; ENDLOOP; height _ Real.RoundI[(maxY-minY)*scale] + 3; width _ Real.RoundI[(maxX-minX)*scale] + 3; orgX _ Real.RoundI[-minX*scale] + 1; orgY _ Real.RoundI[-minY*scale] + 1; bitmap _ GraphicsOps.NewBitmap[width, height]; bitmapDescriptor _ DescriptorFor[bitmap]; }; DrawBitmap: PROCEDURE [f: Frame] = { Paint: PROCEDURE [context: Graphics.Context] = { GraphicsOps.DrawBitmap[self: context, bitmap: bitmap, w: bitmap.width, h: bitmap.height, x: 0, y: 0, xorigin: 0, yorigin: bitmap.height]; }; TJaMGraphics.Painter[Paint]; }; BitMapContext: PROCEDURE RETURNS[Graphics.Context] = { bitmapContext _ GraphicsOps.NewContextFromBitmap[bitmap]; RETURN [bitmapContext]; }; UseBitmap: PROCEDURE [f: Frame] = { TJaMGraphicsContexts.AddContext[f, BitMapContext, $PressFontReaderJaM, TRUE, TRUE]; TJaMGraphicsContexts.DisableViewer[f]; }; UseScreen: PROCEDURE [f: Frame] = { TJaMGraphicsContexts.DisableContext[f, $PressFontReaderJaM]; TJaMGraphicsContexts.EnableViewer[f]; }; GetBit: PROCEDURE [f: Frame] = { i, j: NAT; j _ JaM.PopInt[f]; i _ JaM.PopInt[f]; JaM.PushInt[f, bitmapDescriptor[i][j]]; }; StoreBit: PROCEDURE [f: Frame] = { i, j: NAT; j _ JaM.PopInt[f]; i _ JaM.PopInt[f]; bitmapDescriptor[i][j] _ JaM.PopInt[f]; }; BitmapOrigin: PROCEDURE [f: Frame] = { JaM.PushInt[f, orgX]; JaM.PushInt[f, orgY]; }; BitmapSize: PROCEDURE [f: Frame] = { JaM.PushInt[f, bitmap.width]; JaM.PushInt[f, bitmap.height]; }; orgX, orgY: NAT _ 0; bitmap: GraphicsOps.BitmapRef; bitmapDescriptor: BitmapDescriptor; bitmapContext: Graphics.Context; BitmapDescriptor: PUBLIC TYPE = REF READONLY BitmapDescriptorRec; BitmapDescriptorRec: PUBLIC TYPE = RECORD[ bitmapRef: GraphicsOps.BitmapRef, lines: SEQUENCE height: NAT OF LONG DESCRIPTOR FOR PACKED ARRAY OF [0..1] ]; DescriptorFor: PUBLIC PROCEDURE [bitmap: GraphicsOps.BitmapRef] RETURNS [BitmapDescriptor] = { bitmapDescriptor: REF BitmapDescriptorRec _ NEW[BitmapDescriptorRec[bitmap.height]]; raster: NAT _ bitmap.raster; p: LONG POINTER _ LOOPHOLE[bitmap.base]; IF p=NIL THEN [base: p, raster: raster] _ CGScreen.Bits[]; FOR i:NAT IN [0..bitmap.height) DO bitmapDescriptor[i] _ DESCRIPTOR[p, bitmap.width]; p _ p + raster; ENDLOOP; bitmapDescriptor.bitmapRef _ bitmap; RETURN[bitmapDescriptor]; }; DescBase: PUBLIC PROCEDURE [d: LONG DESCRIPTOR FOR PACKED ARRAY OF [0..1]] RETURNS [LONG POINTER] = {RETURN[BASE[d]]}; DescLength: PUBLIC PROCEDURE [d: LONG DESCRIPTOR FOR PACKED ARRAY OF [0..1]] RETURNS [INT] = {RETURN[LENGTH[d]]}; WriteAISTemp: PROCEDURE [f: Frame] = { aisFile: AIS.FRef; aisWindow: AIS.WRef; raster: AIS.RasterPart; raster.scanCount _ bitmap.height; raster.scanLength _ bitmap.width; raster.scanMode _ rd; raster.bitsPerPixel _ 1; raster.linesPerBlock _ -1; raster.paddingPerBlock _ 0; aisFile _ AIS.CreateFile[name: "AISTemp.ais", raster: @raster, overwrite: TRUE]; aisWindow _ AIS.OpenWindow[aisFile]; FOR i: NAT IN [0..bitmap.height) DO FOR j: NAT IN [0..bitmap.width) DO AIS.WriteSample[aisWindow, 1-bitmapDescriptor[i][j], i, j]; ENDLOOP ENDLOOP; AIS.CloseWindow[aisWindow]; AIS.CloseFile[aisFile]; }; Init: JaM.InitProc = { JaM.Register[State, "PressFont.Open", OpenFontFile]; JaM.Register[State, "PressFont.Close", CloseFontFile]; JaM.Register[State, "PressFont.DrawSplineChar", DrawSplineChar]; JaM.Register[State, "PressFont.DrawRasterChars", DrawRasterChars]; JaM.Register[State, "PressFont.DrawChars", DrawChars]; JaM.Register[State, "PressFont.CharDimensions", CharDimensions]; JaM.Register[State, "PressFont.AllocateBitmap", AllocateBitmap]; JaM.Register[State, "PressFont.DrawBitmap", DrawBitmap]; JaM.Register[State, "PressFont.GetBit", GetBit]; JaM.Register[State, "PressFont.StoreBit", StoreBit]; JaM.Register[State, "PressFont.UseBitmap", UseBitmap]; JaM.Register[State, "PressFont.UseScreen", UseScreen]; JaM.Register[State, "PressFont.WriteAISTemp", WriteAISTemp]; JaM.Register[State, "PressFont.BitmapOrigin", BitmapOrigin]; JaM.Register[State, "PressFont.BitmapSize", BitmapSize]; }; JaM.RegisterInit["PressFontReaderJaM",Init]; END.