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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4766f919c6d0611e918d6f98bc2c5da4da95fb5399990b4e3884cff0b364f149
4
- data.tar.gz: 2716d9cbbe94669080f8ba64063d41c1d1abeef7165409811d486c5ab2a9823e
3
+ metadata.gz: d7ebbb9e4146780f1f9d42e0dee106494c251eb27b7d3f52d69f172da0a0d2e7
4
+ data.tar.gz: 132e451c7c1e9298f305f67a7103f8da8b7d5af3df371f5705e8a2eb95b59991
5
5
  SHA512:
6
- metadata.gz: dce04edf8b7f050236a5c7e73a3f3923e0ce7ef87745600ad68a8bcbcaff1665ce5fa362201848a8a1a681179191f50f62be650f71ba7dd00494756c178e22f0
7
- data.tar.gz: 1ec04a35841dc06e62b5e44baeac1cbe7eccd38f5f4b910ebf282b0e58709f00fff0110ffc29f544a9c5a3711a7bab1a2a35324bdbc03a78943a6afa90638c7b
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", "~> 0.6"
9
-
10
- gem "rake", "~> 13.0"
11
-
12
- gem "rspec", "~> 3.0"
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"
@@ -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.gsub("\r\n", "\n")
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}")
@@ -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(s, realsize)
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
- return current unless current.zero? && !another.zero?
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
- w = image_size_percent(img["width"], realsize[0])
71
- h = image_size_percent(img["height"], realsize[1])
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
- def image_size_percent(value, real)
76
- /%$/.match?(value) && !real.nil? and
77
- value = real * (value.sub(/%$/, "").to_f / 100)
78
- value.to_i
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
- def image_size_zeroes_complete(dim, realsize)
82
- if dim[0].zero? && dim[1].zero?
83
- dim = realsize
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vectory
4
- VERSION = "0.7.7"
4
+ VERSION = "0.8.0"
5
5
  end
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 = `git ls-files -- {spec}/*`.split("\n")
26
+ spec.test_files = `git ls-files -- {spec}/*`.split("\n")
27
27
  spec.required_ruby_version = ">= 2.5.0"
28
28
 
29
- spec.add_runtime_dependency "emf2svg"
30
- spec.add_runtime_dependency "image_size", ">= 3.2.0"
31
- spec.add_runtime_dependency "marcel", "~> 1.0"
32
- spec.add_runtime_dependency "nokogiri", "~> 1.14"
33
- spec.add_runtime_dependency "thor", "~> 1.0"
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.7.7
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: 2024-05-29 00:00:00.000000000 Z
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.3.27
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: []