shithub: fnt

Download patch

ref: 19827008dbe2ae5253cb63df13c4d207ccecbf02
parent: 2296ee3d37775d6cfd87ed27dfee46cb9b85b12b
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Sep 2 18:11:48 EDT 2024

bitmap fonts: error on uninmplemented bit depths

--- a/otf.c.in
+++ b/otf.c.in
@@ -681,6 +681,10 @@
 			break;
 
 		b.bitDepth = bs->bitDepth;
+		if(b.bitDepth != 1 && b.bitDepth != 8){
+			werrstr("unsupported bit depth: %d", b.bitDepth);
+			goto err;
+		}
 		b.ppemX = bs->ppemX;
 		b.ppemY = bs->ppemY;
 		isr = bs->indexSubtableList;
@@ -765,6 +769,7 @@
 		return bitebdt(o, g, &best);
 
 	werrstr("no bitmap");
+err:
 	free(g);
 	return nil;
 }
--- a/plan9/otf.c
+++ b/plan9/otf.c
@@ -682,6 +682,10 @@
 			break;
 
 		b.bitDepth = bs->bitDepth;
+		if(b.bitDepth != 1 && b.bitDepth != 8){
+			werrstr("unsupported bit depth: %d", b.bitDepth);
+			goto err;
+		}
 		b.ppemX = bs->ppemX;
 		b.ppemY = bs->ppemY;
 		isr = bs->indexSubtableList;
@@ -766,6 +770,7 @@
 		return bitebdt(o, g, &best);
 
 	werrstr("no bitmap");
+err:
 	free(g);
 	return nil;
 }
--- a/rast.c
+++ b/rast.c
@@ -774,7 +774,8 @@
 {
 	int i;
 
-	if(bg->bitDepth == 1){
+	switch(bg->bitDepth){
+	case 1:
 		i = y*bg->pitchBits + x;
 		if(bg->format == 2 || bg->format == 5)
 			x = i - (i & ~7);
@@ -781,11 +782,11 @@
 		else
 			x &= 7;
 		return (bg->image[i>>3] & (0x80>>x)) ? 255 : 0;
-	}else if(bg->bitDepth == 4){
+	case 2:
+	case 4:
 		/* FIXME */
-		assert(nil);
-		return 0;
-	}else if(bg->bitDepth == 8){
+		break;
+	case 8:
 		return bg->image[y*bg->pitchBits/8 + x];
 	}
 	return 0;
--