Class: Fontisan::Models::HintSet

Inherits:
Object
  • Object
show all
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.

Examples:

Creating a HintSet

hint_set = HintSet.new(
  format: :truetype,
  font_program: fpgm_data,
  control_value_program: prep_data
)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • format (String, Symbol) (defaults to: nil)

    Hint format (:truetype or :postscript)

  • font_program (String) (defaults to: "")

    Font program bytecode

  • control_value_program (String) (defaults to: "")

    Control value program bytecode

  • control_values (Array<Integer>) (defaults to: [])

    Control values

  • private_dict_hints (String) (defaults to: "{}")

    Private dict hints as JSON

  • hinted_glyph_count (Integer) (defaults to: 0)

    Number of hinted glyphs

  • has_hints (Boolean) (defaults to: false)

    Whether hints are present



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_programString

Returns Control value program (prep table) - initialization code.

Returns:

  • (String)

    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_valuesArray<Integer>

Returns Control values (cvt table) - metrics for hinting.

Returns:

  • (Array<Integer>)

    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_programString

TrueType font-level hint data

Returns:

  • (String)

    Font program (fpgm table) - bytecode executed once



26
27
28
# File 'lib/fontisan/models/hint.rb', line 26

def font_program
  @font_program
end

#formatString

Returns Hint format (:truetype or :postscript).

Returns:

  • (String)

    Hint format (:truetype or :postscript)



22
23
24
# File 'lib/fontisan/models/hint.rb', line 22

def format
  @format
end

#has_hintsBoolean

Returns Whether hints are present.

Returns:

  • (Boolean)

    Whether hints are present



42
43
44
# File 'lib/fontisan/models/hint.rb', line 42

def has_hints
  @has_hints
end

#hinted_glyph_countInteger

Returns Number of glyphs with hints.

Returns:

  • (Integer)

    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_hintsString

PostScript font-level hint data

Returns:

  • (String)

    CFF Private dict hint data (BlueValues, StdHW, etc.) as JSON



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

Parameters:

  • glyph_id (Integer, String)

    Glyph identifier

  • hints (Array<Hint>)

    Hints for the 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)

Returns:

  • (Boolean)

    True if no hints present



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

Parameters:

  • glyph_id (Integer, String)

    Glyph identifier

Returns:

  • (Array<Hint>)

    Hints for the 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_idsArray<String>

Get all glyph IDs with hints

Returns:

  • (Array<String>)

    Glyph identifiers



104
105
106
# File 'lib/fontisan/models/hint.rb', line 104

def hinted_glyph_ids
  parse_glyph_hints.keys
end