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

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:  * Region.php
  4:  *
  5:  * @since       2011-05-23
  6:  * @category    Library
  7:  * @package     PdfPage
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2011-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-pdf-page
 12:  *
 13:  * This file is part of tc-lib-pdf-page software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Pdf\Page;
 17: 
 18: use \Com\Tecnick\Color\Pdf as Color;
 19: use \Com\Tecnick\Pdf\Page\Exception as PageException;
 20: 
 21: /**
 22:  * Com\Tecnick\Pdf\Page\Region
 23:  *
 24:  * @since       2011-05-23
 25:  * @category    Library
 26:  * @package     PdfPage
 27:  * @author      Nicola Asuni <info@tecnick.com>
 28:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 29:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 30:  * @link        https://github.com/tecnickcom/tc-lib-pdf-page
 31:  *
 32:  * A page region defines the writable area of the page.
 33:  */
 34: abstract class Region extends \Com\Tecnick\Pdf\Page\Settings
 35: {
 36:     /**
 37:      * Select the specified page region.
 38:      *
 39:      * @return array Selected region data
 40:      */
 41:     public function selectRegion($idr)
 42:     {
 43:         $this->page[$this->pageid]['currentRegion'] = min(max(0, intval($idr)), $this->page[$this->pageid]['columns']);
 44:         return $this->getCurrentRegion();
 45:     }
 46: 
 47:     /**
 48:      * Returns the current region data
 49:      *
 50:      * @return array
 51:      */
 52:     public function getCurrentRegion()
 53:     {
 54:         return $this->page[$this->pageid]['region'][$this->page[$this->pageid]['currentRegion']];
 55:     }
 56: 
 57:     /**
 58:      * Returns the page data with the next selected region.
 59:      * If there are no more regions available,
 60:      * then the first region on the next page is selected.
 61:      * A new page is added if required.
 62:      *
 63:      * @return array Current page data
 64:      */
 65:     public function getNextRegion()
 66:     {
 67:         $nextid = ($this->page[$this->pageid]['currentRegion'] + 1);
 68:         if (isset($this->page[$this->pageid]['region'][$nextid])) {
 69:             $this->page[$this->pageid]['currentRegion'] = $nextid;
 70:             return $this->page[$this->pageid];
 71:         }
 72:         return $this->getNextPage();
 73:     }
 74: 
 75:     /**
 76:      * Returns the next page data.
 77:      * Creates a new page if required and page break is enabled.
 78:      *
 79:      * @return array Page data
 80:      */
 81:     public function getNextPage()
 82:     {
 83:         if ($this->pageid < $this->pmaxid) {
 84:             return $this->page[++$this->pageid];
 85:         }
 86:         if (!$this->isAutoPageBreakEnabled()) {
 87:             return $this->getCurrentPage();
 88:         }
 89:         return $this->add();
 90:     }
 91: 
 92:     /**
 93:      * Move to the next page region if required.
 94:      *
 95:      * @param float $height Height of the block to add.
 96:      * @param float $ypos   Starting Y position or NULL for current position.
 97:      *
 98:      * @return array Page data
 99:      */
100:     public function checkRegionBreak($height = 0, $ypos = null)
101:     {
102:         if ($this->isYOutRegion($ypos, $height)) {
103:             return $this->getNextRegion();
104:         }
105:         return $this->getCurrentPage();
106:     }
107: 
108:     /**
109:      * Return the auto-page-break status
110:      *
111:      * @return bool True if the auto page break is enabled, false otherwise.
112:      */
113:     public function isAutoPageBreakEnabled()
114:     {
115:         return $this->page[$this->pageid]['autobreak'];
116:     }
117: 
118:     /**
119:      * Enable or disable automatic page break.
120:      *
121:      * @param bool $isenabled Set this to true to enable automatic page break.
122:      */
123:     public function enableAutoPageBreak($isenabled = true)
124:     {
125:         $this->page[$this->pageid]['autobreak'] = (bool) $isenabled;
126:     }
127: 
128:     /**
129:      * Check if the specified position is outside the region.
130:      *
131:      * @param float  $pos Position
132:      * @param string $min ID of the min region value to check
133:      * @param string $max ID of the max region value to check
134:      *
135:      * @return boolean
136:      */
137:     private function isOutRegion($pos, $min, $max)
138:     {
139:         $region = $this->getCurrentRegion();
140:         if (($pos < ($region[$min] - self::EPS)) || ($pos > ($region[$max] + self::EPS))) {
141:             return true;
142:         }
143:         return false;
144:     }
145: 
146:     /**
147:      * Check if the specified vertical position is outside the region.
148:      *
149:      * @param float $posy   Y position or NULL for current position.
150:      * @param float $height Additional height to add.
151:      *
152:      * @return boolean
153:      */
154:     public function isYOutRegion($posy = null, $height = 0)
155:     {
156:         if ($posy === null) {
157:             $posy = $this->getY();
158:         }
159:         return $this->isOutRegion(floatval($posy + $height), 'RY', 'RT');
160:     }
161: 
162:     /**
163:      * Check if the specified horizontal position is outside the region.
164:      *
165:      * @param float $posx  X position or NULL for current position.
166:      * @param float $width Additional width to add.
167:      *
168:      * @return boolean
169:      */
170:     public function isXOutRegion($posx = null, $width = 0)
171:     {
172:         if ($posx === null) {
173:             $posx = $this->getX();
174:         }
175:         return $this->isOutRegion(floatval($posx + $width), 'RX', 'RL');
176:     }
177: 
178:     /**
179:      * Return the absolute horizontal cursor position for the current region.
180:      *
181:      * @return float
182:      */
183:     public function getX()
184:     {
185:         return $this->page[$this->pageid]['region'][$this->page[$this->pageid]['currentRegion']]['x'];
186:     }
187: 
188:     /**
189:      * Return the absolute vertical cursor position for the current region.
190:      *
191:      * @return float
192:      */
193:     public function getY()
194:     {
195:         return $this->page[$this->pageid]['region'][$this->page[$this->pageid]['currentRegion']]['y'];
196:     }
197: 
198:     /**
199:      * Set the absolute horizontal cursor position for the current region.
200:      *
201:      * @param foat $xpos X position relative to the page coordinates.
202:      */
203:     public function setX($xpos)
204:     {
205:         $this->page[$this->pageid]['region'][$this->page[$this->pageid]['currentRegion']]['x'] = floatval($xpos);
206:         return $this;
207:     }
208: 
209:     /**
210:      * Set the absolute vertical cursor position for the current region.
211:      *
212:      * @param foat $ypos Y position relative to the page coordinates.
213:      */
214:     public function setY($ypos)
215:     {
216:         $this->page[$this->pageid]['region'][$this->page[$this->pageid]['currentRegion']]['y'] = floatval($ypos);
217:         return $this;
218:     }
219: }
220: 
 

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