diff options
Diffstat (limited to 'Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps')
-rw-r--r-- | Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps | 644 |
1 files changed, 516 insertions, 128 deletions
diff --git a/Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps b/Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps index 88da2de7485..68a56a3674b 100644 --- a/Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps +++ b/Master/tlpkg/tlgs/Resource/Init/pdf_draw.ps @@ -26,34 +26,6 @@ pdfdict begin % PDF graphics operations, even though this is too liberal. /drawopdict 100 dict def -/SetGroupExtGStateDict -<< - /AlphaIsShape //AIS - /FillConstantAlpha //ca - % We don't have to worry about the enumeration order, even - % with the color/space settings, since we only store, not - % not set them. - /FillColor //sc1 - /FillColorSpace { /FillColorSpace gput } bind - /FillOverprint //op - /SoftMask //SMask - /StrokeConstantAlpha //CA - /StrokeColor //SC1 - /StrokeColorSpace { /StrokeColorSpace gput } bind - /StrokeOverprint //OP - /TextSpacing //Tc - % We can't use //Tz as we've stored the value we actually use, - % not value * 100 (see /Tz in pdf_ops.ps) - /TextHScaling { /TextHScaling gput } bind - /Leading //TD - /TextFont { /TextFont gput} bind - /TextLineMatrix { /TextLineMatrix gput } bind - /TextMatrix { /TextMatrix gput } bind - /TextRise { /TextRise gput } bind - /TextRenderingMode { /TextRenderingMode gput } bind - /WordSpacing //Tw ->> def - % ================================ Graphics ================================ % % ---------------- Functions ---------------- % @@ -156,6 +128,20 @@ pdfdict begin 1 index /Default eq { exch pop } { pop resolveidfnproc } ifelse } bdef +%% A BBox where width or height (or both) is 0 should still paint one pixel +%% See the ISO 32000-2:2017 spec, section 8.7.4.3, p228 'BBox' and 8.7.3.1 +/FixPatternBBox +{ + dup aload pop + 3 index 2 index sub 0 eq { + 3 index 0.000001 add 3 -1 roll pop exch + } if + 2 index 1 index sub 0 eq { + 2 index 0.000001 add exch pop + }if + 5 -1 roll astore +}bind def + % ---------------- Shadings ---------------- % /shrdict mark @@ -177,6 +163,7 @@ pdfdict begin /BBox { dup dup dup aload pop normrect_elems 5 -1 roll astore + FixPatternBBox } bind /ColorSpace { resolvecolorspace @@ -472,6 +459,13 @@ end /AIS { AIS } /BM { BM } /TK { TK } + /UseBlackPtComp { UseBlackPtComp } + /HTO { + % PDF 2.0, supposed to be 'similar' to halftone phase but using a different + % co-ordiate system. Treat the same for now and fix if anyone ever complains. + aload pop transform cvi exch cvi exch 2 array astore + dup sethalftonephases .swapcolors sethalftonephases .swapcolors + } .dicttomark readonly def /gs { % <gsres> gs - Page /ExtGState rget { @@ -502,7 +496,8 @@ end dup /None eq 1 index //null eq or PDFusingtransparency not or { pop //null - SoftMask //null ne { + + .currentSMask //null ne { % get rid of the current SMask (Bug 695471) false % colorspace not set << /Subtype /None >> % Special type for this purpose @@ -558,18 +553,9 @@ end /GroupGState gstate currentgstate 6 2 roll grestore /GroupMat matrix currentmatrix 8 2 roll - /GroupExtGState 1 dict - //SetGroupExtGStateDict - { - exch dup where - { - exch get 2 index 3 1 roll put - } - { - pop pop - } ifelse - } forall - 10 2 roll +% /GroupExtGState 1 dict +% 10 2 roll + /.execmaskgroup cvx 2 packedarray cvx /Draw exch 3 2 roll pop .dicttomark @@ -634,48 +620,62 @@ def 3 -1 roll dup dup 4 1 roll /BBox get aload pop .begintransparencymaskgroup exch dup /Resources knownoget { oforce } { 2 dict } ifelse - 3 -1 roll dup /GroupGState .knownget { 2 index /GroupGState 3 -1 roll put} if - /GroupExtGState .knownget { 1 index /GroupExtGState 3 -1 roll put} if + 3 -1 roll /GroupGState .knownget { 1 index /GroupGState 3 -1 roll put} if exch //false resolvestream - 1 index exch .execgroup + 1 index exch + + %% Get the current colour space and colour values (as an array), we need to pass these to .execgroup + %% as well, so that it can restore them, in case the colour space gets changed by transparency + %% graphics state stuff. + mark currentcolor counttomark array astore exch pop + currentcolorspace 4 2 roll + + .execgroup % We have to remove these in case the Form XObject is subsequently used as % a form rather than a group - they remain in the paramdict for the SMask % so this will all still work if the SMask is re-evaluated. - dup /GroupGState undef - /GroupExtGState undef + /GroupGState undef + .endtransparencymask PDFfile exch setfileposition mark exch /OverrideICC exch .dicttomark setuserparams .setuseciecolor setcolorspace setcolor setmatrix end % restore colorspace, color and ExtGState (end) - /SoftMask where pop /SoftMask //true put % special setting to tell us it has been rendered + .currentSMask /Processed //true put % special setting to tell us it has been rendered } bdef % Paint a Form+Group XObject, either for a transparency mask or for a Do. -/.execgroup { % <resdict> <stream> .execgroup - +/.execgroup { % [colour values] <colour space> <resdict> <stream> .execgroup - pdfemptycount 3 1 roll - /pdfemptycount count 3 sub store + /pdfemptycount count 5 sub store gsave //nodict begin % We have to set the gstate correctly for lazy evaluation of a softmask group. - % we also must preserve the color(space) as setup in .execmaskgroup. + % we also must restore the color(space) as setup in .execmaskgroup or paintformgroup. % This stuff must be done here, as .execmaskgroup can't use gsave/grestore to % manipulate the gstates, due to the requirements of .begintransparencymaskgroup. % We also must set the ExtGState values. % It may seem redundant to do the color(space) twice (once here and once in % .execmaskgroup) but we have to set it in .execmaskgroup for the background % color and set it here once in the correct gstate. - mark currentcolor currentcolorspace counttomark 2 add index dup + 1 index /GroupGState .knownget { setgstate } if - /GroupExtGState .knownget { { exch exec } forall } if - setcolorspace setcolor pop + newpath //null SMask 1 .setopacityalpha 1 .setshapealpha 1 CA 1 ca /Compatible .setblendmode % Execute the body of the Form, similar to DoForm. - pdfopdict .pdfruncontext + pdfopdict + + %% Restore the colour space (passed in on the stack) and current colour + %% + 6 -2 roll + setcolorspace + aload pop setcolor + + .pdfruncontext end grestore /pdfemptycount exch store } bdef @@ -694,6 +694,11 @@ def % .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 - + %% Pass the current color space, and an array with the current color vales + %% as arguments to .execgroup + mark currentcolor counttomark array astore exch pop + currentcolorspace 5 2 roll + dup /Group oget exch /BBox oget % Stack: resdict stream groupdict bbox .beginformgroup @@ -730,7 +735,8 @@ def DataDict /Matte knownoget { /Matte exch def } if - AlphaIsShape { /ShapeMaskDict } { /OpacityMaskDict } ifelse exch def + .currentalphaisshape + { /ShapeMaskDict } { /OpacityMaskDict } ifelse exch def /ColorSpace DataDict /ColorSpace get def } bdef @@ -1055,13 +1061,16 @@ currentdict end readonly def } { % For uncolored patterns, we have to unbind the current % color and color space before running the PaintProc. - //null sc1 //null SC1 + % Not true since moving the ExtGState parameters into the gstate. + % //null sc1 //null SC1 } ifelse % Save old values on opstack, set pdfemptycount to new value. pdfemptycount countdictstack mark - /pdfemptycount count 3 sub def 5 3 roll + %% We can't simply 'def' into the dictionary saved by 'q' above, we need to + %% call gput to copy it and store inside it. Stupid or what.... + /pdfemptycount count 3 sub gput 5 3 roll % % Stack: ... <old emptycount> <dictcount> mark <patdict> <resdict> % | @@ -1074,11 +1083,51 @@ currentdict end readonly def { countdictstack 2 index le { exit } if currentdict /n known not or - Q - } loop { - ( **** Error: Pattern stream has unbalanced q/Q operators \(too many q's\)\n) - pdfformaterror - ( Output may be incorrect.\n) pdfformaterror + currentdict /n known currentdict /self known or{ + Q + }{ + (\n **** Error: File has unbalanced q/Q operators \(too many Q's\)\n Output may be incorrect.\n) + pdfdict /.Qqwarning_issued .knownget + { + { + pop + } + { + currentglobal pdfdict gcheck .setglobal + pdfdict /.Qqwarning_issued //true .forceput + .setglobal + pdfformaterror + } ifelse + } + { + currentglobal pdfdict gcheck .setglobal + pdfdict /.Qqwarning_issued //true .forceput + .setglobal + pdfformaterror + } ifelse + end + } ifelse + } loop + { + (\n **** Error: File has unbalanced q/Q operators \(too many q's\)\n Output may be incorrect.\n) + pdfdict /.Qqwarning_issued .knownget + { + { + pop + } + { + currentglobal pdfdict gcheck .setglobal + pdfdict /.Qqwarning_issued //true .forceput + .setglobal + pdfformaterror + } ifelse + } + { + currentglobal pdfdict gcheck .setglobal + pdfdict /.Qqwarning_issued //true .forceput + .setglobal + pdfformaterror + } ifelse } if pop @@ -1150,7 +1199,7 @@ currentdict end readonly def 2 index /Resources knownoget { oforce } { 0 dict } ifelse /.pdfpaintproc cvx ] cvx put - dup /BBox 2 copy knownoget { normrect put } { pop pop } ifelse + dup /BBox 2 copy knownoget { normrect FixPatternBBox put } { pop pop } ifelse dup /.pattern_uses_transparency 1 index patternusestransparency put PDFDEBUG { pdfdict /PDFSTEPcount .knownget { 1 le } { //true } ifelse { (%Pattern: ) print dup === flush } if } if } bdef @@ -1189,7 +1238,12 @@ drawopdict begin /sc { .incachedevice { .pdfcount { pop } repeat //ignore_color_op pdfformaterror } { - scresolve { sc*_and_set } { sc1_and_set } ifelse + scresolve 1 index //null eq { + pop pop + //ignore_color_op pdfformaterror + } { + { sc*_and_set } { sc1_and_set } ifelse + } ifelse } ifelse } bdef @@ -1233,7 +1287,12 @@ drawopdict begin /SC { .incachedevice { .pdfcount { pop } repeat //ignore_color_op pdfformaterror } { - scresolve { SC*_and_set } { SC1_and_set } ifelse + scresolve 1 index //null eq { + pop pop + //ignore_color_op pdfformaterror + }{ + { SC*_and_set } { SC1_and_set } ifelse + }ifelse } ifelse } bdef @@ -1300,7 +1359,7 @@ drawopdict begin setfillstate resolvesh //sh_save 0 save put PDFusingtransparency { - SoftMask //null ne { + .currentSMask //null ne { //sh_group 1 index /BBox knownoget { { oforce } forall @@ -1327,7 +1386,7 @@ drawopdict begin { .endtransparencygroup .setopacityalpha .setblendmode % end the CompatibleOverprint group } if - SoftMask //null ne { + .currentSMask //null ne { .endtransparencygroup } if } { @@ -1359,7 +1418,7 @@ end /CIEBasedABC { 1 get /RangeABC knownoget not { //01_3 } if } bind /CalGray { pop //01_1 } bind /CalRGB { pop //01_3 } bind - /Lab { 1 get /Range knownoget not { [-100 100 -100 100] } if } bind + /Lab { 1 get /Range knownoget not { [-100 100 -100 100] } {aload pop 0 100 6 2 roll 6 array astore}ifelse } bind /ICCBased { 1 oget dup /Range knownoget { exch pop @@ -2024,7 +2083,7 @@ currentdict /last-ditch-bpc-csp undef ColorSpace dup type /arraytype eq { 0 oget } if /Indexed eq BitsPerComponent 1 eq and { - % AR9 treats Indexed 1 bpc images specially. Bug 692852. + % 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 { % First component is invalid - AR9 ignores the mask @@ -2037,7 +2096,33 @@ currentdict /last-ditch-bpc-csp undef % AR5, AR9 do this for most cases. Bug 690786. [ exch { 1 BitsPerComponent bitshift 1 sub and } forall ] } ifelse - } if + } { + 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 + }{ + dup 0 1 put + } ifelse + } if + }{ + % AR5, AR9 do this for most cases. Bug 690786. + [ exch { 1 BitsPerComponent bitshift 1 sub and } forall ] + } ifelse + } ifelse dup //null ne { /MaskColor exch def } { @@ -2089,7 +2174,7 @@ currentdict /last-ditch-bpc-csp undef .begintransparencymaskimage PDFfile fileposition exch gsave //nodict begin - //null /SoftMask gput + //null .setSMask 1 .setopacityalpha 1 .setshapealpha 1 CA 1 ca /Compatible .setblendmode @@ -2109,7 +2194,7 @@ currentdict /last-ditch-bpc-csp undef % on our lazy evaulation of SMask groups false << /Subtype /None >> 0 0 0 0 .begintransparencymaskgroup } { - SoftMask //null ne { + .currentSMask //null ne { % the image doesn't have an SMask, but the ExtGState does, force a group. << /Subtype /Group /Isolated //true >> 0 0 1 1 .begintransparencygroup doimage @@ -2128,6 +2213,44 @@ currentdict /last-ditch-bpc-csp undef } bdef } if +/ValidateDecode { % <<image dict>> -imagemask- ValidateDecode <<image dict>> + exch + dup /Decode .knownget { + dup length % -imagemask- <<image dict>> [Decode] length + 4 -1 roll % <<image dict>> [Decode] length -imagemask- + { + 1 % ImageMask Decode arrays must be [0 1] or [1 0] + } + { + mark currentcolor counttomark % <<image dict>> [Decode] length [ ... component_count + dup 2 add 1 roll % <<image dict>> [Decode] length component_count [ .... + cleartomark % <<image dict>> [Decode] length component_count + } ifelse + 2 mul dup % <<image dict>> [Decode] length comp_count*2 comp_count*2 + 3 1 roll % <<image dict>> [Decode] comp_count*2 length comp_count*2 + eq { % <<image dict>> length of Decode matches colour space requirement + pop pop % <<image dict>> remove [Decode] and comp_count*2 + }{ % <<image dict>> Decode array incorrect + dup 2 index length % <<image dict>> [Decode] comp_count*2 comp_count*2 length + exch sub 0 gt { % Decode is too long + (\n **** Warning: Decode array for an image is too long\n) pdfformatwarning + ( Output may be incorrect.\n) pdfformatwarning + 0 exch % <<image dict>> [Decode] 0 comp_count*2 + getinterval % <<image dict>> [subarray of Decode] + 1 index exch /Decode exch % <<image dict>> <<image dict>> /Decode [subarray] + put % <<image dict>> + }{ + % Decode is too short, Acrobat throws errors on this + (\n **** ERROR: Decode array for an image is too short\n) pdfformaterror + ( Output may be incorrect.\n) pdfformaterror + pop pop % remove [Decode] and comp_count*2 + } ifelse + } ifelse + } { + exch pop + }ifelse +}bdef + /doimage { % <imagemask> doimage - % imagedict is currentdict, gets popped from dstack //null checkOPtrans { @@ -2160,8 +2283,8 @@ currentdict /last-ditch-bpc-csp undef makemaskimage } if % Stack: datasource imagemask - { currentdict end setfillstate { imagemask } } - { ColorSpace setgcolorspace currentdict end setfillblend { image } } + { currentdict end setfillstate true ValidateDecode { imagemask } } + { ColorSpace setgcolorspace currentdict end setfillblend false ValidateDecode { image } } ifelse PDFSTOPONERROR { exec //false } { stopped } ifelse { dup type /dicttype eq { pop } if % Sometimes image fails to restore the stack @@ -2451,7 +2574,61 @@ currentdict end readonly def //ocg_pocs exch get exec % bool } ifelse } { - /OFF known not % OFF is inserted by process_trailer_attrs + dup /OFF known not % OFF is inserted by process_trailer_attrs + { + %% /OC is not in the OCProperties /OFF array, so we need to + %% test its usage. We may eventually have to add a /ON to the dictionary + %% if the OCProperties /ON array defines the /OC, I think that should override + % the Usage, but I don't have an example to test. + /Usage .knownget { + oforce + /Printed where { + /Printed get + } { + //false + }ifelse + { + %% We are behaving as a printer, check the Print state + /Print .knownget { + /PrintState .knownget { + oforce + /OFF eq { + //false + }{ + //true + } ifelse + }{ + //true + } ifelse + }{ + %% If we don't know, assume its visible + //true + } ifelse + }{ + %% We are behaving as a viewer, check the View state + /View .knownget { + oforce + /ViewState .knownget { + /OFF eq { + //false + }{ + //true + } ifelse + }{ + //true + } ifelse + }{ + %% If we don't know, assume its visible + //true + } ifelse + } ifelse + }{ + %% If we don't know, assume its visible + //true + } ifelse + }{ + pop //false + }ifelse } ifelse } { /OFF known not % OFF is inserted by process_trailer_attrs @@ -2480,30 +2657,72 @@ drawopdict begin } if setfillblend PDFfile fileposition exch % pos /Name - dup Page /XObject rget { - exch pop % pos obj - OFFlevels length 0 eq { - dup /OC knownoget { ocg-is-visible } { //true } ifelse - } { + + % Bug #698226, Acrobat signals an error for recursive XObjects in a PDF file + % but continues. This is true even if the XObject is not a simple self-reference + % (eg /Fm1 -> /Fm2 -> /Fm3 -> /Fm1). + % Normally when dealing with recursion we would put a dictionary on the stack, store the + % object numbers encoutnered in it, and check each new object number to see if we've + % already seen it. This doesn't work well for XObjects, because the operand stack can be + % in any state when we run a Do. So we make a new dictionary in pdfdict to hold the + % object numbers. + % We also don't usually know the object number of a Form, we just get given its name + % so we need a new routine to return the object number. This is because the parent XObject + % might reference teh object by one name, while the child references it by another, we + % can't permit clashes. + % + % Start by getting the object number for a Form XObject + dup Page /XObject obj_get dup 0 eq not { + % Now get the recording dictionary and see if that object number has been seen + pdfdict /Recursive_XObject_D get 1 index known { + ( **** Error: Recursive XObject detected, ignoring ") print 1 index 256 string cvs print (", object number ) print 256 string cvs print (\n) print + ( Output may be incorrect.\n) pdfformaterror //false - } ifelse { - dup /Subtype oget //xobjectprocs exch get % pos obj {proc} - % Don't leave extra objects on the stack while executing - % the definition of the form. - 3 -1 roll % obj {proc} pos - 2 .execn % pos + }{ + % We haven't seen it yet, so record it. + pdfdict /Recursive_XObject_D get 1 index null put + 3 1 roll + //true + }ifelse + } + { + % I don't think this should be possible, but just in case + ( **** Error: Unable to determine object number for ) print exch 256 string cvs print ( so ignoring it) print + ( Output may be incorrect.\n) pdfformaterror + //false + } ifelse + + % If we could get the object number, and we haven't already seen it, then execute it. + { + dup Page /XObject rget { + exch pop % pos obj + OFFlevels length 0 eq { + dup /OC knownoget { ocg-is-visible } { //true } ifelse + } { + //false + } ifelse { + dup /Subtype oget //xobjectprocs exch get % pos obj {proc} + % Don't leave extra objects on the stack while executing + % the definition of the form. + 3 -1 roll % obj {proc} pos + 2 .execn % pos + } { + pop % pos + } ifelse } { - pop % pos + % This should cause an error, but Acrobat Reader can + % continue, so we do too. + ( **** Error: Undefined XObject resource: ) + exch =string cvs concatstrings (\n) concatstrings + pdfformaterror + ( Output may be incorrect.\n) pdfformaterror } ifelse - } { - % This should cause an error, but Acrobat Reader can - % continue, so we do too. - ( **** Error: Undefined XObject resource: ) - exch =string cvs concatstrings (\n) concatstrings - pdfformaterror - ( Output may be incorrect.\n) pdfformaterror + PDFfile exch setfileposition + pdfdict /Recursive_XObject_D get exch undef + }{ + % Otherwise ignore it and tidy up the stacks + pop pop } ifelse - PDFfile exch setfileposition } bdef end @@ -2854,11 +3073,15 @@ end dup (BT ) writestring 1 index /DA fget not { 1 index /V fget { - <FEFF> anchorsearch{ - pop pop /FallBackFont /Identity-UTF16-H [/CIDFallBack] composefont 12 scalefont setfont - }{ + <EFBBBF> anchorsearch { pop /Helvetica findfont 12 scalefont setfont - } ifelse + } { + <FEFF> anchorsearch { + pop pop /FallBackFont /Identity-UTF16-H [/CIDFallBack] composefont 12 scalefont setfont + } { + pop /Helvetica findfont 12 scalefont setfont + }ifelse + }ifelse } if () }if @@ -2894,11 +3117,18 @@ end //false exch NeedAppearances { dup /FT fget { - /Tx eq { - dup /V oknown { - pop not 1 - } if - } if + dup /Tx eq { + pop + dup /V oknown { + pop not 1 + } if + } { + /Ch eq { + dup /V oknown { + pop not 1 + } if + } if + } ifelse } if } if pop @@ -2920,6 +3150,7 @@ end % dup /AP undef % } if % } if + dup /AP knownoget { dup /N known not { ( **** Error: Appearance dictionary (AP) lacks the mandatory normal (N) appearance.\n) @@ -3264,6 +3495,12 @@ currentdict /set_bc_color undef /emptydict 0 dict readonly def /Highlight { +% technically we should apply an appearance stream if we have one, but if we do +% some test files don't match Acrobat. PDF 2.0 says appearance streams are mandatory, +% and take precedence over generatig new ones, so we may need to revisit this. +% dup /AP oknown { +% //true +% }{ 0 setlinecap dup annotsetcolor { /QuadPoints knownoget { @@ -3287,6 +3524,7 @@ currentdict /set_bc_color undef } if } if //false +% } ifelse } bdef currentdict /emptydict undef currentdict /highlight-arc undef @@ -3402,7 +3640,7 @@ currentdict /set_bc_color undef { gsave - dup annotrect (rectclip from freetext annotation) == flush rectclip + dup annotrect rectclip dup /CA knownoget { .setopacityalpha @@ -3684,7 +3922,7 @@ currentdict /set_bc_color undef 2 index 2 div add exch 3 index 2 div add exch translate % dx dy - 50 div exch 190 div .min dup scale + 50 div exch 190 div .min dup 0.0 eq {pop 1.0} if dup scale /Name knownoget not { /Draft } if //stamp_dict 1 index known not { exch pop /Draft exch } if @@ -3700,24 +3938,124 @@ currentdict /set_bc_color undef } ifelse } bdef - currentdict /quadpoints2basis undef + /Popup { + dup /Open oknown { + dup /Open get { + dup /AP oknown { + //true + }{ + gsave + newpath + 0.05 setlinewidth + dup /Parent .knownget { + oforce + } { + dup /P .knownget { + oforce + } { + dup + } ifelse + } ifelse + /C .knownget { + aload pop + }{ + 1 1 0 + }ifelse + setrgbcolor + dup /Rect get + dup aload pop + 2 index sub + exch 3 index sub exch + 4 copy + gsave 1 setgray rectfill grestore + gsave 0 setgray rectstroke grestore + 1 index /Parent .knownget { + oforce + }{ + 1 index /P .knownget { + oforce + }{ + 1 index + } ifelse + }ifelse + dup + /Contents .knownget { + gsave + 0 setgray + /Helvetica findfont 9 scalefont setfont + 2 index aload pop 3 1 roll pop pop 30 sub exch 5 add exch + moveto show + grestore + } if + exch + dup aload pop 3 -1 roll pop exch 2 index sub -15 + 4 copy rectfill + 0 setgray rectstroke + exch + /T .knownget { + gsave + 0 setgray + /Helvetica findfont 9 scalefont setfont + dup stringwidth pop + 2 index aload pop pop exch pop exch sub + exch sub 2 div 2 index aload pop 3 1 roll pop pop 11 sub 3 1 roll add exch moveto + show + grestore + } if + grestore + //false + } ifelse + } { + pop //false + }ifelse + } { + pop //false + }ifelse + } bdef + +currentdict /quadpoints2basis undef currentdict end readonly def +/.PDFDrawAnnotType? +{ + //false exch + /ShowAnnotTypes where + { + /ShowAnnotTypes get + { + dup /* eq exch 2 index eq or + { + pop //true exch + exit + } if + } forall + pop + } + {pop pop //true} + ifelse +} bind def + /drawannot { % <annot> drawannot - dup annotvisible { gsave dup dup /Subtype knownoget { - //drawannottypes exch .knownget { exec } { //true } ifelse + dup //.PDFDrawAnnotType? exec { - dup calc_annot_scale 2 copy mul 0 ne - { - 3 -1 roll drawwidget - } + //drawannottypes exch .knownget { exec } { //true } ifelse { - ( **** Error: ignoring annotation with scale factor of 0\n) pdfformaterror - ( Output may be incorrect.\n) pdfformaterror - }ifelse % Draw rejected annots as widgets - } if % type known + dup calc_annot_scale 2 copy mul 0 ne + { + 3 -1 roll drawwidget + } + { + ( **** Error: ignoring annotation with scale factor of 0\n) pdfformaterror + ( Output may be incorrect.\n) pdfformaterror + }ifelse % Draw rejected annots as widgets + } if % type known + } + { + pop + }ifelse } { pop ( **** Error: Ignoring /Annot dict without required /Subtype entry.\n) @@ -3909,17 +4247,22 @@ currentdict end readonly def dup annotvisible { gsave dup dup /Subtype knownoget { - //preserveannottypes exch .knownget { exec } { //true } ifelse + dup //.PDFDrawAnnotType? exec { - dup calc_annot_scale 2 copy mul 0 ne - { - 3 -1 roll drawwidget - } + //preserveannottypes exch .knownget { exec } { //true } ifelse { - ( **** Error: ignoring annotation with scale factor of 0\n) pdfformaterror - ( Output may be incorrect.\n) pdfformaterror - }ifelse % Draw rejected annots as widgets - } if % type known + dup calc_annot_scale 2 copy mul 0 ne + { + 3 -1 roll drawwidget + } + { + ( **** 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) @@ -3931,6 +4274,7 @@ currentdict end readonly def } bdef currentdict /preserveannottypes undef +currentdict /.PDFDrawAnnotType? undef % ============================ AcroForm fields ============================ % @@ -4013,8 +4357,8 @@ currentdict /preserveannottypes undef { 1 index exch write== } forall dup 3 index /MaxLen pget not { 0 } if write= dup 3 index /V pget not { - 3 index /DV pget not { () } if write== - } if + 3 index /DV pget not { () } if + } if write== dup 3 index /Ff pget not { 0 } if write= dup 3 index /Q pget not { 0 } if write= dup (Tform ET) write= @@ -4026,7 +4370,51 @@ currentdict /preserveannottypes undef } bdef /Ch { - (Ch is not yet implemened) //== exec + dup /AP known 3 index /NeedAppearances knownoget not { //true } if not and { + dup 1 1 3 -1 roll drawwidget + } { + %% If we don't have a NeedApperances, treat as true, because Acrobat + %% always regenerates Appearances anyway. + 2 index /NeedAppearances knownoget not { //true } if { + dup /AP << /N 10 dict dup cvx begin >> put + /Subtype /Form def + /BBox [ 0 0 4 index /Rect oget { oforce } forall 3 -1 roll sub abs 3 1 roll sub abs exch ] def + /Resources 3 index /DR pget not { 0 dict } if def + /File 1000 string dup 3 1 roll def + /Length 1000 def + % <acroform> <field> <annot> (string) + /NullEncode filter % <acroform> <field> <annot> file + + dup (BT ) writestring + 2 index /DA pget not { () } if + [ exch + { token { + dup /Tf eq { + 2 index 0 eq { + /BBox load 3 get + 0.75 mul % empirical constant + 4 -1 roll pop 3 1 roll + } if + } if + exch + } { + exit + } ifelse + } loop + ] + { 1 index exch write== } forall + dup 3 index /MaxLen pget not { 0 } if write= + dup 3 index /V pget not { + 3 index /DV pget not { () } if + } if write== + dup 3 index /Ff pget not { 0 } if write= + dup 3 index /Q pget not { 0 } if write= + dup (Tform ET) write= + end + closefile % <acroform> <field> <annot> + dup 1 1 3 -1 roll drawwidget + } if + } ifelse } bdef /Sig { |