gtk2svg 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +3 -0
  3. data/lib/gtk2svg.rb +152 -0
  4. data.tar.gz.sig +0 -0
  5. metadata +107 -0
  6. metadata.gz.sig +1 -1
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 561a0f8ef7b86006040e05e643470edd7b5039a8
4
+ data.tar.gz: 08402678a96a5e634cd01dc867f9bf44c026b06c
5
+ SHA512:
6
+ metadata.gz: 41302cb344ee54d3ef835383cb7fc5314dda7c273a66b8f3c5e2b03930b2d4e4ad2ffa808162d99b2616bdfc06441b223d457d0cb8f8d822fa56d3ed5fc260c8
7
+ data.tar.gz: 43c3375eb84623df41c6fdc1e3dc3e22bed589d4531b302cebe324ff0f0cacebef1156e1c54547b2351c90ee8d998c248de33543c6c40aa6bb7a0ee80b255c93
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ �RR��xH=�u���E��롷��ؠ�'z���~����
2
+ �ϼKO�ȨԠ S1��(��S��X���HS�{T)�Qf��֤z>x�}��0��K���~Y̦@�O`[��21v��q�� q?؃�{�M�z�/����S�q���k��'�a=��)9W��/�E��)���w�d��#��ؑ�r���r�8��]�6U�.�@`
3
+ b��w׶>� ^�N�|��f�1jW`ޔ�F�����͔�c�\��0�Z<<
data/lib/gtk2svg.rb ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: gtk2svg.rb
4
+
5
+ require 'gtk2'
6
+ require 'dom_render'
7
+
8
+
9
+ # Description: Experimental gem to render SVG within an GTK2 application.
10
+ # Currently it can only render rectangles along with the fill colour.
11
+
12
+ module SVG
13
+ class Element
14
+
15
+ attr_reader :style
16
+
17
+ def initialize(attributes, style)
18
+
19
+ @h = {x: '0', y: '0'}.merge attributes
20
+
21
+ @style = {fill: 'black'}
22
+ @style.merge!(style) if attributes[:style]
23
+
24
+ end
25
+
26
+ def attributes()
27
+ @h
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ module Gtk2SVG
34
+
35
+ class Render < DomRender
36
+
37
+ def svg(x, attributes, style)
38
+ [:window, render_all(x)]
39
+ end
40
+
41
+ def rect(e, attributes, style)
42
+
43
+ e2 = SVG::Element.new attributes, style
44
+ h = e2.attributes
45
+ style = e2.style
46
+
47
+
48
+ x1, y1, width, height = %i(x y width height).map{|x| h[x].to_i }
49
+ x2, y2, = x1 + width, y1 + height
50
+
51
+ [:draw_rectangle, [x1, y1, x2, y2], style, render_all(e)]
52
+ end
53
+
54
+ end
55
+
56
+ class DrawingInstructions
57
+
58
+ attr_accessor :area
59
+
60
+
61
+ def initialize(area=nil)
62
+
63
+ @area = area if area
64
+
65
+ end
66
+
67
+ def draw_rectangle(args)
68
+
69
+ coords, style = args
70
+
71
+ x1, y1, x2, y2 = coords
72
+ gc = gc_ini(fill: style[:fill] || :none)
73
+ @area.window.draw_rectangle(gc, 1, x1, y1, x2, y2)
74
+ end
75
+
76
+ def window(args)
77
+ end
78
+
79
+ def render(a)
80
+ draw a
81
+ end
82
+
83
+ private
84
+
85
+ def draw(a)
86
+
87
+ a.each do |rawx|
88
+
89
+ x, *remaining = rawx
90
+
91
+ if x.is_a? Symbol then
92
+ method(x).call(args=remaining.take(2))
93
+ elsif x.is_a? String then
94
+ draw remaining
95
+ elsif x.is_a? Array
96
+ draw remaining
97
+ else
98
+ method(x).call(remaining.take 2)
99
+ end
100
+
101
+ end
102
+
103
+ end
104
+
105
+ def set_colour(fill)
106
+
107
+ colour = case fill
108
+ when /^rgb/
109
+ regex = /rgb\((\d{1,3}), *(\d{1,3}), *(\d{1,3})\)$/
110
+ r, g, b = fill.match(regex).captures.map {|x| x.to_i * 257}
111
+ colour = Gdk::Color.new(r, g, b)
112
+ when /^#/
113
+ Gdk::Color.parse(fill)
114
+ else
115
+ Gdk::Color.parse(fill)
116
+ end
117
+
118
+ colormap = Gdk::Colormap.system
119
+ colormap.alloc_color(colour, false, true)
120
+
121
+ colour
122
+ end
123
+
124
+ def gc_ini(fill: 'black')
125
+ gc = Gdk::GC.new(area.window)
126
+ gc.set_foreground(set_colour(fill)) unless fill == :none
127
+ gc
128
+ end
129
+
130
+
131
+ end
132
+ end
133
+
134
+
135
+ if __FILE__ == $0 then
136
+
137
+ # Read an SVG file
138
+ s = File.read(ARGV[0])
139
+
140
+ area = Gtk::DrawingArea.new
141
+
142
+ area.signal_connect("expose_event") do
143
+
144
+ drawing = Gtk2SVG::DrawingInstructions.new area
145
+ drawing.render Gtk2SVG::Render.new(s).to_a
146
+
147
+ end
148
+
149
+ Gtk::Window.new.add(area).show_all
150
+ Gtk.main
151
+
152
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gtk2svg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE1MTEyMTEyNDM1MloXDTE2MTEyMDEyNDM1MlowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBALfXiqh75fe/C7nt7T1ZqmXgBEESOxF0pZY88NPI6DTcxOmKe2sGbGqs5G9s
19
+ QqRDG0pNNJk1z91VGo86hOKycJmU3kyWDs+Ezr5q/lpgvIBlzjyMMI6G/mEAU7dC
20
+ 2LRVUd4TLD2IaXUBY6VquXYQm02WuN38mJHRgYLigFsiZ+TLnoA3iDFAARt6AIgJ
21
+ pbKgZ4148CEOorgY+38ezduTxL/dhgYYzCksCKPutEWY/e270V8sNS8BiBU2rA6W
22
+ zsnv1OFzGfZ8QBTEoDZGxBtkRI3pMyUP/R3SHHSybIw3Ttul5ERfWWzjkRi5Co6Q
23
+ GU6BathuDXN8dA7x2D2FIlfw6qcCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUFNzydmBb4YGbQwY2NEWGNmu4eM4wJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAHhAyamfK
27
+ rHF9N9fcNVhk9SLn562e0dQccSTZJwz3LRRnivXIEp5I0hTxOq1++pKhYlBX77zy
28
+ T7lRF7gAA+bh1EsWiHou9LA/jHUx/xiFbls66a4nB9KiCYXhJGpHvi6Mp/Mf9btD
29
+ N+urRJSVHfKdNi67NyBz4TWC8ff3oyh5ZxeAeJwXehPKjzTZjlQ/LEqc4jiSAuEi
30
+ 85UVSWgrMaL5EfU0RRl4+6ZfY6KmrUI9Y4ZaV11zbtG76KO7qPGarfbfqA3XMRuP
31
+ fnNu6z0ydxzHCvBhE0pU4jDzxPTASZiyllpSpQgz9OX3DAlUgWFQLHmj1hGk6GH4
32
+ QldMu2GTc/3h2w==
33
+ -----END CERTIFICATE-----
34
+ date: 2015-11-21 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: gtk2
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.0'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.7
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.0'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 3.0.7
56
+ - !ruby/object:Gem::Dependency
57
+ name: dom_render
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.2'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.2.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.2'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.0
76
+ description:
77
+ email: james@r0bertson.co.uk
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/gtk2svg.rb
83
+ homepage: https://github.com/jrobertson/gtk2svg
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Experimental gem to render SVG using GTK2
107
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+
- �_T�I�K �Y�H�́,�t\�t�MG���9�8`��i1��e@J"\+oH+�}J)�K�����`�m�t�ͽ��1Q8��t5}�e�� @9�� '�"�e,��Y��=�34