📄 gs_ll3.ps
字号:
% Copyright (C) 1997, 1998 Aladdin Enterprises. All rights reserved.
%
% This file is part of Aladdin Ghostscript.
%
% Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
% or distributor accepts any responsibility for the consequences of using it,
% or for whether it serves any particular purpose or works at all, unless he
% or she says so in writing. Refer to the Aladdin Ghostscript Free Public
% License (the "License") for full details.
%
% Every copy of Aladdin Ghostscript must include a copy of the License,
% normally in a plain ASCII text file named PUBLIC. The License grants you
% the right to copy, modify and redistribute Aladdin Ghostscript, but only
% under certain conditions described in the License. Among other things, the
% License requires that the copyright notice and this notice be preserved on
% all copies.
% $Id: gs_ll3.ps $
% Initialization file for PostScript LanguageLevel 3 functions.
% Essentially all of these are stubs right now.
% This file must be loaded after gs_lev2.ps and gs_res.ps.
% These definitions go into ll3dict or various ProcSets.
% NOTE: the interpreter creates ll3dict.
ll3dict begin
% We need LanguageLevel 2 or higher in order to have setuserparams and
% defineresource.
languagelevel dup 2 max .setlanguagelevel
% ------ Idiom recognition ------ %
/IdiomRecognition false .definepsuserparam
% Modify `bind' to apply idiom recognition afterwards.
/.bindscratch 128 string def
% Do the right thing if NOBIND or DELAYBIND is in effect.
% Note also that since this definition of `bind' may get bound in,
% it has to function properly even at lower language levels,
% where IdiomRecognition may not be defined.
/bind load /.bind load ne
/bind { % <proc> bind <proc'>
//.bind currentuserparams /IdiomRecognition
.knownget not { false } if {
(*) {
/IdiomSet findresource
false exch {
% Stack: proc false dummykey [template substitute]
exch pop dup 1 get exch 0 get
% Stack: proc false substitute template
3 index .eqproc {
2 index gcheck 1 index gcheck not and {
pop
} {
3 -1 roll pop exch not exit
} ifelse
} {
pop
} ifelse
} forall { exit } if
} //.bindscratch /IdiomSet resourceforall
} if
} odef
{ /.bind /bind load def
/bind { } def
} if
currentdict /.bindscratch .undef
% ------ HalftoneTypes 6, 10, 16 ------ %
% This code depends on one new operator:
%
% <dict> <Width> <Height> <Thresholds> <bits> <shift> .setstriphalftone -
%
% <dict> is the dictionary that will be returned by .currenthalftone.
% The operator only looks at the TransferFunction entry.
% Width, Height: as for HalftoneType 3.
% Thresholds: a BigStringEncode filter holding the thresholds,
% Width x Height x BitsPerSample / 8 bytes.
% shift: the amount of X shift per Y repetition of the halftone,
% 0 <= Shift < Width.
% bits: bits per sample, 8 or 16.
%
% Eventually the code below will have to get hooked up to sethalftone
% and currenthalftone....
/.copybytes { % <source> <dest> <count> .copybytes -
{ 1 index read not { /sethalftone load /rangecheck signalerror exit } if
1 index exch write
} repeat pop pop
} bind def
/.copythresholds { % <dict> <Width> <Height> <bits> .copythresholds -
dup 8 idiv 3 index mul 2 index mul
dup /BigStringEncode filter 3 1 roll
% Stack: dict width height dest bits nbytes
5 index /Thresholds get 3 index 3 -1 roll .copybytes
1 index closefile
0 .setstriphalftone
} bind def
/.sethalftone6 { % <dict> .sethalftone6 -
% Keys: Width, Height, Thresholds, T'Function
dup /Width get 1 index /Height get
8 .copythresholds
} odef
/.copythresholds2 { % <dict> <Width> <Height> <Width2> <Height2>
% <bits> .copythresholds2 -
% The block height B is gcd(Height, Height2).
3 index 2 index {
2 copy lt { exch } if dup 1 eq { pop exit } if exch 1 index mod
} loop
% The raster R is (Width * Height + Width2 * Height2) / B * bits/8.
5 index 5 index mul 4 index 4 index mul add 1 index idiv
2 index 8 idiv mul
% Currently I don't know how to compute the stride.
% ****** COMPUTE THE STRIDE SOMEHOW ******
% Push additional arguments onto the stack.
1 index 1 index mul /BigStringEncode filter 4 1 roll
9 index /Thresholds get
% Stack: dict width height width2 height2 bits
% dest B R stride source
% For the first rectangle, the number of blocks is Height / B;
% the offset is 0.
5 copy 14 index 5 1 roll
14 index 5 index idiv 4 1 roll
0 exch .copyshifted
% For the second rectangle, the number of blocks is Height2 / B;
% the offset is Width.
5 copy 12 index 5 1 roll
12 index 4 index idiv 4 1 roll
16 index exch .copyshifted
% Stack: dict width height width2 height2 bits
% dest B R stride source
% We want: dict R/(bits/8) B dest bits stride
pop exch 4 index 8 idiv idiv 4 1 roll
% R/(bits/8) dest B stride
exch 3 1 roll 5 -1 roll exch
9 -4 roll 4 { pop } repeat
.setstriphalftone
} bind def
% Copy a shifted rectangular threshold array into a BigStringEncode filter.
% Note that the width and shift are in bytes, not samples.
/.copyshifted { % <dest> <width> <B> <N> <R> <stride> <offset>
% <source> .copyshifted -
% Copy N blocks of <width> x B bytes from <source>.
% Row Y (0 <= Y < B) in group G (0 <= G < N) must get copied to byte position
% Y * R + (G * stride + offset) mod R
% in the destination.
1 index % Stack: ... rowstart
6 index { % iterate over rows within a block
5 index { % iterate over blocks
8 index 1 index setfileposition
1 index 9 index 9 index .copybytes
4 index add % + raster
} repeat % end block
3 index add 4 index mod % + stride, mod raster
} repeat % end row in block
9 { pop } repeat
} bind def
/.sethalftone10 { % <dict> .sethalftone10 -
% Keys: XSquare, YSquare, Thresholds, T'Function
% ****** DOESN'T HANDLE STRING SOURCE ******
dup /XSquare get dup 2 index /YSquare get dup
8 .copythresholds2
} odef
/.sethalftone16 { % <dict> .sethalftone16 -
% Keys: Width, Height, Width2, Height2,
% Thresholds, T'Function
dup /Width get 1 index /Height get
2 index /Width2 .knownget { % 2-rectangle case
3 index /Height2 get
16 .copythresholds2
} { % 1-rectangle case
16 .copythresholds
} ifelse
} odef
{6 10 16} { dup /HalftoneType defineresource pop } forall
% ------ ImageTypes 3 and 4 (masked images) ------ %
.imagetypes
dup 3 /.image3 load put
4 /.image4 load put
% ------ Functions ------ %
% Define the FunctionType resource category.
/Generic /Category findresource dup maxlength 3 add dict .copydict begin
/InstanceType /integertype def
/FunctionType currentdict end /Category defineresource pop
{0 2 3} { dup /FunctionType defineresource pop } forall
% ------ Smooth shading ------ %
% Define the ShadingType resource category.
/Generic /Category findresource dup maxlength 3 add dict .copydict begin
/InstanceType /integertype def
/ShadingType currentdict end /Category defineresource pop
systemdict /.shadingtypes mark % not ll3dict
1 /.buildshading1 load
2 /.buildshading2 load
3 /.buildshading3 load
4 /.buildshading4 load
5 /.buildshading5 load
6 /.buildshading6 load
7 /.buildshading7 load
.dicttomark put
/.buildshading { % <shadingdict> .buildshading <shading>
% The .buildshading operators use the current color space
% for ColorSpace.
dup /ShadingType get //.shadingtypes exch get
1 index /ColorSpace get gsave { setcolorspace exec } stopped
grestore { stop } if
} bind def
/.buildpattern2 { % <template> <matrix> .buildpattern2
% <template> <pattern>
1 index /Shading get .buildshading .buildshadingpattern
} bind def
.patterntypes
2 /.buildpattern2 load put
/shfill { % <shadingdict> shfill -
% Currently, .shfill requires that the color space
% in the pattern be the current color space.
dup .buildshading
1 index /ColorSpace get
gsave { setcolorspace .shfill } stopped grestore { stop } if
pop
} odef
% Establish an arbitrary initial smoothness value.
1 64 div setsmoothness
% ------ Trapping ------ %
% The PostScript-level trapping parameters are maintained in userdict,
% and explicitly reinstalled upon restore.
/Trapping mark
/settrapparams dup { % <paramdict> settrapparams -
/.trapparams .uservar dup length dict .copydict
dup 2 index {
% Stack: paramdict olddict olddict key value
2 index 2 index known { put dup } { pop pop } ifelse
} forall pop
dup .settrapparams % Let the operator check parameter validity.
.userdict /.trapparams 3 -1 roll put pop
} bind .makeoperator
/.copyparams { % <obj> .copyparams <obj'>
dup type /dicttype eq {
dup length dict .copydict
dup {
.copyparams 3 copy put pop pop
} forall
} {
dup type /arraytype eq {
[ exch { .copyparams } forall ]
} if
} ifelse
} odef
/currenttrapparams dup { % - currenttrapparams <paramdict>
/.trapparams .uservar .copyparams
} bind .makeoperator
/settrapzone dup { % - settrapzone -
% ****** DUMMY ******
newpath
} bind .makeoperator
% Define initial (dummy) trapping parameters.
% These values are mostly complete guesses.
userdict /.trapparams mark
/BlackColorLimit 1.0
/BlackDensityLimit 1.0
/BlackWidth 1.0
/ColorantZoneDetails 0 dict
/Enabled true
/HalftoneName null
/ImageInternalTrapping false
/ImageResolution 1
/ImageToObjectTrapping true
/ImageTrapPlacement /Center
/SlidingTrapLimit 1.0
/StepLimit 1.0
/TrapColorScaling 0.0
/TrapSetName null
/TrapWidth 1.0
.dicttomark readonly put
.dicttomark /ProcSet defineresource pop
% ------ Miscellaneous ------ %
% Define additional user and system parameters.
psuserparams begin
/HalftoneMode 0 def
/MaxSuperScreen 1016 def
end
pssystemparams begin % read-only, so use .forcedef
/MaxDisplayAndSourceList 160000 .forcedef
end
% Define the IdiomSet, InkParams, and TrapParams resource categories.
{ /IdiomSet /InkParams /TrapParams } {
/Generic /Category findresource dup maxlength 3 add dict .copydict begin
/InstanceType /dicttype def
currentdict end /Category defineresource pop
} forall
% Define the ReusableStreamDecode filter.
% ****** DOESN'T WORK FOR CONTENTS >64K ******
/.reusablestreamdecode { % <source> <dict> .reusablestreamdecode <file>
% <source> .reusablestreamdecode <file>
% Collect the filter parameters.
dup type /dicttype eq { 2 copy } { dup 0 dict } ifelse
dup .rsdparams
% Construct the filter pipeline.
% The very first filter should use the value of CloseSource
% from the RSD dictionary; all the others should have
% CloseSource = true.
% Stack: source dict filters parms
2 index /CloseSource .knownget not { false } if 5 -1 roll
% Stack: dict filters parms CloseSource source
0 1 5 index length 1 sub {
4 index 1 index get
% Stack: dict filters parms CloseSource source index filtname
4 index null eq {
0 dict
} {
4 index 2 index get dup null eq { pop } if
} ifelse
3 -1 roll pop filter
exch pop true exch % set CloseSource for further filters
} for
% See if we can create the filter directly.
% Stack: dict filters parms CloseSource file
null 2 index { .reusablestream } .internalstopped {
pop pop
% No luck. Read the entire contents of the stream now.
10 dict exch {
% Stack: dict filters parms CloseSource contdict file
dup 1000 string readstring
3 index dup length 4 -1 roll put not { break } if
} loop pop
% Concatenate the contents into one big string.
% Stack: dict filters parms CloseSource contdict
0 1 index { length exch pop add } forall string
exch {
% Stack: dict filters parms CloseSource string index substring
exch 1000 mul exch 2 index 3 1 roll putinterval
} forall
% Now create the stream on the string.
null 3 -1 roll .reusablestream
} if
% We created the stream successfully: clean up.
4 { exch pop } repeat
dup type /dicttype eq { pop } if pop
} odef
filterdict /ReusableStreamDecode /.reusablestreamdecode load put
/languagelevel 3 def
% When running in LanguageLevel 3 mode, this interpreter is supposed to be
% compatible with Adobe version 3010.
/version (3010) readonly def
.setlanguagelevel
end % ll3dict
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -