r2dsvg 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data/lib/r2dsvg.rb +145 -0
- data.tar.gz.sig +0 -0
- metadata +130 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ace8319852e656e2f92b8277bf237679fd0607f475d8d3cf8202eaed8ed583d7
|
4
|
+
data.tar.gz: 55fa2c0ee725a5fd8c22ebac07d0d8cf0f54598c9934e2152ff6245a1386d85e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba05b63001637286b4d9adfbab2f8e3b39871b74933e513785e0fda4b860fcd6695952d56c01d2a0272566f9b6a59869219d74f531c9820ea05642e3026110e8
|
7
|
+
data.tar.gz: c39b551a7b759b376844352e0c8150c76c5a7b9d064a9e89d007f82b0e6e9589d44e5d561043de4a226bfa9ff427d9d32c7a3b720de80b7ef729fca38b049bca
|
checksums.yaml.gz.sig
ADDED
data/lib/r2dsvg.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: r2dsvg.rb
|
4
|
+
|
5
|
+
# Description: Experimental gem to render SVG within a Ruby2D application.
|
6
|
+
|
7
|
+
|
8
|
+
require 'svgle'
|
9
|
+
require 'ruby2d' # experimental gem depends upon simple2d binaries
|
10
|
+
require 'dom_render'
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
class R2dSvg
|
15
|
+
include Ruby2D
|
16
|
+
using ColouredText
|
17
|
+
|
18
|
+
class Render < DomRender
|
19
|
+
|
20
|
+
def rect(e, attributes, raw_style)
|
21
|
+
|
22
|
+
puts 'inside rect attributes: ' + attributes.inspect if @debug
|
23
|
+
style = style_filter(attributes).merge(raw_style)
|
24
|
+
h = attributes
|
25
|
+
|
26
|
+
x1, y1, width, height = %i(x y width height).map{|x| h[x].to_i }
|
27
|
+
x2, y2, = x1 + width, y1 + height
|
28
|
+
|
29
|
+
[:draw_rectangle, [x1, y1, x2, y2], style, render_all(e)]
|
30
|
+
end
|
31
|
+
|
32
|
+
def svg(e, attributes, raw_style)
|
33
|
+
|
34
|
+
style = style_filter(attributes).merge(raw_style)
|
35
|
+
|
36
|
+
h = attributes
|
37
|
+
width, height = %i(width height).map{|x| h[x].to_i }
|
38
|
+
|
39
|
+
[:draw_rectangle, [0, 0, width, height], style, render_all(e)]
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def style_filter(attributes)
|
45
|
+
|
46
|
+
%i(stroke stroke-width fill z-index).inject({}) do |r,x|
|
47
|
+
attributes.has_key?(x) ? r.merge(x => attributes[x]) : r
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
class DrawingInstructions
|
55
|
+
using ColouredText
|
56
|
+
|
57
|
+
attr_accessor :area
|
58
|
+
|
59
|
+
|
60
|
+
def initialize(window, debug: false)
|
61
|
+
|
62
|
+
@window, @debug = window, debug
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def draw_rectangle(args)
|
67
|
+
|
68
|
+
coords, style = args
|
69
|
+
|
70
|
+
x1, y1, x2, y2 = coords
|
71
|
+
|
72
|
+
if @debug then
|
73
|
+
puts 'inside draw_rectangle'.info
|
74
|
+
puts ('style: ' + style.inspect).debug
|
75
|
+
end
|
76
|
+
|
77
|
+
@window.add Rectangle.new(
|
78
|
+
x: x1, y: y1,
|
79
|
+
width: x2 - x1, height: y2 - y1,
|
80
|
+
color: style[:fill],
|
81
|
+
z: style[:"z-index"].to_i
|
82
|
+
)
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def window(args)
|
87
|
+
end
|
88
|
+
|
89
|
+
def render(a)
|
90
|
+
method(a[0]).call(args=a[1..2])
|
91
|
+
draw a[3]
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def draw(a)
|
98
|
+
|
99
|
+
a.each do |rawx|
|
100
|
+
|
101
|
+
x, *remaining = rawx
|
102
|
+
|
103
|
+
if x.is_a? Symbol then
|
104
|
+
method(x).call(args=remaining)
|
105
|
+
elsif x.is_a? String then
|
106
|
+
draw remaining
|
107
|
+
elsif x.is_a? Array
|
108
|
+
draw remaining
|
109
|
+
else
|
110
|
+
method(x).call(remaining.take 2)
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def initialize(svg, title: 'R2dSVG', debug: false)
|
120
|
+
|
121
|
+
@svg, @debug = svg, debug
|
122
|
+
doc = Svgle.new(svg, callback: self, debug: debug)
|
123
|
+
instructions = Render.new(doc, debug: debug).to_a
|
124
|
+
|
125
|
+
window = Window.new
|
126
|
+
drawing = DrawingInstructions.new window, debug: debug
|
127
|
+
puts ('instructions: ' + instructions.inspect).debug if @debug
|
128
|
+
|
129
|
+
@width, @height = %i(width height).map{|x| doc.root.attributes[x].to_i }
|
130
|
+
window.set title: title, width: @width, height: @height
|
131
|
+
|
132
|
+
drawing.render instructions
|
133
|
+
window.show
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
if __FILE__ == $0 then
|
139
|
+
|
140
|
+
# Read an SVG file
|
141
|
+
svg = File.read(ARGV[0])
|
142
|
+
|
143
|
+
app = R2dSvg.new svg
|
144
|
+
|
145
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: r2dsvg
|
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 CERTIFICAT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2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEAo6JZdBbBIo3dNWbnhXes7iMTe2KiX1LZqw0vPdSW
|
29
|
+
C4zrtVK4KSTH3fUcXS5BoevuuFlEDacX/LDFz44h1XKoRDUXnrcvJKky8l65O2ZE
|
30
|
+
RQynlQG0OQSxCEeuYnF6n8/4jUVWoWdVIwuQwNz06SvDL5mTfTHAupjcwRTQz2u8
|
31
|
+
r776IRslpFo7q5fQz9d3kWOTPnDlmJ4Gsakh30/vpWoprbTMuVawfTQlJz8UasPE
|
32
|
+
XgPn7jQA/mX4iqABzRDTg+lqbb2BOU3saWBK3vK7fh+a/cJ8OMmLrsMqMj4cUx7J
|
33
|
+
ZIVROhlwO0MAl6Cpa1rwq9FNz2tiq1cXGAd/oGa/K2PvEZop7upaz+ZvhnlC4Fne
|
34
|
+
TYnQ3G01gSZ88tRRFI24m/UgpKE8uQ9SnkHYcgPVXBbq3kTUqrTSsWjE3V7hN7bB
|
35
|
+
7avBPtmJXpQsK1kfdmXP/+tfAIa7KGseabm2+ntraqYNgx3DqyZur8IRdJFi/DPc
|
36
|
+
113q/9KjkLj6C+dR0HuLRW1c
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2019-02-24 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: svgle
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.4'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.4.4
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.4'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.4.4
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: ruby2d
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.8'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.8.1
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.8'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.8.1
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: dom_render
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - "~>"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0.3'
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.3.2
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.3'
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 0.3.2
|
100
|
+
description:
|
101
|
+
email: james@jamesrobertson.eu
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- lib/r2dsvg.rb
|
107
|
+
homepage: https://github.com/jrobertson/r2dsvg
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubygems_version: 3.0.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Experimental gem to render SVG within a Ruby2D application.
|
130
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|