rbpdf-fruitcake0525 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +96 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE.TXT +504 -0
  5. data/README.md +64 -0
  6. data/Rakefile +12 -0
  7. data/lib/core/rmagick.rb +93 -0
  8. data/lib/htmlcolors.rb +207 -0
  9. data/lib/rbpdf.rb +15138 -0
  10. data/lib/rbpdf/version.rb +3 -0
  11. data/lib/unicode_data.rb +18315 -0
  12. data/logo_example.png +0 -0
  13. data/rbpdf.gemspec +37 -0
  14. data/test/err_font1.rb +3 -0
  15. data/test/err_font2.rb +4 -0
  16. data/test/logo_rbpdf_8bit.gif +0 -0
  17. data/test/logo_rbpdf_8bit.jpg +0 -0
  18. data/test/logo_rbpdf_8bit.png +0 -0
  19. data/test/logo_rbpdf_8bit_alpha.gif +0 -0
  20. data/test/logo_rbpdf_mono_gray.jpg +0 -0
  21. data/test/logo_rbpdf_mono_gray.png +0 -0
  22. data/test/logo_rbpdf_mono_rgb.jpg +0 -0
  23. data/test/logo_rbpdf_mono_rgb.png +0 -0
  24. data/test/png_test_alpha.png +0 -0
  25. data/test/png_test_msk_alpha.png +0 -0
  26. data/test/png_test_non_alpha.png +0 -0
  27. data/test/rbpdf_bidi_test.rb +438 -0
  28. data/test/rbpdf_bookmark_test.rb +56 -0
  29. data/test/rbpdf_cell_test.rb +266 -0
  30. data/test/rbpdf_content_test.rb +196 -0
  31. data/test/rbpdf_css_test.rb +636 -0
  32. data/test/rbpdf_dom_test.rb +338 -0
  33. data/test/rbpdf_font_func_test.rb +41 -0
  34. data/test/rbpdf_font_style_test.rb +33 -0
  35. data/test/rbpdf_font_test.rb +291 -0
  36. data/test/rbpdf_format_test.rb +26 -0
  37. data/test/rbpdf_func_test.rb +135 -0
  38. data/test/rbpdf_html_anchor_test.rb +107 -0
  39. data/test/rbpdf_html_func_test.rb +166 -0
  40. data/test/rbpdf_html_test.rb +580 -0
  41. data/test/rbpdf_htmlcell_test.rb +64 -0
  42. data/test/rbpdf_image_rmagick_test.rb +294 -0
  43. data/test/rbpdf_image_test.rb +107 -0
  44. data/test/rbpdf_test.rb +377 -0
  45. data/test/rbpdf_transaction_test.rb +199 -0
  46. data/test/rbpdf_viewerpreferences_test.rb +37 -0
  47. data/test/rbpdf_write_test.rb +225 -0
  48. data/test/test_helper.rb +4 -0
  49. data/test_unicode.rbpdf +115 -0
  50. data/utf8test.txt +120 -0
  51. metadata +205 -0
@@ -0,0 +1,56 @@
1
+ require 'test_helper'
2
+
3
+ class RbpdfTest < Test::Unit::TestCase
4
+ test "bookmark test" do
5
+ pdf = RBPDF.new
6
+ pdf.add_page()
7
+
8
+ book = pdf.bookmark('Chapter 1', 0, 0)
9
+ assert_equal book, [{:l=>0, :y=>0, :t=>"Chapter 1", :p=>1}]
10
+
11
+ 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}]
14
+
15
+ pdf.add_page()
16
+
17
+ 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}]
21
+
22
+ 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}]
27
+
28
+ pdf.add_page()
29
+
30
+ 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}]
36
+
37
+ 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}]
44
+
45
+ pdf.add_page()
46
+
47
+ 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}]
55
+ end
56
+ end
@@ -0,0 +1,266 @@
1
+ require 'test_helper'
2
+
3
+ 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
+ end
9
+
10
+ test "getCellCode" do
11
+ pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
12
+ 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
16
+ end
17
+
18
+ test "getCellCode link url align test" do
19
+ pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
20
+ pdf.add_page()
21
+ content = []
22
+ contents = pdf.getCellCode(10, 10, 'abc', 'LTRB', 0, '', 0, 'http://example.com')
23
+ contents.each_line {|line| content.push line.chomp }
24
+
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"
27
+ # 28.35 813.82 m 28.35 784.91 l S
28
+ # 28.07 813.54 m 56.98 813.54 l S
29
+ # 56.70 813.82 m 56.70 784.91 l S
30
+ # 28.07 785.19 m 56.98 785.19 l S
31
+ # BT
32
+ # 31.19 795.17 Td
33
+ # 0 Tr 0.00 w
34
+ # [(abc)] TJ
35
+ # ET
36
+ end
37
+
38
+ test "getCellCode link page test" do
39
+ pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
40
+ pdf.add_page()
41
+ content = []
42
+ contents = pdf.getCellCode(10, 10, 'abc', 0, 0, '', 0, 1)
43
+ contents.each_line {|line| content.push line.chomp }
44
+
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"
47
+ # BT
48
+ # 31.19 795.17 Td
49
+ # 0 Tr 0.00 w
50
+ # [(abc)] TJ
51
+ # ET
52
+ end
53
+
54
+ test "getStringHeight Basic test" do
55
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
56
+ pdf.add_page
57
+
58
+ txt = 'abcdefg'
59
+
60
+ w = 50
61
+ y1 = pdf.get_y
62
+ pdf.multi_cell(w, 0, txt)
63
+ pno = pdf.get_page
64
+ assert_equal pno, 1
65
+ y2 = pdf.get_y
66
+ h1 = y2 - y1
67
+
68
+ h2 = pdf.getStringHeight(w, txt)
69
+ assert_in_delta h1, h2, 0.01
70
+
71
+ line = pdf.get_num_lines(txt, w)
72
+ assert_equal line, 1
73
+
74
+ w = 20
75
+ y1 = pdf.get_y
76
+ pdf.multi_cell(w, 0, txt)
77
+ pno = pdf.get_page
78
+ assert_equal pno, 1
79
+ y2 = pdf.get_y
80
+ h1 = y2 - y1
81
+
82
+ h2 = pdf.getStringHeight(w, txt)
83
+ assert_in_delta h1, h2, 0.01
84
+
85
+ line = pdf.get_num_lines(txt, w)
86
+ assert_equal line, 1
87
+ end
88
+
89
+ test "getStringHeight Line Break test" do
90
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
91
+ pdf.add_page
92
+
93
+ txt = 'abcdefg'
94
+
95
+ w = 10
96
+ y1 = pdf.get_y
97
+ pdf.multi_cell(w, 0, txt)
98
+ pno = pdf.get_page
99
+ assert_equal pno, 1
100
+ y2 = pdf.get_y
101
+ h1 = y2 - y1
102
+
103
+ h2 = pdf.getStringHeight(w, txt)
104
+ assert_in_delta h1, h2, 0.01
105
+
106
+ line = pdf.get_num_lines(txt, w)
107
+ assert_equal line, 3
108
+
109
+
110
+ w = 5
111
+ y1 = pdf.get_y
112
+ pdf.multi_cell(w, 0, txt)
113
+ pno = pdf.get_page
114
+ assert_equal pno, 1
115
+ y2 = pdf.get_y
116
+ h1 = y2 - y1
117
+
118
+ h2 = pdf.getStringHeight(w, txt)
119
+ assert_in_delta h1, h2, 0.01
120
+
121
+ line = pdf.get_num_lines(txt, w)
122
+ assert_equal line, 7
123
+ end
124
+
125
+ test "getStringHeight Multi Line test" do
126
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
127
+ pdf.add_page
128
+
129
+ txt = "abc\ndif\nhij"
130
+
131
+ w = 100
132
+ y1 = pdf.get_y
133
+ pdf.multi_cell(w, 0, txt)
134
+ pno = pdf.get_page
135
+ assert_equal pno, 1
136
+ y2 = pdf.get_y
137
+ h1 = y2 - y1
138
+
139
+ h2 = pdf.getStringHeight(w, txt)
140
+ assert_in_delta h1, h2, 0.01
141
+
142
+ line = pdf.get_num_lines(txt, w)
143
+ assert_equal line, 3
144
+ end
145
+
146
+ test "getStringHeight Minimum Width test 1" do
147
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
148
+ pdf.add_page
149
+
150
+ w = pdf.get_string_width('OO')
151
+
152
+ txt = "Export to PDF: align is Good."
153
+
154
+ y1 = pdf.get_y
155
+ pdf.multi_cell(w, 0, txt)
156
+ pno = pdf.get_page
157
+ assert_equal pno, 1
158
+ y2 = pdf.get_y
159
+ h1 = y2 - y1
160
+
161
+ h2 = pdf.getStringHeight(w, txt)
162
+ assert_in_delta h1, h2, 0.01
163
+
164
+ line = pdf.get_num_lines(txt, w)
165
+ assert_equal line, 16
166
+ end
167
+
168
+ test "getStringHeight Minimum Width test 2" do
169
+ pdf = RBPDF.new('L', 'mm', 'A4', true, "UTF-8", true)
170
+ pdf.set_font('kozminproregular', '', 8)
171
+ pdf.add_page
172
+
173
+ margins = pdf.get_margins
174
+ w = pdf.get_string_width('20') + margins['cell'] * 2
175
+
176
+ txt = "20"
177
+
178
+ y1 = pdf.get_y
179
+ pdf.multi_cell(w, 0, txt)
180
+ pno = pdf.get_page
181
+ assert_equal pno, 1
182
+ y2 = pdf.get_y
183
+ h1 = y2 - y1
184
+
185
+ h2 = pdf.getStringHeight(w, txt)
186
+ assert_in_delta h1, h2, 0.01
187
+
188
+ line = pdf.get_num_lines(txt, w)
189
+ assert_equal line, 2
190
+ end
191
+
192
+ test "getStringHeight Minimum Bidi test 1" do
193
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
194
+ pdf.add_page
195
+
196
+ w = pdf.get_string_width('OO')
197
+
198
+ txt = "\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa"
199
+ y1 = pdf.get_y
200
+ pdf.multi_cell(w, 0, txt)
201
+ pno = pdf.get_page
202
+ assert_equal pno, 1
203
+ y2 = pdf.get_y
204
+ h1 = y2 - y1
205
+ h2 = pdf.getStringHeight(w, txt)
206
+ assert_in_delta h1, h2, 0.01
207
+
208
+ line = pdf.get_num_lines(txt, w)
209
+ assert_equal line, 5
210
+
211
+ 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
+
213
+ y1 = pdf.get_y
214
+ pdf.multi_cell(w, 0, txt)
215
+ pno = pdf.get_page
216
+ assert_equal pno, 1
217
+ y2 = pdf.get_y
218
+ h1 = y2 - y1
219
+
220
+ h2 = pdf.getStringHeight(w, txt)
221
+ assert_in_delta h1, h2, 0.01
222
+
223
+ line = pdf.get_num_lines(txt, w)
224
+ assert_equal line, 41
225
+ end
226
+
227
+ test "getStringHeight Minimum Bidi test 2" do
228
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
229
+ pdf.set_font('freesans', '')
230
+ pdf.set_rtl(true)
231
+ pdf.set_temp_rtl('R')
232
+ pdf.add_page
233
+
234
+ margins = pdf.get_margins
235
+ w = pdf.get_string_width('OO') + margins['cell'] * 2
236
+
237
+ txt = "\xd7\x9c 000"
238
+
239
+ y1 = pdf.get_y
240
+ pdf.multi_cell(w, 0, txt)
241
+ pno = pdf.get_page
242
+ assert_equal pno, 1
243
+ y2 = pdf.get_y
244
+ h1 = y2 - y1
245
+
246
+ h2 = pdf.getStringHeight(w, txt)
247
+ assert_in_delta h1, h2, 0.01
248
+
249
+ line = pdf.get_num_lines(txt, w)
250
+ assert_equal line, 3
251
+ end
252
+
253
+ test "removeSHY encoding test" do
254
+ return unless 'test'.respond_to?(:force_encoding)
255
+
256
+ pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
257
+
258
+ str = 'test'.force_encoding('UTF-8')
259
+ txt = pdf.removeSHY(str)
260
+ assert_equal str.encoding.to_s, 'UTF-8'
261
+
262
+ str = 'test'.force_encoding('ASCII-8BIT')
263
+ txt = pdf.removeSHY(str)
264
+ assert_equal str.encoding.to_s, 'ASCII-8BIT'
265
+ end
266
+ end
@@ -0,0 +1,196 @@
1
+ # coding: ASCII-8BIT
2
+ require 'test_helper'
3
+
4
+ class RbpdfPageTest < Test::Unit::TestCase
5
+ class MYPDF < RBPDF
6
+ def getPageBuffer(page)
7
+ super
8
+ end
9
+ end
10
+
11
+ test "Basic Page content test" do
12
+ pdf = MYPDF.new
13
+
14
+ page = pdf.get_page
15
+ assert_equal 0, page
16
+
17
+ width = pdf.get_page_width
18
+
19
+ pdf.set_print_header(false)
20
+ pdf.add_page
21
+ page = pdf.get_page
22
+ assert_equal 1, page
23
+
24
+ content = []
25
+ contents = pdf.getPageBuffer(page)
26
+ contents.each_line {|line| content.push line.chomp }
27
+
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 "
33
+
34
+ ##################################
35
+ # 0.57 w 0 J 0 j [] 0 d 0 G 0 g # add_page,start_page,setGraphicVars(set_fill_color)
36
+ # BT /F1 12.00 Tf ET #
37
+ # 0.57 w 0 J 0 j [] 0 d 0 G 0 g #
38
+ # BT /F1 12.00 Tf ET #
39
+ ##################################
40
+ # 0.57 w # @linestyle_width : Line width.
41
+ # 0 J # @linestyle_cap : Type of cap to put on the line. [butt:0, round:1, square:2]
42
+ # 0 j # @linestyle_join : Type of join. [miter:0, round:1, bevel:2]
43
+ # [] 0 d # @linestyle_dash : Line dash pattern. (see set_line_style)
44
+ # 0 G # @draw_color : Drawing color. (see set_draw_color)
45
+ # 0 g # Set colors
46
+ ########################
47
+ # BT # Begin Text.
48
+ # /F1 12.00 Tf # 12.00 point size font.
49
+ # ET # End Text.
50
+ ########################
51
+
52
+ pdf.set_font('freesans', 'BI', 18)
53
+ content = []
54
+ contents = pdf.getPageBuffer(page)
55
+ contents.each_line {|line| content.push line.chomp }
56
+
57
+ assert_equal content.length, 5
58
+ assert_equal content[4], "BT /F2 18.00 Tf ET "
59
+
60
+ ########################
61
+ # BT # Begin Text.
62
+ # /F2 18.00 Tf # 18.00 point size font.
63
+ # ET # End Text.
64
+ ########################
65
+ pdf.set_font('freesans', 'B', 20)
66
+ content = []
67
+ contents = pdf.getPageBuffer(page)
68
+ contents.each_line {|line| content.push line.chomp }
69
+
70
+ assert_equal content.length, 6
71
+ assert_equal content[5], "BT /F3 20.00 Tf ET "
72
+
73
+ pdf.cell(0, 10, 'Chapter', 0, 1, 'L')
74
+ content = []
75
+ contents = pdf.getPageBuffer(page)
76
+ contents.each_line {|line| content.push line.chomp }
77
+
78
+ assert_equal content.length, 8
79
+ assert_equal content[6], "0.57 w 0 J 0 j [] 0 d 0 G 0 g"
80
+
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"
82
+
83
+ #################################################
84
+ # 0.57 w 0 J 0 j [] 0 d 0 G 0 g # getCellCode
85
+ # BT
86
+ # 31.19 792.37 Td # Set text offset.
87
+ # 0 Tr 0.00 w # Set stroke outline and clipping mode
88
+ # [(\x00C\x00h\x00a\x00p\x00t\x00e\x00r)] TJ # Write array of characters.
89
+ # ET
90
+ #################################################
91
+ end
92
+
93
+ test "circle content" do
94
+ pdf = MYPDF.new
95
+
96
+ pdf.set_print_header(false)
97
+ pdf.add_page
98
+ pdf.circle(100, 200, 50)
99
+ content = []
100
+ contents = pdf.getPageBuffer(1)
101
+ contents.each_line {|line| content.push line.chomp }
102
+
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'
116
+ end
117
+
118
+ test "write content test" do
119
+ pdf = MYPDF.new
120
+ pdf.add_page()
121
+ page = pdf.get_page
122
+ assert_equal 1, page
123
+
124
+ content = []
125
+ line = pdf.write(0, "abc def")
126
+ contents = pdf.getPageBuffer(page)
127
+ 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"
130
+ end
131
+
132
+ test "write content RTL test" do
133
+ pdf = MYPDF.new
134
+ pdf.set_rtl(true)
135
+ pdf.add_page()
136
+ page = pdf.get_page
137
+ assert_equal 1, page
138
+
139
+ content = []
140
+ line = pdf.write(0, "abc def")
141
+ contents = pdf.getPageBuffer(page)
142
+ 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"
145
+ end
146
+
147
+ test "write Persian Sunday content test" do
148
+ pdf = MYPDF.new
149
+ pdf.set_font('dejavusans', '', 18)
150
+ pdf.add_page()
151
+ page = pdf.get_page
152
+ assert_equal 1, page
153
+
154
+ utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
155
+ content = []
156
+ line = pdf.write(0, utf8_persian_str_sunday)
157
+ contents = pdf.getPageBuffer(page)
158
+
159
+ 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"
162
+
163
+ pdf.set_rtl(true)
164
+ line = pdf.write(0, utf8_persian_str_sunday)
165
+ contents = pdf.getPageBuffer(page)
166
+
167
+ 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"
170
+ end
171
+
172
+ test "write English and Persian Sunday content test" do
173
+ pdf = MYPDF.new
174
+ pdf.set_font('dejavusans', '', 18)
175
+ pdf.add_page()
176
+ page = pdf.get_page
177
+ assert_equal 1, page
178
+
179
+ utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
180
+ content = []
181
+ line = pdf.write(0, 'abc def ' + utf8_persian_str_sunday)
182
+ contents = pdf.getPageBuffer(page)
183
+
184
+ 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"
187
+
188
+ pdf.set_rtl(true)
189
+ line = pdf.write(0, 'abc def ' + utf8_persian_str_sunday)
190
+ contents = pdf.getPageBuffer(page)
191
+
192
+ 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"
195
+ end
196
+ end