class TTFunk::Table::Cff::TopDict
CFF top dict.
Constants
- DEFAULT_CHARSTRING_TYPE
Default charstring type.
- OPERATORS
All the operators we currently care about.
- OPERATOR_CODES
Inverse operator mapping.
- PLACEHOLDER_LENGTH
Length of placeholders for other operators.
- POINTER_OPERATORS
Operators whose values are offsets that point to other parts of the file.
- POINTER_PLACEHOLDER_LENGTH
Length of placeholders for pointer operators.
Public Instance Methods
CFF table in this file.
@return [TTFunk::Table::Cff]
# File lib/ttfunk/table/cff/top_dict.rb, line 207 def cff file.cff end
Ofsset of CFF table in the file.
@return [Integer]
# File lib/ttfunk/table/cff/top_dict.rb, line 214 def cff_offset cff.offset end
Charset
specified in this dict.
@return [TTFunk::Table::Cff::Charset, nil]
# File lib/ttfunk/table/cff/top_dict.rb, line 123 def charset @charset ||= if (charset_offset_or_id = self[OPERATORS[:charset]]) if charset_offset_or_id.empty? Charset.new(self, file) else Charset.new(self, file, charset_offset_or_id.first) end end end
Charstring
type specified in this dict.
@return [Integer]
# File lib/ttfunk/table/cff/top_dict.rb, line 167 def charstring_type @charstring_type = self[OPERATORS[:charstring_type]] || DEFAULT_CHARSTRING_TYPE end
Charstrings index specified in this dict.
> OpenType fonts with TrueType outlines use a glyph index to specify
and access glyphs within a font; e.g., to index within the `loca` table and thereby access glyph data in the `glyf` table. This concept is retained in OpenType CFF fonts, except that glyph data is accessed through the CharStrings INDEX of the CFF table.
> — [CFF — Compact Font Format Table](www.microsoft.com/typography/otspec/cff.htm)
@return [TTFunk::Table::Cff::CharstringsIndex, nil]
# File lib/ttfunk/table/cff/top_dict.rb, line 157 def charstrings_index @charstrings_index ||= if (charstrings_offset = self[OPERATORS[:charstrings_index]]) CharstringsIndex.new(self, file, cff_offset + charstrings_offset.first) end end
Encode dict.
@return [TTFunk::EncodedString]
# File lib/ttfunk/table/cff/top_dict.rb, line 41 def encode(*) EncodedString.new do |result| each_with_index do |(operator, operands), _idx| if operator == OPERATORS[:private] result << encode_private elsif pointer_operator?(operator) result << Placeholder.new( OPERATOR_CODES[operator], length: POINTER_PLACEHOLDER_LENGTH, ) else operands.each { |operand| result << encode_operand(operand) } end result << encode_operator(operator) end end end
Encoding
specified in this dict.
@return [TTFunk::Table::Cff::Encoding, nil]
# File lib/ttfunk/table/cff/top_dict.rb, line 137 def encoding # PostScript type 1 fonts, i.e. CID fonts, i.e. some fonts that use # the CFF table, don't specify an encoding, so this can be nil @encoding ||= if (encoding_offset_or_id = self[OPERATORS[:encoding]]) Encoding.new(self, file, encoding_offset_or_id.first) end end
Finalize the table.
@param new_cff_data [TTFunk::EncodedString] @param charmap [Hash{Integer => Hash}] keys are the charac codes,
values are hashes: * `:old` (<tt>Integer</tt>) - glyph ID in the original font. * `:new` (<tt>Integer</tt>) - glyph ID in the subset font.
@return [void]
# File lib/ttfunk/table/cff/top_dict.rb, line 68 def finalize(new_cff_data, charmap) if charset finalize_subtable(new_cff_data, :charset, charset.encode(charmap)) end if encoding finalize_subtable(new_cff_data, :encoding, encoding.encode(charmap)) end if charstrings_index finalize_subtable(new_cff_data, :charstrings_index, charstrings_index.encode(charmap)) end if font_index finalize_subtable(new_cff_data, :font_index, font_index.encode) font_index.finalize(new_cff_data) end if font_dict_selector finalize_subtable(new_cff_data, :font_dict_selector, font_dict_selector.encode(charmap)) end if private_dict encoded_private_dict = private_dict.encode encoded_offset = encode_integer32(new_cff_data.length) encoded_length = encode_integer32(encoded_private_dict.length) new_cff_data.resolve_placeholder(:"private_length_#{@table_offset}", encoded_length) new_cff_data.resolve_placeholder(:"private_offset_#{@table_offset}", encoded_offset) private_dict.finalize(encoded_private_dict) new_cff_data << encoded_private_dict end end
Font dict selector specified in this dict.
@return [TTFunk::Table::Cff::FdSelector, nil]
# File lib/ttfunk/table/cff/top_dict.rb, line 185 def font_dict_selector @font_dict_selector ||= if (fd_select_offset = self[OPERATORS[:font_dict_selector]]) FdSelector.new(self, file, cff_offset + fd_select_offset.first) end end
Font index specified in this dict.
@return [TTFunk::Table::Cff::FontIndex, nil]
# File lib/ttfunk/table/cff/top_dict.rb, line 175 def font_index @font_index ||= if (font_index_offset = self[OPERATORS[:font_index]]) FontIndex.new(self, file, cff_offset + font_index_offset.first) end end
Private dict specified in this dict.
@return [TTFunk::Table::Cff::PrivateDict, nil]
# File lib/ttfunk/table/cff/top_dict.rb, line 195 def private_dict @private_dict ||= if (info = self[OPERATORS[:private]]) private_dict_length, private_dict_offset = info PrivateDict.new(file, cff_offset + private_dict_offset, private_dict_length) end end
Registry Ordering Supplement.
@return [Array(Integer, Integer, Integer), nil]
# File lib/ttfunk/table/cff/top_dict.rb, line 107 def ros self[OPERATORS[:ros]] end
Is Registry Ordering Supplement present in this dict?
@return [Boolean]
# File lib/ttfunk/table/cff/top_dict.rb, line 114 def ros? !ros.nil? end
Private Instance Methods
# File lib/ttfunk/table/cff/top_dict.rb, line 244 def encode_charstring_type(charstring_type) if charstring_type == DEFAULT_CHARSTRING_TYPE '' else encode_operand(charstring_type) end end
# File lib/ttfunk/table/cff/top_dict.rb, line 220 def encode_private EncodedString.new do |result| result << Placeholder.new( :"private_length_#{@table_offset}", length: PLACEHOLDER_LENGTH, ) result << Placeholder.new( :"private_offset_#{@table_offset}", length: PLACEHOLDER_LENGTH, ) end end
# File lib/ttfunk/table/cff/top_dict.rb, line 234 def finalize_subtable(new_cff_data, name, table_data) encoded = encode_integer32(new_cff_data.length) new_cff_data.resolve_placeholder(name, encoded) new_cff_data << table_data end
# File lib/ttfunk/table/cff/top_dict.rb, line 240 def pointer_operator?(operator) POINTER_OPERATORS.include?(OPERATOR_CODES[operator]) end