[gs-cvs] rev 7187 - trunk/gs/src

ray at ghostscript.com ray at ghostscript.com
Sun Nov 12 14:18:05 PST 2006


Author: ray
Date: 2006-11-12 14:18:04 -0800 (Sun, 12 Nov 2006)
New Revision: 7187

Modified:
   trunk/gs/src/gsfunc4.c
   trunk/gs/src/gsfunc4.h
   trunk/gs/src/opextern.h
   trunk/gs/src/zcontrol.c
   trunk/gs/src/zfunc4.c
Log:
Add 'repeat' as an pseudo-operator for FunctionType 4. Needed for PS CET
09-31 and 09-34 that use it in the tint transform for DeviceN with 110 and
250 components.

DETAILS:

Since Type 4 functions are a PDF feature, extending the control operators
to include 'repeat' doesn't create any PS incompatibility.


Modified: trunk/gs/src/gsfunc4.c
===================================================================
--- trunk/gs/src/gsfunc4.c	2006-11-10 12:18:42 UTC (rev 7186)
+++ trunk/gs/src/gsfunc4.c	2006-11-12 22:18:04 UTC (rev 7187)
@@ -109,6 +109,9 @@
     calc_value_t *vstack = &vstack_buf[1];
     calc_value_t *vsp = vstack + pfn->params.m;
     const byte *p = pfn->params.ops.data;
+    int repeat_count[MAX_PSC_FUNCTION_NESTING];
+    int repeat_proc_size[MAX_PSC_FUNCTION_NESTING];
+    int repeat_nesting_level = -1;
     int i;
 
     /*
@@ -211,8 +214,9 @@
 
 	OP1(PtCr_if, E, E),		/* if */
 	OP_NONE(PtCr_else),		/* else */
-	OP_NONE(PtCr_return)		/* return */
-
+	OP_NONE(PtCr_return),		/* return */
+	OP1(E, PtCr_repeat, E),		/* repeat */
+	OP_NONE(PtCr_repeat_end)	/* repeat_end */
     };
 
     vstack[-1].type = CVT_NONE;  /* for type dispatch in empty stack case */
@@ -517,10 +521,23 @@
 	    }
 	    /* falls through */
 	case PtCr_else:
-	    p += 2 + (p[0] << 8) + p[1];
+	    p += 2 + (p[0] << 8) + p[1];	/* skip the past body */
 	    continue;
 	case PtCr_return:
 	    goto fin;
+	case PtCr_repeat:
+	    repeat_nesting_level++;
+	    repeat_count[repeat_nesting_level] = vsp->value.i;
+	    repeat_proc_size[repeat_nesting_level] = 1 + (p[0] << 8) + p[1];	/* body size */
+	    --vsp;		/* pop the counter */
+	    p += 3 + (p[0] <<8) + p[1];		    /* advance just past the repeat_end */
+	    /* falls through */
+	case PtCr_repeat_end:
+	    if ((repeat_count[repeat_nesting_level])-- <= 0)
+		repeat_nesting_level--;
+	    else
+		p -= repeat_proc_size[repeat_nesting_level];
+	    continue;
 	}
     }
  fin:
@@ -825,9 +842,11 @@
 		p += sizeof(int); break;
 	    case PtCr_float:
 		p += sizeof(float); break;
+	    case PtCr_repeat:
 	    case PtCr_if:
 	    case PtCr_else:
 		p += 2;
+	    case PtCr_repeat_end:
 	    case PtCr_true:
 	    case PtCr_false:
 		break;

Modified: trunk/gs/src/gsfunc4.h
===================================================================
--- trunk/gs/src/gsfunc4.h	2006-11-10 12:18:42 UTC (rev 7186)
+++ trunk/gs/src/gsfunc4.h	2006-11-12 22:18:04 UTC (rev 7187)
@@ -24,6 +24,8 @@
 /* Define the Function type. */
 #define function_type_PostScript_Calculator 4
 
+#define MAX_PSC_FUNCTION_NESTING 10
+
 /* Define the opcodes. */
 typedef enum {
 
@@ -50,11 +52,12 @@
 
     /* Special operators */
 
-    PtCr_if, PtCr_else, PtCr_return
-
+    PtCr_if, PtCr_else, PtCr_return,
+    PtCr_repeat, PtCr_repeat_end,		/* Ghostscript extension */
+    PtCr_end			/* dummy to make it easier to insert opcodes above */
 } gs_PtCr_opcode_t;
 #define PtCr_NUM_OPS ((int)PtCr_byte)
-#define PtCr_NUM_OPCODES ((int)PtCr_return + 1)
+#define PtCr_NUM_OPCODES ((int)PtCr_end + 1)
 
 /* Define PostScript Calculator functions. */
 typedef struct gs_function_PtCr_params_s {

Modified: trunk/gs/src/opextern.h
===================================================================
--- trunk/gs/src/opextern.h	2006-11-10 12:18:42 UTC (rev 7186)
+++ trunk/gs/src/opextern.h	2006-11-12 22:18:04 UTC (rev 7187)
@@ -39,6 +39,7 @@
 int zifelse(i_ctx_t *);
 int zindex(i_ctx_t *);
 int zpop(i_ctx_t *);
+int zrepeat(i_ctx_t *);
 int zroll(i_ctx_t *);
 int zsub(i_ctx_t *);
 /* Internal entry points for the interpreter. */

Modified: trunk/gs/src/zcontrol.c
===================================================================
--- trunk/gs/src/zcontrol.c	2006-11-10 12:18:42 UTC (rev 7186)
+++ trunk/gs/src/zcontrol.c	2006-11-12 22:18:04 UTC (rev 7187)
@@ -467,7 +467,7 @@
 
 /* <int> <proc> repeat - */
 private int repeat_continue(i_ctx_t *);
-private int
+int
 zrepeat(i_ctx_t *i_ctx_p)
 {
     os_ptr op = osp;

Modified: trunk/gs/src/zfunc4.c
===================================================================
--- trunk/gs/src/zfunc4.c	2006-11-10 12:18:42 UTC (rev 7186)
+++ trunk/gs/src/zfunc4.c	2006-11-12 22:18:04 UTC (rev 7187)
@@ -148,7 +148,6 @@
  * Note that we arbitrarily limit the depth of procedure nesting.  pref is
  * known to be a procedure.
  */
-#define MAX_PSC_FUNCTION_NESTING 10
 private int
 check_psc_function(i_ctx_t *i_ctx_p, const ref *pref, int depth, byte *ops, int *psize)
 {
@@ -241,9 +240,17 @@
 	    code = check_psc_function(i_ctx_p, &elt, depth + 1, ops, psize);
 	    if (code < 0)
 		return code;
-	    /* Check for {proc} if | {proc1} {proc2} ifelse */
-	    if (resolves_to_oper(i_ctx_p, &elt2, zif)) {
+	    /* Check for { proc } repeat | {proc} if | {proc1} {proc2} ifelse */
+	    if (resolves_to_oper(i_ctx_p, &elt2, zrepeat)) {
 		if (ops) {
+		    *p = PtCr_repeat;
+		    psc_fixup(p, ops + *psize);
+		    p = ops + *psize;
+		    *p++ = PtCr_repeat_end;
+		}
+		*psize += 1;	/* extra room for repeat_end */
+	    } else if (resolves_to_oper(i_ctx_p, &elt2, zif)) {
+		if (ops) {
 		    *p = PtCr_if;
 		    psc_fixup(p, ops + *psize);
 		}
@@ -264,10 +271,10 @@
 		    return code;
 		if (ops)
 		    psc_fixup(p, ops + *psize);
-	    } else
+	    } else 
 		return_error(e_rangecheck);
+	    }	 /* end 'default' */
 	}
-	}
     next:
 	DO_NOTHING;
     }



More information about the gs-cvs mailing list