/** Add object to hold shading properties \param object id. \param action \param options \return action 'new' - dictionary name 'out' - pdf output */ function o_shading($id, $action, $options = '') { if ($action != 'new') { $o =& $this->objects[$id]; } switch ($action) { case 'new': $this->objects[$id] = array('t' => 'shading', 'info' => array('type' => '2', 'ColorSpace' => '/DeviceCMYK')); if (!isset($options['orientation'])) { $options['orientation'] = 'vertical'; } if ($options['orientation'] == 'horizontal') { $angle = 0; } else { if ($options['orientation'] == 'vertical') { $angle = deg2rad(90); } else { $angle = $options['orientation']; } } $this->objects[$id]['info']['Coords'] = '[ ' . sprintf('%.3F', $options['size']['x1']) . ' ' . sprintf('%.3F', $options['size']['y1'] + $options['size']['height']) . ' ' . sprintf('%.3F', $options['size']['x1'] + $options['size']['width'] * cos($angle)) . ' ' . sprintf('%.3F', $options['size']['y1'] + $options['size']['height'] * (1 - sin($angle))) . ']'; //$this->objects[$id]['info']['Coords'] = '[0.0 0.0 50.0 50.0]'; if (is_array($options['color0'])) { if (count($options['color0']) == 3) { $options['color0'] = eZMath::rgbToCMYK($options['color0']); } $color0 = array('c' => sprintf('%.3F', $options['color0']['c']), 'm' => sprintf('%.3F', $options['color0']['m']), 'y' => sprintf('%.3F', $options['color0']['y']), 'k' => sprintf('%.3F', $options['color0']['k'])); } else { $color0 = eZMath::rgbToCMYK2(0, 0, 0); } if (is_array($options['color1'])) { if (count($options['color1']) == 3) { $options['color1'] = eZMath::rgbToCMYK($options['color1']); } $color1 = array('c' => sprintf('%.3F', $options['color1']['c']), 'm' => sprintf('%.3F', $options['color1']['m']), 'y' => sprintf('%.3F', $options['color1']['y']), 'k' => sprintf('%.3F', $options['color1']['k'])); } else { $color1 = eZMath::rgbToCMYK2(1, 1, 1); } $this->numObj++; $this->objects[$id]['info']['Function'] = $this->numObj; $this->o_function($this->numObj, 'new', array('type' => '2', 'Domain' => '[0.0 1.0]', 'C0' => '[' . $color0['c'] . ' ' . $color0['m'] . ' ' . $color0['y'] . ' ' . $color0['k'] . ']', 'C1' => '[' . $color1['c'] . ' ' . $color1['m'] . ' ' . $color1['y'] . ' ' . $color1['k'] . ']', 'N' => '1.0')); $this->objects[$id]['info']['Extend'] = '[true true]'; // also tell the pages node about the new shading $this->o_pages($this->currentNode, 'shading', array('label' => 'Sh' . $id, 'objNum' => $id)); return 'Sh' . $id; break; case 'out': $res = "\n" . $id . " 0 obj\n<< "; $res .= "/ShadingType " . $o['info']['type'] . "\n"; $res .= "/ColorSpace " . $o['info']['ColorSpace'] . "\n"; $res .= "/Coords " . $o['info']['Coords'] . "\n"; $res .= "/Function " . $o['info']['Function'] . " 0 R\n"; $res .= "/Extend " . $o['info']['Extend'] . "\n"; $res .= ">>\nendobject"; return $res; break; } }
static function rgbToCMYK2($r, $g, $b) { return eZMath::rgbToCMYK(array('r' => $r, 'g' => $g, 'b' => $b)); }