rbpdf 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/logo_example.png
ADDED
Binary file
|
data/rbpdf.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
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"
|
8
|
+
spec.version = Rbpdf::VERSION
|
9
|
+
spec.authors = ["NAITOH Jun"]
|
10
|
+
spec.email = ["naitoh@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("lib/fonts/*.{rb,z}") +
|
19
|
+
Dir.glob("lib/fonts/freefont-*/*") +
|
20
|
+
Dir.glob("lib/fonts/dejavu-fonts-ttf-*/{AUTHORS,BUGS,LICENSE,NEWS,README}") +
|
21
|
+
Dir.glob("test/*") +
|
22
|
+
["Rakefile", "rbpdf.gemspec", "Gemfile",
|
23
|
+
"CHANGELOG", "test_unicode.rbpdf", "README.md",
|
24
|
+
"utf8test.txt", "logo_example.png" ]
|
25
|
+
spec.rdoc_options += [ '--exclude', 'lib/fonts/',
|
26
|
+
'--exclude', 'lib/htmlcolors.rb',
|
27
|
+
'--exclude', 'lib/unicode_data.rb' ]
|
28
|
+
|
29
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
30
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
34
|
+
spec.add_development_dependency "rake"
|
35
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# coding: ASCII-8BIT
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class RbpdfTest < ActiveSupport::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
|
+
end
|
13
|
+
|
14
|
+
test "Bidi" do
|
15
|
+
pdf = MYPDF.new
|
16
|
+
|
17
|
+
# UCS4 charactor -> UTF-8 charactor
|
18
|
+
utf8_chr = pdf.unichr(0x61)
|
19
|
+
assert_equal "a", utf8_chr
|
20
|
+
utf8_chr = pdf.unichr(0x5e2)
|
21
|
+
assert_equal "\xd7\xa2", utf8_chr
|
22
|
+
|
23
|
+
# UTF-8 string -> array of UCS4 charactor
|
24
|
+
ary_ucs4 = pdf.UTF8StringToArray("abc")
|
25
|
+
assert_equal [0x61, 0x62, 0x63], ary_ucs4
|
26
|
+
ary_ucs4 = pdf.UTF8StringToArray("\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa")
|
27
|
+
assert_equal [0x5e2, 0x5d1, 0x5e8, 0x5d9, 0x5ea], ary_ucs4
|
28
|
+
|
29
|
+
# Bidirectional Algorithm
|
30
|
+
ascii_str = "abc"
|
31
|
+
utf8_str_1 = "\xd7\xa2"
|
32
|
+
utf8_str_2 = "\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa"
|
33
|
+
|
34
|
+
ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str))
|
35
|
+
assert_equal [0x61, 0x62, 0x63], ary_ucs4
|
36
|
+
ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str), ascii_str, 'R')
|
37
|
+
assert_equal [0x61, 0x62, 0x63], ary_ucs4
|
38
|
+
|
39
|
+
ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_1))
|
40
|
+
assert_equal [0x5e2], ary_ucs4
|
41
|
+
ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_1), utf8_str_1, 'R')
|
42
|
+
assert_equal [0x5e2], ary_ucs4
|
43
|
+
|
44
|
+
ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2))
|
45
|
+
assert_equal [0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_ucs4
|
46
|
+
ary_ucs4 = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2), utf8_str_2, 'R')
|
47
|
+
assert_equal [0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_ucs4 ##
|
48
|
+
|
49
|
+
ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str + utf8_str_2), ascii_str + utf8_str_2, 'L')
|
50
|
+
assert_equal [0x61, 0x62, 0x63, 0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_str
|
51
|
+
ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str + utf8_str_2)) # LTR
|
52
|
+
assert_equal [0x61, 0x62, 0x63, 0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_str
|
53
|
+
ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(ascii_str + utf8_str_2), ascii_str + utf8_str_2, 'R')
|
54
|
+
|
55
|
+
assert_equal [0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2, 0x61, 0x62, 0x63], ary_str
|
56
|
+
|
57
|
+
ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2 + ascii_str), utf8_str_2 + ascii_str, 'L')
|
58
|
+
assert_equal [0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2, 0x61, 0x62, 0x63], ary_str
|
59
|
+
ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2 + ascii_str)) # RTL
|
60
|
+
assert_equal [0x61, 0x62, 0x63, 0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_str
|
61
|
+
ary_str = pdf.utf8Bidi(pdf.UTF8StringToArray(utf8_str_2 + ascii_str), utf8_str_2 + ascii_str, 'R')
|
62
|
+
assert_equal [0x61, 0x62, 0x63, 0x5ea, 0x5d9, 0x5e8, 0x5d1, 0x5e2], ary_str
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RbpdfTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "bookmark test" do
|
6
|
+
pdf = RBPDF.new
|
7
|
+
pdf.add_page()
|
8
|
+
|
9
|
+
book = pdf.bookmark('Chapter 1', 0, 0)
|
10
|
+
assert_equal book, [{:l=>0, :y=>0, :t=>"Chapter 1", :p=>1}]
|
11
|
+
|
12
|
+
book = pdf.bookmark('Paragraph 1.1', 1, 0)
|
13
|
+
assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
|
14
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1}]
|
15
|
+
|
16
|
+
pdf.add_page()
|
17
|
+
|
18
|
+
book = pdf.bookmark('Paragraph 1.2', 1, 0)
|
19
|
+
assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
|
20
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
|
21
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2}]
|
22
|
+
|
23
|
+
book = pdf.bookmark('Sub-Paragraph 1.2.1', 2, 10)
|
24
|
+
assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
|
25
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
|
26
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
|
27
|
+
{:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2}]
|
28
|
+
|
29
|
+
pdf.add_page()
|
30
|
+
|
31
|
+
book = pdf.bookmark('Paragraph 1.3', 1, 0)
|
32
|
+
assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
|
33
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
|
34
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
|
35
|
+
{:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
|
36
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3}]
|
37
|
+
|
38
|
+
book = pdf.bookmark('Sub-Paragraph 1.1.1', 2, 0, 2)
|
39
|
+
assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
|
40
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
|
41
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
|
42
|
+
{:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
|
43
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3},
|
44
|
+
{:y=>0, :l=>2, :t=>"Sub-Paragraph 1.1.1", :p=>2}]
|
45
|
+
|
46
|
+
pdf.add_page()
|
47
|
+
|
48
|
+
book = pdf.bookmark('Paragraph 1.4', 1, 20)
|
49
|
+
assert_equal book, [{:y=>0, :l=>0, :t=>"Chapter 1", :p=>1},
|
50
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.1", :p=>1},
|
51
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.2", :p=>2},
|
52
|
+
{:y=>10, :l=>2, :t=>"Sub-Paragraph 1.2.1", :p=>2},
|
53
|
+
{:y=>0, :l=>1, :t=>"Paragraph 1.3", :p=>3},
|
54
|
+
{:y=>0, :l=>2, :t=>"Sub-Paragraph 1.1.1", :p=>2},
|
55
|
+
{:y=>20, :l=>1, :t=>"Paragraph 1.4", :p=>4}]
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RbpdfTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
class MYPDF < RBPDF
|
6
|
+
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')
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
test "getCellCode" do
|
12
|
+
pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
13
|
+
pdf.add_page()
|
14
|
+
code = pdf.getCellCode(10)
|
15
|
+
assert_equal code, "0.57 w 0 J 0 j [] 0 d 0 G 0 g\n"
|
16
|
+
# 0.57 w 0 J 0 j [] 0 d 0 G 0 rg # getCellCode
|
17
|
+
end
|
18
|
+
|
19
|
+
test "getCellCode link url align test" do
|
20
|
+
pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
21
|
+
pdf.add_page()
|
22
|
+
content = []
|
23
|
+
contents = pdf.getCellCode(10, 10, 'abc', 'LTRB', 0, '', 0, 'http://example.com')
|
24
|
+
contents.each_line {|line| content.push line.chomp }
|
25
|
+
|
26
|
+
assert_equal content.length, 2
|
27
|
+
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"
|
28
|
+
# 28.35 813.82 m 28.35 784.91 l S
|
29
|
+
# 28.07 813.54 m 56.98 813.54 l S
|
30
|
+
# 56.70 813.82 m 56.70 784.91 l S
|
31
|
+
# 28.07 785.19 m 56.98 785.19 l S
|
32
|
+
# BT
|
33
|
+
# 31.19 795.17 Td
|
34
|
+
# 0 Tr 0.00 w
|
35
|
+
# [(abc)] TJ
|
36
|
+
# ET
|
37
|
+
end
|
38
|
+
|
39
|
+
test "getCellCode link page test" do
|
40
|
+
pdf = MYPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
41
|
+
pdf.add_page()
|
42
|
+
content = []
|
43
|
+
contents = pdf.getCellCode(10, 10, 'abc', 0, 0, '', 0, 1)
|
44
|
+
contents.each_line {|line| content.push line.chomp }
|
45
|
+
|
46
|
+
assert_equal content.length, 2
|
47
|
+
assert_equal content[1], "BT 31.19 795.17 Td 0 Tr 0.00 w [(abc)] TJ ET"
|
48
|
+
# BT
|
49
|
+
# 31.19 795.17 Td
|
50
|
+
# 0 Tr 0.00 w
|
51
|
+
# [(abc)] TJ
|
52
|
+
# ET
|
53
|
+
end
|
54
|
+
|
55
|
+
test "getStringHeight Basic test" do
|
56
|
+
pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
57
|
+
pdf.add_page
|
58
|
+
|
59
|
+
txt = 'abcdefg'
|
60
|
+
|
61
|
+
w = 50
|
62
|
+
y1 = pdf.get_y
|
63
|
+
pdf.multi_cell(w, 0, txt)
|
64
|
+
pno = pdf.get_page
|
65
|
+
assert_equal pno, 1
|
66
|
+
y2 = pdf.get_y
|
67
|
+
h1 = y2 - y1
|
68
|
+
|
69
|
+
h2 = pdf.getStringHeight(w, txt)
|
70
|
+
assert_in_delta h1, h2, 0.01
|
71
|
+
|
72
|
+
line = pdf.get_num_lines(txt, w)
|
73
|
+
assert_equal line, 1
|
74
|
+
|
75
|
+
w = 20
|
76
|
+
y1 = pdf.get_y
|
77
|
+
pdf.multi_cell(w, 0, txt)
|
78
|
+
pno = pdf.get_page
|
79
|
+
assert_equal pno, 1
|
80
|
+
y2 = pdf.get_y
|
81
|
+
h1 = y2 - y1
|
82
|
+
|
83
|
+
h2 = pdf.getStringHeight(w, txt)
|
84
|
+
assert_in_delta h1, h2, 0.01
|
85
|
+
|
86
|
+
line = pdf.get_num_lines(txt, w)
|
87
|
+
assert_equal line, 1
|
88
|
+
end
|
89
|
+
|
90
|
+
test "getStringHeight Line Break test" do
|
91
|
+
pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
92
|
+
pdf.add_page
|
93
|
+
|
94
|
+
txt = 'abcdefg'
|
95
|
+
|
96
|
+
w = 10
|
97
|
+
y1 = pdf.get_y
|
98
|
+
pdf.multi_cell(w, 0, txt)
|
99
|
+
pno = pdf.get_page
|
100
|
+
assert_equal pno, 1
|
101
|
+
y2 = pdf.get_y
|
102
|
+
h1 = y2 - y1
|
103
|
+
|
104
|
+
h2 = pdf.getStringHeight(w, txt)
|
105
|
+
assert_in_delta h1, h2, 0.01
|
106
|
+
|
107
|
+
line = pdf.get_num_lines(txt, w)
|
108
|
+
assert_equal line, 3
|
109
|
+
|
110
|
+
|
111
|
+
w = 5
|
112
|
+
y1 = pdf.get_y
|
113
|
+
pdf.multi_cell(w, 0, txt)
|
114
|
+
pno = pdf.get_page
|
115
|
+
assert_equal pno, 1
|
116
|
+
y2 = pdf.get_y
|
117
|
+
h1 = y2 - y1
|
118
|
+
|
119
|
+
h2 = pdf.getStringHeight(w, txt)
|
120
|
+
assert_in_delta h1, h2, 0.01
|
121
|
+
|
122
|
+
line = pdf.get_num_lines(txt, w)
|
123
|
+
assert_equal line, 7
|
124
|
+
end
|
125
|
+
|
126
|
+
test "getStringHeight Minimum Width test 1" do
|
127
|
+
pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
128
|
+
pdf.add_page
|
129
|
+
|
130
|
+
w = pdf.get_string_width('OO')
|
131
|
+
|
132
|
+
txt = "Export to PDF: align is Good."
|
133
|
+
|
134
|
+
y1 = pdf.get_y
|
135
|
+
pdf.multi_cell(w, 0, txt)
|
136
|
+
pno = pdf.get_page
|
137
|
+
assert_equal pno, 1
|
138
|
+
y2 = pdf.get_y
|
139
|
+
h1 = y2 - y1
|
140
|
+
|
141
|
+
h2 = pdf.getStringHeight(w, txt)
|
142
|
+
assert_in_delta h1, h2, 0.01
|
143
|
+
|
144
|
+
line = pdf.get_num_lines(txt, w)
|
145
|
+
assert_equal line, 16
|
146
|
+
end
|
147
|
+
|
148
|
+
test "getStringHeight Minimum Width test 2" do
|
149
|
+
pdf = RBPDF.new('L', 'mm', 'A4', true, "UTF-8", true)
|
150
|
+
pdf.set_font('kozminproregular', '', 8)
|
151
|
+
pdf.add_page
|
152
|
+
|
153
|
+
margins = pdf.get_margins
|
154
|
+
w = pdf.get_string_width('20') + margins['cell'] * 2
|
155
|
+
|
156
|
+
txt = "20"
|
157
|
+
|
158
|
+
y1 = pdf.get_y
|
159
|
+
pdf.multi_cell(w, 0, txt)
|
160
|
+
pno = pdf.get_page
|
161
|
+
assert_equal pno, 1
|
162
|
+
y2 = pdf.get_y
|
163
|
+
h1 = y2 - y1
|
164
|
+
|
165
|
+
h2 = pdf.getStringHeight(w, txt)
|
166
|
+
assert_in_delta h1, h2, 0.01
|
167
|
+
|
168
|
+
line = pdf.get_num_lines(txt, w)
|
169
|
+
assert_equal line, 2
|
170
|
+
end
|
171
|
+
|
172
|
+
test "getStringHeight Minimum Bidi test 1" do
|
173
|
+
pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
174
|
+
pdf.add_page
|
175
|
+
|
176
|
+
w = pdf.get_string_width('OO')
|
177
|
+
|
178
|
+
txt = "\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa"
|
179
|
+
y1 = pdf.get_y
|
180
|
+
pdf.multi_cell(w, 0, txt)
|
181
|
+
pno = pdf.get_page
|
182
|
+
assert_equal pno, 1
|
183
|
+
y2 = pdf.get_y
|
184
|
+
h1 = y2 - y1
|
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, 5
|
190
|
+
|
191
|
+
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"
|
192
|
+
|
193
|
+
y1 = pdf.get_y
|
194
|
+
pdf.multi_cell(w, 0, txt)
|
195
|
+
pno = pdf.get_page
|
196
|
+
assert_equal pno, 1
|
197
|
+
y2 = pdf.get_y
|
198
|
+
h1 = y2 - y1
|
199
|
+
|
200
|
+
h2 = pdf.getStringHeight(w, txt)
|
201
|
+
assert_in_delta h1, h2, 0.01
|
202
|
+
|
203
|
+
line = pdf.get_num_lines(txt, w)
|
204
|
+
assert_equal line, 41
|
205
|
+
end
|
206
|
+
|
207
|
+
test "getStringHeight Minimum Bidi test 2" do
|
208
|
+
pdf = RBPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
209
|
+
pdf.set_font('freesans', '')
|
210
|
+
pdf.set_rtl(true)
|
211
|
+
pdf.set_temp_rtl('R')
|
212
|
+
pdf.add_page
|
213
|
+
|
214
|
+
margins = pdf.get_margins
|
215
|
+
w = pdf.get_string_width('OO') + margins['cell'] * 2
|
216
|
+
|
217
|
+
txt = "\xd7\x9c 000"
|
218
|
+
|
219
|
+
y1 = pdf.get_y
|
220
|
+
pdf.multi_cell(w, 0, txt)
|
221
|
+
pno = pdf.get_page
|
222
|
+
assert_equal pno, 1
|
223
|
+
y2 = pdf.get_y
|
224
|
+
h1 = y2 - y1
|
225
|
+
|
226
|
+
h2 = pdf.getStringHeight(w, txt)
|
227
|
+
assert_in_delta h1, h2, 0.01
|
228
|
+
|
229
|
+
line = pdf.get_num_lines(txt, w)
|
230
|
+
assert_equal line, 3
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RbpdfPageTest < ActiveSupport::TestCase
|
4
|
+
class MYPDF < RBPDF
|
5
|
+
def getPageBuffer(page)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
test "Basic Page content test" do
|
11
|
+
pdf = MYPDF.new
|
12
|
+
|
13
|
+
page = pdf.get_page
|
14
|
+
assert_equal 0, page
|
15
|
+
|
16
|
+
width = pdf.get_page_width
|
17
|
+
|
18
|
+
pdf.set_print_header(false)
|
19
|
+
pdf.add_page
|
20
|
+
page = pdf.get_page
|
21
|
+
assert_equal 1, page
|
22
|
+
|
23
|
+
content = []
|
24
|
+
contents = pdf.getPageBuffer(page)
|
25
|
+
contents.each_line {|line| content.push line.chomp }
|
26
|
+
|
27
|
+
assert_equal content.length, 4
|
28
|
+
assert_equal content[0], "0.57 w 0 J 0 j [] 0 d 0 G 0 g"
|
29
|
+
assert_equal content[1], "BT /F1 12.00 Tf ET "
|
30
|
+
assert_equal content[2], "0.57 w 0 J 0 j [] 0 d 0 G 0 g"
|
31
|
+
assert_equal content[3], "BT /F1 12.00 Tf ET "
|
32
|
+
|
33
|
+
##################################
|
34
|
+
# 0.57 w 0 J 0 j [] 0 d 0 G 0 g # add_page,start_page,setGraphicVars(set_fill_color)
|
35
|
+
# BT /F1 12.00 Tf ET #
|
36
|
+
# 0.57 w 0 J 0 j [] 0 d 0 G 0 g #
|
37
|
+
# BT /F1 12.00 Tf ET #
|
38
|
+
##################################
|
39
|
+
# 0.57 w # @linestyle_width : Line width.
|
40
|
+
# 0 J # @linestyle_cap : Type of cap to put on the line. [butt:0, round:1, square:2]
|
41
|
+
# 0 j # @linestyle_join : Type of join. [miter:0, round:1, bevel:2]
|
42
|
+
# [] 0 d # @linestyle_dash : Line dash pattern. (see set_line_style)
|
43
|
+
# 0 G # @draw_color : Drawing color. (see set_draw_color)
|
44
|
+
# 0 g # Set colors
|
45
|
+
########################
|
46
|
+
# BT # Begin Text.
|
47
|
+
# /F1 12.00 Tf # 12.00 point size font.
|
48
|
+
# ET # End Text.
|
49
|
+
########################
|
50
|
+
|
51
|
+
pdf.set_font('freesans', 'BI', 18)
|
52
|
+
content = []
|
53
|
+
contents = pdf.getPageBuffer(page)
|
54
|
+
contents.each_line {|line| content.push line.chomp }
|
55
|
+
|
56
|
+
assert_equal content.length, 5
|
57
|
+
assert_equal content[4], "BT /F2 18.00 Tf ET "
|
58
|
+
|
59
|
+
########################
|
60
|
+
# BT # Begin Text.
|
61
|
+
# /F2 18.00 Tf # 18.00 point size font.
|
62
|
+
# ET # End Text.
|
63
|
+
########################
|
64
|
+
pdf.set_font('freesans', 'B', 20)
|
65
|
+
content = []
|
66
|
+
contents = pdf.getPageBuffer(page)
|
67
|
+
contents.each_line {|line| content.push line.chomp }
|
68
|
+
|
69
|
+
assert_equal content.length, 6
|
70
|
+
assert_equal content[5], "BT /F3 20.00 Tf ET "
|
71
|
+
|
72
|
+
pdf.cell(0, 10, 'Chapter', 0, 1, 'L')
|
73
|
+
content = []
|
74
|
+
contents = pdf.getPageBuffer(page)
|
75
|
+
contents.each_line {|line| content.push line.chomp }
|
76
|
+
|
77
|
+
assert_equal content.length, 8
|
78
|
+
assert_equal content[6], "0.57 w 0 J 0 j [] 0 d 0 G 0 g"
|
79
|
+
|
80
|
+
assert_equal content[7], "BT 31.19 792.37 Td 0 Tr 0.00 w [(\x00C\x00h\x00a\x00p\x00t\x00e\x00r)] TJ ET"
|
81
|
+
|
82
|
+
#################################################
|
83
|
+
# 0.57 w 0 J 0 j [] 0 d 0 G 0 g # getCellCode
|
84
|
+
# BT
|
85
|
+
# 31.19 792.37 Td # Set text offset.
|
86
|
+
# 0 Tr 0.00 w # Set stroke outline and clipping mode
|
87
|
+
# [(\x00C\x00h\x00a\x00p\x00t\x00e\x00r)] TJ # Write array of characters.
|
88
|
+
# ET
|
89
|
+
#################################################
|
90
|
+
end
|
91
|
+
|
92
|
+
test "circle content" do
|
93
|
+
pdf = MYPDF.new
|
94
|
+
|
95
|
+
pdf.set_print_header(false)
|
96
|
+
pdf.add_page
|
97
|
+
pdf.circle(100, 200, 50)
|
98
|
+
content = []
|
99
|
+
contents = pdf.getPageBuffer(1)
|
100
|
+
contents.each_line {|line| content.push line.chomp }
|
101
|
+
|
102
|
+
assert_equal content.length, 15
|
103
|
+
assert_equal content[4], "425.20 274.96 m" # start point : x0, y0
|
104
|
+
|
105
|
+
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)
|
106
|
+
assert_equal content[6], '370.62 391.58 340.88 408.76 308.08 414.54 c' # 2/9 circle
|
107
|
+
assert_equal content[7], '275.27 420.32 241.45 414.36 212.60 397.70 c' # 3/9 circle
|
108
|
+
assert_equal content[8], '183.75 381.05 161.67 354.74 150.28 323.44 c' # 4/9 circle
|
109
|
+
assert_equal content[9], '138.89 292.13 138.89 257.79 150.28 226.49 c' # 5/9 circle
|
110
|
+
assert_equal content[10], '161.67 195.18 183.75 168.87 212.60 152.22 c' # 6/9 circle
|
111
|
+
assert_equal content[11], '241.45 135.56 275.27 129.60 308.08 135.38 c' # 7/9 circle
|
112
|
+
assert_equal content[12], '340.88 141.17 370.62 158.34 392.04 183.86 c' # 8/9 circle
|
113
|
+
assert_equal content[13], '413.45 209.38 425.20 241.65 425.20 274.96 c' # 9/9 circle
|
114
|
+
assert_equal content[14], 'S'
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|