Class: Fontisan::Tables::Cff::Encoding
- Inherits:
-
Object
- Object
- Fontisan::Tables::Cff::Encoding
- Defined in:
- lib/fontisan/tables/cff/encoding.rb
Overview
CFF Encoding structure
Encoding maps character codes to glyph IDs (GIDs). GID 0 (.notdef) is not encoded.
Three formats:
-
Format 0: Array of codes (one per glyph)
-
Format 1: Ranges of consecutive codes
-
Format 0/1 with supplement: Format 0 or 1 with additional mappings
Predefined encodings:
-
0: Standard encoding (Adobe standard character set)
-
1: Expert encoding (Adobe expert character set)
Reference: CFF specification section 14 “Encodings” adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
Constant Summary collapse
- PREDEFINED =
Predefined encoding identifiers
{ 0 => :standard, 1 => :expert, }.freeze
- FORMAT_MASK =
Format mask to extract format type
0x7F
Instance Attribute Summary collapse
-
#code_to_gid ⇒ Hash<Integer, Integer>
readonly
Map from character code to GID.
-
#format_type ⇒ Integer
readonly
Encoding format (0 or 1).
-
#gid_to_code ⇒ Hash<Integer, Integer>
readonly
Map from GID to character code.
Instance Method Summary collapse
-
#char_code(gid) ⇒ Integer?
Get character code for a GID.
-
#format ⇒ Symbol
Get the format symbol.
-
#glyph_id(code) ⇒ Integer?
Get GID for a character code.
-
#has_supplement? ⇒ Boolean
Check if encoding has supplement.
-
#initialize(data, num_glyphs) ⇒ Encoding
constructor
Initialize an Encoding.
Constructor Details
#initialize(data, num_glyphs) ⇒ Encoding
Initialize an Encoding
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 53 def initialize(data, num_glyphs) @num_glyphs = num_glyphs @code_to_gid = {} @gid_to_code = {} # GID 0 (.notdef) is always at code 0 @code_to_gid[0] = 0 @gid_to_code[0] = 0 if data.is_a?(Integer) && PREDEFINED.key?(data) load_predefined_encoding(data) else @data = data parse! end end |
Instance Attribute Details
#code_to_gid ⇒ Hash<Integer, Integer> (readonly)
Returns Map from character code to GID.
44 45 46 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 44 def code_to_gid @code_to_gid end |
#format_type ⇒ Integer (readonly)
Returns Encoding format (0 or 1).
41 42 43 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 41 def format_type @format_type end |
#gid_to_code ⇒ Hash<Integer, Integer> (readonly)
Returns Map from GID to character code.
47 48 49 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 47 def gid_to_code @gid_to_code end |
Instance Method Details
#char_code(gid) ⇒ Integer?
Get character code for a GID
82 83 84 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 82 def char_code(gid) @gid_to_code[gid] end |
#format ⇒ Symbol
Get the format symbol
89 90 91 92 93 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 89 def format return :predefined unless @format_type @format_type.zero? ? :array : :range end |
#glyph_id(code) ⇒ Integer?
Get GID for a character code
74 75 76 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 74 def glyph_id(code) @code_to_gid[code] end |
#has_supplement? ⇒ Boolean
Check if encoding has supplement
98 99 100 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 98 def has_supplement? @has_supplement || false end |