Class: Fontisan::Stitcher::Deduplicator

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/stitcher/deduplicator.rb

Overview

Registry mapping glyph signatures to canonical glyph names in the target font. Enables signature-based deduplication: when two bindings produce glyphs with identical outlines, they share one gid and the duplicate's codepoint is redirected to the canonical glyph.

Replaces the Stitcher's previous name-based dedup with outline-based dedup. This merges visually identical glyphs from different donors even when their names differ, reducing the glyph count below the TrueType 65,535 cap.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeduplicator

Returns a new instance of Deduplicator.



18
19
20
# File 'lib/fontisan/stitcher/deduplicator.rb', line 18

def initialize
  @signatures = {}
end

Instance Attribute Details

#signaturesObject (readonly)

Returns the value of attribute signatures.



16
17
18
# File 'lib/fontisan/stitcher/deduplicator.rb', line 16

def signatures
  @signatures
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fontisan/stitcher/deduplicator.rb', line 42

def empty?
  @signatures.empty?
end

#find(glyph) ⇒ String?

Returns the canonical name if an identical glyph was already registered, nil otherwise.

Parameters:

Returns:

  • (String, nil)

    the canonical name if an identical glyph was already registered, nil otherwise



33
34
35
# File 'lib/fontisan/stitcher/deduplicator.rb', line 33

def find(glyph)
  @signatures[GlyphSignature.for(glyph)]
end

#register(glyph, canonical_name) ⇒ Object

Record that glyph maps to canonical_name in the target.

Parameters:

  • glyph (Fontisan::Ufo::Glyph)
  • canonical_name (String)

    the name under which the glyph was added to the target font



26
27
28
# File 'lib/fontisan/stitcher/deduplicator.rb', line 26

def register(glyph, canonical_name)
  @signatures[GlyphSignature.for(glyph)] = canonical_name
end

#sizeInteger

Returns number of unique signatures registered.

Returns:

  • (Integer)

    number of unique signatures registered



38
39
40
# File 'lib/fontisan/stitcher/deduplicator.rb', line 38

def size
  @signatures.size
end