Class: TTFunk::Subset::Base Private

Inherits:
Object
  • Object
show all
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

CodePage, Unicode, Unicode8Bit

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

Instance Method Summary collapse

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.

Parameters:

Source Code
lib/ttfunk/subset/base.rb, line 33
33
def initialize(original)
34
  @original = original
35
end

Instance Attribute Details

#originalTTFunk::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

Returns:

Source Code
lib/ttfunk/subset/base.rb, line 30
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.

Parameters:

  • glyph_ids (Array<Integer>)

Returns:

Source Code
lib/ttfunk/subset/base.rb, line 98
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.

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (String)
Source Code
lib/ttfunk/subset/base.rb, line 63
63
def encode(options = {})
64
  encoder_klass.new(original, self, options).encode
65
end

#encoder_klassTTFunk::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
lib/ttfunk/subset/base.rb, line 70
70
def encoder_klass
71
  original.cff.exists? ? OTFEncoder : TTFEncoder
72
end

#glyphsHash{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.

Returns:

Source Code
lib/ttfunk/subset/base.rb, line 87
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?

Returns:

  • (Boolean)
Source Code
lib/ttfunk/subset/base.rb, line 47
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_glyphHash{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.

Returns:

  • (Hash{Integer => Integer})
Source Code
lib/ttfunk/subset/base.rb, line 142
142
def new_to_old_glyph
143
  @new_to_old_glyph ||= old_to_new_glyph.invert
144
end

#old_to_new_glyphHash{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.

Returns:

  • (Hash{Integer => Integer})
Source Code
lib/ttfunk/subset/base.rb, line 117
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_mapHash{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.

Returns:

  • (Hash{Integer => Integer})
Source Code
lib/ttfunk/subset/base.rb, line 55
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?

Returns:

  • (Boolean)
Source Code
lib/ttfunk/subset/base.rb, line 40
40
def unicode?
41
  false
42
end

#unicode_cmapTTFunk::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
lib/ttfunk/subset/base.rb, line 77
77
def unicode_cmap
78
  @unicode_cmap ||= @original.cmap.unicode.first
79
end