Class: TTFunk::Subset::Unicode8Bit
- Defined in:
- lib/ttfunk/subset/unicode_8bit.rb
Overview
An 8-bit Unicode-based subset. It can include any Unicode character but limits number of characters so that the could be encoded by a single byte.
Constant Summary
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) ⇒ Boolean
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) ⇒ Unicode8Bit
constructor
A new instance of Unicode8Bit.
-
#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) ⇒ Unicode8Bit
Returns a new instance of Unicode8Bit.
Source Code
12 | def initialize(original) |
13 | super
|
14 | @subset = { 0x20 => 0x20 } |
15 | @unicodes = { 0x20 => 0x20 } |
16 | @next = 0x21 # apparently, PDF's don't like to use chars between 0-31 |
17 | end
|
Instance Method Details
#covers?(character) ⇒ Boolean
Can this subset include the character?
Source Code
49 | def covers?(character) |
50 | @unicodes.key?(character) || @next < 256 |
51 | end
|
#from_unicode(character) ⇒ Integer
Get character code for Unicode codepoint.
Source Code
65 | def from_unicode(character) |
66 | @unicodes[character] |
67 | end
|
#includes?(character) ⇒ Boolean
Does this subset actually has the character?
Source Code
57 | def includes?(character) |
58 | @unicodes.key?(character) |
59 | end
|
#new_cmap_table ⇒ TTFunk::Table::Cmap
Get cmap
table for this subset.
Source Code
72 | def new_cmap_table |
73 | @new_cmap_table ||= |
74 | begin
|
75 | mapping = |
76 | @subset.each_with_object({}) do |(code, unicode), map| |
77 | map[code] = unicode_cmap[unicode] |
78 | map
|
79 | end
|
80 | |
81 | # since we're mapping a subset of the unicode glyphs into an
|
82 | # arbitrary 256-character space, the actual encoding we're
|
83 | # using is irrelevant. We choose MacRoman because it's a 256-character
|
84 | # encoding that happens to be well-supported in both TTF and
|
85 | # PDF formats.
|
86 | TTFunk::Table::Cmap.encode(mapping, :mac_roman) |
87 | end
|
88 | end
|
#original_glyph_ids ⇒ Array<Integer>
Get the list of Glyph IDs from the original font that are in this subset.
Source Code
94 | def original_glyph_ids |
95 | ([0] + @unicodes.keys.map { |unicode| unicode_cmap[unicode] }).uniq.sort |
96 | end
|
#to_unicode_map ⇒ Hash{Integer => Integer}
Get a mapping from this subset to Unicode.
Source Code
29 | def to_unicode_map |
30 | @subset.dup |
31 | end
|
#unicode? ⇒ true
Is this a Unicode-based subset?
Source Code
22 | def unicode? |
23 | true
|
24 | end
|
#use(character) ⇒ void
This method returns an undefined value.
Add a character to subset.
Source Code
37 | def use(character) |
38 | unless @unicodes.key?(character) |
39 | @subset[@next] = character |
40 | @unicodes[character] = @next |
41 | @next += 1 |
42 | end
|
43 | end
|