Class: Fontisan::Hints::HintConverter

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

Overview

Converts hints between TrueType and PostScript formats

This converter handles bidirectional conversion of rendering hints, translating between TrueType instruction-based hinting and PostScript operator-based hinting while preserving intent where possible.

**Conversion Strategy:**

  • TrueType → PostScript: Extract semantic meaning from instructions and convert to corresponding PostScript operators

  • PostScript → TrueType: Analyze hint operators and generate equivalent TrueType instructions

Examples:

Convert TrueType hints to PostScript

converter = HintConverter.new
ps_hints = converter.to_postscript(tt_hints)

Convert PostScript hints to TrueType

converter = HintConverter.new
tt_hints = converter.to_truetype(ps_hints)

Instance Method Summary collapse

Instance Method Details

#optimize(hints) ⇒ Array<Hint>

Optimize hint set by removing redundant hints

Parameters:

  • hints (Array<Hint>)

    Hints to optimize

Returns:

  • (Array<Hint>)

    Optimized hints



60
61
62
63
64
65
66
67
68
# File 'lib/fontisan/hints/hint_converter.rb', line 60

def optimize(hints)
  return [] if hints.nil? || hints.empty?

  # Remove duplicate hints
  unique_hints = hints.uniq { |h| [h.type, h.data] }

  # Remove conflicting hints (keep first)
  remove_conflicts(unique_hints)
end

#to_postscript(hints) ⇒ Array<Hint>

Convert hints to PostScript format

Parameters:

  • hints (Array<Hint>)

    Source hints (any format)

Returns:

  • (Array<Hint>)

    Hints in PostScript format



32
33
34
35
36
37
38
39
40
# File 'lib/fontisan/hints/hint_converter.rb', line 32

def to_postscript(hints)
  return [] if hints.nil? || hints.empty?

  hints.map do |hint|
    next hint if hint.source_format == :postscript

    convert_hint_to_postscript(hint)
  end.compact
end

#to_truetype(hints) ⇒ Array<Hint>

Convert hints to TrueType format

Parameters:

  • hints (Array<Hint>)

    Source hints (any format)

Returns:

  • (Array<Hint>)

    Hints in TrueType format



46
47
48
49
50
51
52
53
54
# File 'lib/fontisan/hints/hint_converter.rb', line 46

def to_truetype(hints)
  return [] if hints.nil? || hints.empty?

  hints.map do |hint|
    next hint if hint.source_format == :truetype

    convert_hint_to_truetype(hint)
  end.compact
end