rmagick 5.5.0 → 6.0.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.
@@ -14,7 +14,7 @@
14
14
  #define MAIN // Define external variables
15
15
  #include "rmagick.h"
16
16
 
17
- #if defined(HAVE_SETMAGICKALIGNEDMEMORYMETHODS) && defined(HAVE_RB_GC_ADJUST_MEMORY_USAGE)
17
+ #if defined(HAVE_SETMAGICKALIGNEDMEMORYMETHODS)
18
18
  #if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE__ALIGNED_MSIZE)
19
19
  #define USE_RM_ALIGNED_MALLOC 1
20
20
 
@@ -1019,10 +1019,8 @@ Init_RMagick2(void)
1019
1019
  ENUMERATOR(ShapeAlphaChannel)
1020
1020
  ENUMERATOR(TransparentAlphaChannel)
1021
1021
  ENUMERATOR(BackgroundAlphaChannel)
1022
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
1023
1022
  ENUMERATOR(AssociateAlphaChannel)
1024
1023
  ENUMERATOR(DisassociateAlphaChannel)
1025
- #endif
1026
1024
  #if defined(IMAGEMAGICK_7)
1027
1025
  ENUMERATOR(OnAlphaChannel)
1028
1026
  ENUMERATOR(OffAlphaChannel)
@@ -1052,7 +1050,12 @@ Init_RMagick2(void)
1052
1050
  ENUMERATOR(BlackChannel)
1053
1051
  ENUMERATOR(IndexChannel)
1054
1052
  ENUMERATOR(GrayChannel)
1053
+ ENUMERATOR(CompositeChannels)
1055
1054
  ENUMERATOR(AllChannels)
1055
+ ENUMERATOR(TrueAlphaChannel)
1056
+ ENUMERATOR(RGBChannels)
1057
+ ENUMERATOR(GrayChannels)
1058
+ ENUMERATOR(SyncChannels)
1056
1059
  ENUMERATORV(AlphaChannel, OpacityChannel)
1057
1060
  ENUMERATORV(DefaultChannels, 0xff & ~OpacityChannel)
1058
1061
  ENUMERATORV(HueChannel, RedChannel)
@@ -1090,7 +1093,6 @@ Init_RMagick2(void)
1090
1093
  ENUMERATOR(Rec709YCbCrColorspace)
1091
1094
  ENUMERATOR(LogColorspace)
1092
1095
  ENUMERATOR(CMYColorspace)
1093
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
1094
1096
  ENUMERATOR(LuvColorspace)
1095
1097
  ENUMERATOR(HCLColorspace)
1096
1098
  ENUMERATOR(LCHColorspace)
@@ -1103,7 +1105,6 @@ Init_RMagick2(void)
1103
1105
  ENUMERATOR(HCLpColorspace)
1104
1106
  ENUMERATOR(YDbDrColorspace)
1105
1107
  ENUMERATORV(XyYColorspace, xyYColorspace)
1106
- #endif
1107
1108
  #if defined(IMAGEMAGICK_7)
1108
1109
  #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_7_0_8)
1109
1110
  ENUMERATOR(LinearGRAYColorspace)
@@ -1196,9 +1197,7 @@ Init_RMagick2(void)
1196
1197
  ENUMERATOR(UndefinedCompositeOp)
1197
1198
  ENUMERATOR(VividLightCompositeOp)
1198
1199
  ENUMERATOR(XorCompositeOp)
1199
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
1200
1200
  ENUMERATOR(HardMixCompositeOp)
1201
- #endif
1202
1201
  #if defined(IMAGEMAGICK_7)
1203
1202
  ENUMERATOR(CopyAlphaCompositeOp)
1204
1203
  #else
@@ -1242,6 +1241,7 @@ Init_RMagick2(void)
1242
1241
 
1243
1242
  // DisposeType constants
1244
1243
  DEF_ENUM(DisposeType)
1244
+ ENUMERATOR(UnrecognizedDispose)
1245
1245
  ENUMERATOR(UndefinedDispose)
1246
1246
  ENUMERATOR(BackgroundDispose)
1247
1247
  ENUMERATOR(NoneDispose)
@@ -1318,9 +1318,7 @@ Init_RMagick2(void)
1318
1318
  ENUMERATOR(RobidouxSharpFilter)
1319
1319
  ENUMERATOR(CosineFilter)
1320
1320
  ENUMERATOR(SplineFilter)
1321
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
1322
1321
  ENUMERATOR(LanczosRadiusFilter)
1323
- #endif
1324
1322
  ENUMERATORV(WelchFilter, WelshFilter)
1325
1323
  ENUMERATORV(HannFilter, HanningFilter)
1326
1324
  END_ENUM
@@ -1412,9 +1410,7 @@ Init_RMagick2(void)
1412
1410
  ENUMERATOR(RootMeanSquaredErrorMetric)
1413
1411
  ENUMERATOR(NormalizedCrossCorrelationErrorMetric)
1414
1412
  ENUMERATOR(FuzzErrorMetric)
1415
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
1416
1413
  ENUMERATOR(PerceptualHashErrorMetric)
1417
- #endif
1418
1414
  #if defined(IMAGEMAGICK_7)
1419
1415
  ENUMERATOR(UndefinedErrorMetric)
1420
1416
  ENUMERATOR(MeanErrorPerPixelErrorMetric)
@@ -1546,9 +1542,7 @@ Init_RMagick2(void)
1546
1542
  ENUMERATOR(ExponentialQuantumOperator)
1547
1543
  ENUMERATOR(MedianQuantumOperator)
1548
1544
  ENUMERATOR(SumQuantumOperator)
1549
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
1550
1545
  ENUMERATOR(RootMeanSquareQuantumOperator)
1551
- #endif
1552
1546
  END_ENUM
1553
1547
 
1554
1548
  // RenderingIntent
@@ -1673,9 +1667,7 @@ Init_RMagick2(void)
1673
1667
  ENUMERATOR(CorrelateNormalizeValue)
1674
1668
  ENUMERATOR(AreaValue)
1675
1669
  ENUMERATOR(DecimalValue)
1676
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
1677
1670
  ENUMERATOR(SeparatorValue)
1678
- #endif
1679
1671
  ENUMERATOR(AllValues)
1680
1672
  END_ENUM
1681
1673
 
@@ -1744,9 +1736,7 @@ Init_RMagick2(void)
1744
1736
  ENUMERATOR(OctagonalKernel)
1745
1737
  ENUMERATOR(EuclideanKernel)
1746
1738
  ENUMERATOR(UserDefinedKernel)
1747
- #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9)
1748
1739
  ENUMERATOR(BinomialKernel)
1749
- #endif
1750
1740
  END_ENUM
1751
1741
 
1752
1742
  /*-----------------------------------------------------------------------*/
@@ -1822,25 +1812,20 @@ Init_RMagick2(void)
1822
1812
  * were compiled with.
1823
1813
  *
1824
1814
  * No Ruby usage (internal function)
1825
- *
1826
- * Notes:
1827
- * - Bypass the test by defining the constant RMAGICK_BYPASS_VERSION_TEST to
1828
- * 'true' at the top level, before requiring 'rmagick'
1829
1815
  */
1830
1816
  static void
1831
1817
  test_Magick_version(void)
1832
1818
  {
1833
1819
  size_t version_number;
1834
1820
  const char *version_str;
1835
- ID bypass = rb_intern("RMAGICK_BYPASS_VERSION_TEST");
1836
1821
 
1837
- if (RTEST(rb_const_defined(rb_cObject, bypass)) && RTEST(rb_const_get(rb_cObject, bypass)))
1838
- {
1839
- return;
1840
- }
1822
+ /* ImageMagick versions are defined as major, minor and patch, each of which are defined as a value in 1 byte. */
1823
+ /* ImageMagick 6.9.12 has `#define MagickLibVersion 0x69C` */
1824
+ /* It use only major and minor versions. */
1825
+ size_t mask_major_minor_version = 0xFFFFFFF0;
1841
1826
 
1842
1827
  version_str = GetMagickVersion(&version_number);
1843
- if (version_number != MagickLibVersion)
1828
+ if ((version_number & mask_major_minor_version) != (MagickLibVersion & mask_major_minor_version))
1844
1829
  {
1845
1830
  int n, x;
1846
1831
 
@@ -1191,7 +1191,7 @@ rm_set_magick_pixel_packet(Pixel *pixel, MagickPixel *pp)
1191
1191
  /**
1192
1192
  * Return the color name corresponding to the pixel values.
1193
1193
  *
1194
- * @overload to_color(compliance = Magick::AllCompliance, alpha = false, depth = Magick::MAGICKCORE_QUANTUM_DEPTH, hex = false)
1194
+ * @overload to_color(compliance = Magick::AllCompliance, alpha = false, depth = Magick::MAGICKCORE_QUANTUM_DEPTH, hex = true)
1195
1195
  * @param compliance [Magick::ComplianceType] A ComplianceType constant
1196
1196
  * @param alpha [Boolean] If false, the pixel's alpha attribute is ignored
1197
1197
  * @param depth [Numeric] An image depth
@@ -1205,7 +1205,7 @@ Pixel_to_color(int argc, VALUE *argv, VALUE self)
1205
1205
  Image *image;
1206
1206
  Pixel *pixel;
1207
1207
  MagickPixel mpp;
1208
- MagickBooleanType hex = MagickFalse;
1208
+ MagickBooleanType hex = MagickTrue;
1209
1209
  char name[MaxTextExtent];
1210
1210
  ExceptionInfo *exception;
1211
1211
  ComplianceType compliance = AllCompliance;
@@ -21,6 +21,11 @@
21
21
  static VALUE rescue_not_str(VALUE, VALUE ATTRIBUTE_UNUSED) ATTRIBUTE_NORETURN;
22
22
  static void handle_exception(ExceptionInfo *, Image *, ErrorRetention);
23
23
 
24
+ #if defined(IMAGEMAGICK_7)
25
+ DEFINE_GVL_STUB3(TransformImageColorspace, Image *, const ColorspaceType, ExceptionInfo *);
26
+ #else
27
+ DEFINE_GVL_STUB2(TransformImageColorspace, Image *, const ColorspaceType);
28
+ #endif
24
29
 
25
30
  DEFINE_GVL_STUB5(CloneImage, const Image *, const size_t, const size_t, const MagickBooleanType, ExceptionInfo *);
26
31
 
@@ -367,7 +372,6 @@ double
367
372
  rm_percentage2(VALUE arg, double max, bool only_positive)
368
373
  {
369
374
  double pct;
370
- char *end;
371
375
 
372
376
  if (!rm_check_num2dbl(arg))
373
377
  {
@@ -590,23 +594,27 @@ rm_cur_image(VALUE img)
590
594
  VALUE
591
595
  rm_pixelcolor_to_color_name(Image *image, PixelColor *color)
592
596
  {
593
- PixelColor pp;
594
- char name[MaxTextExtent];
595
- ExceptionInfo *exception;
597
+ MagickPixel mpp;
598
+ char tuple[MaxTextExtent];
596
599
 
597
- exception = AcquireExceptionInfo();
598
-
599
- pp = *color;
600
600
  #if defined(IMAGEMAGICK_7)
601
- pp.depth = MAGICKCORE_QUANTUM_DEPTH;
602
- pp.colorspace = image->colorspace;
601
+ mpp = *color;
602
+ mpp.alpha_trait = BlendPixelTrait;
603
+ mpp.colorspace = image->colorspace;
604
+ #else
605
+ rm_init_magickpixel(image, &mpp);
606
+ mpp.red = GetPixelRed(color);
607
+ mpp.green = GetPixelGreen(color);
608
+ mpp.blue = GetPixelBlue(color);
609
+ mpp.opacity = GetPixelOpacity(color);
610
+ mpp.index = (MagickRealType) 0.0;
611
+ mpp.matte = MagickTrue;
603
612
  #endif
613
+ mpp.depth = image->depth;
604
614
 
605
- QueryColorname(image, &pp, X11Compliance, name, exception);
606
- CHECK_EXCEPTION();
607
- DestroyExceptionInfo(exception);
615
+ GetColorTuple(&mpp, MagickTrue, tuple);
608
616
 
609
- return rb_str_new2(name);
617
+ return rb_str_new2(tuple);
610
618
  }
611
619
 
612
620
 
@@ -1057,13 +1065,14 @@ void rm_sync_image_options(Image *image, Info *info)
1057
1065
  {
1058
1066
  #if defined(IMAGEMAGICK_7)
1059
1067
  exception = AcquireExceptionInfo();
1060
- SetImageColorspace(image, info->colorspace, exception);
1061
- // We should not throw an exception in this method because we will
1062
- // leak memory in the place where this method is called. And that is
1063
- // why the exception is being ignored here.
1068
+ GVL_STRUCT_TYPE(TransformImageColorspace) args = { image, info->colorspace, exception };
1069
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransformImageColorspace), &args);
1070
+ CHECK_EXCEPTION();
1064
1071
  DestroyExceptionInfo(exception);
1065
1072
  #else
1066
- SetImageColorspace(image, info->colorspace);
1073
+ GVL_STRUCT_TYPE(TransformImageColorspace) args = { image, info->colorspace };
1074
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransformImageColorspace), &args);
1075
+ rm_check_image_exception(image, RetainOnError);
1067
1076
  #endif
1068
1077
  }
1069
1078
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Magick
4
- VERSION = '5.5.0'
5
- MIN_RUBY_VERSION = '2.3.0'
6
- MIN_IM_VERSION = '6.7.7'
4
+ VERSION = '6.0.0'
5
+ MIN_RUBY_VERSION = '3.0.0'
6
+ MIN_IM_VERSION = '6.8.9'
7
7
  end
data/lib/rmagick.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rmagick_internal.rb'
3
+ require 'rmagick_internal'
@@ -10,7 +10,7 @@
10
10
  # to the classes.
11
11
  #==============================================================================
12
12
 
13
- if RUBY_PLATFORM =~ /mingw/i
13
+ if RUBY_PLATFORM.match?(/mingw/i)
14
14
  begin
15
15
  require 'ruby_installer'
16
16
  ENV['PATH'].split(File::PATH_SEPARATOR).grep(/ImageMagick/i).each do |path|
@@ -51,11 +51,11 @@ module Magick
51
51
  # p Magick.formats
52
52
  # => {"3FR"=>" r-+", "3G2"=>" r-+", "3GP"=>" r-+", "A"=>"*rw+",
53
53
  # ...
54
- def formats
54
+ def formats(&block)
55
55
  formats = init_formats
56
56
 
57
- if block_given?
58
- formats.each { |k, v| yield k, v }
57
+ if block
58
+ formats.each(&block)
59
59
  self
60
60
  else
61
61
  formats
@@ -140,7 +140,7 @@ module Magick
140
140
 
141
141
  # Convert object to a geometry string
142
142
  def to_s
143
- str = String.new
143
+ str = +''
144
144
  if @width > 0
145
145
  fmt = @width.truncate == @width ? '%d' : '%.2f'
146
146
  str << sprintf(fmt, @width)
@@ -227,7 +227,7 @@ module Magick
227
227
 
228
228
  def enquote(str)
229
229
  str = to_string(str)
230
- if str.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(str)
230
+ if str.length > 2 && /\A(?:"[^\"]+"|'[^\']+'|\{[^\}]+\})\z/.match(str)
231
231
  str
232
232
  else
233
233
  '"' + str + '"'
@@ -277,7 +277,7 @@ module Magick
277
277
 
278
278
  # Draw a bezier curve.
279
279
  def bezier(*points)
280
- if points.length.zero?
280
+ if points.empty?
281
281
  Kernel.raise ArgumentError, 'no points specified'
282
282
  elsif points.length.odd?
283
283
  Kernel.raise ArgumentError, 'odd number of arguments specified'
@@ -479,7 +479,7 @@ module Magick
479
479
 
480
480
  # Draw a polygon
481
481
  def polygon(*points)
482
- if points.length.zero?
482
+ if points.empty?
483
483
  Kernel.raise ArgumentError, 'no points specified'
484
484
  elsif points.length.odd?
485
485
  Kernel.raise ArgumentError, 'odd number of points specified'
@@ -489,7 +489,7 @@ module Magick
489
489
 
490
490
  # Draw a polyline
491
491
  def polyline(*points)
492
- if points.length.zero?
492
+ if points.empty?
493
493
  Kernel.raise ArgumentError, 'no points specified'
494
494
  elsif points.length.odd?
495
495
  Kernel.raise ArgumentError, 'odd number of points specified'
@@ -504,7 +504,7 @@ module Magick
504
504
  # pop('pattern')
505
505
 
506
506
  def pop(*what)
507
- if what.length.zero?
507
+ if what.empty?
508
508
  primitive 'pop graphic-context'
509
509
  else
510
510
  primitive 'pop ' + what.map { |x| to_string(x) }.join(' ')
@@ -517,7 +517,7 @@ module Magick
517
517
  # push('gradient')
518
518
  # push('pattern')
519
519
  def push(*what)
520
- if what.length.zero?
520
+ if what.empty?
521
521
  primitive 'push graphic-context'
522
522
  else
523
523
  primitive 'push ' + what.map { |x| to_string(x) }.join(' ')
@@ -573,7 +573,7 @@ module Magick
573
573
 
574
574
  # Specify a stroke dash pattern
575
575
  def stroke_dasharray(*list)
576
- if list.length.zero?
576
+ if list.empty?
577
577
  primitive 'stroke-dasharray none'
578
578
  else
579
579
  list.map! { |x| Float(x) }.each do |x|
@@ -622,7 +622,7 @@ module Magick
622
622
  def text(x, y, text)
623
623
  text = to_string(text)
624
624
  Kernel.raise ArgumentError, 'missing text argument' if text.empty?
625
- if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
625
+ if text.length > 2 && /\A(?:"[^\"]+"|'[^\']+'|\{[^\}]+\})\z/.match(text)
626
626
  # text already quoted
627
627
  elsif !text['\'']
628
628
  text = '\'' + text + '\''
@@ -669,6 +669,7 @@ module Magick
669
669
 
670
670
  # Define IPTC record number:dataset tags for use with Image#get_iptc_dataset
671
671
  module IPTC
672
+ # rubocop:disable Naming/ConstantName
672
673
  module Envelope
673
674
  Model_Version = '1:00'
674
675
  Destination = '1:05'
@@ -766,6 +767,7 @@ module Magick
766
767
  module Post_ObjectData_Descriptor
767
768
  Confirmed_ObjectData_Size = '9:10'
768
769
  end
770
+ # rubocop:enable Naming/ConstantName
769
771
  end # module Magick::IPTC
770
772
 
771
773
  # Ruby-level Magick::Image methods
@@ -837,9 +839,9 @@ module Magick
837
839
  # arrays.
838
840
  def get_exif_by_entry(*entry)
839
841
  ary = []
840
- if entry.length.zero?
842
+ if entry.empty?
841
843
  exif_data = self['EXIF:*']
842
- exif_data.split("\n").each { |exif| ary.push(exif.split('=')) } if exif_data
844
+ exif_data&.split("\n")&.each { |exif| ary.push(exif.split('=')) }
843
845
  else
844
846
  get_exif_by_entry # ensure properties is populated with exif data
845
847
  entry.each do |name|
@@ -853,14 +855,12 @@ module Magick
853
855
  # Retrieve EXIF data by tag number or all tag/value pairs. The return value is a hash.
854
856
  def get_exif_by_number(*tag)
855
857
  hash = {}
856
- if tag.length.zero?
858
+ if tag.empty?
857
859
  exif_data = self['EXIF:!']
858
- if exif_data
859
- exif_data.split("\n").each do |exif|
860
- tag, value = exif.split('=')
861
- tag = tag[1, 4].hex
862
- hash[tag] = value
863
- end
860
+ exif_data&.split("\n")&.each do |exif|
861
+ tag, value = exif.split('=')
862
+ tag = tag[1, 4].hex
863
+ hash[tag] = value
864
864
  end
865
865
  else
866
866
  get_exif_by_number # ensure properties is populated with exif data
@@ -1288,10 +1288,10 @@ module Magick
1288
1288
  # Allow scene to be set to nil
1289
1289
  def scene=(n)
1290
1290
  if n.nil?
1291
- Kernel.raise IndexError, 'scene number out of bounds' unless @images.length.zero?
1291
+ Kernel.raise IndexError, 'scene number out of bounds' unless @images.empty?
1292
1292
  @scene = nil
1293
1293
  return
1294
- elsif @images.length.zero?
1294
+ elsif @images.empty?
1295
1295
  Kernel.raise IndexError, 'scene number out of bounds'
1296
1296
  end
1297
1297
 
@@ -1368,7 +1368,7 @@ module Magick
1368
1368
 
1369
1369
  def []=(*args)
1370
1370
  obj = @images.[]=(*args)
1371
- if obj && obj.respond_to?(:each)
1371
+ if obj.respond_to?(:each)
1372
1372
  assert_image_array(obj)
1373
1373
  set_current obj.last.__id__
1374
1374
  elsif obj
@@ -1522,7 +1522,7 @@ module Magick
1522
1522
  end
1523
1523
 
1524
1524
  def fill(*args, &block)
1525
- assert_image args[0] unless block_given?
1525
+ assert_image args[0] unless block
1526
1526
  current = get_current
1527
1527
  @images.fill(*args, &block)
1528
1528
  assert_image_array self
@@ -1542,7 +1542,7 @@ module Magick
1542
1542
  alias select find_all
1543
1543
 
1544
1544
  def from_blob(*blobs, &block)
1545
- Kernel.raise ArgumentError, 'no blobs given' if blobs.length.zero?
1545
+ Kernel.raise ArgumentError, 'no blobs given' if blobs.empty?
1546
1546
  blobs.each do |b|
1547
1547
  Magick::Image.from_blob(b, &block).each { |n| @images << n }
1548
1548
  end
@@ -1571,9 +1571,8 @@ module Magick
1571
1571
 
1572
1572
  # Call inspect for all the images
1573
1573
  def inspect
1574
- img = []
1575
- @images.each { |image| img << image.inspect }
1576
- img = '[' + img.join(",\n") + "]\nscene=#{@scene}"
1574
+ img = @images.map(&:inspect)
1575
+ '[' + img.join(",\n") + "]\nscene=#{@scene}"
1577
1576
  end
1578
1577
 
1579
1578
  # Set the number of iterations of an animated GIF
@@ -1584,7 +1583,7 @@ module Magick
1584
1583
  end
1585
1584
 
1586
1585
  def last(*args)
1587
- if args.length.zero?
1586
+ if args.empty?
1588
1587
  a = @images.last
1589
1588
  else
1590
1589
  a = @images.last(*args)
@@ -1616,7 +1615,7 @@ module Magick
1616
1615
  def method_missing(meth_id, *args, &block)
1617
1616
  if @scene
1618
1617
  img = @images[@scene]
1619
- new_img = img.send(meth_id, *args, &block)
1618
+ new_img = img.public_send(meth_id, *args, &block)
1620
1619
  img.object_id == new_img.object_id ? self : new_img
1621
1620
  else
1622
1621
  super
@@ -1646,7 +1645,7 @@ module Magick
1646
1645
 
1647
1646
  # Ping files and concatenate the new images
1648
1647
  def ping(*files, &block)
1649
- Kernel.raise ArgumentError, 'no files given' if files.length.zero?
1648
+ Kernel.raise ArgumentError, 'no files given' if files.empty?
1650
1649
  files.each do |f|
1651
1650
  Magick::Image.ping(f, &block).each { |n| @images << n }
1652
1651
  end
@@ -1672,7 +1671,7 @@ module Magick
1672
1671
 
1673
1672
  # Read files and concatenate the new images
1674
1673
  def read(*files, &block)
1675
- Kernel.raise ArgumentError, 'no files given' if files.length.zero?
1674
+ Kernel.raise ArgumentError, 'no files given' if files.empty?
1676
1675
  files.each do |f|
1677
1676
  Magick::Image.read(f, &block).each { |n| @images << n }
1678
1677
  end
@@ -1735,8 +1734,8 @@ module Magick
1735
1734
  self
1736
1735
  end
1737
1736
 
1738
- def reverse_each
1739
- @images.reverse_each { |image| yield(image) }
1737
+ def reverse_each(&block)
1738
+ @images.reverse_each(&block)
1740
1739
  self
1741
1740
  end
1742
1741
 
@@ -1775,9 +1774,7 @@ module Magick
1775
1774
  end
1776
1775
 
1777
1776
  def to_a
1778
- a = []
1779
- @images.each { |image| a << image }
1780
- a
1777
+ @images.map { |image| image }
1781
1778
  end
1782
1779
 
1783
1780
  def uniq
@@ -1811,6 +1808,15 @@ module Magick
1811
1808
  end
1812
1809
  alias indexes values_at
1813
1810
  alias indices values_at
1811
+
1812
+ def destroy!
1813
+ @images.each(&:destroy!)
1814
+ self
1815
+ end
1816
+
1817
+ def destroyed?
1818
+ @images.all?(&:destroyed?)
1819
+ end
1814
1820
  end # Magick::ImageList
1815
1821
 
1816
1822
  class Pixel
data/lib/rvg/container.rb CHANGED
@@ -108,11 +108,11 @@ module Magick
108
108
  # If the element is not a group, defs, symbol, or rvg,
109
109
  # wrap a group around it so it can get a transform and
110
110
  # possibly a new viewport.
111
- if !element.respond_to?(:ref)
111
+ if element.respond_to?(:ref)
112
+ @element = element.deep_copy
113
+ else
112
114
  @element = Group.new
113
115
  @element << element.deep_copy
114
- else
115
- @element = element.deep_copy
116
116
  end
117
117
  @element.ref(x, y, width, height)
118
118
  end
@@ -109,7 +109,7 @@ module Magick
109
109
  short = n > 0 ? y_coords : x_coords
110
110
  olen = short.length
111
111
  n.abs.times { |x| short << short[x % olen] }
112
- points = x_coords.zip(y_coords).flatten
112
+ points = x_coords.zip(y_coords).flatten!
113
113
  end
114
114
  n = points.length
115
115
  raise ArgumentError, "insufficient/odd number of points specified: #{n}" if n < 4 || n.odd?
data/lib/rvg/misc.rb CHANGED
@@ -72,7 +72,7 @@ module Magick
72
72
  end
73
73
 
74
74
  def enquote(text)
75
- return text if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
75
+ return text if text.length > 2 && /\A(?:"[^\"]+"|'[^\']+'|\{[^\}]+\})\z/.match(text)
76
76
 
77
77
  if !text['\'']
78
78
  text = '\'' + text + '\''
@@ -87,7 +87,7 @@ module Magick
87
87
 
88
88
  # escape existing braces, surround with braces
89
89
  text.gsub!(/[}]/) { |b| '\\' + b }
90
- '{' + text + '}'
90
+ '{' + text + '}'
91
91
  end
92
92
 
93
93
  def glyph_metrics(glyph_orientation, glyph)
@@ -114,7 +114,7 @@ module Magick
114
114
  y_rel_coords << wy
115
115
  end
116
116
  first_word = false
117
- word.split('').each do |glyph|
117
+ word.chars.each do |glyph|
118
118
  wx, wy = get_letter_spacing(glyph)
119
119
  x_rel_coords << wx
120
120
  y_rel_coords << wy
@@ -173,7 +173,7 @@ module Magick
173
173
 
174
174
  def render(x, y, text)
175
175
  x_rel_coords, y_rel_coords = text_rel_coords(text)
176
- dx = x_rel_coords.reduce(0) { |sum, a| sum + a }
176
+ dx = x_rel_coords.sum
177
177
  dy = y_rel_coords.max
178
178
 
179
179
  # We're handling the anchoring.
@@ -203,7 +203,7 @@ module Magick
203
203
  text.split(::Magick::RVG::WORD_SEP).each do |word|
204
204
  x += x_rel_coords.shift unless first_word
205
205
  first_word = false
206
- word.split('').each do |glyph|
206
+ word.chars.each do |glyph|
207
207
  render_glyph(@ctx.text_attrs.glyph_orientation_horizontal, x, y, glyph)
208
208
  x += x_rel_coords.shift
209
209
  end
@@ -234,7 +234,7 @@ module Magick
234
234
  def render(x, y, text)
235
235
  x_rel_coords, y_rel_coords = text_rel_coords(text)
236
236
  dx = x_rel_coords.max
237
- dy = y_rel_coords.reduce(0) { |sum, a| sum + a }
237
+ dy = y_rel_coords.sum
238
238
 
239
239
  # We're handling the anchoring.
240
240
  @ctx.gc.push
@@ -271,7 +271,7 @@ module Magick
271
271
  x_rel_coords.shift
272
272
  end
273
273
  first_word = false
274
- word.split('').each do |glyph|
274
+ word.chars.each do |glyph|
275
275
  case @ctx.text_attrs.glyph_orientation_vertical.to_i
276
276
  when 0, 90, 270
277
277
  x_shift = (dx - x_rel_coords.shift) / 2
@@ -579,7 +579,7 @@ module Magick
579
579
 
580
580
  def font_weight(weight)
581
581
  # If the arg is not in the hash use it directly. Handles numeric values.
582
- weight = weight.is_a?(Numeric) ? weight : FONT_WEIGHT.fetch(weight.to_sym, Magick::NormalWeight)
582
+ weight = FONT_WEIGHT.fetch(weight.to_sym, Magick::NormalWeight) unless weight.is_a?(Numeric)
583
583
  @gc.font_weight(weight)
584
584
  @shadow[-1].font_weight = weight
585
585
  nil
@@ -668,7 +668,7 @@ module Magick
668
668
  end
669
669
 
670
670
  def text(x, y, text)
671
- return if text.length.zero?
671
+ return if text.empty?
672
672
 
673
673
  text_renderer = if @text_attrs.non_default?
674
674
  TEXT_STRATEGIES[@text_attrs.writing_mode].new(self)
data/lib/rvg/rvg.rb CHANGED
@@ -41,8 +41,6 @@ require 'rvg/clippath'
41
41
  require 'rvg/paint'
42
42
  require 'rvg/units'
43
43
 
44
- require 'pp' if ENV['debug_rvg']
45
-
46
44
  # RVG is the main class in this library. All graphic elements
47
45
  # must be contained within an RVG object.
48
46
  module Magick
@@ -108,7 +106,7 @@ module Magick
108
106
 
109
107
  if ENV['debug_prim']
110
108
  def print_gc(gc)
111
- primitives = gc.inspect.split(/\n/)
109
+ primitives = gc.inspect.split("\n")
112
110
  indent = 0
113
111
  primitives.each do |cmd|
114
112
  indent -= 1 if cmd['pop ']
@@ -172,7 +170,9 @@ module Magick
172
170
  # The default fill is "none", that is, transparent black.
173
171
  def background_fill=(color)
174
172
  warn 'background_fill= has no effect in nested RVG objects' if @nested
175
- if !color.is_a?(Magick::Pixel)
173
+ if color.is_a?(Magick::Pixel)
174
+ @background_fill = color
175
+ else
176
176
  begin
177
177
  @background_fill = Magick::Pixel.from_color(color)
178
178
  rescue Magick::ImageMagickError
@@ -182,8 +182,6 @@ module Magick
182
182
  rescue StandardError
183
183
  raise ArgumentError, "argument must be a color name or a Pixel (got #{color.class})"
184
184
  end
185
- else
186
- @background_fill = color
187
185
  end
188
186
  end
189
187