Module: Fontisan::Ufo::Compile::Filters

Defined in:
lib/fontisan/ufo/compile/filters.rb,
lib/fontisan/ufo/compile/filters/sort_contours.rb,
lib/fontisan/ufo/compile/filters/remove_overlaps.rb,
lib/fontisan/ufo/compile/filters/transformations.rb,
lib/fontisan/ufo/compile/filters/propagate_anchors.rb,
lib/fontisan/ufo/compile/filters/cubic_to_quadratic.rb,
lib/fontisan/ufo/compile/filters/flatten_components.rb,
lib/fontisan/ufo/compile/filters/decompose_components.rb,
lib/fontisan/ufo/compile/filters/reverse_contour_direction.rb

Overview

Glyph-processing filters applied between the UFO model and the binary table compilers. Each filter is a stateless module with .run(glyphs, **opts) that mutates the glyph list (or returns a new one).

OCP: adding a filter = new module + one REGISTRY entry. The compiler picks which filters to run based on the output format — not a switch statement in compiler code.

Defined Under Namespace

Modules: CubicToQuadratic, DecomposeComponents, FlattenComponents, PropagateAnchors, RemoveOverlaps, ReverseContourDirection, SortContours, Transformations

Constant Summary collapse

TTF_REQUIRED =

Filters that MUST run for TTF output (TrueType only supports quadratic curves + clockwise outer winding).

%i[
  cubic_to_quadratic
  reverse_contour_direction
].freeze
OTF_REQUIRED =

Filters that MUST run for OTF output (CFF handles cubic natively, so no curve conversion needed; winding is already correct for PostScript).

[].freeze
REGISTRY =
{
  reverse_contour_direction: ReverseContourDirection,
  cubic_to_quadratic: CubicToQuadratic,
  decompose_components: DecomposeComponents,
  flatten_components: FlattenComponents,
  transformations: Transformations,
  sort_contours: SortContours,
  propagate_anchors: PropagateAnchors,
  remove_overlaps: RemoveOverlaps,
}.freeze

Class Method Summary collapse

Class Method Details

.apply(names, glyphs) ⇒ Array<Fontisan::Ufo::Glyph>

Returns the (possibly mutated) glyphs.

Parameters:

  • names (Array<Symbol>)

    filter names from REGISTRY

  • glyphs (Array<Fontisan::Ufo::Glyph>)

    glyphs to filter

  • opts (Hash)

    per-filter options

Returns:



59
60
61
62
63
64
65
# File 'lib/fontisan/ufo/compile/filters.rb', line 59

def self.apply(names, glyphs, **)
  Array(names).reduce(glyphs) do |current, name|
    klass = REGISTRY[name.to_sym] or
      raise ArgumentError, "unknown filter: #{name.inspect}"
    klass.run(current, **)
  end
end