rfpdf 1.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +18 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/core/rmagick.rb +85 -0
- data/lib/fonts/README.z +2 -0
- data/lib/fonts/arialunicid0_cw.rb +1738 -0
- data/lib/fonts/cid0cs.rb +21 -0
- data/lib/fonts/cid0ct.rb +21 -0
- data/lib/fonts/cid0jp.rb +21 -0
- data/lib/fonts/cid0kr.rb +21 -0
- data/lib/fonts/courier.rb +37 -0
- data/lib/fonts/dejavu-fonts-ttf-2.33/AUTHORS +53 -0
- data/lib/fonts/dejavu-fonts-ttf-2.33/BUGS +3 -0
- data/lib/fonts/dejavu-fonts-ttf-2.33/LICENSE +99 -0
- data/lib/fonts/dejavu-fonts-ttf-2.33/NEWS +1315 -0
- data/lib/fonts/dejavu-fonts-ttf-2.33/README +59 -0
- data/lib/fonts/dejavusans.ctg.z +0 -0
- data/lib/fonts/dejavusans.rb +338 -0
- data/lib/fonts/dejavusans.z +0 -0
- data/lib/fonts/dejavusansb.ctg.z +0 -0
- data/lib/fonts/dejavusansb.rb +330 -0
- data/lib/fonts/dejavusansb.z +0 -0
- data/lib/fonts/dejavusansbi.ctg.z +0 -0
- data/lib/fonts/dejavusansbi.rb +297 -0
- data/lib/fonts/dejavusansbi.z +0 -0
- data/lib/fonts/dejavusansi.ctg.z +0 -0
- data/lib/fonts/dejavusansi.rb +305 -0
- data/lib/fonts/dejavusansi.z +0 -0
- data/lib/fonts/freefont-20080912/AUTHORS +191 -0
- data/lib/fonts/freefont-20080912/COPYING +341 -0
- data/lib/fonts/freefont-20080912/CREDITS +506 -0
- data/lib/fonts/freefont-20080912/ChangeLog +3320 -0
- data/lib/fonts/freefont-20080912/INSTALL +81 -0
- data/lib/fonts/freefont-20080912/README +108 -0
- data/lib/fonts/freemono.ctg.z +0 -0
- data/lib/fonts/freemono.rb +203 -0
- data/lib/fonts/freemono.z +0 -0
- data/lib/fonts/freemonob.ctg.z +0 -0
- data/lib/fonts/freemonob.rb +120 -0
- data/lib/fonts/freemonob.z +0 -0
- data/lib/fonts/freemonobi.ctg.z +0 -0
- data/lib/fonts/freemonobi.rb +84 -0
- data/lib/fonts/freemonobi.z +0 -0
- data/lib/fonts/freemonoi.ctg.z +0 -0
- data/lib/fonts/freemonoi.rb +136 -0
- data/lib/fonts/freemonoi.z +0 -0
- data/lib/fonts/freesans.ctg.z +0 -0
- data/lib/fonts/freesans.rb +196 -0
- data/lib/fonts/freesans.z +0 -0
- data/lib/fonts/freesansb.ctg.z +0 -0
- data/lib/fonts/freesansb.rb +136 -0
- data/lib/fonts/freesansb.z +0 -0
- data/lib/fonts/freesansbi.ctg.z +0 -0
- data/lib/fonts/freesansbi.rb +108 -0
- data/lib/fonts/freesansbi.z +0 -0
- data/lib/fonts/freesansi.ctg.z +0 -0
- data/lib/fonts/freesansi.rb +136 -0
- data/lib/fonts/freesansi.z +0 -0
- data/lib/fonts/helvetica.rb +34 -0
- data/lib/fonts/helveticab.rb +34 -0
- data/lib/fonts/helveticabi.rb +34 -0
- data/lib/fonts/helveticai.rb +34 -0
- data/lib/fonts/hysmyeongjostdmedium.rb +31 -0
- data/lib/fonts/kozgopromedium.rb +47 -0
- data/lib/fonts/kozminproregular.rb +46 -0
- data/lib/fonts/msungstdlight.rb +23 -0
- data/lib/fonts/sjis.rb +834 -0
- data/lib/fonts/stsongstdlight.rb +23 -0
- data/lib/fonts/symbol.rb +33 -0
- data/lib/fonts/times.rb +34 -0
- data/lib/fonts/timesb.rb +34 -0
- data/lib/fonts/timesbi.rb +34 -0
- data/lib/fonts/timesi.rb +34 -0
- data/lib/fonts/uni2cid_ac15.rb +23613 -0
- data/lib/fonts/uni2cid_ag15.rb +30222 -0
- data/lib/fonts/uni2cid_aj16.rb +15705 -0
- data/lib/fonts/uni2cid_ak12.rb +17530 -0
- data/lib/fonts/zapfdingbats.rb +33 -0
- data/lib/htmlcolors.rb +209 -0
- data/lib/rfpdf/version.rb +3 -0
- data/lib/rfpdf.rb +16 -0
- data/lib/tcpdf.rb +14186 -0
- data/lib/unicode_data.rb +18317 -0
- data/logo_example.png +0 -0
- data/rfpdf.gemspec +35 -0
- data/test/tcpdf_bidi_test.rb +65 -0
- data/test/tcpdf_bookmark_test.rb +57 -0
- data/test/tcpdf_cell_test.rb +54 -0
- data/test/tcpdf_content_test.rb +117 -0
- data/test/tcpdf_css_test.rb +318 -0
- data/test/tcpdf_dom_test.rb +113 -0
- data/test/tcpdf_font_func_test.rb +27 -0
- data/test/tcpdf_font_style_test.rb +34 -0
- data/test/tcpdf_font_test.rb +176 -0
- data/test/tcpdf_format_test.rb +27 -0
- data/test/tcpdf_func_test.rb +126 -0
- data/test/tcpdf_html_test.rb +164 -0
- data/test/tcpdf_image_test.rb +54 -0
- data/test/tcpdf_test.rb +245 -0
- data/test/tcpdf_transaction_test.rb +199 -0
- data/test/tcpdf_viewerpreferences_test.rb +37 -0
- data/test/tcpdf_write_test.rb +173 -0
- data/test/test_helper.rb +1 -0
- data/test_unicode.rfpdf +115 -0
- data/utf8test.txt +135 -0
- metadata +202 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TcpdfTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "Image basic func extension test" do
|
6
|
+
pdf = TCPDF.new
|
7
|
+
|
8
|
+
type = pdf.get_image_file_type("/tmp/tcpdf_logo.gif")
|
9
|
+
assert_equal type, "gif"
|
10
|
+
|
11
|
+
type = pdf.get_image_file_type("/tmp/tcpdf_logo.PNG")
|
12
|
+
assert_equal type, "png"
|
13
|
+
|
14
|
+
type = pdf.get_image_file_type("/tmp/tcpdf_logo.jpg")
|
15
|
+
assert_equal type, "jpeg"
|
16
|
+
|
17
|
+
type = pdf.get_image_file_type("/tmp/tcpdf_logo.jpeg")
|
18
|
+
assert_equal type, "jpeg"
|
19
|
+
|
20
|
+
type = pdf.get_image_file_type("/tmp/tcpdf_logo")
|
21
|
+
assert_equal type, ""
|
22
|
+
|
23
|
+
type = pdf.get_image_file_type("")
|
24
|
+
assert_equal type, ""
|
25
|
+
|
26
|
+
type = pdf.get_image_file_type(nil)
|
27
|
+
assert_equal type, ""
|
28
|
+
end
|
29
|
+
|
30
|
+
test "Image basic func mime type test" do
|
31
|
+
pdf = TCPDF.new
|
32
|
+
|
33
|
+
type = pdf.get_image_file_type(nil, {})
|
34
|
+
assert_equal type, ''
|
35
|
+
|
36
|
+
type = pdf.get_image_file_type(nil, {'mime' => 'image/gif'})
|
37
|
+
assert_equal type, 'gif'
|
38
|
+
|
39
|
+
type = pdf.get_image_file_type(nil, {'mime' => 'image/jpeg'})
|
40
|
+
assert_equal type, 'jpeg'
|
41
|
+
|
42
|
+
type = pdf.get_image_file_type('/tmp/tcpdf_logo.gif', {'mime' => 'image/png'})
|
43
|
+
assert_equal type, 'png'
|
44
|
+
|
45
|
+
type = pdf.get_image_file_type('/tmp/tcpdf_logo.gif', {})
|
46
|
+
assert_equal type, 'gif'
|
47
|
+
|
48
|
+
type = pdf.get_image_file_type(nil, {'mime' => 'text/html'})
|
49
|
+
assert_equal type, ''
|
50
|
+
|
51
|
+
type = pdf.get_image_file_type(nil, [])
|
52
|
+
assert_equal type, ''
|
53
|
+
end
|
54
|
+
end
|
data/test/tcpdf_test.rb
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TcpdfTest < ActiveSupport::TestCase
|
4
|
+
class MYPDF < TCPDF
|
5
|
+
def getPageBuffer(page)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
test "set_x potision" do
|
11
|
+
pdf = TCPDF.new
|
12
|
+
width = pdf.get_page_width
|
13
|
+
|
14
|
+
pdf.set_x(5)
|
15
|
+
x = pdf.get_x
|
16
|
+
abs_x = pdf.get_abs_x
|
17
|
+
assert_equal 5, x
|
18
|
+
assert_equal 5, abs_x
|
19
|
+
|
20
|
+
pdf.set_x(-4)
|
21
|
+
x = pdf.get_x
|
22
|
+
abs_x = pdf.get_abs_x
|
23
|
+
assert_equal width - 4, x
|
24
|
+
assert_equal width - 4, abs_x
|
25
|
+
|
26
|
+
pdf.set_rtl(true) # Right to Left
|
27
|
+
|
28
|
+
pdf.set_x(5)
|
29
|
+
x = pdf.get_x
|
30
|
+
abs_x = pdf.get_abs_x
|
31
|
+
assert_equal 5, x
|
32
|
+
assert_equal width - 5, abs_x
|
33
|
+
|
34
|
+
pdf.set_x(-4)
|
35
|
+
x = pdf.get_x
|
36
|
+
abs_x = pdf.get_abs_x
|
37
|
+
assert_equal width - 4, x
|
38
|
+
assert_equal 4, abs_x
|
39
|
+
end
|
40
|
+
|
41
|
+
test "set_y potision" do
|
42
|
+
pdf = TCPDF.new
|
43
|
+
width = pdf.get_page_width
|
44
|
+
|
45
|
+
pdf.set_left_margin(10)
|
46
|
+
pdf.set_y(20)
|
47
|
+
x = pdf.get_x
|
48
|
+
abs_x = pdf.get_abs_x
|
49
|
+
y = pdf.get_y
|
50
|
+
assert_equal 10, x
|
51
|
+
assert_equal 10, abs_x
|
52
|
+
assert_equal 20, y
|
53
|
+
|
54
|
+
pdf.set_left_margin(30)
|
55
|
+
pdf.set_y(20)
|
56
|
+
x = pdf.get_x
|
57
|
+
abs_x = pdf.get_abs_x
|
58
|
+
y = pdf.get_y
|
59
|
+
assert_equal 30, x
|
60
|
+
assert_equal 30, abs_x
|
61
|
+
assert_equal 20, y
|
62
|
+
|
63
|
+
pdf.set_rtl(true) # Right to Left
|
64
|
+
|
65
|
+
pdf.set_right_margin(10)
|
66
|
+
pdf.set_y(20)
|
67
|
+
x = pdf.get_x
|
68
|
+
abs_x = pdf.get_abs_x
|
69
|
+
y = pdf.get_y
|
70
|
+
assert_equal 10, x
|
71
|
+
assert_equal width - 10, abs_x
|
72
|
+
assert_equal 20, y
|
73
|
+
|
74
|
+
pdf.set_right_margin(30)
|
75
|
+
pdf.set_y(20)
|
76
|
+
x = pdf.get_x
|
77
|
+
abs_x = pdf.get_abs_x
|
78
|
+
y = pdf.get_y
|
79
|
+
assert_equal 30, x
|
80
|
+
assert_equal width - 30, abs_x
|
81
|
+
assert_equal 20, y
|
82
|
+
end
|
83
|
+
|
84
|
+
test "add_page potision" do
|
85
|
+
pdf = TCPDF.new
|
86
|
+
width = pdf.get_page_width
|
87
|
+
|
88
|
+
pdf.add_page
|
89
|
+
x = pdf.get_x
|
90
|
+
abs_x = pdf.get_abs_x
|
91
|
+
y = pdf.get_y
|
92
|
+
assert_in_delta 10.00125, x, 0.00001
|
93
|
+
assert_in_delta 10.00125, abs_x, 0.00001
|
94
|
+
assert_in_delta 10.00125, y, 0.00001
|
95
|
+
|
96
|
+
pdf.set_rtl(true) # Right to Left
|
97
|
+
|
98
|
+
pdf.add_page
|
99
|
+
x = pdf.get_x
|
100
|
+
abs_x = pdf.get_abs_x
|
101
|
+
y = pdf.get_y
|
102
|
+
assert_in_delta 10.00125, x, 0.00001
|
103
|
+
assert_in_delta width - 10.00125, abs_x, 0.00001
|
104
|
+
assert_in_delta 10.00125, y, 0.00001
|
105
|
+
|
106
|
+
pdf.set_page(1)
|
107
|
+
page = pdf.get_page
|
108
|
+
assert_equal 1, page
|
109
|
+
pdf.set_y(20)
|
110
|
+
y = pdf.get_y
|
111
|
+
assert_equal 20, y
|
112
|
+
pdf.add_page
|
113
|
+
y = pdf.get_y
|
114
|
+
assert_in_delta 10.00125, y, 0.00001
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
test "add_page" do
|
119
|
+
pdf = TCPDF.new
|
120
|
+
|
121
|
+
page = pdf.get_page
|
122
|
+
assert_equal 0, page
|
123
|
+
pages = pdf.get_num_pages
|
124
|
+
assert_equal 0, pages
|
125
|
+
|
126
|
+
pdf.add_page
|
127
|
+
page = pdf.get_page
|
128
|
+
assert_equal 1, page
|
129
|
+
pages = pdf.get_num_pages
|
130
|
+
assert_equal 1, pages
|
131
|
+
|
132
|
+
pdf.add_page
|
133
|
+
page = pdf.get_page
|
134
|
+
assert_equal 2, page
|
135
|
+
pages = pdf.get_num_pages
|
136
|
+
assert_equal 2, pages
|
137
|
+
|
138
|
+
pdf.set_page(1)
|
139
|
+
page = pdf.get_page
|
140
|
+
assert_equal 1, page
|
141
|
+
|
142
|
+
pdf.add_page
|
143
|
+
page = pdf.get_page
|
144
|
+
assert_equal 2, page
|
145
|
+
pages = pdf.get_num_pages
|
146
|
+
assert_equal 2, pages
|
147
|
+
|
148
|
+
pdf.add_page
|
149
|
+
page = pdf.get_page
|
150
|
+
assert_equal 3, page
|
151
|
+
pages = pdf.get_num_pages
|
152
|
+
assert_equal 3, pages
|
153
|
+
|
154
|
+
pdf.set_page(1)
|
155
|
+
page = pdf.get_page
|
156
|
+
assert_equal 1, page
|
157
|
+
|
158
|
+
pdf.last_page
|
159
|
+
page = pdf.get_page
|
160
|
+
assert_equal 3, page
|
161
|
+
pages = pdf.get_num_pages
|
162
|
+
assert_equal 3, pages
|
163
|
+
end
|
164
|
+
|
165
|
+
test "add_page set_page Under Error" do
|
166
|
+
pdf = TCPDF.new
|
167
|
+
|
168
|
+
page = pdf.get_page
|
169
|
+
assert_equal 0, page
|
170
|
+
pages = pdf.get_num_pages
|
171
|
+
assert_equal 0, pages
|
172
|
+
|
173
|
+
pdf.add_page
|
174
|
+
page = pdf.get_page
|
175
|
+
assert_equal 1, page
|
176
|
+
pages = pdf.get_num_pages
|
177
|
+
assert_equal 1, pages
|
178
|
+
|
179
|
+
assert_raise(RuntimeError) {pdf.set_page(0)} # Page under size
|
180
|
+
end
|
181
|
+
|
182
|
+
test "add_page set_page Over Error" do
|
183
|
+
pdf = TCPDF.new
|
184
|
+
|
185
|
+
page = pdf.get_page
|
186
|
+
assert_equal 0, page
|
187
|
+
pages = pdf.get_num_pages
|
188
|
+
assert_equal 0, pages
|
189
|
+
|
190
|
+
pdf.add_page
|
191
|
+
page = pdf.get_page
|
192
|
+
assert_equal 1, page
|
193
|
+
pages = pdf.get_num_pages
|
194
|
+
assert_equal 1, pages
|
195
|
+
|
196
|
+
pdf.add_page
|
197
|
+
page = pdf.get_page
|
198
|
+
assert_equal 2, page
|
199
|
+
pages = pdf.get_num_pages
|
200
|
+
assert_equal 2, pages
|
201
|
+
|
202
|
+
pdf.set_page(1)
|
203
|
+
page = pdf.get_page
|
204
|
+
assert_equal 1, page
|
205
|
+
|
206
|
+
assert_raise(RuntimeError) {pdf.set_page(3)} # Page over size
|
207
|
+
end
|
208
|
+
|
209
|
+
test "deletePage test" do
|
210
|
+
pdf = MYPDF.new
|
211
|
+
|
212
|
+
pdf.add_page
|
213
|
+
pdf.write(0, "Page 1")
|
214
|
+
|
215
|
+
page = pdf.get_page
|
216
|
+
assert_equal 1, page
|
217
|
+
pages = pdf.get_num_pages
|
218
|
+
assert_equal 1, pages
|
219
|
+
|
220
|
+
contents1 = pdf.getPageBuffer(1)
|
221
|
+
|
222
|
+
pdf.add_page
|
223
|
+
pdf.write(0, "Page 2")
|
224
|
+
|
225
|
+
page = pdf.get_page
|
226
|
+
assert_equal 2, page
|
227
|
+
pages = pdf.get_num_pages
|
228
|
+
assert_equal 2, pages
|
229
|
+
|
230
|
+
contents2 = pdf.getPageBuffer(2)
|
231
|
+
|
232
|
+
pdf.deletePage(1)
|
233
|
+
page = pdf.get_page
|
234
|
+
assert_equal 1, page
|
235
|
+
pages = pdf.get_num_pages
|
236
|
+
assert_equal 1, pages
|
237
|
+
|
238
|
+
contents3 = pdf.getPageBuffer(1)
|
239
|
+
assert_not_equal contents3, contents1
|
240
|
+
assert_equal contents3, contents2
|
241
|
+
|
242
|
+
contents4 = pdf.getPageBuffer(2)
|
243
|
+
assert_equal contents4, false
|
244
|
+
end
|
245
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TcpdfTest < ActiveSupport::TestCase
|
4
|
+
class MYPDF < TCPDF
|
5
|
+
def getPageBuffer(page)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
test "Transaction write test without diskcache" do
|
11
|
+
pdf = MYPDF.new
|
12
|
+
pdf.add_page()
|
13
|
+
page = pdf.get_page
|
14
|
+
|
15
|
+
pdf.write(0, "LINE 0\n")
|
16
|
+
contents01 = pdf.getPageBuffer(page).dup
|
17
|
+
|
18
|
+
pdf.start_transaction()
|
19
|
+
|
20
|
+
pdf.write(0, "LINE 1\n")
|
21
|
+
pdf.write(0, "LINE 2\n")
|
22
|
+
contents02 = pdf.getPageBuffer(page).dup
|
23
|
+
assert_not_equal contents01, contents02
|
24
|
+
|
25
|
+
# rolls back to the last (re)start 1
|
26
|
+
pdf = pdf.rollback_transaction()
|
27
|
+
contents03 = pdf.getPageBuffer(page).dup
|
28
|
+
assert_equal contents01, contents03
|
29
|
+
|
30
|
+
pdf.start_transaction()
|
31
|
+
|
32
|
+
pdf.write(0, "LINE 3\n")
|
33
|
+
pdf.write(0, "LINE 4\n")
|
34
|
+
contents04 = pdf.getPageBuffer(page).dup
|
35
|
+
assert_not_equal contents03, contents04
|
36
|
+
|
37
|
+
# rolls back to the last (re)start 2
|
38
|
+
pdf = pdf.rollback_transaction()
|
39
|
+
contents05 = pdf.getPageBuffer(page).dup
|
40
|
+
assert_equal contents03, contents05
|
41
|
+
|
42
|
+
pdf.commit_transaction()
|
43
|
+
end
|
44
|
+
|
45
|
+
test "Transaction test with diskcache" do
|
46
|
+
pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
47
|
+
pdf.add_page()
|
48
|
+
page = pdf.get_page
|
49
|
+
|
50
|
+
pdf.write(0, "LINE 0\n")
|
51
|
+
contents01 = pdf.getPageBuffer(page).dup
|
52
|
+
cache_file1 = pdf.cache_file_length.dup
|
53
|
+
|
54
|
+
pdf.start_transaction()
|
55
|
+
|
56
|
+
pdf.write(0, "LINE 1\n")
|
57
|
+
pdf.write(0, "LINE 2\n")
|
58
|
+
cache_file2 = pdf.cache_file_length.dup
|
59
|
+
contents02 = pdf.getPageBuffer(page).dup
|
60
|
+
assert_not_equal cache_file1, cache_file2
|
61
|
+
assert_not_equal contents01, contents02
|
62
|
+
|
63
|
+
# rolls back to the last (re)start 1
|
64
|
+
pdf = pdf.rollback_transaction()
|
65
|
+
|
66
|
+
cache_file3 = pdf.cache_file_length.dup
|
67
|
+
contents03 = pdf.getPageBuffer(page).dup
|
68
|
+
assert_equal cache_file1, cache_file3
|
69
|
+
assert_equal contents01, contents03
|
70
|
+
|
71
|
+
pdf.start_transaction()
|
72
|
+
|
73
|
+
pdf.write(0, "LINE 3\n")
|
74
|
+
pdf.write(0, "LINE 4\n")
|
75
|
+
contents04 = pdf.getPageBuffer(page).dup
|
76
|
+
assert_not_equal contents03, contents04
|
77
|
+
|
78
|
+
# rolls back to the last (re)start 2
|
79
|
+
pdf = pdf.rollback_transaction()
|
80
|
+
|
81
|
+
contents05 = pdf.getPageBuffer(page).dup
|
82
|
+
assert_equal contents03, contents05
|
83
|
+
end
|
84
|
+
|
85
|
+
test "Transaction multi_cell test without diskcache" do
|
86
|
+
pdf = MYPDF.new
|
87
|
+
pdf.add_page()
|
88
|
+
page = pdf.get_page
|
89
|
+
|
90
|
+
pdf.multi_cell(50, 5, 'mult_cell 1', 0)
|
91
|
+
contents01 = pdf.getPageBuffer(page).dup
|
92
|
+
|
93
|
+
pdf.start_transaction()
|
94
|
+
|
95
|
+
pdf.multi_cell(50, 5, 'mult_cell 1', 1)
|
96
|
+
pdf.multi_cell(50, 5, 'mult_cell 2', 1)
|
97
|
+
contents02 = pdf.getPageBuffer(page).dup
|
98
|
+
assert_not_equal contents01, contents02
|
99
|
+
|
100
|
+
# rolls back to the last (re)start 1
|
101
|
+
pdf = pdf.rollback_transaction()
|
102
|
+
contents03 = pdf.getPageBuffer(page).dup
|
103
|
+
assert_equal contents01, contents03
|
104
|
+
|
105
|
+
pdf.start_transaction()
|
106
|
+
|
107
|
+
pdf.multi_cell(50, 5, 'mult_cell 3', 1)
|
108
|
+
pdf.multi_cell(50, 5, 'mult_cell 4', 1)
|
109
|
+
contents04 = pdf.getPageBuffer(page).dup
|
110
|
+
assert_not_equal contents03, contents04
|
111
|
+
|
112
|
+
# rolls back to the last (re)start 2
|
113
|
+
pdf = pdf.rollback_transaction()
|
114
|
+
contents05 = pdf.getPageBuffer(page).dup
|
115
|
+
assert_equal contents03, contents05
|
116
|
+
|
117
|
+
pdf.commit_transaction()
|
118
|
+
end
|
119
|
+
|
120
|
+
test "Transaction mult_cell test with diskcache" do
|
121
|
+
pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
122
|
+
pdf.add_page()
|
123
|
+
page = pdf.get_page
|
124
|
+
|
125
|
+
pdf.multi_cell(50, 5, 'mult_cell 0', 1)
|
126
|
+
cache_file1 = pdf.cache_file_length.dup
|
127
|
+
contents01 = pdf.getPageBuffer(page).dup
|
128
|
+
|
129
|
+
pdf.start_transaction()
|
130
|
+
|
131
|
+
pdf.multi_cell(50, 5, 'mult_cell 1', 1)
|
132
|
+
pdf.multi_cell(50, 5, 'mult_cell 2', 1)
|
133
|
+
cache_file2 = pdf.cache_file_length.dup
|
134
|
+
contents02 = pdf.getPageBuffer(page).dup
|
135
|
+
assert_not_equal cache_file1, cache_file2
|
136
|
+
assert_not_equal contents01, contents02
|
137
|
+
|
138
|
+
# rolls back to the last (re)start 1
|
139
|
+
pdf = pdf.rollback_transaction()
|
140
|
+
|
141
|
+
contents03 = pdf.getPageBuffer(page).dup
|
142
|
+
cache_file3 = pdf.cache_file_length.dup
|
143
|
+
assert_equal cache_file1, cache_file3
|
144
|
+
assert_equal contents01, contents03
|
145
|
+
|
146
|
+
pdf.start_transaction()
|
147
|
+
|
148
|
+
pdf.multi_cell(50, 5, 'mult_cell 3', 1)
|
149
|
+
pdf.multi_cell(50, 5, 'mult_cell 4', 1)
|
150
|
+
contents04 = pdf.getPageBuffer(page).dup
|
151
|
+
assert_not_equal contents03, contents04
|
152
|
+
|
153
|
+
# rolls back to the last (re)start 2
|
154
|
+
pdf = pdf.rollback_transaction()
|
155
|
+
|
156
|
+
contents05 = pdf.getPageBuffer(page).dup
|
157
|
+
assert_equal contents03, contents05
|
158
|
+
end
|
159
|
+
|
160
|
+
test "Transaction mult_cell self test with diskcache" do
|
161
|
+
pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
162
|
+
pdf.add_page()
|
163
|
+
page = pdf.get_page
|
164
|
+
|
165
|
+
pdf.multi_cell(50, 5, 'mult_cell 0', 1)
|
166
|
+
cache_file1 = pdf.cache_file_length.dup
|
167
|
+
contents01 = pdf.getPageBuffer(page).dup
|
168
|
+
|
169
|
+
pdf.start_transaction()
|
170
|
+
|
171
|
+
pdf.multi_cell(50, 5, 'mult_cell 1', 1)
|
172
|
+
pdf.multi_cell(50, 5, 'mult_cell 2', 1)
|
173
|
+
cache_file2 = pdf.cache_file_length.dup
|
174
|
+
contents02 = pdf.getPageBuffer(page).dup
|
175
|
+
assert_not_equal cache_file1, cache_file2
|
176
|
+
assert_not_equal contents01, contents02
|
177
|
+
|
178
|
+
# rolls back to the last (re)start 1
|
179
|
+
pdf.rollback_transaction(true)
|
180
|
+
|
181
|
+
contents03 = pdf.getPageBuffer(page).dup
|
182
|
+
cache_file3 = pdf.cache_file_length.dup
|
183
|
+
assert_equal cache_file1, cache_file3
|
184
|
+
assert_equal contents01, contents03
|
185
|
+
|
186
|
+
pdf.start_transaction()
|
187
|
+
|
188
|
+
pdf.multi_cell(50, 5, 'mult_cell 3', 1)
|
189
|
+
pdf.multi_cell(50, 5, 'mult_cell 4', 1)
|
190
|
+
contents04 = pdf.getPageBuffer(page).dup
|
191
|
+
assert_not_equal contents03, contents04
|
192
|
+
|
193
|
+
# rolls back to the last (re)start 2
|
194
|
+
pdf.rollback_transaction(true)
|
195
|
+
|
196
|
+
contents05 = pdf.getPageBuffer(page).dup
|
197
|
+
assert_equal contents03, contents05
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TcpdfPageTest < ActiveSupport::TestCase
|
4
|
+
class MYPDF < TCPDF
|
5
|
+
def putviewerpreferences
|
6
|
+
super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
test "viewerpreferences test" do
|
11
|
+
# set array for viewer preferences
|
12
|
+
preferences = {
|
13
|
+
'HideToolbar' => true,
|
14
|
+
'HideMenubar' => true,
|
15
|
+
'HideWindowUI' => true,
|
16
|
+
'FitWindow' => true,
|
17
|
+
'CenterWindow' => true,
|
18
|
+
'DisplayDocTitle' => true,
|
19
|
+
'NonFullScreenPageMode' => 'UseNone', # UseNone, UseOutlines, UseThumbs, UseOC
|
20
|
+
'ViewArea' => 'CropBox', # CropBox, BleedBox, TrimBox, ArtBox
|
21
|
+
'ViewClip' => 'CropBox', # CropBox, BleedBox, TrimBox, ArtBox
|
22
|
+
'PrintArea' => 'CropBox', # CropBox, BleedBox, TrimBox, ArtBox
|
23
|
+
'PrintClip' => 'CropBox', # CropBox, BleedBox, TrimBox, ArtBox
|
24
|
+
'PrintScaling' => 'AppDefault', # None, AppDefault
|
25
|
+
'Duplex' => 'DuplexFlipLongEdge', # Simplex, DuplexFlipShortEdge, DuplexFlipLongEdge
|
26
|
+
'PickTrayByPDFSize' => true,
|
27
|
+
'PrintPageRange' => [1,1,2,3],
|
28
|
+
'NumCopies' => 2
|
29
|
+
}
|
30
|
+
|
31
|
+
pdf = MYPDF.new
|
32
|
+
pdf.set_viewer_preferences(preferences)
|
33
|
+
out = pdf.putviewerpreferences()
|
34
|
+
|
35
|
+
assert_equal out, '/ViewerPreferences << /Direction /L2R /HideToolbar true /HideMenubar true /HideWindowUI true /FitWindow true /CenterWindow true /DisplayDocTitle true /NonFullScreenPageMode /UseNone /ViewArea /CropBox /ViewClip /CropBox /PrintArea /CropBox /PrintClip /CropBox /PrintScaling /AppDefault /Duplex /DuplexFlipLongEdge /PickTrayByPDFSize true /PrintPageRange [0 0 1 2] /NumCopies 2 >>'
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TcpdfTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "write Basic test" do
|
6
|
+
pdf = TCPDF.new
|
7
|
+
|
8
|
+
line = pdf.write(0, "LINE 1")
|
9
|
+
assert_equal line, 1
|
10
|
+
|
11
|
+
line = pdf.write(0, "LINE 1\n")
|
12
|
+
assert_equal line, 1
|
13
|
+
|
14
|
+
line = pdf.write(0, "LINE 1\n2\n")
|
15
|
+
assert_equal line, 2
|
16
|
+
|
17
|
+
line = pdf.write(0, "")
|
18
|
+
assert_equal line, 1
|
19
|
+
|
20
|
+
line = pdf.write(0, "\n")
|
21
|
+
assert_equal line, 1
|
22
|
+
|
23
|
+
line = pdf.write(0, "abcdefghijklmnopgrstuvwxyz01234567890")
|
24
|
+
assert_equal line, 1
|
25
|
+
line = pdf.write(0, "abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890")
|
26
|
+
assert_equal line, 2
|
27
|
+
line = pdf.write(0, "abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890")
|
28
|
+
assert_equal line, 3
|
29
|
+
end
|
30
|
+
|
31
|
+
test "write Break test single line 1" do
|
32
|
+
pdf = TCPDF.new
|
33
|
+
pdf.add_page()
|
34
|
+
|
35
|
+
cell_hight = pdf.get_cell_height_ratio()
|
36
|
+
fontsize = pdf.get_font_size()
|
37
|
+
break_hight = pdf.set_auto_page_break(true)
|
38
|
+
|
39
|
+
pno = pdf.get_page
|
40
|
+
assert_equal pno, 1
|
41
|
+
|
42
|
+
0.upto(60) do |i|
|
43
|
+
y = pdf.get_y()
|
44
|
+
old_pno = pno
|
45
|
+
|
46
|
+
line = pdf.write(0, "LINE 1\n")
|
47
|
+
assert_equal line, 1
|
48
|
+
|
49
|
+
pno = pdf.get_page
|
50
|
+
|
51
|
+
if y + fontsize * cell_hight < break_hight
|
52
|
+
assert_equal pno, old_pno
|
53
|
+
else
|
54
|
+
assert_equal pno, old_pno + 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test "write Break test single line 2" do
|
60
|
+
pdf = TCPDF.new
|
61
|
+
pdf.add_page()
|
62
|
+
|
63
|
+
0.upto(49) do |i|
|
64
|
+
line = pdf.write(0, "LINE 1\n")
|
65
|
+
assert_equal line, 1
|
66
|
+
|
67
|
+
pno = pdf.get_page
|
68
|
+
assert_equal pno, 1
|
69
|
+
end
|
70
|
+
|
71
|
+
line = pdf.write(0, "abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890 abcdefghijklmnopgrstuvwxyz01234567890")
|
72
|
+
assert_equal line, 2
|
73
|
+
pno = pdf.get_page
|
74
|
+
assert_equal pno, 2
|
75
|
+
end
|
76
|
+
|
77
|
+
test "write Break test multi line 1" do
|
78
|
+
pdf = TCPDF.new
|
79
|
+
pdf.add_page()
|
80
|
+
pno = pdf.get_page
|
81
|
+
assert_equal pno, 1
|
82
|
+
|
83
|
+
line = pdf.write(0, "1\n\n\n\n\n\n\n\n\n\n 2\n\n\n\n\n\n\n\n\n\n 3\n\n\n\n\n\n\n\n\n\n 4\n\n\n\n\n\n\n\n\n\n")
|
84
|
+
assert_equal line, 40
|
85
|
+
pno = pdf.get_page
|
86
|
+
assert_equal pno, 1
|
87
|
+
|
88
|
+
line = pdf.write(0, "1\n\n\n\n\n\n\n\n\n\n 2\n\n\n\n\n\n\n\n\n\n 3\n\n\n\n\n\n\n\n\n\n 4\n\n\n\n\n\n\n\n\n\n")
|
89
|
+
assert_equal line, 40
|
90
|
+
pno = pdf.get_page
|
91
|
+
assert_equal pno, 2
|
92
|
+
end
|
93
|
+
|
94
|
+
test "write Break test multi line 2" do
|
95
|
+
pdf = TCPDF.new
|
96
|
+
pdf.add_page()
|
97
|
+
pno = pdf.get_page
|
98
|
+
assert_equal pno, 1
|
99
|
+
|
100
|
+
line = pdf.write(0, "1\n\n\n\n\n\n\n\n\n\n 2\n\n\n\n\n\n\n\n\n\n 3\n\n\n\n\n\n\n\n\n\n 4\n\n\n\n\n\n\n\n\n\n 5\n\n\n\n\n\n\n\n\n\n 6\n\n\n\n\n\n\n\n\n\n 7\n\n\n\n\n\n\n\n\n\n 8\n\n\n\n\n\n\n\n\n\n 9\n\n\n\n\n\n\n\n\n\n 10\n\n\n\n\n\n\n\n\n\n 11\n\n\n\n\n\n\n\n\n\n")
|
101
|
+
assert_equal line, 110
|
102
|
+
pno = pdf.get_page
|
103
|
+
assert_equal pno, 3
|
104
|
+
end
|
105
|
+
|
106
|
+
test "write firstline test" do
|
107
|
+
pdf = TCPDF.new
|
108
|
+
pdf.add_page()
|
109
|
+
pno = pdf.get_page
|
110
|
+
assert_equal pno, 1
|
111
|
+
|
112
|
+
line = pdf.write(0, "\n", nil, 0, '', false, 0, true)
|
113
|
+
assert_equal line, "\n"
|
114
|
+
|
115
|
+
line = pdf.write(0, "\n", nil, 0, '', false, 0, true)
|
116
|
+
assert_equal line, "\n"
|
117
|
+
|
118
|
+
line = pdf.write(0, "12345\n", nil, 0, '', false, 0, true)
|
119
|
+
assert_equal line, "\n"
|
120
|
+
|
121
|
+
line = pdf.write(0, "12345\nabcde", nil, 0, '', false, 0, true)
|
122
|
+
assert_equal line, "\nabcde"
|
123
|
+
|
124
|
+
line = pdf.write(0, "12345\nabcde\n", nil, 0, '', false, 0, true)
|
125
|
+
assert_equal line, "\nabcde\n"
|
126
|
+
|
127
|
+
line = pdf.write(0, "12345\nabcde\nefgh", nil, 0, '', false, 0, true)
|
128
|
+
assert_equal line, "\nabcde\nefgh"
|
129
|
+
end
|
130
|
+
|
131
|
+
class MYPDF < TCPDF
|
132
|
+
def endlinex
|
133
|
+
@endlinex
|
134
|
+
end
|
135
|
+
def r_margin
|
136
|
+
@r_margin
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
test "write endline x test 1" do
|
141
|
+
pdf = MYPDF.new
|
142
|
+
pdf.add_page()
|
143
|
+
line = pdf.write(0, " cccccccccc cccccccccc ", nil, 0, '', false, 0, true)
|
144
|
+
endlinex = pdf.endlinex()
|
145
|
+
assert_not_equal endlinex, 0
|
146
|
+
end
|
147
|
+
|
148
|
+
test "write endline x test 2" do
|
149
|
+
pdf = MYPDF.new
|
150
|
+
pdf.add_page()
|
151
|
+
|
152
|
+
r_margin = pdf.r_margin()
|
153
|
+
width = pdf.getPageWidth()
|
154
|
+
x = width - r_margin - 10
|
155
|
+
pdf.SetX(x)
|
156
|
+
line = pdf.write(0, " cccccccccc cccccccccc ", nil, 0, '', false, 0, true)
|
157
|
+
endlinex = pdf.endlinex()
|
158
|
+
assert_equal endlinex, x
|
159
|
+
end
|
160
|
+
|
161
|
+
test "write endline x test 3" do
|
162
|
+
pdf = MYPDF.new
|
163
|
+
pdf.add_page()
|
164
|
+
|
165
|
+
r_margin = pdf.r_margin()
|
166
|
+
width = pdf.getPageWidth()
|
167
|
+
x = width - r_margin - 10
|
168
|
+
pdf.SetX(x)
|
169
|
+
line = pdf.write(0, "cccccccccc cccccccccc ", nil, 0, '', false, 0, true)
|
170
|
+
endlinex = pdf.endlinex()
|
171
|
+
assert_not_equal endlinex, x
|
172
|
+
end
|
173
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#!/usr/bin/env ruby
|