Module: Fontisan::Stitcher::UniqueGlyphName
- Defined in:
- lib/fontisan/stitcher/unique_glyph_name.rb
Overview
Stateless glyph-name deconfliction for the Stitcher's target UFO.
The Layer's contract (see Ufo::Layer) is that two glyphs cannot
share a name — #add raises on conflict. Most Stitcher call sites
already know the name they want is free (e.g. they just synthesised
it). The two that don't — GlyphCopier (outline donors may share
post-table names) and CbdtPropagator (placeholders named "gidN"
collide with outline glyphs sharing the same donor-gid scheme) —
ask this helper to allocate a non-colliding name first.
Centralising the rule here keeps the deconfliction algorithm in one place: the suffix-search loop, the separator, the order in which candidates are tried. Changing the rule (e.g. to a UUID scheme) is a one-file edit.
Constant Summary collapse
- SUFFIX_SEPARATOR =
Separator between the base name and the disambiguating suffix. A literal period so the generated name ("gid110.1") still reads as a variant of the original.
"."
Class Method Summary collapse
-
.in(target, base_name) ⇒ String
base_nameunchanged if no glyph with that name exists intarget.glyphs; otherwise the first"base.1","base.2", ...
Class Method Details
.in(target, base_name) ⇒ String
Returns base_name unchanged if no glyph with that
name exists in target.glyphs; otherwise the first
"base.1", "base.2", ... that does not exist.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fontisan/stitcher/unique_glyph_name.rb', line 32 def self.in(target, base_name) base = base_name.to_s return base unless target.glyphs.key?(base) suffix = 1 loop do candidate = "#{base}#{SUFFIX_SEPARATOR}#{suffix}" return candidate unless target.glyphs.key?(candidate) suffix += 1 end end |