1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dompdf; |
4
|
|
|
|
5
|
|
|
use Dompdf\Css\Style; |
6
|
|
|
use Dompdf\Frame\FrameList; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @package dompdf |
10
|
|
|
* @link http://dompdf.github.com/ |
11
|
|
|
* @author Benj Carson <[email protected]> |
12
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The main Frame class |
17
|
|
|
* |
18
|
|
|
* This class represents a single HTML element. This class stores |
19
|
|
|
* positioning information as well as containing block location and |
20
|
|
|
* dimensions. Style information for the element is stored in a {@link |
21
|
|
|
* Style} object. Tree structure is maintained via the parent & children |
22
|
|
|
* links. |
23
|
|
|
* |
24
|
|
|
* @package dompdf |
25
|
|
|
*/ |
26
|
|
|
class Frame |
27
|
|
|
{ |
28
|
|
|
const WS_TEXT = 1; |
29
|
|
|
const WS_SPACE = 2; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The DOMElement or DOMText object this frame represents |
33
|
|
|
* |
34
|
|
|
* @var \DOMElement|\DOMText |
35
|
|
|
*/ |
36
|
|
|
protected $_node; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Unique identifier for this frame. Used to reference this frame |
40
|
|
|
* via the node. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $_id; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Unique id counter |
48
|
|
|
*/ |
49
|
|
|
public static $ID_COUNTER = 0; /*protected*/ |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* This frame's calculated style |
53
|
|
|
* |
54
|
|
|
* @var Style |
55
|
|
|
*/ |
56
|
|
|
protected $_style; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* This frame's original style. Needed for cases where frames are |
60
|
|
|
* split across pages. |
61
|
|
|
* |
62
|
|
|
* @var Style |
63
|
|
|
*/ |
64
|
|
|
protected $_original_style; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* This frame's parent in the document tree. |
68
|
|
|
* |
69
|
|
|
* @var Frame |
70
|
|
|
*/ |
71
|
|
|
protected $_parent; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* This frame's children |
75
|
|
|
* |
76
|
|
|
* @var Frame[] |
77
|
|
|
*/ |
78
|
|
|
protected $_frame_list; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* This frame's first child. All children are handled as a |
82
|
|
|
* doubly-linked list. |
83
|
|
|
* |
84
|
|
|
* @var Frame |
85
|
|
|
*/ |
86
|
|
|
protected $_first_child; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* This frame's last child. |
90
|
|
|
* |
91
|
|
|
* @var Frame |
92
|
|
|
*/ |
93
|
|
|
protected $_last_child; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* This frame's previous sibling in the document tree. |
97
|
|
|
* |
98
|
|
|
* @var Frame |
99
|
|
|
*/ |
100
|
|
|
protected $_prev_sibling; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* This frame's next sibling in the document tree. |
104
|
|
|
* |
105
|
|
|
* @var Frame |
106
|
|
|
*/ |
107
|
|
|
protected $_next_sibling; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* This frame's containing block (used in layout): array(x, y, w, h) |
111
|
|
|
* |
112
|
|
|
* @var float[] |
113
|
|
|
*/ |
114
|
|
|
protected $_containing_block; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Position on the page of the top-left corner of the margin box of |
118
|
|
|
* this frame: array(x,y) |
119
|
|
|
* |
120
|
|
|
* @var float[] |
121
|
|
|
*/ |
122
|
|
|
protected $_position; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Absolute opacity of this frame |
126
|
|
|
* |
127
|
|
|
* @var float |
128
|
|
|
*/ |
129
|
|
|
protected $_opacity; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* This frame's decorator |
133
|
|
|
* |
134
|
|
|
* @var \Dompdf\FrameDecorator\AbstractFrameDecorator |
135
|
|
|
*/ |
136
|
|
|
protected $_decorator; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* This frame's containing line box |
140
|
|
|
* |
141
|
|
|
* @var LineBox |
142
|
|
|
*/ |
143
|
|
|
protected $_containing_line; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @var array |
147
|
|
|
*/ |
148
|
|
|
protected $_is_cache = array(); |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Tells wether the frame was already pushed to the next page |
152
|
|
|
* |
153
|
|
|
* @var bool |
154
|
|
|
*/ |
155
|
|
|
public $_already_pushed = false; |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @var bool |
159
|
|
|
*/ |
160
|
|
|
public $_float_next_line = false; |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Tells wether the frame was split |
164
|
|
|
* |
165
|
|
|
* @var bool |
166
|
|
|
*/ |
167
|
|
|
public $_splitted; |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @var int |
171
|
|
|
*/ |
172
|
|
|
public static $_ws_state = self::WS_SPACE; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Class constructor |
176
|
|
|
* |
177
|
|
|
* @param \DOMNode $node the DOMNode this frame represents |
178
|
|
|
*/ |
179
|
|
|
public function __construct(\DOMNode $node) |
180
|
|
|
{ |
181
|
|
|
$this->_node = $node; |
|
|
|
|
182
|
|
|
|
183
|
|
|
$this->_parent = null; |
184
|
|
|
$this->_first_child = null; |
185
|
|
|
$this->_last_child = null; |
186
|
|
|
$this->_prev_sibling = $this->_next_sibling = null; |
187
|
|
|
|
188
|
|
|
$this->_style = null; |
189
|
|
|
$this->_original_style = null; |
190
|
|
|
|
191
|
|
|
$this->_containing_block = array( |
|
|
|
|
192
|
|
|
"x" => null, |
193
|
|
|
"y" => null, |
194
|
|
|
"w" => null, |
195
|
|
|
"h" => null, |
196
|
|
|
); |
197
|
|
|
|
198
|
|
|
$this->_containing_block[0] =& $this->_containing_block["x"]; |
199
|
|
|
$this->_containing_block[1] =& $this->_containing_block["y"]; |
200
|
|
|
$this->_containing_block[2] =& $this->_containing_block["w"]; |
201
|
|
|
$this->_containing_block[3] =& $this->_containing_block["h"]; |
202
|
|
|
|
203
|
|
|
$this->_position = array( |
|
|
|
|
204
|
|
|
"x" => null, |
205
|
|
|
"y" => null, |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
$this->_position[0] =& $this->_position["x"]; |
209
|
|
|
$this->_position[1] =& $this->_position["y"]; |
210
|
|
|
|
211
|
|
|
$this->_opacity = 1.0; |
212
|
|
|
$this->_decorator = null; |
213
|
|
|
|
214
|
|
|
$this->set_id(self::$ID_COUNTER++); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* WIP : preprocessing to remove all the unused whitespace |
219
|
|
|
*/ |
220
|
|
|
protected function ws_trim() |
221
|
|
|
{ |
222
|
|
|
if ($this->ws_keep()) { |
223
|
|
|
return; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
if (self::$_ws_state === self::WS_SPACE) { |
227
|
|
|
$node = $this->_node; |
228
|
|
|
|
229
|
|
|
if ($node->nodeName === "#text" && !empty($node->nodeValue)) { |
230
|
|
|
$node->nodeValue = preg_replace("/[ \t\r\n\f]+/u", " ", trim($node->nodeValue)); |
231
|
|
|
self::$_ws_state = self::WS_TEXT; |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @return bool |
238
|
|
|
*/ |
239
|
|
|
protected function ws_keep() |
240
|
|
|
{ |
241
|
|
|
$whitespace = $this->get_style()->white_space; |
|
|
|
|
242
|
|
|
|
243
|
|
|
return in_array($whitespace, array("pre", "pre-wrap", "pre-line")); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return bool |
248
|
|
|
*/ |
249
|
|
|
protected function ws_is_text() |
250
|
|
|
{ |
251
|
|
|
$node = $this->get_node(); |
252
|
|
|
|
253
|
|
|
if ($node->nodeName === "img") { |
254
|
|
|
return true; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
if (!$this->is_in_flow()) { |
258
|
|
|
return false; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
if ($this->is_text_node()) { |
262
|
|
|
return trim($node->nodeValue) !== ""; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
return true; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* "Destructor": forcibly free all references held by this frame |
270
|
|
|
* |
271
|
|
|
* @param bool $recursive if true, call dispose on all children |
272
|
|
|
*/ |
273
|
|
|
public function dispose($recursive = false) |
274
|
|
|
{ |
275
|
|
|
if ($recursive) { |
276
|
|
|
while ($child = $this->_first_child) { |
277
|
|
|
$child->dispose(true); |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
// Remove this frame from the tree |
282
|
|
|
if ($this->_prev_sibling) { |
283
|
|
|
$this->_prev_sibling->_next_sibling = $this->_next_sibling; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
if ($this->_next_sibling) { |
287
|
|
|
$this->_next_sibling->_prev_sibling = $this->_prev_sibling; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
if ($this->_parent && $this->_parent->_first_child === $this) { |
291
|
|
|
$this->_parent->_first_child = $this->_next_sibling; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
if ($this->_parent && $this->_parent->_last_child === $this) { |
295
|
|
|
$this->_parent->_last_child = $this->_prev_sibling; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
if ($this->_parent) { |
299
|
|
|
$this->_parent->get_node()->removeChild($this->_node); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
$this->_style->dispose(); |
303
|
|
|
$this->_style = null; |
304
|
|
|
unset($this->_style); |
305
|
|
|
|
306
|
|
|
$this->_original_style->dispose(); |
307
|
|
|
$this->_original_style = null; |
308
|
|
|
unset($this->_original_style); |
309
|
|
|
|
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Re-initialize the frame |
314
|
|
|
*/ |
315
|
|
|
public function reset() |
316
|
|
|
{ |
317
|
|
|
$this->_position["x"] = null; |
318
|
|
|
$this->_position["y"] = null; |
319
|
|
|
|
320
|
|
|
$this->_containing_block["x"] = null; |
321
|
|
|
$this->_containing_block["y"] = null; |
322
|
|
|
$this->_containing_block["w"] = null; |
323
|
|
|
$this->_containing_block["h"] = null; |
324
|
|
|
|
325
|
|
|
$this->_style = null; |
326
|
|
|
unset($this->_style); |
327
|
|
|
$this->_style = clone $this->_original_style; |
328
|
|
|
|
329
|
|
|
// If this represents a generated node then child nodes represent generated content. |
330
|
|
|
// Remove the children since the content will be generated next time this frame is reflowed. |
331
|
|
|
if ($this->_node->nodeName === "dompdf_generated" && $this->_style->content != "normal") { |
|
|
|
|
332
|
|
|
foreach ($this->get_children() as $child) { |
333
|
|
|
$this->remove_child($child); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @return \DOMElement|\DOMText |
340
|
|
|
*/ |
341
|
|
|
public function get_node() |
342
|
|
|
{ |
343
|
|
|
return $this->_node; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @return string |
348
|
|
|
*/ |
349
|
|
|
public function get_id() |
350
|
|
|
{ |
351
|
|
|
return $this->_id; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @return Style |
356
|
|
|
*/ |
357
|
|
|
public function get_style() |
358
|
|
|
{ |
359
|
|
|
return $this->_style; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @return Style |
364
|
|
|
*/ |
365
|
|
|
public function get_original_style() |
366
|
|
|
{ |
367
|
|
|
return $this->_original_style; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @return Frame |
372
|
|
|
*/ |
373
|
|
|
public function get_parent() |
374
|
|
|
{ |
375
|
|
|
return $this->_parent; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @return \Dompdf\FrameDecorator\AbstractFrameDecorator |
380
|
|
|
*/ |
381
|
|
|
public function get_decorator() |
382
|
|
|
{ |
383
|
|
|
return $this->_decorator; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @return Frame |
388
|
|
|
*/ |
389
|
|
|
public function get_first_child() |
390
|
|
|
{ |
391
|
|
|
return $this->_first_child; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @return Frame |
396
|
|
|
*/ |
397
|
|
|
public function get_last_child() |
398
|
|
|
{ |
399
|
|
|
return $this->_last_child; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @return Frame |
404
|
|
|
*/ |
405
|
|
|
public function get_prev_sibling() |
406
|
|
|
{ |
407
|
|
|
return $this->_prev_sibling; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* @return Frame |
412
|
|
|
*/ |
413
|
|
|
public function get_next_sibling() |
414
|
|
|
{ |
415
|
|
|
return $this->_next_sibling; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @return FrameList|Frame[] |
420
|
|
|
*/ |
421
|
|
|
public function get_children() |
422
|
|
|
{ |
423
|
|
|
if (isset($this->_frame_list)) { |
424
|
|
|
return $this->_frame_list; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
$this->_frame_list = new FrameList($this); |
|
|
|
|
428
|
|
|
|
429
|
|
|
return $this->_frame_list; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
// Layout property accessors |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Containing block dimensions |
436
|
|
|
* |
437
|
|
|
* @param $i string The key of the wanted containing block's dimension (x, y, w, h) |
438
|
|
|
* |
439
|
|
|
* @return float[]|float |
440
|
|
|
*/ |
441
|
|
|
public function get_containing_block($i = null) |
442
|
|
|
{ |
443
|
|
|
if (isset($i)) { |
444
|
|
|
return $this->_containing_block[$i]; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
return $this->_containing_block; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Block position |
452
|
|
|
* |
453
|
|
|
* @param $i string The key of the wanted position value (x, y) |
454
|
|
|
* |
455
|
|
|
* @return array|float |
456
|
|
|
*/ |
457
|
|
|
public function get_position($i = null) |
458
|
|
|
{ |
459
|
|
|
if (isset($i)) { |
460
|
|
|
return $this->_position[$i]; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
return $this->_position; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
//........................................................................ |
|
|
|
|
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Return the height of the margin box of the frame, in pt. Meaningless |
470
|
|
|
* unless the height has been calculated properly. |
471
|
|
|
* |
472
|
|
|
* @return float |
473
|
|
|
*/ |
474
|
|
View Code Duplication |
public function get_margin_height() |
|
|
|
|
475
|
|
|
{ |
476
|
|
|
$style = $this->_style; |
477
|
|
|
|
478
|
|
|
return (float)$style->length_in_pt(array( |
479
|
|
|
$style->height, |
|
|
|
|
480
|
|
|
$style->margin_top, |
|
|
|
|
481
|
|
|
$style->margin_bottom, |
|
|
|
|
482
|
|
|
$style->border_top_width, |
|
|
|
|
483
|
|
|
$style->border_bottom_width, |
|
|
|
|
484
|
|
|
$style->padding_top, |
|
|
|
|
485
|
|
|
$style->padding_bottom |
|
|
|
|
486
|
|
|
), $this->_containing_block["h"]); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
/** |
490
|
|
|
* Return the width of the margin box of the frame, in pt. Meaningless |
491
|
|
|
* unless the width has been calculated properly. |
492
|
|
|
* |
493
|
|
|
* @return float |
494
|
|
|
*/ |
495
|
|
|
public function get_margin_width() |
496
|
|
|
{ |
497
|
|
|
$style = $this->_style; |
498
|
|
|
|
499
|
|
|
return (float)$style->length_in_pt(array( |
500
|
|
|
$style->width, |
|
|
|
|
501
|
|
|
$style->margin_left, |
|
|
|
|
502
|
|
|
$style->margin_right, |
|
|
|
|
503
|
|
|
$style->border_left_width, |
|
|
|
|
504
|
|
|
$style->border_right_width, |
|
|
|
|
505
|
|
|
$style->padding_left, |
|
|
|
|
506
|
|
|
$style->padding_right |
|
|
|
|
507
|
|
|
), $this->_containing_block["w"]); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* @return float |
512
|
|
|
*/ |
513
|
|
View Code Duplication |
public function get_break_margins() |
|
|
|
|
514
|
|
|
{ |
515
|
|
|
$style = $this->_style; |
516
|
|
|
|
517
|
|
|
return (float)$style->length_in_pt(array( |
518
|
|
|
//$style->height, |
519
|
|
|
$style->margin_top, |
|
|
|
|
520
|
|
|
$style->margin_bottom, |
|
|
|
|
521
|
|
|
$style->border_top_width, |
|
|
|
|
522
|
|
|
$style->border_bottom_width, |
|
|
|
|
523
|
|
|
$style->padding_top, |
|
|
|
|
524
|
|
|
$style->padding_bottom |
|
|
|
|
525
|
|
|
), $this->_containing_block["h"]); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* Return the content box (x,y,w,h) of the frame |
530
|
|
|
* |
531
|
|
|
* @return array |
532
|
|
|
*/ |
533
|
|
|
public function get_content_box() |
534
|
|
|
{ |
535
|
|
|
$style = $this->_style; |
536
|
|
|
$cb = $this->_containing_block; |
537
|
|
|
|
538
|
|
|
$x = $this->_position["x"] + |
539
|
|
|
(float)$style->length_in_pt(array($style->margin_left, |
|
|
|
|
540
|
|
|
$style->border_left_width, |
|
|
|
|
541
|
|
|
$style->padding_left), |
|
|
|
|
542
|
|
|
$cb["w"]); |
543
|
|
|
|
544
|
|
|
$y = $this->_position["y"] + |
545
|
|
|
(float)$style->length_in_pt(array($style->margin_top, |
|
|
|
|
546
|
|
|
$style->border_top_width, |
|
|
|
|
547
|
|
|
$style->padding_top), |
|
|
|
|
548
|
|
|
$cb["h"]); |
549
|
|
|
|
550
|
|
|
$w = $style->length_in_pt($style->width, $cb["w"]); |
|
|
|
|
551
|
|
|
|
552
|
|
|
$h = $style->length_in_pt($style->height, $cb["h"]); |
|
|
|
|
553
|
|
|
|
554
|
|
|
return array(0 => $x, "x" => $x, |
555
|
|
|
1 => $y, "y" => $y, |
556
|
|
|
2 => $w, "w" => $w, |
557
|
|
|
3 => $h, "h" => $h); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* Return the padding box (x,y,w,h) of the frame |
562
|
|
|
* |
563
|
|
|
* @return array |
564
|
|
|
*/ |
565
|
|
|
public function get_padding_box() |
566
|
|
|
{ |
567
|
|
|
$style = $this->_style; |
568
|
|
|
$cb = $this->_containing_block; |
569
|
|
|
|
570
|
|
|
$x = $this->_position["x"] + |
571
|
|
|
(float)$style->length_in_pt(array($style->margin_left, |
|
|
|
|
572
|
|
|
$style->border_left_width), |
|
|
|
|
573
|
|
|
$cb["w"]); |
574
|
|
|
|
575
|
|
|
$y = $this->_position["y"] + |
576
|
|
|
(float)$style->length_in_pt(array($style->margin_top, |
|
|
|
|
577
|
|
|
$style->border_top_width), |
|
|
|
|
578
|
|
|
$cb["h"]); |
579
|
|
|
|
580
|
|
|
$w = $style->length_in_pt(array($style->padding_left, |
|
|
|
|
581
|
|
|
$style->width, |
|
|
|
|
582
|
|
|
$style->padding_right), |
|
|
|
|
583
|
|
|
$cb["w"]); |
584
|
|
|
|
585
|
|
|
$h = $style->length_in_pt(array($style->padding_top, |
|
|
|
|
586
|
|
|
$style->height, |
|
|
|
|
587
|
|
|
$style->padding_bottom), |
|
|
|
|
588
|
|
|
$cb["h"]); |
589
|
|
|
|
590
|
|
|
return array(0 => $x, "x" => $x, |
591
|
|
|
1 => $y, "y" => $y, |
592
|
|
|
2 => $w, "w" => $w, |
593
|
|
|
3 => $h, "h" => $h); |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* Return the border box of the frame |
598
|
|
|
* |
599
|
|
|
* @return array |
600
|
|
|
*/ |
601
|
|
|
public function get_border_box() |
602
|
|
|
{ |
603
|
|
|
$style = $this->_style; |
604
|
|
|
$cb = $this->_containing_block; |
605
|
|
|
|
606
|
|
|
$x = $this->_position["x"] + (float)$style->length_in_pt($style->margin_left, $cb["w"]); |
|
|
|
|
607
|
|
|
|
608
|
|
|
$y = $this->_position["y"] + (float)$style->length_in_pt($style->margin_top, $cb["h"]); |
|
|
|
|
609
|
|
|
|
610
|
|
|
$w = $style->length_in_pt(array($style->border_left_width, |
|
|
|
|
611
|
|
|
$style->padding_left, |
|
|
|
|
612
|
|
|
$style->width, |
|
|
|
|
613
|
|
|
$style->padding_right, |
|
|
|
|
614
|
|
|
$style->border_right_width), |
|
|
|
|
615
|
|
|
$cb["w"]); |
616
|
|
|
|
617
|
|
|
$h = $style->length_in_pt(array($style->border_top_width, |
|
|
|
|
618
|
|
|
$style->padding_top, |
|
|
|
|
619
|
|
|
$style->height, |
|
|
|
|
620
|
|
|
$style->padding_bottom, |
|
|
|
|
621
|
|
|
$style->border_bottom_width), |
|
|
|
|
622
|
|
|
$cb["h"]); |
623
|
|
|
|
624
|
|
|
return array(0 => $x, "x" => $x, |
625
|
|
|
1 => $y, "y" => $y, |
626
|
|
|
2 => $w, "w" => $w, |
627
|
|
|
3 => $h, "h" => $h); |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
/** |
631
|
|
|
* @param null $opacity |
632
|
|
|
* |
633
|
|
|
* @return float |
634
|
|
|
*/ |
635
|
|
|
public function get_opacity($opacity = null) |
636
|
|
|
{ |
637
|
|
|
if ($opacity !== null) { |
638
|
|
|
$this->set_opacity($opacity); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
return $this->_opacity; |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
/** |
645
|
|
|
* @return LineBox |
646
|
|
|
*/ |
647
|
|
|
public function &get_containing_line() |
648
|
|
|
{ |
649
|
|
|
return $this->_containing_line; |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
//........................................................................ |
|
|
|
|
653
|
|
|
|
654
|
|
|
// Set methods |
655
|
|
|
/** |
656
|
|
|
* @param $id |
657
|
|
|
*/ |
658
|
|
|
public function set_id($id) |
659
|
|
|
{ |
660
|
|
|
$this->_id = $id; |
661
|
|
|
|
662
|
|
|
// We can only set attributes of DOMElement objects (nodeType == 1). |
663
|
|
|
// Since these are the only objects that we can assign CSS rules to, |
664
|
|
|
// this shortcoming is okay. |
665
|
|
|
if ($this->_node->nodeType == XML_ELEMENT_NODE) { |
666
|
|
|
$this->_node->setAttribute("frame_id", $id); |
|
|
|
|
667
|
|
|
} |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* @param Style $style |
672
|
|
|
*/ |
673
|
|
|
public function set_style(Style $style) |
674
|
|
|
{ |
675
|
|
|
if (is_null($this->_style)) { |
676
|
|
|
$this->_original_style = clone $style; |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
//$style->set_frame($this); |
|
|
|
|
680
|
|
|
$this->_style = $style; |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* @param \Dompdf\FrameDecorator\AbstractFrameDecorator $decorator |
685
|
|
|
*/ |
686
|
|
|
public function set_decorator(FrameDecorator\AbstractFrameDecorator $decorator) |
687
|
|
|
{ |
688
|
|
|
$this->_decorator = $decorator; |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
/** |
692
|
|
|
* @param null $x |
693
|
|
|
* @param null $y |
694
|
|
|
* @param null $w |
695
|
|
|
* @param null $h |
696
|
|
|
*/ |
697
|
|
|
public function set_containing_block($x = null, $y = null, $w = null, $h = null) |
698
|
|
|
{ |
699
|
|
|
if (is_array($x)) { |
700
|
|
|
foreach ($x as $key => $val) { |
701
|
|
|
$$key = $val; |
702
|
|
|
} |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
if (is_numeric($x)) { |
706
|
|
|
$this->_containing_block["x"] = $x; |
707
|
|
|
} |
708
|
|
|
|
709
|
|
|
if (is_numeric($y)) { |
710
|
|
|
$this->_containing_block["y"] = $y; |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
if (is_numeric($w)) { |
714
|
|
|
$this->_containing_block["w"] = $w; |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
if (is_numeric($h)) { |
718
|
|
|
$this->_containing_block["h"] = $h; |
719
|
|
|
} |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
/** |
723
|
|
|
* @param null $x |
724
|
|
|
* @param null $y |
725
|
|
|
*/ |
726
|
|
|
public function set_position($x = null, $y = null) |
727
|
|
|
{ |
728
|
|
|
if (is_array($x)) { |
729
|
|
|
list($x, $y) = array($x["x"], $x["y"]); |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
if (is_numeric($x)) { |
733
|
|
|
$this->_position["x"] = $x; |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
if (is_numeric($y)) { |
737
|
|
|
$this->_position["y"] = $y; |
738
|
|
|
} |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
/** |
742
|
|
|
* @param $opacity |
743
|
|
|
*/ |
744
|
|
|
public function set_opacity($opacity) |
745
|
|
|
{ |
746
|
|
|
$parent = $this->get_parent(); |
747
|
|
|
$base_opacity = (($parent && $parent->_opacity !== null) ? $parent->_opacity : 1.0); |
748
|
|
|
$this->_opacity = $base_opacity * $opacity; |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
/** |
752
|
|
|
* @param LineBox $line |
753
|
|
|
*/ |
754
|
|
|
public function set_containing_line(LineBox $line) |
755
|
|
|
{ |
756
|
|
|
$this->_containing_line = $line; |
757
|
|
|
} |
758
|
|
|
|
759
|
|
|
/** |
760
|
|
|
* Indicates if the margin height is auto sized |
761
|
|
|
* |
762
|
|
|
* @return bool |
763
|
|
|
*/ |
764
|
|
|
public function is_auto_height() |
765
|
|
|
{ |
766
|
|
|
$style = $this->_style; |
767
|
|
|
|
768
|
|
|
return in_array( |
769
|
|
|
"auto", |
770
|
|
|
array( |
771
|
|
|
$style->height, |
|
|
|
|
772
|
|
|
$style->margin_top, |
|
|
|
|
773
|
|
|
$style->margin_bottom, |
|
|
|
|
774
|
|
|
$style->border_top_width, |
|
|
|
|
775
|
|
|
$style->border_bottom_width, |
|
|
|
|
776
|
|
|
$style->padding_top, |
|
|
|
|
777
|
|
|
$style->padding_bottom, |
|
|
|
|
778
|
|
|
$this->_containing_block["h"] |
779
|
|
|
), |
780
|
|
|
true |
781
|
|
|
); |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
/** |
785
|
|
|
* Indicates if the margin width is auto sized |
786
|
|
|
* |
787
|
|
|
* @return bool |
788
|
|
|
*/ |
789
|
|
|
public function is_auto_width() |
790
|
|
|
{ |
791
|
|
|
$style = $this->_style; |
792
|
|
|
|
793
|
|
|
return in_array( |
794
|
|
|
"auto", |
795
|
|
|
array( |
796
|
|
|
$style->width, |
|
|
|
|
797
|
|
|
$style->margin_left, |
|
|
|
|
798
|
|
|
$style->margin_right, |
|
|
|
|
799
|
|
|
$style->border_left_width, |
|
|
|
|
800
|
|
|
$style->border_right_width, |
|
|
|
|
801
|
|
|
$style->padding_left, |
|
|
|
|
802
|
|
|
$style->padding_right, |
|
|
|
|
803
|
|
|
$this->_containing_block["w"] |
804
|
|
|
), |
805
|
|
|
true |
806
|
|
|
); |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
/** |
810
|
|
|
* Tells if the frame is a text node |
811
|
|
|
* |
812
|
|
|
* @return bool |
813
|
|
|
*/ |
814
|
|
|
public function is_text_node() |
815
|
|
|
{ |
816
|
|
|
if (isset($this->_is_cache["text_node"])) { |
817
|
|
|
return $this->_is_cache["text_node"]; |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
return $this->_is_cache["text_node"] = ($this->get_node()->nodeName === "#text"); |
821
|
|
|
} |
822
|
|
|
|
823
|
|
|
/** |
824
|
|
|
* @return bool |
825
|
|
|
*/ |
826
|
|
View Code Duplication |
public function is_positionned() |
|
|
|
|
827
|
|
|
{ |
828
|
|
|
if (isset($this->_is_cache["positionned"])) { |
829
|
|
|
return $this->_is_cache["positionned"]; |
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
$position = $this->get_style()->position; |
|
|
|
|
833
|
|
|
|
834
|
|
|
return $this->_is_cache["positionned"] = in_array($position, Style::$POSITIONNED_TYPES); |
|
|
|
|
835
|
|
|
} |
836
|
|
|
|
837
|
|
|
/** |
838
|
|
|
* @return bool |
839
|
|
|
*/ |
840
|
|
|
public function is_absolute() |
841
|
|
|
{ |
842
|
|
|
if (isset($this->_is_cache["absolute"])) { |
843
|
|
|
return $this->_is_cache["absolute"]; |
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
$position = $this->get_style()->position; |
|
|
|
|
847
|
|
|
|
848
|
|
|
return $this->_is_cache["absolute"] = ($position === "absolute" || $position === "fixed"); |
849
|
|
|
} |
850
|
|
|
|
851
|
|
|
/** |
852
|
|
|
* @return bool |
853
|
|
|
*/ |
854
|
|
View Code Duplication |
public function is_block() |
|
|
|
|
855
|
|
|
{ |
856
|
|
|
if (isset($this->_is_cache["block"])) { |
857
|
|
|
return $this->_is_cache["block"]; |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
return $this->_is_cache["block"] = in_array($this->get_style()->display, Style::$BLOCK_TYPES); |
|
|
|
|
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
/** |
864
|
|
|
* @return bool |
865
|
|
|
*/ |
866
|
|
View Code Duplication |
public function is_inline_block() |
|
|
|
|
867
|
|
|
{ |
868
|
|
|
if (isset($this->_is_cache["inline_block"])) { |
869
|
|
|
return $this->_is_cache["inline_block"]; |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
return $this->_is_cache["inline_block"] = ($this->get_style()->display === 'inline-block'); |
|
|
|
|
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
/** |
876
|
|
|
* @return bool |
877
|
|
|
*/ |
878
|
|
|
public function is_in_flow() |
879
|
|
|
{ |
880
|
|
|
if (isset($this->_is_cache["in_flow"])) { |
881
|
|
|
return $this->_is_cache["in_flow"]; |
882
|
|
|
} |
883
|
|
|
return $this->_is_cache["in_flow"] = !($this->get_style()->float !== "none" || $this->is_absolute()); |
|
|
|
|
884
|
|
|
} |
885
|
|
|
|
886
|
|
|
/** |
887
|
|
|
* @return bool |
888
|
|
|
*/ |
889
|
|
|
public function is_pre() |
890
|
|
|
{ |
891
|
|
|
if (isset($this->_is_cache["pre"])) { |
892
|
|
|
return $this->_is_cache["pre"]; |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
$white_space = $this->get_style()->white_space; |
|
|
|
|
896
|
|
|
|
897
|
|
|
return $this->_is_cache["pre"] = in_array($white_space, array("pre", "pre-wrap")); |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
/** |
901
|
|
|
* @return bool |
902
|
|
|
*/ |
903
|
|
View Code Duplication |
public function is_table() |
|
|
|
|
904
|
|
|
{ |
905
|
|
|
if (isset($this->_is_cache["table"])) { |
906
|
|
|
return $this->_is_cache["table"]; |
907
|
|
|
} |
908
|
|
|
|
909
|
|
|
$display = $this->get_style()->display; |
|
|
|
|
910
|
|
|
|
911
|
|
|
return $this->_is_cache["table"] = in_array($display, Style::$TABLE_TYPES); |
|
|
|
|
912
|
|
|
} |
913
|
|
|
|
914
|
|
|
|
915
|
|
|
/** |
916
|
|
|
* Inserts a new child at the beginning of the Frame |
917
|
|
|
* |
918
|
|
|
* @param $child Frame The new Frame to insert |
919
|
|
|
* @param $update_node boolean Whether or not to update the DOM |
920
|
|
|
*/ |
921
|
|
|
public function prepend_child(Frame $child, $update_node = true) |
922
|
|
|
{ |
923
|
|
|
if ($update_node) { |
924
|
|
|
$this->_node->insertBefore($child->_node, $this->_first_child ? $this->_first_child->_node : null); |
925
|
|
|
} |
926
|
|
|
|
927
|
|
|
// Remove the child from its parent |
928
|
|
|
if ($child->_parent) { |
929
|
|
|
$child->_parent->remove_child($child, false); |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
$child->_parent = $this; |
933
|
|
|
$child->_prev_sibling = null; |
934
|
|
|
|
935
|
|
|
// Handle the first child |
936
|
|
View Code Duplication |
if (!$this->_first_child) { |
|
|
|
|
937
|
|
|
$this->_first_child = $child; |
938
|
|
|
$this->_last_child = $child; |
939
|
|
|
$child->_next_sibling = null; |
940
|
|
|
} else { |
941
|
|
|
$this->_first_child->_prev_sibling = $child; |
942
|
|
|
$child->_next_sibling = $this->_first_child; |
943
|
|
|
$this->_first_child = $child; |
944
|
|
|
} |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
/** |
948
|
|
|
* Inserts a new child at the end of the Frame |
949
|
|
|
* |
950
|
|
|
* @param $child Frame The new Frame to insert |
951
|
|
|
* @param $update_node boolean Whether or not to update the DOM |
952
|
|
|
*/ |
953
|
|
|
public function append_child(Frame $child, $update_node = true) |
954
|
|
|
{ |
955
|
|
|
if ($update_node) { |
956
|
|
|
$this->_node->appendChild($child->_node); |
957
|
|
|
} |
958
|
|
|
|
959
|
|
|
// Remove the child from its parent |
960
|
|
|
if ($child->_parent) { |
961
|
|
|
$child->_parent->remove_child($child, false); |
962
|
|
|
} |
963
|
|
|
|
964
|
|
|
$child->_parent = $this; |
965
|
|
|
$decorator = $child->get_decorator(); |
966
|
|
|
// force an update to the cached parent |
967
|
|
|
if ($decorator !== null) { |
968
|
|
|
$decorator->get_parent(false); |
969
|
|
|
} |
970
|
|
|
$child->_next_sibling = null; |
971
|
|
|
|
972
|
|
|
// Handle the first child |
973
|
|
View Code Duplication |
if (!$this->_last_child) { |
|
|
|
|
974
|
|
|
$this->_first_child = $child; |
975
|
|
|
$this->_last_child = $child; |
976
|
|
|
$child->_prev_sibling = null; |
977
|
|
|
} else { |
978
|
|
|
$this->_last_child->_next_sibling = $child; |
979
|
|
|
$child->_prev_sibling = $this->_last_child; |
980
|
|
|
$this->_last_child = $child; |
981
|
|
|
} |
982
|
|
|
} |
983
|
|
|
|
984
|
|
|
/** |
985
|
|
|
* Inserts a new child immediately before the specified frame |
986
|
|
|
* |
987
|
|
|
* @param $new_child Frame The new Frame to insert |
988
|
|
|
* @param $ref Frame The Frame after the new Frame |
989
|
|
|
* @param $update_node boolean Whether or not to update the DOM |
990
|
|
|
* |
991
|
|
|
* @throws Exception |
992
|
|
|
*/ |
993
|
|
|
public function insert_child_before(Frame $new_child, Frame $ref, $update_node = true) |
994
|
|
|
{ |
995
|
|
|
if ($ref === $this->_first_child) { |
996
|
|
|
$this->prepend_child($new_child, $update_node); |
997
|
|
|
|
998
|
|
|
return; |
999
|
|
|
} |
1000
|
|
|
|
1001
|
|
|
if (is_null($ref)) { |
1002
|
|
|
$this->append_child($new_child, $update_node); |
1003
|
|
|
|
1004
|
|
|
return; |
1005
|
|
|
} |
1006
|
|
|
|
1007
|
|
|
if ($ref->_parent !== $this) { |
1008
|
|
|
throw new Exception("Reference child is not a child of this node."); |
1009
|
|
|
} |
1010
|
|
|
|
1011
|
|
|
// Update the node |
1012
|
|
|
if ($update_node) { |
1013
|
|
|
$this->_node->insertBefore($new_child->_node, $ref->_node); |
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
// Remove the child from its parent |
1017
|
|
|
if ($new_child->_parent) { |
1018
|
|
|
$new_child->_parent->remove_child($new_child, false); |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
$new_child->_parent = $this; |
1022
|
|
|
$new_child->_next_sibling = $ref; |
1023
|
|
|
$new_child->_prev_sibling = $ref->_prev_sibling; |
1024
|
|
|
|
1025
|
|
|
if ($ref->_prev_sibling) { |
1026
|
|
|
$ref->_prev_sibling->_next_sibling = $new_child; |
1027
|
|
|
} |
1028
|
|
|
|
1029
|
|
|
$ref->_prev_sibling = $new_child; |
1030
|
|
|
} |
1031
|
|
|
|
1032
|
|
|
/** |
1033
|
|
|
* Inserts a new child immediately after the specified frame |
1034
|
|
|
* |
1035
|
|
|
* @param $new_child Frame The new Frame to insert |
1036
|
|
|
* @param $ref Frame The Frame before the new Frame |
1037
|
|
|
* @param $update_node boolean Whether or not to update the DOM |
1038
|
|
|
* |
1039
|
|
|
* @throws Exception |
1040
|
|
|
*/ |
1041
|
|
|
public function insert_child_after(Frame $new_child, Frame $ref, $update_node = true) |
1042
|
|
|
{ |
1043
|
|
|
if ($ref === $this->_last_child) { |
1044
|
|
|
$this->append_child($new_child, $update_node); |
1045
|
|
|
|
1046
|
|
|
return; |
1047
|
|
|
} |
1048
|
|
|
|
1049
|
|
|
if (is_null($ref)) { |
1050
|
|
|
$this->prepend_child($new_child, $update_node); |
1051
|
|
|
|
1052
|
|
|
return; |
1053
|
|
|
} |
1054
|
|
|
|
1055
|
|
|
if ($ref->_parent !== $this) { |
1056
|
|
|
throw new Exception("Reference child is not a child of this node."); |
1057
|
|
|
} |
1058
|
|
|
|
1059
|
|
|
// Update the node |
1060
|
|
|
if ($update_node) { |
1061
|
|
|
if ($ref->_next_sibling) { |
1062
|
|
|
$next_node = $ref->_next_sibling->_node; |
1063
|
|
|
$this->_node->insertBefore($new_child->_node, $next_node); |
1064
|
|
|
} else { |
1065
|
|
|
$new_child->_node = $this->_node->appendChild($new_child->_node); |
1066
|
|
|
} |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
// Remove the child from its parent |
1070
|
|
|
if ($new_child->_parent) { |
1071
|
|
|
$new_child->_parent->remove_child($new_child, false); |
1072
|
|
|
} |
1073
|
|
|
|
1074
|
|
|
$new_child->_parent = $this; |
1075
|
|
|
$new_child->_prev_sibling = $ref; |
1076
|
|
|
$new_child->_next_sibling = $ref->_next_sibling; |
1077
|
|
|
|
1078
|
|
|
if ($ref->_next_sibling) { |
1079
|
|
|
$ref->_next_sibling->_prev_sibling = $new_child; |
1080
|
|
|
} |
1081
|
|
|
|
1082
|
|
|
$ref->_next_sibling = $new_child; |
1083
|
|
|
} |
1084
|
|
|
|
1085
|
|
|
/** |
1086
|
|
|
* Remove a child frame |
1087
|
|
|
* |
1088
|
|
|
* @param Frame $child |
1089
|
|
|
* @param boolean $update_node Whether or not to remove the DOM node |
1090
|
|
|
* |
1091
|
|
|
* @throws Exception |
1092
|
|
|
* @return Frame The removed child frame |
1093
|
|
|
*/ |
1094
|
|
|
public function remove_child(Frame $child, $update_node = true) |
1095
|
|
|
{ |
1096
|
|
|
if ($child->_parent !== $this) { |
1097
|
|
|
throw new Exception("Child not found in this frame"); |
1098
|
|
|
} |
1099
|
|
|
|
1100
|
|
|
if ($update_node) { |
1101
|
|
|
$this->_node->removeChild($child->_node); |
1102
|
|
|
} |
1103
|
|
|
|
1104
|
|
|
if ($child === $this->_first_child) { |
1105
|
|
|
$this->_first_child = $child->_next_sibling; |
1106
|
|
|
} |
1107
|
|
|
|
1108
|
|
|
if ($child === $this->_last_child) { |
1109
|
|
|
$this->_last_child = $child->_prev_sibling; |
1110
|
|
|
} |
1111
|
|
|
|
1112
|
|
|
if ($child->_prev_sibling) { |
1113
|
|
|
$child->_prev_sibling->_next_sibling = $child->_next_sibling; |
1114
|
|
|
} |
1115
|
|
|
|
1116
|
|
|
if ($child->_next_sibling) { |
1117
|
|
|
$child->_next_sibling->_prev_sibling = $child->_prev_sibling; |
1118
|
|
|
} |
1119
|
|
|
|
1120
|
|
|
$child->_next_sibling = null; |
1121
|
|
|
$child->_prev_sibling = null; |
1122
|
|
|
$child->_parent = null; |
1123
|
|
|
|
1124
|
|
|
return $child; |
1125
|
|
|
} |
1126
|
|
|
|
1127
|
|
|
//........................................................................ |
|
|
|
|
1128
|
|
|
|
1129
|
|
|
// Debugging function: |
1130
|
|
|
/** |
1131
|
|
|
* @return string |
1132
|
|
|
*/ |
1133
|
|
|
public function __toString() |
1134
|
|
|
{ |
1135
|
|
|
// Skip empty text frames |
|
|
|
|
1136
|
|
|
// if ( $this->is_text_node() && |
1137
|
|
|
// preg_replace("/\s/", "", $this->_node->data) === "" ) |
1138
|
|
|
// return ""; |
1139
|
|
|
|
1140
|
|
|
|
1141
|
|
|
$str = "<b>" . $this->_node->nodeName . ":</b><br/>"; |
1142
|
|
|
//$str .= spl_object_hash($this->_node) . "<br/>"; |
|
|
|
|
1143
|
|
|
$str .= "Id: " . $this->get_id() . "<br/>"; |
1144
|
|
|
$str .= "Class: " . get_class($this) . "<br/>"; |
1145
|
|
|
|
1146
|
|
|
if ($this->is_text_node()) { |
1147
|
|
|
$tmp = htmlspecialchars($this->_node->nodeValue); |
1148
|
|
|
$str .= "<pre>'" . mb_substr($tmp, 0, 70) . |
1149
|
|
|
(mb_strlen($tmp) > 70 ? "..." : "") . "'</pre>"; |
1150
|
|
|
} elseif ($css_class = $this->_node->getAttribute("class")) { |
|
|
|
|
1151
|
|
|
$str .= "CSS class: '$css_class'<br/>"; |
1152
|
|
|
} |
1153
|
|
|
|
1154
|
|
View Code Duplication |
if ($this->_parent) { |
|
|
|
|
1155
|
|
|
$str .= "\nParent:" . $this->_parent->_node->nodeName . |
1156
|
|
|
" (" . spl_object_hash($this->_parent->_node) . ") " . |
1157
|
|
|
"<br/>"; |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
View Code Duplication |
if ($this->_prev_sibling) { |
|
|
|
|
1161
|
|
|
$str .= "Prev: " . $this->_prev_sibling->_node->nodeName . |
1162
|
|
|
" (" . spl_object_hash($this->_prev_sibling->_node) . ") " . |
1163
|
|
|
"<br/>"; |
1164
|
|
|
} |
1165
|
|
|
|
1166
|
|
View Code Duplication |
if ($this->_next_sibling) { |
|
|
|
|
1167
|
|
|
$str .= "Next: " . $this->_next_sibling->_node->nodeName . |
1168
|
|
|
" (" . spl_object_hash($this->_next_sibling->_node) . ") " . |
1169
|
|
|
"<br/>"; |
1170
|
|
|
} |
1171
|
|
|
|
1172
|
|
|
$d = $this->get_decorator(); |
1173
|
|
|
while ($d && $d != $d->get_decorator()) { |
1174
|
|
|
$str .= "Decorator: " . get_class($d) . "<br/>"; |
1175
|
|
|
$d = $d->get_decorator(); |
1176
|
|
|
} |
1177
|
|
|
|
1178
|
|
|
$str .= "Position: " . Helpers::pre_r($this->_position, true); |
1179
|
|
|
$str .= "\nContaining block: " . Helpers::pre_r($this->_containing_block, true); |
1180
|
|
|
$str .= "\nMargin width: " . Helpers::pre_r($this->get_margin_width(), true); |
1181
|
|
|
$str .= "\nMargin height: " . Helpers::pre_r($this->get_margin_height(), true); |
1182
|
|
|
|
1183
|
|
|
$str .= "\nStyle: <pre>" . $this->_style->__toString() . "</pre>"; |
1184
|
|
|
|
1185
|
|
|
if ($this->_decorator instanceof FrameDecorator\Block) { |
1186
|
|
|
$str .= "Lines:<pre>"; |
1187
|
|
|
foreach ($this->_decorator->get_line_boxes() as $line) { |
1188
|
|
|
foreach ($line->get_frames() as $frame) { |
1189
|
|
|
if ($frame instanceof FrameDecorator\Text) { |
1190
|
|
|
$str .= "\ntext: "; |
1191
|
|
|
$str .= "'" . htmlspecialchars($frame->get_text()) . "'"; |
1192
|
|
|
} else { |
1193
|
|
|
$str .= "\nBlock: " . $frame->get_node()->nodeName . " (" . spl_object_hash($frame->get_node()) . ")"; |
1194
|
|
|
} |
1195
|
|
|
} |
1196
|
|
|
|
1197
|
|
|
$str .= |
1198
|
|
|
"\ny => " . $line->y . "\n" . |
1199
|
|
|
"w => " . $line->w . "\n" . |
1200
|
|
|
"h => " . $line->h . "\n" . |
1201
|
|
|
"left => " . $line->left . "\n" . |
1202
|
|
|
"right => " . $line->right . "\n"; |
1203
|
|
|
} |
1204
|
|
|
$str .= "</pre>"; |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
$str .= "\n"; |
1208
|
|
|
if (php_sapi_name() === "cli") { |
1209
|
|
|
$str = strip_tags(str_replace(array("<br/>", "<b>", "</b>"), |
1210
|
|
|
array("\n", "", ""), |
1211
|
|
|
$str)); |
1212
|
|
|
} |
1213
|
|
|
|
1214
|
|
|
return $str; |
1215
|
|
|
} |
1216
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..