Class: TTFunk::Subset::Unicode
- 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
Instance Method Summary collapse
-
#covers?(_character) ⇒ true
Can this subset include the character?.
-
#from_unicode(character) ⇒ Integer
Get character code for Unicode codepoint.
-
#includes?(character) ⇒ Boolean
Does this subset actually has the character?.
-
#initialize(original) ⇒ Unicode
constructor
A new instance of Unicode.
-
#new_cmap_table ⇒ TTFunk::Table::Cmap
Get ‘cmap` table for this subset.
-
#original_glyph_ids ⇒ Array<Integer>
Get the list of Glyph IDs from the original font that are in this subset.
-
#to_unicode_map ⇒ Hash{Integer => Integer}
Get a mapping from this subset to Unicode.
-
#unicode? ⇒ true
Is this a Unicode-based subset?.
-
#use(character) ⇒ void
Add a character to subset.
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.
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?
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.
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?
54 55 56 |
# File 'lib/ttfunk/subset/unicode.rb', line 54 def includes?(character) @subset.include?(character) end |
#new_cmap_table ⇒ TTFunk::Table::Cmap
Get ‘cmap` table for this subset.
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_ids ⇒ Array<Integer>
Get the list of Glyph IDs from the original font that are in this subset.
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_map ⇒ Hash{Integer => Integer}
Get a mapping from this subset to Unicode.
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?
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.
38 39 40 |
# File 'lib/ttfunk/subset/unicode.rb', line 38 def use(character) @subset << character end |