phantom_svg 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phantom/parser/svg_reader.rb +8 -3
- data/lib/phantom/parser/svg_writer.rb +38 -7
- data/phantom_svg.gemspec +1 -1
- data/spec/phantom/svg_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c42b5be52455df5b37f7f06f30590034d4b84ac6
|
4
|
+
data.tar.gz: b4dd3009aeff4f919bb0da11c51773b41849d69e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab8b940f3537dd56977e5dce4fc7a2dae33173c6824e495941623efcc13319a3b930aa0a02087e026920e2b2a47005ea6d849444161ca547e3af7172bc56df53
|
7
|
+
data.tar.gz: 60d30a0a6c905e1f7d56a1173ccaf1625c10bd166f2c46919125fa0287d62d9eea6ea1286e360757a576eab579a113c81b626bd1cc4b053c8416ce320f1e0efb
|
@@ -103,13 +103,17 @@ module Phantom
|
|
103
103
|
|
104
104
|
# Read skip_first.
|
105
105
|
def read_skip_first
|
106
|
-
|
106
|
+
use = @root.elements['svg/defs/symbol/use']
|
107
|
+
@skip_first = use.nil? ? @frames.size > 1 : use.attributes['xlink:href'] != '#frame0'
|
107
108
|
end
|
108
109
|
|
109
110
|
# Read frame durations.
|
110
111
|
def read_durations(options)
|
112
|
+
symbol = @root.elements['svg/defs/symbol']
|
113
|
+
return if symbol.nil?
|
114
|
+
|
111
115
|
i = @skip_first ? 1 : 0
|
112
|
-
|
116
|
+
symbol.elements.each('use') do |use|
|
113
117
|
duration = use.elements['set'].attributes['dur'].to_f
|
114
118
|
@frames[i].duration = choice_value(duration, options[:duration])
|
115
119
|
i += 1
|
@@ -118,7 +122,8 @@ module Phantom
|
|
118
122
|
|
119
123
|
# Read animation loop count.
|
120
124
|
def read_loops
|
121
|
-
|
125
|
+
animate = @root.elements['svg/animate']
|
126
|
+
@loops = animate.nil? ? 0 : animate.attributes['repeatCount'].to_i
|
122
127
|
end
|
123
128
|
|
124
129
|
# Helper method.
|
@@ -17,10 +17,7 @@ module Phantom
|
|
17
17
|
reset
|
18
18
|
|
19
19
|
# Parse object.
|
20
|
-
|
21
|
-
elsif object.is_a?(Frame) then write_svg(object)
|
22
|
-
else return 0
|
23
|
-
end
|
20
|
+
return 0 unless write_proc(object)
|
24
21
|
|
25
22
|
# Add svg version.
|
26
23
|
@root.elements['svg'].add_attribute('version', '1.1')
|
@@ -39,6 +36,20 @@ module Phantom
|
|
39
36
|
@root << REXML::Comment.new(' Generated by phantom_svg. ')
|
40
37
|
end
|
41
38
|
|
39
|
+
# Write procedure.
|
40
|
+
def write_proc(object)
|
41
|
+
if object.is_a?(Base)
|
42
|
+
if object.frames.size == 1 then write_svg(object.frames[0])
|
43
|
+
elsif object.frames.size > 1 then write_animation_svg(object)
|
44
|
+
else return false
|
45
|
+
end
|
46
|
+
elsif object.is_a?(Frame) then write_svg(object)
|
47
|
+
else return false
|
48
|
+
end
|
49
|
+
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
42
53
|
# Write no animation svg.
|
43
54
|
def write_svg(frame)
|
44
55
|
write_image(frame, @root)
|
@@ -109,6 +120,8 @@ module Phantom
|
|
109
120
|
|
110
121
|
# Write animation.
|
111
122
|
def write_animation(base, parent_node)
|
123
|
+
return if skip_frame_and_no_animation?(base)
|
124
|
+
|
112
125
|
REXML::Comment.new(' Animation. ', parent_node)
|
113
126
|
symbol = parent_node.add_element('symbol', 'id' => 'animation')
|
114
127
|
|
@@ -137,8 +150,12 @@ module Phantom
|
|
137
150
|
def write_show_control(base, parent_node)
|
138
151
|
REXML::Comment.new(' Main control. ', parent_node)
|
139
152
|
|
140
|
-
|
141
|
-
|
153
|
+
if skip_frame_and_no_animation?(base)
|
154
|
+
write_show_control_main_2(parent_node)
|
155
|
+
else
|
156
|
+
write_show_control_header(base, parent_node)
|
157
|
+
write_show_control_main(base, parent_node)
|
158
|
+
end
|
142
159
|
end
|
143
160
|
|
144
161
|
# Write show control header.
|
@@ -164,6 +181,15 @@ module Phantom
|
|
164
181
|
'begin' => 'controller.end')
|
165
182
|
end
|
166
183
|
|
184
|
+
# Write show control main.
|
185
|
+
def write_show_control_main_2(parent_node)
|
186
|
+
use = parent_node.add_element('use', 'xlink:href' => '#frame0')
|
187
|
+
|
188
|
+
use.add_element('set', 'attributeName' => 'xlink:href',
|
189
|
+
'to' => '#frame1',
|
190
|
+
'begin' => '0s')
|
191
|
+
end
|
192
|
+
|
167
193
|
# Convert id.
|
168
194
|
def convert_id_to_unique(root_node, prefix)
|
169
195
|
id_array = []
|
@@ -186,7 +212,7 @@ module Phantom
|
|
186
212
|
# Overwrite relative id in surfaces.
|
187
213
|
def overwrite_relative_id(parent_node, prefix, id_array)
|
188
214
|
parent_node.elements.each do |child|
|
189
|
-
child.attributes.each do |
|
215
|
+
child.attributes.each do |_, val|
|
190
216
|
id_array.each do |id|
|
191
217
|
val.gsub!("##{id}", "##{prefix}#{id}")
|
192
218
|
end
|
@@ -194,6 +220,11 @@ module Phantom
|
|
194
220
|
overwrite_relative_id(child, prefix, id_array)
|
195
221
|
end
|
196
222
|
end
|
223
|
+
|
224
|
+
# If base has skip frame and no animation, return true.
|
225
|
+
def skip_frame_and_no_animation?(base)
|
226
|
+
base.skip_first == true && base.frames.size == 2
|
227
|
+
end
|
197
228
|
end # class SVGWriter
|
198
229
|
end # module Parser
|
199
230
|
end # module SVG
|
data/phantom_svg.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.platform = Gem::Platform::RUBY
|
3
3
|
s.name = 'phantom_svg'
|
4
|
-
s.version = '1.1.
|
4
|
+
s.version = '1.1.4'
|
5
5
|
s.license = 'LGPL-3'
|
6
6
|
s.summary = 'Hight end SVG manipulation tools for Ruby'
|
7
7
|
s.description = 'Hight end SVG manipulation tools for Ruby.\n' \
|
data/spec/phantom/svg_spec.rb
CHANGED
@@ -582,5 +582,22 @@ describe Phantom::SVG::Base do
|
|
582
582
|
@loader.add_frame_from_file(source)
|
583
583
|
@loader.save_svg(destination)
|
584
584
|
end
|
585
|
+
|
586
|
+
it 'output no animation svg.' do
|
587
|
+
test_name = 'no_animation_test'
|
588
|
+
source = "#{@source_dir}/gradation_test/0.svg"
|
589
|
+
destination = "#{@destination_dir}/#{test_name}.svg"
|
590
|
+
@loader.add_frame_from_file(source)
|
591
|
+
@loader.save_svg(destination)
|
592
|
+
end
|
593
|
+
|
594
|
+
it 'output no animation and has skip frame svg.' do
|
595
|
+
test_name = 'no_animation_and has_skip_frame_test'
|
596
|
+
destination = "#{@destination_dir}/#{test_name}.svg"
|
597
|
+
@loader.add_frame_from_file("#{@source_dir}/test_frames/0.svg")
|
598
|
+
@loader.add_frame_from_file("#{@source_dir}/gradation_test/0.svg")
|
599
|
+
@loader.skip_first = true
|
600
|
+
@loader.save_svg(destination)
|
601
|
+
end
|
585
602
|
end
|
586
603
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantom_svg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rika Yoshida
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: cairo
|