rbpdf 1.19.2 → 1.19.3

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: 745cf6037c3efe5f56d6c13c24010ff889393050
4
- data.tar.gz: 7fe45fc428b9921af7506b1b0bb775d97b5d8faf
3
+ metadata.gz: fe56fed150bb05fc1e613f87058b5403787068cb
4
+ data.tar.gz: 7e0de6186f06514075d03c9499dc2ff72a11c52a
5
5
  SHA512:
6
- metadata.gz: 9c2b97f1520facee2e23895c030cbc600f84191c67497fb9fd286762beedf10f19b8e38e4c998b9015667552e001310b0c5856d0a209638df0e423ebdab3f458
7
- data.tar.gz: 1787ec42fa71bba0a1524024f29a9acc17c447ac9a9bd9fab25be2ddb1c3e5c15c8aa3c7055de56b6f38e5c770f71038a1790d5279da447bb6b8dc75b93fd2b5
6
+ metadata.gz: b526e43f73722bcf9cd6d4b76fb0f800ebf58462ed0331181c05e80ad062d733b9472c45e41b73a27e9a6c64ac6ce6f4ed691f33131ecac500b7c798bc735532
7
+ data.tar.gz: a6d704fd9fc1c53950933c64bd37021161d2ee77affa6a41effcb38786e3226d42aa7fc080e7b671f05343e8e8569dd839dac94ac067197df694f842a40ae003
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 1.19.3 2017-09-10
2
+ - Rails 5.1 supported.
3
+ - nil link bug fixed. (by jkraemer)
4
+
1
5
  1.19.2 2017-04-08
2
6
  - Ruby 1.9/2.0 on Windows install problem fixed.
3
7
 
@@ -95,6 +95,9 @@ PDF_PRODUCER = 'RBPDF 5.2.000'
95
95
  # @license:: http://www.gnu.org/copyleft/lesser.html LGPL 2.1
96
96
  #
97
97
 
98
+ class RBPDFError < StandardError
99
+ end
100
+
98
101
  class RBPDF
99
102
  include ActionView::Helpers
100
103
  include Rbpdf
@@ -367,7 +370,7 @@ class RBPDF
367
370
  @numfonts ||= 0
368
371
  @fontkeys ||= []
369
372
  @font_obj_ids ||= {}
370
- @pageopen ||= []
373
+ @pageopen ||= [] # Store the fage status (true when opened, false when closed).
371
374
  @default_monospaced_font = 'courier'
372
375
 
373
376
 
@@ -442,7 +445,7 @@ class RBPDF
442
445
  @font_files ||= {}
443
446
  @diffs ||= []
444
447
  @images ||= {}
445
- @links ||= []
448
+ @links ||= [] # array of internal links
446
449
  @html_anchor ||= nil
447
450
  @html_anchors ||= {}
448
451
  @html_anchor_links ||= {}
@@ -1507,13 +1510,21 @@ class RBPDF
1507
1510
  # This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid.
1508
1511
  # * 2004-06-11 :: Nicola Asuni : changed bold tag with strong
1509
1512
  # [@param string :msg] The error message
1513
+ # [@param string :err] Exception object
1510
1514
  # [@access public]
1511
1515
  # [@since 1.0]
1512
1516
  #
1513
- def Error(msg)
1514
- #destroy(true)
1515
- #Fatal error
1516
- raise "RBPDF error: #{msg}"
1517
+ def Error(msg, err = nil)
1518
+ if /^.+?:\d+(?::in `(.*)')?/ =~ caller(2).first
1519
+ method = $1
1520
+ end
1521
+ if err and err.class != RBPDFError
1522
+ logger.error "pdf: #{method}: #{err.message}"
1523
+ err.backtrace.each{|trace|
1524
+ logger.error trace
1525
+ }
1526
+ end
1527
+ raise RBPDFError, "RBPDF error: #{msg}"
1517
1528
  end
1518
1529
  alias_method :error, :Error
1519
1530
 
@@ -2983,7 +2994,7 @@ class RBPDF
2983
2994
  #
2984
2995
  def AddLink()
2985
2996
  #Create a new internal link
2986
- n=@links.length+1;
2997
+ n = @links.length
2987
2998
  @links[n]=[0,0];
2988
2999
  return n;
2989
3000
  end
@@ -3385,6 +3396,8 @@ class RBPDF
3385
3396
  end
3386
3397
  checkPageBreak(h)
3387
3398
  out(getCellCode(w, h, txt, border, ln, align, fill, link, stretch, ignore_min_height, calign, valign))
3399
+ rescue => err
3400
+ Error('Cell Error.', err)
3388
3401
  end
3389
3402
  alias_method :cell, :Cell
3390
3403
 
@@ -3744,7 +3757,7 @@ class RBPDF
3744
3757
  if (@color_flag)
3745
3758
  s<<' Q';
3746
3759
  end
3747
- if link && ((link.is_a?(String) and !link.empty?) or (link.is_a?(Integer) and link != 0)) # Integer is PDF file Page No.
3760
+ if link && ((link.is_a?(String) and !link.empty?) or (link.is_a?(Integer) and link >= 0)) # Integer is @links array index
3748
3761
  Link(xdx, y + ((h - @font_size) / 2.0), width, @font_size, link, ns)
3749
3762
  end
3750
3763
  end
@@ -3843,6 +3856,9 @@ class RBPDF
3843
3856
  # SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()
3844
3857
  #
3845
3858
  def MultiCell(w, h, txt, border=0, align='J', fill=0, ln=1, x='', y='', reseth=true, stretch=0, ishtml=false, autopadding=true, maxh=0)
3859
+
3860
+ @x ||= 0
3861
+
3846
3862
  w = 0 unless w.is_a?(Numeric)
3847
3863
  h = 0 unless h.is_a?(Numeric)
3848
3864
 
@@ -4033,6 +4049,8 @@ class RBPDF
4033
4049
 
4034
4050
  setContentMark()
4035
4051
  return nl
4052
+ rescue => err
4053
+ Error('MultiCell Error.', err)
4036
4054
  end
4037
4055
  alias_method :multi_cell, :MultiCell
4038
4056
 
@@ -4624,6 +4642,8 @@ class RBPDF
4624
4642
  return ''
4625
4643
  end
4626
4644
  return nl
4645
+ rescue => err
4646
+ Error('Write Error.', err)
4627
4647
  end
4628
4648
  alias_method :write, :Write
4629
4649
 
@@ -5107,7 +5127,7 @@ class RBPDF
5107
5127
  img = Magick::ImageList.new(file)
5108
5128
  img.format = 'PNG' # convert to PNG from gif
5109
5129
  if img.alpha?
5110
- img.opacity = 0 # PNG alpha channel delete
5130
+ img.alpha = Magick::DeactivateAlphaChannel # PNG alpha channel delete
5111
5131
  if img.alpha?
5112
5132
  return false
5113
5133
  end
@@ -11824,6 +11844,8 @@ public
11824
11844
  def writeHTMLCell(w, h, x, y, html='', border=0, ln=0, fill=0, reseth=true, align='', autopadding=true)
11825
11845
  rtn = MultiCell(w, h, html, border, align, fill, ln, x, y, reseth, 0, true, autopadding, 0)
11826
11846
  return rtn
11847
+ rescue => err
11848
+ Error('writeHTMLCell Error.', err)
11827
11849
  end
11828
11850
  alias_method :write_html_cell, :writeHTMLCell
11829
11851
 
@@ -13004,6 +13026,8 @@ public
13004
13026
  @listcount = prev_listcount
13005
13027
  @lispacer = prev_lispacer
13006
13028
  dom = nil
13029
+ rescue => err
13030
+ Error('writeHTML Error.', err)
13007
13031
  end
13008
13032
  alias_method :write_html, :writeHTML
13009
13033
 
@@ -13465,7 +13489,7 @@ public
13465
13489
  Ln(0, cell)
13466
13490
  @x = parent['startx']
13467
13491
  # account for booklet mode
13468
- if @page > parent['startpage']
13492
+ if parent['startpage'] and @page > parent['startpage']
13469
13493
  if @rtl and (@pagedim[@page]['orm'] != @pagedim[parent['startpage']]['orm'])
13470
13494
  @x -= @pagedim[@page]['orm'] - @pagedim[parent['startpage']]['orm']
13471
13495
  elsif !@rtl and (@pagedim[@page]['olm'] != @pagedim[parent['startpage']]['olm'])
@@ -13535,6 +13559,7 @@ public
13535
13559
  startpage = parent['startpage']
13536
13560
  end_page = parent['endpage']
13537
13561
  end
13562
+ cellpos['startx'] ||= 0
13538
13563
  if end_page > startpage
13539
13564
  # design borders around HTML cells.
13540
13565
  startpage.upto(end_page) do |page|
@@ -14637,6 +14662,7 @@ public
14637
14662
  # adjust links
14638
14663
  tmplinks = @links
14639
14664
  tmplinks.each_with_index do |link, key|
14665
+ next if link.nil?
14640
14666
  if link[0] > page
14641
14667
  @links[key][0] = link[0] - 1
14642
14668
  elsif link[0] == page
@@ -14815,6 +14841,8 @@ public
14815
14841
  movePage(page_last, page)
14816
14842
  end
14817
14843
  end
14844
+ rescue => err
14845
+ Error('addTOC Error.', err)
14818
14846
  end
14819
14847
  alias_method :add_toc, :addTOC
14820
14848
 
@@ -14919,6 +14947,8 @@ public
14919
14947
  movePage(page_last, page)
14920
14948
  end
14921
14949
  end
14950
+ rescue => err
14951
+ Error('addHTMLTOC Error.', err)
14922
14952
  end
14923
14953
  alias_method :add_html_toc, :addHTMLTOC
14924
14954
 
@@ -3,5 +3,5 @@
3
3
  # http://www.opensource.org/licenses/MIT
4
4
 
5
5
  module Rbpdf
6
- VERSION = "1.19.2"
6
+ VERSION = "1.19.3"
7
7
  end
@@ -286,17 +286,17 @@ class RbpdfFontTest < Test::Unit::TestCase
286
286
  pdf = RBPDF.new
287
287
  RBPDF.k_path_fonts = File.join File.dirname(__FILE__)
288
288
 
289
- err = assert_raises(RuntimeError) {
289
+ err = assert_raises(RBPDFError) {
290
290
  pdf.set_font('err_font', '', 18)
291
291
  }
292
292
  assert_equal 'RBPDF error: Could not include font definition file: err_font', err.message
293
293
 
294
- err = assert_raises(RuntimeError) {
294
+ err = assert_raises(RBPDFError) {
295
295
  pdf.set_font('err_font1', '', 18)
296
296
  }
297
297
  assert_match(/RBPDF error: The font definition file has a bad format: .*err_font1.rb/, err.message)
298
298
 
299
- err = assert_raises(RuntimeError) {
299
+ err = assert_raises(RBPDFError) {
300
300
  pdf.set_font('err_font2', '', 18)
301
301
  }
302
302
  assert_equal 'RBPDF error: Unknow font type: Type0', err.message
@@ -79,7 +79,7 @@ class RbpdfTest < Test::Unit::TestCase
79
79
  pdf.write_html(htmlcontent, true, 0, true, 0)
80
80
 
81
81
  pdf.send(:mapLinksToHtmlAnchors)
82
- link_position = pdf.instance_variable_get(:@links)[1]
82
+ link_position = pdf.instance_variable_get(:@links)[0]
83
83
  assert_equal [3, 73.50124999999998], link_position
84
84
  end
85
85
 
@@ -98,7 +98,7 @@ class RbpdfTest < Test::Unit::TestCase
98
98
 
99
99
  pdf.send(:mapLinksToHtmlAnchors)
100
100
 
101
- link_position = pdf.instance_variable_get(:@links)[1]
101
+ link_position = pdf.instance_variable_get(:@links)[0]
102
102
  assert_equal [1, 10.001249999999999], link_position
103
103
  end
104
104
 
@@ -5,15 +5,6 @@
5
5
  require 'test_helper'
6
6
 
7
7
  class RbpdfTest < Test::Unit::TestCase
8
- class MYPDF < RBPDF
9
- def imageToPNG(file)
10
- super
11
- end
12
- def parsepng(file)
13
- super
14
- end
15
- end
16
-
17
8
  test "image getimagesize PNG test" do
18
9
  pdf = RBPDF.new
19
10
  pdf.add_page
@@ -126,70 +117,95 @@ class RbpdfTest < Test::Unit::TestCase
126
117
  end
127
118
 
128
119
  test "imageToPNG delete GIF test" do
129
- pdf = MYPDF.new
120
+ return unless Object.const_defined?(:Magick)
121
+ pdf = RBPDF.new
130
122
  pdf.add_page
131
123
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.gif')
132
124
 
133
- if Object.const_defined?(:Magick)
134
- tempfile = pdf.imageToPNG(img_file)
135
- assert_not_equal false, tempfile
125
+ tempfile = pdf.send(:imageToPNG, img_file)
126
+ assert_not_equal false, tempfile
127
+
128
+ info = pdf.send(:parsepng, tempfile.path)
129
+
130
+ assert_not_equal 'pngalpha', info
131
+ assert_equal 8, info['bpc']
132
+ assert_equal 'Indexed', info['cs']
133
+ end
134
+
135
+ test "Magick::ImageList delete GIF alpha channel test" do
136
+ return unless Object.const_defined?(:Magick)
137
+ pdf = RBPDF.new
138
+ pdf.add_page
139
+ img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit_alpha.gif')
136
140
 
137
- info = pdf.parsepng(tempfile.path)
141
+ img = Magick::ImageList.new(img_file)
142
+ img.format = 'PNG' # convert to PNG from gif
143
+ assert_equal true, img.alpha?
138
144
 
139
- assert_not_equal 'pngalpha', info
140
- assert_equal 8, info['bpc']
141
- assert_equal 'Indexed', info['cs']
142
- end
145
+ img.alpha = Magick::DeactivateAlphaChannel # PNG alpha channel delete
146
+ assert_equal false, img.alpha?
143
147
  end
144
148
 
145
149
  test "imageToPNG delete GIF alpha channel test" do
146
- pdf = MYPDF.new
150
+ return unless Object.const_defined?(:Magick)
151
+ pdf = RBPDF.new
147
152
  pdf.add_page
148
153
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit_alpha.gif')
149
154
 
150
- if Object.const_defined?(:Magick)
151
- tempfile = pdf.imageToPNG(img_file)
152
- assert_not_equal false, tempfile
155
+ tempfile = pdf.send(:imageToPNG, img_file)
156
+ assert_not_equal false, tempfile
153
157
 
154
- info = pdf.parsepng(tempfile.path)
158
+ info = pdf.send(:parsepng, tempfile.path)
155
159
 
156
- assert_not_equal 'pngalpha', info
157
- assert_equal 8, info['bpc']
158
- assert_equal 'Indexed', info['cs']
159
- end
160
+ assert_not_equal 'pngalpha', info
161
+ assert_equal 8, info['bpc']
162
+ assert_equal 'Indexed', info['cs']
160
163
  end
161
164
 
162
165
  test "imageToPNG delete PNG alpha channel test" do
163
- pdf = MYPDF.new
166
+ return unless Object.const_defined?(:Magick)
167
+ pdf = RBPDF.new
164
168
  pdf.add_page
165
169
  img_file = File.join(File.dirname(__FILE__), 'png_test_alpha.png')
166
170
 
167
- if Object.const_defined?(:Magick)
168
- tempfile = pdf.imageToPNG(img_file)
169
- assert_not_equal false, tempfile
171
+ tempfile = pdf.send(:imageToPNG, img_file)
172
+ assert_not_equal false, tempfile
170
173
 
171
- info = pdf.parsepng(tempfile.path)
174
+ info = pdf.send(:parsepng, tempfile.path)
172
175
 
173
- assert_not_equal 'pngalpha', info
174
- assert_equal 8, info['bpc']
175
- assert_equal 'DeviceRGB', info['cs']
176
- end
176
+ assert_not_equal 'pngalpha', info
177
+ assert_equal 8, info['bpc']
178
+ assert_equal 'DeviceRGB', info['cs']
177
179
  end
178
180
 
179
181
  test "image_alpha_mask DeviceGray test" do
180
- pdf = MYPDF.new
182
+ return unless Object.const_defined?(:Magick)
183
+
184
+ pdf = RBPDF.new
181
185
  pdf.add_page
182
186
  img_file = File.join(File.dirname(__FILE__), 'png_test_alpha.png')
183
187
 
184
- if Object.const_defined?(:Magick)
185
- tempfile = pdf.send(:image_alpha_mask, img_file)
188
+ tempfile = pdf.send(:image_alpha_mask, img_file)
189
+
190
+ info = pdf.send(:parsepng, tempfile.path)
191
+
192
+ assert_not_equal 'pngalpha', info
193
+ assert_equal 8, info['bpc']
194
+ assert_equal 'DeviceGray', info['cs']
186
195
 
187
- info = pdf.parsepng(tempfile.path)
196
+ # embed mask image test
197
+ imgmask = pdf.image(tempfile.path, 10, 10, 100, '', 'PNG', '', '', false, 300, '', true, false)
198
+ assert_equal 1, imgmask
199
+ end
200
+
201
+ test "ImagePngAlpha test" do
202
+ return unless Object.const_defined?(:Magick)
188
203
 
189
- assert_not_equal 'pngalpha', info
190
- assert_equal 8, info['bpc']
191
- assert_equal 'DeviceGray', info['cs']
192
- end
204
+ pdf = RBPDF.new
205
+ pdf.add_page
206
+ img_file = File.join(File.dirname(__FILE__), 'png_test_alpha.png')
207
+ info = pdf.send(:ImagePngAlpha, img_file, 10, 10, 100, '', 'PNG', 'https://rubygems.org/gems/rbpdf')
208
+ assert_equal true, info
193
209
  end
194
210
 
195
211
  test "Image PNG test" do
@@ -59,12 +59,12 @@ class RbpdfTest < Test::Unit::TestCase
59
59
  pdf = RBPDF.new
60
60
  pdf.add_page
61
61
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.png')
62
- assert_nothing_raised(RuntimeError) {
62
+ assert_nothing_raised(RBPDFError) {
63
63
  pdf.image(img_file)
64
64
  }
65
65
 
66
66
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit .png')
67
- assert_nothing_raised(RuntimeError) {
67
+ assert_nothing_raised(RBPDFError) {
68
68
  pdf.image(img_file)
69
69
  }
70
70
  end
@@ -76,24 +76,24 @@ class RbpdfTest < Test::Unit::TestCase
76
76
 
77
77
  # utf8_japanese_aiueo_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a"
78
78
  # img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit_' + utf8_japanese_aiueo_str + '.png')
79
- # assert_nothing_raised(RuntimeError) {
79
+ # assert_nothing_raised(RBPDFError) {
80
80
  # pdf.image(img_file)
81
81
  # }
82
82
  #end
83
83
 
84
84
  test "Image basic filename error test" do
85
85
  pdf = RBPDF.new
86
- err = assert_raise(RuntimeError) {
86
+ err = assert_raise(RBPDFError) {
87
87
  pdf.image(nil)
88
88
  }
89
89
  assert_equal 'RBPDF error: Image filename is empty.', err.message
90
90
 
91
- err = assert_raises(RuntimeError) {
91
+ err = assert_raises(RBPDFError) {
92
92
  pdf.image('')
93
93
  }
94
94
  assert_equal 'RBPDF error: Image filename is empty.', err.message
95
95
 
96
- err = assert_raises(RuntimeError) {
96
+ err = assert_raises(RBPDFError) {
97
97
  pdf.image('foo.png')
98
98
  }
99
99
  assert_equal 'RBPDF error: Missing image file: foo.png', err.message
@@ -174,7 +174,7 @@ class RbpdfTest < Test::Unit::TestCase
174
174
  pages = pdf.get_num_pages
175
175
  assert_equal 1, pages
176
176
 
177
- assert_raise(RuntimeError) {pdf.set_page(0)} # Page under size
177
+ assert_raise(RBPDFError) {pdf.set_page(0)} # Page under size
178
178
  end
179
179
 
180
180
  test "add_page set_page Over Error" do
@@ -201,7 +201,7 @@ class RbpdfTest < Test::Unit::TestCase
201
201
  page = pdf.get_page
202
202
  assert_equal 1, page
203
203
 
204
- assert_raise(RuntimeError) {pdf.set_page(3)} # Page over size
204
+ assert_raise(RBPDFError) {pdf.set_page(3)} # Page over size
205
205
  end
206
206
 
207
207
  test "deletePage 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.2
4
+ version: 1.19.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - NAITOH Jun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-08 00:00:00.000000000 Z
11
+ date: 2017-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -98,12 +98,9 @@ files:
98
98
  - lib/htmlcolors.rb
99
99
  - lib/rbpdf.rb
100
100
  - lib/rbpdf/version.rb
101
- - lib/rbpdf_encode_ok.rb
102
- - lib/rbpdf_encode_ok2.rb
103
101
  - lib/unicode_data.rb
104
102
  - logo_example.png
105
103
  - rbpdf.gemspec
106
- - test/_rbpdf_image_test.rb_
107
104
  - test/err_font1.rb
108
105
  - test/err_font2.rb
109
106
  - test/logo_rbpdf_8bit .png
@@ -171,12 +168,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
168
  version: '0'
172
169
  requirements: []
173
170
  rubyforge_project:
174
- rubygems_version: 2.2.2
171
+ rubygems_version: 2.4.5.1
175
172
  signing_key:
176
173
  specification_version: 4
177
174
  summary: RBPDF via TCPDF.
178
175
  test_files:
179
- - test/_rbpdf_image_test.rb_
180
176
  - test/err_font1.rb
181
177
  - test/err_font2.rb
182
178
  - test/logo_rbpdf_8bit .png