Sha256: 7e500221f719f5417744eab90f6383e55bc0ccd28bbf43270842645fa50eb16f

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 KB

Contents

#
# specifying podoff
#
# Fri Oct 23 08:36:38 JST 2015
#

require 'spec_helper'


describe Podoff::Stream do

  describe '#tf' do

    it 'sets the current font' do

      st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))

      st.tf('/Helvetica', 35)
      st.bt(10, 20, 'helvetic')
      st.tf('/ZapfDingbats', 21)
      st.bt(10, 50, 'zapfesque')

      expect(st.to_s).to eq(%{
1 0 obj
<</Length 95>>
stream
BT /Helvetica 35 Tf 10 20 Td (helvetic) Tj ET
BT /ZapfDingbats 21 Tf 10 50 Td (zapfesque) Tj ET
endstream
endobj
      }.strip)
    end
  end

  describe '#bt' do

    it 'works' do

      st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
      st.bt(10, 20, 'hello world')

      expect(st.to_s).to eq(%{
1 0 obj
<</Length 31>>
stream
BT 10 20 Td (hello world) Tj ET
endstream
endobj
      }.strip)
    end

    it 'escapes the text' do

      st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
      st.bt(10, 20, 'hello()world')

      expect(st.to_s).to eq(%{
1 0 obj
<</Length 34>>
stream
BT 10 20 Td (hello\\(\\)world) Tj ET
endstream
endobj
      }.strip)
    end
  end

  describe '#write' do

    it 'injects text into the stream' do

      st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
      st.bt(10, 20, 'abc')
      st.write("\nBT 25 35 Td (ABC) Tj ET")
      st.bt(30, 40, 'def')

      expect(st.to_s).to eq(%{
1 0 obj
<</Length 71>>
stream
BT 10 20 Td (abc) Tj ET
BT 25 35 Td (ABC) Tj ET
BT 30 40 Td (def) Tj ET
endstream
endobj
      }.strip)
    end
  end

  describe '#to_s' do

    it 'applies /Filter /FlateDecode if stream.size > 98' do

      st = Podoff::Stream.new(OpenStruct.new(ref: '1 0'))
      st.write("BT /Helvetica 35 Tf 123 456 Td (Hello Nada) Tj ET\n" * 4)

      expect(st.to_s).to match(
        /^1 0 obj\n<<\/Length 60 \/Filter \/FlateDecode>>/)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
podoff-1.2.2 spec/stream_spec.rb
podoff-1.2.1 spec/stream_spec.rb
podoff-1.2.0 spec/stream_spec.rb
podoff-1.1.1 spec/stream_spec.rb