-- PressFontReaderJaM.mesa DIRECTORY AIS, Graphics, GraphicsOps, CGScreen, JaMBasic, JaMInternal, JaMOps, PressFontReader, Real, Rope, TJaMGraphics, TJaMGraphicsContexts; PressFontReaderJaM: PROGRAM IMPORTS AIS, GraphicsOps, CGScreen, JaMOps, PressFontReader, Real, Rope, TJaMGraphics, TJaMGraphicsContexts = BEGIN ROPE: TYPE = Rope.ROPE; Frame: TYPE = JaMInternal.Frame; fontFile: PressFontReader.Handle; font: PressFontReader.Font; PopRope: PROCEDURE [f: Frame] RETURNS [rope: ROPE] = { s: string JaMBasic.Object _ JaMOps.PopString[f.opstk]; C: PROC[c: CHAR] RETURNS [BOOLEAN] = {t[t.length]_c; t.length _ t.length+1; RETURN[FALSE]}; t: REF TEXT _ NEW[TEXT[s.length]]; t.length _ 0; JaMOps.StringForAll[s, C]; rope _ Rope.FromRefText[t]; }; PushRope: PROCEDURE [f: Frame, rope: ROPE] = { JaMOps.Push[ f.opstk, JaMOps.MakeString[LOOPHOLE[rope.ToRefText[], LONG STRING]] ]; }; OpenFontFile: PROCEDURE [f: Frame] = { fileName: ROPE _ 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: JaMBasic.Object _ JaMOps.MakeName[".flushpath"L]; moveToObject: JaMBasic.Object _ JaMOps.MakeName[".movetonext"L]; lineToObject: JaMBasic.Object _ JaMOps.MakeName[".lineto"L]; curveToObject: JaMBasic.Object _ JaMOps.MakeName[".curveto"L]; drawAreaObject: JaMBasic.Object _ JaMOps.MakeName[".draweoarea"L]; bboxObject: JaMBasic.Object _ JaMOps.MakeName[".bbox"L]; widthObject: JaMBasic.Object _ JaMOps.MakeName[".width"L]; translateObject: JaMBasic.Object _ JaMOps.MakeName[".translate"L]; DrawSplineChar: PROCEDURE [f: Frame]= { moveToProc: PressFontReader.MoveToProc = { JaMOps.PushReal[f.opstk, x]; JaMOps.PushReal[f.opstk, y]; JaMOps.Execute[f, moveToObject]; }; lineToProc: PressFontReader.LineToProc = { JaMOps.PushReal[f.opstk, x]; JaMOps.PushReal[f.opstk, y]; JaMOps.Execute[f, lineToObject]; }; curveToProc: PressFontReader.CurveToProc = { JaMOps.PushReal[f.opstk, x1]; JaMOps.PushReal[f.opstk, y1]; JaMOps.PushReal[f.opstk, x2]; JaMOps.PushReal[f.opstk, y2]; JaMOps.PushReal[f.opstk, x3]; JaMOps.PushReal[f.opstk, y3]; JaMOps.Execute[f, curveToObject]; }; drawAreaProc: PressFontReader.DrawAreaProc = { JaMOps.Execute[f, drawAreaObject]; }; char: CHAR_ 0C+JaMOps.PopInteger[f.opstk]; info: PressFontReader.CharInfo _ PressFontReader.GetCharInfo[font, char]; JaMOps.PushReal[f.opstk, info.widthX]; JaMOps.PushReal[f.opstk, info.widthY]; JaMOps.Execute[f, widthObject]; JaMOps.PushReal[f.opstk, info.minX]; JaMOps.PushReal[f.opstk, info.minY]; JaMOps.PushReal[f.opstk, info.maxX]; JaMOps.PushReal[f.opstk, info.maxY]; JaMOps.Execute[f, bboxObject]; JaMOps.Execute[f, flushPathObject]; PressFontReader.GetCharOutline[font, char, moveToProc, lineToProc, curveToProc, drawAreaProc]; JaMOps.PushReal[f.opstk, info.widthX]; JaMOps.PushReal[f.opstk, info.widthY]; JaMOps.Execute[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+JaMOps.PopInteger[f.opstk]; info: PressFontReader.CharInfo _ PressFontReader.GetCharInfo[font, char]; JaMOps.PushReal[f.opstk, info.widthX]; JaMOps.PushReal[f.opstk, info.widthY]; JaMOps.PushReal[f.opstk, info.minX]; JaMOps.PushReal[f.opstk, info.minY]; JaMOps.PushReal[f.opstk, info.maxX]; JaMOps.PushReal[f.opstk, info.maxY]; }; AllocateBitmap: PROCEDURE [f: Frame] = { 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 _ JaMOps.PopInteger[f.opstk]; i _ JaMOps.PopInteger[f.opstk]; JaMOps.PushInteger[f.opstk, bitmapDescriptor[i][j]]; }; StoreBit: PROCEDURE [f: Frame] = { i, j: NAT; j _ JaMOps.PopInteger[f.opstk]; i _ JaMOps.PopInteger[f.opstk]; bitmapDescriptor[i][j] _ JaMOps.PopInteger[f.opstk]; }; BitmapOrigin: PROCEDURE [f: Frame] = { JaMOps.PushInteger[f.opstk, orgX]; JaMOps.PushInteger[f.opstk, orgY]; }; BitmapSize: PROCEDURE [f: Frame] = { JaMOps.PushInteger[f.opstk, bitmap.width]; JaMOps.PushInteger[f.opstk, 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]; }; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.Open", OpenFontFile]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.Close", CloseFontFile]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.DrawSplineChar", DrawSplineChar]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.DrawRasterChars", DrawRasterChars]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.DrawChars", DrawChars]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.CharDimensions", CharDimensions]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.AllocateBitmap", AllocateBitmap]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.DrawBitmap", DrawBitmap]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.GetBit", GetBit]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.StoreBit", StoreBit]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.UseBitmap", UseBitmap]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.UseScreen", UseScreen]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.WriteAISTemp", WriteAISTemp]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.BitmapOrigin", BitmapOrigin]; JaMOps.RegisterExplicit[JaMOps.defaultFrame, "PressFont.BitmapSize", BitmapSize]; END. Ύ-- Written by Michael Plass on August 7, 1982 6:32 pm -- Last edit by Michael Plass on December 2, 1982 1:50 pm -- allocates a bitmap large enough to use for the current raster font. Κύ– "Mesa" style˜JšΟcœ˜Jš5™5Jšœ)™9JšΟk œ†˜šœž˜Jšžœd˜kJšœž˜Jšžœžœžœ˜Jšœžœ˜ Jšœ!˜!Jšœ˜procšΟnœž œ žœžœ˜6Jšœ6˜6š žœžœžœžœžœ˜$Jšœ'žœžœ˜6—Jš œžœžœžœžœ ˜"J˜ Jšœžœ˜J˜J˜—šŸœž œžœ˜.˜ J˜Jšœžœžœžœ˜:J˜—J˜—šŸ œž œ˜&Jšœ žœ˜Jšžœ žœžœ˜(Jšœ.˜.Jšœ˜J˜—šŸ œž œ˜'Jšžœ žœžœ˜(Jšœ žœ˜J˜—KšœB˜BJšœ@˜@Jšœ<˜˜>JšœB˜BJšœ8˜8Jšœ:˜:JšœB˜BšŸœž œ˜'šœ*˜*J˜J˜Jšœ ˜ Jšœ˜—šœ*˜*J˜J˜Jšœ ˜ Jšœ˜—šœ,˜,J˜J˜J˜J˜J˜J˜Jšœ!˜!Jšœ˜—šœ.˜.Jšœ"˜"Jšœ˜—Jšœžœ ˜*JšœI˜IJšœ&˜&Jšœ&˜&Jšœ˜Jšœ$˜$Jšœ$˜$Jšœ$˜$Jšœ$˜$Jšœ˜Jšœ#˜#Jšœ^˜^Jšœ&˜&Jšœ&˜&Jšœ#˜#Jšœ˜—šŸœž œ˜(šŸœž œ ˜0šžœžœž˜#Jšœ=˜=Jšž˜—J˜—Jšœžœ˜Jšœ˜Jšœ˜—šŸ œž œ˜#šŸœž œ ˜0šžœžœž˜#Jšœ7˜7Jšž˜—J˜—Jšœžœ˜Jšœ˜J˜—šŸœž œ˜'Jšœžœ!˜+JšœI˜IJšœ&˜&Jšœ&˜&Jšœ$˜$Jšœ$˜$Jšœ$˜$Jšœ$˜$Jšœ˜—šŸœž œ˜(JšF™FJšœžœ˜!Jšœžœ*˜5Jšœžœ˜šžœžœžœž˜1JšœI˜IJšœžœ˜Jšœžœ˜Jšœžœ˜Jšœžœ˜Jšžœ˜—Jšœ,˜,Jšœ+˜+Jšœ$˜$Jšœ$˜$Jšœ.˜.Jšœ)˜)J˜—šŸ œž œ˜$šŸœž œ ˜0Jšœ‰˜‰J˜—Jšœ˜J˜—šŸ œž œžœ˜6Jšœ9˜9Jšžœ˜Jšœ˜—šŸ œž œ˜#JšœGžœžœ˜SJšœ&˜&J˜—šŸ œž œ˜#Jšœ<˜