Class: Fontisan::Tables::Cff::Charset
- Inherits:
-
Object
- Object
- Fontisan::Tables::Cff::Charset
- Defined in:
- lib/fontisan/tables/cff/charset.rb
Overview
CFF Charset structure
Charset maps glyph IDs (GIDs) to glyph names via String IDs (SIDs).
GID 0 is always .notdef and is not included in the Charset data.
Three formats:
- Format 0: Array of SIDs, one per glyph (except .notdef)
- Format 1: Ranges with 8-bit nLeft counts
- Format 2: Ranges with 16-bit nLeft counts
Predefined charsets:
- 0: ISOAdobe charset (SIDs 0-228)
- 1: Expert charset
- 2: Expert Subset charset
Reference: CFF specification section 13 "Charsets" https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
Constant Summary collapse
- FORMATS =
Format identifiers
{ 0 => :array, 1 => :range_8, 2 => :range_16, }.freeze
- PREDEFINED =
Predefined charset identifiers
{ 0 => :iso_adobe, 1 => :expert, 2 => :expert_subset, }.freeze
Instance Attribute Summary collapse
-
#format_type ⇒ Integer
readonly
Charset format (0, 1, or 2).
-
#glyph_names ⇒ Array<String>
readonly
Glyph names indexed by GID.
Instance Method Summary collapse
-
#format ⇒ Symbol
Get the format symbol.
-
#glyph_id(name) ⇒ Integer?
Get GID for a glyph name.
-
#glyph_name(gid) ⇒ String?
Get glyph name for a GID.
-
#initialize(data, num_glyphs, cff_table) ⇒ Charset
constructor
Initialize a Charset.
Constructor Details
#initialize(data, num_glyphs, cff_table) ⇒ Charset
Initialize a Charset
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fontisan/tables/cff/charset.rb', line 58 def initialize(data, num_glyphs, cff_table) @num_glyphs = num_glyphs @cff_table = cff_table @glyph_names = [".notdef"] # GID 0 is always .notdef @glyph_name_to_id = { ".notdef" => 0 } if data.is_a?(Integer) && PREDEFINED.key?(data) load_predefined_charset(data) else @data = data parse! end end |
Instance Attribute Details
#format_type ⇒ Integer (readonly)
Returns Charset format (0, 1, or 2).
48 49 50 |
# File 'lib/fontisan/tables/cff/charset.rb', line 48 def format_type @format_type end |
#glyph_names ⇒ Array<String> (readonly)
Returns Glyph names indexed by GID.
51 52 53 |
# File 'lib/fontisan/tables/cff/charset.rb', line 51 def glyph_names @glyph_names end |
Instance Method Details
#format ⇒ Symbol
Get the format symbol
94 95 96 |
# File 'lib/fontisan/tables/cff/charset.rb', line 94 def format @format_type ? FORMATS[@format_type] : :predefined end |
#glyph_id(name) ⇒ Integer?
Get GID for a glyph name
86 87 88 |
# File 'lib/fontisan/tables/cff/charset.rb', line 86 def glyph_id(name) @glyph_name_to_id[name] end |
#glyph_name(gid) ⇒ String?
Get glyph name for a GID
76 77 78 79 80 |
# File 'lib/fontisan/tables/cff/charset.rb', line 76 def glyph_name(gid) return nil if gid.negative? || gid >= @glyph_names.size @glyph_names[gid] end |