rbpdf 1.20.0 → 1.20.1

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +4 -0
  3. data/lib/rbpdf/version.rb +1 -1
  4. data/rbpdf.gemspec +1 -2
  5. metadata +4 -90
  6. data/test/err_font1.rb +0 -7
  7. data/test/err_font2.rb +0 -8
  8. data/test/input.jpg +0 -0
  9. data/test/json: +0 -0
  10. data/test/logo_rbpdf_8bit .png +0 -0
  11. data/test/logo_rbpdf_8bit+ .png +0 -0
  12. data/test/logo_rbpdf_8bit.gif +0 -0
  13. data/test/logo_rbpdf_8bit.jpg +0 -0
  14. data/test/logo_rbpdf_8bit.png +0 -0
  15. data/test/logo_rbpdf_8bit_alpha.gif +0 -0
  16. data/test/logo_rbpdf_mono_gray.jpg +0 -0
  17. data/test/logo_rbpdf_mono_gray.png +0 -0
  18. data/test/logo_rbpdf_mono_rgb.jpg +0 -0
  19. data/test/logo_rbpdf_mono_rgb.png +0 -0
  20. data/test/output.png +0 -0
  21. data/test/png_test_alpha.png +0 -0
  22. data/test/png_test_msk_alpha.png +0 -0
  23. data/test/png_test_non_alpha.png +0 -0
  24. data/test/rbpdf_bidi_test.rb +0 -453
  25. data/test/rbpdf_bookmark_test.rb +0 -66
  26. data/test/rbpdf_cell_test.rb +0 -231
  27. data/test/rbpdf_content_test.rb +0 -213
  28. data/test/rbpdf_css_test.rb +0 -640
  29. data/test/rbpdf_dom_test.rb +0 -272
  30. data/test/rbpdf_examples_test.rb +0 -83
  31. data/test/rbpdf_font_func_test.rb +0 -45
  32. data/test/rbpdf_font_style_test.rb +0 -37
  33. data/test/rbpdf_font_test.rb +0 -308
  34. data/test/rbpdf_format_test.rb +0 -30
  35. data/test/rbpdf_func_test.rb +0 -139
  36. data/test/rbpdf_html_anchor_test.rb +0 -105
  37. data/test/rbpdf_html_func_test.rb +0 -170
  38. data/test/rbpdf_html_test.rb +0 -658
  39. data/test/rbpdf_htmlcell_test.rb +0 -60
  40. data/test/rbpdf_http_test.rb +0 -76
  41. data/test/rbpdf_image_rmagick_test.rb +0 -170
  42. data/test/rbpdf_image_test.rb +0 -174
  43. data/test/rbpdf_test.rb +0 -375
  44. data/test/rbpdf_transaction_test.rb +0 -203
  45. data/test/rbpdf_viewerpreferences_test.rb +0 -41
  46. data/test/rbpdf_write_test.rb +0 -229
  47. data/test/test.rb +0 -22
  48. data/test/test_helper.rb +0 -9
@@ -1,66 +0,0 @@
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 RbpdfTest < Test::Unit::TestCase
8
- test "bookmark test" do
9
- pdf = RBPDF.new
10
- pdf.add_page()
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
-
18
- book = pdf.bookmark('Chapter 1', 0, 0)
19
- assert_equal [{:l=>0, :y=>0, :t=>"Chapter 1", :p=>1}], book
20
-
21
- book = pdf.bookmark('Paragraph 1.1', 1, 0)
22
- assert_equal [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
23
- {:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1}], book
24
-
25
- pdf.add_page()
26
-
27
- book = pdf.bookmark('Paragraph 1.2', 1, 0)
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
31
-
32
- book = pdf.bookmark('Sub-Paragraph 1.2.1', 2, 10)
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
37
-
38
- pdf.add_page()
39
-
40
- book = pdf.bookmark('Paragraph 1.3', 1, 0)
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
46
-
47
- book = pdf.bookmark('Sub-Paragraph 1.1.1', 2, 0, 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
54
-
55
- pdf.add_page()
56
-
57
- book = pdf.bookmark('Paragraph 1.4', 1, 20)
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
65
- end
66
- end
@@ -1,231 +0,0 @@
1
- # Copyright (c) 2011-2018 NAITOH Jun
2
- # Released under the MIT license
3
- # http://www.opensource.org/licenses/MIT
4
-
5
- require 'test_helper'
6
-
7
- class RbpdfTest < Test::Unit::TestCase
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
14
- end
15
-
16
- test "getCellCode text test" do
17
- pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
18
- pdf.add_page()
19
- content = []
20
- contents = pdf.send(:getCellCode, 10, 10, 'abc')
21
- #pdf.send(:getCellCode, 10, 10, 'abc')
22
- #contents = pdf.output()
23
-
24
- contents.each_line {|line| content.push line.chomp }
25
-
26
- assert_equal 2, content.length
27
- assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[0]
28
- assert_match(/BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(abc\)\] TJ ET/, content[1])
29
- # BT
30
- # 31.19 795.17 Td
31
- # 0 Tr 0.00 w
32
- # [(abc)] TJ
33
- # ET
34
- end
35
-
36
- test "getCellCode back slash text test" do
37
- pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
38
- pdf.add_page()
39
- content = []
40
- contents = pdf.send(:getCellCode, 10, 10, "a\\bc") # use escape() method
41
- contents.each_line {|line| content.push line.chomp }
42
-
43
- assert_equal 2, content.length
44
- assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[0]
45
- assert_match(/BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(a\\\\bc\)\] TJ ET/, content[1])
46
- # BT
47
- # 31.19 795.17 Td
48
- # 0 Tr 0.00 w
49
- # [(a\\bc)] TJ
50
- # ET
51
- end
52
-
53
- test "getCellCode text align test" do
54
- pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
55
- pdf.add_page()
56
- content = []
57
- contents = pdf.send(:getCellCode, 10, 10, 'abc', 'LTRB')
58
- contents.each_line {|line| content.push line.chomp }
59
-
60
- assert_equal 2, content.length
61
- assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[0]
62
- 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])
63
- # 28.35 813.82 m 28.35 784.91 l S
64
- # 28.07 813.54 m 56.98 813.54 l S
65
- # 56.70 813.82 m 56.70 784.91 l S
66
- # 28.07 785.19 m 56.98 785.19 l S
67
- # BT
68
- # 31.19 795.17 Td
69
- # 0 Tr 0.00 w
70
- # [(abc)] TJ
71
- # ET
72
- end
73
-
74
- test "getCellCode link url test" do
75
- pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
76
- pdf.add_page()
77
-
78
- # Check Initialize Values
79
- page_annots = pdf.instance_variable_get('@page_annots')
80
- assert_equal 0, page_annots.length
81
- annots = pdf.send(:getannotsrefs, 1)
82
- assert_equal '', annots
83
-
84
- content = []
85
- contents = pdf.send(:getCellCode, 10, 10, 'abc', '', 0, '', 0, 'http://example.com')
86
- contents.each_line {|line| content.push line.chomp }
87
-
88
- assert_equal 2, content.length
89
- assert_match(/BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(abc\)\] TJ ET/, content[1])
90
- # BT
91
- # 31.19 795.17 Td
92
- # 0 Tr 0.00 w
93
- # [(abc)] TJ
94
- # ET
95
-
96
- # Check Annots
97
- page_annots = pdf.instance_variable_get('@page_annots')
98
- assert_equal 2, page_annots.length
99
- assert_equal nil, page_annots[0]
100
- assert_equal 1, page_annots[1].length
101
- assert_equal 0, page_annots[1][0]['numspaces']
102
- assert_equal({"Subtype"=>"Link"}, page_annots[1][0]['opt'])
103
- assert_equal 'http://example.com', page_annots[1][0]['txt']
104
-
105
- annots = pdf.send(:getannotsrefs, 1)
106
- assert_equal " /Annots [ 200001 0 R ]", annots
107
- end
108
-
109
- test "getCellCode link page test" do
110
- pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
111
- pdf.add_page()
112
- content = []
113
- contents = pdf.send(:getCellCode, 10, 10, 'abc', 0, 0, '', 0, 1)
114
- contents.each_line {|line| content.push line.chomp }
115
-
116
- assert_equal 2, content.length
117
- assert_match(/BT 31.1[89] 795.17 Td 0 Tr 0.00 w \[\(abc\)\] TJ ET/, content[1])
118
- # BT
119
- # 31.19 795.17 Td
120
- # 0 Tr 0.00 w
121
- # [(abc)] TJ
122
- # ET
123
-
124
- # Check Annots
125
- page_annots = pdf.instance_variable_get('@page_annots')
126
- assert_equal 2, page_annots.length
127
- assert_equal nil, page_annots[0]
128
- assert_equal 1, page_annots[1].length
129
- assert_equal 0, page_annots[1][0]['numspaces']
130
- assert_equal({"Subtype"=>"Link"}, page_annots[1][0]['opt'])
131
- assert_equal 1, page_annots[1][0]['txt']
132
-
133
- annots = pdf.send(:getannotsrefs, 1)
134
- assert_equal " /Annots [ 200001 0 R ]", annots
135
- end
136
-
137
- test "Cell link with Close and output PDF document test" do
138
- pdf = RBPDF.new
139
-
140
- # add a page
141
- pdf.add_page()
142
-
143
- text="DUMMY"
144
- pdf.cell(0, 0, text, 1, 1, 'L', 1, 0)
145
-
146
- # Close and output PDF document
147
- content = []
148
- contents = pdf.output()
149
- contents.each_line {|line| content.push line.chomp }
150
- assert_match(/3 0 obj/, content[1])
151
- end
152
-
153
- texts = {
154
- 'Basic' => {:params => [{:txt => "abcdefg", :w => 50, :pno => 1, :line => 1},
155
- {:txt => "abcdefg", :w => 20, :pno => 1, :line => 1}]},
156
- 'Line Break' => {:params => [{:txt => "abcdefg", :w => 10, :pno => 1, :line => 3},
157
- {:txt => "abcdefg", :w => 5, :pno => 1, :line => 7}]},
158
- 'Multi Line' => {:params => [{:txt => "abc\ndif\nhij", :w => 100, :pno => 1, :line => 3}]},
159
- 'Minimum Width' => {:params => [{:txt => "Export to PDF: align is Good.", :w => 'OO', :pno => 1, :line => 16}]},
160
- 'Minimum Width with font' => {:font => "kozminproregular", :orientation => 'L',
161
- :params => [{:txt => "20", :w => '20', :pno => 1, :line => 2}]},
162
- 'Minimum Bidi' => {:params => [{:txt => "\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa", :w => 'OO', :pno => 1, :line => 5},
163
- {: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", :w => 'OO', :pno => 1, :line => 41}]},
164
- 'Minimum Bidi with font' => {:font => "freesans", :rtl => true,
165
- :params => [{:txt => "\xd7\x9c 000", :w => 'OO', :pno => 1, :line => 3}]},
166
- }
167
-
168
- data(texts)
169
- test "getStringHeight test" do |data|
170
- orientation = data[:orientation] ? data[:orientation] : 'P'
171
- pdf = RBPDF.new(orientation, 'mm', 'A4', true, "UTF-8", true)
172
- pdf.set_font(data[:font], '', 8) if data[:font]
173
-
174
- if data[:rtl]
175
- pdf.set_rtl(true)
176
- pdf.set_temp_rtl('R')
177
- end
178
-
179
- pdf.add_page
180
-
181
- data[:params].each_with_index {|param, i|
182
- txt = param[:txt]
183
- if param[:w].is_a? String
184
- if data[:font]
185
- margins = pdf.get_margins
186
- w = pdf.get_string_width(param[:w]) + margins['cell'] * 2
187
- else
188
- w = pdf.get_string_width(param[:w])
189
- end
190
- else
191
- w = param[:w]
192
- end
193
-
194
- lasth_0 = pdf.get_last_h
195
- y1 = pdf.get_y
196
- pdf.multi_cell(w, 0, txt)
197
- lasth_1 = pdf.get_last_h
198
- pno = pdf.get_page
199
- assert_equal param[:pno], pno
200
-
201
- if i == 0
202
- assert_not_equal 0, lasth_1
203
- else
204
- assert_equal lasth_0, lasth_1
205
- end
206
-
207
- y2 = pdf.get_y
208
- h1 = y2 - y1
209
-
210
- h2 = pdf.getStringHeight(w, txt)
211
- assert_in_delta h1, h2, 0.01
212
-
213
- line = pdf.get_num_lines(txt, w)
214
- assert_equal param[:line], line
215
- }
216
- end
217
-
218
- test "removeSHY encoding test" do
219
- return unless 'test'.respond_to?(:force_encoding)
220
-
221
- pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
222
-
223
- str = 'test'.force_encoding('UTF-8')
224
- pdf.removeSHY(str)
225
- assert_equal 'UTF-8', str.encoding.to_s
226
-
227
- str = 'test'.force_encoding('ASCII-8BIT')
228
- pdf.removeSHY(str)
229
- assert_equal 'ASCII-8BIT', str.encoding.to_s
230
- end
231
- end
@@ -1,213 +0,0 @@
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
-
7
- require 'test_helper'
8
-
9
- class RbpdfPageTest < Test::Unit::TestCase
10
- class MYPDF < RBPDF
11
- def getPageBuffer(page)
12
- super
13
- end
14
- end
15
-
16
- test "Basic Page content test" do
17
- pdf = MYPDF.new
18
-
19
- page = pdf.get_page
20
- assert_equal 0, page
21
-
22
- pdf.set_print_header(false)
23
- pdf.add_page
24
- page = pdf.get_page
25
- assert_equal 1, page
26
-
27
- content = []
28
- contents = pdf.getPageBuffer(page)
29
- contents.each_line {|line| content.push line.chomp }
30
-
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]
36
-
37
- ##################################
38
- # 0.57 w 0 J 0 j [] 0 d 0 G 0 g # add_page,start_page,setGraphicVars(set_fill_color)
39
- # BT /F1 12.00 Tf ET #
40
- # 0.57 w 0 J 0 j [] 0 d 0 G 0 g #
41
- # BT /F1 12.00 Tf ET #
42
- ##################################
43
- # 0.57 w # @linestyle_width : Line width.
44
- # 0 J # @linestyle_cap : Type of cap to put on the line. [butt:0, round:1, square:2]
45
- # 0 j # @linestyle_join : Type of join. [miter:0, round:1, bevel:2]
46
- # [] 0 d # @linestyle_dash : Line dash pattern. (see set_line_style)
47
- # 0 G # @draw_color : Drawing color. (see set_draw_color)
48
- # 0 g # Set colors
49
- ########################
50
- # BT # Begin Text.
51
- # /F1 12.00 Tf # 12.00 point size font.
52
- # ET # End Text.
53
- ########################
54
-
55
- pdf.set_font('freesans', 'BI', 18)
56
- content = []
57
- contents = pdf.getPageBuffer(page)
58
- contents.each_line {|line| content.push line.chomp }
59
-
60
- assert_equal 5, content.length
61
- assert_equal "BT /F2 18.00 Tf ET ", content[4]
62
-
63
- ########################
64
- # BT # Begin Text.
65
- # /F2 18.00 Tf # 18.00 point size font.
66
- # ET # End Text.
67
- ########################
68
- pdf.set_font('freesans', 'B', 20)
69
- content = []
70
- contents = pdf.getPageBuffer(page)
71
- contents.each_line {|line| content.push line.chomp }
72
-
73
- assert_equal 6, content.length
74
- assert_equal "BT /F3 20.00 Tf ET ", content[5]
75
-
76
- pdf.cell(0, 10, 'Chapter', 0, 1, 'L')
77
- content = []
78
- contents = pdf.getPageBuffer(page)
79
- contents.each_line {|line| content.push line.chomp }
80
-
81
- assert_equal 8, content.length
82
- assert_equal "0.57 w 0 J 0 j [] 0 d 0 G 0 g", content[6]
83
-
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])
85
-
86
- #################################################
87
- # 0.57 w 0 J 0 j [] 0 d 0 G 0 g # getCellCode
88
- # BT
89
- # 31.19 792.37 Td # Set text offset.
90
- # 0 Tr 0.00 w # Set stroke outline and clipping mode
91
- # [(\x00C\x00h\x00a\x00p\x00t\x00e\x00r)] TJ # Write array of characters.
92
- # ET
93
- #################################################
94
- end
95
-
96
- test "circle content" do
97
- pdf = MYPDF.new
98
-
99
- pdf.set_print_header(false)
100
- pdf.add_page
101
- pdf.circle(100, 200, 50)
102
- content = []
103
- contents = pdf.getPageBuffer(1)
104
- contents.each_line {|line| content.push line.chomp }
105
-
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_match(/138.8[89] 292.13 138.8[89] 257.79 150.28 226.4[89] 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]
119
- end
120
-
121
- test "write content test" do
122
- pdf = MYPDF.new
123
- pdf.add_page()
124
- page = pdf.get_page
125
- assert_equal 1, page
126
-
127
- content = []
128
- pdf.write(0, "abc def")
129
- contents = pdf.getPageBuffer(page)
130
- contents.each_line {|line| content.push line.chomp }
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])
133
- end
134
-
135
- test "write content RTL test" do
136
- pdf = MYPDF.new
137
- pdf.set_rtl(true)
138
- pdf.add_page()
139
- page = pdf.get_page
140
- assert_equal 1, page
141
-
142
- content = []
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()
158
- contents = pdf.getPageBuffer(page)
159
- contents.each_line {|line| content.push line.chomp }
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])
162
- end
163
-
164
- test "write Persian Sunday content test" do
165
- pdf = MYPDF.new
166
- pdf.set_font('dejavusans', '', 18)
167
- pdf.add_page()
168
- page = pdf.get_page
169
- assert_equal 1, page
170
-
171
- utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
172
- content = []
173
- pdf.write(0, utf8_persian_str_sunday)
174
- contents = pdf.getPageBuffer(page)
175
-
176
- contents.each_line {|line| content.push line.chomp }
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])
179
-
180
- pdf.set_rtl(true)
181
- pdf.write(0, utf8_persian_str_sunday)
182
- contents = pdf.getPageBuffer(page)
183
-
184
- contents.each_line {|line| content.push line.chomp }
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]
187
- end
188
-
189
- test "write English and Persian Sunday content test" do
190
- pdf = MYPDF.new
191
- pdf.set_font('dejavusans', '', 18)
192
- pdf.add_page()
193
- page = pdf.get_page
194
- assert_equal 1, page
195
-
196
- utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
197
- content = []
198
- pdf.write(0, 'abc def ' + utf8_persian_str_sunday)
199
- contents = pdf.getPageBuffer(page)
200
-
201
- contents.each_line {|line| content.push line.chomp }
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])
204
-
205
- pdf.set_rtl(true)
206
- pdf.write(0, 'abc def ' + utf8_persian_str_sunday)
207
- contents = pdf.getPageBuffer(page)
208
-
209
- contents.each_line {|line| content.push line.chomp }
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]
212
- end
213
- end