# Copyright (c) 2011-2017 NAITOH Jun
# Released under the MIT license
# http://www.opensource.org/licenses/MIT
require 'test_helper'
class RbpdfTest < Test::Unit::TestCase
test "anchor with text inside" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = 'HTML Example'
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal [1, 10.001249999999999], position
end
test "anchor with id" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = 'HTML Example'
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal [1, 10.001249999999999], position
end
test "empty anchor" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = ''
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal [1, 10.001249999999999], position
end
test "anchor with overtical offset" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '
'
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal [1, 57.626249999999985], position
end
test "on the second page" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = '1
2
3
4
5
6
7
8
9
10
11
'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = ''
pdf.write_html(htmlcontent, true, 0, true, 0)
position = pdf.get_html_anchor_position('foo')
assert_equal [3, 68.20958333333331], position
end
test "maps when anchor after link" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = 'FooLink'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = '1
2
3
4
5
6
7
8
9
10
11
'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = ''
pdf.write_html(htmlcontent, true, 0, true, 0)
pdf.send(:mapLinksToHtmlAnchors)
link_position = pdf.instance_variable_get(:@links)[0]
assert_equal [3, 73.50124999999998], link_position
end
test "maps when anchor before link" do
pdf = RBPDF.new
pdf.add_page()
htmlcontent = ''
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = '1
2
3
4
5
6
7
8
9
10
11
'
pdf.write_html(htmlcontent, true, 0, true, 0)
htmlcontent = 'FooLink'
pdf.write_html(htmlcontent, true, 0, true, 0)
pdf.send(:mapLinksToHtmlAnchors)
link_position = pdf.instance_variable_get(:@links)[0]
assert_equal [1, 10.001249999999999], link_position
end
end