Class: Fontisan::Models::HintSet
- Inherits:
-
Object
- Object
- Fontisan::Models::HintSet
- Defined in:
- lib/fontisan/models/hint.rb
Overview
Container for all font hint data
This model holds complete hint information from a font including font-level programs, control values, and per-glyph hints. It provides a format-agnostic representation that can be converted between TrueType and PostScript formats.
Instance Attribute Summary collapse
-
#control_value_program ⇒ String
Control value program (prep table) - initialization code.
-
#control_values ⇒ Array<Integer>
Control values (cvt table) - metrics for hinting.
-
#font_program ⇒ String
TrueType font-level hint data.
-
#format ⇒ String
Hint format (:truetype or :postscript).
-
#has_hints ⇒ Boolean
Whether hints are present.
-
#hinted_glyph_count ⇒ Integer
Number of glyphs with hints.
-
#private_dict_hints ⇒ String
PostScript font-level hint data.
Instance Method Summary collapse
-
#add_glyph_hints(glyph_id, hints) ⇒ Object
Add hints for a specific glyph.
-
#empty? ⇒ Boolean
Check if empty (no hints).
-
#get_glyph_hints(glyph_id) ⇒ Array<Hint>
Get hints for a specific glyph.
-
#hinted_glyph_ids ⇒ Array<String>
Get all glyph IDs with hints.
-
#initialize(format: nil, font_program: "", control_value_program: "", control_values: [], private_dict_hints: "{}", hinted_glyph_count: 0, has_hints: false) ⇒ HintSet
constructor
Initialize a new HintSet.
Constructor Details
#initialize(format: nil, font_program: "", control_value_program: "", control_values: [], private_dict_hints: "{}", hinted_glyph_count: 0, has_hints: false) ⇒ HintSet
Initialize a new HintSet
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fontisan/models/hint.rb', line 53 def initialize(format: nil, font_program: "", control_value_program: "", control_values: [], private_dict_hints: "{}", hinted_glyph_count: 0, has_hints: false) @format = format.to_s if format @font_program = font_program || "" @control_value_program = control_value_program || "" @control_values = control_values || [] @private_dict_hints = private_dict_hints || "{}" @glyph_hints = "{}" @hinted_glyph_count = hinted_glyph_count @has_hints = has_hints end |
Instance Attribute Details
#control_value_program ⇒ String
Returns Control value program (prep table) - initialization code.
29 30 31 |
# File 'lib/fontisan/models/hint.rb', line 29 def control_value_program @control_value_program end |
#control_values ⇒ Array<Integer>
Returns Control values (cvt table) - metrics for hinting.
32 33 34 |
# File 'lib/fontisan/models/hint.rb', line 32 def control_values @control_values end |
#font_program ⇒ String
TrueType font-level hint data
26 27 28 |
# File 'lib/fontisan/models/hint.rb', line 26 def font_program @font_program end |
#format ⇒ String
Returns Hint format (:truetype or :postscript).
22 23 24 |
# File 'lib/fontisan/models/hint.rb', line 22 def format @format end |
#has_hints ⇒ Boolean
Returns Whether hints are present.
42 43 44 |
# File 'lib/fontisan/models/hint.rb', line 42 def has_hints @has_hints end |
#hinted_glyph_count ⇒ Integer
Returns Number of glyphs with hints.
39 40 41 |
# File 'lib/fontisan/models/hint.rb', line 39 def hinted_glyph_count @hinted_glyph_count end |
#private_dict_hints ⇒ String
PostScript font-level hint data
36 37 38 |
# File 'lib/fontisan/models/hint.rb', line 36 def private_dict_hints @private_dict_hints end |
Instance Method Details
#add_glyph_hints(glyph_id, hints) ⇒ Object
Add hints for a specific glyph
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fontisan/models/hint.rb', line 70 def add_glyph_hints(glyph_id, hints) return if hints.nil? || hints.empty? glyph_hints_hash = parse_glyph_hints # Convert Hint objects to hashes for storage hints_data = hints.map do |h| { type: h.type, data: h.data, source_format: h.source_format, } end glyph_hints_hash[glyph_id.to_s] = hints_data @glyph_hints = glyph_hints_hash.to_json @hinted_glyph_count = glyph_hints_hash.keys.length @has_hints = true end |
#empty? ⇒ Boolean
Check if empty (no hints)
111 112 113 114 115 116 117 |
# File 'lib/fontisan/models/hint.rb', line 111 def empty? !has_hints && (font_program.nil? || font_program.empty?) && (control_value_program.nil? || control_value_program.empty?) && (control_values.nil? || control_values.empty?) && (private_dict_hints.nil? || private_dict_hints == "{}") end |
#get_glyph_hints(glyph_id) ⇒ Array<Hint>
Get hints for a specific glyph
92 93 94 95 96 97 98 99 |
# File 'lib/fontisan/models/hint.rb', line 92 def get_glyph_hints(glyph_id) glyph_hints_hash = parse_glyph_hints hints_data = glyph_hints_hash[glyph_id.to_s] return [] unless hints_data # Reconstruct Hint objects from serialized data hints_data.map { |h| Hint.new(**h.transform_keys(&:to_sym)) } end |
#hinted_glyph_ids ⇒ Array<String>
Get all glyph IDs with hints
104 105 106 |
# File 'lib/fontisan/models/hint.rb', line 104 def hinted_glyph_ids parse_glyph_hints.keys end |