vectory 0.7.7 → 0.8.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/Gemfile +6 -9
- data/lib/vectory/datauri.rb +8 -1
- data/lib/vectory/image_resize.rb +98 -12
- data/lib/vectory/version.rb +1 -1
- data/vectory.gemspec +7 -6
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7ebbb9e4146780f1f9d42e0dee106494c251eb27b7d3f52d69f172da0a0d2e7
|
4
|
+
data.tar.gz: 132e451c7c1e9298f305f67a7103f8da8b7d5af3df371f5705e8a2eb95b59991
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33a7acbdacd776a6627d30a2641123743d325b3c5f89b3f1f40a244556b4f363c1c2a4b49458d2260014c53004a2d06a9c8d7f617e732f82457c30576e9c6085
|
7
|
+
data.tar.gz: 4a243d964fcda1b2d7e8dab7ef9bea706265c646d168d70df847bc6fd4d4e6c9f3453334adf4b0824670a59c029e4fa8a5812d4aecb4714298dfaa3425e1010a
|
data/Gemfile
CHANGED
@@ -5,12 +5,9 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in vectory.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "equivalent-xml"
|
9
|
-
|
10
|
-
gem "
|
11
|
-
|
12
|
-
gem "
|
13
|
-
|
14
|
-
gem "rubocop", "~> 1.22"
|
15
|
-
gem "rubocop-performance", "~> 1.10"
|
16
|
-
gem "rubocop-rails", "~> 2.9"
|
8
|
+
gem "equivalent-xml"
|
9
|
+
gem "rake"
|
10
|
+
gem "rspec"
|
11
|
+
gem "rubocop"
|
12
|
+
gem "rubocop-performance"
|
13
|
+
gem "rexml"
|
data/lib/vectory/datauri.rb
CHANGED
@@ -12,7 +12,14 @@ module Vectory
|
|
12
12
|
|
13
13
|
def self.from_vector(vector)
|
14
14
|
mimetype = vector.class.mimetype
|
15
|
-
content = vector.content
|
15
|
+
content = vector.content
|
16
|
+
|
17
|
+
# Normalize line endings for text-based types before encoding
|
18
|
+
# Apply to PS, EPS, and SVG. EMF is binary, so skip it.
|
19
|
+
if ["application/postscript", "image/svg+xml"].include?(vector.mime)
|
20
|
+
content = content.gsub("\r\n", "\n")
|
21
|
+
end
|
22
|
+
|
16
23
|
data = Base64.strict_encode64(content)
|
17
24
|
|
18
25
|
new("data:#{mimetype};base64,#{data}")
|
data/lib/vectory/image_resize.rb
CHANGED
@@ -6,6 +6,7 @@ module Vectory
|
|
6
6
|
|
7
7
|
def call(img, path, maxheight, maxwidth)
|
8
8
|
s, realsize = get_image_size(img, path)
|
9
|
+
# Ensure s[0] and s[1] are not nil before setting viewBox
|
9
10
|
img.name == "svg" && !img["viewBox"] && s[0] && s[1] and
|
10
11
|
img["viewBox"] = viewbox(s)
|
11
12
|
s, skip = image_dont_resize(s, realsize)
|
@@ -18,7 +19,8 @@ module Vectory
|
|
18
19
|
detected = detect_size(path)
|
19
20
|
realsize = detected if detected
|
20
21
|
s = image_size_interpret(img, realsize || [nil, nil])
|
21
|
-
image_size_zeroes_complete
|
22
|
+
# No call to image_size_zeroes_complete here
|
23
|
+
[s, realsize] # s should now be correctly populated
|
22
24
|
end
|
23
25
|
|
24
26
|
private
|
@@ -53,7 +55,11 @@ module Vectory
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def fill_size(current, another, real_current, real_another)
|
56
|
-
|
58
|
+
# Ensure 'current' and 'another' are not nil before calling zero?
|
59
|
+
# Also ensure real_another is not nil or zero to prevent division by zero
|
60
|
+
return current unless (current.nil? || current.zero?) &&
|
61
|
+
!(another.nil? || another.zero?) &&
|
62
|
+
!(real_another.nil? || real_another.zero?)
|
57
63
|
|
58
64
|
another * real_current / real_another
|
59
65
|
end
|
@@ -67,22 +73,102 @@ module Vectory
|
|
67
73
|
end
|
68
74
|
|
69
75
|
def image_size_interpret(img, realsize)
|
70
|
-
|
71
|
-
|
76
|
+
# Extract parent dimensions for percentage calculations
|
77
|
+
parent_w_px = realsize.is_a?(Array) && realsize.length > 0 ? realsize[0] : nil
|
78
|
+
parent_h_px = realsize.is_a?(Array) && realsize.length > 1 ? realsize[1] : nil
|
79
|
+
|
80
|
+
# Process width and height using the original css_size_to_px signature
|
81
|
+
w = css_size_to_px(img["width"], parent_w_px)
|
82
|
+
h = css_size_to_px(img["height"], parent_h_px)
|
83
|
+
|
84
|
+
# If attributes resulted in no dimensions, but realsize exists, use realsize.
|
85
|
+
# This brings back some of the logic from the removed image_size_zeroes_complete.
|
86
|
+
if w.nil? && h.nil? && realsize && !(realsize[0].nil? && realsize[1].nil?)
|
87
|
+
w = realsize[0]
|
88
|
+
h = realsize[1]
|
89
|
+
end
|
90
|
+
|
91
|
+
# If a dimension attribute led to a nil value (e.g. "auto", or "%" of nil parent)
|
92
|
+
# and the other dimension is resolved, default the nil dimension to 0.
|
93
|
+
if img["width"] && w.nil? && !h.nil?
|
94
|
+
w = 0
|
95
|
+
end
|
96
|
+
if img["height"] && h.nil? && !w.nil?
|
97
|
+
h = 0
|
98
|
+
end
|
99
|
+
|
72
100
|
[w, h]
|
73
101
|
end
|
74
102
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
103
|
+
# Enhanced version of image_size_percent that handles percentage calculations
|
104
|
+
# This is now a helper method for css_size_to_px
|
105
|
+
def image_size_percent(percentage_numeric_value, real_dimension)
|
106
|
+
return nil if real_dimension.nil? || percentage_numeric_value.nil?
|
107
|
+
|
108
|
+
# Calculates the dimension in pixels. The result is a float.
|
109
|
+
(real_dimension * (percentage_numeric_value / 100.0))
|
79
110
|
end
|
80
111
|
|
81
|
-
|
82
|
-
|
83
|
-
|
112
|
+
# New method from image_sizer.rb, incorporated directly into ImageResize
|
113
|
+
# Converts CSS length string to pixels.
|
114
|
+
def css_size_to_px(size_str, real_dimension_for_percentage, dpi: 96)
|
115
|
+
return nil unless size_str.is_a?(String)
|
116
|
+
|
117
|
+
cleaned_size_str = size_str.strip.downcase
|
118
|
+
|
119
|
+
# Handle keywords like "auto" which don't resolve to a numeric pixel value.
|
120
|
+
return nil if cleaned_size_str == "auto"
|
121
|
+
|
122
|
+
# Handle plain numbers (e.g., "150") as pixels.
|
123
|
+
if cleaned_size_str.match?(/^\d+(\.\d+)?$/)
|
124
|
+
return cleaned_size_str.to_f.to_i
|
125
|
+
end
|
126
|
+
|
127
|
+
# Match numeric value and unit (e.g., "10.5cm", "50%", "-5px").
|
128
|
+
match = cleaned_size_str.match(/^([-+]?[0-9]*\.?[0-9]+)([a-z%]+)$/)
|
129
|
+
unless match
|
130
|
+
# Not a plain number and not in "valueUnit" format
|
131
|
+
return nil
|
132
|
+
end
|
133
|
+
|
134
|
+
value = match[1].to_f
|
135
|
+
unit = match[2]
|
136
|
+
px_value = nil # This will store the calculated pixel value as a float.
|
137
|
+
|
138
|
+
case unit
|
139
|
+
when "px"
|
140
|
+
px_value = value
|
141
|
+
when "in"
|
142
|
+
px_value = value * dpi
|
143
|
+
when "cm"
|
144
|
+
px_value = value * dpi / 2.54
|
145
|
+
when "mm"
|
146
|
+
px_value = value * dpi / 25.4
|
147
|
+
when "pt" # 1 point = 1/72 inch
|
148
|
+
px_value = value * dpi / 72.0
|
149
|
+
when "pc" # 1 pica = 12 points
|
150
|
+
px_value = value * 12.0 * dpi / 72.0
|
151
|
+
when "%"
|
152
|
+
# Use the enhanced image_size_percent method
|
153
|
+
px_value = image_size_percent(value, real_dimension_for_percentage)
|
154
|
+
else
|
155
|
+
return nil # Unknown unit
|
156
|
+
end
|
157
|
+
|
158
|
+
return nil if px_value.nil?
|
159
|
+
|
160
|
+
# For 'px' and '%' units, truncate to match "integer conversion" expectation.
|
161
|
+
# For physical units, round to handle floating point inaccuracies correctly.
|
162
|
+
if ["px", "%"].include?(unit)
|
163
|
+
px_value.to_i
|
164
|
+
else
|
165
|
+
px_value.round
|
84
166
|
end
|
85
|
-
[dim, realsize]
|
86
167
|
end
|
168
|
+
|
169
|
+
# REMOVE the image_size_zeroes_complete method entirely if it's still present
|
170
|
+
# def image_size_zeroes_complete(dim, realsize)
|
171
|
+
# ...
|
172
|
+
# end
|
87
173
|
end
|
88
174
|
end
|
data/lib/vectory/version.rb
CHANGED
data/vectory.gemspec
CHANGED
@@ -23,12 +23,13 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
24
|
f.match(%r{^(bin|spec)/})
|
25
25
|
end
|
26
|
-
spec.test_files
|
26
|
+
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
|
27
27
|
spec.required_ruby_version = ">= 2.5.0"
|
28
28
|
|
29
|
-
spec.
|
30
|
-
spec.
|
31
|
-
spec.
|
32
|
-
spec.
|
33
|
-
spec.
|
29
|
+
spec.add_dependency "base64"
|
30
|
+
spec.add_dependency "emf2svg"
|
31
|
+
spec.add_dependency "image_size", ">= 3.2.0"
|
32
|
+
spec.add_dependency "marcel", "~> 1.0"
|
33
|
+
spec.add_dependency "nokogiri", "~> 1.14"
|
34
|
+
spec.add_dependency "thor", "~> 1.0"
|
34
35
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vectory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: base64
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: emf2svg
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +138,7 @@ homepage: https://github.com/metanorma/vectory
|
|
124
138
|
licenses:
|
125
139
|
- BSD-2-Clause
|
126
140
|
metadata: {}
|
127
|
-
post_install_message:
|
141
|
+
post_install_message:
|
128
142
|
rdoc_options: []
|
129
143
|
require_paths:
|
130
144
|
- lib
|
@@ -139,8 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
153
|
- !ruby/object:Gem::Version
|
140
154
|
version: '0'
|
141
155
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
143
|
-
signing_key:
|
156
|
+
rubygems_version: 3.5.22
|
157
|
+
signing_key:
|
144
158
|
specification_version: 4
|
145
159
|
summary: Pairwise vector image conversions.
|
146
160
|
test_files: []
|