Class: TTFunk::Subset::Unicode

Inherits:
Base
  • Object
show all
Defined in:
lib/ttfunk/subset/unicode.rb

Overview

Unicode-based subset.

Constant Summary collapse

SPACE_CHAR =

Space character code

0x20

Constants inherited from Base

Base::MICROSOFT_PLATFORM_ID, Base::MS_SYMBOL_ENCODING_ID

Instance Attribute Summary

Attributes inherited from Base

#original

Instance Method Summary collapse

Methods inherited from Base

#collect_glyphs, #encode, #encoder_klass, #glyphs, #microsoft_symbol?, #new_to_old_glyph, #old_to_new_glyph, #unicode_cmap

Constructor Details

#initialize(original) ⇒ Unicode

Returns a new instance of Unicode.

Parameters:



14
15
16
17
18
# File 'lib/ttfunk/subset/unicode.rb', line 14

def initialize(original)
  super
  @subset = Set.new
  use(SPACE_CHAR)
end

Instance Method Details

#covers?(_character) ⇒ true

Can this subset include the character?

Parameters:

  • _character (Integer)

    Unicode codepoint

Returns:

  • (true)


46
47
48
# File 'lib/ttfunk/subset/unicode.rb', line 46

def covers?(_character)
  true
end

#from_unicode(character) ⇒ Integer

Get character code for Unicode codepoint.

Parameters:

  • character (Integer)

    Unicode codepoint

Returns:

  • (Integer)


62
63
64
# File 'lib/ttfunk/subset/unicode.rb', line 62

def from_unicode(character)
  character
end

#includes?(character) ⇒ Boolean

Does this subset actually has the character?

Parameters:

  • character (Integer)

    Unicode codepoint

Returns:

  • (Boolean)


54
55
56
# File 'lib/ttfunk/subset/unicode.rb', line 54

def includes?(character)
  @subset.include?(character)
end

#new_cmap_tableTTFunk::Table::Cmap

Get ‘cmap` table for this subset.

Returns:



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ttfunk/subset/unicode.rb', line 69

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

      TTFunk::Table::Cmap.encode(mapping, :unicode)
    end
end

#original_glyph_idsArray<Integer>

Get the list of Glyph IDs from the original font that are in this subset.

Returns:

  • (Array<Integer>)


85
86
87
# File 'lib/ttfunk/subset/unicode.rb', line 85

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

#to_unicode_mapHash{Integer => Integer}

Get a mapping from this subset to Unicode.

Returns:

  • (Hash{Integer => Integer})


30
31
32
# File 'lib/ttfunk/subset/unicode.rb', line 30

def to_unicode_map
  @subset.each_with_object({}) { |code, map| map[code] = code }
end

#unicode?true

Is this a Unicode-based subset?

Returns:

  • (true)


23
24
25
# File 'lib/ttfunk/subset/unicode.rb', line 23

def unicode?
  true
end

#use(character) ⇒ void

This method returns an undefined value.

Add a character to subset.

Parameters:

  • character (Integer)

    Unicode codepoint



38
39
40
# File 'lib/ttfunk/subset/unicode.rb', line 38

def use(character)
  @subset << character
end