Documente Academic
Documente Profesional
Documente Cultură
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA 94903, U.S.A., +1(415)492-9861.
languagelevel 1 .setlanguagelevel
level2dict begin
% We have to guard against the BeginPage procedure not popping its operand.
% This is really stupid, but the Genoa CET does it.
/.beginpage { % - .beginpage -
.currentshowpagecount {
.currentpagedevice pop
dup //null ne { /BeginPage .knownget } { pop //false } ifelse {
% Stack: ... pagecount proc
count 2 .execn
% Stack: ... ..???.. oldcount
count 1 add exch sub { pop } repeat
} {
pop
} ifelse
} if
} bind odef
(%gsavepagedevice) cvn
{ currentpagedevice pop gsave
} bind def
(%savepagedevice) cvn
{ currentpagedevice pop save
} bind def
(%gstatepagedevice) cvn
{ currentpagedevice pop gstate
} bind def
(%copygstatepagedevice) cvn
{ currentpagedevice pop copy
} bind def
(%currentgstatepagedevice) cvn
{ currentpagedevice pop currentgstate
} bind def
/.installpagedevice
{ % Since setpagedevice doesn't create new device objects,
% we must (carefully) reinstall the old parameters in
% the same device.
.currentpagedevice pop //null currentdevice //null .trysetparams
dup type /booleantype eq
{ pop pop }
{ % This should never happen!
SETPDDEBUG { (Error in .trysetparams!) = pstack flush } if
cleartomark pop pop pop
/.installpagedevice cvx /rangecheck signalerror
}
ifelse pop pop
% A careful reading of the Red Book reveals that an erasepage
% should occur, but *not* an initgraphics.
erasepage .beginpage
} bind def
/.uninstallpagedevice
{ 2 .endpage { .currentnumcopies //false .outputpage } if
nulldevice
} bind def
(%grestorepagedevice) cvn
{ .uninstallpagedevice grestore .installpagedevice
} bind def
(%grestoreallpagedevice) cvn
{ .uninstallpagedevice grestore .installpagedevice grestoreall
} bind def
(%restore1pagedevice) cvn
{ .uninstallpagedevice grestore .installpagedevice restore
} bind def
(%restorepagedevice) cvn
{ .uninstallpagedevice restore .installpagedevice
} bind def
(%setgstatepagedevice) cvn
{ .uninstallpagedevice setgstate .installpagedevice
} bind def
/.currentnumcopies
{ currentdevice //.numcopiesdict .getdeviceparams
dup type /integertype eq
{ exch pop exch pop }
{ cleartomark #copies }
ifelse
} bind odef
% Define the required attributes of all page devices, and their default values.
% We don't include attributes such as .MediaSize, which all devices
% are guaranteed to supply on their own.
/.defaultpolicies mark
/PolicyNotFound 1
/PageSize 0
/PolicyReport {
dup /.LockSafetyParams known {
% Only possible error is invalidaccess
/setpagedevice .systemvar /invalidaccess signalerror
}
if
pop
} bind
.dicttomark readonly def
% Note that the values of .requiredattrs are executed, not just fetched.
/.requiredattrs mark
/PageDeviceName //null
/PageOffset [0 0] readonly
% We populate InputAttributes with all of the known page sizes
% followed by a dummy media type that handles pages of any size.
% This will create some duplicates, but that only slightly slows
% down the media selection (loop is in zmedia2.c).
%
% Some PostScript creators assume that slot 0 is the default media
% size and some can't handle a non-standard 4-element array which
% is a 'range' type page size (always put last).
%
% Real Devices that can only handle specific page sizes will override this.
/InputAttributes {
mark
% First put the device's default page size in slot 0
% This satifies those that have devices built with a4 as the default
0 mark /PageSize currentdevice /PageSize gsgetdeviceprop .dicttomark
statusdict /.pagetypenames get {
counttomark 1 sub 2 idiv exch mark exch /PageSize exch
% stack: mark --dict-- --dict-- ... key mark /PageSize pagetypename
% see note above about pagetype executable array contents.
load dup 0 get exch 1 get 2 array astore .dicttomark
} forall
% If NORANGEPAGESIZE is defined, (-dNORANGEPAGESIZE), then don't add
% the 'match any' PageSize entry
systemdict /NORANGEPAGESIZE known not {
% Add one last entry which is the 4 element range array (non-standard)
counttomark 2 idiv
% PageSize with either dimension 0 will be detected in
% match_page_size, so we can allow it here
mark /PageSize [0 dup 16#7ffff dup] .dicttomark
} if
.dicttomark
}
(%MediaSource) 0
/OutputAttributes {
mark 0 mark .dicttomark readonly .dicttomark
}
(%MediaDestination) 0
/Install {{.callinstall}} bind
/BeginPage {{.callbeginpage}} bind
/EndPage {{.callendpage}} bind
/Policies .defaultpolicies
/ImagingBBox //null % default value
/UseCIEColor /.getuseciecolor load
.dicttomark readonly def
% Define all the parameters that should always be copied to the merged
% dictionary.
/.copiedkeys [
/OutputDevice
.mergespecial { pop } forall
.inputattrkeys aload pop
.inputselectionkeys aload pop
.outputattrkeys aload pop
] readonly def
% Compute the media size and initial matrix from a merged request (after
% media selection).
/.computemediasize % <request> .computemediasize
% <request> <matrix> <[width height]>
{ dup /PageSize get % requested page size
1 index /InputAttributes get
2 index (%MediaSource) get get /PageSize get % media size
% (may be a range)
2 index /Policies get
dup /PageSize .knownget
{ exch pop } { /PolicyNotFound get } ifelse % PageSize policy,
% affects scaling
3 index /Orientation .knownget not { //null } if
4 index /RollFedMedia .knownget not { //false } if
matrix .matchpagesize not {
% This is a "can't happen" condition!
/setpagedevice load /rangecheck signalerror
} if
2 array astore
} bind def
/setpagedevice
{ % We mustn't pop the argument until the very end,
% so that the pseudo-operator machinery can restore the stack
% if an error occurs.
mark 1 index currentpagedevice
0 dict % <failed>
1 index /InputAttributes .knownget
{ 2 index /Policies get
.inputattrkeys (%MediaSource) cvn .selectmedia
} if
1 index /OutputAttributes .knownget
{ 2 index /Policies get
.outputattrkeys (%MediaDestination) cvn .selectmedia
} if
3 -1 roll 4 1 roll % temporarily swap orig & request
.applypolicies
3 -1 roll 4 1 roll % swap back
pop 2 .endpage
{ 1 //true .outputpage
(>>setpagedevice, press <return> to continue<<\n) .confirm
}
if
% .setdevice clears the current page device!
.currentpagedevice pop exch
.setdevice pop
.setpagedevice
/.setuseciecolor where
{
pop 1 index /UseCIEColor .knownget
{
dup .setuseciecolor not
{ /DeviceRGB setcolorspace }
if
}
if
}
if
% We break out the code after calling the Install procedure into a
% separate procedure, since it is executed even if Install causes an error.
% By making .execinstall a separate operator procedure, we get the stacks
% restored if it fails.
} odef
end % level2dict
.setlanguagelevel