Sha256: 68acddbf84b06ea5585f597fb98c2190c2db9ca871bc85d905e02d8b3007224a

Contents?: true

Size: 1.5 KB

Versions: 20

Compression:

Stored size: 1.5 KB

Contents

require 'set'
require 'ttfunk/subset/base'
require 'ttfunk/encoding/windows_1252'

module TTFunk
  module Subset
    class Windows1252 < Base
      def initialize(original)
        super
        @subset = Array.new(256)
      end

      def to_unicode_map
        Encoding::Windows1252::TO_UNICODE
      end

      def use(character)
        @subset[Encoding::Windows1252::FROM_UNICODE[character]] = character
      end

      def covers?(character)
        Encoding::Windows1252.covers?(character)
      end

      def includes?(character)
        code = Encoding::Windows1252::FROM_UNICODE[character]
        code && @subset[code]
      end

      def from_unicode(character)
        Encoding::Windows1252::FROM_UNICODE[character]
      end

      protected

        def new_cmap_table(options)
          mapping = {}
          @subset.each_with_index do |unicode, cp1252|
            mapping[cp1252] = unicode_cmap[unicode] if cp1252
          end

          # yes, I really mean "mac roman". TTF has no cp1252 encoding, and the
          # alternative would be to encode it using a format 4 unicode table, which
          # is overkill. for our purposes, mac-roman suffices. (If we were building
          # a _real_ font, instead of a PDF-embeddable subset, things would probably
          # be different.)
          TTFunk::Table::Cmap.encode(mapping, :mac_roman)
        end

        def original_glyph_ids
          ([0] + @subset.map { |unicode| unicode && unicode_cmap[unicode] }).compact.uniq.sort
        end
    end
  end
end

Version data entries

20 entries across 20 versions & 7 rubygems

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