Class: Fontisan::Models::Hint
- Inherits:
-
Object
- Object
- Fontisan::Models::Hint
- Defined in:
- lib/fontisan/models/hint.rb
Overview
Universal hint representation supporting both TrueType and PostScript hints
Hints are instructions that improve font rendering at small sizes by providing information about how to align features to the pixel grid. This model provides a format-agnostic representation that can be converted between TrueType instructions and PostScript hint operators.
**Hint Types:**
-
‘:stem` - Vertical or horizontal stem hints (PostScript hstem/vstem)
-
‘:stem3` - Multiple stem hints (PostScript hstem3/vstem3)
-
‘:flex` - Flex hints for smooth curves (PostScript flex)
-
‘:counter` - Counter control hints (PostScript counter)
-
‘:hint_replacement` - Hint replacement (PostScript hintmask)
-
‘:delta` - Delta hints for pixel-level adjustments (TrueType DELTA)
-
‘:interpolate` - Interpolation hints (TrueType IUP)
-
‘:shift` - Shift hints (TrueType SHP)
-
‘:align` - Alignment hints (TrueType ALIGNRP)
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Hint-specific data.
-
#source_format ⇒ Symbol
readonly
Source format (:truetype or :postscript).
-
#type ⇒ Symbol
readonly
Hint type.
Instance Method Summary collapse
-
#compatible_with?(format) ⇒ Boolean
Check if hint is compatible with target format.
-
#initialize(type:, data:, source_format: nil) ⇒ Hint
constructor
Initialize a new hint.
-
#to_postscript ⇒ Hash
Convert hint to PostScript hint format.
-
#to_truetype ⇒ Array<Integer>
Convert hint to TrueType instruction format.
Constructor Details
#initialize(type:, data:, source_format: nil) ⇒ Hint
Initialize a new hint
50 51 52 53 54 |
# File 'lib/fontisan/models/hint.rb', line 50 def initialize(type:, data:, source_format: nil) @type = type @data = data @source_format = source_format end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns Hint-specific data.
40 41 42 |
# File 'lib/fontisan/models/hint.rb', line 40 def data @data end |
#source_format ⇒ Symbol (readonly)
Returns Source format (:truetype or :postscript).
43 44 45 |
# File 'lib/fontisan/models/hint.rb', line 43 def source_format @source_format end |
#type ⇒ Symbol (readonly)
Returns Hint type.
37 38 39 |
# File 'lib/fontisan/models/hint.rb', line 37 def type @type end |
Instance Method Details
#compatible_with?(format) ⇒ Boolean
Check if hint is compatible with target format
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fontisan/models/hint.rb', line 115 def compatible_with?(format) case format when :truetype # Most PostScript hints can be converted to TrueType %i[stem flex counter delta interpolate shift align].include?(type) when :postscript # Most TrueType hints can be approximated in PostScript %i[stem stem3 flex counter hint_replacement].include?(type) else false end end |
#to_postscript ⇒ Hash
Convert hint to PostScript hint format
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fontisan/models/hint.rb', line 88 def to_postscript case type when :stem convert_stem_to_postscript when :stem3 convert_stem3_to_postscript when :flex convert_flex_to_postscript when :counter convert_counter_to_postscript when :hint_replacement # Hintmask operator { operator: :hintmask, args: data[:mask] || [] } when :delta, :interpolate, :shift, :align # TrueType-specific hints don't have direct PS equivalents # Return approximation using stem hints approximate_as_postscript else # Unknown hint type {} end end |
#to_truetype ⇒ Array<Integer>
Convert hint to TrueType instruction format
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fontisan/models/hint.rb', line 59 def to_truetype case type when :stem convert_stem_to_truetype when :flex convert_flex_to_truetype when :counter convert_counter_to_truetype when :delta # Already in TrueType format data[:instructions] || [] when :interpolate # IUP instruction [0x30] # IUP[y], or [0x31] for IUP[x] when :shift # SHP instruction data[:instructions] || [] when :align # ALIGNRP instruction [0x3C] else # Unknown hint type - return empty [] end end |