shithub: pdffs

Download patch

ref: 4b30ac15e8e98f7e8d6ccd130ad21890086a501e
parent: a6111130f184531b8fbaa2cb36187f82dfbfc6bc
author: Noam Preil <noam@pixelhero.dev>
date: Fri Apr 8 10:37:45 EDT 2022

gs: read parameters from dictionary

--- a/op.c
+++ b/op.c
@@ -215,14 +215,44 @@
 gsstate(Op *op, Page *p)
 {
 	char *name = arrayget(p->stack, 0)->name;
-	Object *extgstate;
-	if((extgstate = dictget(dictget(dictget(p->obj, "Resources"), "ExtGState"), name)) == nil){
+	Object *gs, *o;
+	if((gs = dictget(dictget(dictget(p->obj, "Resources"), "ExtGState"), name)) == nil){
 		werrstr("extgstate dictionary not found: %s", name);
 		return 0;
 	}
-	fprint(2, "TODO use GS dictionary\n");
-	USED(op, extgstate);
-	return 1;
+	if((o = dictget(gs, "Type")) != nil && strcmp(o->name, "ExtGState") != 0){
+		werrstr("invalid type on ExtGState object: %s", o->name);
+		return 0;
+	}
+	if((o = dictget(gs, "LW")) != nil){
+		if(o->type != Onum){
+			werrstr("line width must be a number");
+			return 0;
+		}
+		p->GSactive->LW = o->num.d;
+	}
+	if((o = dictget(gs, "LC")) != nil){
+		if(o->type != Onum){
+			werrstr("line cap must be a number");
+			return 0;
+		}
+		p->GSactive->LC = o->num.i;
+	}
+	if((o = dictget(gs, "LJ")) != nil){
+		if(o->type != Onum){
+			werrstr("line join must be a number");
+			return 0;
+		}
+		p->GSactive->LJ = o->num.i;
+	}
+	if((o = dictget(gs, "ML")) != nil){
+		if(o->type != Onum){
+			werrstr("miter limit must be a number");
+			return 0;
+		}
+		p->GSactive->ML = o->num.d;
+	}
+	return flagless(op);
 }
 
 static int