paintBoxGlyph function
Renders cp's ops into cell with fg. No-op (returns false) if cp has
no programmatic ops, so the caller can fall back to the font glyph.
Implementation
bool paintBoxGlyph(Canvas canvas, Rect cell, int cp, Color fg, double lineWidth) {
final ops = boxOps(cp, cell, lineWidth);
if (ops.isEmpty) return false;
final stroke = Paint()
..color = fg
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.butt;
// Block-element fills (RectOp) must not be anti-aliased: cell metrics are
// sub-pixel, so AA'd edges on adjacent block cells leave half-covered seams —
// a faint grid between cells (worst on fractional DPR / widget offset). Solid
// pixel-aligned fills tile exactly, matching alacritty's integer-pixel
// `draw_rect` (builtin_font.rs). Strokes/arcs keep AA for smooth diagonals
// (alacritty likewise only anti-aliases its Xiaolin-Wu line drawing).
final fill = Paint()
..style = PaintingStyle.fill
..isAntiAlias = false;
for (final op in ops) {
switch (op) {
case LineOp(:final a, :final b, :final width):
stroke.strokeWidth = width;
canvas.drawLine(a, b, stroke);
case RectOp(:final rect, :final alpha):
fill.color = fg.withValues(alpha: fg.a * alpha);
canvas.drawRect(rect, fill);
case ArcOp(:final bounds, :final startAngle, :final sweepAngle, :final width):
stroke.strokeWidth = width;
canvas.drawArc(bounds, startAngle, sweepAngle, false, stroke);
case DashOp(:final a, :final b, :final width, :final segments):
stroke.strokeWidth = width;
// Each segment occupies 2/3 of its slot, leaving a 1/3 gap.
final dx = (b.dx - a.dx) / segments;
final dy = (b.dy - a.dy) / segments;
for (var i = 0; i < segments; i++) {
final s = Offset(a.dx + dx * i, a.dy + dy * i);
final e = Offset(a.dx + dx * (i + 0.66), a.dy + dy * (i + 0.66));
canvas.drawLine(s, e, stroke);
}
}
}
return true;
}