source-class-Com.Tecnick.Color.Pdf

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
  1: <?php
  2: /**
  3:  * Pdf.php
  4:  *
  5:  * @since       2015-02-21
  6:  * @category    Library
  7:  * @package     Color
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2015-2015 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-color
 12:  *
 13:  * This file is part of tc-lib-color software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Color;
 17: 
 18: use \Com\Tecnick\Color\Exception as ColorException;
 19: use \Com\Tecnick\Color\Web;
 20: use \Com\Tecnick\Color\Spot;
 21: 
 22: /**
 23:  * Com\Tecnick\Color\Pdf
 24:  *
 25:  * PDF Color class
 26:  *
 27:  * @since       2015-02-21
 28:  * @category    Library
 29:  * @package     Color
 30:  * @author      Nicola Asuni <info@tecnick.com>
 31:  * @copyright   2015-2015 Nicola Asuni - Tecnick.com LTD
 32:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 33:  * @link        https://github.com/tecnickcom/tc-lib-color
 34:  */
 35: class Pdf extends \Com\Tecnick\Color\Spot
 36: {
 37:     /**
 38:      * Array of valid JavaScript color names to be used in PDF documents
 39:      *
 40:      * @var array
 41:      */
 42:     protected static $jscolor = array(
 43:         'transparent',
 44:         'black',
 45:         'white',
 46:         'red',
 47:         'green',
 48:         'blue',
 49:         'cyan',
 50:         'magenta',
 51:         'yellow',
 52:         'dkGray',
 53:         'gray',
 54:         'ltGray',
 55:     );
 56: 
 57:     /**
 58:      * Return the Js color array of names
 59:      *
 60:      * @return array
 61:      */
 62:     public function getJsMap()
 63:     {
 64:         return self::$jscolor;
 65:     }
 66: 
 67:     /**
 68:      * Convert color to javascript string
 69:      *
 70:      * @param string|object $color color name or color object
 71:      *
 72:      * @return string
 73:      */
 74:     public function getJsColorString($color)
 75:     {
 76:         if (in_array($color, self::$jscolor)) {
 77:             return 'color.'.$color;
 78:         }
 79:         try {
 80:             if (($colobj = $this->getColorObj($color)) !== null) {
 81:                 return $colobj->getJsPdfColor();
 82:             }
 83:         } catch (ColorException $e) {
 84:         }
 85:         // default transparent color
 86:         return 'color.'.self::$jscolor[0];
 87:     }
 88: 
 89:     /**
 90:      * Returns a color object from an HTML, CSS or Spot color representation.
 91:      *
 92:      * @param string $color HTML, CSS or Spot color to parse
 93:      *
 94:      * @return object or null in case of error or if the color is not found
 95:      */
 96:     public function getColorObject($color)
 97:     {
 98:         try {
 99:             return $this->getSpotColorObj($color);
100:         } catch (ColorException $e) {
101:         }
102:         try {
103:             return $this->getColorObj($color);
104:         } catch (ColorException $e) {
105:         }
106:         return null;
107:     }
108: 
109:     /**
110:      * Get the color components format used in PDF documents
111:      * NOTE: the alpha channel is omitted
112:      *
113:      * @param string $color  HTML, CSS or Spot color to parse
114:      * @param bool   $stroke True for stroking (lines, drawing) and false for non-stroking (text and area filling).
115:      * @param float  $tint   Intensity of the color (from 0 to 1; 1 = full intensity).
116:      *
117:      * @return string
118:      */
119:     public function getPdfColor($color, $stroke = false, $tint = 1)
120:     {
121:         try {
122:             $col = $this->getSpotColor($color);
123:             $tint = sprintf('cs %F scn', (max(0, min(1, (float) $tint))));
124:             if ($stroke) {
125:                 $tint = strtoupper($tint);
126:             }
127:             return sprintf('/CS%d %s'."\n", $col['i'], $tint);
128:         } catch (ColorException $e) {
129:         }
130:         try {
131:             $col = $this->getColorObj($color);
132:             if ($col !== null) {
133:                 return $col->getPdfColor($stroke);
134:             }
135:         } catch (ColorException $e) {
136:         }
137:         return '';
138:     }
139: 
140:     /**
141:      * Get the RGB color components format used in PDF documents
142:      *
143:      * @param string $color  HTML, CSS or Spot color to parse
144:      *
145:      * @return string
146:      */
147:     public function getPdfRgbComponents($color)
148:     {
149:         $col = $this->getColorObject($color);
150:         if ($col === null) {
151:             return '';
152:         }
153:         $cmp = $col->toRgbArray();
154:         return sprintf('%F %F %F', $cmp['red'], $cmp['green'], $cmp['blue']);
155:     }
156: }
157: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy