phantom_svg 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83b2989f948845f7d83da71c019ec9797badc74f
4
- data.tar.gz: d808e2f5115912c81d87e171fdb20fb5d386df7f
3
+ metadata.gz: 18f99a7628287a82ef66f940b39600f89297d9e2
4
+ data.tar.gz: c2bd3e70192b8e27330905329355a86794e64e9a
5
5
  SHA512:
6
- metadata.gz: eab25f3be99ae749af2c4dd001e95d3ea2ac8d44564edfea46ad36806ac3442cc2c5b56aa142d0eab91355ad79bb108d0c60e648129627cf9eb1d1c4fb9e24c3
7
- data.tar.gz: aa79742a536b34f8fa45180636867c33a305af669591814cf6736543d442666a01174ae94fcb22004523775fccbe4f7180e162b2a1016378fa3ad6a05724063d
6
+ metadata.gz: 350c5c93b3691d385b5b4c8152cbb488b36869c66b2e89c5c479084cb6f76d5985c17b8575b5ced6b72a437dc801d0b2fddb33658353a759a9e2884f0440028f
7
+ data.tar.gz: ef0dcd3d8ffb2ea1a77db9ca7bff109c1ca7f65d31be7a4352599a97d8c8cf2ee753e3ad4a85817a7632100ce4ed6104442a064f60b5da3fee7da4ed154d6253
@@ -56,10 +56,10 @@ module Phantom
56
56
 
57
57
  def set_viewbox(val)
58
58
  @viewbox =
59
- if val.nil? then ViewBox.new
59
+ if val.nil? then ViewBox.new(0, 0, @width, @height)
60
60
  elsif val.is_a?(ViewBox) then val
61
61
  elsif val.is_a?(String) then ViewBox.new.set_from_text(val)
62
- else ViewBox.new
62
+ else ViewBox.new(0, 0, @width, @height)
63
63
  end
64
64
  end
65
65
 
@@ -25,7 +25,7 @@ module Phantom
25
25
  def create_frame_from_png(path, id, duration = nil)
26
26
  pixbuf = Gdk::Pixbuf.new(path)
27
27
 
28
- frame = Phantom::SVG::Frame.new
28
+ frame = Phantom::SVG::Frame.new( { width: pixbuf.width, height: pixbuf.height } )
29
29
  frame.width = "#{pixbuf.width}px"
30
30
  frame.height = "#{pixbuf.height}px"
31
31
  frame.surfaces = create_surfaces(path, pixbuf.width, pixbuf.height)
@@ -64,15 +64,18 @@ module Phantom
64
64
 
65
65
  # Read size from node to dest.
66
66
  def read_size(node, dest, options = {})
67
- node.attributes.each do |key, val|
68
- case key
69
- when 'width'
70
- dest.instance_variable_set(:@width, choice_value(val, options[:width]))
71
- when 'height'
72
- dest.instance_variable_set(:@height, choice_value(val, options[:height]))
73
- when 'viewBox'
74
- dest.viewbox.set_from_text(choice_value(val, options[:viewbox]).to_s)
75
- end
67
+ dest.viewbox.set_from_text(choice_value(node.attributes['viewBox'], options[:viewbox]).to_s) unless node.attributes['viewBox'].nil?
68
+
69
+ if node.attributes['width'].nil? then
70
+ dest.instance_variable_set(:@width, choice_value("#{dest.viewbox.width}px", options[:width]))
71
+ else
72
+ dest.instance_variable_set(:@width, choice_value(node.attributes['width'], options[:width]))
73
+ end
74
+
75
+ if node.attributes['height'].nil? then
76
+ dest.instance_variable_set(:@height, choice_value("#{dest.viewbox.height}px", options[:height]))
77
+ else
78
+ dest.instance_variable_set(:@height, choice_value(node.attributes['height'], options[:height]))
76
79
  end
77
80
  end
78
81
 
@@ -69,6 +69,10 @@ module Phantom
69
69
  def write_size(s, d)
70
70
  d.add_attribute('width', s.width.is_a?(String) ? s.width : "#{s.width.to_i}px")
71
71
  d.add_attribute('height', s.height.is_a?(String) ? s.height : "#{s.height.to_i}px")
72
+ end
73
+
74
+ # Write viewbox.
75
+ def write_viewbox(s, d)
72
76
  d.add_attribute('viewBox', s.viewbox.to_s) if s.instance_variable_defined?(:@viewbox)
73
77
  end
74
78
 
@@ -90,7 +94,9 @@ module Phantom
90
94
  def write_image(frame, parent_node, id = nil)
91
95
  svg = parent_node.add_element('svg')
92
96
  svg.add_attribute('id', id) unless id.nil?
93
- write_size(frame, svg)
97
+ write_size(frame, svg) if parent_node == @root
98
+ write_viewbox(frame, svg)
99
+ svg.add_attribute('preserveAspectRatio', 'none')
94
100
  write_namespaces(frame, svg)
95
101
  write_surfaces(frame.surfaces, svg)
96
102
  end
@@ -51,8 +51,8 @@ module Phantom
51
51
  @width = 0
52
52
  @height = 0
53
53
  frames.each do |frame|
54
- @width = frame.width.to_f if frame.width.to_f > @width
55
- @height = frame.height.to_f if frame.height.to_f > @height
54
+ @width = frame.width.to_i if frame.width.to_i > @width
55
+ @height = frame.height.to_i if frame.height.to_i > @height
56
56
  end
57
57
  end
58
58
 
@@ -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.0.3'
4
+ s.version = '1.0.4'
5
5
  s.license = 'LGPL-3.0'
6
6
  s.summary = 'Hight end SVG manipulation tools for Ruby'
7
7
  s.description = 'Hight end SVG manipulation tools for Ruby.\n' \
@@ -195,8 +195,19 @@ describe Phantom::SVG::Base do
195
195
 
196
196
  it 'successfully converts.' do
197
197
  expect(@loader.frames.size).to eq(12)
198
- is_succeeded = @loader.save_apng(@destination)
199
- expect(is_succeeded).to eq(true)
198
+ expect(@loader.save_apng(@destination)).to eq(true)
199
+ end
200
+
201
+ it 'stretches horizontally' do
202
+ expect(@loader.frames.size).to eq(12)
203
+ @loader.width = 128
204
+ expect(@loader.save_apng("#{SPEC_TEMP_DIR}/svg2apng_h.png")).to eq(true)
205
+ end
206
+
207
+ it 'stretches vertically' do
208
+ expect(@loader.frames.size).to eq(12)
209
+ @loader.height = 128
210
+ expect(@loader.save_apng("#{SPEC_TEMP_DIR}/svg2apng_v.png")).to eq(true)
200
211
  end
201
212
  end
202
213
 
@@ -213,6 +224,79 @@ describe Phantom::SVG::Base do
213
224
  @loader = Phantom::SVG::Base.new
214
225
  end
215
226
 
227
+ it 'loads and saves PNG.' do
228
+ @loader.add_frame_from_file("#{SPEC_SOURCE_DIR}/test_raster.png")
229
+ expect(@loader.frames.size).to eq(1)
230
+ expect(@loader.frames.first.width).to eq("256px")
231
+ expect(@loader.frames.first.height).to eq("128px")
232
+ expect(@loader.frames.first.viewbox.width).to eq(256)
233
+ expect(@loader.frames.first.viewbox.height).to eq(128)
234
+
235
+ write_size = @loader.save_svg("#{SPEC_TEMP_DIR}/static_same.svg")
236
+ expect(write_size).not_to eq(0)
237
+ @loader.width = 64
238
+ @loader.height = 32
239
+ write_size = @loader.save_svg("#{SPEC_TEMP_DIR}/static_scaled.svg")
240
+ expect(write_size).not_to eq(0)
241
+ end
242
+
243
+ it 'loads and saves an irrigularly proportioned PNG' do
244
+ @loader.add_frame_from_file("#{SPEC_SOURCE_DIR}/small_v_raster.png")
245
+ expect(@loader.frames.size).to eq(1)
246
+ expect(@loader.frames.first.width).to eq("33px")
247
+ expect(@loader.frames.first.height).to eq("54px")
248
+ expect(@loader.frames.first.viewbox.width).to eq(33)
249
+ expect(@loader.frames.first.viewbox.height).to eq(54)
250
+
251
+ write_size = @loader.save_svg("#{SPEC_TEMP_DIR}/small_v_same.svg")
252
+ expect(write_size).not_to eq(0)
253
+
254
+ @loader.width = 64
255
+ @loader.height = 32
256
+ write_size = @loader.save_svg("#{SPEC_TEMP_DIR}/small_v_scaled.svg")
257
+ expect(write_size).not_to eq(0)
258
+ end
259
+
260
+ it 'loads an APNG and saves a smaller APNG.' do
261
+ @loader.add_frame_from_file(@source)
262
+ expect(@loader.frames.size).to eq(34)
263
+
264
+ @loader.width = 12
265
+ @loader.height = 12
266
+ write_size = @loader.save_apng("#{SPEC_TEMP_DIR}/apng_scaled.png")
267
+ expect(write_size).not_to eq(0)
268
+ end
269
+
270
+ it 'loads an APNG and saves a bigger APNG.' do
271
+ @loader.add_frame_from_file(@source)
272
+ expect(@loader.frames.size).to eq(34)
273
+
274
+ @loader.width = 128
275
+ @loader.height = 128
276
+ write_size = @loader.save_apng("#{SPEC_TEMP_DIR}/apng_scaled_up.png")
277
+ expect(write_size).not_to eq(0)
278
+ end
279
+
280
+ it 'loads an APNG and saves a horizontally stretched APNG.' do
281
+ @loader.add_frame_from_file(@source)
282
+ expect(@loader.frames.size).to eq(34)
283
+
284
+ @loader.width = 80
285
+ @loader.height = 20
286
+ write_size = @loader.save_apng("#{SPEC_TEMP_DIR}/apng_h_stretched.png")
287
+ expect(write_size).not_to eq(0)
288
+ end
289
+
290
+ it 'loads an APNG and saves a vertically stretched APNG.' do
291
+ @loader.add_frame_from_file(@source)
292
+ expect(@loader.frames.size).to eq(34)
293
+
294
+ @loader.width = 20
295
+ @loader.height = 80
296
+ write_size = @loader.save_apng("#{SPEC_TEMP_DIR}/apng_v_stretched.png")
297
+ expect(write_size).not_to eq(0)
298
+ end
299
+
216
300
  it 'loads an APNG and saves a keyframe animated SVG.' do
217
301
  @loader.add_frame_from_file(@source)
218
302
  expect(@loader.frames.size).to eq(34)
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.0.3
4
+ version: 1.0.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-09-12 00:00:00.000000000 Z
13
+ date: 2014-09-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: cairo
@@ -82,6 +82,7 @@ files:
82
82
  - spec/images/apngasm.png
83
83
  - spec/images/compiled.svg
84
84
  - spec/images/plain.svg
85
+ - spec/images/small_v_raster.png
85
86
  - spec/images/test_frames/0.svg
86
87
  - spec/images/test_frames/1.svg
87
88
  - spec/images/test_frames/10.svg
@@ -102,6 +103,7 @@ files:
102
103
  - spec/images/test_frames/test1.xml
103
104
  - spec/images/test_frames/test2.json
104
105
  - spec/images/test_frames/test2.xml
106
+ - spec/images/test_raster.png
105
107
  - spec/phantom/svg_spec.rb
106
108
  - spec/spec_helper.rb
107
109
  homepage: http://github.com/Genshin/phantom_svg
@@ -133,6 +135,7 @@ test_files:
133
135
  - spec/images/apngasm.png
134
136
  - spec/images/compiled.svg
135
137
  - spec/images/plain.svg
138
+ - spec/images/small_v_raster.png
136
139
  - spec/images/test_frames/0.svg
137
140
  - spec/images/test_frames/1.svg
138
141
  - spec/images/test_frames/10.svg
@@ -153,6 +156,7 @@ test_files:
153
156
  - spec/images/test_frames/test1.xml
154
157
  - spec/images/test_frames/test2.json
155
158
  - spec/images/test_frames/test2.xml
159
+ - spec/images/test_raster.png
156
160
  - spec/phantom/svg_spec.rb
157
161
  - spec/spec_helper.rb
158
162
  has_rdoc: