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
179 180 181 182 183 |
# File 'lib/fontisan/models/hint.rb', line 179 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.
169 170 171 |
# File 'lib/fontisan/models/hint.rb', line 169 def data @data end |
#source_format ⇒ Symbol (readonly)
Returns Source format (:truetype or :postscript).
172 173 174 |
# File 'lib/fontisan/models/hint.rb', line 172 def source_format @source_format end |
#type ⇒ Symbol (readonly)
Returns Hint type.
166 167 168 |
# File 'lib/fontisan/models/hint.rb', line 166 def type @type end |
Instance Method Details
#compatible_with?(format) ⇒ Boolean
Check if hint is compatible with target format
255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/fontisan/models/hint.rb', line 255 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
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/fontisan/models/hint.rb', line 225 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 rescue StandardError => e warn "Error converting hint type #{type} to PostScript: #{e.}" {} end |
#to_truetype ⇒ Array<Integer>
Convert hint to TrueType instruction format
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/fontisan/models/hint.rb', line 188 def to_truetype case type when :stem convert_stem_to_truetype when :stem3 convert_stem3_to_truetype when :flex convert_flex_to_truetype when :counter convert_counter_to_truetype when :hint_replacement convert_hintmask_to_truetype when :delta # Already in TrueType format data[:instructions] || [] when :interpolate # IUP instruction axis = data[:axis] || :y axis == :x ? [0x31] : [0x30] # IUP[x] or IUP[y] when :shift # SHP instruction data[:instructions] || [] when :align # ALIGNRP instruction [0x3C] else # Unknown hint type - return empty [] end rescue StandardError => e warn "Error converting hint type #{type} to TrueType: #{e.}" [] end |