Subversion Repositories Sites.obs-saisons.fr

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 aurelien 1
<?php
2
//=======================================================================
3
// File:	GD_IMAGE.INC.PHP
4
// Description:	GD Instance of Image class
5
// Created: 	2006-05-06
6
// Ver:		$Id: gd_image.inc.php 1008 2008-06-13 23:20:44Z ljp $
7
//
8
// Copyright (c) Aditus Consulting. All rights reserved.
9
//========================================================================
10
 
11
//===================================================
12
// CLASS RGB
13
// Description: Color definitions as RGB triples
14
//===================================================
15
class RGB {
16
    var $rgb_table;
17
    var $img;
18
    function RGB(&$aImg) {
19
	$this->img = &$aImg;
20
 
21
	// Conversion array between color names and RGB
22
	$this->rgb_table = array(
23
	    "aqua"=> array(0,255,255),
24
	    "lime"=> array(0,255,0),
25
	    "teal"=> array(0,128,128),
26
	    "whitesmoke"=>array(245,245,245),
27
	    "gainsboro"=>array(220,220,220),
28
	    "oldlace"=>array(253,245,230),
29
	    "linen"=>array(250,240,230),
30
	    "antiquewhite"=>array(250,235,215),
31
	    "papayawhip"=>array(255,239,213),
32
	    "blanchedalmond"=>array(255,235,205),
33
	    "bisque"=>array(255,228,196),
34
	    "peachpuff"=>array(255,218,185),
35
	    "navajowhite"=>array(255,222,173),
36
	    "moccasin"=>array(255,228,181),
37
	    "cornsilk"=>array(255,248,220),
38
	    "ivory"=>array(255,255,240),
39
	    "lemonchiffon"=>array(255,250,205),
40
	    "seashell"=>array(255,245,238),
41
	    "mintcream"=>array(245,255,250),
42
	    "azure"=>array(240,255,255),
43
	    "aliceblue"=>array(240,248,255),
44
	    "lavender"=>array(230,230,250),
45
	    "lavenderblush"=>array(255,240,245),
46
	    "mistyrose"=>array(255,228,225),
47
	    "white"=>array(255,255,255),
48
	    "black"=>array(0,0,0),
49
	    "darkslategray"=>array(47,79,79),
50
	    "dimgray"=>array(105,105,105),
51
	    "slategray"=>array(112,128,144),
52
	    "lightslategray"=>array(119,136,153),
53
	    "gray"=>array(190,190,190),
54
	    "lightgray"=>array(211,211,211),
55
	    "midnightblue"=>array(25,25,112),
56
	    "navy"=>array(0,0,128),
57
	    "cornflowerblue"=>array(100,149,237),
58
	    "darkslateblue"=>array(72,61,139),
59
	    "slateblue"=>array(106,90,205),
60
	    "mediumslateblue"=>array(123,104,238),
61
	    "lightslateblue"=>array(132,112,255),
62
	    "mediumblue"=>array(0,0,205),
63
	    "royalblue"=>array(65,105,225),
64
	    "blue"=>array(0,0,255),
65
	    "dodgerblue"=>array(30,144,255),
66
	    "deepskyblue"=>array(0,191,255),
67
	    "skyblue"=>array(135,206,235),
68
	    "lightskyblue"=>array(135,206,250),
69
	    "steelblue"=>array(70,130,180),
70
	    "lightred"=>array(211,167,168),
71
	    "lightsteelblue"=>array(176,196,222),
72
	    "lightblue"=>array(173,216,230),
73
	    "powderblue"=>array(176,224,230),
74
	    "paleturquoise"=>array(175,238,238),
75
	    "darkturquoise"=>array(0,206,209),
76
	    "mediumturquoise"=>array(72,209,204),
77
	    "turquoise"=>array(64,224,208),
78
	    "cyan"=>array(0,255,255),
79
	    "lightcyan"=>array(224,255,255),
80
	    "cadetblue"=>array(95,158,160),
81
	    "mediumaquamarine"=>array(102,205,170),
82
	    "aquamarine"=>array(127,255,212),
83
	    "darkgreen"=>array(0,100,0),
84
	    "darkolivegreen"=>array(85,107,47),
85
	    "darkseagreen"=>array(143,188,143),
86
	    "seagreen"=>array(46,139,87),
87
	    "mediumseagreen"=>array(60,179,113),
88
	    "lightseagreen"=>array(32,178,170),
89
	    "palegreen"=>array(152,251,152),
90
	    "springgreen"=>array(0,255,127),
91
	    "lawngreen"=>array(124,252,0),
92
	    "green"=>array(0,255,0),
93
	    "chartreuse"=>array(127,255,0),
94
	    "mediumspringgreen"=>array(0,250,154),
95
	    "greenyellow"=>array(173,255,47),
96
	    "limegreen"=>array(50,205,50),
97
	    "yellowgreen"=>array(154,205,50),
98
	    "forestgreen"=>array(34,139,34),
99
	    "olivedrab"=>array(107,142,35),
100
	    "darkkhaki"=>array(189,183,107),
101
	    "khaki"=>array(240,230,140),
102
	    "palegoldenrod"=>array(238,232,170),
103
	    "lightgoldenrodyellow"=>array(250,250,210),
104
	    "lightyellow"=>array(255,255,200),
105
	    "yellow"=>array(255,255,0),
106
	    "gold"=>array(255,215,0),
107
	    "lightgoldenrod"=>array(238,221,130),
108
	    "goldenrod"=>array(218,165,32),
109
	    "darkgoldenrod"=>array(184,134,11),
110
	    "rosybrown"=>array(188,143,143),
111
	    "indianred"=>array(205,92,92),
112
	    "saddlebrown"=>array(139,69,19),
113
	    "sienna"=>array(160,82,45),
114
	    "peru"=>array(205,133,63),
115
	    "burlywood"=>array(222,184,135),
116
	    "beige"=>array(245,245,220),
117
	    "wheat"=>array(245,222,179),
118
	    "sandybrown"=>array(244,164,96),
119
	    "tan"=>array(210,180,140),
120
	    "chocolate"=>array(210,105,30),
121
	    "firebrick"=>array(178,34,34),
122
	    "brown"=>array(165,42,42),
123
	    "darksalmon"=>array(233,150,122),
124
	    "salmon"=>array(250,128,114),
125
	    "lightsalmon"=>array(255,160,122),
126
	    "orange"=>array(255,165,0),
127
	    "darkorange"=>array(255,140,0),
128
	    "coral"=>array(255,127,80),
129
	    "lightcoral"=>array(240,128,128),
130
	    "tomato"=>array(255,99,71),
131
	    "orangered"=>array(255,69,0),
132
	    "red"=>array(255,0,0),
133
	    "hotpink"=>array(255,105,180),
134
	    "deeppink"=>array(255,20,147),
135
	    "pink"=>array(255,192,203),
136
	    "lightpink"=>array(255,182,193),
137
	    "palevioletred"=>array(219,112,147),
138
	    "maroon"=>array(176,48,96),
139
	    "mediumvioletred"=>array(199,21,133),
140
	    "violetred"=>array(208,32,144),
141
	    "magenta"=>array(255,0,255),
142
	    "violet"=>array(238,130,238),
143
	    "plum"=>array(221,160,221),
144
	    "orchid"=>array(218,112,214),
145
	    "mediumorchid"=>array(186,85,211),
146
	    "darkorchid"=>array(153,50,204),
147
	    "darkviolet"=>array(148,0,211),
148
	    "blueviolet"=>array(138,43,226),
149
	    "purple"=>array(160,32,240),
150
	    "mediumpurple"=>array(147,112,219),
151
	    "thistle"=>array(216,191,216),
152
	    "snow1"=>array(255,250,250),
153
	    "snow2"=>array(238,233,233),
154
	    "snow3"=>array(205,201,201),
155
	    "snow4"=>array(139,137,137),
156
	    "seashell1"=>array(255,245,238),
157
	    "seashell2"=>array(238,229,222),
158
	    "seashell3"=>array(205,197,191),
159
	    "seashell4"=>array(139,134,130),
160
	    "AntiqueWhite1"=>array(255,239,219),
161
	    "AntiqueWhite2"=>array(238,223,204),
162
	    "AntiqueWhite3"=>array(205,192,176),
163
	    "AntiqueWhite4"=>array(139,131,120),
164
	    "bisque1"=>array(255,228,196),
165
	    "bisque2"=>array(238,213,183),
166
	    "bisque3"=>array(205,183,158),
167
	    "bisque4"=>array(139,125,107),
168
	    "peachPuff1"=>array(255,218,185),
169
	    "peachpuff2"=>array(238,203,173),
170
	    "peachpuff3"=>array(205,175,149),
171
	    "peachpuff4"=>array(139,119,101),
172
	    "navajowhite1"=>array(255,222,173),
173
	    "navajowhite2"=>array(238,207,161),
174
	    "navajowhite3"=>array(205,179,139),
175
	    "navajowhite4"=>array(139,121,94),
176
	    "lemonchiffon1"=>array(255,250,205),
177
	    "lemonchiffon2"=>array(238,233,191),
178
	    "lemonchiffon3"=>array(205,201,165),
179
	    "lemonchiffon4"=>array(139,137,112),
180
	    "ivory1"=>array(255,255,240),
181
	    "ivory2"=>array(238,238,224),
182
	    "ivory3"=>array(205,205,193),
183
	    "ivory4"=>array(139,139,131),
184
	    "honeydew"=>array(193,205,193),
185
	    "lavenderblush1"=>array(255,240,245),
186
	    "lavenderblush2"=>array(238,224,229),
187
	    "lavenderblush3"=>array(205,193,197),
188
	    "lavenderblush4"=>array(139,131,134),
189
	    "mistyrose1"=>array(255,228,225),
190
	    "mistyrose2"=>array(238,213,210),
191
	    "mistyrose3"=>array(205,183,181),
192
	    "mistyrose4"=>array(139,125,123),
193
	    "azure1"=>array(240,255,255),
194
	    "azure2"=>array(224,238,238),
195
	    "azure3"=>array(193,205,205),
196
	    "azure4"=>array(131,139,139),
197
	    "slateblue1"=>array(131,111,255),
198
	    "slateblue2"=>array(122,103,238),
199
	    "slateblue3"=>array(105,89,205),
200
	    "slateblue4"=>array(71,60,139),
201
	    "royalblue1"=>array(72,118,255),
202
	    "royalblue2"=>array(67,110,238),
203
	    "royalblue3"=>array(58,95,205),
204
	    "royalblue4"=>array(39,64,139),
205
	    "dodgerblue1"=>array(30,144,255),
206
	    "dodgerblue2"=>array(28,134,238),
207
	    "dodgerblue3"=>array(24,116,205),
208
	    "dodgerblue4"=>array(16,78,139),
209
	    "steelblue1"=>array(99,184,255),
210
	    "steelblue2"=>array(92,172,238),
211
	    "steelblue3"=>array(79,148,205),
212
	    "steelblue4"=>array(54,100,139),
213
	    "deepskyblue1"=>array(0,191,255),
214
	    "deepskyblue2"=>array(0,178,238),
215
	    "deepskyblue3"=>array(0,154,205),
216
	    "deepskyblue4"=>array(0,104,139),
217
	    "skyblue1"=>array(135,206,255),
218
	    "skyblue2"=>array(126,192,238),
219
	    "skyblue3"=>array(108,166,205),
220
	    "skyblue4"=>array(74,112,139),
221
	    "lightskyblue1"=>array(176,226,255),
222
	    "lightskyblue2"=>array(164,211,238),
223
	    "lightskyblue3"=>array(141,182,205),
224
	    "lightskyblue4"=>array(96,123,139),
225
	    "slategray1"=>array(198,226,255),
226
	    "slategray2"=>array(185,211,238),
227
	    "slategray3"=>array(159,182,205),
228
	    "slategray4"=>array(108,123,139),
229
	    "lightsteelblue1"=>array(202,225,255),
230
	    "lightsteelblue2"=>array(188,210,238),
231
	    "lightsteelblue3"=>array(162,181,205),
232
	    "lightsteelblue4"=>array(110,123,139),
233
	    "lightblue1"=>array(191,239,255),
234
	    "lightblue2"=>array(178,223,238),
235
	    "lightblue3"=>array(154,192,205),
236
	    "lightblue4"=>array(104,131,139),
237
	    "lightcyan1"=>array(224,255,255),
238
	    "lightcyan2"=>array(209,238,238),
239
	    "lightcyan3"=>array(180,205,205),
240
	    "lightcyan4"=>array(122,139,139),
241
	    "paleturquoise1"=>array(187,255,255),
242
	    "paleturquoise2"=>array(174,238,238),
243
	    "paleturquoise3"=>array(150,205,205),
244
	    "paleturquoise4"=>array(102,139,139),
245
	    "cadetblue1"=>array(152,245,255),
246
	    "cadetblue2"=>array(142,229,238),
247
	    "cadetblue3"=>array(122,197,205),
248
	    "cadetblue4"=>array(83,134,139),
249
	    "turquoise1"=>array(0,245,255),
250
	    "turquoise2"=>array(0,229,238),
251
	    "turquoise3"=>array(0,197,205),
252
	    "turquoise4"=>array(0,134,139),
253
	    "cyan1"=>array(0,255,255),
254
	    "cyan2"=>array(0,238,238),
255
	    "cyan3"=>array(0,205,205),
256
	    "cyan4"=>array(0,139,139),
257
	    "darkslategray1"=>array(151,255,255),
258
	    "darkslategray2"=>array(141,238,238),
259
	    "darkslategray3"=>array(121,205,205),
260
	    "darkslategray4"=>array(82,139,139),
261
	    "aquamarine1"=>array(127,255,212),
262
	    "aquamarine2"=>array(118,238,198),
263
	    "aquamarine3"=>array(102,205,170),
264
	    "aquamarine4"=>array(69,139,116),
265
	    "darkseagreen1"=>array(193,255,193),
266
	    "darkseagreen2"=>array(180,238,180),
267
	    "darkseagreen3"=>array(155,205,155),
268
	    "darkseagreen4"=>array(105,139,105),
269
	    "seagreen1"=>array(84,255,159),
270
	    "seagreen2"=>array(78,238,148),
271
	    "seagreen3"=>array(67,205,128),
272
	    "seagreen4"=>array(46,139,87),
273
	    "palegreen1"=>array(154,255,154),
274
	    "palegreen2"=>array(144,238,144),
275
	    "palegreen3"=>array(124,205,124),
276
	    "palegreen4"=>array(84,139,84),
277
	    "springgreen1"=>array(0,255,127),
278
	    "springgreen2"=>array(0,238,118),
279
	    "springgreen3"=>array(0,205,102),
280
	    "springgreen4"=>array(0,139,69),
281
	    "chartreuse1"=>array(127,255,0),
282
	    "chartreuse2"=>array(118,238,0),
283
	    "chartreuse3"=>array(102,205,0),
284
	    "chartreuse4"=>array(69,139,0),
285
	    "olivedrab1"=>array(192,255,62),
286
	    "olivedrab2"=>array(179,238,58),
287
	    "olivedrab3"=>array(154,205,50),
288
	    "olivedrab4"=>array(105,139,34),
289
	    "darkolivegreen1"=>array(202,255,112),
290
	    "darkolivegreen2"=>array(188,238,104),
291
	    "darkolivegreen3"=>array(162,205,90),
292
	    "darkolivegreen4"=>array(110,139,61),
293
	    "khaki1"=>array(255,246,143),
294
	    "khaki2"=>array(238,230,133),
295
	    "khaki3"=>array(205,198,115),
296
	    "khaki4"=>array(139,134,78),
297
	    "lightgoldenrod1"=>array(255,236,139),
298
	    "lightgoldenrod2"=>array(238,220,130),
299
	    "lightgoldenrod3"=>array(205,190,112),
300
	    "lightgoldenrod4"=>array(139,129,76),
301
	    "yellow1"=>array(255,255,0),
302
	    "yellow2"=>array(238,238,0),
303
	    "yellow3"=>array(205,205,0),
304
	    "yellow4"=>array(139,139,0),
305
	    "gold1"=>array(255,215,0),
306
	    "gold2"=>array(238,201,0),
307
	    "gold3"=>array(205,173,0),
308
	    "gold4"=>array(139,117,0),
309
	    "goldenrod1"=>array(255,193,37),
310
	    "goldenrod2"=>array(238,180,34),
311
	    "goldenrod3"=>array(205,155,29),
312
	    "goldenrod4"=>array(139,105,20),
313
	    "darkgoldenrod1"=>array(255,185,15),
314
	    "darkgoldenrod2"=>array(238,173,14),
315
	    "darkgoldenrod3"=>array(205,149,12),
316
	    "darkgoldenrod4"=>array(139,101,8),
317
	    "rosybrown1"=>array(255,193,193),
318
	    "rosybrown2"=>array(238,180,180),
319
	    "rosybrown3"=>array(205,155,155),
320
	    "rosybrown4"=>array(139,105,105),
321
	    "indianred1"=>array(255,106,106),
322
	    "indianred2"=>array(238,99,99),
323
	    "indianred3"=>array(205,85,85),
324
	    "indianred4"=>array(139,58,58),
325
	    "sienna1"=>array(255,130,71),
326
	    "sienna2"=>array(238,121,66),
327
	    "sienna3"=>array(205,104,57),
328
	    "sienna4"=>array(139,71,38),
329
	    "burlywood1"=>array(255,211,155),
330
	    "burlywood2"=>array(238,197,145),
331
	    "burlywood3"=>array(205,170,125),
332
	    "burlywood4"=>array(139,115,85),
333
	    "wheat1"=>array(255,231,186),
334
	    "wheat2"=>array(238,216,174),
335
	    "wheat3"=>array(205,186,150),
336
	    "wheat4"=>array(139,126,102),
337
	    "tan1"=>array(255,165,79),
338
	    "tan2"=>array(238,154,73),
339
	    "tan3"=>array(205,133,63),
340
	    "tan4"=>array(139,90,43),
341
	    "chocolate1"=>array(255,127,36),
342
	    "chocolate2"=>array(238,118,33),
343
	    "chocolate3"=>array(205,102,29),
344
	    "chocolate4"=>array(139,69,19),
345
	    "firebrick1"=>array(255,48,48),
346
	    "firebrick2"=>array(238,44,44),
347
	    "firebrick3"=>array(205,38,38),
348
	    "firebrick4"=>array(139,26,26),
349
	    "brown1"=>array(255,64,64),
350
	    "brown2"=>array(238,59,59),
351
	    "brown3"=>array(205,51,51),
352
	    "brown4"=>array(139,35,35),
353
	    "salmon1"=>array(255,140,105),
354
	    "salmon2"=>array(238,130,98),
355
	    "salmon3"=>array(205,112,84),
356
	    "salmon4"=>array(139,76,57),
357
	    "lightsalmon1"=>array(255,160,122),
358
	    "lightsalmon2"=>array(238,149,114),
359
	    "lightsalmon3"=>array(205,129,98),
360
	    "lightsalmon4"=>array(139,87,66),
361
	    "orange1"=>array(255,165,0),
362
	    "orange2"=>array(238,154,0),
363
	    "orange3"=>array(205,133,0),
364
	    "orange4"=>array(139,90,0),
365
	    "darkorange1"=>array(255,127,0),
366
	    "darkorange2"=>array(238,118,0),
367
	    "darkorange3"=>array(205,102,0),
368
	    "darkorange4"=>array(139,69,0),
369
	    "coral1"=>array(255,114,86),
370
	    "coral2"=>array(238,106,80),
371
	    "coral3"=>array(205,91,69),
372
	    "coral4"=>array(139,62,47),
373
	    "tomato1"=>array(255,99,71),
374
	    "tomato2"=>array(238,92,66),
375
	    "tomato3"=>array(205,79,57),
376
	    "tomato4"=>array(139,54,38),
377
	    "orangered1"=>array(255,69,0),
378
	    "orangered2"=>array(238,64,0),
379
	    "orangered3"=>array(205,55,0),
380
	    "orangered4"=>array(139,37,0),
381
	    "deeppink1"=>array(255,20,147),
382
	    "deeppink2"=>array(238,18,137),
383
	    "deeppink3"=>array(205,16,118),
384
	    "deeppink4"=>array(139,10,80),
385
	    "hotpink1"=>array(255,110,180),
386
	    "hotpink2"=>array(238,106,167),
387
	    "hotpink3"=>array(205,96,144),
388
	    "hotpink4"=>array(139,58,98),
389
	    "pink1"=>array(255,181,197),
390
	    "pink2"=>array(238,169,184),
391
	    "pink3"=>array(205,145,158),
392
	    "pink4"=>array(139,99,108),
393
	    "lightpink1"=>array(255,174,185),
394
	    "lightpink2"=>array(238,162,173),
395
	    "lightpink3"=>array(205,140,149),
396
	    "lightpink4"=>array(139,95,101),
397
	    "palevioletred1"=>array(255,130,171),
398
	    "palevioletred2"=>array(238,121,159),
399
	    "palevioletred3"=>array(205,104,137),
400
	    "palevioletred4"=>array(139,71,93),
401
	    "maroon1"=>array(255,52,179),
402
	    "maroon2"=>array(238,48,167),
403
	    "maroon3"=>array(205,41,144),
404
	    "maroon4"=>array(139,28,98),
405
	    "violetred1"=>array(255,62,150),
406
	    "violetred2"=>array(238,58,140),
407
	    "violetred3"=>array(205,50,120),
408
	    "violetred4"=>array(139,34,82),
409
	    "magenta1"=>array(255,0,255),
410
	    "magenta2"=>array(238,0,238),
411
	    "magenta3"=>array(205,0,205),
412
	    "magenta4"=>array(139,0,139),
413
	    "mediumred"=>array(140,34,34),
414
	    "orchid1"=>array(255,131,250),
415
	    "orchid2"=>array(238,122,233),
416
	    "orchid3"=>array(205,105,201),
417
	    "orchid4"=>array(139,71,137),
418
	    "plum1"=>array(255,187,255),
419
	    "plum2"=>array(238,174,238),
420
	    "plum3"=>array(205,150,205),
421
	    "plum4"=>array(139,102,139),
422
	    "mediumorchid1"=>array(224,102,255),
423
	    "mediumorchid2"=>array(209,95,238),
424
	    "mediumorchid3"=>array(180,82,205),
425
	    "mediumorchid4"=>array(122,55,139),
426
	    "darkorchid1"=>array(191,62,255),
427
	    "darkorchid2"=>array(178,58,238),
428
	    "darkorchid3"=>array(154,50,205),
429
	    "darkorchid4"=>array(104,34,139),
430
	    "purple1"=>array(155,48,255),
431
	    "purple2"=>array(145,44,238),
432
	    "purple3"=>array(125,38,205),
433
	    "purple4"=>array(85,26,139),
434
	    "mediumpurple1"=>array(171,130,255),
435
	    "mediumpurple2"=>array(159,121,238),
436
	    "mediumpurple3"=>array(137,104,205),
437
	    "mediumpurple4"=>array(93,71,139),
438
	    "thistle1"=>array(255,225,255),
439
	    "thistle2"=>array(238,210,238),
440
	    "thistle3"=>array(205,181,205),
441
	    "thistle4"=>array(139,123,139),
442
	    "gray1"=>array(10,10,10),
443
	    "gray2"=>array(40,40,30),
444
	    "gray3"=>array(70,70,70),
445
	    "gray4"=>array(100,100,100),
446
	    "gray5"=>array(130,130,130),
447
	    "gray6"=>array(160,160,160),
448
	    "gray7"=>array(190,190,190),
449
	    "gray8"=>array(210,210,210),
450
	    "gray9"=>array(240,240,240),
451
	    "darkgray"=>array(100,100,100),
452
	    "darkblue"=>array(0,0,139),
453
	    "darkcyan"=>array(0,139,139),
454
	    "darkmagenta"=>array(139,0,139),
455
	    "darkred"=>array(139,0,0),
456
	    "silver"=>array(192, 192, 192),
457
	    "eggplant"=>array(144,176,168),
458
	    "lightgreen"=>array(144,238,144));
459
    }
460
//----------------
461
// PUBLIC METHODS
462
    // Colors can be specified as either
463
    // 1. #xxxxxx			HTML style
464
    // 2. "colorname" 	as a named color
465
    // 3. array(r,g,b)	RGB triple
466
    // This function translates this to a native RGB format and returns an
467
    // RGB triple.
468
    function Color($aColor) {
469
	if (is_string($aColor)) {
470
	    // Strip of any alpha factor
471
	    $pos = strpos($aColor,'@');
472
	    if( $pos === false ) {
473
		$alpha = 0;
474
	    }
475
	    else {
476
		$pos2 = strpos($aColor,':');
477
		if( $pos2===false )
478
		    $pos2 = $pos-1; // Sentinel
479
		if( $pos > $pos2 ) {
480
		    $alpha = str_replace(',','.',substr($aColor,$pos+1));
481
		    $aColor = substr($aColor,0,$pos);
482
		}
483
		else {
484
		    $alpha = substr($aColor,$pos+1,$pos2-$pos-1);
485
		    $aColor = substr($aColor,0,$pos).substr($aColor,$pos2);
486
		}
487
	    }
488
 
489
	    // Extract potential adjustment figure at end of color
490
	    // specification
491
	    $pos = strpos($aColor,":");
492
	    if( $pos === false ) {
493
		$adj = 1.0;
494
	    }
495
	    else {
496
		$adj = 0.0 + str_replace(',','.',substr($aColor,$pos+1));
497
		$aColor = substr($aColor,0,$pos);
498
	    }
499
	    if( $adj < 0 )
500
		JpGraphError::RaiseL(25077);//('Adjustment factor for color must be > 0');
501
 
502
	    if (substr($aColor, 0, 1) == "#") {
503
		$r = hexdec(substr($aColor, 1, 2));
504
		$g = hexdec(substr($aColor, 3, 2));
505
		$b = hexdec(substr($aColor, 5, 2));
506
	    } else {
507
      		if(!isset($this->rgb_table[$aColor]) )
508
		    JpGraphError::RaiseL(25078,$aColor);//(" Unknown color: $aColor");
509
		$tmp=$this->rgb_table[$aColor];
510
		$r = $tmp[0];
511
		$g = $tmp[1];
512
		$b = $tmp[2];
513
	    }
514
	    // Scale adj so that an adj=2 always
515
	    // makes the color 100% white (i.e. 255,255,255.
516
	    // and adj=1 neutral and adj=0 black.
517
	    if( $adj > 1 ) {
518
		$m = ($adj-1.0)*(255-min(255,min($r,min($g,$b))));
519
		return array(min(255,$r+$m), min(255,$g+$m), min(255,$b+$m),$alpha);
520
	    }
521
	    elseif( $adj < 1 ) {
522
		$m = ($adj-1.0)*max(255,max($r,max($g,$b)));
523
		return array(max(0,$r+$m), max(0,$g+$m), max(0,$b+$m),$alpha);
524
	    }
525
	    else {
526
		return array($r,$g,$b,$alpha);
527
	    }
528
 
529
	} elseif( is_array($aColor) ) {
530
	    if( count($aColor)==3 ) {
531
		$aColor[3]=0;
532
		return $aColor;
533
	    }
534
	    else
535
		return $aColor;
536
	}
537
	else
538
	    JpGraphError::RaiseL(25079,$aColor,count($aColor));//(" Unknown color specification: $aColor , size=".count($aColor));
539
    }
540
 
541
    // Compare two colors
542
    // return true if equal
543
    function Equal($aCol1,$aCol2) {
544
	$c1 = $this->Color($aCol1);
545
	$c2 = $this->Color($aCol2);
546
	if( $c1[0]==$c2[0] && $c1[1]==$c2[1] && $c1[2]==$c2[2] )
547
	    return true;
548
	else
549
	    return false;
550
    }
551
 
552
    // Allocate a new color in the current image
553
    // Return new color index, -1 if no more colors could be allocated
554
    function Allocate($aColor,$aAlpha=0.0) {
555
	list ($r, $g, $b, $a) = $this->color($aColor);
556
	// If alpha is specified in the color string then this
557
	// takes precedence over the second argument
558
	if( $a > 0 )
559
	    $aAlpha = $a;
560
	if( $aAlpha < 0 || $aAlpha > 1 ) {
561
	    JpGraphError::RaiseL(25080);//('Alpha parameter for color must be between 0.0 and 1.0');
562
	}
563
	return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127));
564
    }
565
} // Class
566
 
567
 
568
//===================================================
569
// CLASS Image
570
// Description: Wrapper class with some goodies to form the
571
// Interface to low level image drawing routines.
572
//===================================================
573
class Image {
574
    var $img_format;
575
    var $expired=true;
576
    var $img=null;
577
    var $left_margin=30,$right_margin=20,$top_margin=20,$bottom_margin=30;
578
    var $plotwidth=0,$plotheight=0;
579
    var $rgb=null;
580
    var $current_color,$current_color_name;
581
    var $lastx=0, $lasty=0;
582
    var $width=0, $height=0;
583
    var $line_weight=1;
584
    var $line_style=1;	// Default line style is solid
585
    var $obs_list=array();
586
    var $font_size=12,$font_family=FF_FONT1, $font_style=FS_NORMAL;
587
    var $font_file='';
588
    var $text_halign="left",$text_valign="bottom";
589
    var $ttf=null;
590
    var $use_anti_aliasing=false;
591
    var $quality=null;
592
    var $colorstack=array(),$colorstackidx=0;
593
    var $canvascolor = 'white' ;
594
    var $langconv = null ;
595
 
596
    //---------------
597
    // CONSTRUCTOR
598
    function Image($aWidth,$aHeight,$aFormat=DEFAULT_GFORMAT,$aSetAutoMargin=true) {
599
	$this->CreateImgCanvas($aWidth,$aHeight);
600
	if( $aSetAutoMargin )
601
	    $this->SetAutoMargin();
602
 
603
	if( !$this->SetImgFormat($aFormat) ) {
604
	    JpGraphError::RaiseL(25081,$aFormat);//("JpGraph: Selected graphic format is either not supported or unknown [$aFormat]");
605
	}
606
	$this->ttf = new TTF();
607
	$this->langconv = new LanguageConv();
608
    }
609
 
610
    // Should we use anti-aliasing. Note: This really slows down graphics!
611
    function SetAntiAliasing() {
612
	$this->use_anti_aliasing=true;
613
    }
614
 
615
    function CreateRawCanvas($aWidth=0,$aHeight=0) {
616
	if( $aWidth <= 1 || $aHeight <= 1 ) {
617
	    JpGraphError::RaiseL(25082,$aWidth,$aHeight);//("Illegal sizes specified for width or height when creating an image, (width=$aWidth, height=$aHeight)");
618
	}
619
	$this->img = @imagecreatetruecolor($aWidth, $aHeight);
620
	if( $this->img < 1 ) {
621
	    JpGraphError::RaiseL(25126);
622
	    //die("Can't create truecolor image. Check that you really have GD2 library installed.");
623
	}
624
	$this->SetAlphaBlending();
625
	if( $this->rgb != null )
626
	    $this->rgb->img = $this->img ;
627
	else
628
	    $this->rgb = new RGB($this->img);
629
    }
630
 
631
    function CloneCanvasH() {
632
	$oldimage = $this->img;
633
	$this->CreateRawCanvas($this->width,$this->height);
634
	imagecopy($this->img,$oldimage,0,0,0,0,$this->width,$this->height);
635
	return $oldimage;
636
    }
637
 
638
    function CreateImgCanvas($aWidth=0,$aHeight=0) {
639
 
640
	$old = array($this->img,$this->width,$this->height);
641
 
642
	$aWidth = round($aWidth);
643
	$aHeight = round($aHeight);
644
 
645
	$this->width=$aWidth;
646
	$this->height=$aHeight;
647
 
648
 
649
	if( $aWidth==0 || $aHeight==0 ) {
650
	    // We will set the final size later.
651
	    // Note: The size must be specified before any other
652
	    // img routines that stroke anything are called.
653
	    $this->img = null;
654
	    $this->rgb = null;
655
	    return $old;
656
	}
657
 
658
	$this->CreateRawCanvas($aWidth,$aHeight);
659
 
660
	// Set canvas color (will also be the background color for a
661
	// a pallett image
662
	$this->SetColor($this->canvascolor);
663
	$this->FilledRectangle(0,0,$aWidth,$aHeight);
664
 
665
	return $old ;
666
    }
667
 
668
    function CopyCanvasH($aToHdl,$aFromHdl,$aToX,$aToY,$aFromX,$aFromY,$aWidth,$aHeight,$aw=-1,$ah=-1) {
669
	if( $aw === -1 ) {
670
	    $aw = $aWidth;
671
	    $ah = $aHeight;
672
	    $f = 'imagecopyresized';
673
	}
674
	else {
675
	    $f = 'imagecopyresampled' ;
676
	}
677
	$f($aToHdl,$aFromHdl,
678
	   $aToX,$aToY,$aFromX,$aFromY, $aWidth,$aHeight,$aw,$ah);
679
    }
680
 
681
    function Copy($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth=-1,$fromHeight=-1) {
682
	$this->CopyCanvasH($this->img,$fromImg,$toX,$toY,$fromX,$fromY,
683
			   $toWidth,$toHeight,$fromWidth,$fromHeight);
684
    }
685
 
686
    function CopyMerge($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth=-1,$fromHeight=-1,$aMix=100) {
687
	if( $aMix == 100 ) {
688
	    $this->CopyCanvasH($this->img,$fromImg,
689
			       $toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth,$fromHeight);
690
	}
691
	else {
692
	    if( ($fromWidth  != -1 && ($fromWidth != $toWidth))  ||
693
		($fromHeight != -1 && ($fromHeight != $fromHeight)) ) {
694
		// Create a new canvas that will hold the re-scaled original from image
695
		if( $toWidth <= 1 || $toHeight <= 1 ) {
696
		    JpGraphError::RaiseL(25083);//('Illegal image size when copying image. Size for copied to image is 1 pixel or less.');
697
		}
698
		$tmpimg = @imagecreatetruecolor($toWidth, $toHeight);
699
		if( $tmpimg < 1 ) {
700
		    JpGraphError::RaiseL(25084);//('Failed to create temporary GD canvas. Out of memory ?');
701
		}
702
		$this->CopyCanvasH($tmpimg,$fromImg,0,0,0,0,
703
				   $toWidth,$toHeight,$fromWidth,$fromHeight);
704
		$fromImg = $tmpimg;
705
	    }
706
	    imagecopymerge($this->img,$fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$aMix);
707
	}
708
    }
709
 
710
    function GetWidth($aImg=null) {
711
	if( $aImg === null )
712
	    $aImg = $this->img;
713
	return imagesx($aImg);
714
    }
715
 
716
    function GetHeight($aImg=null) {
717
	if( $aImg === null )
718
	    $aImg = $this->img;
719
	return imagesy($aImg);
720
    }
721
 
722
    function CreateFromString($aStr) {
723
	$img = @imagecreatefromstring($aStr);
724
	if( $img === false ) {
725
	    JpGraphError::RaiseL(25085);//('An image can not be created from the supplied string. It is either in a format not supported or the string is representing an corrupt image.');
726
	}
727
	return $img;
728
    }
729
 
730
    function SetCanvasH($aHdl) {
731
	$this->img = $aHdl;
732
	$this->rgb->img = $aHdl;
733
    }
734
 
735
    function SetCanvasColor($aColor) {
736
	$this->canvascolor = $aColor ;
737
    }
738
 
739
    function SetAlphaBlending($aFlg=true) {
740
	ImageAlphaBlending($this->img,$aFlg);
741
    }
742
 
743
 
744
    function SetAutoMargin() {
745
	GLOBAL $gJpgBrandTiming;
746
	$min_bm=5;
747
	/*
748
	if( $gJpgBrandTiming )
749
	    $min_bm=15;
750
	*/
751
	$lm = min(40,$this->width/7);
752
	$rm = min(20,$this->width/10);
753
	$tm = max(5,$this->height/7);
754
	$bm = max($min_bm,$this->height/7);
755
 
756
	$this->SetMargin($lm,$rm,$tm,$bm);
757
    }
758
 
759
 
760
    //---------------
761
    // PUBLIC METHODS
762
 
763
    function SetFont($family,$style=FS_NORMAL,$size=10) {
764
	$this->font_family=$family;
765
	$this->font_style=$style;
766
	$this->font_size=$size;
767
	$this->font_file='';
768
	if( ($this->font_family==FF_FONT1 || $this->font_family==FF_FONT2) && $this->font_style==FS_BOLD ){
769
	    ++$this->font_family;
770
	}
771
	if( $this->font_family > FF_FONT2+1 ) { // A TTF font so get the font file
772
 
773
	    // Check that this PHP has support for TTF fonts
774
	    if( !function_exists('imagettfbbox') ) {
775
		JpGraphError::RaiseL(25087);//('This PHP build has not been configured with TTF support. You need to recompile your PHP installation with FreeType support.');
776
	    }
777
	    $this->font_file = $this->ttf->File($this->font_family,$this->font_style);
778
	}
779
    }
780
 
781
    // Get the specific height for a text string
782
    function GetTextHeight($txt="",$angle=0) {
783
	$tmp = split("\n",$txt);
784
	$n = count($tmp);
785
	$m=0;
786
	for($i=0; $i< $n; ++$i)
787
	    $m = max($m,strlen($tmp[$i]));
788
 
789
	if( $this->font_family <= FF_FONT2+1 ) {
790
	    if( $angle==0 ) {
791
		$h = imagefontheight($this->font_family);
792
		if( $h === false ) {
793
		    JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.');
794
		}
795
 
796
		return $n*$h;
797
	    }
798
	    else {
799
		$w = @imagefontwidth($this->font_family);
800
		if( $w === false ) {
801
		    JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.');
802
		}
803
 
804
		return $m*$w;
805
	    }
806
	}
807
	else {
808
	    $bbox = $this->GetTTFBBox($txt,$angle);
809
	    return $bbox[1]-$bbox[5];
810
	}
811
    }
812
 
813
    // Estimate font height
814
    function GetFontHeight($angle=0) {
815
	$txt = "XOMg";
816
	return $this->GetTextHeight($txt,$angle);
817
    }
818
 
819
    // Approximate font width with width of letter "O"
820
    function GetFontWidth($angle=0) {
821
	$txt = 'O';
822
	return $this->GetTextWidth($txt,$angle);
823
    }
824
 
825
    // Get actual width of text in absolute pixels
826
    function GetTextWidth($txt,$angle=0) {
827
 
828
	$tmp = split("\n",$txt);
829
	$n = count($tmp);
830
	if( $this->font_family <= FF_FONT2+1 ) {
831
 
832
	    $m=0;
833
	    for($i=0; $i < $n; ++$i) {
834
		$l=strlen($tmp[$i]);
835
		if( $l > $m ) {
836
		    $m = $l;
837
		}
838
	    }
839
 
840
	    if( $angle==0 ) {
841
		$w = @imagefontwidth($this->font_family);
842
		if( $w === false ) {
843
		    JpGraphError::RaiseL(25088);//('You have a misconfigured GD font support. The call to imagefontwidth() fails.');
844
		}
845
		return $m*$w;
846
	    }
847
	    else {
848
		// 90 degrees internal so height becomes width
849
		$h = @imagefontheight($this->font_family);
850
		if( $h === false ) {
851
		    JpGraphError::RaiseL(25089);//('You have a misconfigured GD font support. The call to imagefontheight() fails.');
852
		}
853
		return $n*$h;
854
	    }
855
	}
856
	else {
857
	    // For TTF fonts we must walk through a lines and find the
858
	    // widest one which we use as the width of the multi-line
859
	    // paragraph
860
	    $m=0;
861
	    for( $i=0; $i < $n; ++$i ) {
862
		$bbox = $this->GetTTFBBox($tmp[$i],$angle);
863
		$mm =  $bbox[2] - $bbox[0];
864
		if( $mm > $m )
865
		    $m = $mm;
866
	    }
867
	    return $m;
868
	}
869
    }
870
 
871
    // Draw text with a box around it
872
    function StrokeBoxedText($x,$y,$txt,$dir=0,$fcolor="white",$bcolor="black",
873
			     $shadowcolor=false,$paragraph_align="left",
874
			     $xmarg=6,$ymarg=4,$cornerradius=0,$dropwidth=3) {
875
 
876
	if( !is_numeric($dir) ) {
877
	    if( $dir=="h" ) $dir=0;
878
	    elseif( $dir=="v" ) $dir=90;
879
	    else JpGraphError::RaiseL(25090,$dir);//(" Unknown direction specified in call to StrokeBoxedText() [$dir]");
880
	}
881
 
882
	if( $this->font_family >= FF_FONT0 && $this->font_family <= FF_FONT2+1) {
883
	    $width=$this->GetTextWidth($txt,$dir) ;
884
	    $height=$this->GetTextHeight($txt,$dir) ;
885
	}
886
	else {
887
	    $width=$this->GetBBoxWidth($txt,$dir) ;
888
	    $height=$this->GetBBoxHeight($txt,$dir) ;
889
	}
890
 
891
	$height += 2*$ymarg;
892
	$width  += 2*$xmarg;
893
 
894
	if( $this->text_halign=="right" ) $x -= $width;
895
	elseif( $this->text_halign=="center" ) $x -= $width/2;
896
	if( $this->text_valign=="bottom" ) $y -= $height;
897
	elseif( $this->text_valign=="center" ) $y -= $height/2;
898
 
899
	$olda = $this->SetAngle(0);
900
 
901
	if( $shadowcolor ) {
902
	    $this->PushColor($shadowcolor);
903
	    $this->FilledRoundedRectangle($x-$xmarg+$dropwidth,$y-$ymarg+$dropwidth,
904
					  $x+$width+$dropwidth,$y+$height-$ymarg+$dropwidth,
905
					  $cornerradius);
906
	    $this->PopColor();
907
	    $this->PushColor($fcolor);
908
	    $this->FilledRoundedRectangle($x-$xmarg,$y-$ymarg,
909
					  $x+$width,$y+$height-$ymarg,
910
					  $cornerradius);
911
	    $this->PopColor();
912
	    $this->PushColor($bcolor);
913
	    $this->RoundedRectangle($x-$xmarg,$y-$ymarg,
914
				    $x+$width,$y+$height-$ymarg,$cornerradius);
915
	    $this->PopColor();
916
	}
917
	else {
918
	    if( $fcolor ) {
919
		$oc=$this->current_color;
920
		$this->SetColor($fcolor);
921
		$this->FilledRoundedRectangle($x-$xmarg,$y-$ymarg,$x+$width,$y+$height-$ymarg,$cornerradius);
922
		$this->current_color=$oc;
923
	    }
924
	    if( $bcolor ) {
925
		$oc=$this->current_color;
926
		$this->SetColor($bcolor);
927
		$this->RoundedRectangle($x-$xmarg,$y-$ymarg,$x+$width,$y+$height-$ymarg,$cornerradius);
928
		$this->current_color=$oc;
929
	    }
930
	}
931
 
932
	$h=$this->text_halign;
933
	$v=$this->text_valign;
934
	$this->SetTextAlign("left","top");
935
	$this->StrokeText($x, $y, $txt, $dir, $paragraph_align);
936
	$bb = array($x-$xmarg,$y+$height-$ymarg,$x+$width,$y+$height-$ymarg,
937
		    $x+$width,$y-$ymarg,$x-$xmarg,$y-$ymarg);
938
	$this->SetTextAlign($h,$v);
939
 
940
	$this->SetAngle($olda);
941
 
942
	return $bb;
943
    }
944
 
945
    // Set text alignment
946
    function SetTextAlign($halign,$valign="bottom") {
947
	$this->text_halign=$halign;
948
	$this->text_valign=$valign;
949
    }
950
 
951
 
952
    function _StrokeBuiltinFont($x,$y,$txt,$dir=0,$paragraph_align="left",&$aBoundingBox,$aDebug=false) {
953
 
954
	if( is_numeric($dir) && $dir!=90 && $dir!=0)
955
	    JpGraphError::RaiseL(25091);//(" Internal font does not support drawing text at arbitrary angle. Use TTF fonts instead.");
956
 
957
	$h=$this->GetTextHeight($txt);
958
	$fh=$this->GetFontHeight();
959
	$w=$this->GetTextWidth($txt);
960
 
961
	if( $this->text_halign=="right")
962
	    $x -= $dir==0 ? $w : $h;
963
	elseif( $this->text_halign=="center" ) {
964
	    // For center we subtract 1 pixel since this makes the middle
965
	    // be prefectly in the middle
966
	    $x -= $dir==0 ? $w/2-1 : $h/2;
967
	}
968
	if( $this->text_valign=="top" )
969
	    $y += $dir==0 ? $h : $w;
970
	elseif( $this->text_valign=="center" )
971
	    $y += $dir==0 ? $h/2 : $w/2;
972
 
973
	if( $dir==90 ) {
974
	    imagestringup($this->img,$this->font_family,$x,$y,$txt,$this->current_color);
975
	    $aBoundingBox = array(round($x),round($y),round($x),round($y-$w),round($x+$h),round($y-$w),round($x+$h),round($y));
976
            if( $aDebug ) {
977
		// Draw bounding box
978
		$this->PushColor('green');
979
		$this->Polygon($aBoundingBox,true);
980
		$this->PopColor();
981
	    }
982
	}
983
	else {
984
	    if( ereg("\n",$txt) ) {
985
		$tmp = split("\n",$txt);
986
		for($i=0; $i < count($tmp); ++$i) {
987
		    $w1 = $this->GetTextWidth($tmp[$i]);
988
		    if( $paragraph_align=="left" ) {
989
			imagestring($this->img,$this->font_family,$x,$y-$h+1+$i*$fh,$tmp[$i],$this->current_color);
990
		    }
991
		    elseif( $paragraph_align=="right" ) {
992
			imagestring($this->img,$this->font_family,$x+($w-$w1),
993
				    $y-$h+1+$i*$fh,$tmp[$i],$this->current_color);
994
		    }
995
		    else {
996
			imagestring($this->img,$this->font_family,$x+$w/2-$w1/2,
997
				    $y-$h+1+$i*$fh,$tmp[$i],$this->current_color);
998
		    }
999
		}
1000
	    }
1001
	    else {
1002
		//Put the text
1003
		imagestring($this->img,$this->font_family,$x,$y-$h+1,$txt,$this->current_color);
1004
	    }
1005
            if( $aDebug ) {
1006
		// Draw the bounding rectangle and the bounding box
1007
		$p1 = array(round($x),round($y),round($x),round($y-$h),round($x+$w),round($y-$h),round($x+$w),round($y));
1008
 
1009
		// Draw bounding box
1010
		$this->PushColor('green');
1011
		$this->Polygon($p1,true);
1012
		$this->PopColor();
1013
 
1014
            }
1015
	    $aBoundingBox=array(round($x),round($y),round($x),round($y-$h),round($x+$w),round($y-$h),round($x+$w),round($y));
1016
	}
1017
    }
1018
 
1019
    function AddTxtCR($aTxt) {
1020
	// If the user has just specified a '\n'
1021
	// instead of '\n\t' we have to add '\r' since
1022
	// the width will be too muchy otherwise since when
1023
	// we print we stroke the individually lines by hand.
1024
	$e = explode("\n",$aTxt);
1025
	$n = count($e);
1026
	for($i=0; $i<$n; ++$i) {
1027
	    $e[$i]=str_replace("\r","",$e[$i]);
1028
	}
1029
	return implode("\n\r",$e);
1030
    }
1031
 
1032
    function GetTTFBBox($aTxt,$aAngle=0) {
1033
	$bbox = @ImageTTFBBox($this->font_size,$aAngle,$this->font_file,$aTxt);
1034
	if( $bbox === false ) {
1035
	    JpGraphError::RaiseL(25092,$this->font_file);
1036
//("There is either a configuration problem with TrueType or a problem reading font file (".$this->font_file."). Make sure file exists and is in a readable place for the HTTP process. (If 'basedir' restriction is enabled in PHP then the font file must be located in the document root.). It might also be a wrongly installed FreeType library. Try uppgrading to at least FreeType 2.1.13 and recompile GD with the correct setup so it can find the new FT library.");
1037
	}
1038
	return $bbox;
1039
    }
1040
 
1041
    function GetBBoxTTF($aTxt,$aAngle=0) {
1042
	// Normalize the bounding box to become a minimum
1043
	// enscribing rectangle
1044
 
1045
	$aTxt = $this->AddTxtCR($aTxt);
1046
 
1047
	if( !is_readable($this->font_file) ) {
1048
	    JpGraphError::RaiseL(25093,$this->font_file);
1049
//('Can not read font file ('.$this->font_file.') in call to Image::GetBBoxTTF. Please make sure that you have set a font before calling this method and that the font is installed in the TTF directory.');
1050
	}
1051
	$bbox = $this->GetTTFBBox($aTxt,$aAngle);
1052
 
1053
	if( $aAngle==0 )
1054
	    return $bbox;
1055
	if( $aAngle >= 0 ) {
1056
	    if(  $aAngle <= 90 ) { //<=0
1057
		$bbox = array($bbox[6],$bbox[1],$bbox[2],$bbox[1],
1058
			      $bbox[2],$bbox[5],$bbox[6],$bbox[5]);
1059
	    }
1060
	    elseif(  $aAngle <= 180 ) { //<= 2
1061
		$bbox = array($bbox[4],$bbox[7],$bbox[0],$bbox[7],
1062
			      $bbox[0],$bbox[3],$bbox[4],$bbox[3]);
1063
	    }
1064
	    elseif(  $aAngle <= 270 )  { //<= 3
1065
		$bbox = array($bbox[2],$bbox[5],$bbox[6],$bbox[5],
1066
			      $bbox[6],$bbox[1],$bbox[2],$bbox[1]);
1067
	    }
1068
	    else {
1069
		$bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3],
1070
			      $bbox[4],$bbox[7],$bbox[0],$bbox[7]);
1071
	    }
1072
	}
1073
	elseif(  $aAngle < 0 ) {
1074
	    if( $aAngle <= -270 ) { // <= -3
1075
		$bbox = array($bbox[6],$bbox[1],$bbox[2],$bbox[1],
1076
			      $bbox[2],$bbox[5],$bbox[6],$bbox[5]);
1077
	    }
1078
	    elseif( $aAngle <= -180 ) { // <= -2
1079
		$bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3],
1080
			      $bbox[4],$bbox[7],$bbox[0],$bbox[7]);
1081
	    }
1082
	    elseif( $aAngle <= -90 ) { // <= -1
1083
		$bbox = array($bbox[2],$bbox[5],$bbox[6],$bbox[5],
1084
			      $bbox[6],$bbox[1],$bbox[2],$bbox[1]);
1085
	    }
1086
	    else {
1087
		$bbox = array($bbox[0],$bbox[3],$bbox[4],$bbox[3],
1088
			      $bbox[4],$bbox[7],$bbox[0],$bbox[7]);
1089
	    }
1090
	}
1091
	return $bbox;
1092
    }
1093
 
1094
    function GetBBoxHeight($aTxt,$aAngle=0) {
1095
	$box = $this->GetBBoxTTF($aTxt,$aAngle);
1096
	return $box[1]-$box[7]+1;
1097
    }
1098
 
1099
    function GetBBoxWidth($aTxt,$aAngle=0) {
1100
	$box = $this->GetBBoxTTF($aTxt,$aAngle);
1101
	return $box[2]-$box[0]+1;
1102
    }
1103
 
1104
    function _StrokeTTF($x,$y,$txt,$dir=0,$paragraph_align="left",&$aBoundingBox,$debug=false) {
1105
 
1106
	// Setupo default inter line margin for paragraphs to
1107
	// 25% of the font height.
1108
	$ConstLineSpacing = 0.25 ;
1109
 
1110
	// Remember the anchor point before adjustment
1111
	if( $debug ) {
1112
	    $ox=$x;
1113
	    $oy=$y;
1114
	}
1115
 
1116
	if( !ereg("\n",$txt) || ($dir>0 && ereg("\n",$txt)) ) {
1117
	    // Format a single line
1118
 
1119
	    $txt = $this->AddTxtCR($txt);
1120
 
1121
	    $bbox=$this->GetBBoxTTF($txt,$dir);
1122
 
1123
	    // Align x,y ot lower left corner of bbox
1124
	    $x -= $bbox[0];
1125
	    $y -= $bbox[1];
1126
 
1127
	    // Note to self: "topanchor" is deprecated after we changed the
1128
	    // bopunding box stuff.
1129
	    if( $this->text_halign=="right" || $this->text_halign=="topanchor" )
1130
		$x -= $bbox[2]-$bbox[0];
1131
	    elseif( $this->text_halign=="center" ) $x -= ($bbox[2]-$bbox[0])/2;
1132
 
1133
	    if( $this->text_valign=="top" ) $y += abs($bbox[5])+$bbox[1];
1134
	    elseif( $this->text_valign=="center" ) $y -= ($bbox[5]-$bbox[1])/2;
1135
 
1136
	    ImageTTFText ($this->img, $this->font_size, $dir, $x, $y,
1137
			  $this->current_color,$this->font_file,$txt);
1138
 
1139
	    // Calculate and return the co-ordinates for the bounding box
1140
	    $box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$txt);
1141
	    $p1 = array();
1142
 
1143
 
1144
	    for($i=0; $i < 4; ++$i) {
1145
		$p1[] = round($box[$i*2]+$x);
1146
		$p1[] = round($box[$i*2+1]+$y);
1147
	    }
1148
	    $aBoundingBox = $p1;
1149
 
1150
	    // Debugging code to highlight the bonding box and bounding rectangle
1151
	    // For text at 0 degrees the bounding box and bounding rectangle are the
1152
	    // same
1153
            if( $debug ) {
1154
		// Draw the bounding rectangle and the bounding box
1155
		$box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$txt);
1156
		$p = array();
1157
		$p1 = array();
1158
		for($i=0; $i < 4; ++$i) {
1159
		    $p[] = $bbox[$i*2]+$x;
1160
		    $p[] = $bbox[$i*2+1]+$y;
1161
		    $p1[] = $box[$i*2]+$x;
1162
		    $p1[] = $box[$i*2+1]+$y;
1163
		}
1164
 
1165
		// Draw bounding box
1166
		$this->PushColor('green');
1167
		$this->Polygon($p1,true);
1168
		$this->PopColor();
1169
 
1170
		// Draw bounding rectangle
1171
		$this->PushColor('darkgreen');
1172
		$this->Polygon($p,true);
1173
		$this->PopColor();
1174
 
1175
		// Draw a cross at the anchor point
1176
		$this->PushColor('red');
1177
		$this->Line($ox-15,$oy,$ox+15,$oy);
1178
		$this->Line($ox,$oy-15,$ox,$oy+15);
1179
		$this->PopColor();
1180
            }
1181
	}
1182
	else {
1183
	    // Format a text paragraph
1184
	    $fh=$this->GetFontHeight();
1185
 
1186
	    // Line margin is 25% of font height
1187
	    $linemargin=round($fh*$ConstLineSpacing);
1188
	    $fh += $linemargin;
1189
	    $w=$this->GetTextWidth($txt);
1190
 
1191
	    $y -= $linemargin/2;
1192
	    $tmp = split("\n",$txt);
1193
	    $nl = count($tmp);
1194
	    $h = $nl * $fh;
1195
 
1196
	    if( $this->text_halign=="right")
1197
		$x -= $dir==0 ? $w : $h;
1198
	    elseif( $this->text_halign=="center" ) {
1199
		$x -= $dir==0 ? $w/2 : $h/2;
1200
	    }
1201
 
1202
	    if( $this->text_valign=="top" )
1203
		$y +=	$dir==0 ? $h : $w;
1204
	    elseif( $this->text_valign=="center" )
1205
		$y +=	$dir==0 ? $h/2 : $w/2;
1206
 
1207
	    // Here comes a tricky bit.
1208
	    // Since we have to give the position for the string at the
1209
	    // baseline this means thaht text will move slightly up
1210
	    // and down depending on any of it's character descend below
1211
	    // the baseline, for example a 'g'. To adjust the Y-position
1212
	    // we therefore adjust the text with the baseline Y-offset
1213
	    // as used for the current font and size. This will keep the
1214
	    // baseline at a fixed positoned disregarding the actual
1215
	    // characters in the string.
1216
	    $standardbox = $this->GetTTFBBox('Gg',$dir);
1217
	    $yadj = $standardbox[1];
1218
	    $xadj = $standardbox[0];
1219
	    $aBoundingBox = array();
1220
	    for($i=0; $i < $nl; ++$i) {
1221
		$wl = $this->GetTextWidth($tmp[$i]);
1222
		$bbox = $this->GetTTFBBox($tmp[$i],$dir);
1223
		if( $paragraph_align=="left" ) {
1224
		    $xl = $x;
1225
		}
1226
		elseif( $paragraph_align=="right" ) {
1227
		    $xl = $x + ($w-$wl);
1228
		}
1229
		else {
1230
		    // Center
1231
		    $xl = $x + $w/2 - $wl/2 ;
1232
		}
1233
 
1234
		$xl -= $bbox[0];
1235
		$yl = $y - $yadj;
1236
		$xl = $xl - $xadj;
1237
		ImageTTFText ($this->img, $this->font_size, $dir,
1238
			      $xl, $yl-($h-$fh)+$fh*$i,
1239
			      $this->current_color,$this->font_file,$tmp[$i]);
1240
 
1241
		if( $debug  ) {
1242
		    // Draw the bounding rectangle around each line
1243
		    $box=@ImageTTFBBox($this->font_size,$dir,$this->font_file,$tmp[$i]);
1244
		    $p = array();
1245
		    for($j=0; $j < 4; ++$j) {
1246
			$p[] = $bbox[$j*2]+$xl;
1247
			$p[] = $bbox[$j*2+1]+$yl-($h-$fh)+$fh*$i;
1248
		    }
1249
 
1250
		    // Draw bounding rectangle
1251
		    $this->PushColor('darkgreen');
1252
		    $this->Polygon($p,true);
1253
		    $this->PopColor();
1254
		}
1255
	    }
1256
 
1257
	    // Get the bounding box
1258
	    $bbox = $this->GetBBoxTTF($txt,$dir);
1259
	    for($j=0; $j < 4; ++$j) {
1260
		$bbox[$j*2]+= round($x);
1261
		$bbox[$j*2+1]+= round($y - ($h-$fh) - $yadj);
1262
	    }
1263
	    $aBoundingBox = $bbox;
1264
 
1265
	    if( $debug ) {
1266
		// Draw a cross at the anchor point
1267
		$this->PushColor('red');
1268
		$this->Line($ox-25,$oy,$ox+25,$oy);
1269
		$this->Line($ox,$oy-25,$ox,$oy+25);
1270
		$this->PopColor();
1271
	    }
1272
 
1273
	}
1274
    }
1275
 
1276
    function StrokeText($x,$y,$txt,$dir=0,$paragraph_align="left",$debug=false) {
1277
 
1278
	$x = round($x);
1279
	$y = round($y);
1280
 
1281
	// Do special language encoding
1282
	$txt = $this->langconv->Convert($txt,$this->font_family);
1283
 
1284
	if( !is_numeric($dir) )
1285
	    JpGraphError::RaiseL(25094);//(" Direction for text most be given as an angle between 0 and 90.");
1286
 
1287
	if( $this->font_family >= FF_FONT0 && $this->font_family <= FF_FONT2+1) {
1288
	    $this->_StrokeBuiltinFont($x,$y,$txt,$dir,$paragraph_align,$boundingbox,$debug);
1289
	}
1290
	elseif($this->font_family >= _FF_FIRST && $this->font_family <= _FF_LAST)  {
1291
	    $this->_StrokeTTF($x,$y,$txt,$dir,$paragraph_align,$boundingbox,$debug);
1292
	}
1293
	else
1294
	    JpGraphError::RaiseL(25095);//(" Unknown font font family specification. ");
1295
	return $boundingbox;
1296
    }
1297
 
1298
    function SetMargin($lm,$rm,$tm,$bm) {
1299
	$this->left_margin=$lm;
1300
	$this->right_margin=$rm;
1301
	$this->top_margin=$tm;
1302
	$this->bottom_margin=$bm;
1303
	$this->plotwidth=$this->width - $this->left_margin-$this->right_margin ;
1304
	$this->plotheight=$this->height - $this->top_margin-$this->bottom_margin ;
1305
	if( $this->width  > 0 && $this->height > 0 ) {
1306
	    if( $this->plotwidth < 0  || $this->plotheight < 0 )
1307
		JpGraphError::raise("Too small plot area. ($lm,$rm,$tm,$bm : $this->plotwidth x $this->plotheight). With the given image size and margins there is to little space left for the plot. Increase the plot size or reduce the margins.");
1308
	}
1309
    }
1310
 
1311
    function SetTransparent($color) {
1312
	imagecolortransparent ($this->img,$this->rgb->allocate($color));
1313
    }
1314
 
1315
    function SetColor($color,$aAlpha=0) {
1316
	$this->current_color_name = $color;
1317
	$this->current_color=$this->rgb->allocate($color,$aAlpha);
1318
	if( $this->current_color == -1 ) {
1319
	    JpGraphError::RaiseL(25096);
1320
//("Can't allocate any more colors.");
1321
	}
1322
	return $this->current_color;
1323
    }
1324
 
1325
    function PushColor($color) {
1326
	if( $color != "" ) {
1327
	    $this->colorstack[$this->colorstackidx]=$this->current_color_name;
1328
	    $this->colorstack[$this->colorstackidx+1]=$this->current_color;
1329
	    $this->colorstackidx+=2;
1330
	    $this->SetColor($color);
1331
	}
1332
	else {
1333
	    JpGraphError::RaiseL(25097);//("Color specified as empty string in PushColor().");
1334
	}
1335
    }
1336
 
1337
    function PopColor() {
1338
	if($this->colorstackidx<1)
1339
	    JpGraphError::RaiseL(25098);//(" Negative Color stack index. Unmatched call to PopColor()");
1340
	$this->current_color=$this->colorstack[--$this->colorstackidx];
1341
	$this->current_color_name=$this->colorstack[--$this->colorstackidx];
1342
    }
1343
 
1344
 
1345
    function SetLineWeight($weight) {
1346
	$this->line_weight = $weight;
1347
    }
1348
 
1349
    function SetStartPoint($x,$y) {
1350
	$this->lastx=round($x);
1351
	$this->lasty=round($y);
1352
    }
1353
 
1354
    function Arc($cx,$cy,$w,$h,$s,$e) {
1355
	// GD Arc doesn't like negative angles
1356
	while( $s < 0) $s += 360;
1357
	while( $e < 0) $e += 360;
1358
 
1359
	imagearc($this->img,round($cx),round($cy),round($w),round($h),
1360
		 $s,$e,$this->current_color);
1361
    }
1362
 
1363
    function FilledArc($xc,$yc,$w,$h,$s,$e,$style="") {
1364
 
1365
	while( $s < 0 ) $s += 360;
1366
	while( $e < 0 ) $e += 360;
1367
	if( $style=="" )
1368
	    $style=IMG_ARC_PIE;
1369
 
1370
	// Workaround for bug in 4.4.7 which will not draw a correct 360
1371
	// degree slice with any other angles than 0,360
1372
	if( 360-abs($s-$e) < 0.01 ) {
1373
	    $s = 0;
1374
	    $e = 360;
1375
	}
1376
	if( abs($s-$e) > 0.001 ) {
1377
	    imagefilledarc($this->img,round($xc),round($yc),round($w),round($h),
1378
			   round($s),round($e),$this->current_color,$style);
1379
	}
1380
    }
1381
 
1382
    function FilledCakeSlice($cx,$cy,$w,$h,$s,$e) {
1383
	$this->CakeSlice($cx,$cy,$w,$h,$s,$e,$this->current_color_name);
1384
    }
1385
 
1386
    function CakeSlice($xc,$yc,$w,$h,$s,$e,$fillcolor="",$arccolor="") {
1387
	$s = round($s); $e = round($e);
1388
	$w = round($w); $h = round($h);
1389
	$xc = round($xc); $yc = round($yc);
1390
 
1391
	if( $s==$e ) {
1392
	    // A full circle. We draw this a plain circle
1393
	    $this->PushColor($fillcolor);
1394
	    imagefilledellipse($this->img,$xc,$yc,2*$w,2*$h,$this->current_color);
1395
	    $this->PopColor();
1396
	    $this->PushColor($arccolor);
1397
	    imageellipse($this->img,$xc,$yc,2*$w,2*$h,$this->current_color);
1398
	    $this->Line($xc,$yc,cos($s*M_PI/180)*$w+$xc,$yc+sin($s*M_PI/180)*$h);
1399
	    $this->PopColor();
1400
	}
1401
	else {
1402
	    $this->PushColor($fillcolor);
1403
	    $this->FilledArc($xc,$yc,2*$w,2*$h,$s,$e);
1404
	    $this->PopColor();
1405
	    if( $arccolor != "" ) {
1406
		$this->PushColor($arccolor);
1407
		// We add 2 pixels to make the Arc() better aligned with the filled arc.
1408
		imagefilledarc($this->img,$xc,$yc,2*$w,2*$h,$s,$e,$this->current_color,IMG_ARC_NOFILL | IMG_ARC_EDGED ) ;
1409
 
1410
		// Workaround for bug in 4.4.7 which will not draw a correct 360
1411
		// degree slice with any other angles than 0,360. Unfortunately we cannot just
1412
		// adjust the angles since the interior ar edge is drawn correct but not the surrounding
1413
		// circle. This workaround can only be used with perfect circle shaped arcs
1414
		if( PHP_VERSION==='4.4.7' && (360-abs($s-$e) < 0.01 && $w==$h) ) {
1415
		    $this->Circle($xc,$yc,$w);
1416
		}
1417
		$this->PopColor();
1418
	    }
1419
	}
1420
    }
1421
 
1422
    function Ellipse($xc,$yc,$w,$h) {
1423
	$this->Arc($xc,$yc,$w,$h,0,360);
1424
    }
1425
 
1426
    // Breseham circle gives visually better result then using GD
1427
    // built in arc(). It takes some more time but gives better
1428
    // accuracy.
1429
    function BresenhamCircle($xc,$yc,$r) {
1430
	$d = 3-2*$r;
1431
	$x = 0;
1432
	$y = $r;
1433
	while($x<=$y) {
1434
	    $this->Point($xc+$x,$yc+$y);
1435
	    $this->Point($xc+$x,$yc-$y);
1436
	    $this->Point($xc-$x,$yc+$y);
1437
	    $this->Point($xc-$x,$yc-$y);
1438
 
1439
	    $this->Point($xc+$y,$yc+$x);
1440
	    $this->Point($xc+$y,$yc-$x);
1441
	    $this->Point($xc-$y,$yc+$x);
1442
	    $this->Point($xc-$y,$yc-$x);
1443
 
1444
	    if( $d<0 ) $d += 4*$x+6;
1445
	    else {
1446
		$d += 4*($x-$y)+10;
1447
		--$y;
1448
	    }
1449
	    ++$x;
1450
	}
1451
    }
1452
 
1453
    function Circle($xc,$yc,$r) {
1454
	if( USE_BRESENHAM )
1455
	    $this->BresenhamCircle($xc,$yc,$r);
1456
	else {
1457
 
1458
	    /*
1459
            // Some experimental code snippet to see if we can get a decent
1460
	    // result doing a trig-circle
1461
	    // Create an approximated circle with 0.05 rad resolution
1462
	    $end = 2*M_PI;
1463
	    $l = $r/10;
1464
	    if( $l < 3 ) $l=3;
1465
	    $step_size = 2*M_PI/(2*$r*M_PI/$l);
1466
	    $pts = array();
1467
	    $pts[] = $r + $xc;
1468
	    $pts[] = $yc;
1469
	    for( $a=$step_size; $a <= $end; $a += $step_size ) {
1470
		$pts[] = round($xc + $r*cos($a));
1471
		$pts[] = round($yc - $r*sin($a));
1472
	    }
1473
	    imagepolygon($this->img,$pts,count($pts)/2,$this->current_color);
1474
	    */
1475
 
1476
	    $this->Arc($xc,$yc,$r*2,$r*2,0,360);
1477
 
1478
	    // For some reason imageellipse() isn't in GD 2.0.1, PHP 4.1.1
1479
	    //imageellipse($this->img,$xc,$yc,$r,$r,$this->current_color);
1480
	}
1481
    }
1482
 
1483
    function FilledCircle($xc,$yc,$r) {
1484
	imagefilledellipse($this->img,round($xc),round($yc),2*$r,2*$r,$this->current_color);
1485
    }
1486
 
1487
    // Linear Color InterPolation
1488
    function lip($f,$t,$p) {
1489
	$p = round($p,1);
1490
	$r = $f[0] + ($t[0]-$f[0])*$p;
1491
	$g = $f[1] + ($t[1]-$f[1])*$p;
1492
	$b = $f[2] + ($t[2]-$f[2])*$p;
1493
	return array($r,$g,$b);
1494
    }
1495
 
1496
    // Anti-aliased line.
1497
    // Note that this is roughly 8 times slower then a normal line!
1498
    function WuLine($x1,$y1,$x2,$y2) {
1499
	// Get foreground line color
1500
	$lc = imagecolorsforindex($this->img,$this->current_color);
1501
	$lc = array($lc["red"],$lc["green"],$lc["blue"]);
1502
 
1503
	$dx = $x2-$x1;
1504
	$dy = $y2-$y1;
1505
 
1506
	if( abs($dx) > abs($dy) ) {
1507
	    if( $dx<0 ) {
1508
		$dx = -$dx;$dy = -$dy;
1509
		$tmp=$x2;$x2=$x1;$x1=$tmp;
1510
		$tmp=$y2;$y2=$y1;$y1=$tmp;
1511
	    }
1512
	    $x=$x1<<16; $y=$y1<<16;
1513
	    $yinc = ($dy*65535)/$dx;
1514
	    $first=true;
1515
	    while( ($x >> 16) < $x2 ) {
1516
 
1517
		$bc = @imagecolorsforindex($this->img,imagecolorat($this->img,$x>>16,$y>>16));
1518
		if( $bc <= 0 ) {
1519
		    JpGraphError::RaiseL(25100);//('Problem with color palette and your GD setup. Please disable anti-aliasing or use GD2 with true-color. If you have GD2 library installed please make sure that you have set the USE_GD2 constant to true and that truecolor is enabled.');
1520
		}
1521
		$bc=array($bc["red"],$bc["green"],$bc["blue"]);
1522
 
1523
		$this->SetColor($this->lip($lc,$bc,($y & 0xFFFF)/65535));
1524
		imagesetpixel($this->img,$x>>16,$y>>16,$this->current_color);
1525
		$this->SetColor($this->lip($lc,$bc,(~$y & 0xFFFF)/65535));
1526
		if( !$first )
1527
		    imagesetpixel($this->img,$x>>16,($y>>16)+1,$this->current_color);
1528
		$x += 65536; $y += $yinc;
1529
		$first=false;
1530
	    }
1531
	}
1532
	else {
1533
	    if( $dy<0 ) {
1534
		$dx = -$dx;$dy = -$dy;
1535
		$tmp=$x2;$x2=$x1;$x1=$tmp;
1536
		$tmp=$y2;$y2=$y1;$y1=$tmp;
1537
	    }
1538
	    $x=$x1<<16; $y=$y1<<16;
1539
	    $xinc = ($dx*65535)/$dy;
1540
	    $first = true;
1541
	    while( ($y >> 16) < $y2 ) {
1542
 
1543
		$bc = @imagecolorsforindex($this->img,imagecolorat($this->img,$x>>16,$y>>16));
1544
		if( $bc <= 0 ) {
1545
		    JpGraphError::RaiseL(25100);//('Problem with color palette and your GD setup. Please disable anti-aliasing or use GD2 with true-color. If you have GD2 library installed please make sure that you have set the USE_GD2 constant to true and truecolor is enabled.');
1546
 
1547
		}
1548
 
1549
		$bc=array($bc["red"],$bc["green"],$bc["blue"]);
1550
 
1551
		$this->SetColor($this->lip($lc,$bc,($x & 0xFFFF)/65535));
1552
		imagesetpixel($this->img,$x>>16,$y>>16,$this->current_color);
1553
		$this->SetColor($this->lip($lc,$bc,(~$x & 0xFFFF)/65535));
1554
		if( !$first )
1555
		    imagesetpixel($this->img,($x>>16)+1,$y>>16,$this->current_color);
1556
		$y += 65536; $x += $xinc;
1557
		$first = false;
1558
	    }
1559
	}
1560
	$this->SetColor($lc);
1561
	//imagesetpixel($this->img,$x2,$y2,$this->current_color);
1562
	//imagesetpixel($this->img,$x1,$y1,$this->current_color);
1563
    }
1564
 
1565
    // Set line style dashed, dotted etc
1566
    function SetLineStyle($s) {
1567
	if( is_numeric($s) ) {
1568
	    if( $s<1 || $s>4 )
1569
		JpGraphError::RaiseL(25101,$s);//(" Illegal numeric argument to SetLineStyle(): ($s)");
1570
	}
1571
	elseif( is_string($s) ) {
1572
	    if( $s == "solid" ) $s=1;
1573
	    elseif( $s == "dotted" ) $s=2;
1574
	    elseif( $s == "dashed" ) $s=3;
1575
	    elseif( $s == "longdashed" ) $s=4;
1576
	    else JpGraphError::RaiseL(25102,$s);//(" Illegal string argument to SetLineStyle(): $s");
1577
	}
1578
	else {
1579
	    JpGraphError::RaiseL(25103,$s);//(" Illegal argument to SetLineStyle $s");
1580
	}
1581
	$old = $this->line_style;
1582
	$this->line_style=$s;
1583
	return $old;
1584
    }
1585
 
1586
    // Same as Line but take the line_style into account
1587
    function StyleLine($x1,$y1,$x2,$y2) {
1588
	switch( $this->line_style ) {
1589
	    case 1:// Solid
1590
		$this->Line($x1,$y1,$x2,$y2);
1591
		break;
1592
	    case 2: // Dotted
1593
		$this->DashedLine($x1,$y1,$x2,$y2,1,6);
1594
		break;
1595
	    case 3: // Dashed
1596
		$this->DashedLine($x1,$y1,$x2,$y2,2,4);
1597
		break;
1598
	    case 4: // Longdashes
1599
		$this->DashedLine($x1,$y1,$x2,$y2,8,6);
1600
		break;
1601
	    default:
1602
		JpGraphError::RaiseL(25104,$this->line_style);//(" Unknown line style: $this->line_style ");
1603
		break;
1604
	}
1605
    }
1606
 
1607
    function Line($x1,$y1,$x2,$y2) {
1608
 
1609
	$x1 = round($x1);
1610
	$x2 = round($x2);
1611
	$y1 = round($y1);
1612
	$y2 = round($y2);
1613
 
1614
	if( $this->line_weight==0 ) return;
1615
	if( $this->use_anti_aliasing ) {
1616
	    $dx = $x2-$x1;
1617
	    $dy = $y2-$y1;
1618
	    // Vertical, Horizontal or 45 lines don't need anti-aliasing
1619
	    if( $dx!=0 && $dy!=0 && $dx!=$dy ) {
1620
		$this->WuLine($x1,$y1,$x2,$y2);
1621
		return;
1622
	    }
1623
	}
1624
	if( $this->line_weight==1 ) {
1625
	    imageline($this->img,$x1,$y1,$x2,$y2,$this->current_color);
1626
	}
1627
	elseif( $x1==$x2 ) {		// Special case for vertical lines
1628
	    imageline($this->img,$x1,$y1,$x2,$y2,$this->current_color);
1629
	    $w1=floor($this->line_weight/2);
1630
	    $w2=floor(($this->line_weight-1)/2);
1631
	    for($i=1; $i<=$w1; ++$i)
1632
		imageline($this->img,$x1+$i,$y1,$x2+$i,$y2,$this->current_color);
1633
	    for($i=1; $i<=$w2; ++$i)
1634
		imageline($this->img,$x1-$i,$y1,$x2-$i,$y2,$this->current_color);
1635
	}
1636
	elseif( $y1==$y2 ) {		// Special case for horizontal lines
1637
	    imageline($this->img,$x1,$y1,$x2,$y2,$this->current_color);
1638
	    $w1=floor($this->line_weight/2);
1639
	    $w2=floor(($this->line_weight-1)/2);
1640
	    for($i=1; $i<=$w1; ++$i)
1641
		imageline($this->img,$x1,$y1+$i,$x2,$y2+$i,$this->current_color);
1642
	    for($i=1; $i<=$w2; ++$i)
1643
		imageline($this->img,$x1,$y1-$i,$x2,$y2-$i,$this->current_color);
1644
	}
1645
	else {	// General case with a line at an angle
1646
	    $a = atan2($y1-$y2,$x2-$x1);
1647
	    // Now establish some offsets from the center. This gets a little
1648
	    // bit involved since we are dealing with integer functions and we
1649
	    // want the apperance to be as smooth as possible and never be thicker
1650
	    // then the specified width.
1651
 
1652
	    // We do the trig stuff to make sure that the endpoints of the line
1653
	    // are perpendicular to the line itself.
1654
	    $dx=(sin($a)*$this->line_weight/2);
1655
	    $dy=(cos($a)*$this->line_weight/2);
1656
 
1657
	    $pnts = array(round($x2+$dx),round($y2+$dy),round($x2-$dx),round($y2-$dy),
1658
			  round($x1-$dx),round($y1-$dy),round($x1+$dx),round($y1+$dy));
1659
	    imagefilledpolygon($this->img,$pnts,count($pnts)/2,$this->current_color);
1660
	}
1661
	$this->lastx=$x2; $this->lasty=$y2;
1662
    }
1663
 
1664
    function Polygon($p,$closed=FALSE,$fast=FALSE) {
1665
	if( $this->line_weight==0 ) return;
1666
	$n=count($p);
1667
	$oldx = $p[0];
1668
	$oldy = $p[1];
1669
	if( $fast ) {
1670
	    for( $i=2; $i < $n; $i+=2 ) {
1671
		imageline($this->img,$oldx,$oldy,$p[$i],$p[$i+1],$this->current_color);
1672
		$oldx = $p[$i];
1673
		$oldy = $p[$i+1];
1674
	    }
1675
	    if( $closed ) {
1676
		imageline($this->img,$p[$n*2-2],$p[$n*2-1],$p[0],$p[1],$this->current_color);
1677
	    }
1678
	}
1679
	else {
1680
	    for( $i=2; $i < $n; $i+=2 ) {
1681
		$this->StyleLine($oldx,$oldy,$p[$i],$p[$i+1]);
1682
		$oldx = $p[$i];
1683
		$oldy = $p[$i+1];
1684
	    }
1685
	    if( $closed )
1686
		$this->Line($oldx,$oldy,$p[0],$p[1]);
1687
	}
1688
    }
1689
 
1690
    function FilledPolygon($pts) {
1691
	$n=count($pts);
1692
	if( $n == 0 ) {
1693
	    JpGraphError::RaiseL(25105);//('NULL data specified for a filled polygon. Check that your data is not NULL.');
1694
	}
1695
	for($i=0; $i < $n; ++$i)
1696
	    $pts[$i] = round($pts[$i]);
1697
	imagefilledpolygon($this->img,$pts,count($pts)/2,$this->current_color);
1698
    }
1699
 
1700
    function Rectangle($xl,$yu,$xr,$yl) {
1701
	$this->Polygon(array($xl,$yu,$xr,$yu,$xr,$yl,$xl,$yl,$xl,$yu));
1702
    }
1703
 
1704
    function FilledRectangle($xl,$yu,$xr,$yl) {
1705
	$this->FilledPolygon(array($xl,$yu,$xr,$yu,$xr,$yl,$xl,$yl));
1706
    }
1707
 
1708
    function FilledRectangle2($xl,$yu,$xr,$yl,$color1,$color2,$style=1) {
1709
	// Fill a rectangle with lines of two colors
1710
	if( $style===1 ) {
1711
	    // Horizontal stripe
1712
	    if( $yl < $yu ) {
1713
		$t = $yl; $yl=$yu; $yu=$t;
1714
	    }
1715
	    for( $y=$yu; $y <= $yl; ++$y) {
1716
		$this->SetColor($color1);
1717
		$this->Line($xl,$y,$xr,$y);
1718
		++$y;
1719
		$this->SetColor($color2);
1720
		$this->Line($xl,$y,$xr,$y);
1721
	    }
1722
	}
1723
	else {
1724
	    if( $xl < $xl ) {
1725
		$t = $xl; $xl=$xr; $xr=$t;
1726
	    }
1727
	    for( $x=$xl; $x <= $xr; ++$x) {
1728
		$this->SetColor($color1);
1729
		$this->Line($x,$yu,$x,$yl);
1730
		++$x;
1731
		$this->SetColor($color2);
1732
		$this->Line($x,$yu,$x,$yl);
1733
	    }
1734
	}
1735
    }
1736
 
1737
    function ShadowRectangle($xl,$yu,$xr,$yl,$fcolor=false,$shadow_width=3,$shadow_color=array(102,102,102)) {
1738
	// This is complicated by the fact that we must also handle the case where
1739
        // the reactangle has no fill color
1740
	$this->PushColor($shadow_color);
1741
	$this->FilledRectangle($xr-$shadow_width,$yu+$shadow_width,$xr,$yl-$shadow_width-1);
1742
	$this->FilledRectangle($xl+$shadow_width,$yl-$shadow_width,$xr,$yl);
1743
	//$this->FilledRectangle($xl+$shadow_width,$yu+$shadow_width,$xr,$yl);
1744
	$this->PopColor();
1745
	if( $fcolor==false )
1746
	    $this->Rectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1);
1747
	else {
1748
	    $this->PushColor($fcolor);
1749
	    $this->FilledRectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1);
1750
	    $this->PopColor();
1751
	    $this->Rectangle($xl,$yu,$xr-$shadow_width-1,$yl-$shadow_width-1);
1752
	}
1753
    }
1754
 
1755
    function FilledRoundedRectangle($xt,$yt,$xr,$yl,$r=5) {
1756
	if( $r==0 ) {
1757
	    $this->FilledRectangle($xt,$yt,$xr,$yl);
1758
	    return;
1759
	}
1760
 
1761
	// To avoid overlapping fillings (which will look strange
1762
	// when alphablending is enabled) we have no choice but
1763
	// to fill the five distinct areas one by one.
1764
 
1765
	// Center square
1766
	$this->FilledRectangle($xt+$r,$yt+$r,$xr-$r,$yl-$r);
1767
	// Top band
1768
	$this->FilledRectangle($xt+$r,$yt,$xr-$r,$yt+$r-1);
1769
	// Bottom band
1770
	$this->FilledRectangle($xt+$r,$yl-$r+1,$xr-$r,$yl);
1771
	// Left band
1772
	$this->FilledRectangle($xt,$yt+$r+1,$xt+$r-1,$yl-$r);
1773
	// Right band
1774
	$this->FilledRectangle($xr-$r+1,$yt+$r,$xr,$yl-$r);
1775
 
1776
	// Topleft & Topright arc
1777
	$this->FilledArc($xt+$r,$yt+$r,$r*2,$r*2,180,270);
1778
	$this->FilledArc($xr-$r,$yt+$r,$r*2,$r*2,270,360);
1779
 
1780
	// Bottomleft & Bottom right arc
1781
	$this->FilledArc($xt+$r,$yl-$r,$r*2,$r*2,90,180);
1782
	$this->FilledArc($xr-$r,$yl-$r,$r*2,$r*2,0,90);
1783
 
1784
    }
1785
 
1786
    function RoundedRectangle($xt,$yt,$xr,$yl,$r=5) {
1787
 
1788
	if( $r==0 ) {
1789
	    $this->Rectangle($xt,$yt,$xr,$yl);
1790
	    return;
1791
	}
1792
 
1793
	// Top & Bottom line
1794
	$this->Line($xt+$r,$yt,$xr-$r,$yt);
1795
	$this->Line($xt+$r,$yl,$xr-$r,$yl);
1796
 
1797
	// Left & Right line
1798
	$this->Line($xt,$yt+$r,$xt,$yl-$r);
1799
	$this->Line($xr,$yt+$r,$xr,$yl-$r);
1800
 
1801
	// Topleft & Topright arc
1802
	$this->Arc($xt+$r,$yt+$r,$r*2,$r*2,180,270);
1803
	$this->Arc($xr-$r,$yt+$r,$r*2,$r*2,270,360);
1804
 
1805
	// Bottomleft & Bottomright arc
1806
	$this->Arc($xt+$r,$yl-$r,$r*2,$r*2,90,180);
1807
	$this->Arc($xr-$r,$yl-$r,$r*2,$r*2,0,90);
1808
    }
1809
 
1810
    function FilledBevel($x1,$y1,$x2,$y2,$depth=2,$color1='white@0.4',$color2='darkgray@0.4') {
1811
	$this->FilledRectangle($x1,$y1,$x2,$y2);
1812
	$this->Bevel($x1,$y1,$x2,$y2,$depth,$color1,$color2);
1813
    }
1814
 
1815
    function Bevel($x1,$y1,$x2,$y2,$depth=2,$color1='white@0.4',$color2='black@0.5') {
1816
	$this->PushColor($color1);
1817
	for( $i=0; $i < $depth; ++$i ) {
1818
	    $this->Line($x1+$i,$y1+$i,$x1+$i,$y2-$i);
1819
	    $this->Line($x1+$i,$y1+$i,$x2-$i,$y1+$i);
1820
	}
1821
	$this->PopColor();
1822
 
1823
	$this->PushColor($color2);
1824
	for( $i=0; $i < $depth; ++$i ) {
1825
	    $this->Line($x1+$i,$y2-$i,$x2-$i,$y2-$i);
1826
	    $this->Line($x2-$i,$y1+$i,$x2-$i,$y2-$i-1);
1827
	}
1828
	$this->PopColor();
1829
    }
1830
 
1831
    function StyleLineTo($x,$y) {
1832
	$this->StyleLine($this->lastx,$this->lasty,$x,$y);
1833
	$this->lastx=$x;
1834
	$this->lasty=$y;
1835
    }
1836
 
1837
    function LineTo($x,$y) {
1838
	$this->Line($this->lastx,$this->lasty,$x,$y);
1839
	$this->lastx=$x;
1840
	$this->lasty=$y;
1841
    }
1842
 
1843
    function Point($x,$y) {
1844
	imagesetpixel($this->img,round($x),round($y),$this->current_color);
1845
    }
1846
 
1847
    function Fill($x,$y) {
1848
	imagefill($this->img,round($x),round($y),$this->current_color);
1849
    }
1850
 
1851
    function FillToBorder($x,$y,$aBordColor) {
1852
	$bc = $this->rgb->allocate($aBordColor);
1853
	if( $bc == -1 ) {
1854
	    JpGraphError::RaiseL(25106);//('Image::FillToBorder : Can not allocate more colors');
1855
	}
1856
	imagefilltoborder($this->img,round($x),round($y),$bc,$this->current_color);
1857
    }
1858
 
1859
    function DashedLine($x1,$y1,$x2,$y2,$dash_length=1,$dash_space=4) {
1860
 
1861
	$x1 = round($x1);
1862
	$x2 = round($x2);
1863
	$y1 = round($y1);
1864
	$y2 = round($y2);
1865
 
1866
	// Code based on, but not identical to, work by Ariel Garza and James Pine
1867
	$line_length = ceil (sqrt(pow(($x2 - $x1),2) + pow(($y2 - $y1),2)) );
1868
	$dx = ($line_length) ? ($x2 - $x1) / $line_length : 0;
1869
	$dy = ($line_length) ? ($y2 - $y1) / $line_length : 0;
1870
	$lastx = $x1; $lasty = $y1;
1871
	$xmax = max($x1,$x2);
1872
	$xmin = min($x1,$x2);
1873
	$ymax = max($y1,$y2);
1874
	$ymin = min($y1,$y2);
1875
	for ($i = 0; $i < $line_length; $i += ($dash_length + $dash_space)) {
1876
	    $x = ($dash_length * $dx) + $lastx;
1877
	    $y = ($dash_length * $dy) + $lasty;
1878
 
1879
	    // The last section might overshoot so we must take a computational hit
1880
	    // and check this.
1881
	    if( $x>$xmax ) $x=$xmax;
1882
	    if( $y>$ymax ) $y=$ymax;
1883
 
1884
	    if( $x<$xmin ) $x=$xmin;
1885
	    if( $y<$ymin ) $y=$ymin;
1886
 
1887
	    $this->Line($lastx,$lasty,$x,$y);
1888
	    $lastx = $x + ($dash_space * $dx);
1889
	    $lasty = $y + ($dash_space * $dy);
1890
	}
1891
    }
1892
 
1893
    function SetExpired($aFlg=true) {
1894
	$this->expired = $aFlg;
1895
    }
1896
 
1897
    // Generate image header
1898
    function Headers() {
1899
 
1900
	// In case we are running from the command line with the client version of
1901
	// PHP we can't send any headers.
1902
	$sapi = php_sapi_name();
1903
	if( $sapi == 'cli' )
1904
	    return;
1905
 
1906
	// These parameters are set by headers_sent() but they might cause
1907
	// an undefined variable error unless they are initilized
1908
	$file='';
1909
	$lineno='';
1910
	if( headers_sent($file,$lineno) ) {
1911
	    $file=basename($file);
1912
	    $t = new ErrMsgText();
1913
	    $msg = $t->Get(10,$file,$lineno);
1914
	    die($msg);
1915
	}
1916
 
1917
	if ($this->expired) {
1918
	    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
1919
	    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
1920
	    header("Cache-Control: no-cache, must-revalidate");
1921
	    header("Pragma: no-cache");
1922
	}
1923
	header("Content-type: image/$this->img_format");
1924
    }
1925
 
1926
    // Adjust image quality for formats that allow this
1927
    function SetQuality($q) {
1928
	$this->quality = $q;
1929
    }
1930
 
1931
    // Stream image to browser or to file
1932
    function Stream($aFile="") {
1933
	$func="image".$this->img_format;
1934
	if( $this->img_format=="jpeg" && $this->quality != null ) {
1935
	    $res = @$func($this->img,$aFile,$this->quality);
1936
	}
1937
	else {
1938
	    if( $aFile != "" ) {
1939
		$res = @$func($this->img,$aFile);
1940
		if( !$res )
1941
		    JpGraphError::RaiseL(25107,$aFile);//("Can't write to file '$aFile'. Check that the process running PHP has enough permission.");
1942
	    }
1943
	    else {
1944
		$res = @$func($this->img);
1945
		if( !$res )
1946
		    JpGraphError::RaiseL(25108);//("Can't stream image. This is most likely due to a faulty PHP/GD setup. Try to recompile PHP and use the built-in GD library that comes with PHP.");
1947
 
1948
	    }
1949
	}
1950
    }
1951
 
1952
    // Clear resource tide up by image
1953
    function Destroy() {
1954
	imagedestroy($this->img);
1955
    }
1956
 
1957
    // Specify image format. Note depending on your installation
1958
    // of PHP not all formats may be supported.
1959
    function SetImgFormat($aFormat,$aQuality=75) {
1960
	$this->quality = $aQuality;
1961
	$aFormat = strtolower($aFormat);
1962
	$tst = true;
1963
	$supported = imagetypes();
1964
	if( $aFormat=="auto" ) {
1965
	    if( $supported & IMG_PNG )
1966
		$this->img_format="png";
1967
	    elseif( $supported & IMG_JPG )
1968
		$this->img_format="jpeg";
1969
	    elseif( $supported & IMG_GIF )
1970
		$this->img_format="gif";
1971
	    elseif( $supported & IMG_WBMP )
1972
		$this->img_format="wbmp";
1973
	    elseif( $supported & IMG_XPM )
1974
		$this->img_format="xpm";
1975
	    else
1976
		JpGraphError::RaiseL(25109);//("Your PHP (and GD-lib) installation does not appear to support any known graphic formats. You need to first make sure GD is compiled as a module to PHP. If you also want to use JPEG images you must get the JPEG library. Please see the PHP docs for details.");
1977
 
1978
	    return true;
1979
	}
1980
	else {
1981
	    if( $aFormat=="jpeg" || $aFormat=="png" || $aFormat=="gif" || $aFormat=="wbmp" || $aFormat=="xpm") {
1982
		if( $aFormat=="jpeg" && !($supported & IMG_JPG) )
1983
		    $tst=false;
1984
		elseif( $aFormat=="png" && !($supported & IMG_PNG) )
1985
		    $tst=false;
1986
		elseif( $aFormat=="gif" && !($supported & IMG_GIF) )
1987
		    $tst=false;
1988
		elseif( $aFormat=="wbmp" && !($supported & IMG_WBMP) )
1989
		    $tst=false;
1990
		elseif( $aFormat=="xpm" && !($supported & IMG_XPM) )
1991
		    $tst=false;
1992
		else {
1993
		    $this->img_format=$aFormat;
1994
		    return true;
1995
		}
1996
	    }
1997
	    else
1998
		$tst=false;
1999
	    if( !$tst )
2000
		JpGraphError::RaiseL(25110,$aFormat);//(" Your PHP installation does not support the chosen graphic format: $aFormat");
2001
	}
2002
    }
2003
} // CLASS
2004
 
2005
//===================================================
2006
// CLASS RotImage
2007
// Description: Exactly as Image but draws the image at
2008
// a specified angle around a specified rotation point.
2009
//===================================================
2010
class RotImage extends Image {
2011
    var $m=array();
2012
    var $a=0;
2013
    var $dx=0,$dy=0,$transx=0,$transy=0;
2014
 
2015
    function RotImage($aWidth,$aHeight,$a=0,$aFormat=DEFAULT_GFORMAT,$aSetAutoMargin=true) {
2016
	$this->Image($aWidth,$aHeight,$aFormat,$aSetAutoMargin);
2017
	$this->dx=$this->left_margin+$this->plotwidth/2;
2018
	$this->dy=$this->top_margin+$this->plotheight/2;
2019
	$this->SetAngle($a);
2020
    }
2021
 
2022
    function SetCenter($dx,$dy) {
2023
	$old_dx = $this->dx;
2024
	$old_dy = $this->dy;
2025
	$this->dx=$dx;
2026
	$this->dy=$dy;
2027
	$this->SetAngle($this->a);
2028
	return array($old_dx,$old_dy);
2029
    }
2030
 
2031
    function SetTranslation($dx,$dy) {
2032
	$old = array($this->transx,$this->transy);
2033
	$this->transx = $dx;
2034
	$this->transy = $dy;
2035
	return $old;
2036
    }
2037
 
2038
    function UpdateRotMatrice()  {
2039
	$a = $this->a;
2040
	$a *= M_PI/180;
2041
	$sa=sin($a); $ca=cos($a);
2042
	// Create the rotation matrix
2043
	$this->m[0][0] = $ca;
2044
	$this->m[0][1] = -$sa;
2045
	$this->m[0][2] = $this->dx*(1-$ca) + $sa*$this->dy ;
2046
	$this->m[1][0] = $sa;
2047
	$this->m[1][1] = $ca;
2048
	$this->m[1][2] = $this->dy*(1-$ca) - $sa*$this->dx ;
2049
    }
2050
 
2051
    function SetAngle($a) {
2052
	$tmp = $this->a;
2053
	$this->a = $a;
2054
	$this->UpdateRotMatrice();
2055
	return $tmp;
2056
    }
2057
 
2058
    function Circle($xc,$yc,$r) {
2059
	// Circle get's rotated through the Arc() call
2060
	// made in the parent class
2061
	parent::Circle($xc,$yc,$r);
2062
    }
2063
 
2064
    function FilledCircle($xc,$yc,$r) {
2065
	list($xc,$yc) = $this->Rotate($xc,$yc);
2066
	parent::FilledCircle($xc,$yc,$r);
2067
    }
2068
 
2069
    function Arc($xc,$yc,$w,$h,$s,$e) {
2070
	list($xc,$yc) = $this->Rotate($xc,$yc);
2071
	$s += $this->a;
2072
	$e += $this->a;
2073
	parent::Arc($xc,$yc,$w,$h,$s,$e);
2074
    }
2075
 
2076
    function FilledArc($xc,$yc,$w,$h,$s,$e) {
2077
	list($xc,$yc) = $this->Rotate($xc,$yc);
2078
	$s += $this->a;
2079
	$e += $this->a;
2080
	parent::FilledArc($xc,$yc,$w,$h,$s,$e);
2081
    }
2082
 
2083
    function SetMargin($lm,$rm,$tm,$bm) {
2084
	parent::SetMargin($lm,$rm,$tm,$bm);
2085
	$this->dx=$this->left_margin+$this->plotwidth/2;
2086
	$this->dy=$this->top_margin+$this->plotheight/2;
2087
	$this->UpdateRotMatrice();
2088
    }
2089
 
2090
    function Rotate($x,$y) {
2091
	// Optimization. Ignore rotation if Angle==0 || ANgle==360
2092
	if( $this->a == 0 || $this->a == 360 ) {
2093
	    return array($x + $this->transx, $y + $this->transy );
2094
	}
2095
	else {
2096
	    $x1=round($this->m[0][0]*$x + $this->m[0][1]*$y,1) + $this->m[0][2] + $this->transx;
2097
	    $y1=round($this->m[1][0]*$x + $this->m[1][1]*$y,1) + $this->m[1][2] + $this->transy;
2098
	    return array($x1,$y1);
2099
	}
2100
    }
2101
 
2102
    function CopyMerge($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth=-1,$fromHeight=-1,$aMix=100) {
2103
	list($toX,$toY) = $this->Rotate($toX,$toY);
2104
	parent::CopyMerge($fromImg,$toX,$toY,$fromX,$fromY,$toWidth,$toHeight,$fromWidth,$fromHeight,$aMix);
2105
 
2106
    }
2107
 
2108
    function ArrRotate($pnts) {
2109
	$n = count($pnts)-1;
2110
	for($i=0; $i < $n; $i+=2) {
2111
	    list ($x,$y) = $this->Rotate($pnts[$i],$pnts[$i+1]);
2112
	    $pnts[$i] = $x; $pnts[$i+1] = $y;
2113
	}
2114
	return $pnts;
2115
    }
2116
 
2117
    function Line($x1,$y1,$x2,$y2) {
2118
	list($x1,$y1) = $this->Rotate($x1,$y1);
2119
	list($x2,$y2) = $this->Rotate($x2,$y2);
2120
	parent::Line($x1,$y1,$x2,$y2);
2121
    }
2122
 
2123
    function Rectangle($x1,$y1,$x2,$y2) {
2124
	// Rectangle uses Line() so it will be rotated through that call
2125
	parent::Rectangle($x1,$y1,$x2,$y2);
2126
    }
2127
 
2128
    function FilledRectangle($x1,$y1,$x2,$y2) {
2129
	if( $y1==$y2 || $x1==$x2 )
2130
	    $this->Line($x1,$y1,$x2,$y2);
2131
	else
2132
	    $this->FilledPolygon(array($x1,$y1,$x2,$y1,$x2,$y2,$x1,$y2));
2133
    }
2134
 
2135
    function Polygon($pnts,$closed=FALSE,$fast=false) {
2136
	// Polygon uses Line() so it will be rotated through that call unless
2137
	// fast drawing routines are used in which case a rotate is needed
2138
	if( $fast ) {
2139
	    parent::Polygon($this->ArrRotate($pnts));
2140
	}
2141
	else
2142
	    parent::Polygon($pnts,$closed,$fast);
2143
    }
2144
 
2145
    function FilledPolygon($pnts) {
2146
	parent::FilledPolygon($this->ArrRotate($pnts));
2147
    }
2148
 
2149
    function Point($x,$y) {
2150
	list($xp,$yp) = $this->Rotate($x,$y);
2151
	parent::Point($xp,$yp);
2152
    }
2153
 
2154
    function StrokeText($x,$y,$txt,$dir=0,$paragraph_align="left",$debug=false) {
2155
	list($xp,$yp) = $this->Rotate($x,$y);
2156
	return parent::StrokeText($xp,$yp,$txt,$dir,$paragraph_align,$debug);
2157
    }
2158
}
2159
 
2160
 
2161
?>