Class: Fontisan::Tables::Cff::CharstringsIndex
- Defined in:
- lib/fontisan/tables/cff/charstrings_index.rb
Overview
CharStrings INDEX wrapper
This class wraps the CharStrings INDEX to provide convenient access to individual CharString objects. The CharStrings INDEX contains the glyph outline programs (Type 2 CharStrings) for each glyph in the font.
CharStrings Format:
- INDEX structure containing binary CharString data
- Each entry is a Type 2 CharString program
- Number of entries typically matches the number of glyphs
- Index 0 is typically .notdef glyph
Usage:
- Create from raw CharStrings INDEX data
- Provide Private DICT and subroutine INDEXes for interpretation
- Access individual CharStrings by glyph index
Reference: CFF specification section 16 "Local/Global Subrs INDEXes" https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
Instance Attribute Summary
Attributes inherited from Index
#count, #data, #off_size, #offsets
Instance Method Summary collapse
-
#all_charstrings(private_dict, global_subrs, local_subrs = nil) ⇒ Array<CharString>
Get all CharStrings as an array of CharString objects.
-
#charstring_at(index, private_dict, global_subrs, local_subrs = nil) ⇒ CharString?
Get a CharString object at the specified glyph index.
-
#charstring_size(index) ⇒ Integer?
Get the size of a CharString in bytes.
-
#each_charstring(private_dict, global_subrs, local_subrs = nil) {|CharString, Integer| ... } ⇒ Enumerator
Iterate over each CharString in the INDEX.
-
#glyph_count ⇒ Integer
Get the number of glyphs (CharStrings) in this INDEX.
-
#valid_glyph_index?(index) ⇒ Boolean
Check if a glyph index is valid.
Methods inherited from Index
#[], #each, #empty?, #initialize, #item_size, #to_a, #total_size
Constructor Details
This class inherits a constructor from Fontisan::Tables::Cff::Index
Instance Method Details
#all_charstrings(private_dict, global_subrs, local_subrs = nil) ⇒ Array<CharString>
Get all CharStrings as an array of CharString objects
This method interprets all CharStrings in the INDEX. Use with caution for fonts with many glyphs as this can be memory-intensive.
94 95 96 97 98 |
# File 'lib/fontisan/tables/cff/charstrings_index.rb', line 94 def all_charstrings(private_dict, global_subrs, local_subrs = nil) Array.new(count) do |i| charstring_at(i, private_dict, global_subrs, local_subrs) end end |
#charstring_at(index, private_dict, global_subrs, local_subrs = nil) ⇒ CharString?
Get a CharString object at the specified glyph index
This method retrieves the binary CharString data at the given index and interprets it as a Type 2 CharString program.
68 69 70 71 72 73 |
# File 'lib/fontisan/tables/cff/charstrings_index.rb', line 68 def charstring_at(index, private_dict, global_subrs, local_subrs = nil) data = self[index] return nil unless data CharString.new(data, private_dict, global_subrs, local_subrs) end |
#charstring_size(index) ⇒ Integer?
Get the size of a CharString in bytes
This returns the size of the binary CharString data without interpreting it.
153 154 155 |
# File 'lib/fontisan/tables/cff/charstrings_index.rb', line 153 def charstring_size(index) item_size(index) end |
#each_charstring(private_dict, global_subrs, local_subrs = nil) {|CharString, Integer| ... } ⇒ Enumerator
Iterate over each CharString in the INDEX
This method yields each CharString as it is interpreted, which is more memory-efficient than loading all at once.
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fontisan/tables/cff/charstrings_index.rb', line 116 def each_charstring(private_dict, global_subrs, local_subrs = nil) unless block_given? return enum_for(:each_charstring, private_dict, global_subrs, local_subrs) end count.times do |i| charstring = charstring_at(i, private_dict, global_subrs, local_subrs) yield charstring, i if charstring end end |
#glyph_count ⇒ Integer
Get the number of glyphs (CharStrings) in this INDEX
This is typically the same as the number of glyphs in the font.
134 135 136 |
# File 'lib/fontisan/tables/cff/charstrings_index.rb', line 134 def glyph_count count end |
#valid_glyph_index?(index) ⇒ Boolean
Check if a glyph index is valid
142 143 144 |
# File 'lib/fontisan/tables/cff/charstrings_index.rb', line 142 def valid_glyph_index?(index) index >= 0 && index < count end |