Академический Документы
Профессиональный Документы
Культура Документы
%
% 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.
/fnrdict mark
0 { .resolvefn0 }
2 { .resolvefn2 }
3 { .resolvefn3 }
4 { .resolvefn4 }
.dicttomark readonly def
/.resolvefn0 {
dup length 1 add dict .copydict % make room for DataSource
% now resolve any indirect references
dup /Size 2 copy knownoget { put } { pop pop } ifelse
dup /BitsPerSample 2 copy knownoget { put } { pop pop } ifelse
dup /Order 2 copy knownoget { put } { pop pop } ifelse
dup /Encode 2 copy knownoget { put } { pop pop } ifelse
dup /Decode 2 copy knownoget { put } { pop pop } ifelse
/.resolvefn2 {
dup length dict .copydict
dup /C0 2 copy knownoget { put } { pop pop } ifelse
dup /C1 2 copy knownoget { put } { pop pop } ifelse
dup /N 2 copy knownoget { put } { pop pop } ifelse
} bdef
/.resolvefn3 {
dup length dict .copydict
dup /Bounds 2 copy knownoget { put } { pop pop } ifelse
dup /Encode 2 copy knownoget { put } { pop pop } ifelse
dup /Functions 2 copy oget mark exch dup {
oforce .resolvefn
} forall
counttomark -1 roll astore exch pop put
} bdef
/.resolvefn4 {
PDFfile fileposition exch % filepos fndict
dup true resolvestream % filepos fndict stream
exch dup length dict copy % filepos stream fndict2
dup /Function undef % filepos stream fndict2
exch dup token not {
() /rangecheck cvx signalerror
} if
exch token {
/rangecheck cvx signalerror
} if
% Use .bind to avoid idiom recognition.
.bind
1 index /Function 3 -1 roll put
exch PDFfile exch setfileposition
} bdef
/shrdict mark
/ColorSpace {
resolvecolorspace
}
/Function {
dup type /dicttype eq {
resolvefunction
} {
[ exch { oforce resolvefunction } forall ]
} ifelse
}
.dicttomark readonly def
/spotfunctions mark
/Round {
abs exch abs 2 copy add 1 le {
dup mul exch dup mul add 1 exch sub
} {
1 sub dup mul exch 1 sub dup mul add 1 sub
} ifelse
}
/Diamond {
abs exch abs 2 copy add .75 le {
dup mul exch dup mul add 1 exch sub
} {
2 copy add 1.23 le {
.85 mul add 1 exch sub
} {
1 sub dup mul exch 1 sub dup mul add 1 sub
} ifelse
} ifelse
}
/Ellipse {
abs exch abs 2 copy 3 mul exch 4 mul add 3 sub dup 0 lt {
pop dup mul exch .75 div dup mul add 4 div 1 exch sub
} {
dup 1 gt {
pop 1 exch sub dup mul exch 1 exch sub
.75 div dup mul add 4 div 1 sub
} {
.5 exch sub exch pop exch pop
} ifelse
} ifelse
}
/EllipseA { dup mul .9 mul exch dup mul add 1 exch sub }
/InvertedEllipseA { dup mul .9 mul exch dup mul add 1 sub }
/EllipseB { dup 5 mul 8 div mul exch dup mul exch add sqrt 1 exch sub }
/EllipseC { dup mul .9 mul exch dup mul add 1 exch sub }
/InvertedEllipseC { dup mul .9 mul exch dup mul add 1 sub }
/Line { exch pop abs neg }
/LineX { pop }
/LineY { exch pop }
/Square { abs exch abs 2 copy lt { exch } if pop neg }
/Cross { abs exch abs 2 copy gt { exch } if pop neg }
/Rhomboid { abs exch abs 0.9 mul add 2 div }
/DoubleDot { 2 {360 mul sin 2 div exch } repeat add }
/InvertedDoubleDot { 2 {360 mul sin 2 div exch } repeat add neg }
/SimpleDot { dup mul exch dup mul add 1 exch sub }
/InvertedSimpleDot { dup mul exch dup mul add 1 sub }
/CosineDot { 180 mul cos exch 180 mul cos add 2 div }
/Double { exch 2 div exch 2 { 360 mul sin 2 div exch } repeat add }
/InvertedDouble {
exch 2 div exch 2 { 360 mul sin 2 div exch } repeat add neg
}
.dicttomark readonly def
/htrdict mark
1 { .resolveht1 }
5 { .resolveht5 }
% We don't support types 6, 10, or 16 yet.
.dicttomark readonly def
/.resolveht1 {
mark exch {
oforce
1 index /SpotFunction eq {
dup type /nametype eq
{ //spotfunctions exch get } { resolvefnproc }
ifelse
} {
1 index /TransferFunction eq {
resolveidfnproc
} if
} ifelse
} forall .dicttomark
} bdef
/.resolveht5 {
mark exch {
oforce dup type /dicttype eq { resolvehalftone } if
} forall .dicttomark
} bdef
/gssmask {
dup /None eq PDFusingtransparency not or {
pop null
} {
% Preprocess the SMask value into a parameter dictionary for
% .begintransparencymask, with added /BBox and /Draw keys.
mark exch % Stack: mark smaskdict
dup /S oget /Subtype exch 3 2 roll
% Stack: mark ... smaskdict
dup /BC knownoget {
gsave
1 index /G oget /Group oget /CS knownoget {
csresolve dup setgcolorspace csput
} if
aload pop setcolor [ currentgray ]
grestore
/Background exch 3 2 roll
} if
dup /TR knownoget {
resolveidfnproc /TransferFunction exch 3 2 roll
} if
dup /G oget dup /BBox oget /BBox exch 4 2 roll
/.execmaskgroup cvx 2 packedarray cvx /Draw exch 3 2 roll
pop .dicttomark
} ifelse SMask
} bdef
% The keys here are resolved (PostScript, not PDF) color space names.
/csncompdict mark
/DeviceGray { pop 1 }
/DeviceRGB { pop 3 }
/DeviceCMYK { pop 4 }
/CIEBasedA { pop 1 }
/CIEBasedABC { pop 3 }
/ICCBased { 1 oget /N oget }
/Separation { pop 1 }
/DeviceN { 1 oget length }
.dicttomark readonly def
/csrdict mark
/DeviceGray { }
/DeviceRGB { }
/DeviceCMYK { }
/CalGray {
1 oget 6 dict begin
dup /Gamma knownoget {
/exp load 2 packedarray cvx /DecodeA exch def
} if
dup /BlackPoint knownoget { /BlackPoint exch def } if
dup /WhitePoint knownoget {
dup /WhitePoint exch def
dup /MatrixA exch def
/RangeLMN [ 3 2 roll { 0 exch } forall ] def
} if
/PDFColorSpace exch def [ /CIEBasedA currentdict end ]
}
/CalRGB {
1 oget 6 dict begin
dup /Gamma knownoget {
[ exch { /exp load 2 packedarray cvx } forall
] /DecodeABC exch def
} if
dup /Matrix knownoget { /MatrixABC exch def } if
dup /BlackPoint knownoget { /BlackPoint exch def } if
dup /WhitePoint knownoget { /WhitePoint exch def } if
/PDFColorSpace exch def [ /CIEBasedABC currentdict end ]
}
/CalCMYK {
pop /DeviceCMYK % not defined by Adobe
}
/Lab {
1 oget 6 dict begin
dup /Range knownoget not { [-100 100 -100 100] } if
[0 100 null null null null] dup 2 4 -1 roll putinterval
/RangeABC exch def
/DecodeABC [{16 add 116 div} bind {500 div} bind {200 div} bind] def
/MatrixABC [1 1 1 1 0 0 0 0 -1] def
dup /BlackPoint knownoget { /BlackPoint exch def } if
dup /WhitePoint knownoget { /WhitePoint exch def } {
( **** Warning: Lab colorspace is missing WhitePoint.\n)
pdfformaterror
/WhitePoint [0.9505 1 1.089] def
} ifelse
% scaling function g() for DecodeLMN construction
{ dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse }
/DecodeLMN [
% Store white point implicitly inside procedures.
[ 3 index aload pop WhitePoint 0 get /mul .systemvar ] cvx bind
[ 4 index aload pop WhitePoint 1 get /mul .systemvar ] cvx bind
[ 5 index aload pop WhitePoint 2 get /mul .systemvar ] cvx bind
] def pop
/PDFColorSpace exch def [ /CIEBasedABC currentdict end ]
}
/ICCBased {
PDFfile fileposition exch
dup dup 1 oget
mark exch { oforce } forall .dicttomark
dup dup true resolvestream
/ReusableStreamDecode filter /DataSource exch put
1 exch put
exch PDFfile exch setfileposition
% Resolve alternate color space
dup 1 get % Get colorspace dictionary
dup /Alternate .knownget % Check for alternate color space
{ oforce resolvecolorspace /Alternate exch put } % resolve and replace
{ pop } % remove colorspace dictionary
ifelse
} bind
/Separation {
aload pop exch oforce resolvecolorspace
% Contrary to PDF manuals up to v.1.5, Acrobat Distiller 3.01
% can use /Identity name here instead of a function.
exch oforce resolveidfnproc
4 array astore
}
/DeviceN {
0 4 getinterval % ignore attributes
aload pop 3 -1 roll oforce % resolve names array
[ exch { oforce } forall ] % resolve each of the names
3 -1 roll oforce resolvecolorspace
3 -1 roll oforce resolvefnproc
4 array astore
}
/Indexed {
aload pop 3 -1 roll oforce resolvecolorspace
% Stack: /Indexed hival lookup basespace
% If the underlying space is a Lab space, we must scale
% the output of the lookup table as part of DecodeABC.
dup dup type /arraytype eq { 0 get } if /CIEBasedABC eq {
dup 1 get /DecodeLMN known {
1 get dup length dict copy
begin /DecodeABC [ 0 2 4 {
RangeABC 1 index 1 add get RangeABC 2 index get sub /mul load
RangeABC 3 index get /add load
DecodeABC 6 -1 roll 2 idiv get [ 6 1 roll aload pop ] cvx
} for ] def
/RangeABC //01_3 def
currentdict end /CIEBasedABC exch 2 array astore
} if
} if
3 1 roll
oforce dup type /stringtype ne {
% The color lookup table is a stream.
% Get its contents. Don't lose our place in PDFfile.
% Stack: /Indexed basespace hival lookup
PDFfile fileposition 5 1 roll true resolvestream
% Stack: filepos /Indexed basespace hival lookupstream
1 index 1 add
% Stack: filepos /Indexed basespace hival lookupstream len
3 index
dup dup type /arraytype eq { 0 get } if
//csncompdict exch get exec mul
string readstring pop
% Stack: filepos /Indexed basespace hival table
5 -1 roll PDFfile exch setfileposition
}
if 4 array astore
% Replace the PDFColorSpace with the Indexed space if needed.
dup 1 get
dup type /arraytype eq {
dup length 2 ge {
dup 1 get type /dicttype eq {
dup 1 get /PDFColorSpace known {
dup 1 get /PDFColorSpace 3 index put
} if
} if
} if
} if pop
}
/Pattern {
dup type /nametype ne {
dup length 1 gt {
1 oget resolvecolorspace
/Pattern exch 2 array astore
} if
} if
}
.dicttomark readonly def
/csnames mark
/DeviceGray dup /DeviceRGB dup /DeviceCMYK dup /Pattern dup
.dicttomark readonly def
/csresolve { % <csresourcename> csresolve <cspace>
dup type /nametype ne {
(\n **** Warning: CS/cs (setcolorspace) operand not a name: ) pdfformaterror
dup stderrfile dup 3 -1 roll write==only flushfile
( ****\n) pdfformaterror
dup type /arraytype eq { % Adobe InDesign + PDF Library has array
resolvecolorspace
} if
} {
dup Page /ColorSpace rget {
exch pop resolvecolorspace
} {
//csnames 1 index known not { /undefined cvx signalerror } if
} ifelse
} ifelse
} bdef
/resolvecolorspace { % <cspace> resolvecolorspace <cspace'>
dup dup type /arraytype eq { 0 get } if
//csrdict exch .knownget
{
exec dup type /nametype ne { dup length 1 eq { 0 get } if } if
} {
dup type /nametype eq { csresolve } { csset exch pop } ifelse
} ifelse
} bdef
Q
PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { true } ifelse { (%End
PaintProc) print dup === flush } if } if
PDFfile exch setfileposition
} bdef
dup 65535 le {
string readstring pop
} {
() /SubFileDecode filter /ReusableStreamDecode filter
} ifelse
% Stack: dict savepos file string
3 1 roll exch setfileposition
1 index /File 3 -1 roll put
dup /FilePosition undef
} if
dup /Shading knownoget {
resolveshading 1 index /Shading 3 -1 roll put
} if
dup /PaintProc [
% Bind the resource dictionary into the PaintProc.
2 index /Resources knownoget { oforce } { 0 dict } ifelse
/.pdfpaintproc cvx
] cvx put
PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { true } ifelse
{ (%Pattern: ) print dup === flush } if } if
} bdef
drawopdict begin
/g { /DeviceGray cssubst { cs sc1 } { g } ifelse } bdef
/rg { /DeviceRGB cssubst { cs sc* } { rg } ifelse } bdef
/k { k } bdef
/cs { csresolve cs } bdef
/sc { scresolve { sc* } { sc1 } ifelse } bdef
/scn /sc load def
/G { /DeviceGray cssubst { CS SC1 } { G } ifelse } bdef
/RG { /DeviceRGB cssubst { CS SC* } { RG } ifelse } bdef
/K { K } bdef
/CS { csresolve CS } bdef
/ri { ri } bdef
/SC { scresolve { SC* } { SC1 } ifelse } bdef
/SCN /SC load def
end
drawopdict begin
% Path construction
/m /moveto load def
/l /lineto load def
/c /curveto load def
/v { currentpoint 6 2 roll curveto } def
/y { 2 copy curveto } def
/re {
4 2 roll moveto exch dup 0 rlineto 0 3 -1 roll rlineto neg 0 rlineto
closepath
} def
/h /closepath load def
% Path painting and clipping
/n { n } def
/S { S } def
/s { s } def
/f { f } def
/f* { f* } def
/B { B } def
/b { b } def
/B* { B* } def
/b* { b* } def
/W { W } def
/W* { W* } def
/sh { setfillstate resolvesh shfill } def
end
% Note that the keys in defaultdecodedict are resolved (PostScript, not PDF)
% color space names.
/defaultdecodedict mark
/DeviceGray { pop //01_1 } bind
/DeviceRGB { pop //01_3 } bind
/DeviceCMYK { pop //01_4 } bind
/CIEBasedA { 1 get /RangeA knownoget not { //01_1 } if } bind
/CIEBasedABC { 1 get /RangeABC knownoget not { //01_3 } if } bind
/ICCBased {
1 oget dup /Range knownoget {
exch pop
}{
/N get [ exch {0 1} repeat ] readonly
} ifelse
} bind
/Separation { pop //01_1 } bind
/DeviceN {
1 oget length [ exch {0 1} repeat ] readonly
} bind
/Indexed {
pop [ 0 1 BitsPerComponent bitshift 1 sub ]
} bind
.dicttomark readonly def
/DoImage {
checkaltimage dup length 6 add dict
1 index /SMask knownoget { 1 index exch /SMask exch put } if
1 index /Mask knownoget { 1 index exch /Mask exch put } if
makeimagedict doimagesmask
} bdef
/makemaskimage { % <datasource> <imagemask> <Mask> makemaskimage
% <datasource> <imagemask>, updates currentdict =
% imagedict
dup type /arraytype eq {
/ImageType 4 def
% Check that every element of the Mask is an integer.
//false 1 index {
type /integertype ne or
} forall {
(\n **** Warning: Some elements of Mask array are not integers.\n)
pdfformaterror
[ exch { 0.5 add cvi } forall ] % following AR4, 5, 6 implementation
} if
/MaskColor exch def
} {
% Mask is a stream, another Image XObject.
% Stack: datasource imagemask(false) maskstreamdict
PDFfile fileposition exch
dup length dict makeimagedict pop
% In order to prevent the two data sources from being
% aliased, we need to make at least one a reusable stream.
% We pick the mask, since it's smaller (in case we need to
% read all its data now).
% Stack: datasource imagemask(false) savedpos
% maskdict is currentdict
/DataSource DataSource mark
/Intent 1
/AsyncRead true
.dicttomark .reusablestreamdecode def
PDFfile exch setfileposition
currentdict end currentdict end
5 dict begin
/ImageType 3 def
/InterleaveType 3 def
/DataDict exch def
/MaskDict exch def
/ColorSpace DataDict /ColorSpace get def
} ifelse
} bdef
/doimagesmask { % <imagemask> doimagesmask -
PDFusingtransparency { currentdict /SMask knownoget } { false } ifelse {
<< /Subtype /Luminosity >> 0 0 0 0 .begintransparencymask
PDFfile fileposition exch
gsave //nodict begin
null /SoftMask gput
1 .setopacityalpha 1 .setshapealpha
0 .inittransparencymask 1 .inittransparencymask
/Compatible .setblendmode
DoImage
end grestore
PDFfile exch setfileposition
0 .endtransparencymask
<< /Subtype /Group /Isolated true >> 0 0 0 0 .begintransparencygroup
doimage
.endtransparencygroup
} {
doimage
} ifelse
} bdef
/doimage { % <imagemask> doimage -
% imagedict is currentdict, gets popped from dstack
DataSource exch
PDFusingtransparency {
currentdict /SMask knownoget
} {
false
} ifelse {
makesoftmaskimage
} {
currentdict /Mask knownoget {
makemaskimage
} if
} ifelse
% Stack: datasource imagemask
% image and imagemask can be redefined in gs_init.ps to tweak interpolation
% after device-specific files are run. Don't bind them here.
{ currentdict end setfillstate /imagemask }
{ ColorSpace setgcolorspace currentdict end setfillblend /image }
ifelse
.systemvar stopped {
pop
$error /errorname get dup /ioerror eq {
pop (\n **** Warning: File has insufficient data for an image.\n)
pdfformaterror
} {
(\n **** Warning: File encountered ')
exch 40 string cvs concatstrings
(' error while processing an image.\n) concatstrings
pdfformaterror
} ifelse
} if
% Close the input stream, unless it is PDFfile or
% PDFsource.
dup dup PDFfile eq exch PDFsource eq or { pop } { closefile } ifelse
} bdef
/DoForm {
% Adobe 2nd edition of the PDF 1.3 spec makes /FormType
% and /Matrix keys optional. Cope with the missing keys.
begin <<
currentdict /FormType known not { /FormType 1 } if
currentdict /Matrix known not { /Matrix { 1 0 0 1 0 0 } cvlit } if
currentdict end { oforce } forall
>>
dup [ 2 index /Resources knownoget { oforce } { 0 dict } ifelse
3 index false /resolvestream cvx
/.paintform cvx
] cvx /PaintProc exch put
% Adjust pdfemptycount since we have an extra dictionary on the stack
pdfemptycount exch
/pdfemptycount where pop count 2 sub /pdfemptycount exch put
q execform Q % gsave / grestore around the Form
% Restore pdfemptycount
/pdfemptycount where pop exch /pdfemptycount exch put
} bdef
/DoPS {
DOPS
{
//_dops_save 0 save put
true resolvestream cvx exec
//_dops_save 0 get restore
}
{ pop }
ifelse
} bdef
drawopdict begin
/Do {
setfillblend
PDFfile fileposition exch
dup Page /XObject rget {
exch pop dup /Subtype get xobjectprocs exch get
% Don't leave extra objects on the stack while executing
% the definition of the form.
3 -1 roll 2 .execn
} {
% This should cause an error, but Acrobat Reader can
% continue, so we do too.
( **** Undefined XObject resource: )
exch =string cvs concatstrings (\n) concatstrings
pdfformaterror
} ifelse
PDFfile exch setfileposition
} bdef
end
drawopdict begin
/BI { mark } bdef
/ID {
counttomark 2 idiv dup 7 add dict begin {
exch //unabbrevkeydict 1 index .knownget { exch pop } if
exch unabbrevvalue def
} repeat pop
/IDFlag true def % flag for stream processing.
/File PDFsource def
currentdict makeimagekeys doimage
% The Adobe documentation says that the data following ID
% consists of "lines", and some PDF files (specifically, some files
% produced by PCL2PDF from Visual Software) contain garbage bytes
% between the last byte of valid data and an EOL.
% Some files (PDFOUT v3.8d by GenText) have EI immediately following
% the stream. Some have no EOL and garbage bytes.
% Therefore, we skip all bytes before EI or EOL
0
{ PDFsource read not { //true exit } if
dup 10 eq 1 index 13 eq or
{ pop PDFsource token pop /EI ne exit
}
if
exch 69 eq 1 index 73 eq and { //false exit } if % 'EI'
}
loop
exch pop
{ /ID cvx /syntaxerror signalerror
}
if
} bdef
end
drawopdict begin
% Text control
/BT { BT } def
/ET { ET } def
/Tc { Tc } def
/TL { TL } def
/Tr { Tr } def
/Ts { Ts } def
/Tw { Tw } def
/Tz { Tz } def
% Text positioning
/Td { Td } def
/TD { TD } def
/Tm { Tm } def
/T* { T* } def
% Text painting
/Tj { Tj } def
/' { ' } def
/" { " } def
/TJ { TJ } def
end
% For stamp object we have to determine the size of the output rectangle
% and the size of the BBox for the stamp image. From these we calculate
% a scale factor for drawing the stamp.
/calcstampscale { % <annot> calcstampscale scale
dup /Rect known {
dup annotrect 4 -2 roll pop pop % get width height size in user space
3 -1 roll /AP knownoget {
/N knownoget {
dup /Matrix knownoget {
% transform /Annot /Rect xwidth to Form space
4 -2 roll 3 -1 roll dtransform 3 -1 roll
} if
/BBox knownoget {
exch pop % discard y height
aload pop pop exch pop sub % BBox width
div % scale x widths
dup 0 lt { neg } if % get magnitude
} {
pop pop 1 % default to unity scaling
} ifelse % if we have /BBox
} {
pop pop 1
} ifelse % if we have /N
} {
pop pop 1
} ifelse % if we have /AP
} {
( **** Warning: /Annot dict is missing required /Rect entry.\n)
pdfformaterror
pop 1
} ifelse
} bdef
% Draw an annotation.
/drawannottypes mark
/Link { drawlink } bind
.dicttomark readonly def
/drawannot { % <annot> drawannot -
dup annotvisible {
gsave
dup dup /Subtype get //drawannottypes exch .knownget {
exec
} {
dup calcstampscale exch drawwidget % Use drawwidget for everything else
} ifelse % type known
grestore
} if pop % annotvisible
} bdef
currentdict /drawannottypes undef
end % pdfdict
end % GS_PDF_ProcSet
.setglobal