Example #1
0
 /**
  * Paints color transition registration bars
  * @param $x (float) abscissa of the top left corner of the rectangle.
  * @param $y (float) ordinate of the top left corner of the rectangle.
  * @param $w (float) width of the rectangle.
  * @param $h (float) height of the rectangle.
  * @param $transition (boolean) if true prints tcolor transitions to white.
  * @param $vertical (boolean) if true prints bar vertically.
  * @param $colors (string) colors to print separated by comma. Valid values are: A,W,R,G,B,C,M,Y,K,RGB,CMYK,ALL,ALLSPOT,<SPOT_COLOR_NAME>. Where: A = grayscale black, W = grayscale white, R = RGB red, G RGB green, B RGB blue, C = CMYK cyan, M = CMYK magenta, Y = CMYK yellow, K = CMYK key/black, RGB = RGB registration color, CMYK = CMYK registration color, ALL = Spot registration color, ALLSPOT = print all defined spot colors, <SPOT_COLOR_NAME> = name of the spot color to print.
  * @author Nicola Asuni
  * @since 4.9.000 (2010-03-26)
  * @public
  */
 public function colorRegistrationBar($x, $y, $w, $h, $transition = true, $vertical = false, $colors = 'A,R,G,B,C,M,Y,K')
 {
     if (strpos($colors, 'ALLSPOT') !== false) {
         // expand spot colors
         $spot_colors = '';
         foreach ($this->spot_colors as $spot_color_name => $v) {
             $spot_colors .= ',' . $spot_color_name;
         }
         if (!empty($spot_colors)) {
             $spot_colors = substr($spot_colors, 1);
             $colors = str_replace('ALLSPOT', $spot_colors, $colors);
         } else {
             $colors = str_replace('ALLSPOT', 'NONE', $colors);
         }
     }
     $bars = explode(',', $colors);
     $numbars = count($bars);
     // number of bars to print
     if ($numbars <= 0) {
         return;
     }
     // set bar measures
     if ($vertical) {
         $coords = array(0, 0, 0, 1);
         $wb = $w / $numbars;
         // bar width
         $hb = $h;
         // bar height
         $xd = $wb;
         // delta x
         $yd = 0;
         // delta y
     } else {
         $coords = array(1, 0, 0, 0);
         $wb = $w;
         // bar width
         $hb = $h / $numbars;
         // bar height
         $xd = 0;
         // delta x
         $yd = $hb;
         // delta y
     }
     $xb = $x;
     $yb = $y;
     foreach ($bars as $col) {
         switch ($col) {
             // set transition colors
             case 'A':
                 // BLACK (GRAYSCALE)
                 $col_a = array(255);
                 $col_b = array(0);
                 break;
             case 'W':
                 // WHITE (GRAYSCALE)
                 $col_a = array(0);
                 $col_b = array(255);
                 break;
             case 'R':
                 // RED (RGB)
                 $col_a = array(255, 255, 255);
                 $col_b = array(255, 0, 0);
                 break;
             case 'G':
                 // GREEN (RGB)
                 $col_a = array(255, 255, 255);
                 $col_b = array(0, 255, 0);
                 break;
             case 'B':
                 // BLUE (RGB)
                 $col_a = array(255, 255, 255);
                 $col_b = array(0, 0, 255);
                 break;
             case 'C':
                 // CYAN (CMYK)
                 $col_a = array(0, 0, 0, 0);
                 $col_b = array(100, 0, 0, 0);
                 break;
             case 'M':
                 // MAGENTA (CMYK)
                 $col_a = array(0, 0, 0, 0);
                 $col_b = array(0, 100, 0, 0);
                 break;
             case 'Y':
                 // YELLOW (CMYK)
                 $col_a = array(0, 0, 0, 0);
                 $col_b = array(0, 0, 100, 0);
                 break;
             case 'K':
                 // KEY - BLACK (CMYK)
                 $col_a = array(0, 0, 0, 0);
                 $col_b = array(0, 0, 0, 100);
                 break;
             case 'RGB':
                 // BLACK REGISTRATION (RGB)
                 $col_a = array(255, 255, 255);
                 $col_b = array(0, 0, 0);
                 break;
             case 'CMYK':
                 // BLACK REGISTRATION (CMYK)
                 $col_a = array(0, 0, 0, 0);
                 $col_b = array(100, 100, 100, 100);
                 break;
             case 'ALL':
                 // SPOT COLOR REGISTRATION
                 $col_a = array(0, 0, 0, 0, 'None');
                 $col_b = array(100, 100, 100, 100, 'All');
                 break;
             case 'NONE':
                 // SKIP THIS COLOR
                 $col_a = array(0, 0, 0, 0, 'None');
                 $col_b = array(0, 0, 0, 0, 'None');
                 break;
             default:
                 // SPECIFIC SPOT COLOR NAME
                 $col_a = array(0, 0, 0, 0, 'None');
                 $col_b = TCPDF_COLORS::getSpotColor($col, $this->spot_colors);
                 if ($col_b === false) {
                     // in case of error defaults to the registration color
                     $col_b = array(100, 100, 100, 100, 'All');
                 }
                 break;
         }
         if ($col != 'NONE') {
             if ($transition) {
                 // color gradient
                 $this->LinearGradient($xb, $yb, $wb, $hb, $col_a, $col_b, $coords);
             } else {
                 $this->SetFillColorArray($col_b);
                 // colored rectangle
                 $this->Rect($xb, $yb, $wb, $hb, 'F', array());
             }
             $xb += $xd;
             $yb += $yd;
         }
     }
 }
Example #2
0
 /**
  * Set the spot color for the specified type ('draw', 'fill', 'text').
  * @param $type (string) Type of object affected by this color: ('draw', 'fill', 'text').
  * @param $name (string) Name of the spot color.
  * @param $tint (float) Intensity of the color (from 0 to 100 ; 100 = full intensity by default).
  * @return (string) PDF color command.
  * @public
  * @since 5.9.125 (2011-10-03)
  */
 public function setSpotColor($type, $name, $tint = 100)
 {
     $spotcolor = TCPDF_COLORS::getSpotColor($name, $this->spot_colors);
     if ($spotcolor === false) {
         $this->Error('Undefined spot color: ' . $name . ', you must add it on the spotcolors.php file.');
     }
     $tint = max(0, min(100, $tint)) / 100;
     $pdfcolor = sprintf('/CS%d ', $this->spot_colors[$name]['i']);
     switch ($type) {
         case 'draw':
             $pdfcolor .= sprintf('CS %F SCN', $tint);
             $this->DrawColor = $pdfcolor;
             $this->strokecolor = $spotcolor;
             break;
         case 'fill':
             $pdfcolor .= sprintf('cs %F scn', $tint);
             $this->FillColor = $pdfcolor;
             $this->bgcolor = $spotcolor;
             break;
         case 'text':
             $pdfcolor .= sprintf('cs %F scn', $tint);
             $this->TextColor = $pdfcolor;
             $this->fgcolor = $spotcolor;
             break;
     }
     $this->ColorFlag = $this->FillColor != $this->TextColor;
     if ($this->state == 2) {
         $this->_out($pdfcolor);
     }
     if ($this->inxobj) {
         // we are inside an XObject template
         $this->xobjects[$this->xobjid]['spot_colors'][$name] = $this->spot_colors[$name];
     }
     return $pdfcolor;
 }