alexheretic / ab-glyph

Rust API for loading, scaling, positioning and rasterizing OpenType font glyphs
Apache License 2.0
372 stars 24 forks source link

Allow using different fill methods for Rasterizer (odd, positive/negative) #56

Open LoganDark opened 2 years ago

LoganDark commented 2 years ago

Right now the rasterizer uses a nonzero filling method, which is convenient for many cases. It would be nice if it also provided an odd filling method, as well as positive/negative

alexheretic commented 2 years ago

The rasterizer returns [0.0, 1.0] f32 coverage to represent how much a glyph covers any given square in a grid.

Can you explain what odd, positive/negative means in this context?

LoganDark commented 2 years ago

Can you explain what odd, positive/negative means in this context?

Winding count. AFAICT, counter-clockwise winding order causes the area inside the shape to increase by one in winding count, and then creating another shape inside with clockwise winding order decreases the winding count again. Pixel coverage is calculated by what percentage of the pixel has the winding count you want (in this case, nonzero - winding counts 1,2,3.. and -1,-2,-3... count as covering the pixel).

image

(I might have my clockwises backward - but this is what I observe with font rendering)

Sometimes it's useful to use odd instead, which is what SVG rendering uses. Sometimes you want only positive or only negative.

LoganDark commented 2 years ago

Come to think of it, I haven't actually checked if c can be outside the 0.0-1.0 range. If it can go above and below by layering additional shapes then I would consider this issue closed. Then I can implement any fill mode I want, including CSG