1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
/** |
5
|
|
|
* ImageBox class. |
6
|
|
|
* |
7
|
|
|
* @package YetiForcePDF\Layout |
8
|
|
|
* |
9
|
|
|
* @copyright YetiForce Sp. z o.o |
10
|
|
|
* @license MIT |
11
|
|
|
* @author Rafal Pospiech <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace YetiForcePDF\Layout; |
15
|
|
|
|
16
|
|
|
use YetiForcePDF\Math; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class ImageBox. |
20
|
|
|
*/ |
21
|
|
|
class ImageBox extends InlineBlockBox |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Measure width. |
25
|
|
|
* |
26
|
|
|
* @param bool $afterPageDividing |
27
|
|
|
* |
28
|
|
|
* @return $this |
29
|
|
|
*/ |
30
|
|
|
public function measureWidth(bool $afterPageDividing = false) |
31
|
|
|
{ |
32
|
|
|
$style = $this->getStyle(); |
33
|
|
|
if ('auto' === $style->getRules('width')) { |
34
|
|
|
$img = $style->getBackgroundImageStream(); |
35
|
|
|
$width = $img->getWidth(); |
36
|
|
|
if (Math::comp($width, $this->getParent()->getDimensions()->computeAvailableSpace()) > 0) { |
37
|
|
|
$width = $this->getParent()->getDimensions()->computeAvailableSpace(); |
38
|
|
|
} |
39
|
|
|
if ('auto' !== $style->getRules('height')) { |
40
|
|
|
Math::setAccurate(true); |
41
|
|
|
$ratio = $img->getRatio(); |
42
|
|
|
$width = Math::mul($ratio, $this->getDimensions()->getStyleHeight()); |
|
|
|
|
43
|
|
|
Math::setAccurate(false); |
44
|
|
|
} |
45
|
|
|
$width = Math::add($width, $style->getHorizontalBordersWidth(), $style->getHorizontalPaddingsWidth()); |
46
|
|
|
$this->getDimensions()->setWidth($width); |
47
|
|
|
} else { |
48
|
|
|
$this->applyStyleWidth(); |
49
|
|
|
} |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Measure height. |
55
|
|
|
* |
56
|
|
|
* @param bool $afterPageDividing |
57
|
|
|
* |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
|
|
public function measureHeight(bool $afterPageDividing = false) |
61
|
|
|
{ |
62
|
|
|
$style = $this->getStyle(); |
63
|
|
|
$img = $style->getBackgroundImageStream(); |
64
|
|
|
Math::setAccurate(true); |
65
|
|
|
$ratio = $img->getRatio(); |
66
|
|
|
$height = Math::div($this->getDimensions()->getInnerWidth(), $ratio); |
67
|
|
|
Math::setAccurate(false); |
68
|
|
|
$height = Math::add($height, $style->getVerticalBordersWidth(), $style->getVerticalPaddingsWidth()); |
69
|
|
|
$this->getDimensions()->setHeight($height); |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|