Graphics.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710
  1. /* This notice must be untouched at all times.
  2. wz_jsgraphics.js v. 3.05
  3. The latest version is available at
  4. http://www.walterzorn.com
  5. or http://www.devira.com
  6. or http://www.walterzorn.de
  7. Copyright (c) 2002-2009 Walter Zorn. All rights reserved.
  8. Created 3. 11. 2002 by Walter Zorn (Web: http://www.walterzorn.com )
  9. Last modified: 2. 2. 2009
  10. Performance optimizations for Internet Explorer
  11. by Thomas Frank and John Holdsworth.
  12. fillPolygon method implemented by Matthieu Haller.
  13. High Performance JavaScript Graphics Library.
  14. Provides methods
  15. - to draw lines, rectangles, ellipses, polygons
  16. with specifiable line thickness,
  17. - to fill rectangles, polygons, ellipses and arcs
  18. - to draw text.
  19. NOTE: Operations, functions and branching have rather been optimized
  20. to efficiency and speed than to shortness of source code.
  21. LICENSE: LGPL
  22. This library is free software; you can redistribute it and/or
  23. modify it under the terms of the GNU Lesser General Public
  24. License (LGPL) as published by the Free Software Foundation; either
  25. version 2.1 of the License, or (at your option) any later version.
  26. This library is distributed in the hope that it will be useful,
  27. but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  29. Lesser General Public License for more details.
  30. You should have received a copy of the GNU Lesser General Public
  31. License along with this library; if not, write to the Free Software
  32. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,
  33. or see http://www.gnu.org/copyleft/lesser.html
  34. */
  35. var jg_ok, jg_ie, jg_fast, jg_dom, jg_moz;
  36. function _chkDHTM(wnd, x, i)
  37. // Under XUL, owner of 'document' must be specified explicitly
  38. {
  39. x = wnd.document.body || null;
  40. jg_ie = x && typeof x.insertAdjacentHTML != "undefined" && wnd.document.createElement;
  41. jg_dom = (x && !jg_ie &&
  42. typeof x.appendChild != "undefined" &&
  43. typeof wnd.document.createRange != "undefined" &&
  44. typeof (i = wnd.document.createRange()).setStartBefore != "undefined" &&
  45. typeof i.createContextualFragment != "undefined");
  46. jg_fast = jg_ie && wnd.document.all && !wnd.opera;
  47. jg_moz = jg_dom && typeof x.style.MozOpacity != "undefined";
  48. jg_ok = !!(jg_ie || jg_dom);
  49. };
  50. function _pntCnvDom()
  51. {
  52. var x = this.wnd.document.createRange();
  53. x.setStartBefore(this.cnv);
  54. x = x.createContextualFragment(jg_fast? this._htmRpc() : this.htm);
  55. if(this.cnv) this.cnv.appendChild(x);
  56. this.htm = "";
  57. };
  58. function _pntCnvIe()
  59. {
  60. if(this.cnv) this.cnv.insertAdjacentHTML("BeforeEnd", jg_fast? this._htmRpc() : this.htm);
  61. this.htm = "";
  62. };
  63. function _pntDoc()
  64. {
  65. this.wnd.document.write(jg_fast? this._htmRpc() : this.htm);
  66. this.htm = '';
  67. };
  68. function _pntN()
  69. {
  70. ;
  71. };
  72. function _mkDiv(x, y, w, h)
  73. {
  74. this.htm += '<div style="position:absolute;'+
  75. 'left:' + x + 'px;'+
  76. 'top:' + y + 'px;'+
  77. 'width:' + w + 'px;'+
  78. 'height:' + h + 'px;'+
  79. 'clip:rect(0,'+w+'px,'+h+'px,0);'+
  80. 'background-color:' + this.color +
  81. (!jg_moz? ';overflow:hidden' : '')+
  82. ';"><\/div>';
  83. };
  84. function _mkDivIe(x, y, w, h, nType) // DIV 마진을 주기 위하여 type 추가 - hjkim
  85. {
  86. this.htm += '%%'+this.color+';'+x+';'+y+';'+w+';'+h+';';
  87. };
  88. function _mkDivPrt(x, y, w, h)
  89. {
  90. this.htm += '<div style="position:absolute;'+
  91. 'border-left:' + w + 'px solid ' + this.color + ';'+
  92. 'left:' + x + 'px;'+
  93. 'top:' + y + 'px;'+
  94. 'width:0px;'+
  95. 'height:' + h + 'px;'+
  96. 'clip:rect(0,'+w+'px,'+h+'px,0);'+
  97. 'background-color:' + this.color +
  98. (!jg_moz? ';overflow:hidden' : '')+
  99. ';"><\/div>';
  100. };
  101. var _regex = /%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g;
  102. function _htmRpc()
  103. {
  104. return this.htm.replace(
  105. _regex,
  106. '<div style="overflow:hidden;position:absolute;background-color:'+
  107. '$1;left:$2px;top:$3px;width:$4px;height:$5px"></div>\n');
  108. };
  109. function _htmPrtRpc()
  110. {
  111. return this.htm.replace(
  112. _regex,
  113. '<div style="overflow:hidden;position:absolute;background-color:'+
  114. '$1;left:$2px;top:$3px;width:$4px;height:$5px;border-left:$4px solid $1"></div>\n');
  115. };
  116. function _mkLin(x1, y1, x2, y2)
  117. {
  118. if(x1 > x2)
  119. {
  120. var _x2 = x2;
  121. var _y2 = y2;
  122. x2 = x1;
  123. y2 = y1;
  124. x1 = _x2;
  125. y1 = _y2;
  126. }
  127. var dx = x2-x1, dy = Math.abs(y2-y1),
  128. x = x1, y = y1,
  129. yIncr = (y1 > y2)? -1 : 1;
  130. if(dx >= dy)
  131. {
  132. var pr = dy<<1,
  133. pru = pr - (dx<<1),
  134. p = pr-dx,
  135. ox = x;
  136. while(dx > 0)
  137. {--dx;
  138. ++x;
  139. if(p > 0)
  140. {
  141. this._mkDiv(ox, y, x-ox, 1);
  142. y += yIncr;
  143. p += pru;
  144. ox = x;
  145. }
  146. else
  147. {
  148. p += pr;
  149. }
  150. }
  151. this._mkDiv(ox, y, x2-ox+1, 1);
  152. }
  153. else
  154. {
  155. var pr = dx<<1,
  156. pru = pr - (dy<<1),
  157. p = pr-dy,
  158. oy = y;
  159. if(y2 <= y1)
  160. {
  161. while(dy > 0)
  162. {--dy;
  163. if(p > 0)
  164. {
  165. this._mkDiv(x++, y, 1, oy-y+1);
  166. y += yIncr;
  167. p += pru;
  168. oy = y;
  169. }
  170. else
  171. {
  172. y += yIncr;
  173. p += pr;
  174. }
  175. }
  176. this._mkDiv(x2, y2, 1, oy-y2+1);
  177. }
  178. else
  179. {
  180. while(dy > 0)
  181. {--dy;
  182. y += yIncr;
  183. if(p > 0)
  184. {
  185. this._mkDiv(x++, oy, 1, y-oy);
  186. p += pru;
  187. oy = y;
  188. }
  189. else
  190. {
  191. p += pr;
  192. }
  193. }
  194. this._mkDiv(x2, oy, 1, y2-oy+1);
  195. }
  196. }
  197. };
  198. function _mkLin2D(x1, y1, x2, y2)
  199. {
  200. if(x1 > x2)
  201. {
  202. var _x2 = x2;
  203. var _y2 = y2;
  204. x2 = x1;
  205. y2 = y1;
  206. x1 = _x2;
  207. y1 = _y2;
  208. }
  209. var dx = x2-x1, dy = Math.abs(y2-y1),
  210. x = x1, y = y1,
  211. yIncr = (y1 > y2)? -1 : 1;
  212. var s = this.stroke;
  213. if(dx >= dy)
  214. {
  215. if(dx > 0 && s-3 > 0)
  216. {
  217. var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s>>1)*dy) / dx;
  218. _s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
  219. }
  220. else var _s = s;
  221. var ad = Math.ceil(s/2);
  222. var pr = dy<<1,
  223. pru = pr - (dx<<1),
  224. p = pr-dx,
  225. ox = x;
  226. while(dx > 0)
  227. {--dx;
  228. ++x;
  229. if(p > 0)
  230. {
  231. this._mkDiv(ox, y, x-ox+ad, _s);
  232. y += yIncr;
  233. p += pru;
  234. ox = x;
  235. }
  236. else
  237. {
  238. p += pr;
  239. }
  240. }
  241. this._mkDiv(ox, y, x2-ox+ad+1, _s);
  242. this.lineWidth = ox+(x2-ox+ad+1); // Margin 적용을 위해 추가 - hjkim
  243. this.lineHeight = _s;
  244. }
  245. else
  246. {
  247. if(s-3 > 0)
  248. {
  249. var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s>>1)*dx-dy) / dy;
  250. _s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
  251. }
  252. else var _s = s;
  253. var ad = Math.round(s/2);
  254. var pr = dx<<1,
  255. pru = pr - (dy<<1),
  256. p = pr-dy,
  257. oy = y;
  258. if(y2 <= y1)
  259. {
  260. ++ad;
  261. while(dy > 0)
  262. {--dy;
  263. if(p > 0)
  264. {
  265. this._mkDiv(x++, y, _s, oy-y+ad);
  266. y += yIncr;
  267. p += pru;
  268. oy = y;
  269. }
  270. else
  271. {
  272. y += yIncr;
  273. p += pr;
  274. }
  275. }
  276. this._mkDiv(x2, y2, _s, oy-y2+ad);
  277. this.lineWidth = _s; // Margin 적용을 위해 추가 - hjkim
  278. this.lineHeight = Math.abs(y2-y1)+(oy-y2+ad);
  279. }
  280. else
  281. {
  282. while(dy > 0)
  283. {--dy;
  284. y += yIncr;
  285. if(p > 0)
  286. {
  287. this._mkDiv(x++, oy, _s, y-oy+ad);
  288. p += pru;
  289. oy = y;
  290. }
  291. else
  292. {
  293. p += pr;
  294. }
  295. }
  296. this._mkDiv(x2, oy, _s, y2-oy+ad+1);
  297. this.lineWidth = _s; // Margin 적용을 위해 추가 - hjkim
  298. this.lineHeight = oy+(y2-oy+ad+1);
  299. }
  300. }
  301. };
  302. function _mkLinDott(x1, y1, x2, y2)
  303. {
  304. if(x1 > x2)
  305. {
  306. var _x2 = x2;
  307. var _y2 = y2;
  308. x2 = x1;
  309. y2 = y1;
  310. x1 = _x2;
  311. y1 = _y2;
  312. }
  313. var dx = x2-x1, dy = Math.abs(y2-y1),
  314. x = x1, y = y1,
  315. yIncr = (y1 > y2)? -1 : 1,
  316. drw = true;
  317. if(dx >= dy)
  318. {
  319. var pr = dy<<1,
  320. pru = pr - (dx<<1),
  321. p = pr-dx;
  322. while(dx > 0)
  323. {--dx;
  324. if(drw) this._mkDiv(x, y, 1, 1);
  325. drw = !drw;
  326. if(p > 0)
  327. {
  328. y += yIncr;
  329. p += pru;
  330. }
  331. else
  332. {
  333. p += pr;
  334. }
  335. ++x;
  336. }
  337. }
  338. else
  339. {
  340. var pr = dx<<1,
  341. pru = pr - (dy<<1),
  342. p = pr-dy;
  343. while(dy > 0)
  344. {--dy;
  345. if(drw)
  346. {
  347. this._mkDiv(x, y, 1, 1);
  348. }
  349. drw = !drw;
  350. y += yIncr;
  351. if(p > 0)
  352. {
  353. ++x;
  354. p += pru;
  355. }
  356. else
  357. {
  358. p += pr;
  359. }
  360. }
  361. }
  362. if(drw)
  363. {
  364. this._mkDiv(x, y, 1, 1);
  365. }
  366. };
  367. function _mkOv(left, top, width, height)
  368. {
  369. var a = (++width)>>1, b = (++height)>>1,
  370. wod = width&1, hod = height&1,
  371. cx = left+a, cy = top+b,
  372. x = 0, y = b,
  373. ox = 0, oy = b,
  374. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  375. st = (aa2>>1)*(1-(b<<1)) + bb2,
  376. tt = (bb2>>1) - aa2*((b<<1)-1),
  377. w, h;
  378. while(y > 0)
  379. {
  380. if(st < 0)
  381. {
  382. st += bb2*((x<<1)+3);
  383. tt += bb4*(++x);
  384. }
  385. else if(tt < 0)
  386. {
  387. st += bb2*((x<<1)+3) - aa4*(y-1);
  388. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  389. w = x-ox;
  390. h = oy-y;
  391. if((w&2) && (h&2))
  392. {
  393. this._mkOvQds(cx, cy, x-2, y+2, 1, 1, wod, hod);
  394. this._mkOvQds(cx, cy, x-1, y+1, 1, 1, wod, hod);
  395. }
  396. else this._mkOvQds(cx, cy, x-1, oy, w, h, wod, hod);
  397. ox = x;
  398. oy = y;
  399. }
  400. else
  401. {
  402. tt -= aa2*((y<<1)-3);
  403. st -= aa4*(--y);
  404. }
  405. }
  406. w = a-ox+1;
  407. h = (oy<<1)+hod;
  408. y = cy-oy;
  409. this._mkDiv(cx-a, y, w, h);
  410. this._mkDiv(cx+ox+wod-1, y, w, h);
  411. };
  412. function _mkOv2D(left, top, width, height)
  413. {
  414. var s = this.stroke;
  415. width += s+1;
  416. height += s+1;
  417. var a = width>>1, b = height>>1,
  418. wod = width&1, hod = height&1,
  419. cx = left+a, cy = top+b,
  420. x = 0, y = b,
  421. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  422. st = (aa2>>1)*(1-(b<<1)) + bb2,
  423. tt = (bb2>>1) - aa2*((b<<1)-1);
  424. if(s-4 < 0 && (!(s-2) || width-51 > 0 && height-51 > 0))
  425. {
  426. var ox = 0, oy = b,
  427. w, h,
  428. pxw;
  429. while(y > 0)
  430. {
  431. if(st < 0)
  432. {
  433. st += bb2*((x<<1)+3);
  434. tt += bb4*(++x);
  435. }
  436. else if(tt < 0)
  437. {
  438. st += bb2*((x<<1)+3) - aa4*(y-1);
  439. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  440. w = x-ox;
  441. h = oy-y;
  442. if(w-1)
  443. {
  444. pxw = w+1+(s&1);
  445. h = s;
  446. }
  447. else if(h-1)
  448. {
  449. pxw = s;
  450. h += 1+(s&1);
  451. }
  452. else pxw = h = s;
  453. this._mkOvQds(cx, cy, x-1, oy, pxw, h, wod, hod);
  454. ox = x;
  455. oy = y;
  456. }
  457. else
  458. {
  459. tt -= aa2*((y<<1)-3);
  460. st -= aa4*(--y);
  461. }
  462. }
  463. this._mkDiv(cx-a, cy-oy, s, (oy<<1)+hod);
  464. this._mkDiv(cx+a+wod-s, cy-oy, s, (oy<<1)+hod);
  465. }
  466. else
  467. {
  468. var _a = (width-(s<<1))>>1,
  469. _b = (height-(s<<1))>>1,
  470. _x = 0, _y = _b,
  471. _aa2 = (_a*_a)<<1, _aa4 = _aa2<<1, _bb2 = (_b*_b)<<1, _bb4 = _bb2<<1,
  472. _st = (_aa2>>1)*(1-(_b<<1)) + _bb2,
  473. _tt = (_bb2>>1) - _aa2*((_b<<1)-1),
  474. pxl = new Array(),
  475. pxt = new Array(),
  476. _pxb = new Array();
  477. pxl[0] = 0;
  478. pxt[0] = b;
  479. _pxb[0] = _b-1;
  480. while(y > 0)
  481. {
  482. if(st < 0)
  483. {
  484. pxl[pxl.length] = x;
  485. pxt[pxt.length] = y;
  486. st += bb2*((x<<1)+3);
  487. tt += bb4*(++x);
  488. }
  489. else if(tt < 0)
  490. {
  491. pxl[pxl.length] = x;
  492. st += bb2*((x<<1)+3) - aa4*(y-1);
  493. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  494. pxt[pxt.length] = y;
  495. }
  496. else
  497. {
  498. tt -= aa2*((y<<1)-3);
  499. st -= aa4*(--y);
  500. }
  501. if(_y > 0)
  502. {
  503. if(_st < 0)
  504. {
  505. _st += _bb2*((_x<<1)+3);
  506. _tt += _bb4*(++_x);
  507. _pxb[_pxb.length] = _y-1;
  508. }
  509. else if(_tt < 0)
  510. {
  511. _st += _bb2*((_x<<1)+3) - _aa4*(_y-1);
  512. _tt += _bb4*(++_x) - _aa2*(((_y--)<<1)-3);
  513. _pxb[_pxb.length] = _y-1;
  514. }
  515. else
  516. {
  517. _tt -= _aa2*((_y<<1)-3);
  518. _st -= _aa4*(--_y);
  519. _pxb[_pxb.length-1]--;
  520. }
  521. }
  522. }
  523. var ox = -wod, oy = b,
  524. _oy = _pxb[0],
  525. l = pxl.length,
  526. w, h;
  527. for(var i = 0; i < l; i++)
  528. {
  529. if(typeof _pxb[i] != "undefined")
  530. {
  531. if(_pxb[i] < _oy || pxt[i] < oy)
  532. {
  533. x = pxl[i];
  534. this._mkOvQds(cx, cy, x, oy, x-ox, oy-_oy, wod, hod);
  535. ox = x;
  536. oy = pxt[i];
  537. _oy = _pxb[i];
  538. }
  539. }
  540. else
  541. {
  542. x = pxl[i];
  543. this._mkDiv(cx-x, cy-oy, 1, (oy<<1)+hod);
  544. this._mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
  545. ox = x;
  546. oy = pxt[i];
  547. }
  548. }
  549. this._mkDiv(cx-a, cy-oy, 1, (oy<<1)+hod);
  550. this._mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
  551. }
  552. };
  553. function _mkOvDott(left, top, width, height)
  554. {
  555. var a = (++width)>>1, b = (++height)>>1,
  556. wod = width&1, hod = height&1, hodu = hod^1,
  557. cx = left+a, cy = top+b,
  558. x = 0, y = b,
  559. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  560. st = (aa2>>1)*(1-(b<<1)) + bb2,
  561. tt = (bb2>>1) - aa2*((b<<1)-1),
  562. drw = true;
  563. while(y > 0)
  564. {
  565. if(st < 0)
  566. {
  567. st += bb2*((x<<1)+3);
  568. tt += bb4*(++x);
  569. }
  570. else if(tt < 0)
  571. {
  572. st += bb2*((x<<1)+3) - aa4*(y-1);
  573. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  574. }
  575. else
  576. {
  577. tt -= aa2*((y<<1)-3);
  578. st -= aa4*(--y);
  579. }
  580. if(drw && y >= hodu) this._mkOvQds(cx, cy, x, y, 1, 1, wod, hod);
  581. drw = !drw;
  582. }
  583. };
  584. function _mkRect(x, y, w, h)
  585. {
  586. var s = this.stroke;
  587. this._mkDiv(x, y, w, s);
  588. this._mkDiv(x+w, y, s, h);
  589. this._mkDiv(x, y+h, w+s, s);
  590. this._mkDiv(x, y+s, s, h-s);
  591. };
  592. function _mkRectDott(x, y, w, h)
  593. {
  594. this.drawLine(x, y, x+w, y);
  595. this.drawLine(x+w, y, x+w, y+h);
  596. this.drawLine(x, y+h, x+w, y+h);
  597. this.drawLine(x, y, x, y+h);
  598. };
  599. function _mkRoundrect(left, top, width, height, ellipsewidth, ellipseheight)
  600. {
  601. if (ellipsewidth >= width)
  602. {
  603. ellipsewidth = width;
  604. }
  605. else
  606. {
  607. this._mkDiv(0+(ellipsewidth/2), 0, width-ellipsewidth, 1);
  608. this._mkDiv(0+(ellipsewidth/2), height-1, width-ellipsewidth, 1);
  609. }
  610. if (ellipseheight >= height)
  611. {
  612. ellipseheight = height;
  613. }
  614. else
  615. {
  616. this._mkDiv(0, 0+(ellipseheight/2), 1, height-ellipseheight);
  617. this._mkDiv(width-1, 0+(ellipseheight/2), 1, height-ellipseheight);
  618. }
  619. var a = (++ellipsewidth)>>1, b = (++ellipseheight)>>1,
  620. wod = ellipsewidth&1, hod = ellipseheight&1;
  621. for (var i = 0; i < 4 ; i++)
  622. {
  623. var cx = left+a, cy = top+b,
  624. x = 0, y = b,
  625. ox = 0, oy = b,
  626. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  627. st = (aa2>>1)*(1-(b<<1)) + bb2,
  628. tt = (bb2>>1) - aa2*((b<<1)-1),
  629. w, h;
  630. while(y > 0)
  631. {
  632. if(st < 0)
  633. {
  634. st += bb2*((x<<1)+3);
  635. tt += bb4*(++x);
  636. }
  637. else if(tt < 0)
  638. {
  639. st += bb2*((x<<1)+3) - aa4*(y-1);
  640. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  641. w = x-ox;
  642. h = oy-y;
  643. var cxTemp, cyTemp;
  644. if (i == 0)
  645. {
  646. cxTemp = cx;
  647. cyTemp = cy;
  648. }
  649. else if (i == 1)
  650. {
  651. cxTemp = cx+width-ellipsewidth;
  652. cyTemp = cy;
  653. }
  654. else if (i == 2)
  655. {
  656. cxTemp = cx+width-ellipsewidth;
  657. cyTemp = cy+height-ellipseheight;
  658. }
  659. else if (i == 3)
  660. {
  661. cxTemp = cx;
  662. cyTemp = cy+height-ellipseheight;
  663. }
  664. if((w&2) && (h&2))
  665. {
  666. this._mkRoundrectQds(cxTemp, cyTemp, x-2, y+2, 1, 1, wod, hod, i);
  667. this._mkRoundrectQds(cxTemp, cyTemp, x-1, y+1, 1, 1, wod, hod, i);
  668. }
  669. else
  670. {
  671. this._mkRoundrectQds(cxTemp, cyTemp, x-1, oy, w, h, wod, hod, i);
  672. }
  673. ox = x;
  674. oy = y;
  675. }
  676. else
  677. {
  678. tt -= aa2*((y<<1)-3);
  679. st -= aa4*(--y);
  680. }
  681. }
  682. w = a-ox+1;
  683. h = ((oy<<1)+hod)/2;
  684. y = cy-oy;
  685. if (i == 0)
  686. {
  687. this._mkDiv(cx-a, y, w, h);
  688. }
  689. else if (i == 1)
  690. {
  691. this._mkDiv(cx+ox+wod-1+width-ellipsewidth, y, w, h);
  692. }
  693. else if (i == 2)
  694. {
  695. this._mkDiv(cx+ox+wod-1+width-ellipsewidth, height-Math.floor(ellipseheight/2), w, h);
  696. }
  697. else if (i == 3)
  698. {
  699. this._mkDiv(cx-a, height-Math.floor(ellipseheight/2), w, h);
  700. }
  701. }
  702. };
  703. function _mkRoundrect2D(left, top, width, height, ellipsewidth, ellipseheight)
  704. {
  705. var s = this.stroke;
  706. if (ellipsewidth >= width)
  707. {
  708. ellipsewidth = width;
  709. }
  710. else
  711. {
  712. this._mkDiv(ellipsewidth/2, -(s/2), width-ellipsewidth, s);
  713. this._mkDiv(ellipsewidth/2, height-(s/2), width-ellipsewidth, s);
  714. }
  715. if (ellipseheight >= height)
  716. {
  717. ellipseheight = height;
  718. }
  719. else
  720. {
  721. this._mkDiv(-(s/2), ellipsewidth/2, s, height-ellipsewidth);
  722. this._mkDiv(width-(s/2), ellipsewidth/2, s, height-ellipsewidth);
  723. }
  724. ellipsewidth += s+1;
  725. ellipseheight += s+1;
  726. var a = ellipsewidth>>1, b = ellipseheight>>1,
  727. wod = ellipsewidth&1, hod = ellipseheight&1;
  728. if(s-4 < 0 && (!(s-2) || ellipsewidth-51 > 0 && ellipseheight-51 > 0))
  729. {
  730. for (var i = 0; i < 4 ; i++)
  731. {
  732. var cx = left+a, cy = top+b,
  733. x = 0, y = b,
  734. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  735. st = (aa2>>1)*(1-(b<<1)) + bb2,
  736. tt = (bb2>>1) - aa2*((b<<1)-1);
  737. var ox = 0, oy = b,
  738. w, h,
  739. pxw;
  740. while(y > 0)
  741. {
  742. if(st < 0)
  743. {
  744. st += bb2*((x<<1)+3);
  745. tt += bb4*(++x);
  746. }
  747. else if(tt < 0)
  748. {
  749. st += bb2*((x<<1)+3) - aa4*(y-1);
  750. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  751. w = x-ox;
  752. h = oy-y;
  753. if(w-1)
  754. {
  755. pxw = w+1+(s&1);
  756. h = s;
  757. }
  758. else if(h-1)
  759. {
  760. pxw = s;
  761. h += 1+(s&1);
  762. }
  763. else
  764. {
  765. pxw = h = s;
  766. }
  767. var cxTemp, cyTemp;
  768. if (i == 0)
  769. {
  770. cxTemp = cx;
  771. cyTemp = cy;
  772. }
  773. else if (i == 1)
  774. {
  775. cxTemp = cx+width-ellipsewidth+s-(s%2);
  776. cyTemp = cy;
  777. }
  778. else if (i == 2)
  779. {
  780. cxTemp = cx+width-ellipsewidth+s-(s%2);
  781. cyTemp = cy+height-ellipseheight+s-(s%2);
  782. }
  783. else if (i == 3)
  784. {
  785. cxTemp = cx;
  786. cyTemp = cy+height-ellipseheight+s-(s%2);
  787. }
  788. this._mkRoundrectQds(cxTemp, cyTemp, x-1, oy, pxw, h, wod, hod, i);
  789. ox = x;
  790. oy = y;
  791. }
  792. else
  793. {
  794. tt -= aa2*((y<<1)-3);
  795. st -= aa4*(--y);
  796. }
  797. }
  798. if (i == 0)
  799. {
  800. this._mkDiv(cx-a, cy-oy, s, ((oy<<1)+hod)/2);
  801. }
  802. else if (i == 1)
  803. {
  804. this._mkDiv(cx+a+wod-s+width-ellipsewidth+s-(s%2), cy-oy, s, ((oy<<1)+hod)/2);
  805. }
  806. else if (i == 2)
  807. {
  808. this._mkDiv(cx+a+wod-s+width-ellipsewidth+s-(s%2), height-Math.floor(ellipseheight/2), s, ((oy<<1)+hod)/2);
  809. }
  810. else if (i == 3)
  811. {
  812. this._mkDiv(cx-a, height-Math.floor(ellipseheight/2), s, ((oy<<1)+hod)/2);
  813. }
  814. }
  815. }
  816. else
  817. {
  818. for (var i = 0; i < 4 ; i++)
  819. {
  820. var cx = left+a, cy = top+b,
  821. x = 0, y = b,
  822. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  823. st = (aa2>>1)*(1-(b<<1)) + bb2,
  824. tt = (bb2>>1) - aa2*((b<<1)-1);
  825. var _a = (ellipsewidth-(s<<1))>>1,
  826. _b = (ellipseheight-(s<<1))>>1,
  827. _x = 0, _y = _b,
  828. _aa2 = (_a*_a)<<1, _aa4 = _aa2<<1, _bb2 = (_b*_b)<<1, _bb4 = _bb2<<1,
  829. _st = (_aa2>>1)*(1-(_b<<1)) + _bb2,
  830. _tt = (_bb2>>1) - _aa2*((_b<<1)-1),
  831. pxl = new Array(),
  832. pxt = new Array(),
  833. _pxb = new Array();
  834. pxl[0] = 0;
  835. pxt[0] = b;
  836. _pxb[0] = _b-1;
  837. while(y > 0)
  838. {
  839. if(st < 0)
  840. {
  841. pxl[pxl.length] = x;
  842. pxt[pxt.length] = y;
  843. st += bb2*((x<<1)+3);
  844. tt += bb4*(++x);
  845. }
  846. else if(tt < 0)
  847. {
  848. pxl[pxl.length] = x;
  849. st += bb2*((x<<1)+3) - aa4*(y-1);
  850. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  851. pxt[pxt.length] = y;
  852. }
  853. else
  854. {
  855. tt -= aa2*((y<<1)-3);
  856. st -= aa4*(--y);
  857. }
  858. if(_y > 0)
  859. {
  860. if(_st < 0)
  861. {
  862. _st += _bb2*((_x<<1)+3);
  863. _tt += _bb4*(++_x);
  864. _pxb[_pxb.length] = _y-1;
  865. }
  866. else if(_tt < 0)
  867. {
  868. _st += _bb2*((_x<<1)+3) - _aa4*(_y-1);
  869. _tt += _bb4*(++_x) - _aa2*(((_y--)<<1)-3);
  870. _pxb[_pxb.length] = _y-1;
  871. }
  872. else
  873. {
  874. _tt -= _aa2*((_y<<1)-3);
  875. _st -= _aa4*(--_y);
  876. _pxb[_pxb.length-1]--;
  877. }
  878. }
  879. }
  880. var ox = -wod, oy = b,
  881. _oy = _pxb[0],
  882. l = pxl.length,
  883. w, h;
  884. var cxTemp, cyTemp;
  885. if (i == 0)
  886. {
  887. cxTemp = cx;
  888. cyTemp = cy;
  889. }
  890. else if (i == 1)
  891. {
  892. cxTemp = cx+width-ellipsewidth+s-(s%2);
  893. cyTemp = cy;
  894. }
  895. else if (i == 2)
  896. {
  897. cxTemp = cx+width-ellipsewidth+s-(s%2);
  898. cyTemp = cy+height-ellipseheight+s-(s%2);
  899. }
  900. else if (i == 3)
  901. {
  902. cxTemp = cx;
  903. cyTemp = cy+height-ellipseheight+s-(s%2);
  904. }
  905. for(var j = 0; j < l; j++)
  906. {
  907. if(typeof _pxb[j] != "undefined")
  908. {
  909. if(_pxb[j] < _oy || pxt[j] < oy)
  910. {
  911. x = pxl[j];
  912. this._mkRoundrectQds(cxTemp, cyTemp, x, oy, x-ox, oy-_oy, wod, hod, i);
  913. ox = x;
  914. oy = pxt[j];
  915. _oy = _pxb[j];
  916. }
  917. }
  918. else
  919. {
  920. x = pxl[j];
  921. if (i == 0)
  922. {
  923. this._mkDiv(cxTemp-x, cyTemp-oy, 1, ((oy<<1)+hod)/2);
  924. }
  925. else if (i == 1)
  926. {
  927. this._mkDiv(cxTemp+ox+wod, cyTemp-oy, 1, ((oy<<1)+hod)/2);
  928. }
  929. else if (i == 2)
  930. {
  931. this._mkDiv(cxTemp+ox+wod, cyTemp, 1, ((oy<<1)+hod)/2);
  932. }
  933. else if (i == 3)
  934. {
  935. this._mkDiv(cxTemp-x, cyTemp, 1, ((oy<<1)+hod)/2);
  936. }
  937. ox = x;
  938. oy = pxt[j];
  939. }
  940. }
  941. if (i == 0)
  942. {
  943. this._mkDiv(cxTemp-a, cyTemp-oy, 1, ((oy<<1)+hod)/2);
  944. }
  945. else if (i == 1)
  946. {
  947. this._mkDiv(cxTemp+ox+wod, cyTemp-oy, 1, ((oy<<1)+hod)/2);
  948. }
  949. else if (i == 2)
  950. {
  951. this._mkDiv(cxTemp+ox+wod, cyTemp, 1, ((oy<<1)+hod)/2);
  952. }
  953. else if (i == 3)
  954. {
  955. this._mkDiv(cxTemp-a, cyTemp, 1, ((oy<<1)+hod)/2);
  956. }
  957. }
  958. }
  959. };
  960. function _mkRoundrectDott(left, top, width, height, ellipsewidth, ellipseheight)
  961. {
  962. if (ellipsewidth >= width)
  963. {
  964. ellipsewidth = width;
  965. }
  966. else
  967. {
  968. this.drawLine(ellipsewidth/2, 0, width-(ellipsewidth/2)-1, 0);
  969. this.drawLine(ellipsewidth/2, height-1, width-(ellipsewidth/2)-1, height-1);
  970. }
  971. if (ellipseheight >= height)
  972. {
  973. ellipseheight = height;
  974. }
  975. else
  976. {
  977. this.drawLine(width-1, ellipseheight/2, width-1, height-(ellipseheight/2)-1);
  978. this.drawLine(0, ellipseheight/2, 0, height-(ellipseheight/2)-1);
  979. }
  980. var a = (++ellipsewidth)>>1, b = (++ellipseheight)>>1,
  981. wod = ellipsewidth&1, hod = ellipseheight&1, hodu = hod^1;
  982. for (var i = 0; i < 4 ; i++)
  983. {
  984. var cx = left+a, cy = top+b,
  985. x = 0, y = b,
  986. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  987. st = (aa2>>1)*(1-(b<<1)) + bb2,
  988. tt = (bb2>>1) - aa2*((b<<1)-1),
  989. drw = true;
  990. while(y > 0)
  991. {
  992. if(st < 0)
  993. {
  994. st += bb2*((x<<1)+3);
  995. tt += bb4*(++x);
  996. }
  997. else if(tt < 0)
  998. {
  999. st += bb2*((x<<1)+3) - aa4*(y-1);
  1000. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  1001. }
  1002. else
  1003. {
  1004. tt -= aa2*((y<<1)-3);
  1005. st -= aa4*(--y);
  1006. }
  1007. var cxTemp, cyTemp;
  1008. if (i == 0)
  1009. {
  1010. cxTemp = cx;
  1011. cyTemp = cy;
  1012. }
  1013. else if (i == 1)
  1014. {
  1015. cxTemp = cx+width-ellipsewidth;
  1016. cyTemp = cy;
  1017. }
  1018. else if (i == 2)
  1019. {
  1020. cxTemp = cx+width-ellipsewidth;
  1021. cyTemp = cy+height-ellipseheight;
  1022. }
  1023. else if (i == 3)
  1024. {
  1025. cxTemp = cx;
  1026. cyTemp = cy+height-ellipseheight;
  1027. }
  1028. if(drw && y >= hodu)
  1029. {
  1030. this._mkRoundrectQds(cxTemp, cyTemp, x, y, 1, 1, wod, hod, i);
  1031. }
  1032. drw = !drw;
  1033. }
  1034. }
  1035. };
  1036. function jsgFont()
  1037. {
  1038. this.PLAIN = 'font-weight:normal;';
  1039. this.BOLD = 'font-weight:bold;';
  1040. this.ITALIC = 'font-style:italic;';
  1041. this.ITALIC_BOLD = this.ITALIC + this.BOLD;
  1042. this.BOLD_ITALIC = this.ITALIC_BOLD;
  1043. };
  1044. var Font = new jsgFont();
  1045. function jsgStroke()
  1046. {
  1047. this.DOTTED = -1;
  1048. };
  1049. var Stroke = new jsgStroke();
  1050. function jsGraphics(cnv, wnd)
  1051. {
  1052. this.setColor = function(x)
  1053. {
  1054. this.color = x.toLowerCase();
  1055. };
  1056. this.setStroke = function(x)
  1057. {
  1058. this.stroke = x;
  1059. if(!(x+1))
  1060. {
  1061. this.drawLine = _mkLinDott;
  1062. this._mkOv = _mkOvDott;
  1063. this.drawRect = _mkRectDott;
  1064. this.drawRoundrect = _mkRoundrectDott;
  1065. }
  1066. else if(x-1 > 0)
  1067. {
  1068. this.drawLine = _mkLin2D;
  1069. this._mkOv = _mkOv2D;
  1070. this.drawRect = _mkRect;
  1071. this.drawRoundrect = _mkRoundrect2D;
  1072. }
  1073. else
  1074. {
  1075. this.drawLine = _mkLin;
  1076. this._mkOv = _mkOv;
  1077. this.drawRect = _mkRect;
  1078. this.drawRoundrect = _mkRoundrect;
  1079. }
  1080. };
  1081. this.setPrintable = function(arg)
  1082. {
  1083. this.printable = arg;
  1084. if(jg_fast)
  1085. {
  1086. this._mkDiv = _mkDivIe;
  1087. this._htmRpc = arg? _htmPrtRpc : _htmRpc;
  1088. }
  1089. else
  1090. {
  1091. this._mkDiv = arg? _mkDivPrt : _mkDiv;
  1092. }
  1093. };
  1094. this.setFont = function(fam, sz, sty)
  1095. {
  1096. this.ftFam = fam;
  1097. this.ftSz = sz;
  1098. this.ftSty = sty || Font.PLAIN;
  1099. };
  1100. this.drawPolyline = this.drawPolyLine = function(x, y)
  1101. {
  1102. for (var i=x.length - 1; i;)
  1103. {--i;
  1104. this.drawLine(x[i], y[i], x[i+1], y[i+1]);
  1105. }
  1106. };
  1107. this.fillRect = function(x, y, w, h)
  1108. {
  1109. this._mkDiv(x, y, w, h);
  1110. };
  1111. this.drawPolygon = function(x, y)
  1112. {
  1113. this.drawPolyline(x, y);
  1114. this.drawLine(x[x.length-1], y[x.length-1], x[0], y[0]);
  1115. };
  1116. this.drawEllipse = this.drawOval = function(x, y, w, h)
  1117. {
  1118. this._mkOv(x, y, w, h);
  1119. };
  1120. this.fillEllipse = this.fillOval = function(left, top, w, h)
  1121. {
  1122. var a = w>>1, b = h>>1,
  1123. wod = w&1, hod = h&1,
  1124. cx = left+a, cy = top+b,
  1125. x = 0, y = b, oy = b,
  1126. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  1127. st = (aa2>>1)*(1-(b<<1)) + bb2,
  1128. tt = (bb2>>1) - aa2*((b<<1)-1),
  1129. xl, dw, dh;
  1130. if(w) while(y > 0)
  1131. {
  1132. if(st < 0)
  1133. {
  1134. st += bb2*((x<<1)+3);
  1135. tt += bb4*(++x);
  1136. }
  1137. else if(tt < 0)
  1138. {
  1139. st += bb2*((x<<1)+3) - aa4*(y-1);
  1140. xl = cx-x;
  1141. dw = (x<<1)+wod;
  1142. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  1143. dh = oy-y;
  1144. this._mkDiv(xl, cy-oy, dw, dh);
  1145. this._mkDiv(xl, cy+y+hod, dw, dh);
  1146. oy = y;
  1147. }
  1148. else
  1149. {
  1150. tt -= aa2*((y<<1)-3);
  1151. st -= aa4*(--y);
  1152. }
  1153. }
  1154. this._mkDiv(cx-a, cy-oy, w, (oy<<1)+hod);
  1155. };
  1156. this.fillArc = function(iL, iT, iW, iH, fAngA, fAngZ)
  1157. {
  1158. var a = iW>>1, b = iH>>1,
  1159. iOdds = (iW&1) | ((iH&1) << 16),
  1160. cx = iL+a, cy = iT+b,
  1161. x = 0, y = b, ox = x, oy = y,
  1162. aa2 = (a*a)<<1, aa4 = aa2<<1, bb2 = (b*b)<<1, bb4 = bb2<<1,
  1163. st = (aa2>>1)*(1-(b<<1)) + bb2,
  1164. tt = (bb2>>1) - aa2*((b<<1)-1),
  1165. // Vars for radial boundary lines
  1166. xEndA, yEndA, xEndZ, yEndZ,
  1167. iSects = (1 << (Math.floor((fAngA %= 360.0)/180.0) << 3))
  1168. | (2 << (Math.floor((fAngZ %= 360.0)/180.0) << 3))
  1169. | ((fAngA >= fAngZ) << 16),
  1170. aBndA = new Array(b+1), aBndZ = new Array(b+1);
  1171. // Set up radial boundary lines
  1172. fAngA *= Math.PI/180.0;
  1173. fAngZ *= Math.PI/180.0;
  1174. xEndA = cx+Math.round(a*Math.cos(fAngA));
  1175. yEndA = cy+Math.round(-b*Math.sin(fAngA));
  1176. _mkLinVirt(aBndA, cx, cy, xEndA, yEndA);
  1177. xEndZ = cx+Math.round(a*Math.cos(fAngZ));
  1178. yEndZ = cy+Math.round(-b*Math.sin(fAngZ));
  1179. _mkLinVirt(aBndZ, cx, cy, xEndZ, yEndZ);
  1180. while(y > 0)
  1181. {
  1182. if(st < 0) // Advance x
  1183. {
  1184. st += bb2*((x<<1)+3);
  1185. tt += bb4*(++x);
  1186. }
  1187. else if(tt < 0) // Advance x and y
  1188. {
  1189. st += bb2*((x<<1)+3) - aa4*(y-1);
  1190. ox = x;
  1191. tt += bb4*(++x) - aa2*(((y--)<<1)-3);
  1192. this._mkArcDiv(ox, y, oy, cx, cy, iOdds, aBndA, aBndZ, iSects);
  1193. oy = y;
  1194. }
  1195. else // Advance y
  1196. {
  1197. tt -= aa2*((y<<1)-3);
  1198. st -= aa4*(--y);
  1199. if(y && (aBndA[y] != aBndA[y-1] || aBndZ[y] != aBndZ[y-1]))
  1200. {
  1201. this._mkArcDiv(x, y, oy, cx, cy, iOdds, aBndA, aBndZ, iSects);
  1202. ox = x;
  1203. oy = y;
  1204. }
  1205. }
  1206. }
  1207. this._mkArcDiv(x, 0, oy, cx, cy, iOdds, aBndA, aBndZ, iSects);
  1208. if(iOdds >> 16) // Odd height
  1209. {
  1210. if(iSects >> 16) // Start-angle > end-angle
  1211. {
  1212. var xl = (yEndA <= cy || yEndZ > cy)? (cx - x) : cx;
  1213. this._mkDiv(xl, cy, x + cx - xl + (iOdds & 0xffff), 1);
  1214. }
  1215. else if((iSects & 0x01) && yEndZ > cy)
  1216. this._mkDiv(cx - x, cy, x, 1);
  1217. }
  1218. };
  1219. /* fillPolygon method, implemented by Matthieu Haller.
  1220. This javascript function is an adaptation of the gdImageFilledPolygon for Walter Zorn lib.
  1221. C source of GD 1.8.4 found at http://www.boutell.com/gd/
  1222. THANKS to Kirsten Schulz for the polygon fixes!
  1223. The intersection finding technique of this code could be improved
  1224. by remembering the previous intertersection, and by using the slope.
  1225. That could help to adjust intersections to produce a nice
  1226. interior_extrema. */
  1227. this.fillPolygon = function(array_x, array_y)
  1228. {
  1229. var i;
  1230. var y;
  1231. var miny, maxy;
  1232. var x1, y1;
  1233. var x2, y2;
  1234. var ind1, ind2;
  1235. var ints;
  1236. var n = array_x.length;
  1237. if(!n) return;
  1238. miny = array_y[0];
  1239. maxy = array_y[0];
  1240. for(i = 1; i < n; i++)
  1241. {
  1242. if(array_y[i] < miny)
  1243. miny = array_y[i];
  1244. if(array_y[i] > maxy)
  1245. maxy = array_y[i];
  1246. }
  1247. for(y = miny; y <= maxy; y++)
  1248. {
  1249. var polyInts = new Array();
  1250. ints = 0;
  1251. for(i = 0; i < n; i++)
  1252. {
  1253. if(!i)
  1254. {
  1255. ind1 = n-1;
  1256. ind2 = 0;
  1257. }
  1258. else
  1259. {
  1260. ind1 = i-1;
  1261. ind2 = i;
  1262. }
  1263. y1 = array_y[ind1];
  1264. y2 = array_y[ind2];
  1265. if(y1 < y2)
  1266. {
  1267. x1 = array_x[ind1];
  1268. x2 = array_x[ind2];
  1269. }
  1270. else if(y1 > y2)
  1271. {
  1272. y2 = array_y[ind1];
  1273. y1 = array_y[ind2];
  1274. x2 = array_x[ind1];
  1275. x1 = array_x[ind2];
  1276. }
  1277. else continue;
  1278. // Modified 11. 2. 2004 Walter Zorn
  1279. if((y >= y1) && (y < y2))
  1280. {
  1281. polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1);
  1282. }
  1283. else if((y == maxy) && (y > y1) && (y <= y2))
  1284. {
  1285. polyInts[ints++] = Math.round((y-y1) * (x2-x1) / (y2-y1) + x1);
  1286. }
  1287. }
  1288. polyInts.sort(_CompInt);
  1289. for(i = 0; i < ints; i+=2)
  1290. {
  1291. this._mkDiv(polyInts[i], y, polyInts[i+1]-polyInts[i]+1, 1);
  1292. }
  1293. }
  1294. };
  1295. this.drawString = function(txt, x, y)
  1296. {
  1297. this.htm += '<div style="position:absolute;white-space:nowrap;'+
  1298. 'left:' + x + 'px;'+
  1299. 'top:' + y + 'px;'+
  1300. 'font-family:' + this.ftFam + ';'+
  1301. 'font-size:' + this.ftSz + ';'+
  1302. 'color:' + this.color + ';' + this.ftSty + '">'+
  1303. txt +
  1304. '<\/div>';
  1305. };
  1306. /* drawStringRect() added by Rick Blommers.
  1307. Allows to specify the size of the text rectangle and to align the
  1308. text both horizontally (e.g. right) and vertically within that rectangle */
  1309. this.drawStringRect = function(txt, x, y, width, halign)
  1310. {
  1311. this.htm += '<div style="position:absolute;overflow:hidden;'+
  1312. 'left:' + x + 'px;'+
  1313. 'top:' + y + 'px;'+
  1314. 'width:'+width +'px;'+
  1315. 'text-align:'+halign+';'+
  1316. 'font-family:' + this.ftFam + ';'+
  1317. 'font-size:' + this.ftSz + ';'+
  1318. 'color:' + this.color + ';' + this.ftSty + '">'+
  1319. txt +
  1320. '<\/div>';
  1321. };
  1322. this.drawImage = function(imgSrc, x, y, w, h, a)
  1323. {
  1324. this.htm += '<div style="position:absolute;'+
  1325. 'left:' + x + 'px;'+
  1326. 'top:' + y + 'px;'+
  1327. // w (width) and h (height) arguments are now optional.
  1328. // Added by Mahmut Keygubatli, 14.1.2008
  1329. (w? ('width:' + w + 'px;') : '') +
  1330. (h? ('height:' + h + 'px;'):'')+'">'+
  1331. '<img src="' + imgSrc +'"'+ (w ? (' width="' + w + '"'):'')+ (h ? (' height="' + h + '"'):'') + (a? (' '+a) : '') + '>'+
  1332. '<\/div>';
  1333. };
  1334. this.clear = function()
  1335. {
  1336. this.htm = "";
  1337. if(this.cnv) this.cnv.innerHTML = "";
  1338. };
  1339. this._mkOvQds = function(cx, cy, x, y, w, h, wod, hod)
  1340. {
  1341. var xl = cx - x, xr = cx + x + wod - w, yt = cy - y, yb = cy + y + hod - h;
  1342. if(xr > xl+w)
  1343. {
  1344. this._mkDiv(xr, yt, w, h);
  1345. this._mkDiv(xr, yb, w, h);
  1346. }
  1347. else
  1348. {
  1349. w = xr - xl + w;
  1350. }
  1351. this._mkDiv(xl, yt, w, h);
  1352. this._mkDiv(xl, yb, w, h);
  1353. };
  1354. this._mkRoundrectQds = function(cx, cy, x, y, w, h, wod, hod, position)
  1355. {
  1356. var xl = cx - x, xr = cx + x + wod - w, yt = cy - y, yb = cy + y + hod - h;
  1357. if (position == 0) this._mkDiv(xl, yt, w, h);
  1358. if (position == 1) this._mkDiv(xr, yt, w, h);
  1359. if (position == 2) this._mkDiv(xr, yb, w, h);
  1360. if (position == 3) this._mkDiv(xl, yb, w, h);
  1361. };
  1362. this._mkArcDiv = function(x, y, oy, cx, cy, iOdds, aBndA, aBndZ, iSects)
  1363. {
  1364. var xrDef = cx + x + (iOdds & 0xffff), y2, h = oy - y, xl, xr, w;
  1365. if(!h) h = 1;
  1366. x = cx - x;
  1367. if(iSects & 0xff0000) // Start-angle > end-angle
  1368. {
  1369. y2 = cy - y - h;
  1370. if(iSects & 0x00ff)
  1371. {
  1372. if(iSects & 0x02)
  1373. {
  1374. xl = Math.max(x, aBndZ[y]);
  1375. w = xrDef - xl;
  1376. if(w > 0) this._mkDiv(xl, y2, w, h);
  1377. }
  1378. if(iSects & 0x01)
  1379. {
  1380. xr = Math.min(xrDef, aBndA[y]);
  1381. w = xr - x;
  1382. if(w > 0) this._mkDiv(x, y2, w, h);
  1383. }
  1384. }
  1385. else
  1386. {
  1387. this._mkDiv(x, y2, xrDef - x, h);
  1388. }
  1389. y2 = cy + y + (iOdds >> 16);
  1390. if(iSects & 0xff00)
  1391. {
  1392. if(iSects & 0x0100)
  1393. {
  1394. xl = Math.max(x, aBndA[y]);
  1395. w = xrDef - xl;
  1396. if(w > 0) this._mkDiv(xl, y2, w, h);
  1397. }
  1398. if(iSects & 0x0200)
  1399. {
  1400. xr = Math.min(xrDef, aBndZ[y]);
  1401. w = xr - x;
  1402. if(w > 0) this._mkDiv(x, y2, w, h);
  1403. }
  1404. }
  1405. else
  1406. {
  1407. this._mkDiv(x, y2, xrDef - x, h);
  1408. }
  1409. }
  1410. else
  1411. {
  1412. if(iSects & 0x00ff)
  1413. {
  1414. if(iSects & 0x02)
  1415. {
  1416. xl = Math.max(x, aBndZ[y]);
  1417. }
  1418. else
  1419. {
  1420. xl = x;
  1421. }
  1422. if(iSects & 0x01)
  1423. {
  1424. xr = Math.min(xrDef, aBndA[y]);
  1425. }
  1426. else
  1427. {
  1428. xr = xrDef;
  1429. }
  1430. y2 = cy - y - h;
  1431. w = xr - xl;
  1432. if(w > 0)
  1433. {
  1434. this._mkDiv(xl, y2, w, h);
  1435. }
  1436. }
  1437. if(iSects & 0xff00)
  1438. {
  1439. if(iSects & 0x0100)
  1440. {
  1441. xl = Math.max(x, aBndA[y]);
  1442. }
  1443. else
  1444. {
  1445. xl = x;
  1446. }
  1447. if(iSects & 0x0200)
  1448. {
  1449. xr = Math.min(xrDef, aBndZ[y]);
  1450. }
  1451. else
  1452. {
  1453. xr = xrDef;
  1454. }
  1455. y2 = cy + y + (iOdds >> 16);
  1456. w = xr - xl;
  1457. if(w > 0)
  1458. {
  1459. this._mkDiv(xl, y2, w, h);
  1460. }
  1461. }
  1462. }
  1463. };
  1464. this.fillRoundrect = function(left, top, width, height, ellipsewidth, ellipseheight)
  1465. {
  1466. if (ellipsewidth >= width)
  1467. {
  1468. ellipsewidth = width;
  1469. }
  1470. else
  1471. {
  1472. this._mkDiv(0+(ellipsewidth/2), 0, width-ellipsewidth, height);
  1473. }
  1474. if (ellipseheight >= height)
  1475. {
  1476. ellipseheight = height;
  1477. }
  1478. else
  1479. {
  1480. this._mkDiv(0, 0+(ellipseheight/2), Math.round(ellipsewidth/2), height-ellipseheight);
  1481. this._mkDiv(width-(ellipsewidth/2), 0+(ellipseheight/2), Math.round(ellipsewidth/2), height-ellipseheight);
  1482. }
  1483. this.fillEllipse(0,0,ellipsewidth,ellipseheight);
  1484. this.fillEllipse(width-ellipsewidth,0,ellipsewidth,ellipseheight);
  1485. this.fillEllipse(width-ellipsewidth,height-ellipseheight,ellipsewidth,ellipseheight);
  1486. this.fillEllipse(0,height-ellipseheight,ellipsewidth,ellipseheight);
  1487. };
  1488. this.setStroke(1);
  1489. this.setFont("verdana,geneva,helvetica,sans-serif", "12px", Font.PLAIN);
  1490. this.color = "#000000";
  1491. this.htm = "";
  1492. this.wnd = wnd || window;
  1493. if(!jg_ok) _chkDHTM(this.wnd);
  1494. if(jg_ok)
  1495. {
  1496. if(cnv)
  1497. {
  1498. if(typeof(cnv) == "string")
  1499. {
  1500. this.cont = document.all? (this.wnd.document.all[cnv] || null)
  1501. : document.getElementById? (this.wnd.document.getElementById(cnv) || null) : null;
  1502. }
  1503. else if(cnv == window.document)
  1504. {
  1505. this.cont = document.getElementsByTagName("body")[0];
  1506. }
  1507. // If cnv is a direct reference to a canvas DOM node
  1508. // (option suggested by Andreas Luleich)
  1509. else
  1510. {
  1511. this.cont = cnv;
  1512. }
  1513. // Create new canvas inside container DIV. Thus the drawing and clearing
  1514. // methods won't interfere with the container's inner html.
  1515. // Solution suggested by Vladimir.
  1516. this.cnv = this.wnd.document.createElement("div");
  1517. this.cnv.style.fontSize=0;
  1518. this.cont.appendChild(this.cnv);
  1519. this.paint = jg_dom? _pntCnvDom : _pntCnvIe;
  1520. }
  1521. else
  1522. {
  1523. this.paint = _pntDoc;
  1524. }
  1525. }
  1526. else
  1527. {
  1528. this.paint = _pntN;
  1529. }
  1530. this.setPrintable(false);
  1531. };
  1532. function _mkLinVirt(aLin, x1, y1, x2, y2)
  1533. {
  1534. var dx = Math.abs(x2-x1), dy = Math.abs(y2-y1),
  1535. x = x1, y = y1,
  1536. xIncr = (x1 > x2)? -1 : 1,
  1537. yIncr = (y1 > y2)? -1 : 1,
  1538. p,
  1539. i = 0;
  1540. if(dx >= dy)
  1541. {
  1542. var pr = dy<<1,
  1543. pru = pr - (dx<<1);
  1544. p = pr-dx;
  1545. while(dx > 0)
  1546. {--dx;
  1547. if(p > 0) // Increment y
  1548. {
  1549. aLin[i++] = x;
  1550. y += yIncr;
  1551. p += pru;
  1552. }
  1553. else
  1554. {
  1555. p += pr;
  1556. }
  1557. x += xIncr;
  1558. }
  1559. }
  1560. else
  1561. {
  1562. var pr = dx<<1,
  1563. pru = pr - (dy<<1);
  1564. p = pr-dy;
  1565. while(dy > 0)
  1566. {--dy;
  1567. y += yIncr;
  1568. aLin[i++] = x;
  1569. if(p > 0) // Increment x
  1570. {
  1571. x += xIncr;
  1572. p += pru;
  1573. }
  1574. else
  1575. {
  1576. p += pr;
  1577. }
  1578. }
  1579. }
  1580. for(var len = aLin.length, i = len-i; i;)
  1581. {
  1582. aLin[len-(i--)] = x;
  1583. }
  1584. };
  1585. function _CompInt(x, y)
  1586. {
  1587. return(x - y);
  1588. };