Module: Fontisan::Ufo::Compile::Filters::CubicToQuadratic
- Defined in:
- lib/fontisan/ufo/compile/filters/cubic_to_quadratic.rb
Overview
Converts cubic Bezier curves to quadratic. TrueType outlines only support quadratic Beziers; UFO sources typically use cubic. This filter walks each contour, finds cubic segments (two consecutive off-curve points followed by an on-curve), and replaces them with one or more quadratic approximations.
Algorithm (fontTools-compatible):
For cubic (P0, C1, C2, P3):
Q1 = (3*C1 - P0) / 2
Q2 = (3*C2 - P3) / 2
Q = midpoint(Q1, Q2)
Error ≈ |Q1 - Q2| / 3
If error ≤ tolerance: emit one quadratic (P0, Q, P3)
Else: subdivide at t=0.5, recurse each half.
Constant Summary collapse
- DEFAULT_TOLERANCE =
1.0
Class Method Summary collapse
-
.run(glyphs, tolerance: DEFAULT_TOLERANCE, **_opts) ⇒ Array<Fontisan::Ufo::Glyph>
The same array, mutated.
Class Method Details
.run(glyphs, tolerance: DEFAULT_TOLERANCE, **_opts) ⇒ Array<Fontisan::Ufo::Glyph>
Returns the same array, mutated.
27 28 29 30 31 32 33 34 |
# File 'lib/fontisan/ufo/compile/filters/cubic_to_quadratic.rb', line 27 def self.run(glyphs, tolerance: DEFAULT_TOLERANCE, **_opts) glyphs.each do |glyph| glyph.contours.each_with_index do |contour, _ci| contour.points = convert_contour(contour.points, tolerance) end end glyphs end |