source-class-Com.Tecnick.Pdf.Page.Box

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: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 
<?php
/**
 * Box.php
 *
 * @since       2011-05-23
 * @category    Library
 * @package     PdfPage
 * @author      Nicola Asuni <info@tecnick.com>
 * @copyright   2011-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-pdf-page
 *
 * This file is part of tc-lib-pdf-page software library.
 */

namespace Com\Tecnick\Pdf\Page;

use \Com\Tecnick\Pdf\Page\Exception as PageException;

/**
 * Com\Tecnick\Pdf\Page\Box
 *
 * @since       2011-05-23
 * @category    Library
 * @package     PdfPage
 * @author      Nicola Asuni <info@tecnick.com>
 * @copyright   2011-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-pdf-page
 */
abstract class Box extends \Com\Tecnick\Pdf\Page\Mode
{
    /**
     * Array of page box names
     *
     * @var array
     */
    public static $box = array(
        'MediaBox',
        'CropBox',
        'BleedBox',
        'TrimBox',
        'ArtBox'
    );

    /**
     * Swap X and Y coordinates of page boxes (change page boxes orientation).
     *
     * @param array $dims Array of page dimensions.
     *
     * @return array Page dimensions.
     *
     */
    public function swapCoordinates(array $dims)
    {
        foreach (self::$box as $type) {
            // swap X and Y coordinates
            if (isset($dims[$type])) {
                $tmp = $dims[$type]['llx'];
                $dims[$type]['llx'] = $dims[$type]['lly'];
                $dims[$type]['lly'] = $tmp;
                $tmp = $dims[$type]['urx'];
                $dims[$type]['urx'] = $dims[$type]['ury'];
                $dims[$type]['ury'] = $tmp;
            }
        }
        return $dims;
    }

    /**
     * Set page boundaries.
     *
     * @param array  $dims    Array of page dimensions to modify
     * @param string $type    Box type: MediaBox, CropBox, BleedBox, TrimBox, ArtBox.
     * @param float  $llx     Lower-left x coordinate in user units.
     * @param float  $lly     Lower-left y coordinate in user units.
     * @param float  $urx     Upper-right x coordinate in user units.
     * @param float  $ury     Upper-right y coordinate in user units.
     * @param array  $bci     BoxColorInfo: guideline style (color, width, style, dash).
     *
     * @return array Page dimensions.
     */
    public function setBox($dims, $type, $llx, $lly, $urx, $ury, array $bci = array())
    {
        if (empty($dims)) {
            // initialize array
            $dims = array();
        }
        if (!in_array($type, self::$box)) {
            throw new PageException('unknown page box type: '.$type);
        }
        $dims[$type]['llx'] = $llx;
        $dims[$type]['lly'] = $lly;
        $dims[$type]['urx'] = $urx;
        $dims[$type]['ury'] = $ury;

        if (empty($bci)) {
            // set default values
            $bci = array(
                'color' => '#000000',
                'width' => (1.0 / $this->kunit),
                'style' => 'S', // S = solid; D = dash
                'dash'  => array(3)
            );
        }
        $dims[$type]['bci'] = $bci;

        return $dims;
    }

    /**
     * Initialize page boxes
     *
     * @param float $width  Page width in points
     * @param float $height Page height in points
     *
     * @return array Page boxes
     */
    public function setPageBoxes($width, $height)
    {
        $dims = array();
        foreach (self::$box as $type) {
            $dims = $this->setBox($dims, $type, 0, 0, $width, $height);
        }
        return $dims;
    }

    /**
     * Returns the PDF command to output the specified page boxes.
     *
     * @param array $dims Array of page dimensions.
     *
     * @return string
     */
    protected function getBox(array $dims)
    {
        $out = '';
        foreach (self::$box as $box) {
            if (empty($dims[$box])) {
                // @codeCoverageIgnoreStart
                continue;
                // @codeCoverageIgnoreEnd
            }
            $out .= '/'.$box.' ['.sprintf(
                '%F %F %F %F',
                $dims[$box]['llx'],
                $dims[$box]['lly'],
                $dims[$box]['urx'],
                $dims[$box]['ury']
            ).']'."\n";
        }
        return $out;
    }

    /**
     * Returns the PDF command to output the specified page BoxColorInfo
     *
     * @param array $dims Array of page dimensions.
     *
     * @return string
     */
    protected function getBoxColorInfo(array $dims)
    {
        $out = '/BoxColorInfo <<'."\n";
        foreach (self::$box as $box) {
            if (empty($dims[$box])) {
                // @codeCoverageIgnoreStart
                continue;
                // @codeCoverageIgnoreEnd
            }
            $out .= '/'.$box.' <<'."\n";
            if (!empty($dims[$box]['bci']['color'])) {
                $out .= '/C ['.$this->col->getPdfRgbComponents($dims[$box]['bci']['color']).']'."\n";
            }
            if (!empty($dims[$box]['bci']['width'])) {
                $out .= '/W '.sprintf('%F', ($dims[$box]['bci']['width'] * $this->kunit))."\n";
            }
            if (!empty($dims[$box]['bci']['style'])) {
                $mode = strtoupper($dims[$box]['bci']['style'][0]);
                if ($mode !== 'D') {
                    $mode = 'S';
                }
                $out .= '/S /'.$mode."\n";
            }
            if (!empty($dims[$box]['bci']['dash'])) {
                $out .= '/D [';
                foreach ($dims[$box]['bci']['dash'] as $dash) {
                    $out .= sprintf(' %F', ((float) $dash * $this->kunit));
                }
                $out .= ' ]'."\n";
            }
            $out .= '>>'."\n";
        }
        $out = '>>'."\n";
        return $out;
    }
}
 

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