class TTFunk::Subset::Unicode8Bit

Public Class Methods

new(original) click to toggle source
Calls superclass method TTFunk::Subset::Base::new
# File lib/ttfunk/subset/unicode_8bit.rb, line 9
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

Public Instance Methods

covers?(character) click to toggle source
# File lib/ttfunk/subset/unicode_8bit.rb, line 32
def covers?(character)
  @unicodes.key?(character) || @next < 256
end
from_unicode(character) click to toggle source
# File lib/ttfunk/subset/unicode_8bit.rb, line 40
def from_unicode(character)
  @unicodes[character]
end
includes?(character) click to toggle source
# File lib/ttfunk/subset/unicode_8bit.rb, line 36
def includes?(character)
  @unicodes.key?(character)
end
new_cmap_table() click to toggle source
# File lib/ttfunk/subset/unicode_8bit.rb, line 44
def new_cmap_table
  @new_cmap_table ||=
    begin
      mapping =
        @subset.each_with_object({}) do |(code, unicode), map|
          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
end
original_glyph_ids() click to toggle source
# File lib/ttfunk/subset/unicode_8bit.rb, line 62
def original_glyph_ids
  ([0] + @unicodes.keys.map { |unicode| unicode_cmap[unicode] }).uniq.sort
end
to_unicode_map() click to toggle source
# File lib/ttfunk/subset/unicode_8bit.rb, line 20
def to_unicode_map
  @subset.dup
end
unicode?() click to toggle source
# File lib/ttfunk/subset/unicode_8bit.rb, line 16
def unicode?
  true
end
use(character) click to toggle source
# File lib/ttfunk/subset/unicode_8bit.rb, line 24
def use(character)
  unless @unicodes.key?(character)
    @subset[@next] = character
    @unicodes[character] = @next
    @next += 1
  end
end