mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-23 16:01:07 +01:00
[gpu] Detect degenerate cubics in cu2qu and emit lines
Cubics with collinear control points (common in CJK fonts) caused cu2qu to subdivide to max depth, generating up to 1024 line segments per cubic. Detect the collinear case early using cross-product distance and emit a single line instead. Fixes encode failure for NotoSerifCJK gid 897 (48 cubics were producing 24672 quadratics; now produces 48 lines). Reduces total encode size for the font by ~34%. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
198dc300d0
commit
76eb0ae60f
1 file changed
+17
@@ -119,6 +119,23 @@ hb_gpu_draw_t::acc_cubic_to (double c1x, double c1y,
|
||||
c2x == x && c2y == y)
|
||||
return;
|
||||
|
||||
/* Degenerate cubic: all control points are collinear.
|
||||
* Emit as a line instead of running cu2qu subdivision. */
|
||||
double dx = x - c0x, dy = y - c0y;
|
||||
double len_sq = dx * dx + dy * dy;
|
||||
if (len_sq > 0.)
|
||||
{
|
||||
double inv = 1.0 / len_sq;
|
||||
double cross1 = (c1x - c0x) * dy - (c1y - c0y) * dx;
|
||||
double cross2 = (c2x - c0x) * dy - (c2y - c0y) * dx;
|
||||
if (cross1 * cross1 * inv <= HB_GPU_CU2QU_TOLERANCE * HB_GPU_CU2QU_TOLERANCE &&
|
||||
cross2 * cross2 * inv <= HB_GPU_CU2QU_TOLERANCE * HB_GPU_CU2QU_TOLERANCE)
|
||||
{
|
||||
acc_line_to (x, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
hb_gpu_cubic_to_quadratics (this,
|
||||
{c0x, c0y}, {c1x, c1y},
|
||||
{c2x, c2y}, {x, y},
|
||||
|
||||
Reference in new issue
Block a user