You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.8 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Transform Testing</title>
  6. <link rel="stylesheet" href="../css/style.css">
  7. <script type="text/javascript" src="../../dist/paper-full.js"></script>
  8. <script type="text/paperscript" canvas="canvas">
  9. // Import Inkscape-style SVG, preserving pivots
  10. var svg = project.importSVG(document.getElementById('svg'), {
  11. onImport: function(node, item) {
  12. var prefix = 'inkscape:transform-center-';
  13. var x = node.getAttribute(prefix + 'x');
  14. var y = node.getAttribute(prefix + 'y');
  15. if (x != null && y != null) {
  16. item.pivot = new Point(+x, +y);
  17. }
  18. }
  19. });
  20. // Illustrate pivot using a simple animation
  21. var rect = svg.children.rectangle;
  22. // Show the pivot
  23. new Path.Circle({
  24. center: rect.localToGlobal(rect.pivot),
  25. radius: 4,
  26. strokeColor: 'black'
  27. });
  28. rect.onFrame = function() {
  29. rect.rotate(1);
  30. }
  31. // And export again, preserving Inkscape pivots
  32. console.log(rect.exportSVG({
  33. onExport: function(item, node) {
  34. var prefix = 'inkscape:transform-center-';
  35. if (item.pivot) {
  36. node.setAttribute(prefix + 'x', item.pivot.x);
  37. node.setAttribute(prefix + 'y', item.pivot.y);
  38. }
  39. }
  40. }))
  41. </script>
  42. </head>
  43. <body>
  44. <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500" height="500" id="svg">
  45. <rect id="rectangle" x="50" y="200" width="200" height="100" fill="red" inkscape:transform-center-x="100" inkscape:transform-center-y="0" />
  46. </svg>
  47. <canvas id="canvas" width="500" height="500"></canvas>
  48. </body>
  49. </html>