-- 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
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]𡤌 t.length ← t.length+1; RETURN[FALSE]};
t: REF TEXTNEW[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] = {
-- 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 ← 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 POINTERLOOPHOLE[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.