gtk2svg 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/gtk2svg.rb +49 -6
- 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: 7a28f74926618fa9722db12e05476fc6342d2158
|
4
|
+
data.tar.gz: a92730f4716da4152ce4a612a3baab5846efcbea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b87717bb3a542e397d90eda891d6b7e02b61d79badff3b2c5792b20855b6ec8ddfc705bca9e43608353e2d8b6f8a70eaf5e0b7482180af765e1b6f9e87f3d90
|
7
|
+
data.tar.gz: 954b8c6b99f1e36148d37edc39e75f496eacd42cfc6eb5dd01dae6df6f4154b2790b5f7024dfcd1822e28c2bcb1109ff1a297e80770d0d7c1eb4a3148407f1c2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/gtk2svg.rb
CHANGED
@@ -9,6 +9,28 @@ 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
|
+
|
13
|
+
module SVG
|
14
|
+
class Element
|
15
|
+
|
16
|
+
attr_reader :style
|
17
|
+
|
18
|
+
def initialize(attributes, style)
|
19
|
+
|
20
|
+
@h = {x: '0', y: '0'}.merge attributes
|
21
|
+
|
22
|
+
@style = {fill: 'black'}
|
23
|
+
@style.merge!(style) if attributes[:style]
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def attributes()
|
28
|
+
@h
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
12
34
|
module Gtk2SVG
|
13
35
|
|
14
36
|
class Render < DomRender
|
@@ -30,6 +52,18 @@ module Gtk2SVG
|
|
30
52
|
|
31
53
|
[:draw_arc, [x, y, width, height], style, render_all(e)]
|
32
54
|
end
|
55
|
+
|
56
|
+
def line(e, attributes, style)
|
57
|
+
|
58
|
+
e2 = SVG::Element.new attributes, style
|
59
|
+
h = e2.attributes
|
60
|
+
style = e2.style
|
61
|
+
style[:stroke_width] = style.delete(:'stroke-width') || '3'
|
62
|
+
|
63
|
+
x1, y1, x2, y2 = %i(x y x2 y2).map{|x| h[x].to_i }
|
64
|
+
|
65
|
+
[:draw_line, [x1, y1, x2, y2], style, render_all(e)]
|
66
|
+
end
|
33
67
|
|
34
68
|
def rect(e, attributes, style)
|
35
69
|
|
@@ -78,6 +112,17 @@ module Gtk2SVG
|
|
78
112
|
gc = gc_ini(fill: style[:fill] || :none)
|
79
113
|
@area.window.draw_arc(gc, 1, x, y, width, height, 0, 64 * 360)
|
80
114
|
end
|
115
|
+
|
116
|
+
def draw_line(args)
|
117
|
+
|
118
|
+
coords, style = args
|
119
|
+
|
120
|
+
x1, y1, x2, y2 = coords
|
121
|
+
gc = gc_ini(stroke: style[:stroke] || :none)
|
122
|
+
gc.set_line_attributes(style[:stroke_width].to_i, Gdk::GC::LINE_SOLID, \
|
123
|
+
Gdk::GC::CAP_NOT_LAST, Gdk::GC::JOIN_MITER)
|
124
|
+
@area.window.draw_line(gc, x1, y1, x2, y2)
|
125
|
+
end
|
81
126
|
|
82
127
|
def draw_rectangle(args)
|
83
128
|
|
@@ -120,11 +165,8 @@ module Gtk2SVG
|
|
120
165
|
x, *remaining = rawx
|
121
166
|
|
122
167
|
if x.is_a? Symbol then
|
123
|
-
|
124
|
-
puts 'remaining: ' + remaining.inspect
|
125
|
-
method(x).call(args=remaining[0..-2])
|
168
|
+
method(x).call(args=remaining)
|
126
169
|
elsif x.is_a? String then
|
127
|
-
puts 'ff'
|
128
170
|
draw remaining
|
129
171
|
elsif x.is_a? Array
|
130
172
|
draw remaining
|
@@ -155,9 +197,10 @@ module Gtk2SVG
|
|
155
197
|
colour
|
156
198
|
end
|
157
199
|
|
158
|
-
def gc_ini(fill:
|
200
|
+
def gc_ini(fill: nil, stroke: nil)
|
159
201
|
gc = Gdk::GC.new(area.window)
|
160
|
-
|
202
|
+
colour = fill || stroke
|
203
|
+
gc.set_foreground(set_colour(colour)) unless colour == :none
|
161
204
|
gc
|
162
205
|
end
|
163
206
|
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|