Sha256: 20c192b81cfb44c86b6c65cd79e7e7835a3f6bcc2d0202449f7493d7ba0b95c1

Contents?: true

Size: 1.52 KB

Versions: 34

Compression:

Stored size: 1.52 KB

Contents

require 'set'
require 'ttfunk/subset/base'

module TTFunk
  module Subset
    class Unicode8Bit < Base
      def initialize(original)
        super
        @subset = { 0x20 => 0x20 }
        @unicodes = { 0x20 => 0x20 }
        @next = 0x21 # apparently, PDF's don't like to use chars between 0-31
      end

      def unicode?
        true
      end

      def to_unicode_map
        @subset.dup
      end

      def use(character)
        if !@unicodes.key?(character)
          @subset[@next] = character
          @unicodes[character] = @next
          @next += 1
        end
      end

      def covers?(character)
        @unicodes.key?(character) || @next < 256
      end

      def includes?(character)
        @unicodes.key?(character)
      end

      def from_unicode(character)
        @unicodes[character]
      end

      protected

        def new_cmap_table(options)
          mapping = @subset.inject({}) do |map, (code,unicode)|
            map[code] = unicode_cmap[unicode]
            map
          end

          # since we're mapping a subset of the unicode glyphs into an
          # arbitrary 256-character space, the actual encoding we're
          # using is irrelevant. We choose MacRoman because it's a 256-character
          # encoding that happens to be well-supported in both TTF and
          # PDF formats.
          TTFunk::Table::Cmap.encode(mapping, :mac_roman)
        end

        def original_glyph_ids
          ([0] + @unicodes.keys.map { |unicode| unicode_cmap[unicode] }).uniq.sort
        end
    end
  end
end

Version data entries

34 entries across 34 versions & 10 rubygems

Version Path
ttfunk-1.2.2 lib/ttfunk/subset/unicode_8bit.rb
ttfunk-1.2.1 lib/ttfunk/subset/unicode_8bit.rb
ttfunk-1.2.0 lib/ttfunk/subset/unicode_8bit.rb
ttfunk-1.1.1 lib/ttfunk/subset/unicode_8bit.rb
ttfunk-1.1.0 lib/ttfunk/subset/unicode_8bit.rb
ttfunk-1.0.3 lib/ttfunk/subset/unicode_8bit.rb
ttfunk-1.0.2 lib/ttfunk/subset/unicode_8bit.rb
ttfunk-1.0.1 lib/ttfunk/subset/unicode_8bit.rb
davebenvenuti-prawn-0.11.1.pre vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
piglop-prawn-0.10.2.3 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
piglop-prawn-0.10.2.2 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
piglop-prawn-0.10.2.1 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
glyph_imager-0.1.1 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
prawn-0.11.1.pre vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
goodwill-prawn-edge-0.10.0 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
alphasights-prawn-0.10.4 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
alphasights-prawn-0.10.3 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
alphasights-prawn-0.10.2 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
alphasights-prawn-0.10.1 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb
glyph_imager-0.1.0 vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb