shithub: fnt

Download patch

ref: 1d352256dfd09685a98184574d2fb7e046589ec8
parent: 96da9f096612bfdb3c7204c14f1ed913e19cbcfe
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Jul 14 21:57:29 EDT 2024

ComponentGlyf reader: fix F2DOT14 parsing

--- a/otf.c.in
+++ b/otf.c.in
@@ -264,6 +264,7 @@
 {
 	ComponentGlyph *v;
 	u8int *b;
+	s16int f;
 
 	if((v = calloc(1, sizeof(*v))) == nil){
 nomem:
@@ -296,16 +297,17 @@
 	}
 	if(b == nil)
 		goto err;
+	#define f2dot14(o) (f = b[2*o]<<8 | b[2*o+1], (f>>14)+(f&((1<<14)-1))/16384.0)
 	if((v->flags & CGLYPH_FL_SCALE) != 0 && (b = otfreadn(o, 2)) != nil){
-		v->scale = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
+		v->scale = f2dot14(0);
 	}else if((v->flags & CGLYPH_FL_SCALE_XY) != 0 && (b = otfreadn(o, 2*2)) != nil){
-		v->scaleX = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
-		v->scaleY = (b[2]<<8 | b[3]>>14)+(b[2]<<8 | b[3]&((1<<14)-1))/16384.0;
+		v->scaleX = f2dot14(0);
+		v->scaleY = f2dot14(1);
 	}else if((v->flags & CGLYPH_FL_2X2_TRANSFORM) != 0 && (b = otfreadn(o, 2*2*2)) != nil){
-		v->scaleX = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
-		v->scale01 = (b[2]<<8 | b[3]>>14)+(b[2]<<8 | b[3]&((1<<14)-1))/16384.0;
-		v->scale10 = (b[4]<<8 | b[5]>>14)+(b[4]<<8 | b[5]&((1<<14)-1))/16384.0;
-		v->scaleY = (b[6]<<8 | b[7]>>14)+(b[6]<<8 | b[7]&((1<<14)-1))/16384.0;
+		v->scaleX = f2dot14(0);
+		v->scale01 = f2dot14(1);
+		v->scale10 = f2dot14(2);
+		v->scaleY = f2dot14(3);
 	}
 	if(b == nil)
 		goto err;
--- a/plan9/otf.c
+++ b/plan9/otf.c
@@ -278,6 +278,7 @@
 {
 	ComponentGlyph *v;
 	u8int *b;
+	s16int f;
 
 	if((v = calloc(1, sizeof(*v))) == nil){
 nomem:
@@ -310,16 +311,17 @@
 	}
 	if(b == nil)
 		goto err;
+	#define f2dot14(o) (f = b[2*o]<<8 | b[2*o+1], (f>>14)+(f&((1<<14)-1))/16384.0)
 	if((v->flags & CGLYPH_FL_SCALE) != 0 && (b = otfreadn(o, 2)) != nil){
-		v->scale = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
+		v->scale = f2dot14(0);
 	}else if((v->flags & CGLYPH_FL_SCALE_XY) != 0 && (b = otfreadn(o, 2*2)) != nil){
-		v->scaleX = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
-		v->scaleY = (b[2]<<8 | b[3]>>14)+(b[2]<<8 | b[3]&((1<<14)-1))/16384.0;
+		v->scaleX = f2dot14(0);
+		v->scaleY = f2dot14(1);
 	}else if((v->flags & CGLYPH_FL_2X2_TRANSFORM) != 0 && (b = otfreadn(o, 2*2*2)) != nil){
-		v->scaleX = (b[0]<<8 | b[1]>>14)+(b[0]<<8 | b[1]&((1<<14)-1))/16384.0;
-		v->scale01 = (b[2]<<8 | b[3]>>14)+(b[2]<<8 | b[3]&((1<<14)-1))/16384.0;
-		v->scale10 = (b[4]<<8 | b[5]>>14)+(b[4]<<8 | b[5]&((1<<14)-1))/16384.0;
-		v->scaleY = (b[6]<<8 | b[7]>>14)+(b[6]<<8 | b[7]&((1<<14)-1))/16384.0;
+		v->scaleX = f2dot14(0);
+		v->scale01 = f2dot14(1);
+		v->scale10 = f2dot14(2);
+		v->scaleY = f2dot14(3);
 	}
 	if(b == nil)
 		goto err;