File: rbpdf_annotation_test.rb

package info (click to toggle)
ruby-rbpdf 1.21.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,488 kB
  • sloc: ruby: 138,259; makefile: 12
file content (66 lines) | stat: -rw-r--r-- 2,489 bytes parent folder | download
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
# Copyright (c) 2011-2023 NAITOH Jun
# Released under the MIT license
# http://www.opensource.org/licenses/MIT

require 'test_helper'

class RbpdfTest < Test::Unit::TestCase
  test "Annotation Basic Test" do
    pdf = RBPDF.new

    x = pdf.get_x
    y = pdf.get_y
    w = 30, h = 40
    txt = "Text annotation \ntest"
    opt = {'Subtype'=>'Text', 'Name' => 'Comment', 'T' => 'title example', 'Subj' => 'example', 'C' => [255, 255, 0]}
    annot_obj_id_org = pdf.instance_variable_get('@annot_obj_id')
    pdf.annotation('', '', w, h, txt, opt)
    page_annots = pdf.instance_variable_get('@page_annots')

    assert_equal 2,   page_annots.length
    assert_equal nil, page_annots[0]
    assert_equal 1,   page_annots[1].length
    assert_equal 0,   page_annots[1][0]['numspaces']
    assert_equal x,   page_annots[1][0]['x']
    assert_equal y,   page_annots[1][0]['y']
    assert_equal w,   page_annots[1][0]['w']
    assert_equal h,   page_annots[1][0]['h']
    assert_equal opt, page_annots[1][0]['opt']
    assert_equal txt, page_annots[1][0]['txt']

    annot_obj_id = pdf.instance_variable_get('@annot_obj_id')
    assert_equal annot_obj_id_org + 1, annot_obj_id
  end

  test "Annotation FileAttachment Test" do
    pdf = RBPDF.new

    TEST_FILE_NAME = 'utf8test.txt'
    TEST_FILE_NAME_PATH = 'example/rails/public/' + TEST_FILE_NAME

    x = 80, y = 25, w = 20, h = 30
    txt = 'text file'
    opt = {'Subtype'=>'FileAttachment', 'Name' => 'PushPin', 'FS' => TEST_FILE_NAME_PATH}
    annot_obj_id_org = pdf.instance_variable_get('@annot_obj_id')
    embedded_start_obj_id = pdf.instance_variable_get('@embedded_start_obj_id')

    pdf.annotation(x, y, w, h, txt, opt)
    page_annots = pdf.instance_variable_get('@page_annots')

    assert_equal 2,   page_annots.length
    assert_equal nil, page_annots[0]
    assert_equal 1,   page_annots[1].length
    assert_equal 0,   page_annots[1][0]['numspaces']
    assert_equal x,   page_annots[1][0]['x']
    assert_equal y,   page_annots[1][0]['y']
    assert_equal w,   page_annots[1][0]['w']
    assert_equal h,   page_annots[1][0]['h']
    assert_equal opt, page_annots[1][0]['opt']
    assert_equal txt, page_annots[1][0]['txt']

    annot_obj_id = pdf.instance_variable_get('@annot_obj_id')
    assert_equal annot_obj_id_org + 1, annot_obj_id
    embeddedfiles = pdf.instance_variable_get('@embeddedfiles')
    assert_equal({TEST_FILE_NAME=>{"file"=>TEST_FILE_NAME_PATH, "n"=>embedded_start_obj_id}}, embeddedfiles)
  end
end