File: annotations_spec.rb

package info (click to toggle)
ruby-prawn 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,220 kB
  • ctags: 826
  • sloc: ruby: 14,469; sh: 43; makefile: 18
file content (67 lines) | stat: -rw-r--r-- 2,067 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
67
# encoding: utf-8

require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")

describe "When creating annotations" do
  before(:each) { create_pdf }

  it "should append annotation to current page" do
    @pdf.start_new_page
    @pdf.annotate(:Rect => [0, 0, 10, 10], :Subtype => :Text, :Contents => "Hello world!")
    PDF::Reader.open(StringIO.new(@pdf.render)) do |pdf|
      expect(pdf.page(1).attributes[:Annots]).to be_nil
      expect(pdf.page(2).attributes[:Annots].size).to eq(1)
    end
  end

  it "should force :Type to be :Annot" do
    opts = @pdf.annotate(:Rect => [0, 0, 10, 10], :Subtype => :Text, :Contents => "Hello world!")
    expect(opts[:Type]).to eq(:Annot)
    opts = @pdf.annotate(:Type => :Bogus, :Rect => [0, 0, 10, 10], :Subtype => :Text, :Contents => "Hello world!")
    expect(opts[:Type]).to eq(:Annot)
  end
end

describe "When creating text annotations" do
  before(:each) do
    @rect = [0, 0, 10, 10]
    @content = "Hello, world!"
    create_pdf
  end

  it "should build appropriate annotation" do
    opts = @pdf.text_annotation(@rect, @content)
    expect(opts[:Type]).to eq(:Annot)
    expect(opts[:Subtype]).to eq(:Text)
    expect(opts[:Rect]).to eq(@rect)
    expect(opts[:Contents]).to eq(@content)
  end

  it "should merge extra options" do
    opts = @pdf.text_annotation(@rect, @content, :Open => true, :Subtype => :Bogus)
    expect(opts[:Subtype]).to eq(:Text)
    expect(opts[:Open]).to eq(true)
  end
end

describe "When creating link annotations" do
  before(:each) do
    @rect = [0, 0, 10, 10]
    @dest = "home"
    create_pdf
  end

  it "should build appropriate annotation" do
    opts = @pdf.link_annotation(@rect, :Dest => @dest)
    expect(opts[:Type]).to eq(:Annot)
    expect(opts[:Subtype]).to eq(:Link)
    expect(opts[:Rect]).to eq(@rect)
    expect(opts[:Dest]).to eq(@dest)
  end

  it "should merge extra options" do
    opts = @pdf.link_annotation(@rect, :Dest => @dest, :Subtype => :Bogus)
    expect(opts[:Subtype]).to eq(:Link)
    expect(opts[:Dest]).to eq(@dest)
  end
end