svg_drawer 1.2.1 → 1.3.0

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: e20b212c8dbf5477c1958ababd22b93d25fef505
4
- data.tar.gz: 38f8d9d0dd4784aa176443009a3130f2da2f1518
3
+ metadata.gz: 471c99db15c507a7b6bdc120cf2979958aae4bb0
4
+ data.tar.gz: 3def8fc5dd2475c4566ca1f6c75d354a8c563e36
5
5
  SHA512:
6
- metadata.gz: 95b7f567b0d5f3b2b624c9978ae699812d65af2e5e469c70fb89ec39873550936762a6801f584a6fa5923d709af719acadf3e1603b4dc1bd506e36a7c76ad5d1
7
- data.tar.gz: c20c30a31b676d3d091401f88228ae43a693701ccc1f97c94f2fc90d1343c2a4e47d4d2a1541c694a297a91b7392a3907c750ea7e96e9cbc307cd4f31b266c28
6
+ metadata.gz: 830d1a7b4cce489dc7c3ae0b99601cba395a6864a0ab8bfe2c234043488189a2fbb42b8be59e73bd771f3e782a3f384736162c675089f346ed2d895eac6b1eab
7
+ data.tar.gz: 7acfdd098d2c7f18136ec42d0c6e01b8ca5d4040969fd923a1c0d305ec9ad6cf0417e4651e9e36202b663145b5e024ab0609d198337a61c9f8b2e3b43b7011dd
@@ -1,31 +1,41 @@
1
1
  module SvgDrawer
2
2
  class Path < Base
3
3
  # Required since there is no known way to calculate them
4
- requires :width
5
- requires :height
4
+ # requires :width
5
+ # requires :height
6
+
7
+ requires :img_width # raw image
8
+ requires :img_height # raw image
6
9
 
7
10
  # Retranslate ensures the parent element can correctly draw borders
11
+ # x_reposition and y_reposition take effect only if viewport bounds are
12
+ # also given
8
13
  defaults fill: 'black',
9
14
  stroke: 'none',
10
- scale: [1, 1],
15
+ scale: 1,
11
16
  overflow: true, # false not supported
12
- x_reposition: false, # true not supported
13
- y_reposition: false # true not supported
17
+ x_reposition: false, # x
18
+ y_reposition: false # y
14
19
 
15
20
  def initialize(path_components, params = {})
16
21
  @components = path_components
17
22
  super(params)
18
23
  end
19
24
 
20
- # No idea how to compute dimensions for paths
21
25
  def width
22
- raise NotImplementedError unless param(:overflow)
23
- param(:width)
26
+ @width ||= width_unscaled * param(:scale).to_d
24
27
  end
25
28
 
26
29
  def height
27
- raise NotImplementedError unless param(:overflow)
28
- param(:height)
30
+ @height ||= height_unscaled * param(:scale).to_d
31
+ end
32
+
33
+ def width_unscaled
34
+ @width_unscaled ||= param(:img_width).to_d
35
+ end
36
+
37
+ def height_unscaled
38
+ @height_unscaled ||= param(:img_height).to_d
29
39
  end
30
40
 
31
41
  def incomplete
@@ -34,17 +44,31 @@ module SvgDrawer
34
44
 
35
45
  private
36
46
 
37
- def _draw(parent)
38
- # No idea how to find boundary coordinates
39
- raise NotImplementedError if param(:x_reposition) || param(:y_reposition)
47
+ def viewport_width
48
+ param(:width) || width
49
+ end
40
50
 
51
+ def viewport_height
52
+ param(:height) || height
53
+ end
54
+
55
+ # This scale comes from preserveAspectRatio which can't be disabled
56
+ # (librsvg crashes with OOM when preserveAspectRatio="none")
57
+ def autoscale
58
+ [width / param(:img_width), height / param(:img_height)].min
59
+ end
60
+
61
+ def _draw(parent)
41
62
  style = {}
42
63
  style[:fill] = param(:fill)
43
64
  style[:stroke] = param(:stroke)
44
65
 
66
+ x = param(:x_reposition) ? (viewport_width / 2 - width_unscaled * autoscale / 2) / param(:scale) : 0
67
+ y = param(:y_reposition) ? (viewport_height / 2 - height_unscaled * autoscale / 2) / param(:scale) : 0
68
+
45
69
  Utils::RasemWrapper.group(parent, class: 'path') do |path_group|
46
70
  @components.each { |path| path_group.path(d: path, style: style) }
47
- end.scale(*param(:scale))
71
+ end.scale(param(:scale), param(:scale)).translate(x, y)
48
72
  end
49
73
  end
50
74
  end
@@ -1,3 +1,3 @@
1
1
  module SvgDrawer
2
- VERSION = '1.2.1'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svg_drawer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simeon Manolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-13 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rasem