Skip to main content
Skip table of contents

Example uses of shadowop


This page applies to Harlequin v13.1r0 and later; both Harlequin Core and Harlequin MultiRIP.

Redefining setgray

This example prints the operand to setgray before calling the true setgray operator. This is the equivalent of the simple redefinition illustrated above.

TEXT
<<
  /setgray {
    (operand: ) = dup == setgray
  } bind
>> 1183615869 internaldict /shadowop get exec

Redefining image and colorimage

This more involved example causes all images (but not masks) to be replaced by equivalently sized gray rectangles. (Recall that the image operator can take a dictionary operand in Level 2 PostScript.)

TEXT
/redefinedimage {
  dup type /dicttype eq {dup} {5 copy} ifelse
  gsave nulldevice image grestore
  gsave
    0.5 setgray
    dup type /dicttype eq {
      begin
        /ImageMatrix load concat
        0 0 Width Height rectfill
      end
    }{
      % w h bps matrix proc
      pop concat pop 0 0 4 -2 roll rectfill
    } ifelse
  grestore
} bind def

<<
  /image /redefinedimage load
  /colorimage { % w h bps matrix dsrc ... dsrc multi ncomp
    % turn it into a dictionary operand image and use the
    % previous redefinition of image
    10 dict begin
      /ImageType 1 def
      /ncompsub1 exch 1 sub def % not used by image op
      /Decode {{0 1}{}{0 1 0 1 0 1}{0 1 0 1 0 1 0 1}}
        ncompsub1 get def
      /MultipleDataSources exch def MultipleDataSources {
        /DataSource [ncompsub1 4 add dup 3 sub roll ] def
      }{
        /DataSource exch def
      } ifelse
      /ImageMatrix exch def
      /BitsPerComponent exch def
      /Height exch def
      /Width exch def currentdict
    end
    gsave
      { /DeviceGray null /DeviceRGB /DeviceCMYK }
      1 index /ncompsub1 get get setcolorspace
      //redefinedimage exec
    grestore
  } bind
>> 1183615869 internaldict /shadowop get exec

Redefining setscreen to use a particular screen angle

The purpose of this example is to change the angle of the screen on each page (this might be needed because we know that the pages are really separations in a pre-separated job). To decide on which page is currently being processed, use the BeginPage procedure of the page device (see [RB3], section 6.2.6).

The example is incomplete in that a full solution would redefine sethalftone and setcolorscreen as well. Recall also that the last operand to setscreen may now possibly be a halftone dictionary (in which case we only do the substitution of the angle if it is a type 1 halftone in this example).

TEXT
/AnglesRequired [15 75 0 45] def

<<
  /BeginPage { % page-number
    //globaldict /SavedPageNo 3 -1 roll 4 mod put
  } bind
>> setpagedevice

<<
  /setscreen {
    dup type /dicttype ne {
      % freq angle proc: replace the angle with ours
      exch pop
      //AnglesRequired
        //globaldict /SavedPageNo get
        get
      exch
    }{
      % freq angle halftone-dictionary
      dup /HalftoneType get 1 eq {
        % replace the dictionary, and an overriding
        % angle on the operand stack with our one for
        % the current page
        dup length dict copy
        dup /Angle
          //AnglesRequired
            //globaldict /SavedPageNo get
            get
          put
        exch pop dup /Angle get exch
      } if
    } ifelse
    setscreen
  } bind
>> 1183615869 internaldict /shadowop get exec

Redefining an application procedure

This example detects that we are running jobs from an application that we know sets up a procedure called XYCropMarks to draw crop marks centered on the point given by the two operands of the procedure. We replace it with a procedure to draw crop marks in our own style, in this example a simple cross. The dictionary operand to shadowop is set up in advance, but only actually applied inside a comment parsing procedure when the name and version of the application has been determined using the %%Creator comment (see Comment parsing).

TEXT
/XYCropMarksDict <<
  /XYCropMarks { % x y
    gsave
      [ /Separation /All /DeviceCMYK { pop 1 1 1 1 } ] setcolorspace
      1 setcolor moveto
      initmatrix % so we work at our own sizes, not the application's
      0.1 setlinewidth 0 [] setdash 1 setlinecap
      0 30 rmoveto 0 -60 rlineto
      30 +30 rmoveto -60 0 rlineto stroke
    grestore
  } bind
>> def

(%%dict) begin (%%actions) begin
  /Creator: [
    /dup load /Creator: load /exec load
    {
      (Mythical Application v2.0) search {
        pop pop
        //XYCropMarksDict 1183615869 internaldict /shadowop get exec
      } if pop
    } /exec load
  ] cvx bind def
end end

currentdict /XYCropMarksDict undef


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.