rmagick 7.1.7 → 7.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.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Magick
4
- VERSION = '7.1.7'
4
+ VERSION = '7.3.0'
5
5
  MIN_RUBY_VERSION = '3.2.0'
6
6
  MIN_IM6_VERSION = '6.9.0'
7
7
  MIN_IM7_VERSION = '7.1.0'
@@ -53,6 +53,41 @@ module Magick
53
53
  end
54
54
  end
55
55
 
56
+ class Enum
57
+ def dup
58
+ self
59
+ end
60
+
61
+ def clone(freeze: nil)
62
+ raise ArgumentError, "unexpected value for freeze: #{freeze.class}" unless [nil, true, false].include?(freeze)
63
+ raise ArgumentError, "can't unfreeze #{self.class}" if freeze == false
64
+
65
+ self
66
+ end
67
+ end
68
+
69
+ # Info and Montage cannot be frozen, as their #freeze raises TypeError, so
70
+ # clone(freeze: true) must not make a frozen copy of them either.
71
+ class Image
72
+ class Info
73
+ def clone(freeze: nil)
74
+ raise TypeError, "can't freeze #{self.class}" if freeze == true
75
+
76
+ super
77
+ end
78
+ end
79
+ end
80
+
81
+ class ImageList
82
+ class Montage
83
+ def clone(freeze: nil)
84
+ raise TypeError, "can't freeze #{self.class}" if freeze == true
85
+
86
+ super
87
+ end
88
+ end
89
+ end
90
+
56
91
  # Geometry class and related enum constants
57
92
  class GeometryValue < Enum
58
93
  # no methods
@@ -215,15 +250,22 @@ module Magick
215
250
 
216
251
  private
217
252
 
218
- def enquote(str)
219
- str = to_string(str)
253
+ # Escape backslashes and return the value as bytes, plus its original
254
+ # encoding. ImageMagick's MVG tokenizer reads the value byte by byte, so in
255
+ # Shift_JIS, Big5 and similar encodings a trail byte equal to a delimiter
256
+ # would slip past a per-character escape and close the token.
257
+ def escape_mvg_bytes(str)
220
258
  # escape existing backslashes, so that they cannot escape the delimiter
221
- # added below and let the rest of the string be parsed as MVG
222
- str = str.gsub('\\') { |b| '\\' + b }
259
+ # added by the caller and let the rest of the string be parsed as MVG
260
+ [str.b.gsub('\\') { |b| '\\' + b }, str.encoding]
261
+ end
262
+
263
+ def enquote(str)
264
+ str, encoding = escape_mvg_bytes(to_string(str))
223
265
  if str.length > 2 && /\A(?:"[^"\\]+"|'[^'\\]+'|\{[^}\\]+\})\z/.match(str)
224
- str
266
+ str.force_encoding(encoding)
225
267
  else
226
- '"' + str.gsub('"') { |c| '\\' + c } + '"'
268
+ ('"' + str.gsub('"') { |c| '\\' + c } + '"').force_encoding(encoding)
227
269
  end
228
270
  end
229
271
 
@@ -627,9 +669,7 @@ module Magick
627
669
  def text(x, y, text)
628
670
  text = to_string(text)
629
671
  Kernel.raise ArgumentError, 'missing text argument' if text.empty?
630
- # escape existing backslashes, so that they cannot escape the delimiter
631
- # added below and let the rest of the string be parsed as MVG
632
- text = text.gsub('\\') { |b| '\\' + b }
672
+ text, encoding = escape_mvg_bytes(text)
633
673
  if text.length > 2 && /\A(?:"[^"\\]+"|'[^'\\]+'|\{[^}\\]+\})\z/.match(text)
634
674
  # text already quoted
635
675
  elsif !text['\'']
@@ -642,7 +682,7 @@ module Magick
642
682
  # escape existing braces, surround with braces
643
683
  text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
644
684
  end
645
- primitive 'text ' + sprintf('%g,%g %s', x, y, text)
685
+ primitive 'text ' + sprintf('%g,%g %s', x, y, text.force_encoding(encoding))
646
686
  end
647
687
 
648
688
  # Specify text alignment relative to a given point
@@ -871,9 +911,13 @@ module Magick
871
911
  hash[tag] = value
872
912
  end
873
913
  else
874
- get_exif_by_number # ensure properties is populated with exif data
914
+ values = {}
915
+ self['EXIF:!']&.split("\n")&.each do |exif|
916
+ name, value = exif.split('=', 2)
917
+ values[name.downcase] = value
918
+ end
875
919
  tag.each do |num|
876
- rval = self[sprintf('#%04X', num.to_i)]
920
+ rval = values[sprintf('#%04x', num.to_i)]
877
921
  hash[num] = rval == 'unknown' ? nil : rval
878
922
  end
879
923
  end
@@ -1606,9 +1650,9 @@ module Magick
1606
1650
  end
1607
1651
 
1608
1652
  def marshal_load(ary)
1609
- @scene = ary.shift
1610
- @images = []
1611
- ary.each { |a| @images << Marshal.load(a) } # rubocop:disable Security/MarshalLoad
1653
+ images = ary.drop(1).map! { |a| Marshal.load(a) } # rubocop:disable Security/MarshalLoad
1654
+ @scene = ary.first
1655
+ @images = images
1612
1656
  end
1613
1657
 
1614
1658
  # The ImageList class supports the Magick::Image class methods by simply sending
@@ -1831,28 +1875,45 @@ module Magick
1831
1875
  class OptionalMethodArguments
1832
1876
  def initialize(img)
1833
1877
  @img = img
1878
+ @artifacts = {}
1834
1879
  end
1835
1880
 
1836
1881
  # miscellaneous options like -verbose
1837
1882
  def method_missing(mth, val)
1838
- @img.define(mth.to_s.tr('_', '-'), val)
1883
+ define(mth.to_s.tr('_', '-'), val)
1839
1884
  end
1840
1885
 
1841
1886
  # set(key, val) corresponds to -set option:key val
1842
1887
  def define(key, val = nil)
1843
- @img.define(key, val)
1888
+ key = -String(key)
1889
+ val = -String(val) unless val.nil?
1890
+ raise ArgumentError, 'string contains null byte' if key.include?("\0") || val&.include?("\0")
1891
+
1892
+ @artifacts[key] = val
1893
+ val
1844
1894
  end
1845
1895
 
1846
1896
  # accepts Pixel object or color name
1847
1897
  def highlight_color=(color)
1848
- color = @img.to_color(color) if color.respond_to?(:to_color)
1849
- @img.define('highlight-color', color)
1898
+ define_compare_color('highlight-color', color)
1850
1899
  end
1851
1900
 
1852
1901
  # accepts Pixel object or color name
1853
1902
  def lowlight_color=(color)
1854
- color = @img.to_color(color) if color.respond_to?(:to_color)
1855
- @img.define('lowlight-color', color)
1903
+ define_compare_color('lowlight-color', color)
1904
+ end
1905
+
1906
+ private
1907
+
1908
+ def define_compare_color(name, color)
1909
+ color = if color.is_a?(Magick::Pixel)
1910
+ color.to_color(Magick::AllCompliance, true)
1911
+ else
1912
+ String.try_convert(color) || raise(TypeError, "argument must be color name or pixel (#{color.class} given)")
1913
+ end
1914
+ define("compare:#{name}", color)
1915
+ # ImageMagick 6.9.6-0 and older read the name without the "compare:" prefix.
1916
+ define(name, color)
1856
1917
  end
1857
1918
  end
1858
1919
 
data/lib/rvg/rvg.rb CHANGED
@@ -36,7 +36,7 @@ module Magick
36
36
  # else, combine it with the background_fill_opacity.
37
37
  def bgfill
38
38
  if @background_fill.nil?
39
- color = Magick::Pixel.new(0, 0, 0, Magick::OpaqueAlpha)
39
+ color = Magick::Pixel.from_color('none')
40
40
  else
41
41
  color = @background_fill
42
42
  color.alpha = @background_fill_opacity * Magick::OpaqueAlpha
@@ -225,7 +225,7 @@ module Magick
225
225
  def cycle_colormap: (int amount) -> Image
226
226
  def decipher: (string passphrase) -> Image
227
227
  def define: (interned artifact, (string | Numeric)? value) -> String?
228
- def deskew: (?magick_percentage threshold, ?int auto_crop_width) -> Image
228
+ def deskew: (?magick_percentage threshold, ?(int | bool | nil) auto_crop_width) -> Image
229
229
  def delete_compose_mask: () -> self
230
230
  def delete_profile: (string name) -> self
231
231
  def despeckle: () -> Image
data/sig/rmagick/enum.rbs CHANGED
@@ -8,6 +8,8 @@ module Magick
8
8
  def <=>: (Enum other) -> (-1 | 0 | 1 | nil)
9
9
  def ===: (Enum other) -> bool
10
10
  def |: (Enum other) -> Enum
11
+ def dup: () -> self
12
+ def clone: (?freeze: bool?) -> self
11
13
  end
12
14
 
13
15
  interface _EnumInstanceMethod
@@ -92,6 +92,7 @@ module Magick
92
92
 
93
93
  class Info
94
94
  def initialize: () -> void
95
+ def clone: (?freeze: bool?) -> Info
95
96
  def channel: (*ChannelType channel) -> self
96
97
  def define: (string format, string key, ?string value) -> self?
97
98
  def []=: (string format, string key, string value) -> self?
@@ -165,6 +165,7 @@ module Magick
165
165
 
166
166
  class Montage
167
167
  def initialize: () -> void
168
+ def clone: (?freeze: bool?) -> Montage
168
169
 
169
170
  attr_writer background_color: magick_color
170
171
  attr_writer border_color: magick_color
@@ -6,7 +6,7 @@ module Magick
6
6
  attr_writer lowlight_color: magick_color
7
7
 
8
8
  def initialize: (magick_image img) -> void
9
- def define: (string key, ?string? value) -> String
9
+ def define: (interned key, ?(string | Numeric)? value) -> String?
10
10
  def method_missing: (untyped mth, untyped val) ?{ (*untyped, **untyped) -> untyped } -> untyped
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmagick
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.7
4
+ version: 7.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Hunter
@@ -58,7 +58,9 @@ files:
58
58
  - ext/RMagick/extconf.rb
59
59
  - ext/RMagick/rmagick.cpp
60
60
  - ext/RMagick/rmagick.h
61
+ - ext/RMagick/rmagick_gvl.cpp
61
62
  - ext/RMagick/rmagick_gvl.h
63
+ - ext/RMagick/rmagick_gvl.hpp
62
64
  - ext/RMagick/rmdraw.cpp
63
65
  - ext/RMagick/rmenum.cpp
64
66
  - ext/RMagick/rmfill.cpp
@@ -143,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
145
  version: '0'
144
146
  requirements:
145
147
  - ImageMagick 6.9.0+ (for ImageMagick 6) or 7.1.0+ (for ImageMagick 7)
146
- rubygems_version: 4.0.20
148
+ rubygems_version: 4.0.24
147
149
  specification_version: 4
148
150
  summary: Ruby binding to ImageMagick
149
151
  test_files: []