PageRenderTime 45ms CodeModel.GetById 41ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/zend/Zend/Pdf/Color/Cmyk.php

http://zoop.googlecode.com/
PHP | 126 lines | 36 code | 16 blank | 74 comment | 8 complexity | 1b8f16c0597db04e7d11e7b3146aa9a4 MD5 | raw file
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the new BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 * It is also available through the world-wide-web at this URL:
 10 * http://framework.zend.com/license/new-bsd
 11 * If you did not receive a copy of the license and are unable to
 12 * obtain it through the world-wide-web, please send an email
 13 * to license@zend.com so we can send you a copy immediately.
 14 *
 15 * @category   Zend
 16 * @package    Zend_Pdf
 17 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 18 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 19 * @version    $Id: Cmyk.php 20096 2010-01-06 02:05:09Z bkarwin $
 20 */
 21
 22/** Internally used classes */
 23require_once 'Zend/Pdf/Element/Numeric.php';
 24
 25
 26/** Zend_Pdf_Color */
 27require_once 'Zend/Pdf/Color.php';
 28
 29/**
 30 * CMYK color implementation
 31 *
 32 * @category   Zend
 33 * @package    Zend_Pdf
 34 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 35 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 36 */
 37class Zend_Pdf_Color_Cmyk extends Zend_Pdf_Color
 38{
 39    /**
 40     * Cyan level.
 41     * 0.0 (zero concentration) - 1.0 (maximum concentration)
 42     *
 43     * @var Zend_Pdf_Element_Numeric
 44     */
 45    private $_c;
 46
 47    /**
 48     * Magenta level.
 49     * 0.0 (zero concentration) - 1.0 (maximum concentration)
 50     *
 51     * @var Zend_Pdf_Element_Numeric
 52     */
 53    private $_m;
 54
 55    /**
 56     * Yellow level.
 57     * 0.0 (zero concentration) - 1.0 (maximum concentration)
 58     *
 59     * @var Zend_Pdf_Element_Numeric
 60     */
 61    private $_y;
 62
 63    /**
 64     * Key (BlacK) level.
 65     * 0.0 (zero concentration) - 1.0 (maximum concentration)
 66     *
 67     * @var Zend_Pdf_Element_Numeric
 68     */
 69    private $_k;
 70
 71
 72    /**
 73     * Object constructor
 74     *
 75     * @param float $c
 76     * @param float $m
 77     * @param float $y
 78     * @param float $k
 79     */
 80    public function __construct($c, $m, $y, $k)
 81    {
 82        if ($c < 0) { $c = 0; }
 83        if ($c > 1) { $c = 1; }
 84
 85        if ($m < 0) { $m = 0; }
 86        if ($m > 1) { $m = 1; }
 87
 88        if ($y < 0) { $y = 0; }
 89        if ($y > 1) { $y = 1; }
 90
 91        if ($k < 0) { $k = 0; }
 92        if ($k > 1) { $k = 1; }
 93
 94        $this->_c = new Zend_Pdf_Element_Numeric($c);
 95        $this->_m = new Zend_Pdf_Element_Numeric($m);
 96        $this->_y = new Zend_Pdf_Element_Numeric($y);
 97        $this->_k = new Zend_Pdf_Element_Numeric($k);
 98    }
 99
100    /**
101     * Instructions, which can be directly inserted into content stream
102     * to switch color.
103     * Color set instructions differ for stroking and nonstroking operations.
104     *
105     * @param boolean $stroking
106     * @return string
107     */
108    public function instructions($stroking)
109    {
110        return $this->_c->toString() . ' '
111             . $this->_m->toString() . ' '
112             . $this->_y->toString() . ' '
113             . $this->_k->toString() .     ($stroking? " K\n" : " k\n");
114    }
115
116    /**
117     * Get color components (color space dependent)
118     *
119     * @return array
120     */
121    public function getComponents()
122    {
123        return array($this->_c->value, $this->_m->value, $this->_y->value, $this->_k->value);
124    }
125}
126