Class: TTFunk::Subset::Base Private
- Inherits:
-
Object
- Object
- TTFunk::Subset::Base
- Defined in:
- lib/ttfunk/subset/base.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base subset.
Direct Known Subclasses
Constant Summary collapse
- MICROSOFT_PLATFORM_ID =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Microsoft Platform ID
3
- MS_SYMBOL_ENCODING_ID =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Symbol Encoding ID for Microsoft Platform
0
Instance Attribute Summary collapse
-
#original ⇒ TTFunk::File
readonly
private
Original font.
Instance Method Summary collapse
-
#collect_glyphs(glyph_ids) ⇒ Hash{Integer => TTFunk::Table::Glyf::Simple, TTFunk::Table::Glyf::Compound>, Hash{Integer => TTFunk::Table::Cff::Charstring}
private
Get glyphs by their IDs in the original font.
-
#encode(options = {}) ⇒ String
private
Encode this subset into a binary font representation.
-
#encoder_klass ⇒ TTFunk::TTFEncoder, TTFunk::OTFEncoder
private
Encoder class for this subset.
-
#glyphs ⇒ Hash{Integer => TTFunk::Table::Glyf::Simple, TTFunk::Table::Glyf::Compound}, Hash{Integer => TTFunk::Table::Cff::Charstring] if original is a CFF-based OpenType font
private
Get glyphs in this subset.
-
#initialize(original) ⇒ Base
constructor
private
A new instance of Base.
-
#microsoft_symbol? ⇒ Boolean
private
Does this subset use Microsoft Symbolic encoding?.
-
#new_to_old_glyph ⇒ Hash{Integer => Integer}
private
Glyph ID mapping from this subset to the original font.
-
#old_to_new_glyph ⇒ Hash{Integer => Integer}
private
Glyph ID mapping from the original font to this subset.
-
#to_unicode_map ⇒ Hash{Integer => Integer}
private
Get a mapping from this subset to Unicode.
-
#unicode? ⇒ Boolean
private
Is this Unicode-based subset?.
-
#unicode_cmap ⇒ TTFunk::Table::Cmap::Subtable
private
Get the first Unicode cmap from the original font.
Constructor Details
#initialize(original) ⇒ Base
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Base.
Source Code
33 | def initialize(original) |
34 | @original = original |
35 | end
|
Instance Attribute Details
#original ⇒ TTFunk::File (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Original font
Source Code
30 | def original |
31 | @original
|
32 | end
|
Instance Method Details
#collect_glyphs(glyph_ids) ⇒ Hash{Integer => TTFunk::Table::Glyf::Simple, TTFunk::Table::Glyf::Compound>, Hash{Integer => TTFunk::Table::Cff::Charstring}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get glyphs by their IDs in the original font.
Source Code
98 | def collect_glyphs(glyph_ids) |
99 | collected = |
100 | glyph_ids.each_with_object({}) do |id, h| |
101 | h[id] = glyph_for(id) |
102 | end
|
103 | |
104 | additional_ids = collected.values |
105 | .select { |g| g && g.compound? } |
106 | .map(&:glyph_ids) |
107 | .flatten |
108 | |
109 | collected.update(collect_glyphs(additional_ids)) if additional_ids.any? |
110 | |
111 | collected
|
112 | end
|
#encode(options = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Encode this subset into a binary font representation.
Source Code
63 | def encode(options = {}) |
64 | encoder_klass.new(original, self, options).encode |
65 | end
|
#encoder_klass ⇒ TTFunk::TTFEncoder, TTFunk::OTFEncoder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Encoder class for this subset.
Source Code
70 | def encoder_klass |
71 | original.cff.exists? ? OTFEncoder : TTFEncoder |
72 | end
|
#glyphs ⇒ Hash{Integer => TTFunk::Table::Glyf::Simple, TTFunk::Table::Glyf::Compound}, Hash{Integer => TTFunk::Table::Cff::Charstring] if original is a CFF-based OpenType font
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get glyphs in this subset.
Source Code
87 | def glyphs |
88 | @glyphs ||= collect_glyphs(original_glyph_ids) |
89 | end
|
#microsoft_symbol? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Does this subset use Microsoft Symbolic encoding?
Source Code
47 | def microsoft_symbol? |
48 | new_cmap_table[:platform_id] == MICROSOFT_PLATFORM_ID && |
49 | new_cmap_table[:encoding_id] == MS_SYMBOL_ENCODING_ID |
50 | end
|
#new_to_old_glyph ⇒ Hash{Integer => Integer}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Glyph ID mapping from this subset to the original font.
Source Code
142 | def new_to_old_glyph |
143 | @new_to_old_glyph ||= old_to_new_glyph.invert |
144 | end
|
#old_to_new_glyph ⇒ Hash{Integer => Integer}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Glyph ID mapping from the original font to this subset.
Source Code
117 | def old_to_new_glyph |
118 | @old_to_new_glyph ||= |
119 | begin
|
120 | charmap = new_cmap_table[:charmap] |
121 | old_to_new = |
122 | charmap.each_with_object(0 => 0) do |(_, ids), map| |
123 | map[ids[:old]] = ids[:new] |
124 | end
|
125 | |
126 | next_glyph_id = new_cmap_table[:max_glyph_id] |
127 | |
128 | glyphs.each_key do |old_id| |
129 | unless old_to_new.key?(old_id) |
130 | old_to_new[old_id] = next_glyph_id |
131 | next_glyph_id += 1 |
132 | end
|
133 | end
|
134 | |
135 | old_to_new
|
136 | end
|
137 | end
|
#to_unicode_map ⇒ Hash{Integer => Integer}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a mapping from this subset to Unicode.
Source Code
55 | def to_unicode_map |
56 | {}
|
57 | end
|
#unicode? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is this Unicode-based subset?
Source Code
40 | def unicode? |
41 | false
|
42 | end
|
#unicode_cmap ⇒ TTFunk::Table::Cmap::Subtable
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the first Unicode cmap from the original font.
Source Code
77 | def unicode_cmap |
78 | @unicode_cmap ||= @original.cmap.unicode.first |
79 | end
|