gtk2svg 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/gtk2svg.rb +33 -42
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28a3f4511a21ce303b6e31768b3dc67885dcf014
|
4
|
+
data.tar.gz: a8d8a02c3e6b894e764a6d6b239b61e7e08bc2cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6ca9424567119773389548e48f14a975742473260e2dcb62a97d9fba6f241edfcba57341008acfe29db46fecd1da0b2c689df8ea61714124211ee048bb49965
|
7
|
+
data.tar.gz: 42ac8dcda9c90462ff0048c377887eec0168d19d3b1f66cd366ff4741fd4ca28f9e3595dfcd065a8e5994345debc081f93e68688616e5bd6536bd65228be1b2b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/gtk2svg.rb
CHANGED
@@ -9,27 +9,6 @@ require 'dom_render'
|
|
9
9
|
# Description: Experimental gem to render SVG within an GTK2 application.
|
10
10
|
# Currently it can only render rectangles along with the fill colour.
|
11
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
12
|
module Gtk2SVG
|
34
13
|
|
35
14
|
class Render < DomRender
|
@@ -64,6 +43,19 @@ module Gtk2SVG
|
|
64
43
|
|
65
44
|
[:draw_rectangle, [x1, y1, x2, y2], style, render_all(e)]
|
66
45
|
end
|
46
|
+
|
47
|
+
def text(e, attributes, style)
|
48
|
+
|
49
|
+
e2 = SVG::Element.new attributes, style
|
50
|
+
h = e2.attributes
|
51
|
+
style = e2.style.merge({font_size: '20'})
|
52
|
+
|
53
|
+
|
54
|
+
x, y, fill = %i(x y fill).map{|x| h[x] }
|
55
|
+
style.merge!({fill: fill})
|
56
|
+
|
57
|
+
[:draw_layout, [x.to_i, y.to_i], e.text, style, render_all(e)]
|
58
|
+
end
|
67
59
|
|
68
60
|
end
|
69
61
|
|
@@ -95,6 +87,22 @@ module Gtk2SVG
|
|
95
87
|
gc = gc_ini(fill: style[:fill] || :none)
|
96
88
|
@area.window.draw_rectangle(gc, 1, x1, y1, x2, y2)
|
97
89
|
end
|
90
|
+
|
91
|
+
def draw_layout(args)
|
92
|
+
|
93
|
+
coords, text, style = args
|
94
|
+
|
95
|
+
x, y = coords
|
96
|
+
|
97
|
+
|
98
|
+
layout = Pango::Layout.new(Gdk::Pango.context)
|
99
|
+
layout.font_description = Pango::FontDescription.\
|
100
|
+
new('Sans ' + style[:font_size])
|
101
|
+
layout.text = text
|
102
|
+
|
103
|
+
gc = gc_ini(fill: style[:fill] || :none)
|
104
|
+
@area.window.draw_layout(gc, x, y, layout)
|
105
|
+
end
|
98
106
|
|
99
107
|
def window(args)
|
100
108
|
end
|
@@ -112,8 +120,11 @@ module Gtk2SVG
|
|
112
120
|
x, *remaining = rawx
|
113
121
|
|
114
122
|
if x.is_a? Symbol then
|
115
|
-
|
123
|
+
puts 'sym'
|
124
|
+
puts 'remaining: ' + remaining.inspect
|
125
|
+
method(x).call(args=remaining[0..-2])
|
116
126
|
elsif x.is_a? String then
|
127
|
+
puts 'ff'
|
117
128
|
draw remaining
|
118
129
|
elsif x.is_a? Array
|
119
130
|
draw remaining
|
@@ -155,26 +166,6 @@ module Gtk2SVG
|
|
155
166
|
end
|
156
167
|
|
157
168
|
|
158
|
-
if __FILE__ == $0 then
|
159
|
-
|
160
|
-
# Read an SVG file
|
161
|
-
s = File.read(ARGV[0])
|
162
|
-
|
163
|
-
area = Gtk::DrawingArea.new
|
164
|
-
|
165
|
-
area.signal_connect("expose_event") do
|
166
|
-
|
167
|
-
drawing = Gtk2SVG::DrawingInstructions.new area
|
168
|
-
drawing.render Gtk2SVG::Render.new(s).to_a
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
Gtk::Window.new.add(area).show_all
|
173
|
-
Gtk.main
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
|
-
|
178
169
|
|
179
170
|
if __FILE__ == $0 then
|
180
171
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|