Class: Fontisan::Tables::Cff::HintOperationInjector

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/tables/cff/hint_operation_injector.rb

Overview

Injects hint operations into CharString operation lists

HintOperationInjector converts abstract Hint objects into CFF CharString operations and injects them at the appropriate position. It handles:

  • Stem hints (hstem, vstem, hstemhm, vstemhm)
  • Hint masks (hintmask with mask data)
  • Counter masks (cntrmask with mask data)
  • Stack management (hints are stack-neutral)

Position Rules:

  • Hints must appear BEFORE any path construction operators
  • Width (if present) comes first
  • Stem hints come before hintmask/cntrmask
  • Once path construction begins, no more hints allowed

Stack Neutrality:

  • Hint operators consume their operands
  • They don't leave anything on the stack
  • Path construction starts with clean stack

Reference: Type 2 CharString Format Section 4 Adobe Technical Note #5177

Examples:

Inject hints into a glyph

injector = HintOperationInjector.new
hints = [
  Hint.new(type: :stem, data: { position: 100, width: 50, orientation: :horizontal })
]
modified_ops = injector.inject(hints, original_operations)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHintOperationInjector

Initialize injector



37
38
39
# File 'lib/fontisan/tables/cff/hint_operation_injector.rb', line 37

def initialize
  @stem_count = 0
end

Instance Attribute Details

#stem_countInteger (readonly)

Get stem count after injection (needed for hintmask)

Returns:

  • (Integer)

    Number of stem hints



63
64
65
# File 'lib/fontisan/tables/cff/hint_operation_injector.rb', line 63

def stem_count
  @stem_count
end

Instance Method Details

#inject(hints, operations) ⇒ Array<Hash>

Inject hint operations into operation list

Parameters:

  • hints (Array<Models::Hint>)

    Hints to inject

  • operations (Array<Hash>)

    Original CharString operations

Returns:

  • (Array<Hash>)

    Modified operations with hints injected



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fontisan/tables/cff/hint_operation_injector.rb', line 46

def inject(hints, operations)
  return operations if hints.nil? || hints.empty?

  # Convert hints to operations
  hint_ops = convert_hints_to_operations(hints)
  return operations if hint_ops.empty?

  # Find injection point (before first path operator)
  inject_index = find_injection_point(operations)

  # Insert hint operations
  operations.dup.insert(inject_index, *hint_ops)
end