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" https://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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 52 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.
43 44 45 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 43 def code_to_gid @code_to_gid end |
#format_type ⇒ Integer (readonly)
Returns Encoding format (0 or 1).
40 41 42 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 40 def format_type @format_type end |
#gid_to_code ⇒ Hash<Integer, Integer> (readonly)
Returns Map from GID to character code.
46 47 48 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 46 def gid_to_code @gid_to_code end |
Instance Method Details
#char_code(gid) ⇒ Integer?
Get character code for a GID
81 82 83 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 81 def char_code(gid) @gid_to_code[gid] end |
#format ⇒ Symbol
Get the format symbol
88 89 90 91 92 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 88 def format return :predefined unless @format_type @format_type.zero? ? :array : :range end |
#glyph_id(code) ⇒ Integer?
Get GID for a character code
73 74 75 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 73 def glyph_id(code) @code_to_gid[code] end |
#has_supplement? ⇒ Boolean
Check if encoding has supplement
97 98 99 |
# File 'lib/fontisan/tables/cff/encoding.rb', line 97 def has_supplement? @has_supplement || false end |