diff options
Diffstat (limited to 'Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps')
-rw-r--r-- | Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps | 524 |
1 files changed, 270 insertions, 254 deletions
diff --git a/Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps b/Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps index e18a7c27f31..a359a9c11c3 100644 --- a/Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps +++ b/Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps @@ -501,8 +501,8 @@ end ( Output may be incorrect.\n) pdfformaterror //pdfdict /.gs_warning_issued //true .forceput PDFSTOPONERROR { /gs /undefined signalerror } if - } if - } + } executeonly if + } executeonly ifelse } bind executeonly def @@ -911,6 +911,16 @@ currentdict /csncompdict undef << exch { oforce resolvecolorspace } forall >> /Colorants exch >> % Finish new attributes dict } if + % devn_array devn_array <<..attributes..>> + 1 index 4 oget /Process knownoget { + dup /ColorSpace knownoget { + 1 index exch resolvecolorspace /ColorSpace exch put + } if + % devn_array devn_array <<..attributes..>> <<..Process..>> + 1 index + /Process 3 -1 roll + put + } if 4 exch put % Put resolved or new attributes dict } if } bind executeonly def @@ -1142,7 +1152,7 @@ currentdict end readonly def .setglobal pdfformaterror } executeonly ifelse - } + } executeonly { currentglobal //pdfdict gcheck .setglobal //pdfdict /.Qqwarning_issued //true .forceput @@ -1150,8 +1160,8 @@ currentdict end readonly def pdfformaterror } executeonly ifelse end - } ifelse - } loop + } executeonly ifelse + } executeonly loop { (\n **** Error: File has unbalanced q/Q operators \(too many q's\)\n Output may be incorrect.\n) //pdfdict /.Qqwarning_issued .knownget @@ -1165,14 +1175,14 @@ currentdict end readonly def .setglobal pdfformaterror } executeonly ifelse - } + } executeonly { currentglobal //pdfdict gcheck .setglobal //pdfdict /.Qqwarning_issued //true .forceput .setglobal pdfformaterror } executeonly ifelse - } if + } executeonly if pop % restore pdfemptycount @@ -1386,7 +1396,6 @@ drawopdict begin /W* { W* } executeonly def /sh_save 1 array def - /sh_group << /Subtype /Group /Isolated //true >> readonly def /do_shade { 0 .setoverprintmode @@ -1407,38 +1416,19 @@ drawopdict begin setfillstate resolvesh //sh_save 0 save put PDFusingtransparency { - .currentSMask //null ne { - //sh_group - 1 index /BBox knownoget { - { oforce } forall - } { - gsave clippath pathbbox grestore - } ifelse - .begintransparencygroup - } if - dup checkOPtrans exch 1 index { - % We need to push a non-isolated, non-knockout transparency group and - % perform the operation in CompatibleOverprint mode, then end the - % transparency group. Do the begintransparencygroup step here. - mark /Subtype /Group /Isolated //false .dicttomark - 1 index /BBox knownoget { - { oforce } forall - } { - gsave clippath pathbbox grestore - } ifelse - .begintransparencygroup - exch .currentblendmode exch .currentopacityalpha exch 4 -1 roll % save current values - /CompatibleOverprint .setblendmode 1 .setopacityalpha - } if - //do_shade exec - { - .endtransparencygroup .setopacityalpha .setblendmode % end the CompatibleOverprint group - } if - .currentSMask //null ne { - .endtransparencygroup - } if + gsave + dup /BBox knownoget { + { oforce } forall + 4 2 roll moveto exch 0 lineto 0 exch lineto closepath + } { + clippath + } ifelse + //null setup_trans + grestore + //do_shade exec + teardown_trans } { - //do_shade exec + //do_shade exec } ifelse //sh_save 0 get restore } { @@ -1706,6 +1696,95 @@ currentdict /jp2_csp_dict .undef /DecodeParms exch put % <resdict> } bind executeonly def +% Add a key-value pair to the all the /DecodeParms +% dictionaries (i.e. handle the array) +% Copy the objects to avoid spoiling shared ones. +% <resdict> <patch dict> -> <resdict> +/add-to-all-params { + 1 index % <resdict> <patch dict> <resdict> + /Filter knownoget + { % <resdict> <patch dict> </name or [array]> + dup type /arraytype eq + { + length % <resdict> <patch dict> <len> + dup 0 gt + { + 2 index /DecodeParms + knownoget + { + oforce_recursive % resolve indirect references + exch pop % <resdict> <patch dict> [array] + [ + exch + { + dup type /dicttype eq + { + mark exch {} forall .dicttomark + } + { + pop 1 dict + } ifelse + } forall + ] % <resdict> <patch dict> [array] + } + { % <resdict> <patch dict> <len> + % create an array of dictionaries + [ + 0 1 4 -1 roll 1 sub + { pop 1 dict } for + ] + % <resdict> <patch dict> [array] + } ifelse + dup % <resdict> <patch dict> [array] [array] + { % <resdict> <patch dict> [array] [dict] + 2 index % <resdict> <patch dict> [array] [dict] <patch dict> + { % <resdict> <patch dict> [array] [dict] </key> <value> + 2 index % <resdict> <patch dict> [array] [dict] </key> <value> [dict] + 3 1 roll + put + } forall + pop + } forall + % <resdict> <patch dict> [array] + exch pop + % <resdict> [dict/array] + 1 index exch /DecodeParms exch put + } + { + pop pop + } ifelse + } + { % <resdict> <patch dict> </name> + pop + 1 index + /DecodeParms knownoget + { + oforce_recursive + dup type /dicttype eq + { + mark exch {} forall .dicttomark + } + { + pop 1 dict + } ifelse + } + { + 1 dict + } ifelse % <resdict> <patch dict> [dict] + + 1 index % <resdict> <patch dict> [dict] <patch dict> + { % <resdict> <patch dict> [dict] </key> <value> + 2 index + 3 1 roll put + } forall + exch pop + % <resdict> [dict/array] + 1 index exch /DecodeParms exch put + } ifelse + } + {pop} ifelse +} bind def + /last-ditch-bpc-csp { currentdict /BitsPerComponent oknown not { ( **** Error: image has no /BitsPerComponent key; assuming 8 bit.\n) @@ -1825,6 +1904,9 @@ currentdict /jp2_csp_dict .undef % Even though we're going to read data, % pass false to resolvestream so that % it doesn't try to use Length (which may not be present). + + % Bug 701083: We add a /ErrsAsEOD key to the DecodeParms here too. + <</ErrsAsEOD //true>> //add-to-all-params exec //false resolvestream /DataSource exch def //true } { @@ -1971,89 +2053,10 @@ currentdict /jp2_csp_dict .undef % filter, create one and add a /Height key. This is to solve the problem % in Bug #695116 where a JPEG image has a bad height, which is later % fixed up using a DNL marker. By placing the image height from the - % PDF in the DeoceParms we cna use it in the DCTDecode filter to + % PDF in the DecodeParms we can use it in the DCTDecode filter to % work around this. - dup /Filter knownoget { % <<stream dict>> /name or [array] - dup type /arraytype eq { - % <<stream dict>> [array of names] - length % <<stream dict>> number of filters - 1 index /DecodeParms knownoget { - exch pop % drop length of Filter array, the DecodeParams has 1 entry per filter - % <<stream dict>> [array of decodeparams] - } { - % No deocde params, we must make an array of them - % <<stream dict>> number of filters - array % <<stream dict>> [] - dup % <<stream dict>> [] [] - 2 index /DecodeParms exch % <<stream dict>> [] [] /DecodeParms <<stream dict>> - 3 1 roll % <<stream dict>> <<stream dict>> [] /DecodeParms - exch put % <<stream dict>> [] - } ifelse - dup length 1 sub % <<stream dict>> [] arraylength-1 - 0 1 3 -1 roll % <<stream dict>> [] 0 1 arraylength-1 - { % <<stream dict>> [] loopcount - 1 index % <<stream dict>> [] loopcount [] - 2 copy % <<stream dict>> [] loopcount [] loopcount [] - exch - get % <<stream dict>> [] loopcount [] <<>> or -null- - dup //null eq { - pop exch % <<stream dict>> [] [] loopcount - <</Height - 5 index /Height oget % <<stream dict>> [] [] loopcount << /Height Height - round cvi - >> - put % <<stream dict>> [] - }{ % - oforce_recursive % resolve any indirect references - dup type /dicttype eq { - % <<stream dict>> [] loopcount [] <<>> - /Height % <<stream dict>> [] loopcount [] <<>> /Height - 5 index /Height oget % <<stream dict>> [] loopcount [] <<>> /Height Height - round - cvi - put pop pop % <<stream dict>> [] - }{ - %% bogus entry, throw it away and create a new one - pop exch % <<stream dict>> [] loopcount [] - <</Height - 5 index /Height oget % <<stream dict>> [] [] loopcount << /Height Height - round cvi - >> - put % <<stream dict>> [] - } ifelse - }ifelse - } for - pop % <<stream dict>> - }{ - pop % <<stream dict>> - dup /DecodeParms knownoget { - oforce_recursive % resolve any indirect references - dup type /dicttype eq { - % <<stream dict>> <<decode parms dict>> - /Height 2 index % <<stream dict>> <<decode parms dict>> /Height <<stream dict>> - /Height oget % <<stream dict>> <<decode parms dict>> /Height ImageHeight - round cvi - put % <<stream dict>> - }{ - %% bogus entry, throw it away and create a new one - pop % <<image dict>> <<stream dict>> [] - <</Height % <<stream dict>> <<image dict>> << /Height - 2 index /Height oget % <<stream dict>> <<image dict>> << /Height Height - round cvi - >> - 1 index exch /DecodeParms exch put % <<stream dict> <<image dict>> - } ifelse - }{ - dup % <<stream dict>> <<stream dict>> - /DecodeParms <</Height % <<stream dict>> <<stream dict>> /DecodeParms << /Height - 3 index % <<stream dict>> <<stream dict>> /DecodeParms << /Height <<stream dict>> - /Height oget - round cvi - >> % <<stream dict>> <<stream dict>> /DecodeParms << /Height ImageHeight>> - put % <<stream dict>> - }ifelse - }ifelse - } if + % Bug 701083: We add a /ErrsAsEOD key to the DecodeParms here too. + << /Height 2 index /Height oget round cvi /ErrsAsEOD //true >> //add-to-all-params exec % Even though we're going to read data, % pass false to resolvestream so that @@ -2064,6 +2067,7 @@ currentdict /jp2_csp_dict .undef } bind executeonly def currentdict /add-to-last-param undef +currentdict /add-to-all-params undef currentdict /last-ditch-bpc-csp undef /DoImage { @@ -2124,13 +2128,15 @@ currentdict /last-ditch-bpc-csp undef 1 BitsPerComponent bitshift 1 sub //false 2 index { % stack: max_value result_bool value dup 0 lt exch 3 index gt or or - } forall exch pop { + } forall exch pop + { ( **** Error: Some elements of Mask array are out of range.\n) pdfformaterror ( Output may be incorrect.\n) pdfformaterror ColorSpace dup type /arraytype eq { 0 oget } if /Indexed eq - BitsPerComponent 1 eq and { + BitsPerComponent 1 eq and + { % AR9 treats Indexed 1 bpc images specially. Bug 692852 see also 697919 and 689717. dup 0 oget dup 0 lt exch 1 BitsPerComponent bitshift ge or { @@ -2140,37 +2146,37 @@ currentdict /last-ditch-bpc-csp undef % Second component is invalid; AR9 replaces it with 1. [ exch 0 oget 1 ] } ifelse - } { - % AR5, AR9 do this for most cases. Bug 690786. - [ exch { 1 BitsPerComponent bitshift 1 sub and } forall ] - } ifelse - } { - ColorSpace dup type /arraytype eq { 0 oget } if /DeviceGray eq - BitsPerComponent 1 eq and { - %% For DeviceGray, try clamping the values to 0 and 1 respectively - dup 0 oget - dup 0 lt exch 1 gt or { - dup 0 oget - dup 0 lt { - pop dup 0 0 put - }{ - dup 0 1 put - } ifelse - } if - dup 1 oget - dup 0 lt exch 1 gt or { - dup 1 oget - dup 0 lt { - pop dup 0 0 put + } + { + BitsPerComponent 1 eq { + dup length 2 gt { + % There are too many Mask entries, discard the Mask array + pop //null }{ - dup 0 1 put + % Bug 701468 and 689717, the latter requires us to set the Mask values + % so that the value is calculated from the BPC, the other requires us + % to ignore the Mask. The only difference between the two files is the + % actual range of the Mask values. This may yet need more work. + % Note! Both files are technically invalid.... + + aload 3 1 roll eq { + % There's only one Mask value, but its illegal, substitute with the + % calculated maximum. + [ exch { 1 BitsPerComponent bitshift 1 sub and } forall ] + } { + % The Mask values are not the same. This is a 2 colour image, if + % we mask off any range then the result will be blank, so ignore the Mask + pop //null + } ifelse } ifelse - } if - }{ - % AR5, AR9 do this for most cases. Bug 690786. - [ exch { 1 BitsPerComponent bitshift 1 sub and } forall ] + } { + % We think AR5, AR9 do this for most other cases. Originally Bug 690786, + % but that is actually handled in the /Indexed case above. + [ exch { 1 BitsPerComponent bitshift 1 sub and } forall ] + } ifelse } ifelse - } ifelse + } if + dup //null ne { /MaskColor exch def } { @@ -2231,7 +2237,7 @@ currentdict /last-ditch-bpc-csp undef PDFfile exch setfileposition 0 .endtransparencymask } ifelse - << /Subtype /Group /Isolated //true + << /Subtype /Group /Isolated //true /.image_with_SMask //true % pdfwrite needs : see gs/src/ztrans.c, gs/src/gdevpdft.c % Code to deal with a Matte in the SMask. We know the image dictionary must have an SMask @@ -2241,7 +2247,7 @@ currentdict /last-ditch-bpc-csp undef % We also need to actually set the current colour space to be the same as the group % code only picks up the current colour space, not the space from the dictionary. currentdict /SMask get /Matte known {/CS currentdict /ColorSpace get dup pdfopdict /cs get exec } if - >> 0 0 1 1 .begintransparencygroup + >> 0 0 1 1 .begintransparencygroup doimage .endtransparencygroup % tell the compositor we're done with the SMask. @@ -2309,15 +2315,6 @@ currentdict /last-ditch-bpc-csp undef /doimage { % <imagemask> doimage - % imagedict is currentdict, gets popped from dstack - //null checkOPtrans { - % We need to push a non-isolated, non-knockout transparency group and - % perform the operation in CompatibleOverprint mode, then end the - % transparency group. Do the begintransparencygroup step here. - mark /Subtype /Group /Isolated //false .dicttomark 0 0 1 1 .begintransparencygroup - OPsavedict dup /saveBM .currentblendmode put /saveOA .currentopacityalpha put % save current values - /CompatibleOverprint .setblendmode 1 .setopacityalpha - } if - %% save the current rendering intent .currentrenderintent exch @@ -2339,6 +2336,7 @@ currentdict /last-ditch-bpc-csp undef makemaskimage } if % Stack: datasource imagemask + gsave 1 1 moveto 0 0 lineto /image setup_trans grestore { currentdict end setfillstate //true ValidateDecode { imagemask } } { ColorSpace setgcolorspace currentdict end setfillblend //false ValidateDecode { image } } ifelse @@ -2363,10 +2361,7 @@ currentdict /last-ditch-bpc-csp undef %% restore the rendering intent .setrenderingintent - .currentblendmode /CompatibleOverprint eq { - .endtransparencygroup - OPsavedict dup /saveOA get .setopacityalpha /saveBM get .setblendmode - } if + teardown_trans } bind executeonly def /.paintform { % <formdict> <resdict> <stream> .paintform - @@ -4348,37 +4343,46 @@ currentdict /set_bc_color undef /k {setcmykcolor} /K {setcmykcolor} >> def + dup /DA knownoget { length string /tempstr exch def dup /DA get tempstr copy pop + + gstate + mark { - %% This is kind of ugly, we use token to process the string - %% and process each token separately. - tempstr - token { - exch /tempstr exch def - %% If the token is a name - %% - dup type /nametype eq { - %% Is it a name we want to take actionon - dup DA_Action_Dict exch known { - DA_Action_Dict exch get exec + { + %% This is kind of ugly, we use token to process the string + %% and process each token separately. + tempstr + token { + exch /tempstr exch def + %% If the token is a name + %% + dup type /nametype eq { + %% Is it a name we want to take actionon + dup DA_Action_Dict exch known { + DA_Action_Dict exch get exec + }{ + %% Its not a name we know, is it executable + dup xcheck {exec} if + } ifelse }{ - %% Its not a name we know, is it executable - dup xcheck {exec} if - } ifelse + %% Not a name, just make it executable and execute it + cvx exec + }ifelse }{ - %% Not a name, just make it executable and execute it - cvx exec + exit }ifelse - }{ - exit - }ifelse - } loop + } loop + } stopped + {cleartomark setgstate} + {cleartomark pop} ifelse } { 0 setgray /Helvetica findfont 12 scalefont setfont }ifelse + %% draw the border, if we don't have a border style dictionary, draw a default one. dup /BS knownoget { pop dup drawborder @@ -4401,58 +4405,69 @@ currentdict /set_bc_color undef %% Get the Contents string, if we don't have one, we're done %% 2 index /Contents knownoget { - PDFusingtransparency { - .begintransparencytextgroup - } if - %% Check for UTF16-BE, we probably don't work properly with this yet. - %% - dup 0 get 254 eq 1 index 1 get 255 eq and - { - /FallBackFont /Identity-UTF16-H [/CIDFallBack] composefont 12 scalefont setfont - dup length 2 div 1 sub 0 1 3 -1 roll { - %% llx urx (string) index - 1 index exch 2 mul 2 getinterval %% llx urx (string) (substring) - dup stringwidth pop currentpoint pop add 3 index gt { - currentpoint exch pop 4 index exch 12 sub moveto - } if - show - } for - pop - } - { - %% Heuristic to determine the height (ascender to descender) of the text - %% for when we move down a line. - gsave - /..TextHeight (Hy) //false charpath pathbbox exch pop exch sub exch pop def - grestore - %% and use it immediatley to start the text one line down - %% - currentpoint ..TextHeight sub moveto - - %% Now we process each character code in the string. If we find - %% a /r/ or /n then we drop a line. If the character would end up - %% outside the Annot Rect, then we drop a line before showing it. - %% - dup length 1 sub 0 1 3 -1 roll { - %% llx urx (string) index - 1 index exch get %% llx urx (string) int - dup 10 eq 1 index 13 eq or { - pop - currentpoint exch pop 3 index exch ..TextHeight sub moveto - } { - 1 string dup 0 4 -1 roll - put dup %% llx urx (string) (int) (int) - stringwidth pop currentpoint pop add 3 index gt { - currentpoint exch pop 4 index exch ..TextHeight sub moveto + dup length 0 gt { + PDFusingtransparency { + .begintransparencytextgroup + } if + %% Check for UTF16-BE, we probably don't work properly with this yet. + %% (If the string is less than 4 bytes its either not UTF16-BE or it is + %% but has no actual content) + dup length 4 ge { + dup 0 get 254 eq 1 index 1 get 255 eq and + }{ + //false + } ifelse + + { + /FallBackFont /Identity-UTF16-H [/CIDFallBack] composefont 12 scalefont setfont + dup length 2 div 1 sub 0 1 3 -1 roll { + %% llx urx (string) index + 1 index exch 2 mul 2 getinterval %% llx urx (string) (substring) + dup stringwidth pop currentpoint pop add 3 index gt { + currentpoint exch pop 4 index exch 12 sub moveto } if show - } ifelse - } for + } for + pop + } + { + %% Heuristic to determine the height (ascender to descender) of the text + %% for when we move down a line. + gsave + /..TextHeight (Hy) //false charpath pathbbox exch pop exch sub exch pop def + grestore + %% and use it immediatley to start the text one line down + %% + currentpoint ..TextHeight sub moveto + + %% Now we process each character code in the string. If we find + %% a /r/ or /n then we drop a line. If the character would end up + %% outside the Annot Rect, then we drop a line before showing it. + %% + dup length 1 sub 0 1 3 -1 roll { + %% llx urx (string) index + 1 index exch get %% llx urx (string) int + dup 10 eq 1 index 13 eq or { + pop + currentpoint exch pop 3 index exch ..TextHeight sub moveto + } { + 1 string dup 0 4 -1 roll + put dup %% llx urx (string) (int) (int) + stringwidth pop currentpoint pop add 3 index gt { + currentpoint exch pop 4 index exch ..TextHeight sub moveto + } if + show + } ifelse + } for + pop + }ifelse + PDFusingtransparency { + .endtransparencytextgroup + } if + } + { pop - }ifelse - PDFusingtransparency { - .endtransparencytextgroup - } if + } ifelse } if pop pop //endannottransparency exec @@ -5029,18 +5044,17 @@ currentdict /drawannottypes undef currentdict end readonly def /preserveannot { % <annot> preserveannot - - dup /.gs.pdfobj# known { dup /.gs.pdfobj# undef } if - dup annotvisible { - gsave - dup dup /Subtype knownoget { - dup //.PDFDrawAnnotType? exec + gsave + dup dup /Subtype knownoget { + dup //.PDFDrawAnnotType? exec + { + //preserveannottypes exch .knownget { exec } { //true } ifelse { - //preserveannottypes exch .knownget { exec } { //true } ifelse - { + dup annotvisible { dup calc_annot_scale 2 copy mul 0 ne { 3 -1 roll drawwidget @@ -5049,18 +5063,20 @@ currentdict end readonly def ( **** Error: ignoring annotation with scale factor of 0\n) pdfformaterror ( Output may be incorrect.\n) pdfformaterror }ifelse % Draw rejected annots as widgets - } if - } - {pop} ifelse - % type known - } { - pop - ( **** Error: Ignoring /Annot dict without required /Subtype entry.\n) - pdfformaterror - ( Output may be incorrect.\n) pdfformaterror - } ifelse - grestore - } if pop % annotvisible + } { + pop + }ifelse + } if + } + {pop} ifelse + % type known + } { + pop + ( **** Error: Ignoring /Annot dict without required /Subtype entry.\n) + pdfformaterror + ( Output may be incorrect.\n) pdfformaterror + } ifelse + grestore } bind executeonly def currentdict /preserveannottypes undef |