Class: Fontisan::Hints::TrueTypeHintApplier

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/hints/truetype_hint_applier.rb

Overview

Applies rendering hints to TrueType font tables

This applier writes TrueType hint data into font-level tables:

  • fpgm (Font Program) - bytecode executed once at font initialization

  • prep (Control Value Program) - bytecode for glyph preparation

  • cvt (Control Values) - array of 16-bit values for hinting metrics

The applier ensures proper table structure with correct checksums and does not corrupt the font if hint application fails.

Examples:

Apply hints from a HintSet

applier = TrueTypeHintApplier.new
tables = {}
updated_tables = applier.apply(hint_set, tables)

Instance Method Summary collapse

Instance Method Details

#apply(hint_set, tables) ⇒ Hash

Apply TrueType hints to font tables

Parameters:

  • hint_set (HintSet)

    Hint data to apply

  • tables (Hash)

    Font tables to update

Returns:

  • (Hash)

    Updated font tables



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fontisan/hints/truetype_hint_applier.rb', line 25

def apply(hint_set, tables)
  return tables if hint_set.nil? || hint_set.empty?
  return tables unless hint_set.format == "truetype"

  # Write fpgm table if present
  if hint_set.font_program && !hint_set.font_program.empty?
    tables["fpgm"] = build_fpgm_table(hint_set.font_program)
  end

  # Write prep table if present
  if hint_set.control_value_program && !hint_set.control_value_program.empty?
    tables["prep"] = build_prep_table(hint_set.control_value_program)
  end

  # Write cvt table if present
  if hint_set.control_values && !hint_set.control_values.empty?
    tables["cvt "] = build_cvt_table(hint_set.control_values)
  end

  # Future enhancement: Apply per-glyph hints to glyf table
  # For now, font-level tables only

  tables
end