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” 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
65 66 67 68 69 70 |
# File 'lib/fontisan/tables/cff/dict.rb', line 65 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.
60 61 62 |
# File 'lib/fontisan/tables/cff/dict.rb', line 60 def data @data end |
#dict ⇒ Hash (readonly)
Returns Parsed dictionary as key-value pairs.
57 58 59 |
# File 'lib/fontisan/tables/cff/dict.rb', line 57 def dict @dict end |
Instance Method Details
#[](key) ⇒ Object?
Get a value from the dictionary by operator name
76 77 78 |
# File 'lib/fontisan/tables/cff/dict.rb', line 76 def [](key) @dict[key] end |
#[]=(key, value) ⇒ Object
Set a value in the dictionary
84 85 86 |
# File 'lib/fontisan/tables/cff/dict.rb', line 84 def []=(key, value) @dict[key] = value end |
#empty? ⇒ Boolean
Check if DICT is empty
127 128 129 |
# File 'lib/fontisan/tables/cff/dict.rb', line 127 def empty? @dict.empty? end |
#has_key?(key) ⇒ Boolean
Check if the dictionary contains a specific operator
92 93 94 |
# File 'lib/fontisan/tables/cff/dict.rb', line 92 def has_key?(key) @dict.key?(key) end |
#keys ⇒ Array<Symbol>
Get all operator names in this DICT
99 100 101 |
# File 'lib/fontisan/tables/cff/dict.rb', line 99 def keys @dict.keys end |
#size ⇒ Integer
Number of entries in the DICT
120 121 122 |
# File 'lib/fontisan/tables/cff/dict.rb', line 120 def size @dict.size end |
#to_h ⇒ Hash
Convert DICT to Hash
113 114 115 |
# File 'lib/fontisan/tables/cff/dict.rb', line 113 def to_h @dict.dup end |
#values ⇒ Array<Object>
Get all values in this DICT
106 107 108 |
# File 'lib/fontisan/tables/cff/dict.rb', line 106 def values @dict.values end |