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
@@ -5,52 +9,58 @@ class RbpdfTest < Test::Unit::TestCase
5
9
  pdf = RBPDF.new
6
10
  pdf.add_page()
7
11
 
12
+ # Adds a bookmark.
13
+ # [@param string :txt] bookmark description.
14
+ # [@param int :level] bookmark level.
15
+ # [@param float :y] Ordinate of the boorkmark position (default = -1 = current position).
16
+ # [@param int :page] target page number (leave empty for current page).
17
+
8
18
  book = pdf.bookmark('Chapter 1', 0, 0)
9
- assert_equal book, [{:l=>0, :y=>0, :t=>"Chapter 1", :p=>1}]
19
+ assert_equal [{:l=>0, :y=>0, :t=>"Chapter 1", :p=>1}], book
10
20
 
11
21
  book = pdf.bookmark('Paragraph 1.1', 1, 0)
12
- assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
13
- {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1}]
22
+ assert_equal [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
23
+ {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1}], book
14
24
 
15
25
  pdf.add_page()
16
26
 
17
27
  book = pdf.bookmark('Paragraph 1.2', 1, 0)
18
- assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
19
- {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
20
- {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2}]
28
+ assert_equal [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
29
+ {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
30
+ {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2}], book
21
31
 
22
32
  book = pdf.bookmark('Sub-Paragraph 1.2.1', 2, 10)
23
- assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
24
- {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
25
- {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
26
- {:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2}]
33
+ assert_equal [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
34
+ {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
35
+ {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
36
+ {:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2}], book
27
37
 
28
38
  pdf.add_page()
29
39
 
30
40
  book = pdf.bookmark('Paragraph 1.3', 1, 0)
31
- assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
32
- {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
33
- {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
34
- {:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
35
- {:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3}]
41
+ assert_equal [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
42
+ {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
43
+ {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
44
+ {:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
45
+ {:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3}], book
36
46
 
37
47
  book = pdf.bookmark('Sub-Paragraph 1.1.1', 2, 0, 2)
38
- assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
39
- {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
40
- {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
41
- {:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
42
- {:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3},
43
- {:y=>0, :l=>2, :t=>"Sub-Paragraph 1.1.1", :p=>2}]
48
+ assert_equal [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
49
+ {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
50
+ {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
51
+ {:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
52
+ {:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3},
53
+ {:y=>0, :l=>2, :t=>"Sub-Paragraph 1.1.1", :p=>2}], book
44
54
 
45
55
  pdf.add_page()
46
56
 
47
57
  book = pdf.bookmark('Paragraph 1.4', 1, 20)
48
- assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
49
- {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
50
- {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
51
- {:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
52
- {:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3},
53
- {:y=>0, :l=>2, :t=>"Sub-Paragraph 1.1.1", :p=>2},
54
- {:y=>20, :l=>1, :t=>"Paragraph 1.4", :p=>4}]
58
+ assert_equal [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
59
+ {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
60
+ {:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
61
+ {:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
62
+ {:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3},
63
+ {:y=>0, :l=>2, :t=>"Sub-Paragraph 1.1.1", :p=>2},
64
+ {:y=>20, :l=>1, :t=>"Paragraph 1.4", :p=>4}], book
55
65
  end
56
66
  end
@@ -1,29 +1,62 @@
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
4
- class MYPDF < RBPDF
5
- def getCellCode(w, h=0, txt='', border=0, ln=0, align='', fill=0, link=nil, stretch=0, ignore_min_height=false, calign='T', valign='M')
6
- super
7
- end
8
+ test "getCellCode basic test" do
9
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
10
+ pdf.add_page()
11
+ code = pdf.send(:getCellCode, 10)
12
+ assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g\n", code
13
+ # 0.57 w 0 J 0 j [] 0 d 0 G 0 rg # getCellCode
8
14
  end
9
15
 
10
- test "getCellCode" do
11
- pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
16
+ test "getCellCode text test" do
17
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
12
18
  pdf.add_page()
13
- code = pdf.getCellCode(10)
14
- assert_equal code, "0.57 w 0 J 0 j [] 0 d 0 G 0 g\n"
15
- # 0.57 w 0 J 0 j [] 0 d 0 G 0 rg # getCellCode
19
+ content = []
20
+ contents = pdf.send(:getCellCode, 10, 10, 'abc')
21
+ contents.each_line {|line| content.push line.chomp }
22
+
23
+ assert_equal 2, content.length
24
+ assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[0]
25
+ assert_match(/BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(abc\)\] TJ ET/, content[1])
26
+ # BT
27
+ # 31.19 795.17 Td
28
+ # 0 Tr 0.00 w
29
+ # [(abc)] TJ
30
+ # ET
16
31
  end
17
32
 
18
- test "getCellCode link url align test" do
19
- pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
33
+ test "getCellCode back slash text test" do
34
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
20
35
  pdf.add_page()
21
36
  content = []
22
- contents = pdf.getCellCode(10, 10, 'abc', 'LTRB', 0, '', 0, 'http://example.com')
37
+ contents = pdf.send(:getCellCode, 10, 10, "a\\bc") # use escape() method
23
38
  contents.each_line {|line| content.push line.chomp }
24
39
 
25
- assert_equal content.length, 2
26
- assert_equal content[1], "28.35 813.83 m 28.35 784.91 l S 28.07 813.54 m 56.98 813.54 l S 56.70 813.83 m 56.70 784.91 l S 28.07 785.19 m 56.98 785.19 l S BT 31.19 795.17 Td 0 Tr 0.00 w [(abc)] TJ ET"
40
+ assert_equal 2, content.length
41
+ assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[0]
42
+ assert_match(/BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(a\\\\bc\)\] TJ ET/, content[1])
43
+ # BT
44
+ # 31.19 795.17 Td
45
+ # 0 Tr 0.00 w
46
+ # [(a\\bc)] TJ
47
+ # ET
48
+ end
49
+
50
+ test "getCellCode text align test" do
51
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
52
+ pdf.add_page()
53
+ content = []
54
+ contents = pdf.send(:getCellCode, 10, 10, 'abc', 'LTRB')
55
+ contents.each_line {|line| content.push line.chomp }
56
+
57
+ assert_equal 2, content.length
58
+ assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[0]
59
+ assert_match(/28.35 813.8[23] m 28.35 784.91 l S 28.0[67] 813.54 m 56.98 813.54 l S 56.70 813.8[32] m 56.70 784.91 l S 28.0[67] 785.19 m 56.98 785.19 l S BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(abc\)\] TJ ET/, content[1])
27
60
  # 28.35 813.82 m 28.35 784.91 l S
28
61
  # 28.07 813.54 m 56.98 813.54 l S
29
62
  # 56.70 813.82 m 56.70 784.91 l S
@@ -35,20 +68,67 @@ class RbpdfTest < Test::Unit::TestCase
35
68
  # ET
36
69
  end
37
70
 
71
+ test "getCellCode link url test" do
72
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
73
+ pdf.add_page()
74
+
75
+ # Check Initialize Values
76
+ page_annots = pdf.instance_variable_get('@page_annots')
77
+ assert_equal 0, page_annots.length
78
+ annots = pdf.send(:getannotsrefs, 1)
79
+ assert_equal '', annots
80
+
81
+ content = []
82
+ contents = pdf.send(:getCellCode, 10, 10, 'abc', '', 0, '', 0, 'http://example.com')
83
+ contents.each_line {|line| content.push line.chomp }
84
+
85
+ assert_equal 2, content.length
86
+ assert_match(/BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(abc\)\] TJ ET/, content[1])
87
+ # BT
88
+ # 31.19 795.17 Td
89
+ # 0 Tr 0.00 w
90
+ # [(abc)] TJ
91
+ # ET
92
+
93
+ # Check Annots
94
+ page_annots = pdf.instance_variable_get('@page_annots')
95
+ assert_equal 2, page_annots.length
96
+ assert_equal nil, page_annots[0]
97
+ assert_equal 1, page_annots[1].length
98
+ assert_equal 0, page_annots[1][0]['numspaces']
99
+ assert_equal({"Subtype"=>"Link"}, page_annots[1][0]['opt'])
100
+ assert_equal 'http://example.com', page_annots[1][0]['txt']
101
+
102
+ annots = pdf.send(:getannotsrefs, 1)
103
+ assert_equal " /Annots [ 200001 0 R ]", annots
104
+ end
105
+
38
106
  test "getCellCode link page test" do
39
- pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
107
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
40
108
  pdf.add_page()
41
109
  content = []
42
- contents = pdf.getCellCode(10, 10, 'abc', 0, 0, '', 0, 1)
110
+ contents = pdf.send(:getCellCode, 10, 10, 'abc', 0, 0, '', 0, 1)
43
111
  contents.each_line {|line| content.push line.chomp }
44
112
 
45
- assert_equal content.length, 2
46
- assert_equal content[1], "BT 31.19 795.17 Td 0 Tr 0.00 w [(abc)] TJ ET"
113
+ assert_equal 2, content.length
114
+ assert_match(/BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(abc\)\] TJ ET/, content[1])
47
115
  # BT
48
116
  # 31.19 795.17 Td
49
117
  # 0 Tr 0.00 w
50
118
  # [(abc)] TJ
51
119
  # ET
120
+
121
+ # Check Annots
122
+ page_annots = pdf.instance_variable_get('@page_annots')
123
+ assert_equal 2, page_annots.length
124
+ assert_equal nil, page_annots[0]
125
+ assert_equal 1, page_annots[1].length
126
+ assert_equal 0, page_annots[1][0]['numspaces']
127
+ assert_equal({"Subtype"=>"Link"}, page_annots[1][0]['opt'])
128
+ assert_equal 1, page_annots[1][0]['txt']
129
+
130
+ annots = pdf.send(:getannotsrefs, 1)
131
+ assert_equal " /Annots [ 200001 0 R ]", annots
52
132
  end
53
133
 
54
134
  test "getStringHeight Basic test" do
@@ -61,7 +141,7 @@ class RbpdfTest < Test::Unit::TestCase
61
141
  y1 = pdf.get_y
62
142
  pdf.multi_cell(w, 0, txt)
63
143
  pno = pdf.get_page
64
- assert_equal pno, 1
144
+ assert_equal 1, pno
65
145
  y2 = pdf.get_y
66
146
  h1 = y2 - y1
67
147
 
@@ -69,13 +149,13 @@ class RbpdfTest < Test::Unit::TestCase
69
149
  assert_in_delta h1, h2, 0.01
70
150
 
71
151
  line = pdf.get_num_lines(txt, w)
72
- assert_equal line, 1
152
+ assert_equal 1, line
73
153
 
74
154
  w = 20
75
155
  y1 = pdf.get_y
76
156
  pdf.multi_cell(w, 0, txt)
77
157
  pno = pdf.get_page
78
- assert_equal pno, 1
158
+ assert_equal 1, pno
79
159
  y2 = pdf.get_y
80
160
  h1 = y2 - y1
81
161
 
@@ -83,7 +163,7 @@ class RbpdfTest < Test::Unit::TestCase
83
163
  assert_in_delta h1, h2, 0.01
84
164
 
85
165
  line = pdf.get_num_lines(txt, w)
86
- assert_equal line, 1
166
+ assert_equal 1, line
87
167
  end
88
168
 
89
169
  test "getStringHeight Line Break test" do
@@ -96,7 +176,7 @@ class RbpdfTest < Test::Unit::TestCase
96
176
  y1 = pdf.get_y
97
177
  pdf.multi_cell(w, 0, txt)
98
178
  pno = pdf.get_page
99
- assert_equal pno, 1
179
+ assert_equal 1, pno
100
180
  y2 = pdf.get_y
101
181
  h1 = y2 - y1
102
182
 
@@ -104,14 +184,14 @@ class RbpdfTest < Test::Unit::TestCase
104
184
  assert_in_delta h1, h2, 0.01
105
185
 
106
186
  line = pdf.get_num_lines(txt, w)
107
- assert_equal line, 3
187
+ assert_equal 3, line
108
188
 
109
189
 
110
190
  w = 5
111
191
  y1 = pdf.get_y
112
192
  pdf.multi_cell(w, 0, txt)
113
193
  pno = pdf.get_page
114
- assert_equal pno, 1
194
+ assert_equal 1, pno
115
195
  y2 = pdf.get_y
116
196
  h1 = y2 - y1
117
197
 
@@ -119,7 +199,7 @@ class RbpdfTest < Test::Unit::TestCase
119
199
  assert_in_delta h1, h2, 0.01
120
200
 
121
201
  line = pdf.get_num_lines(txt, w)
122
- assert_equal line, 7
202
+ assert_equal 7, line
123
203
  end
124
204
 
125
205
  test "getStringHeight Multi Line test" do
@@ -132,7 +212,7 @@ class RbpdfTest < Test::Unit::TestCase
132
212
  y1 = pdf.get_y
133
213
  pdf.multi_cell(w, 0, txt)
134
214
  pno = pdf.get_page
135
- assert_equal pno, 1
215
+ assert_equal 1, pno
136
216
  y2 = pdf.get_y
137
217
  h1 = y2 - y1
138
218
 
@@ -140,7 +220,7 @@ class RbpdfTest < Test::Unit::TestCase
140
220
  assert_in_delta h1, h2, 0.01
141
221
 
142
222
  line = pdf.get_num_lines(txt, w)
143
- assert_equal line, 3
223
+ assert_equal 3, line
144
224
  end
145
225
 
146
226
  test "getStringHeight Minimum Width test 1" do
@@ -154,7 +234,7 @@ class RbpdfTest < Test::Unit::TestCase
154
234
  y1 = pdf.get_y
155
235
  pdf.multi_cell(w, 0, txt)
156
236
  pno = pdf.get_page
157
- assert_equal pno, 1
237
+ assert_equal 1, pno
158
238
  y2 = pdf.get_y
159
239
  h1 = y2 - y1
160
240
 
@@ -162,7 +242,7 @@ class RbpdfTest < Test::Unit::TestCase
162
242
  assert_in_delta h1, h2, 0.01
163
243
 
164
244
  line = pdf.get_num_lines(txt, w)
165
- assert_equal line, 16
245
+ assert_equal 16, line
166
246
  end
167
247
 
168
248
  test "getStringHeight Minimum Width test 2" do
@@ -178,7 +258,7 @@ class RbpdfTest < Test::Unit::TestCase
178
258
  y1 = pdf.get_y
179
259
  pdf.multi_cell(w, 0, txt)
180
260
  pno = pdf.get_page
181
- assert_equal pno, 1
261
+ assert_equal 1, pno
182
262
  y2 = pdf.get_y
183
263
  h1 = y2 - y1
184
264
 
@@ -186,7 +266,7 @@ class RbpdfTest < Test::Unit::TestCase
186
266
  assert_in_delta h1, h2, 0.01
187
267
 
188
268
  line = pdf.get_num_lines(txt, w)
189
- assert_equal line, 2
269
+ assert_equal 2, line
190
270
  end
191
271
 
192
272
  test "getStringHeight Minimum Bidi test 1" do
@@ -199,21 +279,21 @@ class RbpdfTest < Test::Unit::TestCase
199
279
  y1 = pdf.get_y
200
280
  pdf.multi_cell(w, 0, txt)
201
281
  pno = pdf.get_page
202
- assert_equal pno, 1
282
+ assert_equal 1, pno
203
283
  y2 = pdf.get_y
204
284
  h1 = y2 - y1
205
285
  h2 = pdf.getStringHeight(w, txt)
206
286
  assert_in_delta h1, h2, 0.01
207
287
 
208
288
  line = pdf.get_num_lines(txt, w)
209
- assert_equal line, 5
289
+ assert_equal 5, line
210
290
 
211
291
  txt = "? \xd7\x93\xd7\x92 \xd7\xa1\xd7\xa7\xd7\xa8\xd7\x9f \xd7\xa9\xd7\x98 \xd7\x91\xd7\x99\xd7\x9d \xd7\x9e\xd7\x90\xd7\x95\xd7\x9b\xd7\x96\xd7\x91 \xd7\x95\xd7\x9c\xd7\xa4\xd7\xaa\xd7\xa2 \xd7\x9e\xd7\xa6\xd7\x90 \xd7\x9c\xd7\x95 \xd7\x97\xd7\x91\xd7\xa8\xd7\x94 \xd7\x90\xd7\x99\xd7\x9a \xd7\x94\xd7\xa7\xd7\x9c\xd7\x99\xd7\x98\xd7\x94"
212
292
 
213
293
  y1 = pdf.get_y
214
294
  pdf.multi_cell(w, 0, txt)
215
295
  pno = pdf.get_page
216
- assert_equal pno, 1
296
+ assert_equal 1, pno
217
297
  y2 = pdf.get_y
218
298
  h1 = y2 - y1
219
299
 
@@ -221,7 +301,7 @@ class RbpdfTest < Test::Unit::TestCase
221
301
  assert_in_delta h1, h2, 0.01
222
302
 
223
303
  line = pdf.get_num_lines(txt, w)
224
- assert_equal line, 41
304
+ assert_equal 41, line
225
305
  end
226
306
 
227
307
  test "getStringHeight Minimum Bidi test 2" do
@@ -239,7 +319,7 @@ class RbpdfTest < Test::Unit::TestCase
239
319
  y1 = pdf.get_y
240
320
  pdf.multi_cell(w, 0, txt)
241
321
  pno = pdf.get_page
242
- assert_equal pno, 1
322
+ assert_equal 1, pno
243
323
  y2 = pdf.get_y
244
324
  h1 = y2 - y1
245
325
 
@@ -247,7 +327,7 @@ class RbpdfTest < Test::Unit::TestCase
247
327
  assert_in_delta h1, h2, 0.01
248
328
 
249
329
  line = pdf.get_num_lines(txt, w)
250
- assert_equal line, 3
330
+ assert_equal 3, line
251
331
  end
252
332
 
253
333
  test "removeSHY encoding test" do
@@ -257,10 +337,10 @@ class RbpdfTest < Test::Unit::TestCase
257
337
 
258
338
  str = 'test'.force_encoding('UTF-8')
259
339
  txt = pdf.removeSHY(str)
260
- assert_equal str.encoding.to_s, 'UTF-8'
340
+ assert_equal 'UTF-8', str.encoding.to_s
261
341
 
262
342
  str = 'test'.force_encoding('ASCII-8BIT')
263
343
  txt = pdf.removeSHY(str)
264
- assert_equal str.encoding.to_s, 'ASCII-8BIT'
344
+ assert_equal 'ASCII-8BIT', str.encoding.to_s
265
345
  end
266
346
  end
@@ -1,4 +1,9 @@
1
1
  # coding: ASCII-8BIT
2
+ #
3
+ # Copyright (c) 2011-2017 NAITOH Jun
4
+ # Released under the MIT license
5
+ # http://www.opensource.org/licenses/MIT
6
+
2
7
  require 'test_helper'
3
8
 
4
9
  class RbpdfPageTest < Test::Unit::TestCase
@@ -14,8 +19,6 @@ class RbpdfPageTest < Test::Unit::TestCase
14
19
  page = pdf.get_page
15
20
  assert_equal 0, page
16
21
 
17
- width = pdf.get_page_width
18
-
19
22
  pdf.set_print_header(false)
20
23
  pdf.add_page
21
24
  page = pdf.get_page
@@ -25,11 +28,11 @@ class RbpdfPageTest < Test::Unit::TestCase
25
28
  contents = pdf.getPageBuffer(page)
26
29
  contents.each_line {|line| content.push line.chomp }
27
30
 
28
- assert_equal content.length, 4
29
- assert_equal content[0], "0.57 w 0 J 0 j [] 0 d 0 G 0 g"
30
- assert_equal content[1], "BT /F1 12.00 Tf ET "
31
- assert_equal content[2], "0.57 w 0 J 0 j [] 0 d 0 G 0 g"
32
- assert_equal content[3], "BT /F1 12.00 Tf ET "
31
+ assert_equal 4, content.length
32
+ assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[0]
33
+ assert_equal "BT /F1 12.00 Tf ET ", content[1]
34
+ assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[2]
35
+ assert_equal "BT /F1 12.00 Tf ET ", content[3]
33
36
 
34
37
  ##################################
35
38
  # 0.57 w 0 J 0 j [] 0 d 0 G 0 g # add_page,start_page,setGraphicVars(set_fill_color)
@@ -54,8 +57,8 @@ class RbpdfPageTest < Test::Unit::TestCase
54
57
  contents = pdf.getPageBuffer(page)
55
58
  contents.each_line {|line| content.push line.chomp }
56
59
 
57
- assert_equal content.length, 5
58
- assert_equal content[4], "BT /F2 18.00 Tf ET "
60
+ assert_equal 5, content.length
61
+ assert_equal "BT /F2 18.00 Tf ET ", content[4]
59
62
 
60
63
  ########################
61
64
  # BT # Begin Text.
@@ -67,18 +70,18 @@ class RbpdfPageTest < Test::Unit::TestCase
67
70
  contents = pdf.getPageBuffer(page)
68
71
  contents.each_line {|line| content.push line.chomp }
69
72
 
70
- assert_equal content.length, 6
71
- assert_equal content[5], "BT /F3 20.00 Tf ET "
73
+ assert_equal 6, content.length
74
+ assert_equal "BT /F3 20.00 Tf ET ", content[5]
72
75
 
73
76
  pdf.cell(0, 10, 'Chapter', 0, 1, 'L')
74
77
  content = []
75
78
  contents = pdf.getPageBuffer(page)
76
79
  contents.each_line {|line| content.push line.chomp }
77
80
 
78
- assert_equal content.length, 8
79
- assert_equal content[6], "0.57 w 0 J 0 j [] 0 d 0 G 0 g"
81
+ assert_equal 8, content.length
82
+ assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[6]
80
83
 
81
- assert_equal content[7], "BT 31.19 792.37 Td 0 Tr 0.00 w [(\x00C\x00h\x00a\x00p\x00t\x00e\x00r)] TJ ET"
84
+ assert_match(/BT 31.1[89] 792.37 Td 0 Tr 0.00 w \[\(\x00C\x00h\x00a\x00p\x00t\x00e\x00r\)\] TJ ET/, content[7])
82
85
 
83
86
  #################################################
84
87
  # 0.57 w 0 J 0 j [] 0 d 0 G 0 g # getCellCode
@@ -100,19 +103,19 @@ class RbpdfPageTest < Test::Unit::TestCase
100
103
  contents = pdf.getPageBuffer(1)
101
104
  contents.each_line {|line| content.push line.chomp }
102
105
 
103
- assert_equal content.length, 15
104
- assert_equal content[4], "425.20 274.96 m" # start point : x0, y0
105
-
106
- assert_equal content[5], '425.20 308.27 413.45 340.54 392.04 366.06 c' # 1/9 circle : x1, y1(control point 1), x2, y2(control point 2), x3, y3(end point and next start point)
107
- assert_equal content[6], '370.62 391.58 340.88 408.76 308.08 414.54 c' # 2/9 circle
108
- assert_equal content[7], '275.27 420.32 241.45 414.36 212.60 397.70 c' # 3/9 circle
109
- assert_equal content[8], '183.75 381.05 161.67 354.74 150.28 323.44 c' # 4/9 circle
110
- assert_equal content[9], '138.89 292.13 138.89 257.79 150.28 226.49 c' # 5/9 circle
111
- assert_equal content[10], '161.67 195.18 183.75 168.87 212.60 152.22 c' # 6/9 circle
112
- assert_equal content[11], '241.45 135.56 275.27 129.60 308.08 135.38 c' # 7/9 circle
113
- assert_equal content[12], '340.88 141.17 370.62 158.34 392.04 183.86 c' # 8/9 circle
114
- assert_equal content[13], '413.45 209.38 425.20 241.65 425.20 274.96 c' # 9/9 circle
115
- assert_equal content[14], 'S'
106
+ assert_equal 15, content.length
107
+ assert_equal "425.20 274.96 m" , content[4] # start point : x0, y0
108
+
109
+ assert_equal '425.20 308.27 413.45 340.54 392.04 366.06 c', content[5] # 1/9 circle : x1, y1(control point 1), x2, y2(control point 2), x3, y3(end point and next start point)
110
+ assert_equal '370.62 391.58 340.88 408.76 308.08 414.54 c', content[6] # 2/9 circle
111
+ assert_equal '275.27 420.32 241.45 414.36 212.60 397.70 c', content[7] # 3/9 circle
112
+ assert_equal '183.75 381.05 161.67 354.74 150.28 323.44 c', content[8] # 4/9 circle
113
+ assert_equal '138.89 292.13 138.89 257.79 150.28 226.49 c', content[9] # 5/9 circle
114
+ assert_equal '161.67 195.18 183.75 168.87 212.60 152.22 c', content[10] # 6/9 circle
115
+ assert_equal '241.45 135.56 275.27 129.60 308.08 135.38 c', content[11] # 7/9 circle
116
+ assert_equal '340.88 141.17 370.62 158.34 392.04 183.86 c', content[12] # 8/9 circle
117
+ assert_equal '413.45 209.38 425.20 241.65 425.20 274.96 c', content[13] # 9/9 circle
118
+ assert_equal 'S' , content[14]
116
119
  end
117
120
 
118
121
  test "write content test" do
@@ -122,11 +125,11 @@ class RbpdfPageTest < Test::Unit::TestCase
122
125
  assert_equal 1, page
123
126
 
124
127
  content = []
125
- line = pdf.write(0, "abc def")
128
+ pdf.write(0, "abc def")
126
129
  contents = pdf.getPageBuffer(page)
127
130
  contents.each_line {|line| content.push line.chomp }
128
- assert_equal content.length, 22
129
- assert_equal content[21], "BT 31.19 801.84 Td 0 Tr 0.00 w [(abc def)] TJ ET"
131
+ assert_equal 22, content.length
132
+ assert_match(/BT 31.1[89] 801.84 Td 0 Tr 0.00 w \[\(abc def\)\] TJ ET/, content[21])
130
133
  end
131
134
 
132
135
  test "write content RTL test" do
@@ -137,11 +140,25 @@ class RbpdfPageTest < Test::Unit::TestCase
137
140
  assert_equal 1, page
138
141
 
139
142
  content = []
140
- line = pdf.write(0, "abc def")
143
+ pdf.write(0, "abc def")
144
+ contents = pdf.getPageBuffer(page)
145
+ contents.each_line {|line| content.push line.chomp }
146
+ assert_equal 22, content.length
147
+ assert_match(/BT 524.7[34] 801.84 Td 0 Tr 0.00 w \[\(abc def\)\] TJ ET/, content[21])
148
+ end
149
+
150
+ test "write content back slash test" do
151
+ pdf = MYPDF.new
152
+ pdf.add_page()
153
+ page = pdf.get_page
154
+ assert_equal 1, page
155
+
156
+ content = []
157
+ pdf.write(0, "abc \\def") # use escape() method in getCellCode()
141
158
  contents = pdf.getPageBuffer(page)
142
159
  contents.each_line {|line| content.push line.chomp }
143
- assert_equal content.length, 22
144
- assert_equal content[21], "BT 524.73 801.84 Td 0 Tr 0.00 w [(abc def)] TJ ET"
160
+ assert_equal 22, content.length
161
+ assert_match(/BT 31.1[89] 801.84 Td 0 Tr 0.00 w \[\(abc \\\\def\)\] TJ ET/, content[21])
145
162
  end
146
163
 
147
164
  test "write Persian Sunday content test" do
@@ -153,20 +170,20 @@ class RbpdfPageTest < Test::Unit::TestCase
153
170
 
154
171
  utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
155
172
  content = []
156
- line = pdf.write(0, utf8_persian_str_sunday)
173
+ pdf.write(0, utf8_persian_str_sunday)
157
174
  contents = pdf.getPageBuffer(page)
158
175
 
159
176
  contents.each_line {|line| content.push line.chomp }
160
- assert_equal content.length, 22
161
- assert_equal content[21], "BT 31.19 796.06 Td 0 Tr 0.00 w [(\xFE\xEA\xFE\x92\xFE\xE8\xFE\xB7 \f\xFB\x8F\xFB\xFE)] TJ ET"
177
+ assert_equal 22, content.length
178
+ assert_match(/BT 31.1[89] 796.06 Td 0 Tr 0.00 w \[\(\xFE\xEA\xFE\x92\xFE\xE8\xFE\xB7 \f\xFB\x8F\xFB\xFE\)\] TJ ET/, content[21])
162
179
 
163
180
  pdf.set_rtl(true)
164
- line = pdf.write(0, utf8_persian_str_sunday)
181
+ pdf.write(0, utf8_persian_str_sunday)
165
182
  contents = pdf.getPageBuffer(page)
166
183
 
167
184
  contents.each_line {|line| content.push line.chomp }
168
- assert_equal content.length, 46
169
- assert_equal content[45], "BT 507.38 796.06 Td 0 Tr 0.00 w [(\xFE\xEA\xFE\x92\xFE\xE8\xFE\xB7 \f\xFB\x8F\xFB\xFE)] TJ ET"
185
+ assert_equal 46, content.length
186
+ assert_equal "BT 507.38 796.06 Td 0 Tr 0.00 w [(\xFE\xEA\xFE\x92\xFE\xE8\xFE\xB7 \f\xFB\x8F\xFB\xFE)] TJ ET", content[45]
170
187
  end
171
188
 
172
189
  test "write English and Persian Sunday content test" do
@@ -178,19 +195,19 @@ class RbpdfPageTest < Test::Unit::TestCase
178
195
 
179
196
  utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
180
197
  content = []
181
- line = pdf.write(0, 'abc def ' + utf8_persian_str_sunday)
198
+ pdf.write(0, 'abc def ' + utf8_persian_str_sunday)
182
199
  contents = pdf.getPageBuffer(page)
183
200
 
184
201
  contents.each_line {|line| content.push line.chomp }
185
- assert_equal content.length, 22
186
- assert_equal content[21], "BT 31.19 796.06 Td 0 Tr 0.00 w [(\x00a\x00b\x00c\x00 \x00d\x00e\x00f\x00 \xFE\xEA\xFE\x92\xFE\xE8\xFE\xB7 \f\xFB\x8F\xFB\xFE)] TJ ET"
202
+ assert_equal 22, content.length
203
+ assert_match(/BT 31.1[89] 796.06 Td 0 Tr 0.00 w \[\(\x00a\x00b\x00c\x00 \x00d\x00e\x00f\x00 \xFE\xEA\xFE\x92\xFE\xE8\xFE\xB7 \f\xFB\x8F\xFB\xFE\)\] TJ ET/, content[21])
187
204
 
188
205
  pdf.set_rtl(true)
189
- line = pdf.write(0, 'abc def ' + utf8_persian_str_sunday)
206
+ pdf.write(0, 'abc def ' + utf8_persian_str_sunday)
190
207
  contents = pdf.getPageBuffer(page)
191
208
 
192
209
  contents.each_line {|line| content.push line.chomp }
193
- assert_equal content.length, 46
194
- assert_equal content[45], "BT 434.73 796.06 Td 0 Tr 0.00 w [(\xFE\xEA\xFE\x92\xFE\xE8\xFE\xB7 \f\xFB\x8F\xFB\xFE\x00 \x00a\x00b\x00c\x00 \x00d\x00e\x00f)] TJ ET"
210
+ assert_equal 46, content.length
211
+ assert_equal "BT 434.73 796.06 Td 0 Tr 0.00 w [(\xFE\xEA\xFE\x92\xFE\xE8\xFE\xB7 \f\xFB\x8F\xFB\xFE\x00 \x00a\x00b\x00c\x00 \x00d\x00e\x00f)] TJ ET", content[45]
195
212
  end
196
213
  end