File: annotations_spec.rb

package info (click to toggle)
ruby-prawn 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,936 kB
  • ctags: 802
  • sloc: ruby: 13,906; sh: 43; makefile: 15
file content (74 lines) | stat: -rw-r--r-- 1,980 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
68
69
70
71
72
73
74
# 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|
      pdf.page(1).attributes[:Annots].should be_nil
      pdf.page(2).attributes[:Annots].size.should == 1
    end
  end

  it "should force :Type to be :Annot" do
    opts = @pdf.annotate(:Rect => [0,0,10,10], :Subtype => :Text, :Contents => "Hello world!")
    opts[:Type].should == :Annot
    opts = @pdf.annotate(:Type => :Bogus, :Rect => [0,0,10,10], :Subtype => :Text, :Contents => "Hello world!")
    opts[:Type].should == :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)
    opts[:Type].should == :Annot
    opts[:Subtype].should == :Text
    opts[:Rect].should == @rect
    opts[:Contents].should == @content
  end

  it "should merge extra options" do
    opts = @pdf.text_annotation(@rect, @content, :Open => true, :Subtype => :Bogus)
    opts[:Subtype].should == :Text
    opts[:Open].should == 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)
    opts[:Type].should == :Annot
    opts[:Subtype].should == :Link
    opts[:Rect].should == @rect
    opts[:Dest].should == @dest
  end

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

end