% FileVersion: 6
% Copyright (c) 2021 Global Graphics Software Ltd. All rights reserved.
%
% This example is provided on an "as is" basis and without
% warranty of any kind. Global Graphics Software Ltd. does not
% warrant or make any representations regarding the use or results
% of use of this example.
%
% This example is the template RIP configuration.

% NOTE: The color config using setreproduction requires a license for
%       the RIP's ColorPro feature.
(Missing license for ColorPro: ) [ /ColorPro ]
ErrorIfNoLicense

<<
  /TransparencyStrategy 2
>>setsystemparams

<<
  /HWResolution [ $HD_DPIX$ $HD_DPIY$ ]

  /PageBufferType /HQNDIRECT
  /ExtraPageDeviceKeys <<
    /RasterParams <<
      /HQNDIRECT <<
      /RasterHeader 24
      /PlaneNumberStart $PLANE_NUMBER$
      >>
    >>
  >>

  $IS_COLOR$ {
    % The output is color.
    /SeparationColorNames [ $ALL_COLOR_NAMES$ ]
    /SeparationOrder [ $COLOR_NAMES$ ]

    /ProcessColorModel /DeviceCMYK
    /SeparationDetails <<
      /Separations false
      /SeparationStyle 4
      /CompositeColorNames [ $COLOR_NAMES$ ]
    >>
  } if

  % We're outputting 8 or 16 bits per pixel contone raster.
  /ValuesPerComponent $Allow16BitSupport$ { 65536 } { 256 } ifelse

  % Frame interleaved.
  /InterleavingStyle 4

  /Halftone false
  /BandHeight 32

  /BeginPage
  {
      pop

      /PageWidth  currentpagedevice /PageSize get 0 get def
      /PageHeight currentpagedevice /PageSize get 1 get def

      % Default to left alignment
      /HorizontalOffset 0 def

      /ScaleX $HD_SCALEX$ def
      /ScaleY $HD_SCALEY$ def
      /ScaleAlignment ($HD_SCALE_ALIGNMENT$) def

      ScaleAlignment (Center) eq {
        /HorizontalOffset PageWidth 2 div def
      } if

      ScaleAlignment (Left) eq {
        /HorizontalOffset 0 def
      } if

      ScaleAlignment (Right) eq {
        /HorizontalOffset PageWidth def
      } if

       HorizontalOffset PageHeight translate
       ScaleX ScaleY scale
       HorizontalOffset -1 mul PageHeight -1 mul translate
  }
  
/InputAttributes <<
    1 << /PageSize [0 0 ] >>
>>

>> setpagedevice

<<
    /Install [
      currentpagedevice /Install get /exec load {
	  $ALIAS_COLORS$
      } bind /exec load
    ] cvx
 >> setpagedevice

%
% Color management.
%

% ====================================================================%
% This is for handling ICC profiles embedded in EPS images
/HqnImportICC /ProcSet findresource /InstallEmbeddedICCHandlers get exec

% Start setting up the CM intercept with a clean slate
null setinterceptcolorspace

[$IgnoreSpotList$] /HqnColorDatabase /ProcSet findresource /AddToIgnoredSpots get exec

$DisablePrinterProfile$ {
  % Only use CM from the job
  % Note that this mode is intended for calibration mode targets only
  % which are not expected to contain any ICC profiles anyway.
  <<
    % These are the defaults but set explicitly here for clarity
    /DeviceCMYK null
    /DeviceRGB null
    /DeviceGray null

    % In Calibration Mode there will be no output profile available
    % so ensure we don't honour any input profile either.
    /OverrideCMYK $ICC_ACTIVE$ not
    /OverrideRGB $ICC_ACTIVE$ not
    /OverrideGray $ICC_ACTIVE$ not

     % Do not preserve 100% black (this is the default)
    /Black true
    /BlackTint true

    % The default is false and although calibration mode targets
    % are not expected to contain spots, this is safer in general.
    /OverprintPreview /SpotsOnly

  >> setinterceptcolorspace
} {
  % Provide a CM setup including ICC profiles to use where the job
  % has none itself.
  <<
    % Set ICC source profiles to use where the job has none

    /DeviceCMYK [ /ICCBased (%os%PocIccProfiles/$SOURCE_CMYK_ICC_NAME$.icc) (r) file ]
    /DeviceRGB  [ /ICCBased (%os%PocIccProfiles/$SOURCE_RGB_ICC_NAME$.icc) (r) file ]
    /DeviceGray null % treat as DeviceCMYK

    % Set overrides to false to honour CM from the job where provided
    /OverrideCMYK $OVERRIDE_CM_IN_JOB$
    /OverrideRGB  $OVERRIDE_CM_IN_JOB$
    /OverrideGray $OVERRIDE_CM_IN_JOB$

    % Set black intercepts to false to preserve 100% black
    /Black <<
       /Default $DO_NOT_PRESERVE_BLACK$
       
       /Text <<
          /Default $DO_NOT_KEEP_TEXT_BLACK$
       >>
    >>
    /BlackTint $DO_NOT_PRESERVE_BLACK$

    /OverprintPreview /SpotsOnly
  >> setinterceptcolorspace

  $DO_NOT_TREAT_GRAY_AS_CMYK$ {
    << 
      /DeviceGray [ /ICCBased (%os%PocIccProfiles/$SOURCE_GRAY_ICC_NAME$.icc) (r) file ]
    >> setinterceptcolorspace
  } if
} ifelse

% This is the default rendering intent for use when the job doesn't
% specify any.  By default it ought to be set to RelativeColorimetric
% elsewhere.
/$MAIN_RENDERING_INTENT$ setrenderingintent

% Set all the reproduction dictionary values to defaults
% This is based on the assumption that we will always run this before
% anything else that may be using setreproduction
<<>> setreproduction


<<
  % In Calibration Mode we have no output profile and will be passed the
  % non-existent None.icc profile name so must avoid using this section.
  $ICC_ACTIVE$ {
    $NO_EMULATION_PROFILE$ {
      % Define the output ICC profile.
      /Profile (%os%PocIccProfiles/$ICC_NAME$.icc) (r) file
	  
	  $ApplyInkLimiting$ {
		/NextDevice <<
		/InputColorSpace [ /ICCBased (%os%/PocIccProfiles/$TotalAreaCoverage$.icc)(r) file ]
		>>
	  } if
    } {
      /Profile (%os%PocIccProfiles/$ICC_EMULATION_PROFILE_NAME$.icc) (r) file
      /NextDevice <<
        /Profile (%os%PocIccProfiles/$ICC_NAME$.icc) (r) file
		
		$ApplyInkLimiting$ {
		/NextDevice <<
		/InputColorSpace [ /ICCBased (%os%/PocIccProfiles/$TotalAreaCoverage$.icc)(r) file ]
		>>
	  } if
      >>
    } ifelse
  } if

  /BlackPointCompensation true
  /NamedColorIntent /AbsoluteColorimetric def
  /IntentMappings <<
    /Other <<
      /NamedColor NamedColorIntent
    >>
    /Text <<
      /NamedColor NamedColorIntent
    >>
    /Vignette <<
      /NamedColor NamedColorIntent
    >>
    /Picture << 
      /Default     null
      /CMYK        $CMYK_IMAGES_RI_OVERRIDE$
      /RGB         $RGB_IMAGES_RI_OVERRIDE$
      $DO_NOT_TREAT_GRAY_AS_CMYK$ not {
        /Gray        $CMYK_IMAGES_RI_OVERRIDE$
      } if
    >>
  >>
>> setreproduction

<< /TreatSingleRowImagesAs  /Picture
>> setmiscobjectmappings

<<
  /OverprintICCBased true % actually the default
  /OverprintWhite true
  % Smoothing
  /FasterColorGradients true
  /MaxSmoothness .002
>> setuserparams

<<
  /CalibrationType 6
  /MissingCalibrationAbort false
  /ActualPress
  <<
    $HD_CalCurves$
  >>
>>
1183615869 internaldict /setcalibration get exec

<<
  /EnforcePDFVersion 0
>> setpdfparams

% Use the crop box by default.
<< /PageCropTo 4 >> setpdfparams

% Duplex options.
$DuplexSideAFirst$ { % Side A first.
  <<
    /PageOrder
    <<
        /BlockSize 2
        /Order [$IsSideA$ { 1 } { 2 } ifelse]
        /AutoBlankPage true
    >>
  >> setpdfparams
} if

$DuplexSideBFirst$ { % Side B first.
  <<
    /PageOrder
    <<
        /BlockSize 2
        /Order [$IsSideA$ { 2 } { 1 } ifelse]
        /AutoBlankPage true
    >>
  >> setpdfparams
} if

<< >> setpagedevice
% Helper for pdf shadowop procedures
% id pdfexamineinfo -
/pdfexamineinfo {
  dup 1183615869 internaldict /getPDFinfo get exec
  dup /SetupPS known {
    dup /SetupPS get dup type /pdfobjtype eq {
      3 index 1183615869 internaldict /getPDFobject get exec
    } if
    cvx exec
  } if
  pop
} def


<< % shadowop dictionary
/pdfexec << >> def
/pdfexec {
  2 copy pdfopen exch pop % file id
  //pdfexamineinfo exec
  % file id
  dup //pdfexec pdfexecid pdfclose closefile
} bind

/pdfopen {
  pdfopen % id
  //pdfexamineinfo exec
} bind
% id
>> 1183615869 internaldict /shadowop get exec