File: built_in_spec.rb

package info (click to toggle)
ruby-pdf-reader 2.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,544 kB
  • sloc: ruby: 11,993; sh: 46; makefile: 11
file content (64 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download | duplicates (2)
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
# typed: false
# coding: utf-8

describe PDF::Reader::WidthCalculator::BuiltIn do
  it_behaves_like "a WidthCalculator duck type" do
    let!(:font) { double(:basefont => :Helvetica) }
    subject     { PDF::Reader::WidthCalculator::BuiltIn.new(font)}
  end

  describe "#glyph_width" do
    context "With Helvetica, StandardEncoding and no Widths" do
      let!(:encoding)     { PDF::Reader::Encoding.new(:StandardEncoding) }
      let!(:font)         { double(:basefont => :Helvetica,
                                  :subtype => :TrueType,
                                  :encoding => encoding,
                                  :widths => []) }

      let(:width_calculator) {
        PDF::Reader::WidthCalculator::BuiltIn.new(font)
      }

      it "returns width 0 for code point 160(non breaking space)" do
        expect(width_calculator.glyph_width(160)).to eq(0)
      end

      it "returns width 0 for code point 157(unknown)" do
        expect(width_calculator.glyph_width(157)).to eq(0)
      end
    end

    context "With Helvetica and a custom encoding that overwrites standard codepoints" do
      # Codepoint 196 (tilde) is mapped to German umlaut Ä
      let(:encoding)     { PDF::Reader::Encoding.new({:Differences => [196, :Adieresis]}) }
      let(:font)         { double(:basefont => :Helvetica,
                                  :subtype => :Type1,
                                  :encoding => encoding) }

      let(:width_calculator) {
        PDF::Reader::WidthCalculator::BuiltIn.new(font)
      }

      it "returns the correct width for the overwritten codepoint" do
        # tilde = 333, Ä = 667
        expect(width_calculator.glyph_width(196)).to eq(667)
      end
    end

    context "With Foo, a font that isn't part of the built-in 14" do
      let!(:encoding)     { PDF::Reader::Encoding.new(:WinAnsiEncoding) }
      let!(:font)         { double(:basefont => :Foo,
                                  :subtype => :Type1,
                                  :encoding => encoding,
                                  :widths => []) }

      let(:width_calculator) {
        PDF::Reader::WidthCalculator::BuiltIn.new(font)
      }

      it "returns width 722 for code point 65 (A)" do
        expect(width_calculator.glyph_width(65)).to eq(722)
      end
    end
  end
end