| 2410 | |
| 2411 | var __cnv, __ct; |
| 2412 | function pathToContext(path, ctx) { |
| 2413 | var c = 0, cmds = path["cmds"], crds = path["crds"]; |
| 2414 | |
| 2415 | //ctx.translate(3500,500); ctx.rotate(0.25); ctx.scale(1,-1); |
| 2416 | |
| 2417 | for (var j = 0; j < cmds.length; j++) { |
| 2418 | var cmd = cmds[j]; |
| 2419 | if (cmd == "M") { |
| 2420 | ctx.moveTo(crds[c], crds[c + 1]); |
| 2421 | c += 2; |
| 2422 | } |
| 2423 | else if (cmd == "L") { |
| 2424 | ctx.lineTo(crds[c], crds[c + 1]); |
| 2425 | c += 2; |
| 2426 | } |
| 2427 | else if (cmd == "C") { |
| 2428 | ctx.bezierCurveTo(crds[c], crds[c + 1], crds[c + 2], crds[c + 3], crds[c + 4], crds[c + 5]); |
| 2429 | c += 6; |
| 2430 | } |
| 2431 | else if (cmd == "Q") { |
| 2432 | ctx.quadraticCurveTo(crds[c], crds[c + 1], crds[c + 2], crds[c + 3]); |
| 2433 | c += 4; |
| 2434 | } |
| 2435 | else if (cmd[0] == "d") { |
| 2436 | var upng = window["UPNG"]; |
| 2437 | var x0 = crds[c], y0 = crds[c + 1], x1 = crds[c + 2], y1 = crds[c + 3], x2 = crds[c + 4], y2 = crds[c + 5], x3 = crds[c + 6], y3 = crds[c + 7]; c += 8; |
| 2438 | //y0+=400; y1+=400; y1+=600; |
| 2439 | if (upng == null) { |
| 2440 | ctx.moveTo(x0, y0); ctx.lineTo(x1, y1); ctx.lineTo(x2, y2); ctx.lineTo(x3, y3); ctx.closePath(); |
| 2441 | continue; |
| 2442 | } |
| 2443 | var dx0 = (x1 - x0), dy0 = (y1 - y0), dx1 = (x3 - x0), dy1 = (y3 - y0); |
| 2444 | var sbmp = atob(cmd.slice(22)); |
| 2445 | var bmp = new Uint8Array(sbmp.length); |
| 2446 | for (var i = 0; i < sbmp.length; i++) bmp[i] = sbmp.charCodeAt(i); |
| 2447 | |
| 2448 | var img = upng["decode"](bmp.buffer), w = img["width"], h = img["height"]; //console.log(img); |
| 2449 | |
| 2450 | var nbmp = new Uint8Array(upng["toRGBA8"](img)[0]); |
| 2451 | var tr = ctx["getTransform"](); |
| 2452 | var scl = Math.sqrt(Math.abs(tr["a"] * tr["d"] - tr["b"] * tr["c"])) * Math.sqrt(dx1 * dx1 + dy1 * dy1) / h; |
| 2453 | while (scl < 0.5) { |
| 2454 | var nd = mipmapB(nbmp, w, h); |
| 2455 | nbmp = nd.buff; w = nd.w; h = nd.h; scl *= 2; |
| 2456 | } |
| 2457 | |
| 2458 | if (__cnv == null) { __cnv = document.createElement("canvas"); __ct = __cnv.getContext("2d"); } |
| 2459 | if (__cnv.width != w || __cnv.height != h) { __cnv.width = w; __cnv.height = h; } |
| 2460 | |
| 2461 | __ct.putImageData(new ImageData(new Uint8ClampedArray(nbmp.buffer), w, h), 0, 0); |
| 2462 | ctx.save(); |
| 2463 | ctx.transform(dx0, dy0, dx1, dy1, x0, y0); |
| 2464 | ctx.scale(1 / w, 1 / h); |
| 2465 | ctx.drawImage(__cnv, 0, 0); //*/ |
| 2466 | ctx.restore(); |
| 2467 | } |
| 2468 | else if (cmd.charAt(0) == "#" || cmd.charAt(0) == "r") { |
| 2469 | ctx.beginPath(); |