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:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 
<?php
/**
 * Pdf.php
 *
 * @since       2015-02-21
 * @category    Library
 * @package     Color
 * @author      Nicola Asuni <info@tecnick.com>
 * @copyright   2015-2015 Nicola Asuni - Tecnick.com LTD
 * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 * @link        https://github.com/tecnickcom/tc-lib-color
 *
 * This file is part of tc-lib-color software library.
 */

namespace Com\Tecnick\Color;

use \Com\Tecnick\Color\Exception as ColorException;
use \Com\Tecnick\Color\Web;
use \Com\Tecnick\Color\Spot;

/**
 * Com\Tecnick\Color\Pdf
 *
 * PDF Color class
 *
 * @since       2015-02-21
 * @category    Library
 * @package     Color
 * @author      Nicola Asuni <info@tecnick.com>
 * @copyright   2015-2015 Nicola Asuni - Tecnick.com LTD
 * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 * @link        https://github.com/tecnickcom/tc-lib-color
 */
class Pdf extends \Com\Tecnick\Color\Spot
{
    /**
     * Array of valid JavaScript color names to be used in PDF documents
     *
     * @var array
     */
    protected static $jscolor = array(
        'transparent',
        'black',
        'white',
        'red',
        'green',
        'blue',
        'cyan',
        'magenta',
        'yellow',
        'dkGray',
        'gray',
        'ltGray',
    );

    /**
     * Return the Js color array of names
     *
     * @return array
     */
    public function getJsMap()
    {
        return self::$jscolor;
    }

    /**
     * Convert color to javascript string
     *
     * @param string|object $color color name or color object
     *
     * @return string
     */
    public function getJsColorString($color)
    {
        if (in_array($color, self::$jscolor)) {
            return 'color.'.$color;
        }
        try {
            if (($colobj = $this->getColorObj($color)) !== null) {
                return $colobj->getJsPdfColor();
            }
        } catch (ColorException $e) {
        }
        // default transparent color
        return 'color.'.self::$jscolor[0];
    }

    /**
     * Returns a color object from an HTML, CSS or Spot color representation.
     *
     * @param string $color HTML, CSS or Spot color to parse
     *
     * @return object or null in case of error or if the color is not found
     */
    public function getColorObject($color)
    {
        try {
            return $this->getSpotColorObj($color);
        } catch (ColorException $e) {
        }
        try {
            return $this->getColorObj($color);
        } catch (ColorException $e) {
        }
        return null;
    }

    /**
     * Get the color components format used in PDF documents
     * NOTE: the alpha channel is omitted
     *
     * @param string $color  HTML, CSS or Spot color to parse
     * @param bool   $stroke True for stroking (lines, drawing) and false for non-stroking (text and area filling).
     * @param float  $tint   Intensity of the color (from 0 to 1; 1 = full intensity).
     *
     * @return string
     */
    public function getPdfColor($color, $stroke = false, $tint = 1)
    {
        try {
            $col = $this->getSpotColor($color);
            $tint = sprintf('cs %F scn', (max(0, min(1, (float) $tint))));
            if ($stroke) {
                $tint = strtoupper($tint);
            }
            return sprintf('/CS%d %s'."\n", $col['i'], $tint);
        } catch (ColorException $e) {
        }
        try {
            $col = $this->getColorObj($color);
            if ($col !== null) {
                return $col->getPdfColor($stroke);
            }
        } catch (ColorException $e) {
        }
        return '';
    }

    /**
     * Get the RGB color components format used in PDF documents
     *
     * @param string $color  HTML, CSS or Spot color to parse
     *
     * @return string
     */
    public function getPdfRgbComponents($color)
    {
        $col = $this->getColorObject($color);
        if ($col === null) {
            return '';
        }
        $cmp = $col->toRgbArray();
        return sprintf('%F %F %F', $cmp['red'], $cmp['green'], $cmp['blue']);
    }
}
 

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