File: private_dict_spec.rb

package info (click to toggle)
ruby-ttfunk 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,472 kB
  • sloc: ruby: 7,954; makefile: 7
file content (61 lines) | stat: -rw-r--r-- 1,884 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
# frozen_string_literal: true

require 'spec_helper'
require 'ttfunk/table/cff'

RSpec.describe TTFunk::Table::Cff::PrivateDict do
  let(:font) { TTFunk::File.open(font_path) }
  let(:private_dict) { font.cff.top_index[0].font_index[0].private_dict }
  let(:font_path) { test_font('NotoSansCJKsc-Thin', :otf) }

  describe '#default_width_x' do
    it 'identifies the correct default x width' do
      expect(private_dict.default_width_x).to eq(1000)
    end
  end

  describe '#nominal_width_x' do
    it 'identifies the correct nominal x width' do
      # this is the default if no nominal width is specified
      expect(private_dict.nominal_width_x).to eq(0)
    end
  end

  describe '#subr_index' do
    let(:subr_index) { private_dict.subr_index }

    it 'fetches the subroutine index' do
      expect(subr_index).to be_a(TTFunk::Table::Cff::SubrIndex)
    end

    it 'parses subroutines correctly' do
      # Subroutines provide shared chunks of instructions that can be used
      # when constructing charstrings. In other words, these seemingly
      # random bytes mean something specific to the charstrings code. See
      # the subr index tests for more.
      expect(subr_index[2].bytes).to eq [127, 171, 119, 159, 248, 122, 171, 18, 11]
    end
  end

  describe '#encode' do
    it 'produces an encoded dict that can be re-parsed successfully' do
      result = private_dict.encode
      dict_length = result.length

      private_dict.finalize(result)
      io = StringIO.new(result.string)
      file = TestFile.new(io)
      new_dict = described_class.new(file, 0, dict_length)

      expect(new_dict.to_h).to(
        eq(
          private_dict.to_h.merge(
            described_class::OPERATORS[:subrs] => [dict_length],
          ),
        ),
      )

      expect(new_dict.subr_index.items_count).to eq(private_dict.subr_index.items_count)
    end
  end
end