Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
class EdgePDF {
4
  var $width;
5
  var $color;
6
  var $style;
7
 
8
  var $_isDefaultColor;
9
 
10
  /**
11
   * Optimization: width/color fields of this class
12
   * never modified partially, so we could use one shared object
13
   * as a default value
14
   */
15
  function EdgePDF() {
16
    static $default_width = null;
17
    if (is_null($default_width)) {
18
      $default_width =& Value::fromData(0, UNIT_PT);
19
    };
20
 
21
    static $default_color = null;
22
    if (is_null($default_color)) {
23
      $default_color =& new Color(array(0,0,0), true);
24
    };
25
 
26
    $this->width =& $default_width;
27
    $this->color =& $default_color;
28
    $this->style = BS_NONE;
29
 
30
    $this->_isDefaultColor = true;
31
  }
32
 
33
  function isDefaultColor() {
34
    return $this->_isDefaultColor;
35
  }
36
 
37
  function setColor(&$color) {
38
    if ($color != CSS_PROPERTY_INHERIT) {
39
      $this->color = $color->copy();
40
    } else {
41
      $this->color = CSS_PROPERTY_INHERIT;
42
    };
43
 
44
    $this->_isDefaultColor = false;
45
  }
46
 
47
  function doInherit(&$state, $code_width, $code_color, $code_style) {
48
    if ($this->width === CSS_PROPERTY_INHERIT) {
49
      $value = $state->getInheritedProperty($code_width);
50
      $this->width = $value->copy();
51
    };
52
 
53
    if ($this->color === CSS_PROPERTY_INHERIT) {
54
      $value = $state->getInheritedProperty($code_color);
55
      $this->width = $value->copy();
56
    };
57
 
58
    if ($this->style === CSS_PROPERTY_INHERIT) {
59
      $value = $state->getInheritedProperty($code_style);
60
      $this->width = $value;
61
    };
62
  }
63
 
64
  function &create($data) {
65
    $edge =& new EdgePDF();
66
    $edge->width = $data['width'];
67
    $edge->color =& new Color($data['color'], is_transparent($data['color']));
68
    $edge->style = $data['style'];
69
    $edge->_isDefaultColor = true;
70
    return $edge;
71
  }
72
 
73
  function &copy() {
74
    $edge =& new EdgePDF();
75
 
76
    if ($this->width != CSS_PROPERTY_INHERIT) {
77
      $edge->width = $this->width->copy();
78
    } else {
79
      $edge->width = CSS_PROPERTY_INHERIT;
80
    };
81
 
82
    if ($this->color != CSS_PROPERTY_INHERIT) {
83
      $edge->color = $this->color->copy();
84
    } else {
85
      $edge->color = CSS_PROPERTY_INHERIT;
86
    };
87
 
88
    $edge->style = $this->style;
89
    $edge->_isDefaultColor = $this->_isDefaultColor;
90
 
91
    return $edge;
92
  }
93
 
94
  function &get_color() {
95
    return $this->color;
96
  }
97
 
98
  function &get_style() {
99
    return $this->style;
100
  }
101
 
102
  function get_width() {
103
    if ($this->style === BS_NONE) {
104
      return 0;
105
    };
106
 
107
    return $this->width->getPoints();
108
  }
109
 
110
  function units2pt($base_font_size) {
111
    $this->width->units2pt($base_font_size);
112
  }
113
 
114
  function is_visible() {
115
    return
116
      ($this->width->getPoints() > 0) &&
117
      ($this->style !== BS_NONE);
118
  }
119
 
120
  function show(&$viewport, &$box,
121
                $x1, $y1,
122
                $x2, $y2,
123
                $x3, $y3,
124
                $x4, $y4,
125
                $hilight) {
126
 
127
    // If this border have 'transparent' color value, we just will not draw it
128
    //
129
    if ($this->color->transparent) { return; };
130
 
131
    switch ($this->style) {
132
    case BS_SOLID:
133
      $this->color->apply($viewport);
134
 
135
      $viewport->moveto($x1, $y1);
136
      $viewport->lineto($x2, $y2);
137
      $viewport->lineto($x3, $y3);
138
      $viewport->lineto($x4, $y4);
139
      $viewport->closepath();
140
      $viewport->fill();
141
 
142
      break;
143
 
144
    case BS_INSET:
145
      if ($hilight) {
146
        $this->color->apply($viewport);
147
      } else {
148
        $color = $this->color->copy();
149
        $color->blend(new Color(array(255,255,255), false), HILIGHT_COLOR_ALPHA);
150
        $color->apply($viewport);
151
      };
152
 
153
      $viewport->moveto($x1, $y1);
154
      $viewport->lineto($x2, $y2);
155
      $viewport->lineto($x3, $y3);
156
      $viewport->lineto($x4, $y4);
157
      $viewport->closepath();
158
      $viewport->fill();
159
 
160
      break;
161
 
162
    case BS_GROOVE:
163
      /**
164
       * Draw outer part
165
       */
166
      if ($hilight) {
167
        $this->color->apply($viewport);
168
      } else {
169
        $color = $this->color->copy();
170
        $color->blend(new Color(array(255,255,255), false), HILIGHT_COLOR_ALPHA);
171
        $color->apply($viewport);
172
      };
173
 
174
      $viewport->moveto($x1, $y1);
175
      $viewport->lineto($x2, $y2);
176
      $viewport->lineto($x3, $y3);
177
      $viewport->lineto($x4, $y4);
178
      $viewport->closepath();
179
      $viewport->fill();
180
 
181
      /**
182
       * Draw inner part
183
       */
184
      if ($hilight) {
185
        $color = $this->color->copy();
186
        $color->blend(new Color(array(255,255,255), false), HILIGHT_COLOR_ALPHA);
187
        $color->apply($viewport);
188
      } else {
189
        $this->color->apply($viewport);
190
      };
191
 
192
      $x1a = ($x1 + $x4) / 2;
193
      $y1a = ($y1 + $y4) / 2;
194
 
195
      $x2a = ($x2 + $x3) / 2;
196
      $y2a = ($y2 + $y3) / 2;
197
 
198
      $viewport->moveto($x1a, $y1a);
199
      $viewport->lineto($x2a, $y2a);
200
      $viewport->lineto($x3, $y3);
201
      $viewport->lineto($x4, $y4);
202
      $viewport->closepath();
203
      $viewport->fill();
204
 
205
      break;
206
 
207
    case BS_RIDGE:
208
      /**
209
       * Draw outer part
210
       */
211
      if ($hilight) {
212
        $color = $this->color->copy();
213
        $color->blend(new Color(array(255,255,255), false), HILIGHT_COLOR_ALPHA);
214
        $color->apply($viewport);
215
      } else {
216
        $this->color->apply($viewport);
217
      };
218
 
219
      $viewport->moveto($x1, $y1);
220
      $viewport->lineto($x2, $y2);
221
      $viewport->lineto($x3, $y3);
222
      $viewport->lineto($x4, $y4);
223
      $viewport->closepath();
224
      $viewport->fill();
225
 
226
      /**
227
       * Draw inner part
228
       */
229
      if ($hilight) {
230
        $this->color->apply($viewport);
231
      } else {
232
        $color = $this->color->copy();
233
        $color->blend(new Color(array(255,255,255), false), HILIGHT_COLOR_ALPHA);
234
        $color->apply($viewport);
235
      };
236
 
237
      $x1a = ($x1 + $x4) / 2;
238
      $y1a = ($y1 + $y4) / 2;
239
 
240
      $x2a = ($x2 + $x3) / 2;
241
      $y2a = ($y2 + $y3) / 2;
242
 
243
      $viewport->moveto($x1a, $y1a);
244
      $viewport->lineto($x2a, $y2a);
245
      $viewport->lineto($x3, $y3);
246
      $viewport->lineto($x4, $y4);
247
      $viewport->closepath();
248
      $viewport->fill();
249
      break;
250
 
251
    case BS_OUTSET:
252
      if (!$hilight) {
253
        $this->color->apply($viewport);
254
      } else {
255
        $color = $this->color->copy();
256
        $color->blend(new Color(array(255,255,255), false), HILIGHT_COLOR_ALPHA);
257
        $color->apply($viewport);
258
      };
259
 
260
      $viewport->moveto($x1, $y1);
261
      $viewport->lineto($x2, $y2);
262
      $viewport->lineto($x3, $y3);
263
      $viewport->lineto($x4, $y4);
264
      $viewport->closepath();
265
      $viewport->fill();
266
 
267
      break;
268
 
269
    case BS_DASHED:
270
      $this->color->apply($viewport);
271
 
272
      $viewport->dash($this->width->getPoints()*4, $this->width->getPoints()*5);
273
      $viewport->setlinewidth($this->width->getPoints());
274
      $viewport->moveto(($x1+$x4)/2,($y1+$y4)/2);
275
      $viewport->lineto(($x2+$x3)/2,($y2+$y3)/2);
276
      $viewport->stroke();
277
 
278
      // Restore solid line
279
      $viewport->dash(1,0);
280
      break;
281
 
282
    case BS_DOTTED:
283
      $this->color->apply($viewport);
284
 
285
      $viewport->dash($this->width->getPoints(), $this->width->getPoints()*2);
286
      $viewport->setlinewidth($this->width->getPoints());
287
      $viewport->moveto(($x1+$x4)/2,($y1+$y4)/2);
288
      $viewport->lineto(($x2+$x3)/2,($y2+$y3)/2);
289
      $viewport->stroke();
290
 
291
      // Restore solid line
292
      $viewport->dash(1,0);
293
      break;
294
 
295
    case BS_DOUBLE:
296
      $this->color->apply($viewport);
297
      $viewport->setlinewidth(px2pt(1));
298
 
299
      $viewport->moveto($x1, $y1);
300
      $viewport->lineto($x2, $y2);
301
      $viewport->stroke();
302
 
303
      $viewport->moveto($x3, $y3);
304
      $viewport->lineto($x4, $y4);
305
      $viewport->stroke();
306
      break;
307
    case BS_NONE:
308
    default:
309
      break;
310
    }
311
  }
312
}
313
 
314
?>