prawn-svg 0.15.0.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -12
  3. data/lib/prawn/svg/calculators/aspect_ratio.rb +58 -0
  4. data/lib/prawn/svg/calculators/document_sizing.rb +75 -0
  5. data/lib/prawn/svg/calculators/pixels.rb +21 -0
  6. data/lib/prawn/svg/document.rb +16 -43
  7. data/lib/prawn/svg/element.rb +71 -18
  8. data/lib/prawn/svg/extension.rb +3 -3
  9. data/lib/prawn/svg/interface.rb +80 -19
  10. data/lib/prawn/svg/parser/image.rb +9 -62
  11. data/lib/prawn/svg/parser/path.rb +19 -1
  12. data/lib/prawn/svg/parser/text.rb +2 -0
  13. data/lib/prawn/svg/parser.rb +53 -18
  14. data/lib/prawn/svg/url_loader.rb +34 -0
  15. data/lib/prawn/svg/version.rb +1 -1
  16. data/lib/prawn-svg.rb +4 -0
  17. data/prawn-svg.gemspec +7 -4
  18. data/spec/integration_spec.rb +83 -0
  19. data/spec/prawn/svg/calculators/aspect_ratio_spec.rb +95 -0
  20. data/spec/prawn/svg/calculators/document_sizing_spec.rb +73 -0
  21. data/spec/prawn/svg/document_spec.rb +21 -17
  22. data/spec/prawn/svg/element_spec.rb +1 -1
  23. data/spec/prawn/svg/interface_spec.rb +59 -0
  24. data/spec/prawn/svg/parser/path_spec.rb +89 -0
  25. data/spec/prawn/svg/url_loader_spec.rb +46 -0
  26. data/spec/sample_images/mushroom-long.jpg +0 -0
  27. data/spec/sample_images/mushroom-wide.jpg +0 -0
  28. data/spec/sample_svg/cap_styles.svg +13 -0
  29. data/spec/sample_svg/display_none.svg +13 -0
  30. data/spec/sample_svg/gistfile1.svg +36 -0
  31. data/spec/sample_svg/hidden_paths.svg +6 -0
  32. data/spec/sample_svg/image01.svg +31 -31
  33. data/spec/sample_svg/negminy.svg +25 -0
  34. data/spec/sample_svg/path.svg +5 -0
  35. data/spec/sample_svg/pie_piece.svg +7 -0
  36. data/spec/sample_svg/viewbox.svg +4 -0
  37. data/spec/sample_svg/viewport.svg +23 -0
  38. data/spec/spec_helper.rb +7 -0
  39. metadata +81 -25
  40. data/spec/lib/path_spec.rb +0 -54
  41. data/spec/lib/svg_spec.rb +0 -47
  42. /data/spec/{lib → prawn/svg}/parser_spec.rb +0 -0
@@ -18,113 +18,113 @@
18
18
  <text y="25" font-size="12pt">wide image, aspect ratio meet</text>
19
19
 
20
20
  <rect y="50" width="100" height="100" fill="none" stroke="blue" stroke-width="2"/>
21
- <image y="50" width="100" height="100" preserveAspectRatio="xMidYMid" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
21
+ <image y="50" width="100" height="100" preserveAspectRatio="xMidYMid" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
22
22
 
23
23
  <rect y="200" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
24
- <image y="200" width="150" height="100" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
24
+ <image y="200" width="150" height="100" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
25
25
 
26
26
  <rect y="350" width="100" height="150" fill="none" stroke="blue" stroke-width="2"/>
27
- <image y="350" width="100" height="150" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
27
+ <image y="350" width="100" height="150" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
28
28
 
29
29
  <rect y="550" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
30
- <image y="550" width="150" height="100" preserveAspectRatio="xMinYMin" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
30
+ <image y="550" width="150" height="100" preserveAspectRatio="xMinYMin" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
31
31
 
32
32
  <rect y="700" width="100" height="150" fill="none" stroke="blue" stroke-width="2"/>
33
- <image y="700" width="100" height="150" preserveAspectRatio="xMinYMin" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
33
+ <image y="700" width="100" height="150" preserveAspectRatio="xMinYMin" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
34
34
 
35
35
  <rect y="900" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
36
- <image y="900" width="150" height="100" preserveAspectRatio="xMaxYMax" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
36
+ <image y="900" width="150" height="100" preserveAspectRatio="xMaxYMax" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
37
37
 
38
38
  <rect y="1050" width="100" height="150" fill="none" stroke="blue" stroke-width="2"/>
39
- <image y="1050" width="100" height="150" preserveAspectRatio="xMaxYMax" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
39
+ <image y="1050" width="100" height="150" preserveAspectRatio="xMaxYMax" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
40
40
  </g>
41
41
 
42
42
  <g transform="translate(250 0)">
43
43
  <text y="25" font-size="12pt">wide image, aspect ratio slice</text>
44
44
 
45
45
  <rect y="50" width="100" height="100" fill="none" stroke="blue" stroke-width="2"/>
46
- <image y="50" width="100" height="100" preserveAspectRatio="xMidYMid slice" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
46
+ <image y="50" width="100" height="100" preserveAspectRatio="xMidYMid slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
47
47
 
48
48
  <rect y="200" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
49
- <image y="200" width="150" height="100" preserveAspectRatio="xMidYMid slice" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
49
+ <image y="200" width="150" height="100" preserveAspectRatio="xMidYMid slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
50
50
 
51
51
  <rect y="350" width="100" height="150" fill="none" stroke="blue" stroke-width="2"/>
52
- <image y="350" width="100" height="150" preserveAspectRatio="xMidYMid slice" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
52
+ <image y="350" width="100" height="150" preserveAspectRatio="xMidYMid slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
53
53
 
54
54
  <rect y="550" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
55
- <image y="550" width="150" height="100" preserveAspectRatio="xMinYMin slice" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
55
+ <image y="550" width="150" height="100" preserveAspectRatio="xMinYMin slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
56
56
 
57
57
  <rect y="700" width="100" height="150" fill="none" stroke="blue" stroke-width="2"/>
58
- <image y="700" width="100" height="150" preserveAspectRatio="xMinYMin slice" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
58
+ <image y="700" width="100" height="150" preserveAspectRatio="xMinYMin slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
59
59
 
60
60
  <rect y="900" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
61
- <image y="900" width="150" height="100" preserveAspectRatio="xMaxYMax slice" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
61
+ <image y="900" width="150" height="100" preserveAspectRatio="xMaxYMax slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
62
62
 
63
63
  <rect y="1050" width="100" height="150" fill="none" stroke="blue" stroke-width="2"/>
64
- <image y="1050" width="100" height="150" preserveAspectRatio="xMaxYMax slice" xlink:href="http://files.myopera.com/baby2u/albums/423302/smiley-cool.jpg"></image>
64
+ <image y="1050" width="100" height="150" preserveAspectRatio="xMaxYMax slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg"></image>
65
65
  </g>
66
66
 
67
67
  <g transform="translate(450 0)">
68
68
  <text y="25" font-size="12pt">long image, aspect ratio meet</text>
69
69
 
70
70
  <rect y="50" width="100" height="100" fill="none" stroke="blue" stroke-width="2"/>
71
- <image y="50" width="100" height="100" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
71
+ <image y="50" width="100" height="100" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
72
72
 
73
73
  <rect y="200" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
74
- <image y="200" width="150" height="100" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
74
+ <image y="200" width="150" height="100" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
75
75
 
76
76
  <rect y="350" width="100" height="200" fill="none" stroke="blue" stroke-width="2"/>
77
- <image y="350" width="100" height="200" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
77
+ <image y="350" width="100" height="200" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
78
78
 
79
79
  <rect y="550" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
80
- <image y="550" width="150" height="100" preserveAspectRatio="xMinYMin" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
80
+ <image y="550" width="150" height="100" preserveAspectRatio="xMinYMin" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
81
81
 
82
82
  <rect y="700" width="100" height="200" fill="none" stroke="blue" stroke-width="2"/>
83
- <image y="700" width="100" height="200" preserveAspectRatio="xMinYMin" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
83
+ <image y="700" width="100" height="200" preserveAspectRatio="xMinYMin" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
84
84
 
85
85
  <rect y="900" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
86
- <image y="900" width="150" height="100" preserveAspectRatio="xMaxYMax" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
86
+ <image y="900" width="150" height="100" preserveAspectRatio="xMaxYMax" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
87
87
 
88
88
  <rect y="1050" width="100" height="200" fill="none" stroke="blue" stroke-width="2"/>
89
- <image y="1050" width="100" height="200" preserveAspectRatio="xMaxYMax" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
89
+ <image y="1050" width="100" height="200" preserveAspectRatio="xMaxYMax" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
90
90
  </g>
91
91
 
92
92
  <g transform="translate(650 0)">
93
93
  <text y="25" font-size="12pt">long image, aspect ratio slice</text>
94
94
 
95
95
  <rect y="50" width="100" height="100" fill="none" stroke="blue" stroke-width="2"/>
96
- <image y="50" width="100" height="100" preserveAspectRatio="xMidYMid slice" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
96
+ <image y="50" width="100" height="100" preserveAspectRatio="xMidYMid slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
97
97
 
98
98
  <rect y="200" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
99
- <image y="200" width="150" height="100" preserveAspectRatio="xMidYMid slice" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
99
+ <image y="200" width="150" height="100" preserveAspectRatio="xMidYMid slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
100
100
 
101
101
  <rect y="350" width="100" height="200" fill="none" stroke="blue" stroke-width="2"/>
102
- <image y="350" width="100" height="200" preserveAspectRatio="xMidYMid slice" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
102
+ <image y="350" width="100" height="200" preserveAspectRatio="xMidYMid slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
103
103
 
104
104
  <rect y="550" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
105
- <image y="550" width="150" height="100" preserveAspectRatio="xMinYMin slice" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
105
+ <image y="550" width="150" height="100" preserveAspectRatio="xMinYMin slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
106
106
 
107
107
  <rect y="700" width="100" height="200" fill="none" stroke="blue" stroke-width="2"/>
108
- <image y="700" width="100" height="200" preserveAspectRatio="xMinYMin slice" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
108
+ <image y="700" width="100" height="200" preserveAspectRatio="xMinYMin slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
109
109
 
110
110
  <rect y="900" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
111
- <image y="900" width="150" height="100" preserveAspectRatio="xMaxYMax slice" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
111
+ <image y="900" width="150" height="100" preserveAspectRatio="xMaxYMax slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
112
112
 
113
113
  <rect y="1050" width="100" height="200" fill="none" stroke="blue" stroke-width="2"/>
114
- <image y="1050" width="100" height="200" preserveAspectRatio="xMaxYMax slice" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
114
+ <image y="1050" width="100" height="200" preserveAspectRatio="xMaxYMax slice" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
115
115
  </g>
116
116
 
117
117
  <g transform="translate(850 0)">
118
118
  <text y="25" font-size="12pt">aspect ratio preservation disabled</text>
119
119
 
120
120
  <rect y="50" width="100" height="100" fill="none" stroke="blue" stroke-width="2"/>
121
- <image y="50" width="100" height="100" preserveAspectRatio="none" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
121
+ <image y="50" width="100" height="100" preserveAspectRatio="none" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
122
122
 
123
123
  <rect y="200" width="150" height="100" fill="none" stroke="blue" stroke-width="2"/>
124
- <image y="200" width="150" height="100" preserveAspectRatio="none" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
124
+ <image y="200" width="150" height="100" preserveAspectRatio="none" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
125
125
 
126
126
  <rect y="350" width="100" height="200" fill="none" stroke="blue" stroke-width="2"/>
127
- <image y="350" width="100" height="200" preserveAspectRatio="none" xlink:href="http://imalbum.aufeminin.com/album/D20090809/583007_KWWH1ZQ8FU5ATJXSR84C5MRBUWW33L_989174388_H143954_L.jpg"></image>
127
+ <image y="350" width="100" height="200" preserveAspectRatio="none" xlink:href="https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg"></image>
128
128
  </g>
129
129
 
130
130
  </svg>
@@ -0,0 +1,25 @@
1
+ <svg xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 -1329 4012.5722934428577 1964.1614245832113" xmlns="http://www.w3.org/2000/svg">
2
+ <defs id="MathJax_SVG_glyphs">
3
+ <path id="STIXWEBSIZE1-221A" stroke-width="10" d="M1089 1552l-562 -1847h-42l-231 751c-14 46 -30 68 -62 68c-19 0 -44 -8 -68 -27l-12 20l164 126h25l227 -737h4l500 1646h57Z"/>
4
+ <path id="STIXWEBMAINI-78" stroke-width="10" d="M243 355l12 -57c70 107 107 143 151 143c24 0 41 -15 41 -37c0 -21 -14 -36 -34 -36c-19 0 -28 17 -52 17c-18 0 -54 -44 -98 -121c0 -7 2 -21 8 -45l32 -134c7 -28 16 -41 30 -41c13 0 24 10 47 40c9 12 13 18 21 28l15 -9c-58 -90 -84 -114 -122 -114 c-32 0 -47 18 -59 68l-29 119l-88 -119c-44 -59 -64 -68 -95 -68s-50 16 -50 42c0 20 14 36 34 36c9 0 19 -4 32 -11c10 -6 20 -9 26 -9c11 0 30 19 51 49l82 116l-28 124c-14 60 -21 68 -46 68c-8 0 -20 -2 -39 -7l-18 -5l-3 16l11 4c61 22 94 29 117 29 c25 0 37 -18 51 -86Z"/>
5
+ <path id="STIXWEBMAIN-32" stroke-width="10" d="M474 137l-54 -137h-391v12l178 189c94 99 130 175 130 260c0 91 -54 141 -139 141c-72 0 -107 -32 -147 -130l-21 5c21 117 85 199 208 199c113 0 185 -77 185 -176c0 -79 -39 -154 -128 -248l-165 -176h234c42 0 63 11 96 67Z"/>
6
+ <path id="STIXWEBMAIN-2B" stroke-width="10" d="M636 220h-261v-261h-66v261h-261v66h261v261h66v-261h261v-66Z"/>
7
+ <path id="STIXWEBMAINI-79" stroke-width="10" d="M243 186l21 -110c85 141 122 213 122 257c0 14 -7 20 -26 32c-20 13 -26 23 -26 39c0 22 17 37 40 37c30 0 52 -25 52 -55c0 -57 -48 -167 -131 -305c-104 -172 -211 -287 -268 -287c-30 0 -51 17 -51 43c0 22 17 40 39 40c35 0 35 -28 61 -28c13 0 25 8 48 33 c18 19 63 78 71 91c6 12 10 24 10 35c0 40 -55 264 -82 332c-19 49 -37 64 -77 64c-11 0 -20 -1 -31 -4v17c11 2 22 4 32 6c20 4 53 10 107 18h4c15 0 68 -166 85 -255Z"/>
8
+ </defs>
9
+ <g transform="matrix(1 0 0 1 0 0)">
10
+ <rect x="0" y="-1329" width="4012" height="1964" stroke="green" fill="none" stroke-width="5" />
11
+ <g stroke="black" fill="black" stroke-width="0" transform="matrix(1 0 0 -1 0 0)">
12
+ <use href="#STIXWEBSIZE1-221A" x="0" y="-312" xlink:href="#STIXWEBSIZE1-221A"/>
13
+ <rect stroke="none" width="2950" height="60" x="1062" y="1190"/>
14
+ <g transform="translate(1062,0)">
15
+ <use href="#STIXWEBMAINI-78" xlink:href="#STIXWEBMAINI-78"/>
16
+ <use transform="scale(0.7071067811865476)" href="#STIXWEBMAIN-32" x="640" y="583" xlink:href="#STIXWEBMAIN-32"/>
17
+ <use href="#STIXWEBMAIN-2B" x="1132" y="0" xlink:href="#STIXWEBMAIN-2B"/>
18
+ <g transform="translate(2044,0)">
19
+ <use href="#STIXWEBMAINI-79" xlink:href="#STIXWEBMAINI-79"/>
20
+ <use transform="scale(0.7071067811865476)" href="#STIXWEBMAIN-32" x="634" y="583" xlink:href="#STIXWEBMAIN-32"/>
21
+ </g>
22
+ </g>
23
+ </g>
24
+ </g>
25
+ </svg>
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1100" height="400">
2
+ <rect x="100" y="100" width="900" height="300" fill="none" stroke="blue" stroke-width="2" />
3
+
4
+ <path d="M200 200 L800 300 L800 200" stroke="green" stroke-width="10" fill="red" />
5
+ </svg>
@@ -0,0 +1,7 @@
1
+ <svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" style="font-family:'lucida grande', 'lucida sans unicode', arial, helvetica, sans-serif;font-size:12px;" xmlns="http://www.w3.org/2000/svg" width="850" height="300">
2
+ <g transform="translate(10,10) scale(1 1)">
3
+ <path fill="#009ACB" d="M 414.97698492798247 39.00000234377684 A 113 113 0 1 1 311.39206002954353
4
+ 197.10426559737175 L 415 152 A 0 0 0 1 0 415 152 Z" stroke="#FFFFFF" stroke-width="1" stroke-linejoin="round"
5
+ transform="translate(0,0)"></path>
6
+ </g>
7
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="300" viewBox="-100 -100 100 100" xmlns="http://www.w3.org/2000/svg">
2
+ <rect x="-98" y="-98" width="96" height="96" fill="blue" stroke="red" />
3
+ <line x1="-1000" y1="-1000" x2="1000" y2="1000" stroke="green" />
4
+ </svg>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg width="100px" height="200px" version="1.1"
5
+ viewBox="0 0 1500 1000" preserveAspectRatio="none"
6
+ xmlns="http://www.w3.org/2000/svg">
7
+ <desc>Example ViewBox - uses the viewBox
8
+ attribute to automatically create an initial user coordinate
9
+ system which causes the graphic to scale to fit into the
10
+ viewport no matter what size the viewport is.</desc>
11
+ <!-- This rectangle goes from (0,0) to (1500,1000) in user space.
12
+ Because of the viewBox attribute above,
13
+ the rectangle will end up filling the entire area
14
+ reserved for the SVG content. -->
15
+ <rect x="0" y="0" width="1500" height="1000"
16
+ fill="yellow" stroke="blue" stroke-width="12" />
17
+ <!-- A large, red triangle -->
18
+ <path fill="red" d="M 750,100 L 250,900 L 1250,900 z"/>
19
+ <!-- A text string that spans most of the viewport -->
20
+ <text x="100" y="600" font-size="200" font-family="Verdana" >
21
+ Stretch to fit
22
+ </text>
23
+ </svg>
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,13 @@ Bundler.require(:default, :development)
6
6
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
7
 
8
8
  RSpec.configure do |config|
9
+ config.mock_with :rspec do |c|
10
+ c.syntax = [:should, :expect]
11
+ end
12
+
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = [:should, :expect]
15
+ end
9
16
  end
10
17
 
11
18
  Prawn::Svg::Font.load_external_fonts(Prawn::Document.new.font_families)
metadata CHANGED
@@ -1,70 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.8.4
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - '>='
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.8.4
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: css_parser
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: rspec
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
- - - ~>
51
+ - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: 2.14.1
53
+ version: '3.0'
34
54
  type: :development
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
- - - ~>
58
+ - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: 2.14.1
60
+ version: '3.0'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: rake
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
- - - '>='
65
+ - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '0'
67
+ version: '10.1'
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
- - - '>='
72
+ - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '0'
55
- description: SVG renderer for Prawn PDF library
74
+ version: '10.1'
75
+ description: This gem allows you to render SVG directly into a PDF using the 'prawn'
76
+ gem. Since PDF is vector-based, you'll get nice scaled graphics if you use SVG
77
+ instead of an image.
56
78
  email: roger@seriousorange.com
57
79
  executables: []
58
80
  extensions: []
59
81
  extra_rdoc_files: []
60
82
  files:
61
- - .gitignore
62
- - .rspec
83
+ - ".gitignore"
84
+ - ".rspec"
63
85
  - Gemfile
64
86
  - LICENSE
65
87
  - README.md
66
88
  - Rakefile
67
89
  - lib/prawn-svg.rb
90
+ - lib/prawn/svg/calculators/aspect_ratio.rb
91
+ - lib/prawn/svg/calculators/document_sizing.rb
92
+ - lib/prawn/svg/calculators/pixels.rb
68
93
  - lib/prawn/svg/color.rb
69
94
  - lib/prawn/svg/document.rb
70
95
  - lib/prawn/svg/element.rb
@@ -75,26 +100,37 @@ files:
75
100
  - lib/prawn/svg/parser/image.rb
76
101
  - lib/prawn/svg/parser/path.rb
77
102
  - lib/prawn/svg/parser/text.rb
103
+ - lib/prawn/svg/url_loader.rb
78
104
  - lib/prawn/svg/version.rb
79
105
  - prawn-svg.gemspec
80
- - spec/lib/parser_spec.rb
81
- - spec/lib/path_spec.rb
82
- - spec/lib/svg_spec.rb
106
+ - spec/integration_spec.rb
107
+ - spec/prawn/svg/calculators/aspect_ratio_spec.rb
108
+ - spec/prawn/svg/calculators/document_sizing_spec.rb
83
109
  - spec/prawn/svg/color_spec.rb
84
110
  - spec/prawn/svg/document_spec.rb
85
111
  - spec/prawn/svg/element_spec.rb
86
112
  - spec/prawn/svg/font_spec.rb
113
+ - spec/prawn/svg/interface_spec.rb
114
+ - spec/prawn/svg/parser/path_spec.rb
87
115
  - spec/prawn/svg/parser/text_spec.rb
116
+ - spec/prawn/svg/parser_spec.rb
117
+ - spec/prawn/svg/url_loader_spec.rb
118
+ - spec/sample_images/mushroom-long.jpg
119
+ - spec/sample_images/mushroom-wide.jpg
88
120
  - spec/sample_output/directory
89
121
  - spec/sample_svg/arcs01.svg
122
+ - spec/sample_svg/cap_styles.svg
90
123
  - spec/sample_svg/circle01.svg
91
124
  - spec/sample_svg/clip_path.svg
92
125
  - spec/sample_svg/close_path.svg
93
126
  - spec/sample_svg/cubic01.svg
94
127
  - spec/sample_svg/cubic01a.svg
95
128
  - spec/sample_svg/cubic02.svg
129
+ - spec/sample_svg/display_none.svg
96
130
  - spec/sample_svg/ellipse01.svg
131
+ - spec/sample_svg/gistfile1.svg
97
132
  - spec/sample_svg/google_charts.svg
133
+ - spec/sample_svg/hidden_paths.svg
98
134
  - spec/sample_svg/highcharts.svg
99
135
  - spec/sample_svg/image01.svg
100
136
  - spec/sample_svg/image02_base64.svg
@@ -102,8 +138,11 @@ files:
102
138
  - spec/sample_svg/maths.svg
103
139
  - spec/sample_svg/matrix_transform.svg
104
140
  - spec/sample_svg/matrix_transform_3.svg
141
+ - spec/sample_svg/negminy.svg
105
142
  - spec/sample_svg/omnigraffle.svg
106
143
  - spec/sample_svg/opacity01.svg
144
+ - spec/sample_svg/path.svg
145
+ - spec/sample_svg/pie_piece.svg
107
146
  - spec/sample_svg/polygon01.svg
108
147
  - spec/sample_svg/polyline01.svg
109
148
  - spec/sample_svg/quad01.svg
@@ -120,6 +159,8 @@ files:
120
159
  - spec/sample_svg/tspan03.svg
121
160
  - spec/sample_svg/tspan04.svg
122
161
  - spec/sample_svg/use.svg
162
+ - spec/sample_svg/viewbox.svg
163
+ - spec/sample_svg/viewport.svg
123
164
  - spec/spec_helper.rb
124
165
  homepage: http://github.com/mogest/prawn-svg
125
166
  licenses:
@@ -131,39 +172,49 @@ require_paths:
131
172
  - lib
132
173
  required_ruby_version: !ruby/object:Gem::Requirement
133
174
  requirements:
134
- - - '>='
175
+ - - ">="
135
176
  - !ruby/object:Gem::Version
136
- version: '0'
177
+ version: 1.9.3
137
178
  required_rubygems_version: !ruby/object:Gem::Requirement
138
179
  requirements:
139
- - - '>='
180
+ - - ">="
140
181
  - !ruby/object:Gem::Version
141
182
  version: '0'
142
183
  requirements: []
143
184
  rubyforge_project:
144
- rubygems_version: 2.1.11
185
+ rubygems_version: 2.2.2
145
186
  signing_key:
146
187
  specification_version: 4
147
188
  summary: SVG renderer for Prawn PDF library
148
189
  test_files:
149
- - spec/lib/parser_spec.rb
150
- - spec/lib/path_spec.rb
151
- - spec/lib/svg_spec.rb
190
+ - spec/integration_spec.rb
191
+ - spec/prawn/svg/calculators/aspect_ratio_spec.rb
192
+ - spec/prawn/svg/calculators/document_sizing_spec.rb
152
193
  - spec/prawn/svg/color_spec.rb
153
194
  - spec/prawn/svg/document_spec.rb
154
195
  - spec/prawn/svg/element_spec.rb
155
196
  - spec/prawn/svg/font_spec.rb
197
+ - spec/prawn/svg/interface_spec.rb
198
+ - spec/prawn/svg/parser/path_spec.rb
156
199
  - spec/prawn/svg/parser/text_spec.rb
200
+ - spec/prawn/svg/parser_spec.rb
201
+ - spec/prawn/svg/url_loader_spec.rb
202
+ - spec/sample_images/mushroom-long.jpg
203
+ - spec/sample_images/mushroom-wide.jpg
157
204
  - spec/sample_output/directory
158
205
  - spec/sample_svg/arcs01.svg
206
+ - spec/sample_svg/cap_styles.svg
159
207
  - spec/sample_svg/circle01.svg
160
208
  - spec/sample_svg/clip_path.svg
161
209
  - spec/sample_svg/close_path.svg
162
210
  - spec/sample_svg/cubic01.svg
163
211
  - spec/sample_svg/cubic01a.svg
164
212
  - spec/sample_svg/cubic02.svg
213
+ - spec/sample_svg/display_none.svg
165
214
  - spec/sample_svg/ellipse01.svg
215
+ - spec/sample_svg/gistfile1.svg
166
216
  - spec/sample_svg/google_charts.svg
217
+ - spec/sample_svg/hidden_paths.svg
167
218
  - spec/sample_svg/highcharts.svg
168
219
  - spec/sample_svg/image01.svg
169
220
  - spec/sample_svg/image02_base64.svg
@@ -171,8 +222,11 @@ test_files:
171
222
  - spec/sample_svg/maths.svg
172
223
  - spec/sample_svg/matrix_transform.svg
173
224
  - spec/sample_svg/matrix_transform_3.svg
225
+ - spec/sample_svg/negminy.svg
174
226
  - spec/sample_svg/omnigraffle.svg
175
227
  - spec/sample_svg/opacity01.svg
228
+ - spec/sample_svg/path.svg
229
+ - spec/sample_svg/pie_piece.svg
176
230
  - spec/sample_svg/polygon01.svg
177
231
  - spec/sample_svg/polyline01.svg
178
232
  - spec/sample_svg/quad01.svg
@@ -189,4 +243,6 @@ test_files:
189
243
  - spec/sample_svg/tspan03.svg
190
244
  - spec/sample_svg/tspan04.svg
191
245
  - spec/sample_svg/use.svg
246
+ - spec/sample_svg/viewbox.svg
247
+ - spec/sample_svg/viewport.svg
192
248
  - spec/spec_helper.rb
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Prawn::Svg::Parser::Path do
4
- before :each do
5
- @path = Prawn::Svg::Parser::Path.new
6
- end
7
-
8
- describe "command parsing" do
9
- it "correctly parses a valid path" do
10
- calls = []
11
- @path.stub(:run_path_command) {|*args| calls << args}
12
- @path.parse("A12.34 -56.78 89B4 5 12-34 -.5.7+3 2.3e3 4e4 4e+4 c31,-2e-5C 6,7 T QX 0 Z")
13
-
14
- calls.should == [
15
- ["A", [12.34, -56.78, 89]],
16
- ["B", [4, 5, 12, -34, -0.5, 0.7, 3, 2.3e3, 4e4, 4e4]],
17
- ["c", [31, -2e-5]],
18
- ["C", [6, 7]],
19
- ["T", []],
20
- ["Q", []],
21
- ["X", [0]],
22
- ["Z", []]
23
- ]
24
- end
25
-
26
- it "treats subsequent points to m/M command as relative/absolute depending on command" do
27
-
28
- [
29
- ["M", [1,2,3,4]],
30
- ["L", [3,4]],
31
- ["m", [5,6,7,8]],
32
- ["l", [7,8]]
33
- ].each do |args|
34
- @path.should_receive(:run_path_command).with(*args).and_call_original
35
- end
36
-
37
- @path.parse("M 1,2 3,4 m 5,6 7,8")
38
- end
39
-
40
- it "correctly parses an empty path" do
41
- @path.should_not_receive(:run_path_command)
42
- @path.parse("").should == []
43
- @path.parse(" ").should == []
44
- end
45
-
46
- it "raises on invalid characters in the path" do
47
- lambda {@path.parse("M 10 % 20")}.should raise_error(Prawn::Svg::Parser::Path::InvalidError)
48
- end
49
-
50
- it "raises on numerical data before a command letter" do
51
- lambda {@path.parse("10 P")}.should raise_error(Prawn::Svg::Parser::Path::InvalidError)
52
- end
53
- end
54
- end
data/spec/lib/svg_spec.rb DELETED
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Prawn::Svg::Interface do
4
- root = "#{File.dirname(__FILE__)}/../.."
5
-
6
- describe "sample file rendering" do
7
- files = Dir["#{root}/spec/sample_svg/*.svg"]
8
-
9
- it "has at least 10 SVG sample files to test" do
10
- files.length.should >= 10
11
- end
12
-
13
- files.each do |file|
14
- it "renders the #{File.basename file} sample file without warnings or crashing" do
15
- warnings = nil
16
- Prawn::Document.generate("#{root}/spec/sample_output/#{File.basename file}.pdf") do |prawn|
17
- r = prawn.svg IO.read(file), :at => [0, prawn.bounds.top], :width => prawn.bounds.width, :cache_images => true
18
- warnings = r[:warnings].reject {|w| w =~ /Verdana/ && w =~ /is not a known font/ }
19
- end
20
- warnings.should == []
21
- end
22
- end
23
- end
24
-
25
- describe "multiple file rendering" do
26
- it "renders multiple files on to the same PDF" do
27
- Prawn::Document.generate("#{root}/spec/sample_output/multiple.pdf") do |prawn|
28
- width = prawn.bounds.width
29
-
30
- y = prawn.bounds.top - 12
31
- prawn.draw_text "This is multiple SVGs being output to the same PDF", :at => [0, y]
32
-
33
- y -= 12
34
- prawn.svg IO.read("#{root}/spec/sample_svg/arcs01.svg"), :at => [0, y], :width => width / 2
35
- prawn.svg IO.read("#{root}/spec/sample_svg/circle01.svg"), :at => [width / 2, y], :width => width / 2
36
-
37
- y -= 120
38
- prawn.draw_text "Here are some more PDFs below", :at => [0, y]
39
-
40
- y -= 12
41
- prawn.svg IO.read("#{root}/spec/sample_svg/quad01.svg"), :at => [0, y], :width => width / 3
42
- prawn.svg IO.read("#{root}/spec/sample_svg/rect01.svg"), :at => [width / 3, y], :width => width / 3
43
- prawn.svg IO.read("#{root}/spec/sample_svg/rect02.svg"), :at => [width / 3 * 2, y], :width => width / 3
44
- end
45
- end
46
- end
47
- end
File without changes