9front - general discussion about 9front
 help / color / mirror / Atom feed
From: nicolagi@sdf.org
To: 9front@9front.org
Subject: truetypefs
Date: Fri, 30 Oct 2020 17:45:07 +0000	[thread overview]
Message-ID: <012440E4E4FD8FD9B1E1955DA8640092@sdf.org> (raw)

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: à.

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 = 0; i < np; i++){
 		p = &g->pt[g->npt + i];
-		p->flags = *fp & 1;
+		p->flags = *fp & ONCURVE;
 		switch(*fp++ & 0x12){
 		case 0x00: ttfunpack(f, "w", &temp16); p->x = lastx += temp16; break;
 		case 0x02: ttfunpack(f, "b", &temp8); p->x = lastx -= 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) != 0)
 		pi = h->f->rp[(n >> 4 & 3) - 1];
 	if((n & NOTOUCH) == 0){
-		if(h->f->fvx != 0) p.flags |= 2;
-		if(h->f->fvy != 0) p.flags |= 4;
+		if(h->f->fvx != 0) p.flags |= TOUCHX;
+		if(h->f->fvy != 0) p.flags |= TOUCHY;
 	}
 	if((h->f->zp >> (n >> 8 & 3) & 1) != 0){
 		if(h->g == nil)
@@ -1374,7 +1374,7 @@
 		herror(h, "FLIPRG without glyph");
 	for(; i <= e; i++)
 		if((int)i < h->g->npt)
-			h->g->pt[i].flags = h->g->pt[i].flags & ~1 | h->ip[-1] & 1;
+			h->g->pt[i].flags = h->g->pt[i].flags & ~ONCURVE | h->ip[-1] & 1;
 }
 
 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 = 0; i < g->ncon; i++){
 		if(g->confst[i] + 1 >= g->confst[i+1]) continue;
 		p = g->pt[g->confst[i]];
-		assert((p.flags & 1) != 0);
+		/* assert((p.flags & ONCURVE) != 0); */
 		for(j = g->confst[i]; j++ < g->confst[i+1]; ){
-			if(j < g->confst[i+1] && (g->pt[j].flags & 1) == 0)
+			if(j < g->confst[i+1] && (g->pt[j].flags & ONCURVE) == 0)
 				q = g->pt[j++];
 			else
 				q = p;
@@ -378,14 +378,14 @@
 				r = g->pt[g->confst[i]];
 			else{
 				r = g->pt[j];
-				if((g->pt[j].flags & 1) == 0){
+				if((g->pt[j].flags & ONCURVE) == 0){
 					r.x = (r.x + q.x) / 2;
 					r.y = (r.y + q.y) / 2;
 				}
 			}
 			dobezier(&s, p, q, r);
 			p = r;
-			if(j < g->confst[i+1] && (g->pt[j].flags & 1) == 0)
+			if(j < g->confst[i+1] && (g->pt[j].flags & ONCURVE) == 0)
 				j--;
 		}
 	}
@@ -440,9 +440,9 @@
 		(*fp)[0] = p.x * scale;
 		(*fp)[1] = p.y * scale + offy;
 	}
-	assert((p.flags & 1) != 0);
+	assert((p.flags & ONCURVE) != 0);
 	for(j = g->confst[i]; j++ < g->confst[i+1]; ){
-		if(j < g->confst[i+1] && (g->pt[j].flags & 1) == 0)
+		if(j < g->confst[i+1] && (g->pt[j].flags & ONCURVE) == 0)
 			q = g->pt[j++];
 		else
 			q = p;
@@ -450,7 +450,7 @@
 			r = g->pt[g->confst[i]];
 		else{
 			r = g->pt[j];
-			if((g->pt[j].flags & 1) == 0){
+			if((g->pt[j].flags & ONCURVE) == 0){
 				r.x = (r.x + q.x) / 2;
 				r.y = (r.y + q.y) / 2;
 			}
@@ -469,7 +469,7 @@
 		}
 		p = r;
 		n += 2;
-		if(j < g->confst[i+1] && (g->pt[j].flags & 1) == 0)
+		if(j < g->confst[i+1] && (g->pt[j].flags & ONCURVE) == 0)
 			j--;
 	}
 	if(np != nil)



             reply	other threads:[~2020-10-30 17:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30 17:45 nicolagi [this message]
2020-10-31 11:42 ` [9front] truetypefs cinap_lenrek
2020-11-06 16:07 ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=012440E4E4FD8FD9B1E1955DA8640092@sdf.org \
    --to=nicolagi@sdf.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).