svg_drawer 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/svg_drawer/path.rb +38 -14
- 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: 471c99db15c507a7b6bdc120cf2979958aae4bb0
|
4
|
+
data.tar.gz: 3def8fc5dd2475c4566ca1f6c75d354a8c563e36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 830d1a7b4cce489dc7c3ae0b99601cba395a6864a0ab8bfe2c234043488189a2fbb42b8be59e73bd771f3e782a3f384736162c675089f346ed2d895eac6b1eab
|
7
|
+
data.tar.gz: 7acfdd098d2c7f18136ec42d0c6e01b8ca5d4040969fd923a1c0d305ec9ad6cf0417e4651e9e36202b663145b5e024ab0609d198337a61c9f8b2e3b43b7011dd
|
data/lib/svg_drawer/path.rb
CHANGED
@@ -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:
|
15
|
+
scale: 1,
|
11
16
|
overflow: true, # false not supported
|
12
|
-
x_reposition: false, #
|
13
|
-
y_reposition: false #
|
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
|
-
|
23
|
-
param(:width)
|
26
|
+
@width ||= width_unscaled * param(:scale).to_d
|
24
27
|
end
|
25
28
|
|
26
29
|
def height
|
27
|
-
|
28
|
-
|
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
|
38
|
-
|
39
|
-
|
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(
|
71
|
+
end.scale(param(:scale), param(:scale)).translate(x, y)
|
48
72
|
end
|
49
73
|
end
|
50
74
|
end
|
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.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-
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rasem
|