1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
require 'test_helper'
class RbpdfTest < Test::Unit::TestCase
class MYPDF < RBPDF
def getPageBuffer(page)
super
end
end
test "anchor with text inside" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '<a name="foo">HTML Example</a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal position, [1, 10.001249999999999]
end
test "anchor with id" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '<a id="foo">HTML Example</a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal position, [1, 10.001249999999999]
end
test "empty anchor" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '<a id="foo"></a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal position, [1, 10.001249999999999]
end
test "anchor with overtical offset" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '<br><br><br><br><br><br><br><br><br><br><a id="foo"></a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal position, [1, 57.626249999999985]
end
test "on the second page" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br><br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br><br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br><br><br><br><br><br><br><br><br>'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = '<a id="foo"></a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal position, [3, 68.20958333333331]
end
test "maps when anchor after link" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '<a href="#foo">FooLink</a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = '1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br><br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br><br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br><br><br><br><br><br><br><br><br>'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = '<a id="foo"></a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
pdf.send(:mapLinksToHtmlAnchors)
link_position = pdf.instance_variable_get(:@links)[1]
assert_equal link_position, [3, 73.50124999999998]
end
test "maps when anchor before link" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '<a id="foo"></a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = '1<br><br><br><br><br><br><br><br><br><br> 2<br><br><br><br><br><br><br><br><br><br> 3<br><br><br><br><br><br><br><br><br><br> 4<br><br><br><br><br><br><br><br><br><br> 5<br><br><br><br><br><br><br><br><br><br> 6<br><br><br><br><br><br><br><br><br><br> 7<br><br><br><br><br><br><br><br><br><br> 8<br><br><br><br><br><br><br><br><br><br> 9<br><br><br><br><br><br><br><br><br><br> 10<br><br><br><br><br><br><br><br><br><br> 11<br><br><br><br><br><br><br><br><br><br>'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = '<a href="#foo">FooLink</a>'
pdf.write_html(htmlcontent, true, 0, true, 0)
pdf.send(:mapLinksToHtmlAnchors)
link_position = pdf.instance_variable_get(:@links)[1]
assert_equal link_position, [1, 10.001249999999999]
end
end
|