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.
33 34 35 |
# File 'lib/ttfunk/subset/base.rb', line 33 def initialize(original) @original = original 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
30 31 32 |
# File 'lib/ttfunk/subset/base.rb', line 30 def original @original 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.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ttfunk/subset/base.rb', line 98 def collect_glyphs(glyph_ids) collected = glyph_ids.each_with_object({}) do |id, h| h[id] = glyph_for(id) end additional_ids = collected.values .select { |g| g && g.compound? } .map(&:glyph_ids) .flatten collected.update(collect_glyphs(additional_ids)) if additional_ids.any? collected 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.
63 64 65 |
# File 'lib/ttfunk/subset/base.rb', line 63 def encode( = {}) encoder_klass.new(original, self, ).encode 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.
70 71 72 |
# File 'lib/ttfunk/subset/base.rb', line 70 def encoder_klass original.cff.exists? ? OTFEncoder : TTFEncoder 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.
87 88 89 |
# File 'lib/ttfunk/subset/base.rb', line 87 def glyphs @glyphs ||= collect_glyphs(original_glyph_ids) 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?
47 48 49 50 |
# File 'lib/ttfunk/subset/base.rb', line 47 def microsoft_symbol? new_cmap_table[:platform_id] == MICROSOFT_PLATFORM_ID && new_cmap_table[:encoding_id] == MS_SYMBOL_ENCODING_ID 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.
142 143 144 |
# File 'lib/ttfunk/subset/base.rb', line 142 def new_to_old_glyph @new_to_old_glyph ||= old_to_new_glyph.invert 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.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ttfunk/subset/base.rb', line 117 def old_to_new_glyph @old_to_new_glyph ||= begin charmap = new_cmap_table[:charmap] old_to_new = charmap.each_with_object(0 => 0) do |(_, ids), map| map[ids[:old]] = ids[:new] end next_glyph_id = new_cmap_table[:max_glyph_id] glyphs.each_key do |old_id| unless old_to_new.key?(old_id) old_to_new[old_id] = next_glyph_id next_glyph_id += 1 end end old_to_new end 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.
55 56 57 |
# File 'lib/ttfunk/subset/base.rb', line 55 def to_unicode_map {} 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?
40 41 42 |
# File 'lib/ttfunk/subset/base.rb', line 40 def unicode? false 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.
77 78 79 |
# File 'lib/ttfunk/subset/base.rb', line 77 def unicode_cmap @unicode_cmap ||= @original.cmap.unicode.first end |