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 +4 -4
- data/lib/svg_drawer/image.rb +35 -18
- data/lib/svg_drawer/line.rb +0 -1
- data/lib/svg_drawer/path.rb +3 -2
- data/lib/svg_drawer/version.rb +1 -1
- 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: 3ceac63b9d8ea76c14839b59bbc2ed3b6f850231
|
4
|
+
data.tar.gz: cfbf467db61ffc9aa75543b84e3c90c662ad5350
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1978a112282787ae1adc5b8c9a954062cbb2ef93b617ed0694ec3439f0a0b2144b0d5924c409050a0ba75a75a24acc046c11cf02b2d534b23fb8dbe95d359e1
|
7
|
+
data.tar.gz: 26030034faf70f4d5d13e1144ea905d469d3d4f0855b82979b1c86d763485c1ad2df3e851ca7a3a410f5b6f6f7013a3bb78c93b71f3d605471fc10cfc7f04699
|
data/lib/svg_drawer/image.rb
CHANGED
@@ -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 :
|
5
|
-
requires :
|
4
|
+
requires :img_width # raw image
|
5
|
+
requires :img_height # raw image
|
6
6
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
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(:
|
19
|
+
@width ||= width_unscaled * param(:scale).to_d
|
19
20
|
end
|
20
21
|
|
21
22
|
def height
|
22
|
-
param(:
|
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
|
32
|
-
|
33
|
-
|
40
|
+
def viewport_width
|
41
|
+
param(:width) || width
|
42
|
+
end
|
34
43
|
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
data/lib/svg_drawer/line.rb
CHANGED
data/lib/svg_drawer/path.rb
CHANGED
@@ -9,7 +9,8 @@ module SvgDrawer
|
|
9
9
|
stroke: 'none',
|
10
10
|
scale: [1, 1],
|
11
11
|
overflow: true, # false not supported
|
12
|
-
|
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(:
|
39
|
+
raise NotImplementedError if param(:x_reposition) || param(:y_reposition)
|
39
40
|
|
40
41
|
style = {}
|
41
42
|
style[:fill] = param(:fill)
|
data/lib/svg_drawer/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rasem
|