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
data/logo_example.png ADDED
Binary file
data/rbpdf.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rbpdf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rbpdf-fruitcake0525"
8
+ spec.version = Rbpdf::VERSION
9
+ spec.authors = ["fruitcake0525"]
10
+ spec.email = ["fruitcake0525@gmail.com"]
11
+ spec.summary = %q{RBPDF via TCPDF.}
12
+ spec.description = %q{A template plugin allowing the inclusion of ERB-enabled RBPDF template files.}
13
+ spec.homepage = ""
14
+ spec.license = "LGPL 2.1 or later"
15
+ spec.files = Dir.glob("lib/rbpdf/version.rb") +
16
+ Dir.glob("lib/*.rb") +
17
+ Dir.glob("lib/core/rmagick.rb") +
18
+ Dir.glob("test/*") +
19
+ ["Rakefile", "rbpdf.gemspec", "Gemfile",
20
+ "CHANGELOG", "test_unicode.rbpdf", "README.md", "LICENSE.TXT",
21
+ "utf8test.txt", "logo_example.png" ]
22
+ spec.rdoc_options += [ '--exclude', 'lib/fonts/',
23
+ '--exclude', 'lib/htmlcolors.rb',
24
+ '--exclude', 'lib/unicode_data.rb' ]
25
+
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "htmlentities", "= 4.3.4"
31
+ spec.add_runtime_dependency "rbpdf-font", "~> 1.19.0"
32
+ spec.required_ruby_version = '>= 1.8.7'
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.6"
35
+ spec.add_development_dependency "rake"
36
+ spec.add_development_dependency "test-unit", "~> 3.0"
37
+ end
data/test/err_font1.rb ADDED
@@ -0,0 +1,3 @@
1
+ RBPDFFontDescriptor.define('err_font1') do |font|
2
+ font[:type]='Type0'
3
+ end
data/test/err_font2.rb ADDED
@@ -0,0 +1,4 @@
1
+ RBPDFFontDescriptor.define('err_font2') do |font|
2
+ font[:type]='Type0'
3
+ font[:cw]={}
4
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,438 @@
1
+ # coding: ASCII-8BIT
2
+ require 'test_helper'
3
+
4
+ class RbpdfTest < Test::Unit::TestCase
5
+ class MYPDF < RBPDF
6
+ def UTF8StringToArray(str)
7
+ super
8
+ end
9
+ def utf8Bidi(ta, str='', forcertl=false)
10
+ super
11
+ end
12
+ def cache_utf8_string_to_array(str)
13
+ @cache_utf8_string_to_array[str]
14
+ end
15
+ def rtl_text_dir
16
+ super
17
+ end
18
+ def get_current_font
19
+ return @current_font
20
+ end
21
+ end
22
+
23
+ test "RTL test" do
24
+ pdf = MYPDF.new
25
+
26
+ # LTR
27
+ rtl = pdf.get_rtl
28
+ assert_equal rtl, false
29
+ rtl = pdf.is_rtl_text_dir
30
+ assert_equal rtl, false
31
+ rtl = pdf.rtl_text_dir
32
+ assert_equal rtl, 'L'
33
+
34
+ pdf.set_temp_rtl('rtl')
35
+ rtl = pdf.is_rtl_text_dir
36
+ assert_equal rtl, true
37
+ rtl = pdf.rtl_text_dir
38
+ assert_equal rtl, 'R'
39
+
40
+ # RTL
41
+ pdf.set_rtl(true)
42
+ rtl = pdf.get_rtl
43
+ assert_equal rtl, true
44
+ rtl = pdf.is_rtl_text_dir
45
+ assert_equal rtl, true
46
+ rtl = pdf.rtl_text_dir
47
+ assert_equal rtl, 'R'
48
+
49
+ pdf.set_temp_rtl('ltr')
50
+ rtl = pdf.is_rtl_text_dir
51
+ assert_equal rtl, false
52
+ rtl = pdf.rtl_text_dir
53
+ assert_equal rtl, 'L'
54
+ end
55
+
56
+ test "Bidi subset font test" do
57
+ pdf = MYPDF.new
58
+ ary_ucs4 = pdf.UTF8StringToArray("abc")
59
+ assert_equal [0x61, 0x62, 0x63], ary_ucs4
60
+ current_font = pdf.get_current_font
61
+ assert_equal 256, current_font['subsetchars'].length
62
+
63
+ ary_ucs4 = pdf.UTF8StringToArray("\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa")
64
+ assert_equal [0x5e2, 0x5d1, 0x5e8, 0x5d9, 0x5ea], ary_ucs4
65
+ current_font = pdf.get_current_font
66
+ assert_equal 261, current_font['subsetchars'].compact.length
67
+ end
68
+
69
+ test "Bidi" do
70
+ pdf = MYPDF.new
71
+
72
+ # UCS4 charactor -> UTF-8 charactor
73
+ utf8_chr = pdf.unichr(0x61)
74
+ assert_equal "a", utf8_chr
75
+ utf8_chr = pdf.unichr(0x5e2)
76
+ assert_equal "\xd7\xa2", utf8_chr
77
+
78
+ # UTF-8 string -> array of UCS4 charactor
79
+ ary_ucs4 = pdf.UTF8StringToArray("abc")
80
+ assert_equal [0x61, 0x62, 0x63], ary_ucs4
81
+ current_font = pdf.get_current_font
82
+ assert_equal 256, current_font['subsetchars'].compact.length
83
+
84
+ ary_ucs4 = pdf.UTF8StringToArray("\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa")
85
+ assert_equal [0x5e2, 0x5d1, 0x5e8, 0x5d9, 0x5ea], ary_ucs4
86
+ current_font = pdf.get_current_font
87
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
88
+
89
+ # Bidirectional Algorithm
90
+ ascii_str = "abc"
91
+ utf8_str_1 = "\xd7\xa2"
92
+ utf8_str_2 = "\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa"
93
+
94
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
95
+ assert_equal [0x61, 0x62, 0x63], ary_ucs4
96
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), ascii_str, 'R')
97
+ assert_equal [0x61, 0x62, 0x63], ary_ucs4
98
+
99
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_1))
100
+ assert_equal [0x5e2], ary_ucs4
101
+ current_font = pdf.get_current_font
102
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
103
+
104
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_1), utf8_str_1, 'R')
105
+ assert_equal [0x5e2], ary_ucs4
106
+ current_font = pdf.get_current_font
107
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
108
+
109
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2))
110
+ assert_equal [0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_ucs4
111
+ current_font = pdf.get_current_font
112
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
113
+
114
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2), utf8_str_2, 'R')
115
+ assert_equal [0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_ucs4 ##
116
+ current_font = pdf.get_current_font
117
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
118
+
119
+ ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str + utf8_str_2), ascii_str + utf8_str_2, 'L')
120
+ assert_equal [0x61, 0x62, 0x63, 0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_str
121
+ current_font = pdf.get_current_font
122
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
123
+
124
+ ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str + utf8_str_2)) # LTR
125
+ assert_equal [0x61, 0x62, 0x63, 0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_str
126
+ current_font = pdf.get_current_font
127
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
128
+
129
+ ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str + utf8_str_2), ascii_str + utf8_str_2, 'R')
130
+ assert_equal [0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2, 0x61, 0x62, 0x63], ary_str
131
+ current_font = pdf.get_current_font
132
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
133
+
134
+ ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2 + ascii_str), utf8_str_2 + ascii_str, 'L')
135
+ assert_equal [0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2, 0x61, 0x62, 0x63], ary_str
136
+ ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2 + ascii_str)) # RTL
137
+ assert_equal [0x61, 0x62, 0x63, 0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_str
138
+ ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2 + ascii_str), utf8_str_2 + ascii_str, 'R')
139
+ assert_equal [0x61, 0x62, 0x63, 0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_str
140
+ end
141
+
142
+ test "Bidi ascii space test" do
143
+ pdf = MYPDF.new
144
+
145
+ ascii_str = "abc def"
146
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
147
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x20, 0x64, 0x65, 0x66]
148
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
149
+ assert_equal ary_ucs4_2, ary_ucs4_1
150
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
151
+ assert_equal ary_ucs4_2, ary_ucs4_1
152
+
153
+ ascii_str = "abc def"
154
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
155
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x20, 0x20, 0x64, 0x65, 0x66]
156
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
157
+ assert_equal ary_ucs4_2, ary_ucs4_1
158
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
159
+ assert_equal ary_ucs4_2, ary_ucs4_1
160
+
161
+ ascii_str = "abc "
162
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
163
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x20, 0x20]
164
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
165
+ assert_equal ary_ucs4_2, ary_ucs4_1
166
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
167
+ assert_equal ary_ucs4_2, [0x20, 0x20, 0x61, 0x62, 0x63]
168
+
169
+ ascii_str = "abc_def"
170
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
171
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x5f, 0x64, 0x65, 0x66]
172
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
173
+ assert_equal ary_ucs4_2, ary_ucs4_1
174
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
175
+ assert_equal ary_ucs4_2, ary_ucs4_1
176
+ end
177
+
178
+ test "Bidi ascii numeric space test" do
179
+ pdf = MYPDF.new
180
+
181
+ ascii_str = "abc 123 def"
182
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
183
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x20, 0x31, 0x32, 0x33, 0x20, 0x64, 0x65, 0x66]
184
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
185
+ assert_equal ary_ucs4_2, ary_ucs4_1
186
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
187
+ assert_equal ary_ucs4_2, ary_ucs4_1
188
+
189
+ ascii_str = "abc_123_def"
190
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
191
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x5f, 0x31, 0x32, 0x33, 0x5f, 0x64, 0x65, 0x66]
192
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
193
+ assert_equal ary_ucs4_2, ary_ucs4_1
194
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
195
+ assert_equal ary_ucs4_2, ary_ucs4_1
196
+ end
197
+
198
+ test "Bidi ascii colon test" do
199
+ pdf = MYPDF.new
200
+
201
+ ascii_str = "abc:def"
202
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
203
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x3a, 0x64, 0x65, 0x66]
204
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
205
+ assert_equal ary_ucs4_2, ary_ucs4_1
206
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
207
+ assert_equal ary_ucs4_2, ary_ucs4_1
208
+
209
+ ascii_str = "abc: def"
210
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
211
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x3a, 0x20, 0x64, 0x65, 0x66]
212
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
213
+ assert_equal ary_ucs4_2, ary_ucs4_1
214
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
215
+ assert_equal ary_ucs4_2, ary_ucs4_1
216
+
217
+ ascii_str = "abc : def"
218
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
219
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x20, 0x3a, 0x20, 0x64, 0x65, 0x66]
220
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
221
+ assert_equal ary_ucs4_2, ary_ucs4_1
222
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
223
+ assert_equal ary_ucs4_2, ary_ucs4_1
224
+
225
+ ascii_str = "abc :: def"
226
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
227
+ assert_equal ary_ucs4_1, [0x61, 0x62, 0x63, 0x20, 0x20, 0x3a, 0x3a, 0x20, 0x20, 0x64, 0x65, 0x66]
228
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'R')
229
+ assert_equal ary_ucs4_2, ary_ucs4_1
230
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), '', 'L')
231
+ assert_equal ary_ucs4_2, ary_ucs4_1
232
+ end
233
+
234
+
235
+ test "Bidi arabic test" do
236
+ pdf = MYPDF.new
237
+
238
+ # Bidirectional Algorithm
239
+ ascii_str = "role"
240
+ utf8_arabic_str_1 = "\xd8\xaf\xd9\x88\xd8\xb1"
241
+ utf8_arabic_char_1 = "\xd8\xaf"
242
+
243
+ # UCS4 charactor -> UTF-8 charactor
244
+ utf8_chr = pdf.unichr(0x62f)
245
+ assert_equal "\xd8\xaf", utf8_chr
246
+
247
+ # UTF-8 string -> array of UCS4 charactor
248
+ ary_ucs4 = pdf.UTF8StringToArray(ascii_str)
249
+ assert_equal [0x72, 0x6f, 0x6c, 0x65], ary_ucs4
250
+ ary_ucs4 = pdf.UTF8StringToArray(utf8_arabic_str_1)
251
+ assert_equal [0x62f, 0x648, 0x631], ary_ucs4
252
+ ary_ucs4 = pdf.UTF8StringToArray(utf8_arabic_char_1)
253
+ assert_equal [0x62f], ary_ucs4
254
+
255
+
256
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
257
+ assert_equal [0x72, 0x6f, 0x6c, 0x65], ary_ucs4
258
+
259
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), ascii_str, 'R')
260
+ assert_equal [0x72, 0x6f, 0x6c, 0x65], ary_ucs4
261
+
262
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_arabic_char_1))
263
+ assert_equal [0xfea9], ary_ucs4
264
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_arabic_char_1), utf8_arabic_char_1, 'R')
265
+ assert_equal [0xfea9], ary_ucs4
266
+
267
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_arabic_str_1))
268
+ assert_equal [0xfead, 0xfeed, 0xfea9], ary_ucs4
269
+ end
270
+
271
+ test "Bidi Persian Sunday test" do
272
+ pdf = MYPDF.new
273
+
274
+ utf8_persian_str_1 = "\xdb\x8c" # 0x06cc
275
+ utf8_persian_str_2 = "\xdb\x8c\xda\xa9" # 0x06cc, 0x06a9
276
+ utf8_persian_str_3 = "\xdb\x8c\xda\xa9\xe2\x80\x8c" # 0x06cc, 0x06a9, 0x200c
277
+ utf8_persian_str_4 = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4" # 0x06cc, 0x06a9, 0x200c, 0x0634
278
+ utf8_persian_str_5 = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86" # 0x06cc, 0x06a9, 0x200c, 0x0634, 0x0646
279
+ utf8_persian_str_6 = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8" # 0x06cc, 0x06a9, 0x200c, 0x0634, 0x0646, 0x0628
280
+ utf8_persian_str_7 = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87" # Sunday # 0x06cc, 0x06a9, 0x200c, 0x0634, 0x0646, 0x0628, 0x0647
281
+
282
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_1))
283
+ assert_equal ary_ucs4, [0xfbfc]
284
+ current_font = pdf.get_current_font
285
+ assert_equal 256 + 2, current_font['subsetchars'].compact.length # 0x06cc, 0xfbfc
286
+
287
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_2))
288
+ assert_equal ary_ucs4, [0xfb8f, 0xfbfe]
289
+ current_font = pdf.get_current_font
290
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length # 0xfbfc + 0x06cc, 0x06a9, 0xfb8f, 0xfbfe
291
+
292
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_3))
293
+ assert_equal ary_ucs4, [0x200c, 0xfb8f, 0xfbfe]
294
+ current_font = pdf.get_current_font
295
+ assert_equal 256 + 6, current_font['subsetchars'].compact.length # 0xfbfc + 0x06cc, 0x06a9, 0x200c, 0xfb8f, 0xfbfe
296
+
297
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_4))
298
+ assert_equal ary_ucs4, [0xfeb5, 0x200c, 0xfb8f, 0xfbfe]
299
+ current_font = pdf.get_current_font
300
+ assert_equal 256 + 8, current_font['subsetchars'].compact.length # 0xfbfc + 0x06cc, 0x06a9, 0x200c, 0x0634, 0xfeb5, 0xfb8f, 0xfbfe
301
+
302
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_5))
303
+ assert_equal ary_ucs4, [0xfee6, 0xfeb7, 0x200c, 0xfb8f, 0xfbfe]
304
+ current_font = pdf.get_current_font
305
+ assert_equal 256 + 11, current_font['subsetchars'].compact.length # 0xfbfc, 0xfeb5 + 0x06cc, 0x06a9, 0x200c, 0x0634, 0x0646, 0xfee6, 0xfeb7, 0xfb8f, 0xfbfe
306
+
307
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_6))
308
+ assert_equal ary_ucs4, [0xfe90, 0xfee8, 0xfeb7, 0x200c, 0xfb8f, 0xfbfe]
309
+ current_font = pdf.get_current_font
310
+ assert_equal 256 + 14, current_font['subsetchars'].compact.length # 0xfbfc, 0xfeb5, 0xfee6 + 0x06cc, 0x06a9, 0x200c, 0x0634, 0x0646, 0x0628, 0xfe90, 0xfee8, 0xfeb7, 0xfb8f, 0xfbfe
311
+
312
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_7))
313
+ assert_equal ary_ucs4, [0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0x200c, 0xfb8f, 0xfbfe]
314
+ current_font = pdf.get_current_font
315
+ assert_equal 256 + 17, current_font['subsetchars'].compact.length # 0xfbfc, 0xfeb5, 0xfee6, 0xfe90 + 0x06cc, 0x06a9, 0x200c, 0x0634, 0x0646, 0x0628, 0x0647, 0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0xfb8f, 0xfbfe
316
+ end
317
+
318
+ test "Bidi Persian Sunday forcertl test" do
319
+ pdf = MYPDF.new
320
+ utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
321
+
322
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_sunday), '', 'R')
323
+ assert_equal ary_ucs4_1, [0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0x200C, 0xfb8f, 0xfbfe]
324
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_sunday), '', 'L')
325
+ assert_equal ary_ucs4_2, ary_ucs4_1
326
+ end
327
+
328
+ test "Bidi Persian Monday test" do
329
+ pdf = MYPDF.new
330
+
331
+ utf8_persian_str_1 = "\xd8\xaf"
332
+ utf8_persian_str_2 = "\xd8\xaf\xd9\x88"
333
+ utf8_persian_str_3 = "\xd8\xaf\xd9\x88\xd8\xb4"
334
+ utf8_persian_str_4 = "\xd8\xaf\xd9\x88\xd8\xb4\xd9\x86"
335
+ utf8_persian_str_5 = "\xd8\xaf\xd9\x88\xd8\xb4\xd9\x86\xd8\xa8"
336
+ utf8_persian_str_6 = "\xd8\xaf\xd9\x88\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87" # Monday
337
+
338
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_1))
339
+ assert_equal ary_ucs4, [0xfea9]
340
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_2))
341
+ assert_equal ary_ucs4, [0xfeed, 0xfea9]
342
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_3))
343
+ assert_equal ary_ucs4, [0xfeb5, 0xfeed, 0xfea9]
344
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_4))
345
+ assert_equal ary_ucs4, [0xfee6, 0xfeb7, 0xfeed, 0xfea9]
346
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_5))
347
+ assert_equal ary_ucs4, [0xfe90, 0xfee8, 0xfeb7, 0xfeed, 0xfea9]
348
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_6))
349
+ assert_equal ary_ucs4, [0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0xfeed, 0xfea9]
350
+ end
351
+
352
+ test "Bidi Persian Monday forcertl test" do
353
+ pdf = MYPDF.new
354
+ utf8_persian_str_monday = "\xd8\xaf\xd9\x88\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
355
+
356
+ ary_ucs4_1 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_monday), '', 'R')
357
+ assert_equal ary_ucs4_1, [0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0xfeed, 0xfea9]
358
+ ary_ucs4_2 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_monday), '', 'L')
359
+ assert_equal ary_ucs4_2, ary_ucs4_1
360
+ end
361
+
362
+ test "Bidi Persian and English test" do
363
+ pdf = MYPDF.new
364
+
365
+ utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
366
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_sunday + ' abc'))
367
+ assert_equal ary_ucs4, [0x61, 0x62, 0x63, 0x20, # 'abc '
368
+ 0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0x200C, 0xfb8f, 0xfbfe] # Sunday
369
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_sunday + ' abc'), '', 'R')
370
+ assert_equal ary_ucs4, [0x61, 0x62, 0x63, 0x20, # 'abc '
371
+ 0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0x200C, 0xfb8f, 0xfbfe] # Sunday
372
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_persian_str_sunday + ' abc'), '', 'L')
373
+ assert_equal ary_ucs4, [0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0x200C, 0xfb8f, 0xfbfe, # Sunday
374
+ 0x20, 0x61, 0x62, 0x63] # 'abc '
375
+ end
376
+
377
+ test "Bidi English and Persian test" do
378
+ pdf = MYPDF.new
379
+
380
+ utf8_persian_str_sunday = "\xdb\x8c\xda\xa9\xe2\x80\x8c\xd8\xb4\xd9\x86\xd8\xa8\xd9\x87"
381
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray('abc ' + utf8_persian_str_sunday))
382
+ assert_equal ary_ucs4, [0x61, 0x62, 0x63, 0x20, # 'abc '
383
+ 0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0x200C, 0xfb8f, 0xfbfe] # Sunday
384
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray('abc ' + utf8_persian_str_sunday), '', 'L')
385
+ assert_equal ary_ucs4, [0x61, 0x62, 0x63, 0x20, # 'abc '
386
+ 0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0x200C, 0xfb8f, 0xfbfe] # Sunday
387
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray('abc ' + utf8_persian_str_sunday), '', 'R')
388
+ assert_equal ary_ucs4, [0xfeea, 0xfe92, 0xfee8, 0xfeb7, 0x200C, 0xfb8f, 0xfbfe, # Sunday
389
+ 0x20, 0x61, 0x62, 0x63] # 'abc '
390
+ end
391
+
392
+ test "Bidi date test" do
393
+ pdf = MYPDF.new
394
+
395
+ utf8_date_str_1 = '12/01/2014'
396
+
397
+ pdf.set_rtl(true)
398
+ pdf.set_temp_rtl('rtl')
399
+ # UTF-8 string -> array of UCS4 charactor
400
+ ary_ucs4 = pdf.UTF8StringToArray(utf8_date_str_1)
401
+ assert_equal [0x31, 0x32, 0x2f, 0x30, 0x31, 0x2f, 0x32, 0x30, 0x31, 0x34], ary_ucs4 # 12/01/2014
402
+
403
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_date_str_1))
404
+ assert_equal [0x31, 0x32, 0x2f, 0x30, 0x31, 0x2f, 0x32, 0x30, 0x31, 0x34], ary_ucs4 # 12/01/2014
405
+
406
+ ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_date_str_1), utf8_date_str_1, 'R')
407
+ assert_equal [0x31, 0x32, 0x2f, 0x30, 0x31, 0x2f, 0x32, 0x30, 0x31, 0x34], ary_ucs4 # 12/01/2014
408
+ end
409
+
410
+ test "Bidi Japanese test" do
411
+ pdf = MYPDF.new
412
+
413
+ utf8_japanese_aiueo_str_1 = "\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a"
414
+
415
+ # UTF-8 string -> array of UCS4 charactor
416
+ ary_ucs4 = pdf.UTF8StringToArray(utf8_japanese_aiueo_str_1)
417
+ assert_equal [0x3042, 0x3044, 0x3046, 0x3048, 0x304a], ary_ucs4 # Japanese aiueo
418
+
419
+ current_font = pdf.get_current_font
420
+ assert_equal 256 + 5, current_font['subsetchars'].compact.length
421
+ end
422
+
423
+ test "UTF8StringToArray cache_utf8_string_to_array test" do
424
+ pdf = MYPDF.new
425
+
426
+ chars = pdf.UTF8StringToArray('1234')
427
+ chars.reverse!
428
+
429
+ rtn = pdf.cache_utf8_string_to_array('1234')
430
+ assert_equal rtn, [0x31, 0x32, 0x33, 0x34]
431
+ end
432
+
433
+ test "UniArrSubString test" do
434
+ pdf = RBPDF.new
435
+ str = pdf.uni_arr_sub_string(['a', 'b', 'c', ' ', 'd', 'e', 'f'])
436
+ assert_equal str, 'abc def'
437
+ end
438
+ end