Class: Fontisan::Tables::Cff::Dict
- Inherits:
-
Object
- Object
- Fontisan::Tables::Cff::Dict
- Defined in:
- lib/fontisan/tables/cff/dict.rb
Overview
CFF DICT (Dictionary) structure parser
DICTs in CFF use a compact operand-operator format similar to PostScript. Operands are pushed onto a stack, then an operator consumes them.
Operand Encoding:
- 32-247: Small integers (values -107 to +107)
- 28: 3-byte signed integer follows
- 29: 5-byte signed integer follows
- 30: Real number (nibble-encoded)
- 247-254: 2-byte signed integers
- 255: Reserved
- 0-21, 22-27: Operators (single or two-byte)
Reference: CFF specification section 4 "DICT Data" https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
Direct Known Subclasses
Constant Summary collapse
- OPERATORS =
Common DICT operators shared across Top DICT and Private DICT
Key: operator byte(s), Value: operator name symbol
{ 0 => :version, 1 => :notice, 2 => :full_name, 3 => :family_name, 4 => :weight, [12, 0] => :copyright, [12, 1] => :is_fixed_pitch, [12, 2] => :italic_angle, [12, 3] => :underline_position, [12, 4] => :underline_thickness, [12, 5] => :paint_type, [12, 6] => :charstring_type, [12, 7] => :font_matrix, [12, 8] => :stroke_width, [12, 20] => :synthetic_base, [12, 21] => :postscript, [12, 22] => :base_font_name, [12, 23] => :base_font_blend, }.freeze
Instance Attribute Summary collapse
-
#data ⇒ String
readonly
Raw binary data of the DICT.
-
#dict ⇒ Hash
readonly
Parsed dictionary as key-value pairs.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Get a value from the dictionary by operator name.
-
#[]=(key, value) ⇒ Object
Set a value in the dictionary.
-
#empty? ⇒ Boolean
Check if DICT is empty.
-
#has_key?(key) ⇒ Boolean
Check if the dictionary contains a specific operator.
-
#initialize(data) ⇒ Dict
constructor
Initialize and parse a DICT from binary data.
-
#keys ⇒ Array<Symbol>
Get all operator names in this DICT.
-
#size ⇒ Integer
Number of entries in the DICT.
-
#to_h ⇒ Hash
Convert DICT to Hash.
-
#values ⇒ Array<Object>
Get all values in this DICT.
Constructor Details
#initialize(data) ⇒ Dict
Initialize and parse a DICT from binary data
64 65 66 67 68 69 |
# File 'lib/fontisan/tables/cff/dict.rb', line 64 def initialize(data) @data = data.is_a?(String) ? data : data.read @dict = {} @io = StringIO.new(@data) parse! end |
Instance Attribute Details
#data ⇒ String (readonly)
Returns Raw binary data of the DICT.
59 60 61 |
# File 'lib/fontisan/tables/cff/dict.rb', line 59 def data @data end |
#dict ⇒ Hash (readonly)
Returns Parsed dictionary as key-value pairs.
56 57 58 |
# File 'lib/fontisan/tables/cff/dict.rb', line 56 def dict @dict end |
Instance Method Details
#[](key) ⇒ Object?
Get a value from the dictionary by operator name
75 76 77 |
# File 'lib/fontisan/tables/cff/dict.rb', line 75 def [](key) @dict[key] end |
#[]=(key, value) ⇒ Object
Set a value in the dictionary
83 84 85 |
# File 'lib/fontisan/tables/cff/dict.rb', line 83 def []=(key, value) @dict[key] = value end |
#empty? ⇒ Boolean
Check if DICT is empty
126 127 128 |
# File 'lib/fontisan/tables/cff/dict.rb', line 126 def empty? @dict.empty? end |
#has_key?(key) ⇒ Boolean
Check if the dictionary contains a specific operator
91 92 93 |
# File 'lib/fontisan/tables/cff/dict.rb', line 91 def has_key?(key) @dict.key?(key) end |
#keys ⇒ Array<Symbol>
Get all operator names in this DICT
98 99 100 |
# File 'lib/fontisan/tables/cff/dict.rb', line 98 def keys @dict.keys end |
#size ⇒ Integer
Number of entries in the DICT
119 120 121 |
# File 'lib/fontisan/tables/cff/dict.rb', line 119 def size @dict.size end |
#to_h ⇒ Hash
Convert DICT to Hash
112 113 114 |
# File 'lib/fontisan/tables/cff/dict.rb', line 112 def to_h @dict.dup end |
#values ⇒ Array<Object>
Get all values in this DICT
105 106 107 |
# File 'lib/fontisan/tables/cff/dict.rb', line 105 def values @dict.values end |