rbpdf 1.18.2 → 1.18.3
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 +4 -4
- data/CHANGELOG +11 -0
- data/LICENSE.TXT +504 -0
- data/README.md +3 -3
- data/lib/rbpdf.rb +56 -25
- data/lib/rbpdf/version.rb +1 -1
- data/rbpdf.gemspec +1 -1
- data/test/rbpdf_bidi_test.rb +66 -0
- data/test/rbpdf_cell_test.rb +14 -0
- data/test/rbpdf_css_test.rb +43 -0
- data/test/rbpdf_dom_test.rb +63 -0
- data/test/rbpdf_font_func_test.rb +14 -0
- data/test/rbpdf_func_test.rb +9 -0
- data/test/rbpdf_html_func_test.rb +136 -0
- data/test/rbpdf_test.rb +37 -0
- data/test/rbpdf_write_test.rb +53 -0
- metadata +5 -2
data/test/rbpdf_dom_test.rb
CHANGED
|
@@ -114,6 +114,60 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
114
114
|
assert_equal dom[3]['width'], '10'
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
+
test "Dom self close tag test" do
|
|
118
|
+
pdf = MYPDF.new
|
|
119
|
+
|
|
120
|
+
# Simple Tag
|
|
121
|
+
dom = pdf.getHtmlDomArray('<b>ab<br>c</b>')
|
|
122
|
+
assert_equal dom.length, 6
|
|
123
|
+
|
|
124
|
+
assert_equal 0, dom[0]['parent'] # Root
|
|
125
|
+
assert_equal false, dom[0]['tag']
|
|
126
|
+
assert_equal({}, dom[0]['attribute'])
|
|
127
|
+
|
|
128
|
+
# <b>
|
|
129
|
+
assert_equal dom[1]['parent'], 0 # parent -> parent tag key
|
|
130
|
+
assert_equal dom[1]['elkey'], 0
|
|
131
|
+
assert_equal dom[1]['tag'], true
|
|
132
|
+
assert_equal dom[1]['opening'], true
|
|
133
|
+
assert_equal dom[1]['value'], 'b'
|
|
134
|
+
assert_equal dom[1]['attribute'], {}
|
|
135
|
+
|
|
136
|
+
# ab
|
|
137
|
+
assert_equal({'tag' => false, 'value'=>'ab', 'elkey'=>1, 'parent'=>1, 'block'=>false}, dom[2]) # parent -> open tag key
|
|
138
|
+
|
|
139
|
+
# <br>
|
|
140
|
+
assert_equal dom[3]['parent'], 1 # parent -> open tag key
|
|
141
|
+
assert_equal dom[3]['elkey'], 2
|
|
142
|
+
assert_equal dom[3]['tag'], true
|
|
143
|
+
assert_equal dom[3]['opening'], true
|
|
144
|
+
assert_equal dom[3]['value'], 'br'
|
|
145
|
+
assert_equal dom[3]['attribute'], {}
|
|
146
|
+
|
|
147
|
+
# c
|
|
148
|
+
assert_equal({'tag' => false, 'value'=>'c', 'elkey'=>3, 'parent'=>1, 'block'=>false}, dom[4]) # parent -> open tag key
|
|
149
|
+
|
|
150
|
+
# </b>
|
|
151
|
+
assert_equal dom[5]['parent'], 1 # parent -> open tag key
|
|
152
|
+
assert_equal dom[5]['elkey'], 4
|
|
153
|
+
assert_equal dom[5]['tag'], true
|
|
154
|
+
assert_equal dom[5]['opening'], false
|
|
155
|
+
assert_equal dom[5]['value'], 'b'
|
|
156
|
+
|
|
157
|
+
dom2 = pdf.getHtmlDomArray('<b>ab<br/>c</b>')
|
|
158
|
+
assert_equal dom, dom2
|
|
159
|
+
|
|
160
|
+
htmlcontent = '<b><img src="' + Rails.root.to_s + '/public/ng.png" alt="test alt attribute" width="30" height="30" border="0"/></b>'
|
|
161
|
+
dom1 = pdf.getHtmlDomArray(htmlcontent)
|
|
162
|
+
htmlcontent = '<b><img src="' + Rails.root.to_s + '/public/ng.png" alt="test alt attribute" width="30" height="30" border="0"></b>'
|
|
163
|
+
dom2 = pdf.getHtmlDomArray(htmlcontent)
|
|
164
|
+
assert_equal dom1, dom2
|
|
165
|
+
|
|
166
|
+
dom1 = pdf.getHtmlDomArray('<b>ab<hr/>c</b>')
|
|
167
|
+
dom2 = pdf.getHtmlDomArray('<b>ab<hr>c</b>')
|
|
168
|
+
assert_equal dom1, dom2
|
|
169
|
+
end
|
|
170
|
+
|
|
117
171
|
test "Dom HTMLTagHandler Basic test" do
|
|
118
172
|
pdf = MYPDF.new
|
|
119
173
|
pdf.add_page
|
|
@@ -139,4 +193,13 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
139
193
|
assert_equal dom1, dom2
|
|
140
194
|
assert_equal pdf.get_image_rby - (12 / pdf.get_scale_factor) , y2
|
|
141
195
|
end
|
|
196
|
+
|
|
197
|
+
test "getHtmlDomArray encoding test" do
|
|
198
|
+
return unless 'test'.respond_to?(:force_encoding)
|
|
199
|
+
|
|
200
|
+
pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
|
201
|
+
htmlcontent = 'test'.force_encoding('ASCII-8BIT')
|
|
202
|
+
dom = pdf.getHtmlDomArray(htmlcontent)
|
|
203
|
+
assert_equal htmlcontent.encoding.to_s, 'ASCII-8BIT'
|
|
204
|
+
end
|
|
142
205
|
end
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class RbpdfFontFuncTest < ActiveSupport::TestCase
|
|
4
|
+
class MYPDF < RBPDF
|
|
5
|
+
def putAPXObject(w=0, h=0, stream='')
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
end
|
|
4
9
|
test "Font get_font_descent function test 1" do
|
|
5
10
|
pdf = RBPDF.new
|
|
6
11
|
fontdescent = pdf.get_font_descent('times', '', 18)
|
|
@@ -24,4 +29,13 @@ class RbpdfFontFuncTest < ActiveSupport::TestCase
|
|
|
24
29
|
fontascent = pdf.get_font_ascent('freesans', '', 18)
|
|
25
30
|
assert_in_delta 6.35, fontascent, 0.01
|
|
26
31
|
end
|
|
32
|
+
|
|
33
|
+
test "putAPXObject test" do
|
|
34
|
+
pdf = MYPDF.new
|
|
35
|
+
|
|
36
|
+
apxo_obj_id = pdf.putAPXObject
|
|
37
|
+
assert_equal apxo_obj_id, 400001
|
|
38
|
+
apxo_obj_id = pdf.putAPXObject
|
|
39
|
+
assert_equal apxo_obj_id, 400002
|
|
40
|
+
end
|
|
27
41
|
end
|
data/test/rbpdf_func_test.rb
CHANGED
|
@@ -123,4 +123,13 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
123
123
|
pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '1,2,3,4', 'phase' => 0, 'color' => [255, 0, 0]})
|
|
124
124
|
pdf.set_line_style({'width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 'a', 'phase' => 0, 'color' => [255, 0, 0]}) # Invalid
|
|
125
125
|
end
|
|
126
|
+
|
|
127
|
+
test "get_string_width encoding test" do
|
|
128
|
+
return unless 'test'.respond_to?(:force_encoding)
|
|
129
|
+
|
|
130
|
+
pdf = RBPDF.new
|
|
131
|
+
str = 'test'.force_encoding('UTF-8')
|
|
132
|
+
width = pdf.get_string_width(str)
|
|
133
|
+
assert_equal str.encoding.to_s, 'UTF-8'
|
|
134
|
+
end
|
|
126
135
|
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class RbpdfTest < ActiveSupport::TestCase
|
|
4
|
+
class MYPDF < RBPDF
|
|
5
|
+
def addHTMLVertSpace(hbz, hb, cell, firstorlast)
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "html func addHTMLVertSpace empty lines test" do
|
|
11
|
+
pdf = MYPDF.new
|
|
12
|
+
pdf.add_page()
|
|
13
|
+
|
|
14
|
+
# same line, start position
|
|
15
|
+
x1 = pdf.get_x
|
|
16
|
+
pdf.set_x(x1 + 10)
|
|
17
|
+
y1 = pdf.get_y
|
|
18
|
+
pdf.addHTMLVertSpace(1, 0, false, true)
|
|
19
|
+
x2 = pdf.get_x
|
|
20
|
+
y2 = pdf.get_y
|
|
21
|
+
assert_equal x2, x1
|
|
22
|
+
assert_equal y2, y1
|
|
23
|
+
|
|
24
|
+
# same line, @c_margin position
|
|
25
|
+
margins = pdf.get_margins
|
|
26
|
+
|
|
27
|
+
x1 = pdf.get_x
|
|
28
|
+
y1 = pdf.get_y
|
|
29
|
+
pdf.addHTMLVertSpace(1, 0, true, true)
|
|
30
|
+
x2 = pdf.get_x
|
|
31
|
+
y2 = pdf.get_y
|
|
32
|
+
assert_equal x2, x1 + margins['cell']
|
|
33
|
+
assert_equal y2, y1
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test "html func addHTMLVertSpace add line test" do
|
|
37
|
+
pdf = MYPDF.new
|
|
38
|
+
pdf.add_page()
|
|
39
|
+
|
|
40
|
+
# next line, start position
|
|
41
|
+
x1 = pdf.get_x
|
|
42
|
+
pdf.set_x(x1 + 10)
|
|
43
|
+
y1 = pdf.get_y
|
|
44
|
+
pdf.addHTMLVertSpace(5, 0, false, false)
|
|
45
|
+
x2 = pdf.get_x
|
|
46
|
+
y2 = pdf.get_y
|
|
47
|
+
assert_equal x2, x1
|
|
48
|
+
assert_equal y2, y1 + 5
|
|
49
|
+
|
|
50
|
+
# next line, @c_margin position
|
|
51
|
+
margins = pdf.get_margins
|
|
52
|
+
|
|
53
|
+
x1 = pdf.get_x
|
|
54
|
+
y1 = pdf.get_y
|
|
55
|
+
pdf.addHTMLVertSpace(5, 0, true, false)
|
|
56
|
+
x2 = pdf.get_x
|
|
57
|
+
y2 = pdf.get_y
|
|
58
|
+
assert_equal x2, x1 + margins['cell']
|
|
59
|
+
assert_equal y2, y1 + 5
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test "html func addHTMLVertSpace height of the break test 1" do
|
|
63
|
+
pdf = MYPDF.new
|
|
64
|
+
pdf.add_page()
|
|
65
|
+
|
|
66
|
+
margins = pdf.get_margins
|
|
67
|
+
x1 = pdf.get_x
|
|
68
|
+
y1 = pdf.get_y
|
|
69
|
+
pdf.addHTMLVertSpace(0, 5, true, false) # height of the break : 5
|
|
70
|
+
x2 = pdf.get_x
|
|
71
|
+
y2 = pdf.get_y
|
|
72
|
+
assert_equal x2, x1 + margins['cell']
|
|
73
|
+
assert_equal y2, y1 + 5
|
|
74
|
+
|
|
75
|
+
pdf.addHTMLVertSpace(0, 5, true, false) # height of the break : 5
|
|
76
|
+
x3 = pdf.get_x
|
|
77
|
+
y3 = pdf.get_y
|
|
78
|
+
assert_equal x3, x2
|
|
79
|
+
assert_equal y3, y2
|
|
80
|
+
|
|
81
|
+
pdf.addHTMLVertSpace(0, 5 + 2, true, false) # height of the break : 7
|
|
82
|
+
x4 = pdf.get_x
|
|
83
|
+
y4 = pdf.get_y
|
|
84
|
+
assert_equal x4, x3
|
|
85
|
+
assert_equal y4, y3 + 2
|
|
86
|
+
|
|
87
|
+
pdf.addHTMLVertSpace(0, 5, true, false) # height of the break : 7
|
|
88
|
+
x5 = pdf.get_x
|
|
89
|
+
y5 = pdf.get_y
|
|
90
|
+
assert_equal x5, x4
|
|
91
|
+
assert_equal y5, y4
|
|
92
|
+
|
|
93
|
+
pdf.addHTMLVertSpace(0, 5 + 2 + 1, true, false) # height of the break : 8
|
|
94
|
+
x6 = pdf.get_x
|
|
95
|
+
y6 = pdf.get_y
|
|
96
|
+
assert_equal x6, x5
|
|
97
|
+
assert_equal y6, y5 + 1
|
|
98
|
+
|
|
99
|
+
pdf.addHTMLVertSpace(0, 10, true, true) # height of the break : 0 (reset)
|
|
100
|
+
x7 = pdf.get_x
|
|
101
|
+
y7 = pdf.get_y
|
|
102
|
+
assert_equal x7, x6
|
|
103
|
+
assert_equal y7, y6
|
|
104
|
+
|
|
105
|
+
pdf.addHTMLVertSpace(0, 2, true, false) # height of the break : 2
|
|
106
|
+
x8 = pdf.get_x
|
|
107
|
+
y8 = pdf.get_y
|
|
108
|
+
assert_equal x8, x7
|
|
109
|
+
assert_equal y8, y7 + 2
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
test "html func addHTMLVertSpace height of the break test 2" do
|
|
113
|
+
pdf = MYPDF.new
|
|
114
|
+
pdf.add_page()
|
|
115
|
+
|
|
116
|
+
x1 = pdf.get_x
|
|
117
|
+
y1 = pdf.get_y
|
|
118
|
+
pdf.addHTMLVertSpace(10, 5, false, false) # height of the break : 5
|
|
119
|
+
x2 = pdf.get_x
|
|
120
|
+
y2 = pdf.get_y
|
|
121
|
+
assert_equal x2, x1
|
|
122
|
+
assert_equal y2, y1 + 10 + 5
|
|
123
|
+
|
|
124
|
+
pdf.addHTMLVertSpace(10, 5, false, false) # height of the break : 5
|
|
125
|
+
x3 = pdf.get_x
|
|
126
|
+
y3 = pdf.get_y
|
|
127
|
+
assert_equal x3, x2
|
|
128
|
+
assert_equal y3, y2 + 10
|
|
129
|
+
|
|
130
|
+
pdf.addHTMLVertSpace(10, 5 + 2, false, false) # height of the break : 7
|
|
131
|
+
x4 = pdf.get_x
|
|
132
|
+
y4 = pdf.get_y
|
|
133
|
+
assert_equal x4, x3
|
|
134
|
+
assert_equal y4, y3 + 10 + 2
|
|
135
|
+
end
|
|
136
|
+
end
|
data/test/rbpdf_test.rb
CHANGED
|
@@ -242,4 +242,41 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
242
242
|
contents4 = pdf.getPageBuffer(2)
|
|
243
243
|
assert_equal contents4, false
|
|
244
244
|
end
|
|
245
|
+
|
|
246
|
+
test "start_page_group test" do
|
|
247
|
+
pdf = RBPDF.new
|
|
248
|
+
pdf.add_page
|
|
249
|
+
pdf.start_page_group
|
|
250
|
+
pdf.start_page_group(1)
|
|
251
|
+
pdf.start_page_group(nil)
|
|
252
|
+
pdf.start_page_group('')
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
test "get_page_dimensions test" do
|
|
256
|
+
pdf = RBPDF.new
|
|
257
|
+
pdf.add_page
|
|
258
|
+
|
|
259
|
+
pagedim = pdf.get_page_dimensions
|
|
260
|
+
assert_equal pagedim['CropBox']['llx'], 0.0
|
|
261
|
+
pagedim = pdf.get_page_dimensions(1)
|
|
262
|
+
assert_equal pagedim['CropBox']['llx'], 0.0
|
|
263
|
+
pagedim = pdf.get_page_dimensions(nil)
|
|
264
|
+
assert_equal pagedim['CropBox']['llx'], 0.0
|
|
265
|
+
pagedim = pdf.get_page_dimensions('')
|
|
266
|
+
assert_equal pagedim['CropBox']['llx'], 0.0
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
test "get_break_margin test" do
|
|
270
|
+
pdf = RBPDF.new
|
|
271
|
+
pdf.add_page
|
|
272
|
+
|
|
273
|
+
b_margin = pdf.get_break_margin
|
|
274
|
+
assert_in_delta b_margin, 20.0, 0.1
|
|
275
|
+
b_margin = pdf.get_break_margin(1)
|
|
276
|
+
assert_in_delta b_margin, 20.0, 0.1
|
|
277
|
+
b_margin = pdf.get_break_margin(nil)
|
|
278
|
+
assert_in_delta b_margin, 20.0, 0.1
|
|
279
|
+
b_margin = pdf.get_break_margin('')
|
|
280
|
+
assert_in_delta b_margin, 20.0, 0.1
|
|
281
|
+
end
|
|
245
282
|
end
|
data/test/rbpdf_write_test.rb
CHANGED
|
@@ -170,4 +170,57 @@ class RbpdfTest < ActiveSupport::TestCase
|
|
|
170
170
|
endlinex = pdf.endlinex()
|
|
171
171
|
assert_not_equal endlinex, x
|
|
172
172
|
end
|
|
173
|
+
|
|
174
|
+
test "write encoding test" do
|
|
175
|
+
return unless 'test'.respond_to?(:force_encoding)
|
|
176
|
+
|
|
177
|
+
pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
|
178
|
+
str = 'test'.force_encoding('UTF-8')
|
|
179
|
+
width = pdf.write(0, str)
|
|
180
|
+
assert_equal str.encoding.to_s, 'UTF-8'
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
test "write Bidi arabic test" do
|
|
184
|
+
pdf = RBPDF.new
|
|
185
|
+
pdf.set_font('dejavusans', '', 18)
|
|
186
|
+
pdf.add_page
|
|
187
|
+
|
|
188
|
+
ascii_str = "role"
|
|
189
|
+
utf8_arabic_str_1 = "\xd8\xaf\xd9\x88\xd8\xb1"
|
|
190
|
+
|
|
191
|
+
line = pdf.write(0, ascii_str)
|
|
192
|
+
assert_equal line, 1
|
|
193
|
+
line = pdf.write(0, utf8_arabic_str_1)
|
|
194
|
+
assert_equal line, 1
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
test "write Bidi arabic set_rtl test" do
|
|
198
|
+
pdf = RBPDF.new
|
|
199
|
+
pdf.set_font('dejavusans', '', 18)
|
|
200
|
+
pdf.set_rtl(true)
|
|
201
|
+
pdf.add_page
|
|
202
|
+
|
|
203
|
+
ascii_str = "role"
|
|
204
|
+
utf8_arabic_str_1 = "\xd8\xaf\xd9\x88\xd8\xb1"
|
|
205
|
+
|
|
206
|
+
line = pdf.write(0, ascii_str)
|
|
207
|
+
assert_equal line, 1
|
|
208
|
+
line = pdf.write(0, utf8_arabic_str_1)
|
|
209
|
+
assert_equal line, 1
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
test "write Bidi arabic set_temp_rtl test" do
|
|
213
|
+
pdf = RBPDF.new
|
|
214
|
+
pdf.set_font('dejavusans', '', 18)
|
|
215
|
+
pdf.set_temp_rtl('rtl')
|
|
216
|
+
pdf.add_page
|
|
217
|
+
|
|
218
|
+
ascii_str = "role"
|
|
219
|
+
utf8_arabic_str_1 = "\xd8\xaf\xd9\x88\xd8\xb1"
|
|
220
|
+
|
|
221
|
+
line = pdf.write(0, ascii_str)
|
|
222
|
+
assert_equal line, 1
|
|
223
|
+
line = pdf.write(0, utf8_arabic_str_1)
|
|
224
|
+
assert_equal line, 1
|
|
225
|
+
end
|
|
173
226
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbpdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.18.
|
|
4
|
+
version: 1.18.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- NAITOH Jun
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -48,6 +48,7 @@ extra_rdoc_files: []
|
|
|
48
48
|
files:
|
|
49
49
|
- CHANGELOG
|
|
50
50
|
- Gemfile
|
|
51
|
+
- LICENSE.TXT
|
|
51
52
|
- README.md
|
|
52
53
|
- Rakefile
|
|
53
54
|
- lib/core/rmagick.rb
|
|
@@ -165,6 +166,7 @@ files:
|
|
|
165
166
|
- test/rbpdf_font_test.rb
|
|
166
167
|
- test/rbpdf_format_test.rb
|
|
167
168
|
- test/rbpdf_func_test.rb
|
|
169
|
+
- test/rbpdf_html_func_test.rb
|
|
168
170
|
- test/rbpdf_html_test.rb
|
|
169
171
|
- test/rbpdf_htmlcell_test.rb
|
|
170
172
|
- test/rbpdf_image_rmagick_test.rb
|
|
@@ -229,6 +231,7 @@ test_files:
|
|
|
229
231
|
- test/rbpdf_font_test.rb
|
|
230
232
|
- test/rbpdf_format_test.rb
|
|
231
233
|
- test/rbpdf_func_test.rb
|
|
234
|
+
- test/rbpdf_html_func_test.rb
|
|
232
235
|
- test/rbpdf_html_test.rb
|
|
233
236
|
- test/rbpdf_htmlcell_test.rb
|
|
234
237
|
- test/rbpdf_image_rmagick_test.rb
|