File: text_rendering_mode_spec.rb

package info (click to toggle)
ruby-prawn 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,380 kB
  • sloc: ruby: 15,820; sh: 43; makefile: 20
file content (48 lines) | stat: -rw-r--r-- 1,558 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
# frozen_string_literal: true

require 'spec_helper'

describe Prawn::Text do
  let(:pdf) { create_pdf }

  describe '#text_rendering_mode' do
    it 'draws the text rendering mode to the document' do
      pdf.text_rendering_mode(:stroke) do
        pdf.text('hello world')
      end
      contents = PDF::Inspector::Text.analyze(pdf.render)
      expect(contents.text_rendering_mode.first).to eq(1)
    end

    it 'does not draw the text rendering mode to the document' \
      ' when the new mode matches the old' do
      pdf.text_rendering_mode(:fill) do
        pdf.text('hello world')
      end
      contents = PDF::Inspector::Text.analyze(pdf.render)
      expect(contents.text_rendering_mode).to be_empty
    end

    it 'restores character spacing to 0' do
      pdf.text_rendering_mode(:stroke) do
        pdf.text('hello world')
      end
      contents = PDF::Inspector::Text.analyze(pdf.render)
      expect(contents.text_rendering_mode).to eq([1, 0])
    end

    it 'functions as an accessor when no parameter given' do
      pdf.text_rendering_mode(:fill_stroke) do
        pdf.text('hello world')
        expect(pdf.text_rendering_mode).to eq(:fill_stroke)
      end
      expect(pdf.text_rendering_mode).to eq(:fill)
    end

    it 'raise_errors an exception when passed an invalid mode' do
      expect { pdf.text_rendering_mode(-1) }.to raise_error(ArgumentError)
      expect { pdf.text_rendering_mode(8) }.to raise_error(ArgumentError)
      expect { pdf.text_rendering_mode(:flil) }.to raise_error(ArgumentError)
    end
  end
end