svg_drawer 1.1.1 → 1.2.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: 3b5368262397aaec468e35d34f8932d36f15bd09
4
- data.tar.gz: cf2cc4742dcd2b630740ba83c42b55d5b7d6c37d
3
+ metadata.gz: 3ceac63b9d8ea76c14839b59bbc2ed3b6f850231
4
+ data.tar.gz: cfbf467db61ffc9aa75543b84e3c90c662ad5350
5
5
  SHA512:
6
- metadata.gz: eea2dde6b645e3b92855183e0bbdf442964ee978acd7d7aee1d97d89918eb12501698d5b891e3be10597e8e94d01c45ec0ab8cfe9029ddd83b7ee0b88f3b687b
7
- data.tar.gz: 657f3e7d46a77242e224bc02b756aef7cefd87c461649e032fd3f7857285f4c93093e340a477a946e6ecd071fa30a4b9c4944f5f0376241b731782379ee788bc
6
+ metadata.gz: e1978a112282787ae1adc5b8c9a954062cbb2ef93b617ed0694ec3439f0a0b2144b0d5924c409050a0ba75a75a24acc046c11cf02b2d534b23fb8dbe95d359e1
7
+ data.tar.gz: 26030034faf70f4d5d13e1144ea905d469d3d4f0855b82979b1c86d763485c1ad2df3e851ca7a3a410f5b6f6f7013a3bb78c93b71f3d605471fc10cfc7f04699
@@ -1,13 +1,14 @@
1
1
  module SvgDrawer
2
2
  class Image < Base
3
3
  # Required since there is no known way to calculate them
4
- requires :width
5
- requires :height
4
+ requires :img_width # raw image
5
+ requires :img_height # raw image
6
6
 
7
- # Retranslate ensures the parent element can correctly draw borders
8
- defaults scale: [1, 1],
9
- overflow: true,
10
- retranslate: false # true not supported
7
+ # x_reposition and y_reposition take effect only if viewport bounds are
8
+ # also given
9
+ defaults scale: 1,
10
+ x_reposition: false, # x
11
+ y_reposition: false # y
11
12
 
12
13
  def initialize(href, params = {})
13
14
  @href = href
@@ -15,11 +16,19 @@ module SvgDrawer
15
16
  end
16
17
 
17
18
  def width
18
- param(:width)
19
+ @width ||= width_unscaled * param(:scale).to_d
19
20
  end
20
21
 
21
22
  def height
22
- param(:height)
23
+ @height ||= height_unscaled * param(:scale).to_d
24
+ end
25
+
26
+ def width_unscaled
27
+ @width_unscaled ||= param(:img_width).to_d
28
+ end
29
+
30
+ def height_unscaled
31
+ @height_unscaled ||= param(:img_height).to_d
23
32
  end
24
33
 
25
34
  def incomplete
@@ -28,18 +37,26 @@ module SvgDrawer
28
37
 
29
38
  private
30
39
 
31
- def _draw(parent)
32
- # No idea how to find boundary coordinates
33
- raise NotImplementedError if param(:retranslate)
40
+ def viewport_width
41
+ param(:width) || width
42
+ end
34
43
 
35
- Utils::RasemWrapper.group(parent, class: 'image') do |image_group|
36
- w = param(:width) unless param(:overflow)
37
- h = param(:height) unless param(:overflow)
44
+ def viewport_height
45
+ param(:height) || height
46
+ end
47
+
48
+ # This scale comes from preserveAspectRatio which can't be disabled
49
+ # (librsvg crashes with OOM when preserveAspectRatio="none")
50
+ def autoscale
51
+ [width / param(:img_width), height / param(:img_height)].min
52
+ end
38
53
 
39
- res = image_group.image(nil, nil, w, h, @href)
40
- %i[x y width height].each { |k| res.attributes.delete(k) if res.attributes[k].blank? }
41
- res
42
- end.scale(*param(:scale))
54
+ def _draw(parent)
55
+ Utils::RasemWrapper.group(parent, class: 'image') do |image_group|
56
+ x = param(:x_reposition) ? (viewport_width / 2 - width_unscaled * autoscale / 2) / param(:scale) : 0
57
+ y = param(:y_reposition) ? (viewport_height / 2 - height_unscaled * autoscale / 2) / param(:scale) : 0
58
+ image_group.image(x, y, width_unscaled, height_unscaled, @href, preserveAspectRatio: 'xMinYMin meet')
59
+ end.scale(param(:scale), param(:scale))
43
60
  end
44
61
  end
45
62
  end
@@ -1,6 +1,5 @@
1
1
  module SvgDrawer
2
2
  class Line < Polyline
3
- # Retranslate ensures the parent element can correctly draw borders
4
3
  defaults Polyline.default_params
5
4
 
6
5
  def incomplete
@@ -9,7 +9,8 @@ module SvgDrawer
9
9
  stroke: 'none',
10
10
  scale: [1, 1],
11
11
  overflow: true, # false not supported
12
- retranslate: false # true not supported
12
+ x_reposition: false, # true not supported
13
+ y_reposition: false # true not supported
13
14
 
14
15
  def initialize(path_components, params = {})
15
16
  @components = path_components
@@ -35,7 +36,7 @@ module SvgDrawer
35
36
 
36
37
  def _draw(parent)
37
38
  # No idea how to find boundary coordinates
38
- raise NotImplementedError if param(:retranslate)
39
+ raise NotImplementedError if param(:x_reposition) || param(:y_reposition)
39
40
 
40
41
  style = {}
41
42
  style[:fill] = param(:fill)
@@ -1,3 +1,3 @@
1
1
  module SvgDrawer
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.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.1.1
4
+ version: 1.2.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-04-18 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rasem