PDInterpOutputViewerImpl.mesa
Copyright (C) 1984, Xerox Corporation. All rights reserved.
Michael Plass, July 3, 1985 11:12:19 am PDT
Implements a Cedar PD output device that shows the bitmap in a viewer.
DIRECTORY BitmapViewer, PDFileFormat, PDInterpBitmap, ImagerPixelMap, PDInterpOutput, ViewerClasses, Process, PDTextBitmap, String, PDQueue, IO, FS;
PDInterpOutputViewerImpl: PROGRAM
IMPORTS BitmapViewer, ImagerPixelMap, Process, PDTextBitmap, PDInterpBitmap, String, IO, FS, PDQueue
EXPORTS PDInterpOutput
= BEGIN
viewer: ViewerClasses.Viewer ← NIL;
pageMap: ImagerPixelMap.PixelMap ← ImagerPixelMap.Create[0, [0,0,0,0]];
currentStartImage: PDFileFormat.StartImage;
currentHerald: PDFileFormat.Herald;
bandNumber: NAT ← 0;
oneBandAtATime: BOOLEANFALSE;
nonStop: BOOLEANFALSE;
StartImage: PUBLIC PROC [herald: PDFileFormat.Herald, startImage: PDFileFormat.StartImage, request: PDQueue.Request]
RETURNS [PDInterpBitmap.BitmapDesc] = {
bandMap: ImagerPixelMap.PixelMap;
pageMapLines: NATIF oneBandAtATime THEN herald.bandSSize ELSE startImage.nBands*herald.bandSSize;
pageMap ← ImagerPixelMap.Create[0, [startImage.passBands*herald.bandSSize, startImage.fMinPage, pageMapLines, startImage.fSizePage]];
currentStartImage ← startImage;
currentHerald ← herald;
bandNumber ← 0;
pageMap.Clear;
bandMap ← pageMap.Clip[[startImage.passBands*herald.bandSSize, startImage.fMinPage, herald.bandSSize, startImage.fSizePage]];
RETURN [[
sOrigin: bandMap.sOrigin,
fOrigin: bandMap.fOrigin,
sMin: bandMap.sMin,
fMin: bandMap.fMin,
sSize: bandMap.sSize,
fSize: bandMap.fSize,
pointer: bandMap.refRep.pointer,
rast: bandMap.refRep.rast,
lines: bandMap.refRep.lines
]]
};
EndBand: PUBLIC PROC RETURNS [PDInterpBitmap.BitmapDesc] = {
bandMap: ImagerPixelMap.PixelMap;
bandNumber ← bandNumber + 1;
IF oneBandAtATime THEN ShowPage[];
IF oneBandAtATime THEN {pageMap ← pageMap.ShiftMap[currentHerald.bandSSize, 0]; pageMap.Clear};
bandMap ← pageMap.Clip[[(currentStartImage.passBands+bandNumber)*currentHerald.bandSSize, currentStartImage.fMinPage, currentHerald.bandSSize, currentStartImage.fSizePage]];
RETURN [[
sOrigin: bandMap.sOrigin,
fOrigin: bandMap.fOrigin,
sMin: bandMap.sMin,
fMin: bandMap.fMin,
sSize: bandMap.sSize,
fSize: bandMap.fSize,
pointer: bandMap.refRep.pointer,
rast: bandMap.refRep.rast,
lines: bandMap.refRep.lines
]]
};
ShowPage: PROC = {
IF viewer = NIL OR viewer.destroyed THEN {
viewer ← BitmapViewer.Create[info: [name: "PD page", column: left, iconic: TRUE, hscrollable: TRUE]];
};
BitmapViewer.SetBitmap[viewer, pageMap];
DO
IF viewer.destroyed OR oneBandAtATime OR nonStop THEN EXIT;
Process.Pause[Process.MsecToTicks[200]];
ENDLOOP;
};
EndImage: PUBLIC PROC [request: PDQueue.Request] = {
separator: LONG STRING ← [160];
String.Copy[separator, request.requestTime];
THROUGH [0..2) DO String.AppendChar[separator, ' ] ENDLOOP;
String.AppendString[separator, request.fileName];
THROUGH [0..2) DO String.AppendChar[separator, ' ] ENDLOOP;
String.AppendString[separator, request.requestor];
THROUGH [0..2) DO String.AppendChar[separator, ' ] ENDLOOP;
ShowPage[];
IF PDTextBitmap.fontName.length = 0 THEN IF NOT PDTextBitmap.SetFont["[Indigo]<Peach>Fonts>TimesRoman36B.ks", request.requestor, request.requestorPassword] THEN ERROR;
pageMap ← pageMap.refRep.Reshape[0, [-1-PDTextBitmap.FontAscent[], -PDTextBitmap.FontAscent[], PDTextBitmap.FontAscent[]+PDTextBitmap.FontDescent[]+2, PDTextBitmap.TextWidth[separator]+2*PDTextBitmap.FontAscent[]]];
{
bits: PDInterpBitmap.BitmapDesc ← [
sOrigin: pageMap.sOrigin,
fOrigin: pageMap.fOrigin,
sMin: pageMap.sMin,
fMin: pageMap.fMin,
sSize: pageMap.sSize,
fSize: pageMap.fSize,
pointer: pageMap.refRep.pointer,
rast: pageMap.refRep.rast,
lines: pageMap.refRep.lines
];
PDInterpBitmap.Fill[bits, [-10000, -10000, 20000, 20000], 1];
PDTextBitmap.TextToBitmap[dest: bits, string: separator, function: [and, complement]];
};
ShowPage[];
};
ReprintLastPage: PUBLIC PROC [copies: CARDINAL] = {
IF currentHerald.password # PDFileFormat.passwordValue THEN RETURN;
currentHerald.copies ← copies;
ShowPage[];
};
ReadQueue: PROC [address: LONG POINTER, nwords: CARDINAL] = TRUSTED {
stream: IO.STREAM;
stream ← FS.StreamOpen["[]<>Peach.queue", $read, ALL[FALSE] ! FS.Error => CONTINUE];
IF stream#NIL THEN {
[] ← stream.UnsafeGetBlock[[base: address, startIndex: 0, count: nwords*2]];
stream.Close;
};
};
WriteQueue: PROC [address: LONG POINTER, nwords: CARDINAL] = TRUSTED {
stream: IO.STREAMFS.StreamOpen["[]<>Peach.queue", $create];
[] ← stream.UnsafePutBlock[[base: address, startIndex: 0, count: nwords*2]];
stream.Close;
};
RegisterDisk: PROC = {PDQueue.RegisterDisk[ReadQueue, WriteQueue, 1024]};
currentHerald.password ← 0;
PDQueue.RegisterDisk[ReadQueue, WriteQueue, 1024];
END.