Module: Fontisan::Ufo::Compile::Filters::RemoveOverlaps
- Defined in:
- lib/fontisan/ufo/compile/filters/remove_overlaps.rb
Overview
Boolean union of overlapping contours within each glyph. Two contours that overlap visually are merged into one, removing the seam. Required for some hinting programs and for SVG/COLR rendering correctness.
Why bounding-box approximation, not polygon clipping
Full polygon clipping (Greiner-Hormann or Vatti) operates on straight-line polygons. UFO contours are Bezier curves. Applying polygon clipping would require:
1. Flatten Bezier to polygon edges (tessellation).
2. Run polygon clipping (union).
3. Re-fit Bezier curves on the result (curve fitting).
Step 3 is the killer: curve fitting is lossy. The output curves won't match the input curves' control points, changing the glyph's rendering at small sizes. For a font pipeline, preserving curve fidelity matters more than mathematical union correctness.
The bounding-box approximation handles the common cases
(overlapping duplicates, fully-contained sub-contours)
without losing any curve data. It does NOT handle partial
overlaps — those remain as separate contours. For fonts
that need partial-overlap removal, preprocess in an editor
(FontLab, Glyphs) or use the clipper gem as a pre-compile
step with explicit curve-flattening tolerances.
Class Method Summary collapse
-
.run(glyphs, **_opts) ⇒ Array<Fontisan::Ufo::Glyph>
The same array, mutated in place.
Class Method Details
.run(glyphs, **_opts) ⇒ Array<Fontisan::Ufo::Glyph>
Returns the same array, mutated in place.
38 39 40 41 |
# File 'lib/fontisan/ufo/compile/filters/remove_overlaps.rb', line 38 def self.run(glyphs, **_opts) glyphs.each { |g| remove_overlaps_in_glyph(g) } glyphs end |