shithub: pdffs

Download patch

ref: a6111130f184531b8fbaa2cb36187f82dfbfc6bc
parent: e759007ea6a033ca713e53a4f1cdeea933e02c30
author: Noam Preil <[email protected]>
date: Fri Apr 8 10:26:56 EDT 2022

gs: implement remaining parameter setters

--- a/op.c
+++ b/op.c
@@ -149,7 +149,11 @@
 static int
 gswidth(Op *op, Page *p)
 {
-	p->GSactive->LW = arrayget(p->stack, 0)->num.i;
+	p->GSactive->LW = arrayget(p->stack, 0)->num.d;
+	if(p->GSactive->LW < 0){
+		werrstr("line width cannot be negative: %f", p->GSactive->LW);
+		return 0;
+	}
 	return flagless(op);
 }
 
@@ -156,22 +160,34 @@
 static int
 gscap(Op *op, Page *p)
 {
-	USED(op, p);
-	return 0;
+	p->GSactive->LC = arrayget(p->stack, 0)->num.d;
+	if(p->GSactive->LC > CapEND){
+		werrstr("invalid line cap: %d", p->GSactive->LC);
+		return 0;
+	}
+	return flagless(op);
 }
 
 static int
 gsjoin(Op *op, Page *p)
 {
-	USED(op, p);
-	return 0;
+	p->GSactive->LJ = arrayget(p->stack, 0)->num.d;
+	if(p->GSactive->LJ > JoinEND){
+		werrstr("invalid line join: %d", p->GSactive->LJ);
+		return 0;
+	}
+	return flagless(op);
 }
 
 static int
 gsmiterlim(Op *op, Page *p)
 {
-	USED(op, p);
-	return 0;
+	p->GSactive->ML = arrayget(p->stack, 0)->num.d;
+	if(p->GSactive->ML < 0){
+		werrstr("miter limit cannot be negative: %f", p->GSactive->ML);
+		return 0;
+	}
+	return flagless(op);
 }
 
 static int
@@ -1272,10 +1288,10 @@
 	USED(p);
 	/* todo: actually initialize the full state */
 	ctminit(p, gs->CTM);
-	gs->LW = 1;
-	gs->LC = 0;
-	gs->LJ = 0;
-	gs->ML = 10;
+	gs->LW = 1.0;
+	gs->LC = CapButt;
+	gs->LJ = JoinMiter;
+	gs->ML = 10.0;
 	gs->SCS = gs->NSCS = DeviceGray;
 	// Alpha is lowest byte; this is (0, 0, 0, 255) == black
 	gs->SC = gs->NSC = 255;
--- a/pdf.h
+++ b/pdf.h
@@ -108,7 +108,17 @@
 	};
 };
 
-/* Color spaces; 8.6.3 / table 61 */
+/* 8.4.3.3 / table 53 */
+typedef enum {
+	CapButt = 0, CapRound = 1, CapProjectingSquare = 2, CapEND = CapProjectingSquare,
+} LineCap;
+
+/* 8.4.3.4 / table 54 */
+typedef enum {
+	JoinMiter = 0, JoinRound = 1, JoinBevel = 2, JoinEND = JoinBevel,
+} LineJoin;
+
+/* 8.6.3 / table 61 */
 typedef enum ColorSpace {
 	DeviceGray, DeviceRGB, DeviceCMYK, /* Device family */
 	CalGray, CalRGB, Lab, ICCBased, /* CIE-based family */
@@ -118,7 +128,11 @@
 /* Since the GS gets duplicated onto a stack, avoid holding pointers, which would become messy to clean up properly */
 struct GS {
 	double CTM[6]; /* current transformation matrix ; 8.3 */
-	int LW, LC, LJ, ML, RI, OP, op, OPM, SA, AIS, TK;
+	double LW, ML;
+	LineCap LC;
+	LineJoin LJ;
+	int OP, op, OPM, SA, AIS, TK;
+	int *DP;
 	double SM, CA, ca, FL;
 	struct{ /* coloring info */
 		ColorSpace SCS, NSCS; /* stroking color space and nonstroking color space */