/var/www/hkosl.com/littleark/webadmin/libraies/dompdf/dompdf/src/Frame/Factory.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
/**
 * @package dompdf
 * @link    http://dompdf.github.com/
 * @author  Benj Carson <benjcarson@digitaljunkies.ca>
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 */
namespace Dompdf\Frame;

use 
Dompdf\Css\Style;
use 
Dompdf\Dompdf;
use 
Dompdf\Exception;
use 
Dompdf\Frame;
use 
Dompdf\FrameDecorator\AbstractFrameDecorator;
use 
DOMXPath;
use 
Dompdf\FrameDecorator\Page as PageFrameDecorator;
use 
Dompdf\FrameReflower\Page as PageFrameReflower;

/**
 * Contains frame decorating logic
 *
 * This class is responsible for assigning the correct {@link AbstractFrameDecorator},
 * {@link AbstractPositioner}, and {@link AbstractFrameReflower} objects to {@link Frame}
 * objects.  This is determined primarily by the Frame's display type, but
 * also by the Frame's node's type (e.g. DomElement vs. #text)
 *
 * @access  private
 * @package dompdf
 */
class Factory
{

    
/**
     * Decorate the root Frame
     *
     * @param $root   Frame The frame to decorate
     * @param $dompdf Dompdf The dompdf instance
     *
     * @return PageFrameDecorator
     */
    
static function decorate_root(Frame $rootDompdf $dompdf)
    {
        
$frame = new PageFrameDecorator($root$dompdf);
        
$frame->set_reflower(new PageFrameReflower($frame));
        
$root->set_decorator($frame);

        return 
$frame;
    }

    
/**
     * Decorate a Frame
     *
     * @param Frame $frame   The frame to decorate
     * @param Dompdf $dompdf The dompdf instance
     * @param Frame $root    The frame to decorate
     *
     * @throws Exception
     * @return AbstractFrameDecorator
     * FIXME: this is admittedly a little smelly...
     */
    
static function decorate_frame(Frame $frameDompdf $dompdfFrame $root null)
    {
        if (
is_null($dompdf)) {
            throw new 
Exception("The DOMPDF argument is required");
        }

        
$style $frame->get_style();

        
// Floating (and more generally out-of-flow) elements are blocks
        // http://coding.smashingmagazine.com/2007/05/01/css-float-theory-things-you-should-know/
        
if (!$frame->is_in_flow() && in_array($style->displayStyle::$INLINE_TYPES)) {
            
$style->display "block";
        }

        
$display $style->display;

        switch (
$display) {

            case 
"block":
                
$positioner "Block";
                
$decorator "Block";
                
$reflower "Block";
                break;

            case 
"inline-block":
                
$positioner "Inline";
                
$decorator "Block";
                
$reflower "Block";
                break;

            case 
"inline":
                
$positioner "Inline";
                if (
$frame->is_text_node()) {
                    
$decorator "Text";
                    
$reflower "Text";
                } else {
                    if (
$style->float !== "none") {
                        
$decorator "Block";
                        
$reflower "Block";
                    } else {
                        
$decorator "Inline";
                        
$reflower "Inline";
                    }
                }
                break;

            case 
"table":
                
$positioner "Block";
                
$decorator "Table";
                
$reflower "Table";
                break;

            case 
"inline-table":
                
$positioner "Inline";
                
$decorator "Table";
                
$reflower "Table";
                break;

            case 
"table-row-group":
            case 
"table-header-group":
            case 
"table-footer-group":
                
$positioner "NullPositioner";
                
$decorator "TableRowGroup";
                
$reflower "TableRowGroup";
                break;

            case 
"table-row":
                
$positioner "NullPositioner";
                
$decorator "TableRow";
                
$reflower "TableRow";
                break;

            case 
"table-cell":
                
$positioner "TableCell";
                
$decorator "TableCell";
                
$reflower "TableCell";
                break;

            case 
"list-item":
                
$positioner "Block";
                
$decorator "Block";
                
$reflower "Block";
                break;

            case 
"-dompdf-list-bullet":
                if (
$style->list_style_position === "inside") {
                    
$positioner "Inline";
                } else {
                    
$positioner "ListBullet";
                }

                if (
$style->list_style_image !== "none") {
                    
$decorator "ListBulletImage";
                } else {
                    
$decorator "ListBullet";
                }

                
$reflower "ListBullet";
                break;

            case 
"-dompdf-image":
                
$positioner "Inline";
                
$decorator "Image";
                
$reflower "Image";
                break;

            case 
"-dompdf-br":
                
$positioner "Inline";
                
$decorator "Inline";
                
$reflower "Inline";
                break;

            default:
                
// FIXME: should throw some sort of warning or something?
            
case "none":
                if (
$style->_dompdf_keep !== "yes") {
                    
// Remove the node and the frame
                    
$frame->get_parent()->remove_child($frame);
                    return;
                }

                
$positioner "NullPositioner";
                
$decorator "NullFrameDecorator";
                
$reflower "NullFrameReflower";
                break;
        }

        
// Handle CSS position
        
$position $style->position;

        if (
$position === "absolute") {
            
$positioner "Absolute";
        } else {
            if (
$position === "fixed") {
                
$positioner "Fixed";
            }
        }

        
$node $frame->get_node();

        
// Handle nodeName
        
if ($node->nodeName === "img") {
            
$style->display "-dompdf-image";
            
$decorator "Image";
            
$reflower "Image";
        }

        
$positioner "Dompdf\\Positioner\\$positioner";
        
$decorator  "Dompdf\\FrameDecorator\\$decorator";
        
$reflower   "Dompdf\\FrameReflower\\$reflower";

        
/** @var AbstractFrameDecorator $deco */
        
$deco = new $decorator($frame$dompdf);

        
$deco->set_positioner(new $positioner($deco));
        
$deco->set_reflower(new $reflower($deco$dompdf->getFontMetrics()));

        if (
$root) {
            
$deco->set_root($root);
        }

        if (
$display === "list-item") {
            
// Insert a list-bullet frame
            
$xml $dompdf->get_dom();
            
$bullet_node $xml->createElement("bullet"); // arbitrary choice
            
$b_f = new Frame($bullet_node);

            
$node $frame->get_node();
            
$parent_node $node->parentNode;

            if (
$parent_node) {
                if (!
$parent_node->hasAttribute("dompdf-children-count")) {
                    
$xpath = new DOMXPath($xml);
                    
$count $xpath->query("li"$parent_node)->length;
                    
$parent_node->setAttribute("dompdf-children-count"$count);
                }

                if (
is_numeric($node->getAttribute("value"))) {
                    
$index intval($node->getAttribute("value"));
                } else {
                    if (!
$parent_node->hasAttribute("dompdf-counter")) {
                        
$index = ($parent_node->hasAttribute("start") ? $parent_node->getAttribute("start") : 1);
                    } else {
                        
$index $parent_node->getAttribute("dompdf-counter") + 1;
                    }
                }

                
$parent_node->setAttribute("dompdf-counter"$index);
                
$bullet_node->setAttribute("dompdf-counter"$index);
            }

            
$new_style $dompdf->get_css()->create_style();
            
$new_style->display "-dompdf-list-bullet";
            
$new_style->inherit($style);
            
$b_f->set_style($new_style);

            
$deco->prepend_child(Factory::decorate_frame($b_f$dompdf$root));
        }

        return 
$deco;
    }
}