Sha256: f7afa2c6ec441ef2efcf4e75f8bda5fe43777053dd2284a8fddf8c4ada1992f3

Contents?: true

Size: 1.8 KB

Versions: 84

Compression:

Stored size: 1.8 KB

Contents

# -*- encoding: utf-8 -*-

require 'test_helper'
require 'hexapdf/font/cmap/writer'

describe HexaPDF::Font::CMap::Writer do
  before do
    @cmap_data = <<~EOF
      /CIDInit /ProcSet findresource begin
      12 dict begin
      begincmap
      /CIDSystemInfo
      << /Registry (Adobe)
      /Ordering (UCS)
      /Supplement 0
      >> def
      /CMapName /Adobe-Identity-UCS def
      /CMapType 2 def
      1 begincodespacerange
      <0000> <FFFF>
      endcodespacerange
      2 beginbfchar
      <0060><0090>
      <3A51><d840dc3e>
      endbfchar
      2 beginbfrange
      <0000><005E><0020>
      <1379><137B><90fe>
      endbfrange
      endcmap
      CMapName currentdict /CMap defineresource pop
      end
      end
    EOF
    @mapping = []
    0x00.upto(0x5e) {|i| @mapping << [i, 0x20 + i] }
    @mapping << [0x60, 0x90]
    0x1379.upto(0x137B) {|i| @mapping << [i, 0x90FE + i - 0x1379] }
    @mapping << [0x3A51, 0x2003E]
  end

  describe "create_to_unicode_cmap" do
    it "creates a correct CMap file" do
      assert_equal(@cmap_data, HexaPDF::Font::CMap.create_to_unicode_cmap(@mapping))
    end

    it "works if the last item is a range" do
      @mapping.pop
      @cmap_data.sub!(/2 beginbfchar/, '1 beginbfchar')
      @cmap_data.sub!(/<3A51><d840dc3e>\n/, '')
      assert_equal(@cmap_data, HexaPDF::Font::CMap.create_to_unicode_cmap(@mapping))
    end

    it "works with only ranges" do
      @mapping.delete_at(-1)
      @mapping.delete_at(0x5f)
      @cmap_data.sub!(/\n2 beginbfchar.*endbfchar/m, '')
      assert_equal(@cmap_data, HexaPDF::Font::CMap.create_to_unicode_cmap(@mapping))
    end

    it "returns an empty CMap if the mapping is empty" do
      assert_equal(@cmap_data.sub(/\d+ beginbfchar.*endbfrange/m, ''),
                   HexaPDF::Font::CMap.create_to_unicode_cmap([]))
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
hexapdf-0.47.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.46.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.45.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.44.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.41.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.40.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.39.1 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.39.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.38.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.37.2 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.37.1 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.37.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.36.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.35.1 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.35.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.34.1 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.34.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.33.0 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.32.2 test/hexapdf/font/cmap/test_writer.rb
hexapdf-0.32.1 test/hexapdf/font/cmap/test_writer.rb