gtk2svg 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5abbaefcd35af7fee0cbae1165a33c33d196aa5
4
- data.tar.gz: b816bb276df43b7d5534efe3c221171f5771c708
3
+ metadata.gz: f0fe558967f563d8d4f111a47f1c6437c13d369a
4
+ data.tar.gz: f0004931e1cac3e8fa85098dcfcaa4c05fbd0f40
5
5
  SHA512:
6
- metadata.gz: 4f446664fdbd10a7aa62e55b82bfba59ee1f69153410838af99afcf6036f8d9f1d1c67ea053720e3b3eefd0996dcd6300240185b695f2f59710abc3491eca4f6
7
- data.tar.gz: 5b8787216f1152cd675d8dd4422291a9a719abc4e1b95d09bc31d43162cc2758165ceb1d41375af7034f089e9792e89bb5350fe96427cc4c6ce679467e3d2353
6
+ metadata.gz: 285349e48fb22a23d68cd8f7d2e56a072778d9d6ce6dceddfbd81ee67cc20e19e4b9bb81f3b7810438c53e33d4fdbcafb0c88e644e65edf9e5192ffd8273d909
7
+ data.tar.gz: bec7350106552e774b66486d708c744fa136167862c50371fad7adf68925e763e38c9f9940b0853579017ad047f84059a57aa120b13641bb41c4c83ab194c6cf
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -9,12 +9,15 @@ require 'svgle'
9
9
  # Description: Experimental gem to render SVG within an GTK2 application.
10
10
 
11
11
 
12
+
12
13
  module Gtk2SVG
13
14
 
14
15
  class Render < DomRender
15
16
 
16
17
 
17
- def circle(e, attributes, style)
18
+ def circle(e, attributes, raw_style)
19
+
20
+ style = style_filter(attributes).merge(raw_style)
18
21
 
19
22
  h = attributes
20
23
 
@@ -24,8 +27,9 @@ module Gtk2SVG
24
27
  [:draw_arc, [x, y, radius, radius], style, render_all(e)]
25
28
  end
26
29
 
27
- def ellipse(e, attributes, style)
30
+ def ellipse(e, attributes, raw_style)
28
31
 
32
+ style = style_filter(attributes).merge(raw_style)
29
33
  h = attributes
30
34
 
31
35
  x, y= %i(cx cy).map{|x| h[x].to_i }
@@ -35,33 +39,36 @@ module Gtk2SVG
35
39
  [:draw_arc, [x, y, width, height], style, render_all(e)]
36
40
  end
37
41
 
38
- def line(e, attributes, style)
42
+ def line(e, attributes, raw_style)
39
43
 
40
- style[:stroke_width] = style.delete(:'stroke-width') || '3'
44
+ style = style_filter(attributes).merge(raw_style)
41
45
 
42
46
  x1, y1, x2, y2 = %i(x1 y1 x2 y2).map{|x| attributes[x].to_i }
43
47
 
44
48
  [:draw_line, [x1, y1, x2, y2], style, render_all(e)]
45
49
  end
46
50
 
47
- def polygon(e, attributes, style)
51
+ def polygon(e, attributes, raw_style)
48
52
 
53
+ style = style_filter(attributes).merge(raw_style)
49
54
  points = attributes[:points].split(/\s+/). \
50
55
  map {|x| x.split(/\s*,\s*/).map(&:to_i)}
51
56
 
52
57
  [:draw_polygon, points, style, render_all(e)]
53
58
  end
54
59
 
55
- def polyline(e, attributes, style)
60
+ def polyline(e, attributes, raw_style)
56
61
 
62
+ style = style_filter(attributes).merge(raw_style)
57
63
  points = attributes[:points].split(/\s+/). \
58
64
  map {|x| x.split(/\s*,\s*/).map(&:to_i)}
59
65
 
60
- [:draw_polyline, points, style, render_all(e)]
66
+ [:draw_lines, points, style, render_all(e)]
61
67
  end
62
68
 
63
- def rect(e, attributes, style)
69
+ def rect(e, attributes, raw_style)
64
70
 
71
+ style = style_filter(attributes).merge(raw_style)
65
72
  h = attributes
66
73
 
67
74
  x1, y1, width, height = %i(x y width height).map{|x| h[x].to_i }
@@ -78,15 +85,25 @@ module Gtk2SVG
78
85
  [:window, render_all(x)]
79
86
  end
80
87
 
81
- def text(e, attributes, style)
88
+ def text(e, attributes, raw_style)
82
89
 
90
+ style = style_filter(attributes).merge(raw_style)
83
91
  style.merge!({font_size: '20'})
84
92
 
85
- x, y, fill = %i(x y fill).map{|x| attributes[x] }
86
- style.merge!({fill: fill})
93
+ x, y = %i(x y).map{|x| attributes[x].to_i }
87
94
 
88
- [:draw_layout, [x.to_i, y.to_i], e.text, style, render_all(e)]
95
+ [:draw_layout, [x, y], e.text, style, render_all(e)]
89
96
  end
97
+
98
+ private
99
+
100
+ def style_filter(attributes)
101
+
102
+ %i(stroke stroke-width fill).inject({}) do |r,x|
103
+ attributes.has_key?(x) ? r.merge(x => attributes[x]) : r
104
+ end
105
+
106
+ end
90
107
 
91
108
  end
92
109
 
@@ -132,11 +149,9 @@ module Gtk2SVG
132
149
  @area.window.draw_polygon(gc, 1, points)
133
150
  end
134
151
 
135
- def draw_polyline(args)
136
- puts 'inside sraw_polying;'
137
- points, style = args
138
- puts 'style: ' + style.inspect
152
+ def draw_lines(args)
139
153
 
154
+ points, style = args
140
155
 
141
156
  gc = gc_ini(fill: style[:fill] || :none, stroke: style[:stroke] || :none)
142
157
  gc.set_line_attributes(style[:'stroke-width'].to_i, Gdk::GC::LINE_SOLID, \
@@ -224,7 +239,6 @@ module Gtk2SVG
224
239
  def gc_ini(fill: nil, stroke: nil)
225
240
  gc = Gdk::GC.new(@area.window)
226
241
  colour = fill || stroke
227
- puts 'colur : ' + colour.inspect
228
242
 
229
243
  unless colour == :none or colour == 'none'
230
244
  gc.set_foreground(set_colour(colour))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtk2svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file