From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx.sdf.org ([205.166.94.24]) by ewsd; Fri Oct 30 13:45:15 -0400 2020 Received: from sdf.org (IDENT:nicolagi@otaku.sdf.org [205.166.94.8]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 09UHjCSQ010311 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for <9front@9front.org>; Fri, 30 Oct 2020 17:45:12 GMT Received: (from nicolagi@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 09UHjBeD007649 for 9front@9front.org; Fri, 30 Oct 2020 17:45:11 GMT Message-ID: <012440E4E4FD8FD9B1E1955DA8640092@sdf.org> To: 9front@9front.org Subject: truetypefs Date: Fri, 30 Oct 2020 17:45:07 +0000 From: nicolagi@sdf.org MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx.sdf.org id 09UHjCSQ010311 List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: compliant ISO-certified storage-oriented package-scale singleton NoSQL locator Hi all, truetypefs used to crash for me; it used to happen when trying to display some non-ASCII glyph, e.g., an accented vowel: =C3=A0. Commenting out the assertion at /sys/src/libttf/scan.c:371 solves the problem for me, although I fail to grasp why, and whether it's the right fix; I'll share why I gleaned so far. (Since text renders correctly on my end, I presume the assertion is wrong, but it's really just a guess.) The flags field of TTPoint defined at /sys/include/ttf.h:/^struct.TTPoint/ seems to hold values defined at /sys/src/libttf/impl.h:/ONCURVE/. So in other words, the assertion I commented out fails because a point is expected to be on the curve, while it is not. What point is it? If I were to guess from /sys/src/libttf/scan.c:370, I'd say the final point of each countour. AFAICS, the only place that can clear the bit is /sys/src/libttf/hint.c:1377, part of some hinting operation (flip range). Is the operation wrong, or is the assertion wrong? I'm including a patch that replaces magic numbers with enum values and comments out the problematic assertion. I realize it's not of much value but I hope someone can improve on it. Thanks, Nicola diff -r f4aa654bc414 sys/include/ttf.h --- a/sys/include/ttf.h Thu Oct 29 18:26:35 2020 +0100 +++ b/sys/include/ttf.h Fri Oct 30 17:33:50 2020 +0000 @@ -31,6 +31,7 @@ }; struct TTPoint { int x, y; + /* ONCURVE, TOUCHX, TOUCHY, TOUCH. */ u8int flags; }; struct TTBitmap { diff -r f4aa654bc414 sys/src/libttf/glyf.c --- a/sys/src/libttf/glyf.c Thu Oct 29 18:26:35 2020 +0100 +++ b/sys/src/libttf/glyf.c Fri Oct 30 17:33:50 2020 +0000 @@ -135,7 +135,7 @@ goto err; for(i =3D 0; i < np; i++){ p =3D &g->pt[g->npt + i]; - p->flags =3D *fp & 1; + p->flags =3D *fp & ONCURVE; switch(*fp++ & 0x12){ case 0x00: ttfunpack(f, "w", &temp16); p->x =3D lastx +=3D temp16; bre= ak; case 0x02: ttfunpack(f, "b", &temp8); p->x =3D lastx -=3D temp8; break= ; diff -r f4aa654bc414 sys/src/libttf/hint.c --- a/sys/src/libttf/hint.c Thu Oct 29 18:26:35 2020 +0100 +++ b/sys/src/libttf/hint.c Fri Oct 30 17:33:50 2020 +0000 @@ -136,8 +136,8 @@ if((n & RP2) !=3D 0) pi =3D h->f->rp[(n >> 4 & 3) - 1]; if((n & NOTOUCH) =3D=3D 0){ - if(h->f->fvx !=3D 0) p.flags |=3D 2; - if(h->f->fvy !=3D 0) p.flags |=3D 4; + if(h->f->fvx !=3D 0) p.flags |=3D TOUCHX; + if(h->f->fvy !=3D 0) p.flags |=3D TOUCHY; } if((h->f->zp >> (n >> 8 & 3) & 1) !=3D 0){ if(h->g =3D=3D nil) @@ -1374,7 +1374,7 @@ herror(h, "FLIPRG without glyph"); for(; i <=3D e; i++) if((int)i < h->g->npt) - h->g->pt[i].flags =3D h->g->pt[i].flags & ~1 | h->ip[-1] & 1; + h->g->pt[i].flags =3D h->g->pt[i].flags & ~ONCURVE | h->ip[-1] & 1; } =20 static void diff -r f4aa654bc414 sys/src/libttf/scan.c --- a/sys/src/libttf/scan.c Thu Oct 29 18:26:35 2020 +0100 +++ b/sys/src/libttf/scan.c Fri Oct 30 17:33:50 2020 +0000 @@ -368,9 +368,9 @@ for(i =3D 0; i < g->ncon; i++){ if(g->confst[i] + 1 >=3D g->confst[i+1]) continue; p =3D g->pt[g->confst[i]]; - assert((p.flags & 1) !=3D 0); + /* assert((p.flags & ONCURVE) !=3D 0); */ for(j =3D g->confst[i]; j++ < g->confst[i+1]; ){ - if(j < g->confst[i+1] && (g->pt[j].flags & 1) =3D=3D 0) + if(j < g->confst[i+1] && (g->pt[j].flags & ONCURVE) =3D=3D 0) q =3D g->pt[j++]; else q =3D p; @@ -378,14 +378,14 @@ r =3D g->pt[g->confst[i]]; else{ r =3D g->pt[j]; - if((g->pt[j].flags & 1) =3D=3D 0){ + if((g->pt[j].flags & ONCURVE) =3D=3D 0){ r.x =3D (r.x + q.x) / 2; r.y =3D (r.y + q.y) / 2; } } dobezier(&s, p, q, r); p =3D r; - if(j < g->confst[i+1] && (g->pt[j].flags & 1) =3D=3D 0) + if(j < g->confst[i+1] && (g->pt[j].flags & ONCURVE) =3D=3D 0) j--; } } @@ -440,9 +440,9 @@ (*fp)[0] =3D p.x * scale; (*fp)[1] =3D p.y * scale + offy; } - assert((p.flags & 1) !=3D 0); + assert((p.flags & ONCURVE) !=3D 0); for(j =3D g->confst[i]; j++ < g->confst[i+1]; ){ - if(j < g->confst[i+1] && (g->pt[j].flags & 1) =3D=3D 0) + if(j < g->confst[i+1] && (g->pt[j].flags & ONCURVE) =3D=3D 0) q =3D g->pt[j++]; else q =3D p; @@ -450,7 +450,7 @@ r =3D g->pt[g->confst[i]]; else{ r =3D g->pt[j]; - if((g->pt[j].flags & 1) =3D=3D 0){ + if((g->pt[j].flags & ONCURVE) =3D=3D 0){ r.x =3D (r.x + q.x) / 2; r.y =3D (r.y + q.y) / 2; } @@ -469,7 +469,7 @@ } p =3D r; n +=3D 2; - if(j < g->confst[i+1] && (g->pt[j].flags & 1) =3D=3D 0) + if(j < g->confst[i+1] && (g->pt[j].flags & ONCURVE) =3D=3D 0) j--; } if(np !=3D nil)