123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- namespace Fpdi\PdfReader\DataStructure;
- use Fpdi\PdfParser\CrossReference\CrossReferenceException;
- use Fpdi\PdfParser\PdfParser;
- use Fpdi\PdfParser\PdfParserException;
- use Fpdi\PdfParser\Type\PdfArray;
- use Fpdi\PdfParser\Type\PdfNumeric;
- use Fpdi\PdfParser\Type\PdfType;
- use Fpdi\PdfParser\Type\PdfTypeException;
- class Rectangle
- {
-
- protected $llx;
-
- protected $lly;
-
- protected $urx;
-
- protected $ury;
-
- public static function byPdfArray($array, PdfParser $parser)
- {
- $array = PdfArray::ensure(PdfType::resolve($array, $parser), 4)->value;
- $ax = PdfNumeric::ensure(PdfType::resolve($array[0], $parser))->value;
- $ay = PdfNumeric::ensure(PdfType::resolve($array[1], $parser))->value;
- $bx = PdfNumeric::ensure(PdfType::resolve($array[2], $parser))->value;
- $by = PdfNumeric::ensure(PdfType::resolve($array[3], $parser))->value;
- return new self($ax, $ay, $bx, $by);
- }
-
- public function __construct($ax, $ay, $bx, $by)
- {
- $this->llx = \min($ax, $bx);
- $this->lly = \min($ay, $by);
- $this->urx = \max($ax, $bx);
- $this->ury = \max($ay, $by);
- }
-
- public function getWidth()
- {
- return $this->urx - $this->llx;
- }
-
- public function getHeight()
- {
- return $this->ury - $this->lly;
- }
-
- public function getLlx()
- {
- return $this->llx;
- }
-
- public function getLly()
- {
- return $this->lly;
- }
-
- public function getUrx()
- {
- return $this->urx;
- }
-
- public function getUry()
- {
- return $this->ury;
- }
-
- public function toArray()
- {
- return [
- $this->llx,
- $this->lly,
- $this->urx,
- $this->ury
- ];
- }
-
- public function toPdfArray()
- {
- $array = new PdfArray();
- $array->value[] = PdfNumeric::create($this->llx);
- $array->value[] = PdfNumeric::create($this->lly);
- $array->value[] = PdfNumeric::create($this->urx);
- $array->value[] = PdfNumeric::create($this->ury);
- return $array;
- }
- }
|