8efeb1c0c7d5b8edd3afb4e0602b9c95102c90a6c74d88247478378e3809282f482a0333025aeb1d83fc2e74d3ad0668e18cf7c276186cdd0c356aedd2966b 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <!DOCTYPE html>
  2. <meta http-equiv="content-type" content="text/html; charset=UTF8">
  3. <title>saveSvgAsPng</title>
  4. <link href='https://fonts.googleapis.com/css?family=Open+Sans:400italic,400,300,600' rel='stylesheet' type='text/css' />
  5. <link rel=stylesheet href=bootstrap.min.css />
  6. <style>
  7. @font-face {
  8. font-family: 'Stalemate';
  9. font-style: normal;
  10. font-weight: 400;
  11. src: url(stalemate.ttf) format('truetype');
  12. }
  13. input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button {
  14. padding: 15px;
  15. }
  16. h2, h3 {
  17. margin-top: 0;
  18. }
  19. h3 .btn {
  20. margin-top: -8px;
  21. }
  22. ul {
  23. list-style-type: none;
  24. padding: 0;
  25. }
  26. ul li {
  27. padding: 30px 20px;
  28. border-bottom: 1px dashed gray;
  29. }
  30. svg, img {
  31. border: 1px solid lightgray;
  32. }
  33. textarea {
  34. width: 100%;
  35. height: 100px;
  36. }
  37. button {
  38. background-color: lightgray;
  39. }
  40. .error {
  41. border: 1px solid red;
  42. border-radius: 10px;
  43. color: red;
  44. padding: 8px 10px;
  45. }
  46. #sized-with-css svg {
  47. width: 200px;
  48. height: 200px;
  49. }
  50. #selectors-prefixed svg rect {
  51. fill: blue;
  52. }
  53. rect.css-styled {
  54. fill: green !important;
  55. }
  56. #selectors-prefixed rect.css-styled {
  57. fill: green !important;
  58. }
  59. /* Invalid selectors */
  60. [ng\:cloak] {
  61. display: block;
  62. }
  63. ng\:form {
  64. display: block;
  65. }
  66. </style>
  67. <script type=text/template id=inline-template>
  68. <div class=row>
  69. <div class=col-md-6>
  70. <h2></h2>
  71. </div>
  72. <div class=col-md-6>
  73. <h3>Preview <button class="save btn">Save as PNG</button></h3>
  74. </div>
  75. </div>
  76. <div class=row>
  77. <div class="canvas col-md-6">
  78. </div>
  79. <div class=col-md-6>
  80. <div class=preview></div>
  81. </div>
  82. </div>
  83. </script>
  84. <div class=container>
  85. <!-- Needed to trigger correct custom font rasterization in Chrome -->
  86. <span style='font-family: "Stalemate";color:white'>A</span>
  87. <h1>saveSvgAsPng</h1>
  88. <p>This page tests various features of saveSvgAsPng.</p>
  89. <p>You can test your own SVG code in the Sandbox. If something doesn't work as expected, you can <a href="https://github.com/exupero/saveSvgAsPng/issues">file an issue on GitHub</a>.</p>
  90. <ul>
  91. <li id=sandbox>
  92. <h2>Sandbox</h2>
  93. <p>Paste you SVG below to see how it renders.</p>
  94. <textarea><svg></svg></textarea>
  95. <br/>
  96. <button class="render btn">Preview</button>
  97. <div class=load-target style="margin-top:20px;"></div>
  98. <br/>
  99. <h3>Preview <button class="save btn">Save as PNG</button></h3>
  100. <span class=error style="display:none;"></span>
  101. <div class=preview></div>
  102. </li>
  103. <li id=filereader>
  104. <div class=row>
  105. <div class=col-md-6>
  106. <h2>Load from your hard drive</h2>
  107. </div>
  108. <div class=col-md-6>
  109. <h3>Preview <button class="save btn">Save as PNG</button></h3>
  110. </div>
  111. </div>
  112. <div class=row>
  113. <div class=col-md-6>
  114. <input type=file id=file name="files[]" />
  115. <div class=load-target></div>
  116. </div>
  117. <div class=col-md-6>
  118. <div class=preview>No file selected.</div>
  119. </div>
  120. </div>
  121. </li>
  122. <li id=inline>
  123. <svg width=200 height=200>
  124. <rect x=50 y=50 width=100 height=100></rect>
  125. </svg>
  126. </li>
  127. <li id=embedded-png>
  128. <svg width=200 height=200>
  129. <image xlink:href=image.png x=50 y=50 width=100 height=100></image>
  130. </svg>
  131. </li>
  132. <li id=embedded-svg>
  133. <svg width=200 height=200>
  134. <image xlink:href=test.svg x=50 y=50 width=100 height=100></image>
  135. </svg>
  136. </li>
  137. <li id=sized-with-pixels>
  138. <svg width="200px" height="200px">
  139. <rect x=50 y=50 width=100 height=100></rect>
  140. </svg>
  141. </li>
  142. <li id=sized-with-style>
  143. <svg style="width:200px;height:200px;">
  144. <rect x=50 y=50 width=100 height=100></rect>
  145. </svg>
  146. </li>
  147. <li id=sized-with-css>
  148. <svg>
  149. <rect x=50 y=50 width=100 height=100></rect>
  150. </svg>
  151. </li>
  152. <li id=scaling>
  153. <svg width=200 height=200>
  154. <rect width=100 height=100></rect>
  155. <image xlink:href=image.png x=50 y=50 width=100 height=100></image>
  156. </svg>
  157. </li>
  158. <li id=selectors-prefixed>
  159. <svg width=200 height=200>
  160. <rect x=0 y=50 width=100 height=100></rect>
  161. <rect class=css-styled x=100 y=50 width=100 height=100></rect>
  162. </svg>
  163. </li>
  164. <li id=modified-style>
  165. <svg width=200 height=200>
  166. <rect x=0 y=50 width=100 height=100></rect>
  167. <rect class=css-styled x=100 y=50 width=100 height=100></rect>
  168. </svg>
  169. </li>
  170. <li id=modified-css>
  171. <svg width=200 height=200>
  172. <rect x=0 y=50 width=100 height=100></rect>
  173. <rect class=css-styled x=100 y=50 width=100 height=100></rect>
  174. </svg>
  175. </li>
  176. <li id=group>
  177. <svg width=200 height=200>
  178. <g id=sub-group transform="translate(40,40)">
  179. <rect x=10 y=10 width=100 height=100></rect>
  180. </g>
  181. </svg>
  182. </li>
  183. <li id=percentage-size>
  184. <svg width="100%" height="100%">
  185. <rect x=25 y=25 width=100 height=100></rect>
  186. </svg>
  187. </li>
  188. <li id=background-color>
  189. <svg width=200 height=200>
  190. <g id=sub-group transform="translate(40,40)">
  191. <rect x=10 y=10 width=100 height=100></rect>
  192. </g>
  193. </svg>
  194. </li>
  195. <li id=pan-and-zoom>
  196. <svg width=200 height=200>
  197. <g transform="scale(2)">
  198. <rect x=10 y=10 width=100 height=100></rect>
  199. </g>
  200. </svg>
  201. </li>
  202. <li id=unicode>
  203. <svg width=200 height=200>
  204. <text x=100 y=100 text-anchor=middle dy=14>ö,i,ç,ğ</text>
  205. </svg>
  206. </li>
  207. <li id=gradient>
  208. <svg width=200 height=200>
  209. <defs>
  210. <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
  211. <stop offset="0%" style="stop-color:rgb(255,0,255);stop-opacity:1" />
  212. <stop offset="100%" style="stop-color:rgb(0,255,255);stop-opacity:1" />
  213. </linearGradient>
  214. </defs>
  215. <line x2="200" y2="200" stroke="url(#grad1)" stroke-width="5px" />
  216. </svg>
  217. </li>
  218. <li id=foreign-object>
  219. <svg width=200 height=200>
  220. <foreignobject x=50 y=50 width=50 height=100>
  221. <div>Foreign Object</div>
  222. </foreignobject>
  223. </svg>
  224. </li>
  225. <li id=xmlns-override>
  226. <svg width=200 height=200>
  227. <foreignobject x=50 y=50 width=50 height=100>
  228. <div xmlns="http://www.w3.org/1999/xhtml">Foreign Object</div>
  229. </foreignobject>
  230. </svg>
  231. </li>
  232. <li id=opacity>
  233. <svg width=200 height=200>
  234. <rect x=50 y=50 width=100 height=100 fill="green"></rect>
  235. <rect x=60 y=60 width=100 height=100 fill="blue" opacity="0.5"></rect>
  236. </svg>
  237. </li>
  238. <li id=entities>
  239. <svg width=200 height=200>
  240. <text x=50 y=100>&quot;&amp;&cent;&nbsp;&pound;&raquo;&frac14;&Ccedil;</text>
  241. </svg>
  242. </li>
  243. <li id=transformed-text>
  244. <svg width=200 height=200>
  245. <text transform="translate(100,100)rotate(45)">Hello</text>
  246. </svg>
  247. </li>
  248. <li id=marker-end>
  249. <svg width=200 height=200>
  250. <defs>
  251. <marker id='head' orient="auto" markerWidth='2' markerHeight='4' refX='0.1' refY='2'>
  252. <path d='M0,0 V4 L2,2 Z' fill="red"/>
  253. </marker>
  254. </defs>
  255. <g transform="translate(50,50)">
  256. <path id='arrow-line' marker-end='url(#head)' stroke-width='5' fill='none' stroke='black' d='M0,0 C45,45 45,-45 90,0' />
  257. </g>
  258. </svg>
  259. </li>
  260. <li id=style-background>
  261. <svg width="200" height="200" style="background:green">
  262. </svg>
  263. </li>
  264. <li id=svg-in-svg>
  265. <svg width="200" height="200">
  266. <foreignObject x="50" y="50" width="50" height="100">
  267. <svg width="50" height="50">
  268. <image xlink:href=test.svg width=50 height=50></image>
  269. </svg>
  270. </foreignObject>
  271. </svg>
  272. </li>
  273. <li id=exclude-unused-css>
  274. <svg width="200" height="200">
  275. <rect x=50 y=50 width=100 height=100 fill="green"></rect>
  276. </svg>
  277. </li>
  278. <li id=custom-font>
  279. <svg width=200 height=200>
  280. <text x=100 y=100 text-anchor=middle dy=14 style="font-family:'Stalemate';font-size:36pt;">Custom Fonts</text>
  281. </svg>
  282. <div style="color:red;">
  283. <p>
  284. Custom fonts are supported but in a very rudimentary way. Note: if you don't see the demo working,
  285. click "Save as PNG" - it should work.
  286. </p>
  287. <p>Make sure that the custom font is applied to a non-svg element first. This will help browser to rasterize SVG correctly onto canvas.</p>
  288. <p>@font-face declaration has to be inside document stylesheets (not in the external `link` tag)</p>
  289. <p>Only first `url()` is inlined into svg (don't have multiple urls in the font-face).</p>
  290. </div>
  291. </li>
  292. </ul>
  293. </div>
  294. <script src=https://code.jquery.com/jquery-latest.js></script>
  295. <script src=src/saveSvgAsPng.js></script>
  296. <script src=index.js></script>