Updated gui for user facility settings (#1327)
[openemr.git] / vendor / phpoffice / phpexcel / Classes / PHPExcel / Style / Alignment.php
blob00825debf2c04dc28e31fc9614389dd65523d43d
1 <?php
2 /**
3 * PHPExcel
5 * Copyright (c) 2006 - 2014 PHPExcel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * @category PHPExcel
22 * @package PHPExcel_Style
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
29 /**
30 * PHPExcel_Style_Alignment
32 * @category PHPExcel
33 * @package PHPExcel_Style
34 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
36 class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
38 /* Horizontal alignment styles */
39 const HORIZONTAL_GENERAL = 'general';
40 const HORIZONTAL_LEFT = 'left';
41 const HORIZONTAL_RIGHT = 'right';
42 const HORIZONTAL_CENTER = 'center';
43 const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous';
44 const HORIZONTAL_JUSTIFY = 'justify';
45 const HORIZONTAL_FILL = 'fill';
46 const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only
48 /* Vertical alignment styles */
49 const VERTICAL_BOTTOM = 'bottom';
50 const VERTICAL_TOP = 'top';
51 const VERTICAL_CENTER = 'center';
52 const VERTICAL_JUSTIFY = 'justify';
53 const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only
55 /* Read order */
56 const READORDER_CONTEXT = 0;
57 const READORDER_LTR = 1;
58 const READORDER_RTL = 2;
60 /**
61 * Horizontal alignment
63 * @var string
65 protected $_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
67 /**
68 * Vertical alignment
70 * @var string
72 protected $_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
74 /**
75 * Text rotation
77 * @var integer
79 protected $_textRotation = 0;
81 /**
82 * Wrap text
84 * @var boolean
86 protected $_wrapText = FALSE;
88 /**
89 * Shrink to fit
91 * @var boolean
93 protected $_shrinkToFit = FALSE;
95 /**
96 * Indent - only possible with horizontal alignment left and right
98 * @var integer
100 protected $_indent = 0;
103 * Read order
105 * @var integer
107 protected $_readorder = 0;
110 * Create a new PHPExcel_Style_Alignment
112 * @param boolean $isSupervisor Flag indicating if this is a supervisor or not
113 * Leave this value at default unless you understand exactly what
114 * its ramifications are
115 * @param boolean $isConditional Flag indicating if this is a conditional style or not
116 * Leave this value at default unless you understand exactly what
117 * its ramifications are
119 public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
121 // Supervisor?
122 parent::__construct($isSupervisor);
124 if ($isConditional) {
125 $this->_horizontal = NULL;
126 $this->_vertical = NULL;
127 $this->_textRotation = NULL;
132 * Get the shared style component for the currently active cell in currently active sheet.
133 * Only used for style supervisor
135 * @return PHPExcel_Style_Alignment
137 public function getSharedComponent()
139 return $this->_parent->getSharedComponent()->getAlignment();
143 * Build style array from subcomponents
145 * @param array $array
146 * @return array
148 public function getStyleArray($array)
150 return array('alignment' => $array);
154 * Apply styles from array
156 * <code>
157 * $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray(
158 * array(
159 * 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
160 * 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
161 * 'rotation' => 0,
162 * 'wrap' => TRUE
164 * );
165 * </code>
167 * @param array $pStyles Array containing style information
168 * @throws PHPExcel_Exception
169 * @return PHPExcel_Style_Alignment
171 public function applyFromArray($pStyles = NULL) {
172 if (is_array($pStyles)) {
173 if ($this->_isSupervisor) {
174 $this->getActiveSheet()->getStyle($this->getSelectedCells())
175 ->applyFromArray($this->getStyleArray($pStyles));
176 } else {
177 if (isset($pStyles['horizontal'])) {
178 $this->setHorizontal($pStyles['horizontal']);
180 if (isset($pStyles['vertical'])) {
181 $this->setVertical($pStyles['vertical']);
183 if (isset($pStyles['rotation'])) {
184 $this->setTextRotation($pStyles['rotation']);
186 if (isset($pStyles['wrap'])) {
187 $this->setWrapText($pStyles['wrap']);
189 if (isset($pStyles['shrinkToFit'])) {
190 $this->setShrinkToFit($pStyles['shrinkToFit']);
192 if (isset($pStyles['indent'])) {
193 $this->setIndent($pStyles['indent']);
195 if (isset($pStyles['readorder'])) {
196 $this->setReadorder($pStyles['readorder']);
199 } else {
200 throw new PHPExcel_Exception("Invalid style array passed.");
202 return $this;
206 * Get Horizontal
208 * @return string
210 public function getHorizontal() {
211 if ($this->_isSupervisor) {
212 return $this->getSharedComponent()->getHorizontal();
214 return $this->_horizontal;
218 * Set Horizontal
220 * @param string $pValue
221 * @return PHPExcel_Style_Alignment
223 public function setHorizontal($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
224 if ($pValue == '') {
225 $pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
228 if ($this->_isSupervisor) {
229 $styleArray = $this->getStyleArray(array('horizontal' => $pValue));
230 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
232 else {
233 $this->_horizontal = $pValue;
235 return $this;
239 * Get Vertical
241 * @return string
243 public function getVertical() {
244 if ($this->_isSupervisor) {
245 return $this->getSharedComponent()->getVertical();
247 return $this->_vertical;
251 * Set Vertical
253 * @param string $pValue
254 * @return PHPExcel_Style_Alignment
256 public function setVertical($pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM) {
257 if ($pValue == '') {
258 $pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
261 if ($this->_isSupervisor) {
262 $styleArray = $this->getStyleArray(array('vertical' => $pValue));
263 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
264 } else {
265 $this->_vertical = $pValue;
267 return $this;
271 * Get TextRotation
273 * @return int
275 public function getTextRotation() {
276 if ($this->_isSupervisor) {
277 return $this->getSharedComponent()->getTextRotation();
279 return $this->_textRotation;
283 * Set TextRotation
285 * @param int $pValue
286 * @throws PHPExcel_Exception
287 * @return PHPExcel_Style_Alignment
289 public function setTextRotation($pValue = 0) {
290 // Excel2007 value 255 => PHPExcel value -165
291 if ($pValue == 255) {
292 $pValue = -165;
295 // Set rotation
296 if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
297 if ($this->_isSupervisor) {
298 $styleArray = $this->getStyleArray(array('rotation' => $pValue));
299 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
300 } else {
301 $this->_textRotation = $pValue;
303 } else {
304 throw new PHPExcel_Exception("Text rotation should be a value between -90 and 90.");
307 return $this;
311 * Get Wrap Text
313 * @return boolean
315 public function getWrapText() {
316 if ($this->_isSupervisor) {
317 return $this->getSharedComponent()->getWrapText();
319 return $this->_wrapText;
323 * Set Wrap Text
325 * @param boolean $pValue
326 * @return PHPExcel_Style_Alignment
328 public function setWrapText($pValue = FALSE) {
329 if ($pValue == '') {
330 $pValue = FALSE;
332 if ($this->_isSupervisor) {
333 $styleArray = $this->getStyleArray(array('wrap' => $pValue));
334 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
335 } else {
336 $this->_wrapText = $pValue;
338 return $this;
342 * Get Shrink to fit
344 * @return boolean
346 public function getShrinkToFit() {
347 if ($this->_isSupervisor) {
348 return $this->getSharedComponent()->getShrinkToFit();
350 return $this->_shrinkToFit;
354 * Set Shrink to fit
356 * @param boolean $pValue
357 * @return PHPExcel_Style_Alignment
359 public function setShrinkToFit($pValue = FALSE) {
360 if ($pValue == '') {
361 $pValue = FALSE;
363 if ($this->_isSupervisor) {
364 $styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
365 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
366 } else {
367 $this->_shrinkToFit = $pValue;
369 return $this;
373 * Get indent
375 * @return int
377 public function getIndent() {
378 if ($this->_isSupervisor) {
379 return $this->getSharedComponent()->getIndent();
381 return $this->_indent;
385 * Set indent
387 * @param int $pValue
388 * @return PHPExcel_Style_Alignment
390 public function setIndent($pValue = 0) {
391 if ($pValue > 0) {
392 if ($this->getHorizontal() != self::HORIZONTAL_GENERAL &&
393 $this->getHorizontal() != self::HORIZONTAL_LEFT &&
394 $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
395 $pValue = 0; // indent not supported
398 if ($this->_isSupervisor) {
399 $styleArray = $this->getStyleArray(array('indent' => $pValue));
400 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
401 } else {
402 $this->_indent = $pValue;
404 return $this;
408 * Get read order
410 * @return integer
412 public function getReadorder() {
413 if ($this->_isSupervisor) {
414 return $this->getSharedComponent()->getReadorder();
416 return $this->_readorder;
420 * Set read order
422 * @param int $pValue
423 * @return PHPExcel_Style_Alignment
425 public function setReadorder($pValue = 0) {
426 if ($pValue < 0 || $pValue > 2) {
427 $pValue = 0;
429 if ($this->_isSupervisor) {
430 $styleArray = $this->getStyleArray(array('readorder' => $pValue));
431 $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
432 } else {
433 $this->_readorder = $pValue;
435 return $this;
439 * Get hash code
441 * @return string Hash code
443 public function getHashCode() {
444 if ($this->_isSupervisor) {
445 return $this->getSharedComponent()->getHashCode();
447 return md5(
448 $this->_horizontal
449 . $this->_vertical
450 . $this->_textRotation
451 . ($this->_wrapText ? 't' : 'f')
452 . ($this->_shrinkToFit ? 't' : 'f')
453 . $this->_indent
454 . $this->_readorder
455 . __CLASS__