rbpdf 1.18.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG +35 -0
- data/Gemfile +4 -0
- data/README.md +68 -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/freeserif.ctg.z +0 -0
- data/lib/fonts/freeserif.rb +285 -0
- data/lib/fonts/freeserif.z +0 -0
- data/lib/fonts/freeserifb.ctg.z +0 -0
- data/lib/fonts/freeserifb.rb +164 -0
- data/lib/fonts/freeserifb.z +0 -0
- data/lib/fonts/freeserifbi.ctg.z +0 -0
- data/lib/fonts/freeserifbi.rb +130 -0
- data/lib/fonts/freeserifbi.z +0 -0
- data/lib/fonts/freeserifi.ctg.z +0 -0
- data/lib/fonts/freeserifi.rb +151 -0
- data/lib/fonts/freeserifi.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 +207 -0
- data/lib/rbpdf.rb +14472 -0
- data/lib/rbpdf/version.rb +3 -0
- data/lib/unicode_data.rb +18315 -0
- data/logo_example.png +0 -0
- data/rbpdf.gemspec +35 -0
- data/test/rbpdf_bidi_test.rb +65 -0
- data/test/rbpdf_bookmark_test.rb +57 -0
- data/test/rbpdf_cell_test.rb +232 -0
- data/test/rbpdf_content_test.rb +117 -0
- data/test/rbpdf_css_test.rb +318 -0
- data/test/rbpdf_dom_test.rb +113 -0
- data/test/rbpdf_font_func_test.rb +27 -0
- data/test/rbpdf_font_style_test.rb +34 -0
- data/test/rbpdf_font_test.rb +181 -0
- data/test/rbpdf_format_test.rb +27 -0
- data/test/rbpdf_func_test.rb +126 -0
- data/test/rbpdf_html_test.rb +164 -0
- data/test/rbpdf_htmlcell_test.rb +64 -0
- data/test/rbpdf_image_test.rb +108 -0
- data/test/rbpdf_test.rb +245 -0
- data/test/rbpdf_transaction_test.rb +199 -0
- data/test/rbpdf_viewerpreferences_test.rb +37 -0
- data/test/rbpdf_write_test.rb +173 -0
- data/test/test_helper.rb +1 -0
- data/test_unicode.rbpdf +115 -0
- data/utf8test.txt +120 -0
- metadata +216 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class RbpdfTest < ActiveSupport::TestCase
|
|
4
|
+
test "write_html_cell Basic test" do
|
|
5
|
+
pdf = RBPDF.new
|
|
6
|
+
pdf.add_page()
|
|
7
|
+
|
|
8
|
+
htmlcontent = '<p>foo</p>'
|
|
9
|
+
pdf.write_html_cell(0, 5, 10, '', htmlcontent, 0, 1)
|
|
10
|
+
|
|
11
|
+
pno = pdf.get_page
|
|
12
|
+
assert_equal pno, 1
|
|
13
|
+
|
|
14
|
+
y = pdf.get_y
|
|
15
|
+
assert_in_delta 17.3, y, 0.1
|
|
16
|
+
|
|
17
|
+
no = pdf.get_num_pages
|
|
18
|
+
assert_equal no, 1
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "write_html_cell Page Break test 1" do
|
|
22
|
+
pdf = RBPDF.new
|
|
23
|
+
pdf.add_page()
|
|
24
|
+
|
|
25
|
+
pdf.set_top_margin(30)
|
|
26
|
+
|
|
27
|
+
h = pdf.get_page_height
|
|
28
|
+
pdf.set_y(h - 15)
|
|
29
|
+
|
|
30
|
+
htmlcontent = '<p>foo</p>'
|
|
31
|
+
pdf.write_html_cell(0, 5, 10, '', htmlcontent, 0, 1)
|
|
32
|
+
|
|
33
|
+
pno = pdf.get_page
|
|
34
|
+
assert_equal pno, 2
|
|
35
|
+
|
|
36
|
+
y = pdf.get_y
|
|
37
|
+
assert_in_delta 40.0, y, 0.1
|
|
38
|
+
|
|
39
|
+
no = pdf.get_num_pages
|
|
40
|
+
assert_equal no, 2
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test "write_html_cell Page Break test 2" do
|
|
44
|
+
pdf = RBPDF.new
|
|
45
|
+
pdf.add_page()
|
|
46
|
+
|
|
47
|
+
pdf.set_top_margin(30)
|
|
48
|
+
|
|
49
|
+
h = pdf.get_page_height
|
|
50
|
+
pdf.set_y(h - 15)
|
|
51
|
+
|
|
52
|
+
htmlcontent = '<p>foo</p>'
|
|
53
|
+
pdf.write_html_cell(0, 5, 10, '', htmlcontent, "LRBT", 1)
|
|
54
|
+
|
|
55
|
+
pno = pdf.get_page
|
|
56
|
+
assert_equal pno, 2
|
|
57
|
+
|
|
58
|
+
y = pdf.get_y
|
|
59
|
+
assert_in_delta 40.0, y, 0.1
|
|
60
|
+
|
|
61
|
+
no = pdf.get_num_pages
|
|
62
|
+
assert_equal no, 2
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class RbpdfTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
test "Image basic func extension test" do
|
|
6
|
+
pdf = RBPDF.new
|
|
7
|
+
|
|
8
|
+
type = pdf.get_image_file_type("/tmp/rbpdf_logo.gif")
|
|
9
|
+
assert_equal type, "gif"
|
|
10
|
+
|
|
11
|
+
type = pdf.get_image_file_type("/tmp/rbpdf_logo.PNG")
|
|
12
|
+
assert_equal type, "png"
|
|
13
|
+
|
|
14
|
+
type = pdf.get_image_file_type("/tmp/rbpdf_logo.jpg")
|
|
15
|
+
assert_equal type, "jpeg"
|
|
16
|
+
|
|
17
|
+
type = pdf.get_image_file_type("/tmp/rbpdf_logo.jpeg")
|
|
18
|
+
assert_equal type, "jpeg"
|
|
19
|
+
|
|
20
|
+
type = pdf.get_image_file_type("/tmp/rbpdf_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 = RBPDF.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/rbpdf_logo.gif', {'mime' => 'image/png'})
|
|
43
|
+
assert_equal type, 'png'
|
|
44
|
+
|
|
45
|
+
type = pdf.get_image_file_type('/tmp/rbpdf_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
|
+
|
|
55
|
+
test "Image basic filename test" do
|
|
56
|
+
pdf = RBPDF.new
|
|
57
|
+
err = assert_raises(RuntimeError) {
|
|
58
|
+
pdf.image(nil)
|
|
59
|
+
}
|
|
60
|
+
assert_equal( err.message, 'RBPDF error: Image filename is empty.')
|
|
61
|
+
|
|
62
|
+
err = assert_raises(RuntimeError) {
|
|
63
|
+
pdf.image('')
|
|
64
|
+
}
|
|
65
|
+
assert_equal( err.message, 'RBPDF error: Image filename is empty.')
|
|
66
|
+
|
|
67
|
+
err = assert_raises(RuntimeError) {
|
|
68
|
+
pdf.image('foo.png')
|
|
69
|
+
}
|
|
70
|
+
assert_equal( err.message, 'RBPDF error: Missing image file: foo.png')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test "Image basic test" do
|
|
74
|
+
pdf = RBPDF.new
|
|
75
|
+
pdf.add_page
|
|
76
|
+
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
|
|
77
|
+
|
|
78
|
+
result_img = pdf.image(img_file, 50, 0, 0, '', '', '', '', false, 300, '', true)
|
|
79
|
+
|
|
80
|
+
no = pdf.get_num_pages
|
|
81
|
+
assert_equal no, 1
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
test "Image fitonpage test 1" do
|
|
85
|
+
pdf = RBPDF.new
|
|
86
|
+
pdf.add_page
|
|
87
|
+
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
|
|
88
|
+
|
|
89
|
+
result_img = pdf.image(img_file, 50, 140, 100, '', '', '', '', false, 300, '', true, false, 0, false, false, true)
|
|
90
|
+
|
|
91
|
+
no = pdf.get_num_pages
|
|
92
|
+
assert_equal no, 1
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
test "Image fitonpage test 2" do
|
|
96
|
+
pdf = RBPDF.new
|
|
97
|
+
pdf.add_page
|
|
98
|
+
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
|
|
99
|
+
|
|
100
|
+
y = 100
|
|
101
|
+
w = pdf.get_page_width * 2
|
|
102
|
+
h = pdf.get_page_height
|
|
103
|
+
result_img = pdf.image(img_file, '', y, w, h, '', '', '', false, 300, '', true, false, 0, false, false, true)
|
|
104
|
+
|
|
105
|
+
no = pdf.get_num_pages
|
|
106
|
+
assert_equal no, 1
|
|
107
|
+
end
|
|
108
|
+
end
|
data/test/rbpdf_test.rb
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class RbpdfTest < ActiveSupport::TestCase
|
|
4
|
+
class MYPDF < RBPDF
|
|
5
|
+
def getPageBuffer(page)
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "set_x potision" do
|
|
11
|
+
pdf = RBPDF.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 = RBPDF.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 = RBPDF.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 = RBPDF.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 = RBPDF.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 = RBPDF.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 RbpdfTest < ActiveSupport::TestCase
|
|
4
|
+
class MYPDF < RBPDF
|
|
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
|