~ubuntu-branches/ubuntu/intrepid/moin/intrepid-updates

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/editor/filemanager/browser/mcpuk/js/wz_jsgraphics.js

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-02-14 16:09:24 UTC
  • mfrom: (0.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20060214160924-fyrx3gvknzqvt4vj
Tags: 1.5.2-1ubuntu1
Drop python2.3 package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * FCKeditor - The text editor for internet
3
 
 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
4
 
 * 
5
 
 * Licensed under the terms of the GNU Lesser General Public License:
6
 
 *              http://www.opensource.org/licenses/lgpl-license.php
7
 
 * 
8
 
 * For further information visit:
9
 
 *              http://www.fckeditor.net/
10
 
 * 
11
 
 * "Support Open Source software. What about a donation today?"
12
 
 * 
13
 
 * File Name: wz_jsgraphics.js
14
 
 *      Javascript Graphics.
15
 
 * 
16
 
 * File Authors:
17
 
 *              Grant French (grant@mcpuk.net)
18
 
 */
19
 
/***********************************************************************
20
 
** Title.........:  Javascript Graphics
21
 
** Version.......:  1.0
22
 
** Author........:  Xiang Wei ZHUO <wei@zhuo.org>
23
 
** Filename......:  wz_jsgraphics.js
24
 
** Last changed..:  31 Aug 2003  
25
 
** Notes.........:  Modified for Image Editor, added extra commands
26
 
**/ 
27
 
 
28
 
/* This notice must be untouched at all times.
29
 
 
30
 
wz_jsgraphics.js    v. 2.03
31
 
The latest version is available at
32
 
http://www.walterzorn.com
33
 
or http://www.devira.com
34
 
or http://www.walterzorn.de
35
 
 
36
 
Copyright (c) 2002-2003 Walter Zorn. All rights reserved.
37
 
Created 3. 11. 2002 by Walter Zorn <walter@kreuzotter.de>
38
 
Last modified: 11. 6. 2003
39
 
 
40
 
High Performance JavaScript Graphics Library.
41
 
Provides methods
42
 
- to draw lines, rectangles, ellipses, polygons
43
 
  with specifiable line thickness,
44
 
- to fill rectangles and ellipses
45
 
- to draw text.
46
 
NOTE: Operations, functions and branching have rather been optimized
47
 
to efficiency and speed than to shortness of source code.
48
 
 
49
 
This program is free software;
50
 
you can redistribute it and/or modify it under the terms of the
51
 
GNU General Public License as published by the Free Software Foundation;
52
 
either version 2 of the License, or (at your option) any later version.
53
 
This program is distributed in the hope that it will be useful,
54
 
but WITHOUT ANY WARRANTY;
55
 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
56
 
See the GNU General Public License
57
 
at http://www.gnu.org/copyleft/gpl.html for more details.
58
 
*/
59
 
 
60
 
var jg_ihtm, jg_ie, jg_dom,
61
 
jg_n4 = (document.layers && typeof document.classes != "undefined");
62
 
 
63
 
function chkDHTM(x, i)
64
 
{
65
 
    x = document.body || null;
66
 
    jg_ie = (x && typeof x.insertAdjacentHTML != "undefined");
67
 
    jg_dom = (x && !jg_ie &&
68
 
        typeof x.appendChild != "undefined" &&
69
 
        typeof document.createRange != "undefined" &&
70
 
        typeof (i = document.createRange()).setStartBefore != "undefined" &&
71
 
        typeof i.createContextualFragment != "undefined");
72
 
    jg_ihtm = (!jg_ie && !jg_dom && x && typeof x.innerHTML != "undefined");
73
 
}
74
 
 
75
 
 
76
 
 
77
 
 
78
 
 
79
 
function pntDoc()
80
 
{
81
 
    this.wnd.document.write(this.htm);
82
 
    this.htm = '';
83
 
}
84
 
 
85
 
 
86
 
 
87
 
 
88
 
 
89
 
function pntCnvDom()
90
 
{
91
 
    var x = document.createRange();
92
 
    x.setStartBefore(this.cnv);
93
 
    x = x.createContextualFragment(this.htm);
94
 
    this.cnv.appendChild(x);
95
 
    this.htm = '';
96
 
}
97
 
 
98
 
 
99
 
 
100
 
 
101
 
 
102
 
function pntCnvIe()
103
 
{
104
 
    this.cnv.insertAdjacentHTML("BeforeEnd", this.htm);
105
 
    this.htm = '';
106
 
}
107
 
 
108
 
 
109
 
 
110
 
 
111
 
 
112
 
function pntCnvIhtm()
113
 
{
114
 
    this.cnv.innerHTML += this.htm;
115
 
    this.htm = '';
116
 
}
117
 
 
118
 
 
119
 
 
120
 
 
121
 
 
122
 
function pntCnv()
123
 
{
124
 
    this.htm = '';
125
 
}
126
 
 
127
 
 
128
 
 
129
 
 
130
 
 
131
 
function mkDiv(x, y, w, h)
132
 
{
133
 
    this.htm += '<div style="position:absolute;'+
134
 
        'left:' + x + 'px;'+
135
 
        'top:' + y + 'px;'+
136
 
        'width:' + w + 'px;'+
137
 
        'height:' + h + 'px;'+
138
 
        'clip:rect(0,'+w+'px,'+h+'px,0);'+
139
 
        'overflow:hidden;background-color:' + this.color + ';'+
140
 
        '"><\/div>';
141
 
 
142
 
    //alert(this.htm);
143
 
}
144
 
 
145
 
 
146
 
 
147
 
 
148
 
function mkDivPrint(x, y, w, h)
149
 
{
150
 
    this.htm += '<div style="position:absolute;'+
151
 
        'border-left:' + w + 'px solid ' + this.color + ';'+
152
 
        'left:' + x + 'px;'+
153
 
        'top:' + y + 'px;'+
154
 
        'width:' + w + 'px;'+
155
 
        'height:' + h + 'px;'+
156
 
        'clip:rect(0,'+w+'px,'+h+'px,0);'+
157
 
        'overflow:hidden;background-color:' + this.color + ';'+
158
 
        '"><\/div>';
159
 
}
160
 
 
161
 
 
162
 
 
163
 
 
164
 
 
165
 
function mkLyr(x, y, w, h)
166
 
{
167
 
    this.htm += '<layer '+
168
 
        'left="' + x + '" '+
169
 
        'top="' + y + '" '+
170
 
        'width="' + w + '" '+
171
 
        'height="' + h + '" '+
172
 
        'bgcolor="' + this.color + '"><\/layer>\n';
173
 
}
174
 
 
175
 
 
176
 
 
177
 
 
178
 
 
179
 
function mkLbl(txt, x, y)
180
 
{
181
 
    this.htm += '<div style="position:absolute;white-space:nowrap;'+
182
 
        'left:' + x + 'px;'+
183
 
        'top:' + y + 'px;'+
184
 
        'font-family:' +  this.ftFam + ';'+
185
 
        'font-size:' + this.ftSz + ';'+
186
 
        'color:' + this.color + ';' + this.ftSty + '">'+
187
 
        txt +
188
 
        '<\/div>';
189
 
}
190
 
 
191
 
 
192
 
 
193
 
 
194
 
 
195
 
function mkLin(x1, y1, x2, y2)
196
 
{
197
 
    if (x1 > x2)
198
 
    {
199
 
        var _x2 = x2;
200
 
        var _y2 = y2;
201
 
        x2 = x1;
202
 
        y2 = y1;
203
 
        x1 = _x2;
204
 
        y1 = _y2;
205
 
    }
206
 
    var dx = x2-x1, dy = Math.abs(y2-y1),
207
 
    x = x1, y = y1,
208
 
    yIncr = (y1 > y2)? -1 : 1;
209
 
 
210
 
    if (dx >= dy)
211
 
    {
212
 
        var pr = dy<<1,
213
 
        pru = pr - (dx<<1),
214
 
        p = pr-dx,
215
 
        ox = x;
216
 
        while ((dx--) > 0)
217
 
        {
218
 
            ++x;
219
 
            if (p > 0)
220
 
            {
221
 
                this.mkDiv(ox, y, x-ox, 1);
222
 
                y += yIncr;
223
 
                p += pru;
224
 
                ox = x;
225
 
            }
226
 
            else p += pr;
227
 
        }
228
 
        this.mkDiv(ox, y, x2-ox+1, 1);
229
 
    }
230
 
 
231
 
    else
232
 
    {
233
 
        var pr = dx<<1,
234
 
        pru = pr - (dy<<1),
235
 
        p = pr-dy,
236
 
        oy = y;
237
 
        if (y2 <= y1)
238
 
        {
239
 
            while ((dy--) > 0)
240
 
            {
241
 
                if (p > 0)
242
 
                {
243
 
                    this.mkDiv(x++, y, 1, oy-y+1);
244
 
                    y += yIncr;
245
 
                    p += pru;
246
 
                    oy = y;
247
 
                }
248
 
                else
249
 
                {
250
 
                    y += yIncr;
251
 
                    p += pr;
252
 
                }
253
 
            }
254
 
            this.mkDiv(x2, y2, 1, oy-y2+1);
255
 
        }
256
 
        else
257
 
        {
258
 
            while ((dy--) > 0)
259
 
            {
260
 
                y += yIncr;
261
 
                if (p > 0)
262
 
                {
263
 
                    this.mkDiv(x++, oy, 1, y-oy);
264
 
                    p += pru;
265
 
                    oy = y;
266
 
                }
267
 
                else p += pr;
268
 
            }
269
 
            this.mkDiv(x2, oy, 1, y2-oy+1);
270
 
        }
271
 
    }
272
 
}
273
 
 
274
 
 
275
 
 
276
 
 
277
 
 
278
 
function mkLin2D(x1, y1, x2, y2)
279
 
{
280
 
    if (x1 > x2)
281
 
    {
282
 
        var _x2 = x2;
283
 
        var _y2 = y2;
284
 
        x2 = x1;
285
 
        y2 = y1;
286
 
        x1 = _x2;
287
 
        y1 = _y2;
288
 
    }
289
 
    var dx = x2-x1, dy = Math.abs(y2-y1),
290
 
    x = x1, y = y1,
291
 
    yIncr = (y1 > y2)? -1 : 1;
292
 
 
293
 
 
294
 
    var s = this.stroke;
295
 
    if (dx >= dy)
296
 
    {
297
 
        if (s-0x3 > 0)
298
 
        {
299
 
            var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s>>1)*dy) / dx;
300
 
            _s = (!(s-0x4)? Math.ceil(_s) : Math.round(_s)) + 1;
301
 
        }
302
 
        else var _s = s;
303
 
        var ad = Math.ceil(s/2);
304
 
 
305
 
        var pr = dy<<1,
306
 
        pru = pr - (dx<<1),
307
 
        p = pr-dx,
308
 
        ox = x;
309
 
        while ((dx--) > 0)
310
 
        {
311
 
            ++x;
312
 
            if (p > 0)
313
 
            {
314
 
                this.mkDiv(ox, y, x-ox+ad, _s);
315
 
                y += yIncr;
316
 
                p += pru;
317
 
                ox = x;
318
 
            }
319
 
            else p += pr;
320
 
        }
321
 
        this.mkDiv(ox, y, x2-ox+ad+1, _s);
322
 
    }
323
 
 
324
 
    else
325
 
    {
326
 
        if (s-0x3 > 0)
327
 
        {
328
 
            var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s>>1)*dx-dy) / dy;
329
 
            _s = (!(s-0x4)? Math.ceil(_s) : Math.round(_s)) + 1;
330
 
        }
331
 
        else var _s = s;
332
 
        var ad = Math.round(s/2);
333
 
 
334
 
        var pr = dx<<1,
335
 
        pru = pr - (dy<<1),
336
 
        p = pr-dy,
337
 
        oy = y;
338
 
        if (y2 <= y1)
339
 
        {
340
 
            ++ad;
341
 
            while ((dy--) > 0)
342
 
            {
343
 
                if (p > 0)
344
 
                {
345
 
                    this.mkDiv(x++, y, _s, oy-y+ad);
346
 
                    y += yIncr;
347
 
                    p += pru;
348
 
                    oy = y;
349
 
                }
350
 
                else
351
 
                {
352
 
                    y += yIncr;
353
 
                    p += pr;
354
 
                }
355
 
            }
356
 
            this.mkDiv(x2, y2, _s, oy-y2+ad);
357
 
        }
358
 
        else
359
 
        {
360
 
            while ((dy--) > 0)
361
 
            {
362
 
                y += yIncr;
363
 
                if (p > 0)
364
 
                {
365
 
                    this.mkDiv(x++, oy, _s, y-oy+ad);
366
 
                    p += pru;
367
 
                    oy = y;
368
 
                }
369
 
                else p += pr;
370
 
            }
371
 
            this.mkDiv(x2, oy, _s, y2-oy+ad+1);
372
 
        }
373
 
    }
374
 
}
375
 
 
376
 
 
377
 
 
378
 
 
379
 
 
380
 
function mkLinDott(x1, y1, x2, y2)
381
 
{
382
 
    if (x1 > x2)
383
 
    {
384
 
        var _x2 = x2;
385
 
        var _y2 = y2;
386
 
        x2 = x1;
387
 
        y2 = y1;
388
 
        x1 = _x2;
389
 
        y1 = _y2;
390
 
    }
391
 
    var dx = x2-x1, dy = Math.abs(y2-y1),
392
 
    x = x1, y = y1,
393
 
    yIncr = (y1 > y2)? -1 : 1,
394
 
    drw = true;
395
 
    if (dx >= dy)
396
 
    {
397
 
        var pr = dy<<1,
398
 
        pru = pr - (dx<<1),
399
 
        p = pr-dx;
400
 
        while ((dx--) > 0)
401
 
        {
402
 
            if (drw) this.mkDiv(x, y, 1, 1);
403
 
            drw = !drw;
404
 
            if (p > 0)
405
 
            {
406
 
                y += yIncr;
407
 
                p += pru;
408
 
            }
409
 
            else p += pr;
410
 
            ++x;
411
 
        }
412
 
        if (drw) this.mkDiv(x, y, 1, 1);
413
 
    }
414
 
 
415
 
    else
416
 
    {
417
 
        var pr = dx<<1,
418
 
        pru = pr - (dy<<1),
419
 
        p = pr-dy;
420
 
        while ((dy--) > 0)
421
 
        {
422
 
            if (drw) this.mkDiv(x, y, 1, 1);
423
 
            drw = !drw;
424
 
            y += yIncr;
425
 
            if (p > 0)
426
 
            {
427
 
                ++x;
428
 
                p += pru;
429
 
            }
430
 
            else p += pr;
431
 
        }
432
 
        if (drw) this.mkDiv(x, y, 1, 1);
433
 
    }
434
 
}
435
 
 
436
 
 
437
 
 
438
 
 
439
 
 
440
 
function mkOv(left, top, width, height)
441
 
{
442
 
    var a = width>>1, b = height>>1,
443
 
    wod = width&1, hod = (height&1)+1,
444
 
    cx = left+a, cy = top+b,
445
 
    x = 0, y = b,
446
 
    ox = 0, oy = b,
447
 
    aa = (a*a)<<1, bb = (b*b)<<1,
448
 
    st = (aa>>1)*(1-(b<<1)) + bb,
449
 
    tt = (bb>>1) - aa*((b<<1)-1),
450
 
    w, h;
451
 
    while (y > 0)
452
 
    {
453
 
        if (st < 0)
454
 
        {
455
 
            st += bb*((x<<1)+0x3);
456
 
            tt += (bb<<1)*(++x);
457
 
        }
458
 
        else if (tt < 0)
459
 
        {
460
 
            st += bb*((x<<1)+0x3) - (aa<<1)*(y-1);
461
 
            tt += (bb<<1)*(++x) - aa*(((y--)<<1)-0x3);
462
 
            w = x-ox;
463
 
            h = oy-y;
464
 
            if (w&0x2 && h&0x2)
465
 
            {
466
 
                this.mkOvQds(cx, cy, -x+0x2, ox+wod, -oy, oy-1+hod, 1, 1);
467
 
                this.mkOvQds(cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1);
468
 
            }
469
 
            else this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, oy-h+hod, w, h);
470
 
            ox = x;
471
 
            oy = y;
472
 
        }
473
 
        else
474
 
        {
475
 
            tt -= aa*((y<<1)-0x3);
476
 
            st -= (aa<<1)*(--y);
477
 
        }
478
 
    }
479
 
    this.mkDiv(cx-a, cy-oy, a-ox+1, (oy<<1)+hod);
480
 
    this.mkDiv(cx+ox+wod, cy-oy, a-ox+1, (oy<<1)+hod);
481
 
}
482
 
 
483
 
 
484
 
 
485
 
 
486
 
 
487
 
function mkOv2D(left, top, width, height)
488
 
{
489
 
    var s = this.stroke;
490
 
    width += s-1;
491
 
    height += s-1;
492
 
    var a = width>>1, b = height>>1,
493
 
    wod = width&1, hod = (height&1)+1,
494
 
    cx = left+a, cy = top+b,
495
 
    x = 0, y = b,
496
 
    aa = (a*a)<<1, bb = (b*b)<<1,
497
 
    st = (aa>>1)*(1-(b<<1)) + bb,
498
 
    tt = (bb>>1) - aa*((b<<1)-1);
499
 
 
500
 
 
501
 
    if (s-0x4 < 0 && (!(s-0x2) || width-0x33 > 0 && height-0x33 > 0))
502
 
    {
503
 
        var ox = 0, oy = b,
504
 
        w, h,
505
 
        pxl, pxr, pxt, pxb, pxw;
506
 
        while (y > 0)
507
 
        {
508
 
            if (st < 0)
509
 
            {
510
 
                st += bb*((x<<1)+0x3);
511
 
                tt += (bb<<1)*(++x);
512
 
            }
513
 
            else if (tt < 0)
514
 
            {
515
 
                st += bb*((x<<1)+0x3) - (aa<<1)*(y-1);
516
 
                tt += (bb<<1)*(++x) - aa*(((y--)<<1)-0x3);
517
 
                w = x-ox;
518
 
                h = oy-y;
519
 
 
520
 
                if (w-1)
521
 
                {
522
 
                    pxw = w+1+(s&1);
523
 
                    h = s;
524
 
                }
525
 
                else if (h-1)
526
 
                {
527
 
                    pxw = s;
528
 
                    h += 1+(s&1);
529
 
                }
530
 
                else pxw = h = s;
531
 
                this.mkOvQds(cx, cy, -x+1, ox-pxw+w+wod, -oy, -h+oy+hod, pxw, h);
532
 
                ox = x;
533
 
                oy = y;
534
 
            }
535
 
            else
536
 
            {
537
 
                tt -= aa*((y<<1)-0x3);
538
 
                st -= (aa<<1)*(--y);
539
 
            }
540
 
        }
541
 
        this.mkDiv(cx-a, cy-oy, s, (oy<<1)+hod);
542
 
        this.mkDiv(cx+a+wod-s+1, cy-oy, s, (oy<<1)+hod);
543
 
    }
544
 
 
545
 
 
546
 
    else
547
 
    {
548
 
        var _a = (width-((s-1)<<1))>>1,
549
 
        _b = (height-((s-1)<<1))>>1,
550
 
        _x = 0, _y = _b,
551
 
        _aa = (_a*_a)<<1, _bb = (_b*_b)<<1,
552
 
        _st = (_aa>>1)*(1-(_b<<1)) + _bb,
553
 
        _tt = (_bb>>1) - _aa*((_b<<1)-1),
554
 
 
555
 
        pxl = new Array(),
556
 
        pxt = new Array(),
557
 
        _pxb = new Array();
558
 
        pxl[0] = 0;
559
 
        pxt[0] = b;
560
 
        _pxb[0] = _b-1;
561
 
        while (y > 0)
562
 
        {
563
 
            if (st < 0)
564
 
            {
565
 
                st += bb*((x<<1)+0x3);
566
 
                tt += (bb<<1)*(++x);
567
 
                pxl[pxl.length] = x;
568
 
                pxt[pxt.length] = y;
569
 
            }
570
 
            else if (tt < 0)
571
 
            {
572
 
                st += bb*((x<<1)+0x3) - (aa<<1)*(y-1);
573
 
                tt += (bb<<1)*(++x) - aa*(((y--)<<1)-0x3);
574
 
                pxl[pxl.length] = x;
575
 
                pxt[pxt.length] = y;
576
 
            }
577
 
            else
578
 
            {
579
 
                tt -= aa*((y<<1)-0x3);
580
 
                st -= (aa<<1)*(--y);
581
 
            }
582
 
 
583
 
            if (_y > 0)
584
 
            {
585
 
                if (_st < 0)
586
 
                {
587
 
                    _st += _bb*((_x<<1)+0x3);
588
 
                    _tt += (_bb<<1)*(++_x);
589
 
                    _pxb[_pxb.length] = _y-1;
590
 
                }
591
 
                else if (_tt < 0)
592
 
                {
593
 
                    _st += _bb*((_x<<1)+0x3) - (_aa<<1)*(_y-1);
594
 
                    _tt += (_bb<<1)*(++_x) - _aa*(((_y--)<<1)-0x3);
595
 
                    _pxb[_pxb.length] = _y-1;
596
 
                }
597
 
                else
598
 
                {
599
 
                    _tt -= _aa*((_y<<1)-0x3);
600
 
                    _st -= (_aa<<1)*(--_y);
601
 
                    _pxb[_pxb.length-1]--;
602
 
                }
603
 
            }
604
 
        }
605
 
 
606
 
        var ox = 0, oy = b,
607
 
        _oy = _pxb[0],
608
 
        l = pxl.length,
609
 
        w, h;
610
 
        for (var i = 0; i < l; i++)
611
 
        {
612
 
            if (typeof _pxb[i] != "undefined")
613
 
            {
614
 
                if (_pxb[i] < _oy || pxt[i] < oy)
615
 
                {
616
 
                    x = pxl[i];
617
 
                    this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy);
618
 
                    ox = x;
619
 
                    oy = pxt[i];
620
 
                    _oy = _pxb[i];
621
 
                }
622
 
            }
623
 
            else
624
 
            {
625
 
                x = pxl[i];
626
 
                this.mkDiv(cx-x+1, cy-oy, 1, (oy<<1)+hod);
627
 
                this.mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
628
 
                ox = x;
629
 
                oy = pxt[i];
630
 
            }
631
 
        }
632
 
        this.mkDiv(cx-a, cy-oy, 1, (oy<<1)+hod);
633
 
        this.mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
634
 
    }
635
 
}
636
 
 
637
 
 
638
 
 
639
 
 
640
 
 
641
 
function mkOvDott(left, top, width, height)
642
 
{
643
 
    var a = width>>1, b = height>>1,
644
 
    wod = width&1, hod = height&1,
645
 
    cx = left+a, cy = top+b,
646
 
    x = 0, y = b,
647
 
    aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
648
 
    st = (aa2>>1)*(1-(b<<1)) + bb,
649
 
    tt = (bb>>1) - aa2*((b<<1)-1),
650
 
    drw = true;
651
 
    while (y > 0)
652
 
    {
653
 
        if (st < 0)
654
 
        {
655
 
            st += bb*((x<<1)+0x3);
656
 
            tt += (bb<<1)*(++x);
657
 
        }
658
 
        else if (tt < 0)
659
 
        {
660
 
            st += bb*((x<<1)+0x3) - aa4*(y-1);
661
 
            tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-0x3);
662
 
        }
663
 
        else
664
 
        {
665
 
            tt -= aa2*((y<<1)-0x3);
666
 
            st -= aa4*(--y);
667
 
        }
668
 
        if (drw) this.mkOvQds(cx, cy, -x, x+wod, -y, y+hod, 1, 1);
669
 
        drw = !drw;
670
 
    }
671
 
}
672
 
 
673
 
 
674
 
 
675
 
 
676
 
 
677
 
function mkRect(x, y, w, h)
678
 
{
679
 
    var s = this.stroke;
680
 
    this.mkDiv(x, y, w, s);
681
 
    this.mkDiv(x+w, y, s, h);
682
 
    this.mkDiv(x, y+h, w+s, s);
683
 
    this.mkDiv(x, y+s, s, h-s);
684
 
}
685
 
 
686
 
 
687
 
 
688
 
 
689
 
 
690
 
function mkRectDott(x, y, w, h)
691
 
{
692
 
    this.drawLine(x, y, x+w, y);
693
 
    this.drawLine(x+w, y, x+w, y+h);
694
 
    this.drawLine(x, y+h, x+w, y+h);
695
 
    this.drawLine(x, y, x, y+h);
696
 
}
697
 
 
698
 
 
699
 
 
700
 
 
701
 
 
702
 
function jsgFont()
703
 
{
704
 
    this.PLAIN = 'font-weight:normal;';
705
 
    this.BOLD = 'font-weight:bold;';
706
 
    this.ITALIC = 'font-style:italic;';
707
 
    this.ITALIC_BOLD = this.ITALIC + this.BOLD;
708
 
    this.BOLD_ITALIC = this.ITALIC_BOLD;
709
 
}
710
 
var Font = new jsgFont();
711
 
 
712
 
 
713
 
 
714
 
 
715
 
 
716
 
function jsgStroke()
717
 
{
718
 
    this.DOTTED = -1;
719
 
}
720
 
var Stroke = new jsgStroke();
721
 
 
722
 
 
723
 
 
724
 
 
725
 
 
726
 
function jsGraphics(id, wnd)
727
 
{
728
 
    this.setColor = new Function('arg', 'this.color = arg;');
729
 
 
730
 
 
731
 
    this.getColor = new Function('return this.color');
732
 
 
733
 
    this.setStroke = function(x)
734
 
    {
735
 
        this.stroke = x;
736
 
        if (!(x+1))
737
 
        {
738
 
            this.drawLine = mkLinDott;
739
 
            this.mkOv = mkOvDott;
740
 
            this.drawRect = mkRectDott;
741
 
        }
742
 
        else if (x-1 > 0)
743
 
        {
744
 
            this.drawLine = mkLin2D;
745
 
            this.mkOv = mkOv2D;
746
 
            this.drawRect = mkRect;
747
 
        }
748
 
        else
749
 
        {
750
 
            this.drawLine = mkLin;
751
 
            this.mkOv = mkOv;
752
 
            this.drawRect = mkRect;
753
 
        }
754
 
    };
755
 
 
756
 
 
757
 
 
758
 
    this.setPrintable = function(arg)
759
 
    {
760
 
        this.printable = arg;
761
 
        this.mkDiv = jg_n4? mkLyr : arg? mkDivPrint : mkDiv;
762
 
    };
763
 
 
764
 
 
765
 
 
766
 
    this.setFont = function(fam, sz, sty)
767
 
    {
768
 
        this.ftFam = fam;
769
 
        this.ftSz = sz;
770
 
        this.ftSty = sty || Font.PLAIN;
771
 
    };
772
 
 
773
 
 
774
 
 
775
 
    this.drawPolyline = this.drawPolyLine = function(x, y, s)
776
 
    {
777
 
        var i = x.length-1; while (i >= 0)
778
 
            this.drawLine(x[i], y[i], x[--i], y[i]);
779
 
    };
780
 
 
781
 
 
782
 
 
783
 
    this.fillRect = function(x, y, w, h)
784
 
    {
785
 
        this.mkDiv(x, y, w, h);
786
 
    };
787
 
 
788
 
 
789
 
    this.fillRectPattern = function(x, y, w, h, url)
790
 
    {
791
 
        this.htm += '<div style="position:absolute;'+
792
 
            'left:' + x + 'px;'+
793
 
            'top:' + y + 'px;'+
794
 
            'width:' + w + 'px;'+
795
 
            'height:' + h + 'px;'+
796
 
            'clip:rect(0,'+w+'px,'+h+'px,0);'+
797
 
            'overflow:hidden;'+
798
 
            //'background-color:' + this.color + ';'+
799
 
            "background-image: url('" + url + "');"+
800
 
            "layer-background-image: url('" + url + "');"+
801
 
            'z-index:100;"><\/div>';
802
 
        //alert(this.htm);
803
 
    }
804
 
 
805
 
    this.drawHandle = function(x, y, w, h, cursor)
806
 
    {
807
 
        
808
 
        this.htm += '<div style="position:absolute;'+
809
 
        'left:' + x + 'px;'+
810
 
        'top:' + y + 'px;'+
811
 
        'width:' + w + 'px;'+
812
 
        'height:' + h + 'px;'+
813
 
        'clip:rect(0,'+w+'px,'+h+'px,0);'+
814
 
        'padding: 2px;overflow:hidden;'+
815
 
        "cursor: '" + cursor + "';"+
816
 
        '" class="handleBox" id="' + cursor + '" ><\/div>';
817
 
    }
818
 
 
819
 
    this.drawHandleBox = function(x, y, w, h, cursor)
820
 
    {
821
 
        
822
 
        this.htm += '<div style="position:absolute;'+
823
 
        'left:' + x + 'px;'+
824
 
        'top:' + y + 'px;'+
825
 
        'width:' + w + 'px;'+
826
 
        'height:' + h + 'px;'+
827
 
        'clip:rect(0,'+(w+2)+'px,'+(h+2)+'px,0);'+
828
 
        'overflow:hidden; border: solid 1px '+ this.color+';'+
829
 
        "cursor: '" + cursor + "';"+
830
 
        '" class="handleBox" id="' + cursor + '" ><\/div>';
831
 
 
832
 
        
833
 
    }
834
 
 
835
 
    this.drawPolygon = function(x, y)
836
 
    {
837
 
        this.drawPolyline(x, y);
838
 
        this.drawLine(x[x.length-1], y[x.length-1], x[0], y[0]);
839
 
    };
840
 
 
841
 
 
842
 
 
843
 
    this.drawEllipse = this.drawOval = function(x, y, w, h)
844
 
    {
845
 
        this.mkOv(x, y, w, h);
846
 
    };
847
 
 
848
 
 
849
 
 
850
 
    this.fillEllipse = this.fillOval = function(left, top, w, h)
851
 
    {
852
 
        var a = (w -= 1)>>1, b = (h -= 1)>>1,
853
 
        wod = (w&1)+1, hod = (h&1)+1,
854
 
        cx = left+a, cy = top+b,
855
 
        x = 0, y = b,
856
 
        ox = 0, oy = b,
857
 
        aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
858
 
        st = (aa2>>1)*(1-(b<<1)) + bb,
859
 
        tt = (bb>>1) - aa2*((b<<1)-1),
860
 
        pxl, dw, dh;
861
 
        if (w+1) while (y > 0)
862
 
        {
863
 
            if (st < 0)
864
 
            {
865
 
                st += bb*((x<<1)+0x3);
866
 
                tt += (bb<<1)*(++x);
867
 
            }
868
 
            else if (tt < 0)
869
 
            {
870
 
                st += bb*((x<<1)+0x3) - aa4*(y-1);
871
 
                pxl = cx-x;
872
 
                dw = (x<<1)+wod;
873
 
                tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-0x3);
874
 
                dh = oy-y;
875
 
                this.mkDiv(pxl, cy-oy, dw, dh);
876
 
                this.mkDiv(pxl, cy+oy-dh+hod, dw, dh);
877
 
                ox = x;
878
 
                oy = y;
879
 
            }
880
 
            else
881
 
            {
882
 
                tt -= aa2*((y<<1)-0x3);
883
 
                st -= aa4*(--y);
884
 
            }
885
 
        }
886
 
        this.mkDiv(cx-a, cy-oy, w+1, (oy<<1)+hod);
887
 
    };
888
 
 
889
 
 
890
 
 
891
 
    this.drawString = mkLbl;
892
 
 
893
 
 
894
 
 
895
 
    this.clear = function()
896
 
    {
897
 
        this.htm = "";
898
 
        if (this.cnv) this.cnv.innerHTML = this.defhtm;
899
 
        
900
 
    };
901
 
 
902
 
 
903
 
 
904
 
    this.mkOvQds = function(cx, cy, xl, xr, yt, yb, w, h)
905
 
    {
906
 
        this.mkDiv(xr+cx, yt+cy, w, h);
907
 
        this.mkDiv(xr+cx, yb+cy, w, h);
908
 
        this.mkDiv(xl+cx, yb+cy, w, h);
909
 
        this.mkDiv(xl+cx, yt+cy, w, h);
910
 
    };
911
 
 
912
 
 
913
 
    this.setStroke(1);
914
 
    this.setPrintable(false);
915
 
    this.setFont('verdana,geneva,helvetica,sans-serif', String.fromCharCode(0x31, 0x32, 0x70, 0x78), Font.PLAIN);
916
 
    this.color = '#000000';
917
 
    this.htm = '';
918
 
    this.wnd = wnd || window;
919
 
 
920
 
 
921
 
    if (!(jg_ie || jg_dom || jg_ihtm)) chkDHTM();
922
 
    if (typeof id != 'string' || !id) this.paint = pntDoc;
923
 
    else
924
 
    {
925
 
        this.cnv = document.all? (this.wnd.document.all[id] || null)
926
 
            : document.getElementById? (this.wnd.document.getElementById(id) || null)
927
 
            : null;
928
 
        this.defhtm = (this.cnv && this.cnv.innerHTML)? this.cnv.innerHTML : '';
929
 
        this.paint = jg_dom? pntCnvDom : jg_ie? pntCnvIe : jg_ihtm? pntCnvIhtm : pntCnv;
930
 
    }
931
 
}