quinn-ruby-svg 0.0.1 → 0.1.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.
data/README.mkdn CHANGED
@@ -1,10 +0,0 @@
1
- ruby-svg
2
- ========
3
-
4
- This is the beginning of a library for creating SVG documents with Ruby.
5
-
6
- Something I started on when I was bored, and didn't get very far before I was bored again.
7
-
8
- Feel free to fork and continue work, please send me a pullrequest if you get something worthwhile going.
9
-
10
- ~ elliottcable.name
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :patch: 0
3
3
  :major: 0
4
- :minor: 0
4
+ :minor: 1
@@ -0,0 +1,143 @@
1
+
2
+ #==============================================================================#
3
+ # svg/core.rb
4
+ # $Id: core.rb,v 1.11 2003/02/06 14:59:43 yuya Exp $
5
+ #==============================================================================#
6
+
7
+ #==============================================================================#
8
+ # SVG Module
9
+ module SVG
10
+
11
+ def self.new(*args)
12
+ return Picture.new(*args)
13
+ end
14
+
15
+ #============================================================================#
16
+ # Picture Class
17
+ class Picture
18
+
19
+ include ArrayMixin
20
+
21
+ def initialize(width, height, view_box = nil)
22
+ @width = width
23
+ @height = height
24
+ @x = nil
25
+ @y = nil
26
+ @view_box = view_box
27
+ @title = nil
28
+ @desc = nil
29
+
30
+ @elements = []
31
+ @styles = []
32
+ @scripts = []
33
+ end
34
+
35
+ attr_reader :elements, :styles, :scripts
36
+ attr_accessor :width, :height, :x, :y, :view_box, :title, :desc
37
+
38
+ def array
39
+ return @elements
40
+ end
41
+ private :array
42
+
43
+ def define_style(class_name, style)
44
+ @styles << DefineStyle.new(class_name, style)
45
+ end
46
+
47
+ def to_s
48
+ text = %|<?xml version="1.0" standalone="no"?>\n|
49
+ text << %|<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">\n|
50
+ text << %|<svg width="#{@width}" height="#{@height}"|
51
+ text << %| viewBox="#{@view_box}"| if @view_box
52
+ text << %|>\n|
53
+
54
+ @scripts.each { |script|
55
+ text << script.to_s
56
+ }
57
+
58
+ unless @styles.empty?
59
+ text << %|<defs>\n|
60
+ text << %|<style type="text/css"><![CDATA[\n|
61
+ text << @styles.collect { |define| define.to_s + "\n" }.join
62
+ text << %|]]></style>\n|
63
+ text << %|</defs>\n|
64
+ end
65
+
66
+ text << %|<title>#{@title}</title>\n| if @title
67
+ text << %|<desc>#{@desc}</desc>\n| if @desc
68
+ text << @elements.collect { |element| element.to_s + "\n" }.join
69
+ text << %|</svg>\n|
70
+ return text
71
+ end
72
+
73
+ def svg
74
+ return self.to_s
75
+ end
76
+
77
+ def svgz
78
+ require 'zlib'
79
+ return Deflate.deflate(self.to_s, Deflate::BEST_COMPRESSION)
80
+ end
81
+
82
+ def mime_type
83
+ return 'image/svg+xml'
84
+ end
85
+
86
+ end # Picture
87
+
88
+ #============================================================================#
89
+ # DefineStyle Class
90
+ class DefineStyle
91
+
92
+ def initialize(class_name, style)
93
+ @class_name = class_name
94
+ @style = style
95
+ end
96
+
97
+ attr_accessor :class_name, :style
98
+
99
+ def to_s
100
+ return "#{@class_name} { #{@style} }"
101
+ end
102
+
103
+ end # DefineStyle
104
+
105
+ #============================================================================#
106
+ # ECMAScript Class
107
+ class ECMAScript
108
+
109
+ def initialize(script)
110
+ @script = script
111
+ end
112
+
113
+ attr_accessor :script
114
+
115
+ def to_s
116
+ text = %|<script type="text/ecmascript"><![CDATA[\n|
117
+ text << @script << "\n"
118
+ text << %|]]></script>\n|
119
+ return text
120
+ end
121
+
122
+ end # ECMAScript
123
+
124
+ #============================================================================#
125
+ # ECMAScriptURI Class
126
+ class ECMAScriptURI
127
+
128
+ def initialize(uri)
129
+ @uri = uri
130
+ end
131
+
132
+ attr_accessor :uri
133
+
134
+ def to_s
135
+ return %|<script type="text/ecmascript" xlink:href="#{@uri}" />\n|
136
+ end
137
+
138
+ end # ECMAScriptURI
139
+
140
+ end # SVG
141
+
142
+ #==============================================================================#
143
+ #==============================================================================#
@@ -0,0 +1,358 @@
1
+
2
+ #==============================================================================#
3
+ # svg/element.rb
4
+ # $Id: element.rb,v 1.14 2003/02/06 14:59:43 yuya Exp $
5
+ #==============================================================================#
6
+
7
+ #==============================================================================#
8
+ # SVG Module
9
+ module SVG
10
+
11
+ #============================================================================#
12
+ # ElementBase Class
13
+ class ElementBase
14
+
15
+ def initialize(&block)
16
+ @id = nil
17
+ @style = nil
18
+ @class = nil
19
+ @transform = nil
20
+ @attr = nil
21
+
22
+ if block_given?
23
+ instance_eval(&block)
24
+ end
25
+ end
26
+
27
+ attr_accessor :id, :style, :class, :transform, :attr
28
+
29
+ def to_s
30
+ text = ''
31
+ text << %| id="#{@id}"| if @id
32
+ text << %| style="#{@style}"| if @style
33
+ text << %| class="#{@class}"| if @class
34
+ text << %| transform="#{@transform}"| if @transform
35
+ text << %| #{@attr}| if @attr
36
+ return text
37
+ end
38
+
39
+ end # ElementBase
40
+
41
+ #============================================================================#
42
+ # Group Class
43
+ class Group < ElementBase
44
+
45
+ include ArrayMixin
46
+
47
+ def initialize
48
+ super()
49
+ @elements = []
50
+ end
51
+
52
+ attr_reader :elements
53
+
54
+ def array
55
+ return @elements
56
+ end
57
+ private :array
58
+
59
+ def to_s
60
+ text = %|<g|
61
+ text << super()
62
+ text << %|>\n|
63
+ text << @elements.collect { |element| element.to_s + "\n" }.join
64
+ text << %|</g>\n|
65
+ end
66
+
67
+ end # Group
68
+
69
+ #============================================================================#
70
+ # Anchor Class
71
+ class Anchor < ElementBase
72
+
73
+ include ArrayMixin
74
+
75
+ def initialize(uri)
76
+ super()
77
+ @uri = uri
78
+ @elements = []
79
+ end
80
+
81
+ attr_accessor :uri
82
+ attr_reader :elements
83
+
84
+ def array
85
+ return @elements
86
+ end
87
+ private :array
88
+
89
+ def to_s
90
+ text = %|<a|
91
+ text << super()
92
+ text << %| xlink:href="#{@uri}">\n|
93
+ text << @elements.collect { |element| element.to_s + "\n" }.join
94
+ text << %|</a>\n|
95
+ end
96
+
97
+ end # Anchor
98
+
99
+ #============================================================================#
100
+ # Use Class
101
+ class Use < ElementBase
102
+
103
+ def initialize(uri)
104
+ super()
105
+ @uri = uri
106
+ end
107
+
108
+ attr_accessor :uri
109
+
110
+ def to_s
111
+ text = %|<use|
112
+ text << super()
113
+ text << %| xlink:href="#{@uri}"/>\n|
114
+ end
115
+
116
+ end # Use
117
+
118
+ #============================================================================#
119
+ # Rect Class
120
+ class Rect < ElementBase
121
+
122
+ def initialize(x, y, width, height, rx = nil, ry = nil)
123
+ super()
124
+
125
+ @x = x
126
+ @y = y
127
+ @width = width
128
+ @height = height
129
+ @rx = rx
130
+ @ry = ry
131
+ end
132
+
133
+ attr_accessor :width, :height, :x, :y, :rx, :ry
134
+
135
+ def to_s
136
+ text = %|<rect width="#{@width}" height="#{@height}"|
137
+ text << %| x="#{@x}"| if @x
138
+ text << %| y="#{@y}"| if @y
139
+ text << %| rx="#{@rx}"| if @rx
140
+ text << %| ry="#{@ry}"| if @ry
141
+ text << super()
142
+ text << %| />|
143
+ return text
144
+ end
145
+
146
+ end # Rect
147
+
148
+ #============================================================================#
149
+ # Circle Class
150
+ class Circle < ElementBase
151
+
152
+ def initialize(cx, cy, r)
153
+ super()
154
+
155
+ @cx = cx
156
+ @cy = cy
157
+ @r = r
158
+ end
159
+
160
+ attr_accessor :cx, :cy, :r
161
+
162
+ def to_s
163
+ text = %|<circle cx="#{@cx}" cy="#{@cy}" r="#{@r}"|
164
+ text << super()
165
+ text << %| />|
166
+ return text
167
+ end
168
+
169
+ end # Circle
170
+
171
+ #============================================================================#
172
+ # Ellipse Class
173
+ class Ellipse < ElementBase
174
+
175
+ def initialize(cx, cy, rx, ry)
176
+ super()
177
+
178
+ @cx = cx
179
+ @cy = cy
180
+ @rx = rx
181
+ @ry = ry
182
+ end
183
+
184
+ attr_accessor :cx, :cy, :rx, :ry
185
+
186
+ def to_s
187
+ text = %|<ellipse cx="#{@cx}" cy="#{@cy}" rx="#{@rx}" ry="#{@ry}"|
188
+ text << super()
189
+ text << %| />|
190
+ return text
191
+ end
192
+
193
+ end # Ellipse
194
+
195
+ #============================================================================#
196
+ # Line Class
197
+ class Line < ElementBase
198
+
199
+ def initialize(x1, y1, x2, y2)
200
+ super()
201
+ @x1 = x1
202
+ @y1 = y1
203
+ @x2 = x2
204
+ @y2 = y2
205
+ end
206
+
207
+ attr_accessor :x1, :y1, :x2, :y2
208
+
209
+ def to_s
210
+ text = %|<line x1="#{@x1}" y1="#{@y1}" x2="#{@x2}" y2="#{@y2}"|
211
+ text << super()
212
+ text << %| />|
213
+ return text
214
+ end
215
+
216
+ end # Line
217
+
218
+ #============================================================================#
219
+ # Polyline Class
220
+ class Polyline < ElementBase
221
+
222
+ def initialize(points)
223
+ super()
224
+ @points = points
225
+ end
226
+
227
+ attr_accessor :points
228
+
229
+ def to_s
230
+ text = %|<polyline points="#{@points.join(' ')}"|
231
+ text << super()
232
+ text << %| />|
233
+ return text
234
+ end
235
+
236
+ end # Polyline
237
+
238
+ #============================================================================#
239
+ # Polygon Class
240
+ class Polygon < ElementBase
241
+
242
+ def initialize(points)
243
+ super()
244
+ @points = points
245
+ end
246
+
247
+ attr_accessor :points
248
+
249
+ def to_s
250
+ text = %|<polygon points="#{@points.join(' ')}"|
251
+ text << super()
252
+ text << %| />|
253
+ return text
254
+ end
255
+
256
+ end # Polygon
257
+
258
+ #============================================================================#
259
+ # Image Class
260
+ class Image < ElementBase
261
+
262
+ def initialize(x, y, width, height, href)
263
+ super()
264
+ @x = x
265
+ @y = y
266
+ @width = width
267
+ @height = height
268
+ @href = href
269
+ end
270
+
271
+ attr_accessor :x, :y, :width, :height, :href
272
+
273
+ def to_s
274
+ text = %|<image|
275
+ text << %| x="#{@x}"| if @x
276
+ text << %| y="#{@y}"| if @y
277
+ text << %| width="#{@width}"|
278
+ text << %| height="#{@height}"|
279
+ text << %| xlink:href="#{@href}"|
280
+ text << super()
281
+ text << %| />|
282
+ return text
283
+ end
284
+
285
+ end # Image
286
+
287
+ #============================================================================#
288
+ # Path Class
289
+ class Path < ElementBase
290
+
291
+ def initialize(path, length = nil)
292
+ super()
293
+ @path = path
294
+ @length = length
295
+ end
296
+
297
+ attr_accessor :path, :length
298
+
299
+ def to_s
300
+ text = %|<path d="#{@path.join(' ')}"|
301
+ text = %| length="#{@length}"| if @length
302
+ text << super()
303
+ text << %| />|
304
+ return text
305
+ end
306
+
307
+ end # Path
308
+
309
+ #============================================================================#
310
+ # Text Class
311
+ class Text < ElementBase
312
+
313
+ def initialize(x, y, text)
314
+ super()
315
+ @x = x
316
+ @y = y
317
+ @text = text
318
+ @length = nil
319
+ @length_adjust = nil
320
+ end
321
+
322
+ attr_accessor :x, :y, :text, :length, :length_adjust
323
+
324
+ def to_s
325
+ svg = %|<text|
326
+ svg << %| x="#{@x}"| if @x
327
+ svg << %| y="#{@y}"| if @y
328
+ svg << %| textLength="#{@length}"| if @length
329
+ svg << %| lengthAdjust="#{@length_adjust}"| if @length_adjust
330
+ svg << super()
331
+ svg << %|>|
332
+ svg << text
333
+ svg << %|</text>|
334
+ return svg
335
+ end
336
+
337
+ end # Text
338
+
339
+ #============================================================================#
340
+ # Verbatim Class
341
+ class Verbatim
342
+
343
+ def initialize(xml)
344
+ @xml = xml
345
+ end
346
+
347
+ attr_accessor :xml
348
+
349
+ def to_s
350
+ return @xml
351
+ end
352
+
353
+ end # Verbatim
354
+
355
+ end # SVG
356
+
357
+ #==============================================================================#
358
+ #==============================================================================#
@@ -0,0 +1,82 @@
1
+
2
+ #==============================================================================#
3
+ # svg/misc.rb
4
+ # $Id: misc.rb,v 1.6 2003/02/06 14:59:43 yuya Exp $
5
+ #==============================================================================#
6
+
7
+ #==============================================================================#
8
+ # SVG Module
9
+ module SVG
10
+
11
+ #============================================================================#
12
+ # Point Class
13
+ class Point
14
+
15
+ def initialize(x, y)
16
+ @x = x
17
+ @y = y
18
+ end
19
+
20
+ attr_accessor :x, :y
21
+
22
+ def self.[](*points)
23
+ if points.size % 2 == 0
24
+ return (0...(points.size / 2)).collect { |i|
25
+ self.new(points[i * 2], points[i * 2 + 1])
26
+ }
27
+ else
28
+ raise ArgumentError, 'odd number args for Point'
29
+ end
30
+ end
31
+
32
+ def to_s
33
+ return "#{@x} #{@y}"
34
+ end
35
+
36
+ end # Point
37
+
38
+ #============================================================================#
39
+ # ArrayMixin Module
40
+ module ArrayMixin
41
+
42
+ include Enumerable
43
+
44
+ def array
45
+ raise NotImplementedError
46
+ end
47
+ private :array
48
+
49
+ def [](index)
50
+ array[index]
51
+ end
52
+
53
+ def []=(index, value)
54
+ array[index] = value
55
+ end
56
+
57
+ def <<(other)
58
+ array << other
59
+ end
60
+
61
+ def clear
62
+ array.clear
63
+ end
64
+
65
+ def first
66
+ array.first
67
+ end
68
+
69
+ def last
70
+ array.last
71
+ end
72
+
73
+ def each(&block)
74
+ array.each(&block)
75
+ end
76
+
77
+ end # ArrayMixin
78
+
79
+ end # SVG
80
+
81
+ #==============================================================================#
82
+ #==============================================================================#
@@ -0,0 +1,112 @@
1
+
2
+ #==============================================================================#
3
+ # svg/style.rb
4
+ # $Id: style.rb,v 1.6 2003/02/06 14:59:43 yuya Exp $
5
+ #==============================================================================#
6
+
7
+ #==============================================================================#
8
+ # SVG Module
9
+ module SVG
10
+
11
+ #============================================================================#
12
+ # Style Class
13
+ class Style
14
+
15
+ Attributes = [
16
+ 'stroke', #
17
+ 'stroke-dasharray', #
18
+ 'stroke-dashoffset', #
19
+ 'stroke-linecap', # round | butt | square | inherit
20
+ 'stroke-linejoin', # round | bevel | miter | inherit
21
+ 'stroke-miterlimit', #
22
+ 'stroke-opacity', #
23
+ 'stroke-width', #
24
+ 'fill', #
25
+ 'fill-opacity', #
26
+ 'fill-rule', # evenodd | nonzero | inherit
27
+ 'alignment-baseline', # auto | baseline | before-edge | text-before-edge | middle | after-edge | text-after-edge | ideographic | alphabetic | hanging | mathematical | inherit
28
+ 'baseline-shift', # baseline | sub | super | <percentage> | <length> | inherit
29
+ 'direction', # ltr | rtl | inherit
30
+ 'dominant-baseline', # auto | autosense-script | no-change | reset | ideographic | lower | hanging | mathematical | inherit
31
+ 'font', #
32
+ 'font-family', #
33
+ 'font-size', #
34
+ 'font-size-adjust', # [0-9]+ | none | inherit
35
+ 'font-stretch', # normal | wider | narrower | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded | inherit
36
+ 'font-style', # normal | italic | oblique | inherit
37
+ 'font-variant', # normal | small-caps | inherit
38
+ 'font-weight', # normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
39
+ 'glyph-orientation-hoizontal', # <angle> | inherit
40
+ 'glyph-orientation-vertical', # auto | <angle> | inherit
41
+ 'kerning', # auto | <length> | inherit
42
+ 'letter-spacing', # normal | <length> | inherit
43
+ 'text-anchor', # start | middle | end | inherit
44
+ 'text-decoration', # none | underline | overline | line-through | blink | inherit
45
+ 'text-rendering', # auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit
46
+ 'unicode-bidi', # normal | embed | bidi-override | inherit
47
+ 'word-spacing', # normal | length | inherit
48
+ 'writing-mode', # lr-tb | rl-tb | tb-rl | lr | rl | tb | inherit
49
+ 'clip', # auto | rect(...) | inherit
50
+ 'clip-path', # <uri> | none | inherit
51
+ 'clip-rule', # evenodd | nonzero | inherit
52
+ 'color', #
53
+ 'color-interpolation', # auto | sRGB | linearRGB | inherit
54
+ 'color-rendering', # auto | optimizeSpeed | optimizeQuality | inherit
55
+ 'cursor', # [ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize| text | wait | help ] ] | inherit
56
+ 'display', # inline | none | inherit
57
+ 'enable-background', # accumulate | new [ ( <x> <y> <width> <height> ) ] | inherit
58
+ 'filter', # <uri> | none | uri
59
+ 'image-rendering', # auto | optimizeSpeed | optimizeQuality
60
+ 'marker', #
61
+ 'marker-end', # none | <uri>
62
+ 'marker-mid', #
63
+ 'marker-start', #
64
+ 'mask', #
65
+ 'opacity', #
66
+ 'overflow', # visible | hidden | scroll | auto | inherit
67
+ 'pointer-events', # visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all | none | inherit
68
+ 'rendering-intent', # auto | perceptual | relative-colorimetric | saturation | absolute-colorimetric | inherit
69
+ 'shape-rendering', # auto | optimizeSpeed | crispEdges|geometricPrecision | inherit
70
+ 'visibility', # visible | hidden | collapse | inherit
71
+ ]
72
+
73
+ def initialize(attr = nil)
74
+ @attributes = {}
75
+
76
+ if attr && attr.kind_of?(Hash)
77
+ attr.each { |key, value|
78
+ @attributes[key.to_s.gsub(/_/, '-')] = value
79
+ }
80
+ end
81
+ end
82
+
83
+ Attributes.each { |attr|
84
+ name = attr.gsub(/-/, '_')
85
+ class_eval(<<-EOS)
86
+ def #{name}
87
+ return @attributes['#{attr}']
88
+ end
89
+ def #{name}=(value)
90
+ @attributes['#{attr}'] = value
91
+ end
92
+ EOS
93
+ }
94
+
95
+ def to_s
96
+ text = @attributes.select { |key, value|
97
+ !value.nil?
98
+ }.sort { |(a_key, a_value), (b_key, b_value)|
99
+ a_key <=> b_key
100
+ }.collect { |key, value|
101
+ "#{key}: #{value};"
102
+ }.join(' ')
103
+
104
+ return text
105
+ end
106
+
107
+ end # Style
108
+
109
+ end # SVG
110
+
111
+ #==============================================================================#
112
+ #==============================================================================#
data/lib/ruby-svg.rb CHANGED
@@ -1,86 +1,13 @@
1
- require 'ruby-svg/primatives/Path'
2
- require 'ruby-svg/primatives/Rectangle'
3
- require 'ruby-svg/primatives/A'
4
- # require 'ruby-svg/complex/Pie'
5
1
 
6
- class SVG
7
- def initialize(args = {})
8
- args = { :encoding => 'UTF-8',
9
- :doctype => 'svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"',
10
- :namespace => 'svg',
11
- :width => 500,
12
- :height => 500 }.merge(args)
13
- args.each do |k,v|
14
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
15
- end
16
- @content = Array.new
17
- end
18
-
19
- attr_accessor :style
20
- attr_accessor :title
21
- attr_accessor :desc
22
-
23
- attr_reader :content
24
- def << (element)
25
- @content << element
26
- end
27
-
28
- def to_xml(args = {})
29
- standalone = args[:standalone].nil? || args[:standalone].class == (TrueClass || FalseClass) ? true : args[:standalone]
30
- indent = args[:indent].nil? || args[:indent].class != Fixnum ? 0 : args[:indent]
31
- indent = 0 if standalone
32
-
33
- out = Array.new
34
- if standalone
35
- out << SVGHelper::wrap("?xml version='1.0' encoding='#{@encoding}' standalone='no'?", indent)
36
- out << SVGHelper::wrap("!DOCTYPE #{@doctype}", indent)
37
- end
38
-
39
- # Header
40
- header = String.new
41
- header << (standalone ? '' : @namespace + ':') + 'svg'
42
- [:width, :height].each do |a|
43
- header << " #{a.to_s}='#{instance_variable_get('@' + a.to_s)}'"
44
- end
45
- header << " version='1.1' xmlns='http://www.w3.org/2000/svg'" if standalone
46
- header << " xmlns:xlink='http://www.w3.org/1999/xlink'"
47
- out << SVGHelper::wrap(header, indent)
48
- indent += 1
49
-
50
- {:title => {}, :style => {:type => 'text/css'}, :desc => {}}.each do |tag,attribs|
51
- it = instance_variable_get('@' + tag.to_s)
52
- unless it.nil?
53
- header = (standalone ? '' : @namespace + ':') + tag.to_s
54
- attribs.each do |k,v|
55
- header << " #{k}='#{v}'"
56
- end
57
- out << SVGHelper::wrap(header, indent)
58
- indent += 1
59
- lines = ''
60
- it.each do |line|
61
- lines << SVGHelper::indent(line, indent)
62
- end
63
- out << lines.sub(/([^\n])\z/, "\\1\n")
64
- indent -= 1
65
- out << SVGHelper::wrap('/' + tag.to_s, indent)
66
- end
67
- end
68
-
69
- @content.each do |element|
70
- out << element.to_xml(:standalone => standalone, :indent => indent)
71
- end
72
-
73
- indent -= 1
74
- out << SVGHelper::wrap('/' + (standalone ? '' : @namespace + ':') + 'svg', indent).chomp
75
- end
76
- end
2
+ #==============================================================================#
3
+ # svg/svg.rb
4
+ # $Id: svg.rb,v 1.4 2002/09/10 09:59:08 yuya Exp $
5
+ #==============================================================================#
77
6
 
78
- class SVGHelper
79
- def self.wrap(c, indent = 0)
80
- SVGHelper::indent("<#{c}>", indent) + "\n"
81
- end
82
-
83
- def self.indent(c, level)
84
- (' ' * level) + c
85
- end
86
- end
7
+ require 'svg/misc'
8
+ require 'svg/core'
9
+ require 'svg/element'
10
+ require 'svg/style'
11
+
12
+ #==============================================================================#
13
+ #==============================================================================#
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quinn-ruby-svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - quinn
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-09 00:00:00 -08:00
12
+ date: 2009-02-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,20 +25,17 @@ files:
25
25
  - README.mkdn
26
26
  - VERSION.yml
27
27
  - lib/ruby-svg
28
- - lib/ruby-svg/complex
29
- - lib/ruby-svg/complex/Pie.rb
30
- - lib/ruby-svg/primatives
31
- - lib/ruby-svg/primatives/A.rb
32
- - lib/ruby-svg/primatives/Defs.rb
33
- - lib/ruby-svg/primatives/Path.rb
34
- - lib/ruby-svg/primatives/Polygon.rb
35
- - lib/ruby-svg/primatives/Rectangle.rb
28
+ - lib/ruby-svg/core.rb
29
+ - lib/ruby-svg/element.rb
30
+ - lib/ruby-svg/misc.rb
31
+ - lib/ruby-svg/style.rb
36
32
  - lib/ruby-svg.rb
37
- has_rdoc: false
33
+ has_rdoc: true
38
34
  homepage: http://github.com/quinn/ruby-svg
39
35
  post_install_message:
40
- rdoc_options: []
41
-
36
+ rdoc_options:
37
+ - --inline-source
38
+ - --charset=UTF-8
42
39
  require_paths:
43
40
  - lib
44
41
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -1,20 +0,0 @@
1
- class SVGPieChart
2
-
3
- end
4
-
5
- class SVGPieSlice
6
- # x, y, radius, percent, used
7
- def initialize(args = {})
8
- args.each do |k,v|
9
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
10
- end
11
- @angle = (2 * Math::PI) * (@percent / 100.0)
12
- @full = @percent + @used
13
- end
14
-
15
- def angle
16
- (2 * Math::PI) * (@percent - / 100.0)
17
- end
18
-
19
-
20
- end
@@ -1,33 +0,0 @@
1
- class SVGA
2
- def initialize(args = {})
3
- args = { :href => '#' }.merge(args)
4
- args.each do |k,v|
5
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
6
- end
7
- @content = Array.new
8
- end
9
-
10
- attr_reader :content
11
- def << (element)
12
- @content << element
13
- end
14
-
15
- def to_xml(args = {})
16
- standalone = args[:standalone].nil? || args[:standalone].class == (TrueClass || FalseClass) ? true : args[:standalone]
17
- indent = args[:indent].nil? || args[:indent].class != Fixnum ? 0 : args[:indent]
18
-
19
- element = (standalone ? '' : @namespace + ':') + 'a'
20
-
21
- element << " xlink:href='#{@href}'"
22
-
23
- out = SVGHelper::wrap(element, indent)
24
- indent += 1
25
-
26
- @content.each do |element|
27
- out << element.to_xml(:standalone => standalone, :indent => indent)
28
- end
29
-
30
- indent -= 1
31
- out << SVGHelper::wrap('/' + (standalone ? '' : @namespace + ':') + 'a', indent)
32
- end
33
- end
File without changes
@@ -1,80 +0,0 @@
1
- class SVGPath
2
- def initialize(args = {})
3
- args.each do |k,v|
4
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
5
- end
6
- @descriptors = Array.new
7
- end
8
-
9
- attr_reader :descriptors
10
-
11
- def <<(descriptor)
12
- @descriptors << descriptor
13
- end
14
-
15
- def to_xml(args = {})
16
- standalone = args[:standalone].nil? || args[:standalone].class == (TrueClass || FalseClass) ? true : args[:standalone]
17
- indent = args[:indent].nil? || args[:indent].class != Fixnum ? 0 : args[:indent]
18
-
19
- element = (standalone ? '' : @namespace + ':') + 'path'
20
-
21
- descriptors = String.new
22
- @descriptors.each do |descriptor|
23
- descriptors << descriptor.to_s + " "
24
- end
25
- descriptors << "Z"
26
-
27
- element << " d='#{descriptors}'"
28
-
29
- [:id, :class, :style].each do |a|
30
- element << " #{a.to_s}='#{instance_variable_get('@' + a.to_s)}'" unless a.nil?
31
- end
32
- out = SVGHelper::wrap(element + "/", indent)
33
- end
34
- end
35
-
36
- class SVGPathMoveComponent
37
- def initialize(args = {})
38
- args = { :x => 0, :y => 0 }.merge(args)
39
- args.each do |k,v|
40
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
41
- end
42
- end
43
-
44
- def to_s
45
- "M#{@x},#{@y}"
46
- end
47
- end
48
- class SVGPathLineComponent
49
- def initialize(args = {})
50
- args = { :x => 0, :y => 0 }.merge(args)
51
- args.each do |k,v|
52
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
53
- end
54
- end
55
-
56
- def to_s
57
- "L#{@x},#{@y}"
58
- end
59
- end
60
- class SVGPathArcComponent
61
- # :direction => :american
62
- def initialize(args = {})
63
- args = { :rx => 100, :ry => 100, :slant => 0, :long => false, :direction => :cartesian, :x => 100, :y => 100 }.merge(args)
64
- args.each do |k,v|
65
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
66
- end
67
- end
68
-
69
- def to_s
70
- long = @long ? 1 : 0
71
- direction = case @direction
72
- when :cartesian
73
- 0
74
- when :american
75
- 1
76
- end
77
-
78
- "A#{@rx},#{@ry} #{@slant} #{long},#{direction} #{@x},#{@y}"
79
- end
80
- end
@@ -1,28 +0,0 @@
1
- class SVGPolygon
2
- def initialize(args = {})
3
- @points = ""
4
- args = { :x => 0, :y => 0,
5
- :width => 500, :height => 500 }.merge(args)
6
- args.each do |k,v|
7
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
8
- end
9
- @content = Array.new
10
- end
11
-
12
- def vertex x,y
13
- @points << "#{x}, #{y}"
14
- end
15
-
16
- alias_method :vertex, :point
17
-
18
- def to_xml(args = {})
19
- standalone = args[:standalone].nil? || args[:standalone].class == (TrueClass || FalseClass) ? true : args[:standalone]
20
- indent = args[:indent].nil? || args[:indent].class != Fixnum ? 0 : args[:indent]
21
-
22
- element = (standalone ? '' : @namespace + ':') + 'polygon'
23
- [:x, :y, :points, :id, :class, :style].each do |a|
24
- element << " #{a.to_s}='#{instance_variable_get('@' + a.to_s)}'" unless a.nil?
25
- end
26
- out = SVGHelper::wrap(element + "/", indent)
27
- end
28
- end
@@ -1,21 +0,0 @@
1
- class SVGRectangle
2
- def initialize(args = {})
3
- args = { :x => 0, :y => 0,
4
- :width => 500, :height => 500 }.merge(args)
5
- args.each do |k,v|
6
- self.instance_variable_set(('@' + k.to_s).to_sym, v)
7
- end
8
- @content = Array.new
9
- end
10
-
11
- def to_xml(args = {})
12
- standalone = args[:standalone].nil? || args[:standalone].class == (TrueClass || FalseClass) ? true : args[:standalone]
13
- indent = args[:indent].nil? || args[:indent].class != Fixnum ? 0 : args[:indent]
14
-
15
- element = (standalone ? '' : @namespace + ':') + 'rect'
16
- [:x, :y, :width, :height, :id, :class, :style].each do |a|
17
- element << " #{a.to_s}='#{instance_variable_get('@' + a.to_s)}'" unless a.nil?
18
- end
19
- out = SVGHelper::wrap(element + "/", indent)
20
- end
21
- end