% Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved.% % 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. % $Id: pdf_draw.ps,v 1.98 2005/10/05 14:37:59 ray Exp $% pdf_draw.ps% PDF drawing operations (graphics, text, and images). /.setlanguagelevel where { pop 2 .setlanguagelevel } if.currentglobal true .setglobal/pdfdict where { pop } { /pdfdict 100 dict def } ifelseGS_PDF_ProcSet beginpdfdict begin % For simplicity, we use a single interpretation dictionary for all% PDF graphics operations, even though this is too liberal./drawopdict 100 dict def % ================================ Graphics ================================ % % ---------------- Functions ---------------- % % Note that resolvefunction converts a PDF Function to a PostScript Function;% resolve*fnproc converts a PDF function to a PostScript procedure.% We need to process all required and optional parameters to resolve any% use of indirect references. /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 % Don't lose our place in PDFfile. PDFfile fileposition exch dup true resolvestream % The stream isn't positionable, so read all the data now. % Stack: filepos fndict stream 1 index /Range get length 2 idiv 2 index /BitsPerSample get mul 2 index /Size get { mul } forall 7 add 8 idiv string 1 index exch readstring pop exch closefile % Stack: filepos fndict data exch dup /DataSource 4 -1 roll put exch PDFfile exch setfileposition} bdef /.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 /.resolvefn { % <fndict> .resolvefn <fndict'> dup length dict .copydict dup /Domain 2 copy knownoget { put } { pop pop } ifelse dup /Range 2 copy knownoget { put } { pop pop } ifelse dup /FunctionType oget //fnrdict exch get exec} bdef /resolvefunction { % <fndict> resolvefunction <function> .resolvefn PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { true } ifelse { (%Function: ) print dup === flush } if } if} bdef /resolvefnproc { % <fndict> resolvefnproc <proc> resolvefunction .buildfunction} bdef /resolveidfnproc { % <fndict> resolveidfnproc <proc> dup /Identity eq { pop { } } { resolvefnproc } ifelse} bdef /resolvedefaultfnproc { % <fndict> <default> resolved'fnproc <proc> 1 index /Default eq { exch pop } { pop resolveidfnproc } ifelse} bdef % ---------------- Shadings ---------------- % /shrdict mark /ColorSpace { resolvecolorspace } /Function { dup type /dicttype eq { resolvefunction } { [ exch { oforce resolvefunction } forall ] } ifelse }.dicttomark readonly def /resolveshading { % <shadingstream> resolveshading <shading> PDFfile fileposition exch mark exch { oforce //shrdict 2 index .knownget { exec } if } forall .dicttomark dup /ShadingType get 4 ge { dup dup true resolvestream % Make a reusable stream so that the shading doesn't % reposition PDFfile at unexpected times. /ReusableStreamDecode filter /DataSource exch put } if exch PDFfile exch setfileposition} bdef/resolvesh { % <shname> resolveshading <shading> Page /Shading rget { resolveshading } { null }ifelse} bdef % ---------------- Halftones ---------------- % /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 /resolvehalftone { % <dict> resolvehalftone <halftone> dup /HalftoneType get dup //htrdict exch .knownget { exch pop exec } { (\n\n **** Unsupported HalftoneType ) pdfformaterror =string cvs pdfformaterror (. ***\n\n) pdfformaterror /resolvehalftone cvx /unregistered signalerror } ifelse} bdef % ---------------- Graphics state management ---------------- % /cmmatrix matrix defdrawopdict begin % Graphics state stack /q { q } def /Q { Q } def % Graphics state setting /cm { { //false upath } stopped { pop % discard 'false' (upath failed, probably no currentpoint). //cmmatrix astore concat } { % update the CTM, then uappend. 7 1 roll //cmmatrix astore concat newpath { mark exch uappend } stopped cleartomark } ifelse } def /i { 1 .min setflat } def /J /setlinecap load def /d /setdash load def /j /setlinejoin load def /w /setlinewidth load def /M { 1 .max setmiterlimit } bdef /gs { gs } defend % Each entry in this dictionary is% <gsres> <value> -proc- <gsres>/gsbg { /BGDefault load resolvedefaultfnproc setblackgeneration} bdef/gsucr { /UCRDefault load resolvedefaultfnproc setundercolorremoval} bdef/gstr { dup type /arraytype eq { { oforce /TRDefault load resolvedefaultfnproc } forall setcolortransfer } { /TRDefault load resolvedefaultfnproc settransfer } ifelse} bdef/gsparamdict mark /SA { setstrokeadjust } /OP { 1 index /op known not { dup op } if OP } % The PDF 1.3 specification says that the name /Default is only % recognized for {BG,UCR,TR}2. However, PDF 1.3 files produced % by Adobe Acrobat Distiller 4.0 for Windows use the name /Default % with the older keys, so we have to implement this. /BG { 1 index /BG2 known { pop } { gsbg } ifelse } /UCR { 1 index /UCR2 known { pop } { gsucr } ifelse } /TR { 1 index /TR2 known { pop } { gstr } ifelse } /HT { dup /Default eq { pop .setdefaulthalftone } { %****** DOESN'T IMPLEMENT THE STREAM CASE YET ****** resolvehalftone sethalftone } ifelse % the transfer function may dependent on the halftone, so make sure % it is set if included in the graphic state (otherwise this is % subject to order of a dictionary forall, which is unpredictable) dup /TR2 .knownget { dup /Default eq { oforce gsparamdict /TR2 get exec } { pop } ifelse } { dup /TR .knownget { /dup /Default eq { oforce gsparamdict /TR get exec } { pop } ifelse } if } ifelse } /HTP { % HTP may be present even if this isn't a DPS interpreter. /sethalftonephase where { pop aload pop sethalftonephase } { pop } ifelse } % PDF 1.3 /Font { aload pop Tf } /LW { setlinewidth } /LC { setlinecap } /LJ { setlinejoin } /ML { 1 .max setmiterlimit } /D { aload pop setdash } /RI { ri } /op { op } /OPM { OPM } /BG2 { gsbg } /UCR2 { gsucr } /TR2 { gstr } /FL { 1 .min setflat } /SM { % SM may be present even if this is only a Level 2 interpreter. /setsmoothness where { pop setsmoothness } { pop } ifelse } % PDF 1.4 % All of these require the "transparency" feature in the interpreter. /ca { ca } /CA { CA } /SMask { gssmask } /AIS { AIS } /BM { BM } /TK { TK }.dicttomark readonly def/gs { % <gsres> gs - Page /ExtGState rget { % We keep the dictionary on the stack during the forall so that % keys that interact with each other have access to it. dup { oforce exch gsparamdict exch .knownget { exec } { pop } ifelse } forall pop } if} bdef % ------ Transparency support ------ % /gssmask { dup /None eq PDFusingtransparency not or { pop null } { % Preprocess the SMask value into a parameter dictionary for % .begintransparencymaskgroup, 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 { dup /Background exch 4 2 roll gsave 1 index /G oget /Group oget /CS knownoget { csresolve dup setgcolorspace csput } if aload pop setcolor [ currentgray ] grestore /GrayBackground 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 % This procedure is called to actually render the soft mask./.execmaskgroup { % <masknum> <paramdict> <formdict> .execmaskgroup - % Save our place in PDFfile, and do a gsave to avoid resetting % the color space. currentcolorspace 4 1 roll PDFfile fileposition 4 1 roll % We have to select the group's color space so that the % background color will be interpreted correctly. dup /Group oget /CS knownoget { csresolve dup setgcolorspace csput } if exch dup /BBox get aload pop .begintransparencymaskgroup { dup /Resources knownoget { oforce } { 0 dict } ifelse exch false resolvestream .execgroup .endtransparencymask } stopped { .discardtransparencymask stop } if PDFfile exch setfileposition setcolorspace} bdef% Paint a Form+Group XObject, either for a transparency mask or for a Do./.execgroup { % <resdict> <stream> .execgroup - gsave //nodict begin null SMask 1 .setopacityalpha 1 .setshapealpha 0 .inittransparencymask 1 .inittransparencymask /Compatible .setblendmode % Execute the body of the Form, similar to DoForm. pdfopdict .pdfruncontext end grestore} bdef /.beginformgroup { % groupdict bbox .beginformgroup - exch mark exch % bbox mark groupdict dup /CS knownoget { csresolve setgcolorspace } if dup /I knownoget { /Isolated exch 3 2 roll } if dup /K knownoget { /Knockout exch 3 2 roll } if pop .dicttomark % Stack: bbox paramdict exch aload pop .begintransparencygroup} bdef % .paintgroupform implements the Form PaintProc in the case where the% Form XObject dictionary includes a Group key. See .paintform below./.paintgroupform { % <resdict> <stream> <formdict> .paintgroupform - dup /Group oget exch /BBox oget % Stack: resdict stream groupdict bbox .beginformgroup { .execgroup } stopped { .discardtransparencygroup stop } if .endtransparencygroup} bdef % Make an ImageType 103 (soft-masked) image./makesoftmaskimage { % <datasource> <imagemask> <SMask> makesoftmaskimage % <datasource> <imagemask>, updates currentdict = % imagedict % See the ImageType 3 case of makemaskimage below. % SMask is a stream, another Image XObject. % Stack: datasource imagemask(false) smaskstreamdict PDFfile fileposition exch dup /Matte knownoget { /Matte exch def } if 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 103 def /DataDict exch def dup /InterleaveType 3 put DataDict /Matte knownoget { /Matte exch def } if AlphaIsShape { /ShapeMaskDict } { /OpacityMaskDict } ifelse exch def /ColorSpace DataDict /ColorSpace get def} bdef % ---------------- Color setting ---------------- % /01_1 [0 1] readonly def/01_3 [0 1 0 1 0 1] readonly def/01_4 [0 1 0 1 0 1 0 1] readonly def % 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 defLines 1–500 of 1336. Load more
% Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved. % % 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. % $Id: pdf_draw.ps,v 1.98 2005/10/05 14:37:59 ray Exp $ % pdf_draw.ps % PDF drawing operations (graphics, text, and images). /.setlanguagelevel where { pop 2 .setlanguagelevel } if .currentglobal true .setglobal /pdfdict where { pop } { /pdfdict 100 dict def } ifelse GS_PDF_ProcSet begin pdfdict begin % For simplicity, we use a single interpretation dictionary for all % PDF graphics operations, even though this is too liberal. /drawopdict 100 dict def % ================================ Graphics ================================ % % ---------------- Functions ---------------- % % Note that resolvefunction converts a PDF Function to a PostScript Function; % resolve*fnproc converts a PDF function to a PostScript procedure. % We need to process all required and optional parameters to resolve any % use of indirect references. /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 % Don't lose our place in PDFfile. PDFfile fileposition exch dup true resolvestream % The stream isn't positionable, so read all the data now. % Stack: filepos fndict stream 1 index /Range get length 2 idiv 2 index /BitsPerSample get mul 2 index /Size get { mul } forall 7 add 8 idiv string 1 index exch readstring pop exch closefile % Stack: filepos fndict data exch dup /DataSource 4 -1 roll put exch PDFfile exch setfileposition } bdef /.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 /.resolvefn { % <fndict> .resolvefn <fndict'> dup length dict .copydict dup /Domain 2 copy knownoget { put } { pop pop } ifelse dup /Range 2 copy knownoget { put } { pop pop } ifelse dup /FunctionType oget //fnrdict exch get exec } bdef /resolvefunction { % <fndict> resolvefunction <function> .resolvefn PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { true } ifelse { (%Function: ) print dup === flush } if } if } bdef /resolvefnproc { % <fndict> resolvefnproc <proc> resolvefunction .buildfunction } bdef /resolveidfnproc { % <fndict> resolveidfnproc <proc> dup /Identity eq { pop { } } { resolvefnproc } ifelse } bdef /resolvedefaultfnproc { % <fndict> <default> resolved'fnproc <proc> 1 index /Default eq { exch pop } { pop resolveidfnproc } ifelse } bdef % ---------------- Shadings ---------------- % /shrdict mark /ColorSpace { resolvecolorspace } /Function { dup type /dicttype eq { resolvefunction } { [ exch { oforce resolvefunction } forall ] } ifelse } .dicttomark readonly def /resolveshading { % <shadingstream> resolveshading <shading> PDFfile fileposition exch mark exch { oforce //shrdict 2 index .knownget { exec } if } forall .dicttomark dup /ShadingType get 4 ge { dup dup true resolvestream % Make a reusable stream so that the shading doesn't % reposition PDFfile at unexpected times. /ReusableStreamDecode filter /DataSource exch put } if exch PDFfile exch setfileposition } bdef /resolvesh { % <shname> resolveshading <shading> Page /Shading rget { resolveshading } { null }ifelse } bdef % ---------------- Halftones ---------------- % /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 /resolvehalftone { % <dict> resolvehalftone <halftone> dup /HalftoneType get dup //htrdict exch .knownget { exch pop exec } { (\n\n **** Unsupported HalftoneType ) pdfformaterror =string cvs pdfformaterror (. ***\n\n) pdfformaterror /resolvehalftone cvx /unregistered signalerror } ifelse } bdef % ---------------- Graphics state management ---------------- % /cmmatrix matrix def drawopdict begin % Graphics state stack /q { q } def /Q { Q } def % Graphics state setting /cm { { //false upath } stopped { pop % discard 'false' (upath failed, probably no currentpoint). //cmmatrix astore concat } { % update the CTM, then uappend. 7 1 roll //cmmatrix astore concat newpath { mark exch uappend } stopped cleartomark } ifelse } def /i { 1 .min setflat } def /J /setlinecap load def /d /setdash load def /j /setlinejoin load def /w /setlinewidth load def /M { 1 .max setmiterlimit } bdef /gs { gs } def end % Each entry in this dictionary is % <gsres> <value> -proc- <gsres> /gsbg { /BGDefault load resolvedefaultfnproc setblackgeneration } bdef /gsucr { /UCRDefault load resolvedefaultfnproc setundercolorremoval } bdef /gstr { dup type /arraytype eq { { oforce /TRDefault load resolvedefaultfnproc } forall setcolortransfer } { /TRDefault load resolvedefaultfnproc settransfer } ifelse } bdef /gsparamdict mark /SA { setstrokeadjust } /OP { 1 index /op known not { dup op } if OP } % The PDF 1.3 specification says that the name /Default is only % recognized for {BG,UCR,TR}2. However, PDF 1.3 files produced % by Adobe Acrobat Distiller 4.0 for Windows use the name /Default % with the older keys, so we have to implement this. /BG { 1 index /BG2 known { pop } { gsbg } ifelse } /UCR { 1 index /UCR2 known { pop } { gsucr } ifelse } /TR { 1 index /TR2 known { pop } { gstr } ifelse } /HT { dup /Default eq { pop .setdefaulthalftone } { %****** DOESN'T IMPLEMENT THE STREAM CASE YET ****** resolvehalftone sethalftone } ifelse % the transfer function may dependent on the halftone, so make sure % it is set if included in the graphic state (otherwise this is % subject to order of a dictionary forall, which is unpredictable) dup /TR2 .knownget { dup /Default eq { oforce gsparamdict /TR2 get exec } { pop } ifelse } { dup /TR .knownget { /dup /Default eq { oforce gsparamdict /TR get exec } { pop } ifelse } if } ifelse } /HTP { % HTP may be present even if this isn't a DPS interpreter. /sethalftonephase where { pop aload pop sethalftonephase } { pop } ifelse } % PDF 1.3 /Font { aload pop Tf } /LW { setlinewidth } /LC { setlinecap } /LJ { setlinejoin } /ML { 1 .max setmiterlimit } /D { aload pop setdash } /RI { ri } /op { op } /OPM { OPM } /BG2 { gsbg } /UCR2 { gsucr } /TR2 { gstr } /FL { 1 .min setflat } /SM { % SM may be present even if this is only a Level 2 interpreter. /setsmoothness where { pop setsmoothness } { pop } ifelse } % PDF 1.4 % All of these require the "transparency" feature in the interpreter. /ca { ca } /CA { CA } /SMask { gssmask } /AIS { AIS } /BM { BM } /TK { TK } .dicttomark readonly def /gs { % <gsres> gs - Page /ExtGState rget { % We keep the dictionary on the stack during the forall so that % keys that interact with each other have access to it. dup { oforce exch gsparamdict exch .knownget { exec } { pop } ifelse } forall pop } if } bdef % ------ Transparency support ------ % /gssmask { dup /None eq PDFusingtransparency not or { pop null } { % Preprocess the SMask value into a parameter dictionary for % .begintransparencymaskgroup, 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 { dup /Background exch 4 2 roll gsave 1 index /G oget /Group oget /CS knownoget { csresolve dup setgcolorspace csput } if aload pop setcolor [ currentgray ] grestore /GrayBackground 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 % This procedure is called to actually render the soft mask. /.execmaskgroup { % <masknum> <paramdict> <formdict> .execmaskgroup - % Save our place in PDFfile, and do a gsave to avoid resetting % the color space. currentcolorspace 4 1 roll PDFfile fileposition 4 1 roll % We have to select the group's color space so that the % background color will be interpreted correctly. dup /Group oget /CS knownoget { csresolve dup setgcolorspace csput } if exch dup /BBox get aload pop .begintransparencymaskgroup { dup /Resources knownoget { oforce } { 0 dict } ifelse exch false resolvestream .execgroup .endtransparencymask } stopped { .discardtransparencymask stop } if PDFfile exch setfileposition setcolorspace } bdef % Paint a Form+Group XObject, either for a transparency mask or for a Do. /.execgroup { % <resdict> <stream> .execgroup - gsave //nodict begin null SMask 1 .setopacityalpha 1 .setshapealpha 0 .inittransparencymask 1 .inittransparencymask /Compatible .setblendmode % Execute the body of the Form, similar to DoForm. pdfopdict .pdfruncontext end grestore } bdef /.beginformgroup { % groupdict bbox .beginformgroup - exch mark exch % bbox mark groupdict dup /CS knownoget { csresolve setgcolorspace } if dup /I knownoget { /Isolated exch 3 2 roll } if dup /K knownoget { /Knockout exch 3 2 roll } if pop .dicttomark % Stack: bbox paramdict exch aload pop .begintransparencygroup } bdef % .paintgroupform implements the Form PaintProc in the case where the % Form XObject dictionary includes a Group key. See .paintform below. /.paintgroupform { % <resdict> <stream> <formdict> .paintgroupform - dup /Group oget exch /BBox oget % Stack: resdict stream groupdict bbox .beginformgroup { .execgroup } stopped { .discardtransparencygroup stop } if .endtransparencygroup } bdef % Make an ImageType 103 (soft-masked) image. /makesoftmaskimage { % <datasource> <imagemask> <SMask> makesoftmaskimage % <datasource> <imagemask>, updates currentdict = % imagedict % See the ImageType 3 case of makemaskimage below. % SMask is a stream, another Image XObject. % Stack: datasource imagemask(false) smaskstreamdict PDFfile fileposition exch dup /Matte knownoget { /Matte exch def } if 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 103 def /DataDict exch def dup /InterleaveType 3 put DataDict /Matte knownoget { /Matte exch def } if AlphaIsShape { /ShapeMaskDict } { /OpacityMaskDict } ifelse exch def /ColorSpace DataDict /ColorSpace get def } bdef % ---------------- Color setting ---------------- % /01_1 [0 1] readonly def /01_3 [0 1 0 1 0 1] readonly def /01_4 [0 1 0 1 0 1 0 1] readonly def % 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