DIRECTORY
Atom USING [DottedPairNode, PropList],
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Parse],
FS USING [Error],
Imager,
ImagerInterpress USING [Close, Create, DoPage, Ref],
ImagerTypefaceExtras USING [GenericCreatorProc, GenericCreatorRep, RegisterGenericCreator],
ProcessProps USING [AddPropList, GetProp],
Real USING [RoundC],
Rope USING [Cat, Equal, Find, ROPE],
Vector2 USING [VEC],
ViewerClasses USING [Viewer, ViewerRec],
ViewerOps USING [EnumerateViewers, EnumProc],
ViewerSpecs USING [windowBorderSize],
ViewersToIP;
~
BEGIN
Context: TYPE ~ Imager.Context;
ROPE: TYPE ~ Rope.ROPE;
VEC: TYPE ~ Vector2.VEC;
Viewer: TYPE ~ ViewerClasses.Viewer;
windowBorderSize: INTEGER ~ ViewerSpecs.windowBorderSize;
viewerToIPDoc: ROPE ~ "\nCreate interpress master from viewer. (ViewerToIP output ← viewer [version])";
pressProp: Atom.PropList ~ LIST[NEW[Atom.DottedPairNode ← [key: $ViewersToIPFontSubstitution, val: $PressFonts]]];
ViewerToIPCmd: Commander.CommandProc ~ {
ENABLE
FS.Error =>
IF error.group=user
THEN {
result ← $Failure; msg ← error.explanation;
GOTO Fail;
};
args: CommandTool.ArgumentVector ~ CommandTool.Parse[cmd];
viewer: Viewer;
version: ROPE ← NIL;
IF ~args.argc IN [4..5] OR ~Rope.Equal[args[2], "←"] THEN RETURN [result: $Failure, msg: viewerToIPDoc];
IF args.argc=5 THEN version ← args[4]; --Optional version number
viewer ← FindViewer[args[3]];
IF viewer=NIL THEN RETURN [result: $Failure, msg: "Can't find that viewer."];
{
inner:
PROC ~ {
ViewerToIP[viewer, args[1], version];
};
ProcessProps.AddPropList[propList: pressProp, inner: inner]
}
};
ViewerToIP:
PUBLIC
PROC [v: Viewer, file:
ROPE, version:
ROPE ←
NIL, pixelsPerInch:
REAL ← 72.0, pageSize:
VEC ← [8.5, 11], clipChildren:
BOOLEAN ←
FALSE] ~ {
PaintPage:
PROC [context: Context] ~ {
fakeViewer: ViewerClasses.Viewer ← NEW[ViewerClasses.ViewerRec ← v^];
[] ← v.class.paint[self: v, context: context, whatChanged: NIL, clear: TRUE];
fakeViewer.wx ← fakeViewer.wy ← 0;
fakeViewer.cx ← fakeViewer.cy ← 1;
fakeViewer.ww ← Real.RoundC[pageSize.x*pixelsPerInch];
fakeViewer.cw ← fakeViewer.ww-2;
fakeViewer.wh ← Real.RoundC[pageSize.y*pixelsPerInch];
fakeViewer.ch ← fakeViewer.wh-2;
fakeViewer.iconic ← FALSE;
IF v.class.topDownCoordSys THEN Imager.TranslateT[context, [0, MAX[fakeViewer.wh-v.wh,0]]];
RecursivelyPaintViewers[fakeViewer, context, clipChildren];
};
ip: ImagerInterpress.Ref ~ ImagerInterpress.Create[file, IF version=NIL THEN NIL ELSE Rope.Cat["Interpress/Xerox/", version, " "]];
ImagerInterpress.DoPage[self: ip, action: PaintPage, scale: Imager.metersPerInch/pixelsPerInch];
ImagerInterpress.Close[ip];
};
RecursivelyPaintViewers:
PROC [viewer: Viewer, context: Context, clipChildren:
BOOLEAN ←
FALSE] = {
PaintViewer:
PROC ~ {
IF viewer.class.paint#
NIL
THEN {
quit ← viewer.class.paint[viewer, context, NIL, TRUE];
};
};
quit: BOOL ← FALSE;
Paint the border if needed
IF viewer.parent#
NIL
THEN {
w: INTEGER ~ viewer.ww;
h: INTEGER ~ viewer.wh;
IF viewer.border
THEN {
Imager.SetColor[context, Imager.black];
Imager.MaskRectangleI[context, 0, 0, windowBorderSize, h];
Imager.MaskRectangleI[context, w, 0, -windowBorderSize, h];
Imager.MaskRectangleI[context, 0, 0, w, windowBorderSize];
Imager.MaskRectangleI[context, 0, h, w, -windowBorderSize];
};
};
Imager.DoSaveAll[context, PaintViewer];
do we need to paint any of the children?
IF quit THEN RETURN;
recursively paint children
FOR v: Viewer ← viewer.child, v.sibling
UNTIL v=
NIL
DO
action:
PROC ~ {
Translate the viewer position if a child viewer
Imager.TranslateT[context, [v.wx, IF v.parent.class.topDownCoordSys THEN v.parent.wh-v.wy-v.wh ELSE v.wy]];
IF clipChildren THEN Imager.ClipRectangleI[context, 0, 0, viewer.ww, viewer.wh];
RecursivelyPaintViewers[v, context];
};
Imager.DoSaveAll[context, action];
ENDLOOP;
};
Some stuff to change strike fonts into press fonts
SubstitutePressFonts: ImagerTypefaceExtras.GenericCreatorProc ~ {
IF ProcessProps.GetProp[$ViewersToIPFontSubstitution]=$PressFonts
THEN {
ERROR
}
ELSE RETURN [NIL]
};
Like ViewerOps.Find, except willing to match subpattern.
FindViewer:
PROC [name: Rope.
ROPE]
RETURNS [viewer: Viewer ←
NIL] = {
MatchName: ViewerOps.EnumProc = {
IF Rope.Find[s1: v.name, s2: name, case:
FALSE] >= 0
THEN {
viewer ← v;
RETURN [FALSE]
}
ELSE RETURN[TRUE];
};
ViewerOps.EnumerateViewers[MatchName];
};
Commander.Register[key: "ViewerToIP", proc: ViewerToIPCmd, doc: viewerToIPDoc];
ImagerTypefaceExtras.RegisterGenericCreator[genericCreator: NEW[ImagerTypefaceExtras.GenericCreatorRep ← [data: NIL, proc: SubstitutePressFonts, priority: 1]]];