rbpdf 1.19.4 → 1.19.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ad5083c310d25cd904c1826bd2672b7bbb31a93
4
- data.tar.gz: dcb1537363d38928044d3f55168381409c5f7b1b
3
+ metadata.gz: 2639ff84fd70b4fcf84386c2d2d4ec407cfe932e
4
+ data.tar.gz: 59a2e7fe5a678bec81f112744dae30d004ae9a00
5
5
  SHA512:
6
- metadata.gz: 82119b8767536543d6e2cdd625bcdb48b0a7c75bc4ea92a3f2154f74731527eab42b7a1d605ee31f31b12a9bc3034599d4b5b1eeec2ce50036ea98cddeedea4d
7
- data.tar.gz: 9c2428dbe401fb1425ee29096b09e50df64231ff9dcf8976c9bd0303dbd681bb95e8d3aecca5265ba73201647c5e39f92de4d64b83d9f1ee64570ce235b14a51
6
+ metadata.gz: 10d521aaf60b79a63a03d4a7e04830ee2cacee71f5d0a6f3f1acafb03a0d0973c48ce8fb77eec9f86747b72f4c52e5d0ccfcc59f55edca70e25804e0fb65302c
7
+ data.tar.gz: de13ae61679876a96365899664338a1a54134805eeec6e1d93cf2355c0b2b89c7266ad314a6b9066f306cc210712659914578cafab8f3907729f9d1c24c50692
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 1.19.5 2018-06-24
2
+ - Fixed that the handling of Tempfile was wrong.
3
+ - Fixed compatibility problem with Magick::RGBColorspace and Magick::SRGBColorspace.
4
+ image_alpha_mask function has been fixed to use Magick :: ExtractAlphaChannel.
5
+ - Deleted exception handling of ImagePngAlpha function.
6
+
1
7
  1.19.4 2018-06-16
2
8
  - Ruby 2.5 supported.
3
9
  - Rails 5.2 supported.
@@ -4836,6 +4836,9 @@ class RBPDF
4836
4836
  # set bottomcoordinates
4837
4837
  @img_rb_y = y + h
4838
4838
  Error('Image filename is empty.') if file.nil? or file.length == 0
4839
+ unless File.exist?(file)
4840
+ Error('Image file is not found. : ' + file)
4841
+ end
4839
4842
 
4840
4843
  # get image dimensions
4841
4844
  imsize = getimagesize(file)
@@ -4845,14 +4848,14 @@ class RBPDF
4845
4848
  imsize = getimagesize(file)
4846
4849
 
4847
4850
  if imsize.nil?
4848
- Error('Missing image file: ' + file)
4851
+ Error("Can't get image dimension. : " + file)
4849
4852
  elsif imsize == false
4850
4853
  if (w > 0) and (h > 0)
4851
4854
  pw = getHTMLUnitToUnits(w, 0, @pdfunit, true) * @img_scale * @k
4852
4855
  ph = getHTMLUnitToUnits(h, 0, @pdfunit, true) * @img_scale * @k
4853
4856
  imsize = [pw, ph]
4854
4857
  else
4855
- Error('[Image] Unable to get image width and height: ' + file)
4858
+ Error('Unable to get image width and height: ' + file)
4856
4859
  end
4857
4860
  end
4858
4861
  end
@@ -4963,7 +4966,7 @@ class RBPDF
4963
4966
  tmpFile = imageToPNG(file)
4964
4967
  if tmpFile != false
4965
4968
  info=parsepng(tmpFile.path)
4966
- tmpFile.delete
4969
+ tmpFile.close(true)
4967
4970
  end
4968
4971
  else
4969
4972
  #Allow for additional formats
@@ -4997,10 +5000,10 @@ class RBPDF
4997
5000
  tmpname.binmode
4998
5001
  jpeg_quality = @jpeg_quality
4999
5002
  tmpname.print img.to_blob { self.quality = jpeg_quality }
5000
- tmpname.close
5003
+ tmpname.fsync
5001
5004
 
5002
5005
  info = parsejpeg(tmpname.path)
5003
- tmpname.delete
5006
+ tmpname.close(true)
5004
5007
  else
5005
5008
  return false
5006
5009
  end
@@ -5137,9 +5140,8 @@ class RBPDF
5137
5140
  tmpFile = Tempfile.new(['', '_' + File::basename(file) + '.png'], @@k_path_cache);
5138
5141
  tmpFile.binmode
5139
5142
  tmpFile.print img.to_blob
5143
+ tmpFile.fsync
5140
5144
  tmpFile
5141
- ensure
5142
- tmpFile.close unless tmpFile.nil?
5143
5145
  end
5144
5146
  protected :imageToPNG
5145
5147
 
@@ -5247,17 +5249,18 @@ class RBPDF
5247
5249
 
5248
5250
  def image_alpha_mask(file)
5249
5251
  img = Magick::ImageList.new(file)
5250
-
5251
- img2 = img.separate(Magick::OpacityChannel)
5252
- img = img2.negate(true)
5252
+ if img.alpha?
5253
+ img.alpha = Magick::ExtractAlphaChannel # PNG alpha channel Mask
5254
+ else
5255
+ return false
5256
+ end
5253
5257
 
5254
5258
  #use a temporary file....
5255
5259
  tmpFile = Tempfile.new(['msk_', '.png'], @@k_path_cache)
5256
5260
  tmpFile.binmode
5257
5261
  tmpFile.print img.to_blob
5262
+ tmpFile.fsync
5258
5263
  tmpFile
5259
- ensure
5260
- tmpFile.close unless tmpFile.nil?
5261
5264
  end
5262
5265
  protected :image_alpha_mask
5263
5266
 
@@ -5294,22 +5297,19 @@ class RBPDF
5294
5297
  if tempfile_plain == false
5295
5298
  return false
5296
5299
  end
5297
- info=parsepng(tempfile_plain.path)
5298
- if info['cs'] != 'DeviceRGB'
5299
- tempfile_plain.delete
5300
- return false
5301
- end
5302
5300
 
5303
5301
  tempfile_alpha = image_alpha_mask(file)
5302
+ if tempfile_alpha == false
5303
+ return false
5304
+ end
5304
5305
 
5305
5306
  # embed mask image
5306
5307
  imgmask = Image(tempfile_alpha.path, x, y, w, h, 'PNG', '', '', resize, dpi, '', true, false)
5308
+ tempfile_alpha.close(true)
5307
5309
 
5308
5310
  # embed image, masked with previously embedded mask
5309
5311
  Image(tempfile_plain.path, x, y, w, h, type, link, align, resize, dpi, palign, false, imgmask)
5310
- # remove temp files
5311
- tempfile_alpha.delete
5312
- tempfile_plain.delete
5312
+ tempfile_plain.close(true)
5313
5313
 
5314
5314
  return true
5315
5315
  end
@@ -11775,9 +11775,8 @@ protected
11775
11775
  res = http.get(uri.path)
11776
11776
  tmpFile.print res.body
11777
11777
  end
11778
+ tmpFile.fsync
11778
11779
  tmpFile
11779
- ensure
11780
- tmpFile.close unless tmpFile.nil?
11781
11780
  end
11782
11781
 
11783
11782
  #
@@ -13266,7 +13265,7 @@ public
13266
13265
  result_img = false
13267
13266
  ensure
13268
13267
  # remove temp files
13269
- tmpFile.delete unless tmpFile.nil?
13268
+ tmpFile.close(true) unless tmpFile.nil?
13270
13269
  end
13271
13270
 
13272
13271
  if result_img or ih != 0
@@ -14149,8 +14148,6 @@ protected
14149
14148
  tmpFile = Tempfile.new(name + '_', @@k_path_cache)
14150
14149
  tmpFile.binmode
14151
14150
  tmpFile
14152
- ensure
14153
- tmpFile.close
14154
14151
  end
14155
14152
 
14156
14153
  #
@@ -3,5 +3,5 @@
3
3
  # http://www.opensource.org/licenses/MIT
4
4
 
5
5
  module Rbpdf
6
- VERSION = "1.19.4"
6
+ VERSION = "1.19.5"
7
7
  end
@@ -24,9 +24,11 @@ class RbpdfHttpTest < Test::Unit::TestCase
24
24
  utf8_japanese_aiueo_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a"
25
25
 
26
26
  images = [
27
- 'logo_rbpdf_8bit.png',
28
- 'logo_rbpdf_8bit .png',
29
- 'logo_rbpdf_8bit+ .png',
27
+ # file_name, error_message
28
+ ['logo_rbpdf_8bit.png', nil],
29
+ ['logo_rbpdf_8bit .png', nil],
30
+ ['logo_rbpdf_8bit+ .png', nil],
31
+ ['logo_rbpdf_8bit_no_file.png', /^RBPDF error: Unable to get image width and height: /],
30
32
  ]
31
33
  # no use
32
34
  #if RUBY_VERSION >= '2.0' # Ruby 1.9.2/1.9.3
@@ -36,19 +38,26 @@ class RbpdfHttpTest < Test::Unit::TestCase
36
38
  pdf = MYPDF.new
37
39
  images.each_with_index {|image, i|
38
40
  pdf.add_page
39
- #tmpFile = pdf.get_image_file('http://127.0.0.1:' + @port.to_s + '/logo_rbpdf_8bit.png')
40
- #tmpFile = pdf.get_image_file('http://127.0.0.1:' + @port.to_s + '/logo_rbpdf_8bit .png')
41
- #tmpFile = pdf.get_image_file('http://127.0.0.1:' + @port.to_s + '/' + image)
42
- #image.force_encoding('ASCII-8BIT') if image.respond_to?(:force_encoding)
43
- tmpFile = pdf.get_image_file('http://127.0.0.1:' + @port.to_s + '/' + image)
41
+ #image[0].force_encoding('ASCII-8BIT') if image[0].respond_to?(:force_encoding)
42
+ tmpFile = pdf.get_image_file('http://127.0.0.1:' + @port.to_s + '/' + image[0])
43
+
44
44
  img_file = tmpFile.path
45
45
  assert_not_equal "", img_file
46
46
  unless File.exist?(img_file)
47
47
  assert false, "file not found. :" + img_file
48
48
  end
49
49
 
50
- result_img = pdf.image(img_file, 50, 0, 0, '', '', '', '', false, 300, '', true)
51
- assert_equal i+1, result_img
50
+ if image[1].nil?
51
+ result_img = pdf.image(img_file, 50, 0, 0, '', '', '', '', false, 300, '', true)
52
+ assert_equal i+1, result_img
53
+ else
54
+ err = assert_raise(RBPDFError) {
55
+ result_img = pdf.image(img_file, 50, 0, 0, '', '', '', '', false, 300, '', true)
56
+ }
57
+ assert_match image[1], err.message
58
+ assert_equal nil, result_img
59
+ end
60
+
52
61
  no = pdf.get_num_pages
53
62
  assert_equal i+1, no
54
63
 
@@ -31,8 +31,8 @@ class RbpdfTest < Test::Unit::TestCase
31
31
  assert_equal data[:type], info[2] # Image Type
32
32
  assert_equal 'height="89" width="240"', info[3]
33
33
  assert_equal data[:mime], info['mime']
34
- assert_equal data[:channels], info['channels'] if @channels # RGB
35
- assert_equal data[:bits], info['bits'] if @bits # depth
34
+ assert_equal data[:channels], info['channels'] if data[:channels] # RGB
35
+ assert_equal data[:bits], info['bits'] if data[:bits] # depth
36
36
  end
37
37
 
38
38
  images = {
@@ -95,7 +95,7 @@ class RbpdfTest < Test::Unit::TestCase
95
95
 
96
96
  images = {
97
97
  'PNG alpha' => {:file => 'png_test_alpha.png', :info => true},
98
- 'PNG alpha Error' => {:file => 'png_test_alpha.png', :info => false, :png_alpha_error => true},
98
+ #'PNG alpha Error' => {:file => 'png_test_alpha.png', :info => false, :png_alpha_error => true}, # no use
99
99
  }
100
100
 
101
101
  data(images)
@@ -105,7 +105,7 @@ class RbpdfTest < Test::Unit::TestCase
105
105
  pdf = RBPDF.new
106
106
  pdf.add_page
107
107
  img_file = File.join(File.dirname(__FILE__), data[:file])
108
- pdf.singleton_class.send(:define_method, :parsepng){|*args| {:cs => 'Indexed'}} if data[:png_alpha_error]
108
+ #pdf.singleton_class.send(:define_method, :parsepng){|*args| {:cs => 'Indexed'}} if data[:png_alpha_error] # no use
109
109
  info = pdf.send(:ImagePngAlpha, img_file, 10, 10, 100, '', 'PNG', 'https://rubygems.org/gems/rbpdf')
110
110
  assert_equal data[:info], info
111
111
  end
@@ -113,7 +113,7 @@ class RbpdfTest < Test::Unit::TestCase
113
113
  images = {
114
114
  'PNG' => {:file => 'logo_rbpdf_8bit.png', :info => 1, :use_magick => false},
115
115
  'PNG alpha' => {:file => 'png_test_alpha.png', :info => true, :use_magick => true},
116
- 'PNG alpha Error' => {:file => 'png_test_alpha.png', :info => 1, :use_magick => true, :png_alpha_error => true},
116
+ #'PNG alpha Error' => {:file => 'png_test_alpha.png', :info => 1, :use_magick => true, :png_alpha_error => true}, # no use
117
117
  'GIF' => {:file => 'logo_rbpdf_8bit.gif', :info => 1, :use_magick => true},
118
118
  'GIF alpha' => {:file => 'logo_rbpdf_8bit_alpha.gif', :info => 1, :use_magick => true},
119
119
  'JPEG' => {:file => 'logo_rbpdf_8bit.jpg', :info => 1, :use_magick => true},
@@ -128,7 +128,7 @@ class RbpdfTest < Test::Unit::TestCase
128
128
  pdf = RBPDF.new
129
129
  pdf.add_page
130
130
  img_file = File.join(File.dirname(__FILE__), data[:file])
131
- pdf.singleton_class.send(:define_method, :parsepng){|*args| {:cs => 'Indexed'}} if data[:png_alpha_error]
131
+ #pdf.singleton_class.send(:define_method, :parsepng){|*args| {:cs => 'Indexed'}} if data[:png_alpha_error] # no use
132
132
  info = pdf.image(img_file, 10, 10, 100, '', '', 'https://rubygems.org/gems/rbpdf', '', false, 300)
133
133
  assert_equal data[:info], info
134
134
  end
@@ -96,7 +96,7 @@ class RbpdfTest < Test::Unit::TestCase
96
96
  err = assert_raises(RBPDFError) {
97
97
  pdf.image('foo.png')
98
98
  }
99
- assert_equal 'RBPDF error: Missing image file: foo.png', err.message
99
+ assert_equal 'RBPDF error: Image file is not found. : foo.png', err.message
100
100
  end
101
101
 
102
102
  test "Image basic test" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbpdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.4
4
+ version: 1.19.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - NAITOH Jun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-16 00:00:00.000000000 Z
11
+ date: 2018-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.2.2
171
+ rubygems_version: 2.6.10
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: RBPDF via TCPDF.
@@ -211,4 +211,3 @@ test_files:
211
211
  - test/rbpdf_viewerpreferences_test.rb
212
212
  - test/rbpdf_write_test.rb
213
213
  - test/test_helper.rb
214
- has_rdoc: