rbpdf 1.19.0 → 1.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +10 -0
  3. data/Gemfile +4 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +16 -0
  6. data/Rakefile +4 -0
  7. data/lib/core/rmagick.rb +1 -1
  8. data/lib/rbpdf.rb +82 -47
  9. data/lib/rbpdf/version.rb +5 -1
  10. data/lib/rbpdf_encode_ok.rb +15170 -0
  11. data/lib/rbpdf_encode_ok2.rb +15178 -0
  12. data/lib/unicode_data.rb +18 -1
  13. data/rbpdf.gemspec +21 -5
  14. data/test/_rbpdf_image_test.rb_ +161 -0
  15. data/test/err_font1.rb +4 -0
  16. data/test/err_font2.rb +4 -0
  17. data/test/logo_rbpdf_8bit .png +0 -0
  18. data/test/logo_rbpdf_8bit+ .png +0 -0
  19. data/test/logo_rbpdf_8bit_/343/201/202/343/201/204/343/201/206/343/201/210/343/201/212.png +0 -0
  20. data/test/rbpdf_bidi_test.rb +76 -71
  21. data/test/rbpdf_bookmark_test.rb +38 -28
  22. data/test/rbpdf_cell_test.rb +120 -40
  23. data/test/rbpdf_content_test.rb +62 -45
  24. data/test/rbpdf_css_test.rb +275 -271
  25. data/test/rbpdf_dom_test.rb +123 -113
  26. data/test/rbpdf_font_func_test.rb +6 -2
  27. data/test/rbpdf_font_style_test.rb +7 -3
  28. data/test/rbpdf_font_test.rb +44 -27
  29. data/test/rbpdf_format_test.rb +15 -11
  30. data/test/rbpdf_func_test.rb +26 -22
  31. data/test/rbpdf_html_anchor_test.rb +11 -13
  32. data/test/rbpdf_html_func_test.rb +34 -30
  33. data/test/rbpdf_html_test.rb +58 -5
  34. data/test/rbpdf_htmlcell_test.rb +10 -6
  35. data/test/rbpdf_http_test.rb +67 -0
  36. data/test/rbpdf_image_rmagick_test.rb +70 -87
  37. data/test/rbpdf_image_test.rb +86 -22
  38. data/test/rbpdf_test.rb +88 -90
  39. data/test/rbpdf_transaction_test.rb +4 -0
  40. data/test/rbpdf_viewerpreferences_test.rb +5 -1
  41. data/test/rbpdf_write_test.rb +49 -45
  42. data/test/test_helper.rb +5 -0
  43. data/test_unicode.rbpdf +4 -0
  44. metadata +22 -9
@@ -1,3 +1,7 @@
1
+ # Copyright (c) 2011-2017 NAITOH Jun
2
+ # Released under the MIT license
3
+ # http://www.opensource.org/licenses/MIT
4
+
1
5
  require 'test_helper'
2
6
 
3
7
  class RbpdfTest < Test::Unit::TestCase
@@ -9,13 +13,13 @@ class RbpdfTest < Test::Unit::TestCase
9
13
  pdf.write_html_cell(0, 5, 10, '', htmlcontent, 0, 1)
10
14
 
11
15
  pno = pdf.get_page
12
- assert_equal pno, 1
16
+ assert_equal 1, pno
13
17
 
14
18
  y = pdf.get_y
15
19
  assert_in_delta 17.3, y, 0.1
16
20
 
17
21
  no = pdf.get_num_pages
18
- assert_equal no, 1
22
+ assert_equal 1, no
19
23
  end
20
24
 
21
25
  test "write_html_cell Page Break test 1" do
@@ -31,13 +35,13 @@ class RbpdfTest < Test::Unit::TestCase
31
35
  pdf.write_html_cell(0, 5, 10, '', htmlcontent, 0, 1)
32
36
 
33
37
  pno = pdf.get_page
34
- assert_equal pno, 2
38
+ assert_equal 2, pno
35
39
 
36
40
  y = pdf.get_y
37
41
  assert_in_delta 40.0, y, 0.1
38
42
 
39
43
  no = pdf.get_num_pages
40
- assert_equal no, 2
44
+ assert_equal 2, no
41
45
  end
42
46
 
43
47
  test "write_html_cell Page Break test 2" do
@@ -53,12 +57,12 @@ class RbpdfTest < Test::Unit::TestCase
53
57
  pdf.write_html_cell(0, 5, 10, '', htmlcontent, "LRBT", 1)
54
58
 
55
59
  pno = pdf.get_page
56
- assert_equal pno, 2
60
+ assert_equal 2, pno
57
61
 
58
62
  y = pdf.get_y
59
63
  assert_in_delta 40.0, y, 0.1
60
64
 
61
65
  no = pdf.get_num_pages
62
- assert_equal no, 2
66
+ assert_equal 2, no
63
67
  end
64
68
  end
@@ -0,0 +1,67 @@
1
+ # Copyright (c) 2011-2017 NAITOH Jun
2
+ # Released under the MIT license
3
+ # http://www.opensource.org/licenses/MIT
4
+
5
+ require 'test_helper'
6
+
7
+ class RbpdfHttpTest < Test::Unit::TestCase
8
+ class MYPDF < RBPDF
9
+ def get_image_file(uri)
10
+ super
11
+ end
12
+ end
13
+
14
+ def setup
15
+ require 'webrick'
16
+ @port = 51234
17
+
18
+ dir = File.dirname(__FILE__)
19
+ @s = WEBrick::HTTPServer.new(:Port => @port, :DocumentRoot => dir, :BindAddress => "0.0.0.0", :DoNotReverseLookup => true)
20
+ @t = Thread.new { @s.start }
21
+ end
22
+
23
+ test "Image get image file test" do
24
+ utf8_japanese_aiueo_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a"
25
+
26
+ images = [
27
+ 'logo_rbpdf_8bit.png',
28
+ 'logo_rbpdf_8bit .png',
29
+ 'logo_rbpdf_8bit+ .png',
30
+ ]
31
+ if RUBY_VERSION >= '2.0' # Ruby 1.9.2/1.9.3
32
+ images << 'logo_rbpdf_8bit_' + utf8_japanese_aiueo_str + '.png'
33
+ end
34
+
35
+ pdf = MYPDF.new
36
+ images.each_with_index {|image, i|
37
+ pdf.add_page
38
+ #tmpFile = pdf.get_image_file('http://127.0.0.1:' + @port.to_s + '/logo_rbpdf_8bit.png')
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 + '/' + image)
41
+ #image.force_encoding('ASCII-8BIT') if image.respond_to?(:force_encoding)
42
+ tmpFile = pdf.get_image_file('http://127.0.0.1:' + @port.to_s + '/' + image)
43
+ img_file = tmpFile.path
44
+ assert_not_equal "", img_file
45
+ unless File.exist?(img_file)
46
+ assert false, "file not found. :" + img_file
47
+ end
48
+
49
+ result_img = pdf.image(img_file, 50, 0, 0, '', '', '', '', false, 300, '', true)
50
+ assert_equal i+1, result_img
51
+ no = pdf.get_num_pages
52
+ assert_equal i+1, no
53
+
54
+ # remove temp files
55
+ tmpFile.delete unless tmpFile.nil?
56
+
57
+ if File.exist?(img_file)
58
+ assert false, "file found. :" + img_file
59
+ end
60
+ }
61
+ end
62
+
63
+ def teardown
64
+ @s.shutdown
65
+ @t.join
66
+ end
67
+ end
@@ -1,3 +1,7 @@
1
+ # Copyright (c) 2011-2017 NAITOH Jun
2
+ # Released under the MIT license
3
+ # http://www.opensource.org/licenses/MIT
4
+
1
5
  require 'test_helper'
2
6
 
3
7
  class RbpdfTest < Test::Unit::TestCase
@@ -16,14 +20,11 @@ class RbpdfTest < Test::Unit::TestCase
16
20
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.png')
17
21
 
18
22
  info = pdf.getimagesize(img_file)
19
- pixw = info[0]
20
- pixh = info[1]
21
- fileinfo = info[2]
22
- assert_equal info[0], 240 # width
23
- assert_equal info[1], 89 # height
24
- assert_equal info[2], 'PNG' # Image Type
25
- assert_equal info[3], 'height="89" width="240"'
26
- assert_equal info['mime'], 'image/png'
23
+ assert_equal 240, info[0] # width
24
+ assert_equal 89, info[1] # height
25
+ assert_equal 'PNG', info[2] # Image Type
26
+ assert_equal 'height="89" width="240"', info[3]
27
+ assert_equal 'image/png', info['mime']
27
28
  end
28
29
 
29
30
  test "image getimagesize GIF test" do
@@ -34,16 +35,13 @@ class RbpdfTest < Test::Unit::TestCase
34
35
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.gif')
35
36
 
36
37
  info = pdf.getimagesize(img_file)
37
- pixw = info[0]
38
- pixh = info[1]
39
- fileinfo = info[2]
40
- assert_equal info[0], 240 # width
41
- assert_equal info[1], 89 # height
42
- assert_equal info[2], 'GIF' # Image Type
43
- assert_equal info[3], 'height="89" width="240"'
44
- assert_equal info['mime'], 'image/gif'
45
- assert_equal info['channels'], 3 # RGB
46
- assert_equal info['bits'], 8 # depth
38
+ assert_equal 240, info[0] # width
39
+ assert_equal 89, info[1] # height
40
+ assert_equal 'GIF', info[2] # Image Type
41
+ assert_equal 'height="89" width="240"', info[3]
42
+ assert_equal 'image/gif', info['mime']
43
+ assert_equal 3, info['channels'] # RGB
44
+ assert_equal 8, info['bits'] # depth
47
45
  end
48
46
 
49
47
  test "image getimagesize GIF alpha test" do
@@ -54,16 +52,13 @@ class RbpdfTest < Test::Unit::TestCase
54
52
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit_alpha.gif')
55
53
 
56
54
  info = pdf.getimagesize(img_file)
57
- pixw = info[0]
58
- pixh = info[1]
59
- fileinfo = info[2]
60
- assert_equal info[0], 240 # width
61
- assert_equal info[1], 89 # height
62
- assert_equal info[2], 'GIF' # Image Type
63
- assert_equal info[3], 'height="89" width="240"'
64
- assert_equal info['mime'], 'image/gif'
65
- assert_equal info['channels'], 3 # RGB
66
- assert_equal info['bits'], 8 # depth
55
+ assert_equal 240, info[0] # width
56
+ assert_equal 89, info[1] # height
57
+ assert_equal 'GIF', info[2] # Image Type
58
+ assert_equal 'height="89" width="240"', info[3]
59
+ assert_equal 'image/gif', info['mime']
60
+ assert_equal 3, info['channels'] # RGB
61
+ assert_equal 8, info['bits'] # depth
67
62
  end
68
63
 
69
64
  test "image getimagesize JPEG RGB test" do
@@ -74,16 +69,13 @@ class RbpdfTest < Test::Unit::TestCase
74
69
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.jpg')
75
70
 
76
71
  info = pdf.getimagesize(img_file)
77
- pixw = info[0]
78
- pixh = info[1]
79
- fileinfo = info[2]
80
- assert_equal info[0], 240 # width
81
- assert_equal info[1], 89 # height
82
- assert_equal info[2], 'JPEG' # Image Type
83
- assert_equal info[3], 'height="89" width="240"'
84
- assert_equal info['mime'], 'image/jpeg'
85
- assert_equal info['channels'], 3 # RGB
86
- assert_equal info['bits'], 8 # depth
72
+ assert_equal 240, info[0] # width
73
+ assert_equal 89, info[1] # height
74
+ assert_equal 'JPEG', info[2] # Image Type
75
+ assert_equal 'height="89" width="240"', info[3]
76
+ assert_equal 'image/jpeg', info['mime']
77
+ assert_equal 3, info['channels'] # RGB
78
+ assert_equal 8, info['bits'] # depth
87
79
  end
88
80
 
89
81
  test "image getimagesize JPEG monotone RGB test" do
@@ -94,16 +86,13 @@ class RbpdfTest < Test::Unit::TestCase
94
86
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_mono_rgb.jpg')
95
87
 
96
88
  info = pdf.getimagesize(img_file)
97
- pixw = info[0]
98
- pixh = info[1]
99
- fileinfo = info[2]
100
- assert_equal info[0], 240 # width
101
- assert_equal info[1], 89 # height
102
- assert_equal info[2], 'JPEG' # Image Type
103
- assert_equal info[3], 'height="89" width="240"'
104
- assert_equal info['mime'], 'image/jpeg'
105
- assert_equal info['channels'], 3 # RGB
106
- assert_equal info['bits'], 8 # depth
89
+ assert_equal 240, info[0] # width
90
+ assert_equal 89, info[1] # height
91
+ assert_equal 'JPEG', info[2] # Image Type
92
+ assert_equal 'height="89" width="240"', info[3]
93
+ assert_equal 'image/jpeg', info['mime']
94
+ assert_equal 3, info['channels'] # RGB
95
+ assert_equal 8, info['bits'] # depth
107
96
  end
108
97
 
109
98
  test "image getimagesize JPEG monotone Gray test" do
@@ -114,16 +103,13 @@ class RbpdfTest < Test::Unit::TestCase
114
103
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_mono_gray.jpg')
115
104
 
116
105
  info = pdf.getimagesize(img_file)
117
- pixw = info[0]
118
- pixh = info[1]
119
- fileinfo = info[2]
120
- assert_equal info[0], 240 # width
121
- assert_equal info[1], 89 # height
122
- assert_equal info[2], 'JPEG' # Image Type
123
- assert_equal info[3], 'height="89" width="240"'
124
- assert_equal info['mime'], 'image/jpeg'
125
- assert_equal info['channels'], 0 # Gray
126
- assert_equal info['bits'], 8 # depth
106
+ assert_equal 240, info[0] # width
107
+ assert_equal 89, info[1] # height
108
+ assert_equal 'JPEG', info[2] # Image Type
109
+ assert_equal 'height="89" width="240"', info[3]
110
+ assert_equal 'image/jpeg', info['mime']
111
+ assert_equal 0, info['channels'] # Gray
112
+ assert_equal 8, info['bits'] # depth
127
113
  end
128
114
 
129
115
  test "image getimagesize PNG monotone test" do
@@ -132,14 +118,11 @@ class RbpdfTest < Test::Unit::TestCase
132
118
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_mono_rgb.png')
133
119
 
134
120
  info = pdf.getimagesize(img_file)
135
- pixw = info[0]
136
- pixh = info[1]
137
- fileinfo = info[2]
138
- assert_equal info[0], 240 # width
139
- assert_equal info[1], 89 # height
140
- assert_equal info[2], 'PNG' # Image Type
141
- assert_equal info[3], 'height="89" width="240"'
142
- assert_equal info['mime'], 'image/png'
121
+ assert_equal 240, info[0] # width
122
+ assert_equal 89, info[1] # height
123
+ assert_equal 'PNG', info[2] # Image Type
124
+ assert_equal 'height="89" width="240"', info[3]
125
+ assert_equal 'image/png', info['mime']
143
126
  end
144
127
 
145
128
  test "imageToPNG delete GIF test" do
@@ -149,13 +132,13 @@ class RbpdfTest < Test::Unit::TestCase
149
132
 
150
133
  if Object.const_defined?(:Magick)
151
134
  tempfile = pdf.imageToPNG(img_file)
152
- assert_not_equal tempfile, false
135
+ assert_not_equal false, tempfile
153
136
 
154
137
  info = pdf.parsepng(tempfile.path)
155
138
 
156
- assert_not_equal info, 'pngalpha'
157
- assert_equal info['bpc'], 8
158
- assert_equal info['cs'], 'Indexed'
139
+ assert_not_equal 'pngalpha', info
140
+ assert_equal 8, info['bpc']
141
+ assert_equal 'Indexed', info['cs']
159
142
  end
160
143
  end
161
144
 
@@ -166,13 +149,13 @@ class RbpdfTest < Test::Unit::TestCase
166
149
 
167
150
  if Object.const_defined?(:Magick)
168
151
  tempfile = pdf.imageToPNG(img_file)
169
- assert_not_equal tempfile, false
152
+ assert_not_equal false, tempfile
170
153
 
171
154
  info = pdf.parsepng(tempfile.path)
172
155
 
173
- assert_not_equal info, 'pngalpha'
174
- assert_equal info['bpc'], 8
175
- assert_equal info['cs'], 'Indexed'
156
+ assert_not_equal 'pngalpha', info
157
+ assert_equal 8, info['bpc']
158
+ assert_equal 'Indexed', info['cs']
176
159
  end
177
160
  end
178
161
 
@@ -183,13 +166,13 @@ class RbpdfTest < Test::Unit::TestCase
183
166
 
184
167
  if Object.const_defined?(:Magick)
185
168
  tempfile = pdf.imageToPNG(img_file)
186
- assert_not_equal tempfile, false
169
+ assert_not_equal false, tempfile
187
170
 
188
171
  info = pdf.parsepng(tempfile.path)
189
172
 
190
- assert_not_equal info, 'pngalpha'
191
- assert_equal info['bpc'], 8
192
- assert_equal info['cs'], 'DeviceRGB'
173
+ assert_not_equal 'pngalpha', info
174
+ assert_equal 8, info['bpc']
175
+ assert_equal 'DeviceRGB', info['cs']
193
176
  end
194
177
  end
195
178
 
@@ -199,13 +182,13 @@ class RbpdfTest < Test::Unit::TestCase
199
182
  img_file = File.join(File.dirname(__FILE__), 'png_test_alpha.png')
200
183
 
201
184
  if Object.const_defined?(:Magick)
202
- tempfile = pdf.image_alpha_mask(img_file)
185
+ tempfile = pdf.send(:image_alpha_mask, img_file)
203
186
 
204
187
  info = pdf.parsepng(tempfile.path)
205
188
 
206
- assert_not_equal info, 'pngalpha'
207
- assert_equal info['bpc'], 8
208
- assert_equal info['cs'], 'DeviceGray'
189
+ assert_not_equal 'pngalpha', info
190
+ assert_equal 8, info['bpc']
191
+ assert_equal 'DeviceGray', info['cs']
209
192
  end
210
193
  end
211
194
 
@@ -214,7 +197,7 @@ class RbpdfTest < Test::Unit::TestCase
214
197
  pdf.add_page
215
198
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.png')
216
199
  info = pdf.image(img_file, 10, 10, 100, '', '', 'https://rubygems.org/gems/rbpdf', '', false, 300)
217
- assert_equal info, 1
200
+ assert_equal 1, info
218
201
  end
219
202
 
220
203
  test "Image PNG alpha test" do
@@ -224,7 +207,7 @@ class RbpdfTest < Test::Unit::TestCase
224
207
  pdf.add_page
225
208
  img_file = File.join(File.dirname(__FILE__), 'png_test_alpha.png')
226
209
  info = pdf.image(img_file, 10, 10, 100, '', '', 'https://rubygems.org/gems/rbpdf', '', false, 300)
227
- assert_equal info, true
210
+ assert_equal true, info
228
211
  end
229
212
 
230
213
  test "Image GIF test" do
@@ -234,7 +217,7 @@ class RbpdfTest < Test::Unit::TestCase
234
217
  pdf.add_page
235
218
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.gif')
236
219
  info = pdf.image(img_file, 10, 10, 100, '', '', 'https://rubygems.org/gems/rbpdf', '', false, 300)
237
- assert_equal info, 1
220
+ assert_equal 1, info
238
221
  end
239
222
 
240
223
  test "Image GIF alpha test" do
@@ -244,7 +227,7 @@ class RbpdfTest < Test::Unit::TestCase
244
227
  pdf.add_page
245
228
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit_alpha.gif')
246
229
  info = pdf.image(img_file, 10, 10, 100, '', '', 'https://rubygems.org/gems/rbpdf', '', false, 300)
247
- assert_equal info, 1
230
+ assert_equal 1, info
248
231
  end
249
232
 
250
233
  test "Image JPEG test" do
@@ -254,7 +237,7 @@ class RbpdfTest < Test::Unit::TestCase
254
237
  pdf.add_page
255
238
  img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.jpg')
256
239
  info = pdf.image(img_file, 10, 10, 100, '', '', 'https://rubygems.org/gems/rbpdf', '', false, 300)
257
- assert_equal info, 1
240
+ assert_equal 1, info
258
241
  end
259
242
 
260
243
  test "HTML Image test" do
@@ -1,3 +1,7 @@
1
+ # Copyright (c) 2011-2017 NAITOH Jun
2
+ # Released under the MIT license
3
+ # http://www.opensource.org/licenses/MIT
4
+
1
5
  require 'test_helper'
2
6
 
3
7
  class RbpdfTest < Test::Unit::TestCase
@@ -5,68 +9,93 @@ class RbpdfTest < Test::Unit::TestCase
5
9
  pdf = RBPDF.new
6
10
 
7
11
  type = pdf.get_image_file_type("/tmp/rbpdf_logo.gif")
8
- assert_equal type, "gif"
12
+ assert_equal 'gif', type
9
13
 
10
14
  type = pdf.get_image_file_type("/tmp/rbpdf_logo.PNG")
11
- assert_equal type, "png"
15
+ assert_equal 'png', type
12
16
 
13
17
  type = pdf.get_image_file_type("/tmp/rbpdf_logo.jpg")
14
- assert_equal type, "jpeg"
18
+ assert_equal 'jpeg', type
15
19
 
16
20
  type = pdf.get_image_file_type("/tmp/rbpdf_logo.jpeg")
17
- assert_equal type, "jpeg"
21
+ assert_equal 'jpeg', type
18
22
 
19
23
  type = pdf.get_image_file_type("/tmp/rbpdf_logo")
20
- assert_equal type, ""
24
+ assert_equal '', type
21
25
 
22
26
  type = pdf.get_image_file_type("")
23
- assert_equal type, ""
27
+ assert_equal '', type
24
28
 
25
29
  type = pdf.get_image_file_type(nil)
26
- assert_equal type, ""
30
+ assert_equal '', type
27
31
  end
28
32
 
29
33
  test "Image basic func mime type test" do
30
34
  pdf = RBPDF.new
31
35
 
32
36
  type = pdf.get_image_file_type(nil, {})
33
- assert_equal type, ''
37
+ assert_equal '', type
34
38
 
35
39
  type = pdf.get_image_file_type(nil, {'mime' => 'image/gif'})
36
- assert_equal type, 'gif'
40
+ assert_equal 'gif', type
37
41
 
38
42
  type = pdf.get_image_file_type(nil, {'mime' => 'image/jpeg'})
39
- assert_equal type, 'jpeg'
43
+ assert_equal 'jpeg', type
40
44
 
41
45
  type = pdf.get_image_file_type('/tmp/rbpdf_logo.gif', {'mime' => 'image/png'})
42
- assert_equal type, 'png'
46
+ assert_equal 'png', type
43
47
 
44
48
  type = pdf.get_image_file_type('/tmp/rbpdf_logo.gif', {})
45
- assert_equal type, 'gif'
49
+ assert_equal 'gif', type
46
50
 
47
51
  type = pdf.get_image_file_type(nil, {'mime' => 'text/html'})
48
- assert_equal type, ''
52
+ assert_equal '', type
49
53
 
50
54
  type = pdf.get_image_file_type(nil, [])
51
- assert_equal type, ''
55
+ assert_equal '', type
52
56
  end
53
57
 
54
- test "Image basic filename test" do
58
+ test "Image basic ascii filename test" do
55
59
  pdf = RBPDF.new
56
- err = assert_raises(RuntimeError) {
60
+ pdf.add_page
61
+ img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit.png')
62
+ assert_nothing_raised(RuntimeError) {
63
+ pdf.image(img_file)
64
+ }
65
+
66
+ img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit .png')
67
+ assert_nothing_raised(RuntimeError) {
68
+ pdf.image(img_file)
69
+ }
70
+ end
71
+
72
+ test "Image basic non ascii filename test" do
73
+ pdf = RBPDF.new
74
+ pdf.add_page
75
+
76
+ utf8_japanese_aiueo_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a"
77
+ img_file = File.join(File.dirname(__FILE__), 'logo_rbpdf_8bit_' + utf8_japanese_aiueo_str + '.png')
78
+ assert_nothing_raised(RuntimeError) {
79
+ pdf.image(img_file)
80
+ }
81
+ end
82
+
83
+ test "Image basic filename error test" do
84
+ pdf = RBPDF.new
85
+ err = assert_raise(RuntimeError) {
57
86
  pdf.image(nil)
58
87
  }
59
- assert_equal( err.message, 'RBPDF error: Image filename is empty.')
88
+ assert_equal 'RBPDF error: Image filename is empty.', err.message
60
89
 
61
90
  err = assert_raises(RuntimeError) {
62
91
  pdf.image('')
63
92
  }
64
- assert_equal( err.message, 'RBPDF error: Image filename is empty.')
93
+ assert_equal 'RBPDF error: Image filename is empty.', err.message
65
94
 
66
95
  err = assert_raises(RuntimeError) {
67
96
  pdf.image('foo.png')
68
97
  }
69
- assert_equal( err.message, 'RBPDF error: Missing image file: foo.png')
98
+ assert_equal 'RBPDF error: Missing image file: foo.png', err.message
70
99
  end
71
100
 
72
101
  test "Image basic test" do
@@ -77,7 +106,8 @@ class RbpdfTest < Test::Unit::TestCase
77
106
  result_img = pdf.image(img_file, 50, 0, 0, '', '', '', '', false, 300, '', true)
78
107
 
79
108
  no = pdf.get_num_pages
80
- assert_equal no, 1
109
+ assert_equal 1, no
110
+ assert_equal 1, result_img
81
111
  end
82
112
 
83
113
  test "Image fitonpage test 1" do
@@ -88,7 +118,8 @@ class RbpdfTest < Test::Unit::TestCase
88
118
  result_img = pdf.image(img_file, 50, 140, 100, '', '', '', '', false, 300, '', true, false, 0, false, false, true)
89
119
 
90
120
  no = pdf.get_num_pages
91
- assert_equal no, 1
121
+ assert_equal 1, no
122
+ assert_equal 1, result_img
92
123
  end
93
124
 
94
125
  test "Image fitonpage test 2" do
@@ -102,6 +133,39 @@ class RbpdfTest < Test::Unit::TestCase
102
133
  result_img = pdf.image(img_file, '', y, w, h, '', '', '', false, 300, '', true, false, 0, false, false, true)
103
134
 
104
135
  no = pdf.get_num_pages
105
- assert_equal no, 1
136
+ assert_equal 1, no
137
+ assert_equal 1, result_img
138
+ end
139
+
140
+ test "HTML Image test without RMagick" do
141
+ return if Object.const_defined?(:Magick)
142
+
143
+ utf8_japanese_aiueo_str = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a"
144
+
145
+ images = {
146
+ 'png_test_msk_alpha.png' => 40.11,
147
+ 'png_test_non_alpha.png' => 40.11,
148
+ 'logo_rbpdf_8bit.png' => 36.58,
149
+ 'logo_rbpdf_8bit .png' => 36.58,
150
+ 'logo_rbpdf_8bit+ .png' => 36.58,
151
+ 'logo_rbpdf_8bit_' + utf8_japanese_aiueo_str + '.png' => 36.58,
152
+ 'ng.png' => 9.42
153
+ }
154
+
155
+ pdf = RBPDF.new
156
+ images.each {|image, h|
157
+ pdf.add_page
158
+ img_file = File.join(File.dirname(__FILE__), image)
159
+ htmlcontent = '<img src="'+ img_file + '"/>'
160
+
161
+ x_org = pdf.get_x
162
+ y_org = pdf.get_y
163
+ pdf.write_html(htmlcontent, true, 0, true, 0)
164
+ x = pdf.get_x
165
+ y = pdf.get_y
166
+
167
+ assert_equal '[' + image + ']:' + x_org.to_s, '[' + image + ']:' + x.to_s
168
+ assert_equal '[' + image + ']:' + (y_org + h).round(2).to_s, '[' + image + ']:' + y.round(2).to_s
169
+ }
106
170
  end
107
171
  end