shithub: pdffs

Download patch

ref: 4ac213e298e696d4c0816bc824dc4914077cb0c6
parent: 1ecdb9da0d3e8ae0e6b6c49d4cfdea72355261a0
author: Noam Preil <[email protected]>
date: Thu Aug 5 16:29:06 EDT 2021

op: recognize more glyph names.

PDF allows fonts to override their base encoding, using named glpyhs. This commit adds, among others, the decimal digits, uppercase and lowercase letters, and some greek symbols. It also fixes the validation check for appending a bullet (•) to check against strlen(

--- a/op.c
+++ b/op.c
@@ -494,10 +494,12 @@
 	return tmove(p, 0, 0 - p->TS.TL, 1) && flagless(op);
 }
 
+//TODO: replace this with a precomputed map when the font is loaded
 static int
 writepatched(Page *p, uchar c)
 {
 	int i, len, d = 0;
+	char buf[2];
 	Object *o;
 	if(p->GSactive->Font.enc != nil){
 		len = arraylen(p->GSactive->Font.enc);
@@ -506,6 +508,22 @@
 			if(o->type == Onum)
 				d = o->num.i;
 			else if(d == c){
+				if(strcmp(o->name, "Omega") == 0)
+					return bufput(&p->buf, (uchar*)"Ω", strlen("Ω")) == strlen("Ω");
+				if(strcmp(o->name, "Pi") == 0)
+					return bufput(&p->buf, (uchar*)"Π", strlen("Π")) == strlen("Π");
+				if(strcmp(o->name, "mu") == 0)
+					return bufput(&p->buf, (uchar*)"μ", strlen("μ")) == strlen("μ");
+				if(strcmp(o->name, "pi") == 0)
+					return bufput(&p->buf, (uchar*)"π", strlen("π")) == strlen("π");
+				if(strcmp(o->name, "heart") == 0)
+					return bufput(&p->buf, (uchar*)"♥", strlen("♥")) == strlen("♥");
+				if(strcmp(o->name, "minus") == 0)
+					return bufput(&p->buf, (uchar*)"1", 1) == 1;
+				if(strcmp(o->name, "fl") == 0)
+					return bufput(&p->buf, (uchar*)"fl", 2) == 2;
+				if(strcmp(o->name, "dieresis") == 0)
+					return bufput(&p->buf, (uchar*)"¨", strlen("¨")) == strlen("¨");
 				if(strcmp(o->name, "endash") == 0)
 					return bufput(&p->buf, (uchar*)"-", 1) == 1;
 				if(strcmp(o->name, "fi") == 0)
@@ -515,7 +533,7 @@
 				if(strcmp(o->name, "ffi") == 0)
 					return bufput(&p->buf, (uchar*)"ffi", 3) == 3;
 				if(strcmp(o->name, "bullet") == 0)
-					return bufput(&p->buf, (uchar*)"•", strlen("•")) == 3;
+					return bufput(&p->buf, (uchar*)"•", strlen("•")) == strlen("•");
 				if(strcmp(o->name, "quotedblleft") == 0)
 					return bufput(&p->buf, (uchar*)"\"", 1) == 1;
 				if(strcmp(o->name, "quotedblright") == 0)
@@ -522,8 +540,49 @@
 					return bufput(&p->buf, (uchar*)"\"", 1) == 1;
 				if(strcmp(o->name, "quoteleft") == 0)
 					return bufput(&p->buf, (uchar*)"'", 1) == 1;
+				if(strcmp(o->name, "zero") == 0)
+					return bufput(&p->buf, (uchar*)"0", 1) == 1;
+				if(strcmp(o->name, "one") == 0)
+					return bufput(&p->buf, (uchar*)"1", 1) == 1;
+				if(strcmp(o->name, "two") == 0)
+					return bufput(&p->buf, (uchar*)"2", 1) == 1;
+				if(strcmp(o->name, "three") == 0)
+					return bufput(&p->buf, (uchar*)"3", 1) == 1;
+				if(strcmp(o->name, "four") == 0)
+					return bufput(&p->buf, (uchar*)"4", 1) == 1;
+				if(strcmp(o->name, "five") == 0)
+					return bufput(&p->buf, (uchar*)"5", 1) == 1;
+				if(strcmp(o->name, "six") == 0)
+					return bufput(&p->buf, (uchar*)"6", 1) == 1;
+				if(strcmp(o->name, "seven") == 0)
+					return bufput(&p->buf, (uchar*)"7", 1) == 1;
+				if(strcmp(o->name, "eight") == 0)
+					return bufput(&p->buf, (uchar*)"8", 1) == 1;
+				if(strcmp(o->name, "nine") == 0)
+					return bufput(&p->buf, (uchar*)"9", 1) == 1;
+				if(strcmp(o->name, "space") == 0)
+					return bufput(&p->buf, (uchar*)" ", 1) == 1;
 				if(strcmp(o->name, "quoteright") == 0)
 					return bufput(&p->buf, (uchar*)"'", 1) == 1;
+				if(strcmp(o->name, "backslash") == 0)
+					return bufput(&p->buf, (uchar*)"\\", 1) == 1;
+				if(strcmp(o->name, "braceright") == 0)
+					return bufput(&p->buf, (uchar*)"}", 1) == 1;
+				if(strcmp(o->name, "period") == 0)
+					return bufput(&p->buf, (uchar*)".", 1) == 1;
+				if(strcmp(o->name, "comma") == 0)
+					return bufput(&p->buf, (uchar*)",", 1) == 1;
+				if(strcmp(o->name, "braceleft") == 0)
+					return bufput(&p->buf, (uchar*)"{", 1) == 1;
+				if(strcmp(o->name, "arrowright") == 0)
+					return bufput(&p->buf, (uchar*)"→", strlen("→")) == strlen("→");
+				buf[1] = 0;
+				for(buf[0] = 'A'; buf[0] <= 'Z'; buf[0] += 1)
+					if(strcmp(buf, o->name) == 0)
+						return bufput(&p->buf, (uchar*)buf, 1) == 1;
+				for(buf[0] = 'a'; buf[0] <= 'z'; buf[0] += 1)
+					if(strcmp(buf, o->name) == 0)
+						return bufput(&p->buf, (uchar*)buf, 1) == 1;
 				fprint(2, "TODO: recognize glyph name '%s'\n", o->name);
 				return 1;
 			} else