File: page_layout_spec.rb

package info (click to toggle)
ruby-pdf-reader 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,908 kB
  • ctags: 569
  • sloc: ruby: 8,330; makefile: 10
file content (125 lines) | stat: -rw-r--r-- 3,676 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# coding: utf-8

require "spec_helper"

describe PDF::Reader::PageLayout, "#to_s" do
  context "with an A4 page" do
    let(:mediabox) { [0, 0, 595.28, 841.89 ]}

    context "with no words" do
      subject { PDF::Reader::PageLayout.new([], mediabox)}

      it "should return a correct string" do
        subject.to_s.should == ""
      end
    end
    context "with one word" do
      let!(:runs) do
        [
          PDF::Reader::TextRun.new(30, 700, 50, 12, "Hello")
        ]
      end
      subject { PDF::Reader::PageLayout.new(runs, mediabox)}

      it "should return a correct string" do
        subject.to_s.should == "Hello"
      end
    end
    context "with one run directly below another" do
      let!(:runs) do
        [
          PDF::Reader::TextRun.new(30, 700, 50, 12, "Hello"),
          PDF::Reader::TextRun.new(30, 687, 50, 12, "World"),
        ]
      end
      subject { PDF::Reader::PageLayout.new(runs, mediabox)}

      it "should return a correct string" do
        subject.to_s.should == "Hello\nWorld"
      end
    end
    context "with one two words on one line, separated by a font size gap" do
      let!(:runs) do
        [
          PDF::Reader::TextRun.new(30, 700, 50, 12, "Hello"),
          PDF::Reader::TextRun.new(92, 700, 50, 12, "World"),
        ]
      end
      subject { PDF::Reader::PageLayout.new(runs, mediabox)}

      it "should return a correct string" do
        subject.to_s.should == "Hello World"
      end
    end

    context "with two words on one line, separated just over the mean glyph width" do
      let!(:runs) do
        [
          PDF::Reader::TextRun.new(30, 700, 50, 12, "Hello"),
          PDF::Reader::TextRun.new(91, 700, 50, 12, "World"),
        ]
      end
      subject { PDF::Reader::PageLayout.new(runs, mediabox)}

      it "should return a correct string" do
        subject.to_s.should == "Hello World"
      end
    end

    context "with one two words on one line, separated just over 2x the mean glyph width" do
      let!(:runs) do
        [
          PDF::Reader::TextRun.new(30, 700, 50, 12, "Hello"),
          PDF::Reader::TextRun.new(101, 700, 50, 12, "World"),
        ]
      end
      subject { PDF::Reader::PageLayout.new(runs, mediabox)}

      it "should return a correct string" do
        subject.to_s.should == "Hello  World"
      end
    end

    context "with one run directly below another and indented by just over 1 font size gap" do
      let!(:runs) do
        [
          PDF::Reader::TextRun.new(30, 700, 50, 12, "Hello"),
          PDF::Reader::TextRun.new(43, 687, 50, 12, "World"),
        ]
      end
      subject { PDF::Reader::PageLayout.new(runs, mediabox)}

      it "should return a correct string" do
        subject.to_s.should == "Hello\n World"
      end
    end

    context "with one run directly below another and the first indented by just over 1x fs gap" do
      let!(:runs) do
        [
          PDF::Reader::TextRun.new(43, 700, 50, 12, "Hello"),
          PDF::Reader::TextRun.new(30, 687, 50, 12, "World"),
        ]
      end
      subject { PDF::Reader::PageLayout.new(runs, mediabox)}

      it "should return a correct string" do
        subject.to_s.should == " Hello\nWorld"
      end
    end

    context "with one run directly below another with 1 font size gap" do
      let!(:runs) do
        [
          PDF::Reader::TextRun.new(30, 700, 50, 12, "Hello"),
          PDF::Reader::TextRun.new(30, 676, 50, 12, "World"),
        ]
      end
      subject { PDF::Reader::PageLayout.new(runs, mediabox)}

      it "should return a correct string" do
        subject.to_s.should == "Hello\n\nWorld"
      end
    end
  end
end