1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AppUtils\ImageHelper; |
6
|
|
|
|
7
|
|
|
use AppUtils\ImageHelper_Size; |
8
|
|
|
use ArrayAccess; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @package AppUtils |
13
|
|
|
* @subpackage ImageHelper |
14
|
|
|
* @author Sebastian Mordziol <[email protected]> |
15
|
|
|
* |
16
|
|
|
* @implements ArrayAccess<string,int|float> |
17
|
|
|
*/ |
18
|
|
|
class ComputedTextSize implements ArrayAccess |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var array{size:float,top_left_x:int,top_left_y:int,top_right_x:int,top_right_y:int,bottom_left_x:int,bottom_left_y:int,bottom_right_x:int,bottom_right_y:int,width:int,height:int} |
22
|
|
|
*/ |
23
|
|
|
private array $size; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param array{size:float,top_left_x:int,top_left_y:int,top_right_x:int,top_right_y:int,bottom_left_x:int,bottom_left_y:int,bottom_right_x:int,bottom_right_y:int,width:int,height:int} $sizeArray |
27
|
|
|
*/ |
28
|
|
|
public function __construct(array $sizeArray) |
29
|
|
|
{ |
30
|
|
|
$this->size = $sizeArray; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getWidth() : int |
34
|
|
|
{ |
35
|
|
|
return $this->size['width']; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getHeight() : int |
39
|
|
|
{ |
40
|
|
|
return $this->size['height']; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return float |
45
|
|
|
*/ |
46
|
|
|
public function getFontSize() : float |
47
|
|
|
{ |
48
|
|
|
return $this->size['size']; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getLeft() : int |
52
|
|
|
{ |
53
|
|
|
return $this->size['top_left_x']; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getRight() : int |
57
|
|
|
{ |
58
|
|
|
return $this->size['top_right_x']; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getTop() : int |
62
|
|
|
{ |
63
|
|
|
return $this->size['top_left_y']; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getBottom() : int |
67
|
|
|
{ |
68
|
|
|
return $this->size['bottom_left_y']; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getSize() : ImageHelper_Size |
72
|
|
|
{ |
73
|
|
|
return new ImageHelper_Size(array( |
74
|
|
|
$this->size['width'], |
75
|
|
|
$this->size['height']) |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getTopLeft() : PixelCoordinate |
80
|
|
|
{ |
81
|
|
|
return new PixelCoordinate( |
82
|
|
|
$this->size['top_left_x'], |
83
|
|
|
$this->size['top_left_y'] |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getTopRight() : PixelCoordinate |
88
|
|
|
{ |
89
|
|
|
return new PixelCoordinate( |
90
|
|
|
$this->size['top_right_x'], |
91
|
|
|
$this->size['top_right_y'] |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getBottomLeft() : PixelCoordinate |
96
|
|
|
{ |
97
|
|
|
return new PixelCoordinate( |
98
|
|
|
$this->size['bottom_left_x'], |
99
|
|
|
$this->size['bottom_left_y'] |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getBottomRight() : PixelCoordinate |
104
|
|
|
{ |
105
|
|
|
return new PixelCoordinate( |
106
|
|
|
$this->size['bottom_right_x'], |
107
|
|
|
$this->size['bottom_right_y'] |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
// region: ArrayAccess interface |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $offset |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function offsetExists($offset) : bool |
118
|
|
|
{ |
119
|
|
|
return isset($this->size[$offset]); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $offset |
124
|
|
|
* @return int|float |
125
|
|
|
*/ |
126
|
|
|
public function offsetGet($offset) |
127
|
|
|
{ |
128
|
|
|
return $this->size[$offset] ?? -1; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $offset |
133
|
|
|
* @param int|float $value |
134
|
|
|
* @return void |
135
|
|
|
*/ |
136
|
|
|
public function offsetSet($offset, $value) : void |
137
|
|
|
{ |
138
|
|
|
$this->size[$offset] = $value; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param string $offset |
143
|
|
|
* @return void |
144
|
|
|
*/ |
145
|
|
|
public function offsetUnset($offset) : void |
146
|
|
|
{ |
147
|
|
|
// we do not want to unset any of the keys. |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
// endregion |
151
|
|
|
} |
152
|
|
|
|