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:

Source Code
lib/ttfunk/subset/unicode.rb, line 14
14
def initialize(original)
15
  super
16
  @subset = Set.new
17
  use(SPACE_CHAR)
18
end

Instance Method Details

#covers?(_character) ⇒ true

Can this subset include the character?

Parameters:

  • _character (Integer)

    Unicode codepoint

Returns:

  • (true)
Source Code
lib/ttfunk/subset/unicode.rb, line 46
46
def covers?(_character)
47
  true
48
end

#from_unicode(character) ⇒ Integer

Get character code for Unicode codepoint.

Parameters:

  • character (Integer)

    Unicode codepoint

Returns:

  • (Integer)
Source Code
lib/ttfunk/subset/unicode.rb, line 62
62
def from_unicode(character)
63
  character
64
end

#includes?(character) ⇒ Boolean

Does this subset actually has the character?

Parameters:

  • character (Integer)

    Unicode codepoint

Returns:

  • (Boolean)
Source Code
lib/ttfunk/subset/unicode.rb, line 54
54
def includes?(character)
55
  @subset.include?(character)
56
end

#new_cmap_tableTTFunk::Table::Cmap

Get cmap table for this subset.

Returns:

Source Code
lib/ttfunk/subset/unicode.rb, line 69
69
def new_cmap_table
70
  @new_cmap_table ||=
71
    begin
72
      mapping =
73
        @subset.each_with_object({}) do |code, map|
74
          map[code] = unicode_cmap[code]
75
        end
76
77
      TTFunk::Table::Cmap.encode(mapping, :unicode)
78
    end
79
end

#original_glyph_idsArray<Integer>

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

Returns:

  • (Array<Integer>)
Source Code
lib/ttfunk/subset/unicode.rb, line 85
85
def original_glyph_ids
86
  ([0] + @subset.map { |code| unicode_cmap[code] }).uniq.sort
87
end

#to_unicode_mapHash{Integer => Integer}

Get a mapping from this subset to Unicode.

Returns:

  • (Hash{Integer => Integer})
Source Code
lib/ttfunk/subset/unicode.rb, line 30
30
def to_unicode_map
31
  @subset.each_with_object({}) { |code, map| map[code] = code }
32
end

#unicode?true

Is this a Unicode-based subset?

Returns:

  • (true)
Source Code
lib/ttfunk/subset/unicode.rb, line 23
23
def unicode?
24
  true
25
end

#use(character) ⇒ void

This method returns an undefined value.

Add a character to subset.

Parameters:

  • character (Integer)

    Unicode codepoint

Source Code
lib/ttfunk/subset/unicode.rb, line 38
38
def use(character)
39
  @subset << character
40
end