v1.2.0

Curves and polygons

A GPU rasterizer that evaluates curves in a shader wants quadratics only, and one that walks straight edges wants polygons. daegun gives either.

Quadratic curves

let curves = font.glyph_quads(gid, &[])?;
// 32 curves for Inter's W, each [start, control, end] in em units, wound clockwise

Em units are font units over upm, y up. Lines come back as curves with their control at the midpoint, and cubics are split to within about 1/4096 em. QuadraticPen does the same for any outline, and normalize_winding rewinds a set of curves.

Polygons

use daegun::{flatten, max_area_for, resolve_overlaps, Path};

let mut units = Path::default();
font.outline_glyph(gid, &mut units).expect("is in the font");
let polygons = flatten(&units, max_area_for(32.0, f32::from(font.upm())))
    .expect("a real glyph stays under MAX_FLATTEN_POINTS");
let merged = resolve_overlaps(&polygons);
// Some for a W, whose one contour crosses itself where its strokes meet; None for an H

flatten turns a path into closed polygons; max_area_for gives the tolerance daegun's rasterizer used through 1.1.7 at a size. resolve_overlaps replaces overlapping contours with one boundary, which a rasterizer that sums coverage needs where it would otherwise count a pixel twice. It works in font units, and answers None where there is nothing to resolve or too much: keep the input then.

Subpixel filters

SubpixelLayout describes a display's stripes for a rasterizer that filters subpixels itself: how many samples a pixel takes, the filter's taps and weights, and how far a glyph's box has to grow to fit them.

use daegun::{StripeOrder, SubpixelLayout};

let lcd = SubpixelLayout::horizontal(StripeOrder::Rgb);
lcd.oversample();   // (3, 1): three samples a pixel across
lcd.pad();          // pixels to grow a glyph's box on each side
lcd.weights(0);     // the red channel's filter

Type to search.