SlatePrintingImpl.mesa
Copyright Ó 1993 by Xerox Corporation. All rights reserved.
Christian Jacobi, February 24, 1993 6:44 pm PST
Christian Jacobi, August 16, 1993 12:38 pm PDT
DIRECTORY
CommanderOps,
Imager,
ImagerTransformation,
IO,
PropList,
Rope,
SlateControls,
SlateIO,
Slate,
Xl,
XlColorAccess,
XTk,
XTkWidgets;
SlatePrintingImpl:
CEDAR
MONITOR
IMPORTS CommanderOps, ImagerTransformation, IO, PropList, Rope, SlateControls, SlateIO, Slate, Xl, XlColorAccess, XTk, XTkWidgets ~
BEGIN
Widget: TYPE = XTk.Widget;
FullScaleTrans:
PROC []
RETURNS [trans: Imager.Transformation] = {
trans ¬ ImagerTransformation.Rotate[90];
trans ¬ ImagerTransformation.PostScale[trans, 72.0/300.0*5.0];
-- Scale so that pixels on screen are integer number of pixel on printer
-- 72 = pixel/inch on screen
-- 300 = pixel/inch on some printers e.g. snoball
-- 5 = nice integral factor blowing picture up only a little
trans ¬ ImagerTransformation.PostTranslate[trans, [x: 0.0254*8.5-0.004, y: 0.004]];
-- Center on page
-- 0.0254*8.5-0.004 translate 8+1/2 inch to match page width, left 4 mm
-- 0.004 up 4 mm from page border
};
FitNiceTrans:
PROC []
RETURNS [trans: Imager.Transformation] = {
trans ¬ ImagerTransformation.Rotate[90];
trans ¬ ImagerTransformation.PostScale[trans, 72.0/300.0*4.0];
-- Scale so that pixels on screen are integer number of pixel on printer
-- 72 = pixel/inch on screen
-- 300 = pixel/inch on some printers e.g. snoball
-- 4 = nice integral factor blowing picture up only a little
trans ¬ ImagerTransformation.PostTranslate[trans, [x: 0.0254*8.5-0.0254, y: 0.0254]];
-- Center on page
-- 0.0254*8.5 translate 8+1/2 inch to match page width, left 1 inch
-- 0.0254 up 1 inch from page border
};
CallName:
PROC [callData:
REF]
RETURNS [Rope.
ROPE] = {
nameWidget: Widget ~ NARROW[callData];
name: Rope.ROPE ~ XTkWidgets.GetText[nameWidget];
RETURN [name];
};
IPPrintAllButtonHit: XTkWidgets.ButtonHitProcType = {
trans: Imager.Transformation ¬ NIL;
instance: Slate.Instance ¬ NARROW[registerData];
printerName: Rope.ROPE ¬ CallName[callData];
trans ¬ FitNiceTrans[];
SlateIO.IPPrint[pages: Slate.CurrentListOfPages[instance.session], printerName: printerName, log: instance.log, server: widget.connection, trans: trans]
};
IPPrintPageHit: XTkWidgets.ButtonHitProcType = {
trans: Imager.Transformation ¬ NIL;
instance: Slate.Instance ¬ NARROW[registerData];
printerName: Rope.ROPE ¬ CallName[callData];
trans ¬ FitNiceTrans[];
SlateIO.IPPrint[pages: LIST[Slate.ActivePage[instance.session]], printerName: printerName, log: instance.log, server: widget.connection, trans: trans]
};
PSPrintAllButtonHit: XTkWidgets.ButtonHitProcType = {
trans: Imager.Transformation ¬ NIL;
instance: Slate.Instance ¬ NARROW[registerData];
printerName: Rope.ROPE ¬ CallName[callData];
trans ¬ FitNiceTrans[];
SlateIO.PSPrint[pages: Slate.CurrentListOfPages[instance.session], printerName: printerName, log: instance.log, server: widget.connection, trans: trans]
};
CreatePrintingWidget: Slate.EventProc = {
shell: Widget ¬ XTkWidgets.CreateShell[
className: $SlateControl,
windowHeader: "Slate Printing",
packageName: "SlateControl",
shortName: "Slate Control"
];
pnField: Widget ¬ XTkWidgets.CreateLabeledField[label: "printer:", init: "Snoball"];
printPageWidget: Widget ~ XTkWidgets.CreateButton[
text: "PrintPage", hitProc: IPPrintPageHit, registerData: instance, callData: pnField
];
printAll: Widget ~ XTkWidgets.CreateButton[
text: "IP-PrintAll", hitProc: IPPrintAllButtonHit, registerData: instance, callData: pnField
];
printPSAll: Widget ~ XTkWidgets.CreateButton[
text: "PS-PrintAll", hitProc: PSPrintAllButtonHit, registerData: instance, callData: pnField
];
xCont: Widget ~ XTkWidgets.CreateXStack[[], LIST[printAll, printPSAll, printPageWidget]];
topYCont: Widget ← XTkWidgets.CreateYStack[[],LIST[pnField, xCont]];
XTkWidgets.SetShellChild[shell, topYCont];
XTkWidgets.BindScreenShell[shell, callData ! Xl.connectionNotCreated => {
IO.PutRope[instance.log, Rope.Concat["Failed: ", why.reason]];
GOTO oops
}];
SlateControls.LimitLifetime[shell, instance];
XTkWidgets.RealizeShell[shell];
EXITS oops => {}
};
WritePageButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
fileName: Rope.ROPE ¬ CallName[callData];
SlateIO.WriteSlateFile[pages: LIST[Slate.ActivePage[instance.session]], fileName: fileName, log: instance.log, server: widget.connection]
};
WriteAllButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
fileName: Rope.ROPE ¬ CallName[callData];
SlateIO.WriteSlateFile[pages: Slate.CurrentListOfPages[instance.session], fileName: fileName, log: instance.log, server: widget.connection]
};
WriteIPPageButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
fileName: Rope.ROPE ¬ CallName[callData];
SlateIO.WriteIPFile[pages: LIST[Slate.ActivePage[instance.session]], fileName: fileName, log: instance.log, server: widget.connection]
};
WriteIPAllButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
fileName: Rope.ROPE ¬ CallName[callData];
SlateIO.WriteIPFile[pages: Slate.CurrentListOfPages[instance.session], fileName: fileName, log: instance.log, server: widget.connection]
};
WritePSPageButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
fileName: Rope.ROPE ¬ CallName[callData];
SlateIO.WritePSFile[pages: LIST[Slate.ActivePage[instance.session]], fileName: fileName, log: instance.log, server: widget.connection]
};
WritePSAllButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
fileName: Rope.ROPE ¬ CallName[callData];
SlateIO.WritePSFile[pages: Slate.CurrentListOfPages[instance.session], fileName: fileName, log: instance.log, server: widget.connection]
};
ReadButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
mapEntries: REF;
fileName: Rope.ROPE ¬ CallName[callData];
mapEntries ¬ GetColorInfo[instance].mapEntries;
SlateIO.ReadSlateFile[instance.session, fileName, instance.log, mapEntries];
};
ReadIPFileButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
bpp: NAT; mapEntries: REF;
fileName: Rope.ROPE ¬ CallName[callData];
[bpp, mapEntries] ¬ GetColorInfo[instance];
SlateIO.ReadIPFile[instance.session, fileName, instance.log, [0, 0], bpp, mapEntries];
};
CountPages:
PROC [pages:
LIST
OF Slate.Page]
RETURNS [n:
INT ¬ 0] = {
FOR list:
LIST
OF Slate.Page ¬ pages, list.rest
WHILE list#
NIL
DO
n ¬ n+1
ENDLOOP;
};
FancyRemovePages:
PROC [pages:
LIST
OF Slate.Page] = {
--Remove these pages from their session, except: noop if these are all pages
--This fancy exception recognizes when a read operation failed
removeCount: INT ~ CountPages[pages];
session: Slate.Session ¬ NIL;
FOR list:
LIST
OF Slate.Page ¬ pages, list.rest
WHILE (list#
NIL
AND session=
NIL)
DO
IF list.first#NIL THEN session ¬ list.first.session
ENDLOOP;
IF session#
NIL
THEN {
currentCount: INT ~ CountPages[Slate.CurrentListOfPages[session]];
IF removeCount<currentCount
THEN {
FOR list:
LIST
OF Slate.Page ¬ pages, list.rest
WHILE list#
NIL
DO
Slate.RemovePage[list.first];
ENDLOOP;
};
};
};
GetColorInfo:
PROC [instance: Slate.Instance]
RETURNS [bpp:
NAT ¬ 1, mapEntries:
REF ¬
NIL] = {
Note that mapEntries is returned when available, even on bpp=1
IsColorWidget:
PROC [w: Widget]
RETURNS [
BOOL] = {
shell: Widget ¬ XTk.RootWidget[w];
RETURN [XTk.GetWidgetProp[shell, $Color]#NIL]
};
shell: Widget ~ instance.shell;
cd: XlColorAccess.ColorData ¬ XlColorAccess.Access[shell.screenDepth.screen, 8, Xl.VisualClass.pseudoColor];
bpp ¬ IF IsColorWidget[shell] THEN 8 ELSE 1;
IF cd#NIL AND cd.hasColors THEN mapEntries ¬ cd.entries
};
ReadIPOverButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
bpp: NAT; mapEntries: REF;
fileName: Rope.ROPE ¬ CallName[callData];
pages: LIST OF Slate.Page ¬ Slate.CurrentListOfPages[instance.session];
[bpp, mapEntries] ¬ GetColorInfo[instance];
SlateIO.ReadIPFile[instance.session, fileName, instance.log, [0, 0], bpp, mapEntries];
FancyRemovePages[pages];
};
ReadOverButtonHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
fileName: Rope.ROPE ¬ CallName[callData];
pages: LIST OF Slate.Page ¬ Slate.CurrentListOfPages[instance.session];
mapEntries: REF ¬ GetColorInfo[instance].mapEntries;
SlateIO.ReadSlateFile[instance.session, fileName, instance.log, mapEntries];
FancyRemovePages[pages];
};
SetDefaultFileHit: XTkWidgets.ButtonHitProcType = {
instance: Slate.Instance ~ NARROW[registerData];
fileName: Rope.ROPE ¬ CallName[callData];
[] ¬ PropList.PutProp[instance.properties, $SafeName, fileName];
IO.PutF1[instance.log, "Default filename for safe: %g\n", IO.rope[fileName]];
};
CreateIOWidget: Slate.EventProc = {
shell: Widget ¬ XTkWidgets.CreateShell[
className: $SlateControl,
windowHeader: "Slate IO",
packageName: "SlateControl",
shortName: "Slate IO"
];
fnField: Widget ¬ XTkWidgets.CreateLabeledField[label: "file:", init: "/tmp/temp.slate"];
--
writePage: Widget ~ XTkWidgets.CreateButton[
text: "WritePage", hitProc: WritePageButtonHit, registerData: instance, callData: fnField
];
writeAl: Widget ~ XTkWidgets.CreateButton[
text: "WriteAll", hitProc: WriteAllButtonHit, registerData: instance, callData: fnField
];
read: Widget ~ XTkWidgets.CreateButton[
text: "Read", hitProc: ReadButtonHit, registerData: instance, callData: fnField
];
readOver: Widget ~ XTkWidgets.CreateButton[
text: "ReadOver", hitProc: ReadOverButtonHit, registerData: instance, callData: fnField
];
setDefaultFile: Widget ~ XTkWidgets.CreateButton[
text: "SetSafeFile", hitProc: SetDefaultFileHit, registerData: instance, callData: fnField
];
--
writeIPPage: Widget ~ XTkWidgets.CreateButton[
text: "IPWritePage", hitProc: WriteIPPageButtonHit, registerData: instance, callData: fnField
];
writeIPAll: Widget ~ XTkWidgets.CreateButton[
text: "IPWriteAll", hitProc: WriteIPAllButtonHit, registerData: instance, callData: fnField
];
readIP: Widget ~ XTkWidgets.CreateButton[
text: "IPRead", hitProc: ReadIPFileButtonHit, registerData: instance, callData: fnField
];
readIPOver: Widget ~ XTkWidgets.CreateButton[
text: "IPReadOver", hitProc: ReadIPOverButtonHit, registerData: instance, callData: fnField
];
--
writePSPage: Widget ~ XTkWidgets.CreateButton[
text: "PSWritePage", hitProc: WritePSPageButtonHit, registerData: instance, callData: fnField
];
writePSAll: Widget ~ XTkWidgets.CreateButton[
text: "PSWriteAll", hitProc: WritePSAllButtonHit, registerData: instance, callData: fnField
];
regContainer: Widget ~ XTkWidgets.CreateXStack[[], LIST[writePage, writeAl, read, readOver, setDefaultFile]];
ipContainer: Widget ~ XTkWidgets.CreateXStack[[], LIST[writeIPPage, writeIPAll, readIP, readIPOver]];
psContainer: Widget ~ XTkWidgets.CreateXStack[[], LIST[writePSPage, writePSAll]];
topYContainer: Widget ← XTkWidgets.CreateYStack[[],
LIST[fnField, regContainer, ipContainer, psContainer]
];
XTkWidgets.SetShellChild[shell, topYContainer];
XTkWidgets.BindScreenShell[shell, callData ! Xl.connectionNotCreated => {
IO.PutRope[instance.log, Rope.Concat["Failed: ", why.reason]];
GOTO oops
}];
SlateControls.LimitLifetime[shell, instance];
XTkWidgets.RealizeShell[shell];
EXITS oops => {}
};
CreateScanner: Slate.EventProc = {
out: Rope.ROPE; result: REF;
serverName: Rope.ROPE ~ Xl.ServerName[NARROW[callData]];
[out, result] ¬ CommanderOps.DoCommandRope[Rope.Cat["X11 -server ", serverName, " -- ScannerTool"], NIL, NIL];
IO.PutRope[instance.log, out];
};
CreateHandwritingRecognizer: Slate.EventProc = {
out: Rope.ROPE; result: REF;
serverName: Rope.ROPE ~ Xl.ServerName[NARROW[callData]];
[out, result] ¬ CommanderOps.DoCommandRope[Rope.Cat["X11 -server ", serverName, " -- X11Handwriting"], NIL, NIL];
IO.PutRope[instance.log, out];
};
RegisterMain:
PROC [name: Rope.
ROPE, proc: Slate.EventProc] = {
key: REF INT ¬ NEW[INT];
SlateControls.RegisterButton[$Main, name, key];
Slate.RegisterGlobalEventProc[key, proc];
};
RegisterMain["Scanning", CreateScanner];
RegisterMain["Printing", CreatePrintingWidget];
RegisterMain["IO", CreateIOWidget];
RegisterMain["Handwriting", CreateHandwritingRecognizer];
END.