]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/hpgl-attr.c
Merge changes from CUPS 1.5svn-r8950.
[thirdparty/cups.git] / filter / hpgl-attr.c
index 5a645c1cb7fe26f9be9568ac02f6ac85dd742c3c..7a93ad7d87254816ebdc259c03837914fa81d99e 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: hpgl-attr.c 4494 2005-02-18 02:18:11Z mike $"
+ * "$Id: hpgl-attr.c 6649 2007-07-11 21:46:42Z mike $"
  *
  *   HP-GL/2 attribute processing for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1993-2005 by Easy Software Products.
+ *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 1993-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  *   This file is subject to the Apple OS-Developed Software exception.
  *
@@ -82,8 +73,9 @@ CR_color_range(int     num_params,    /* I - Number of parameters */
     ColorRange[2][1] = params[5].value.number - params[4].value.number;
   }
   else
-    fprintf(stderr, "WARNING: HP-GL/2 \'CR\' command with invalid number of parameters (%d)!\n",
-            num_params);
+    fprintf(stderr,
+            "DEBUG: HP-GL/2 \'CR\' command with invalid number of "
+           "parameters (%d)!\n", num_params);
 }
 
 
@@ -205,13 +197,24 @@ NP_number_pens(int     num_params,        /* I - Number of parameters */
 
   if (num_params == 0)
     PenCount = 8;
-  else if (num_params == 1 && params[0].value.number <= 1024)
-    PenCount = (int)params[0].value.number;
+  else if (num_params == 1)
+  {
+    if (params[0].value.number < 1 || params[0].value.number > MAX_PENS)
+    {
+      fprintf(stderr,
+             "DEBUG: HP-GL/2 \'NP\' command with invalid number of "
+             "pens (%d)!\n", (int)params[0].value.number);
+      PenCount = 8;
+    }
+    else
+      PenCount = (int)params[0].value.number;
+  }
   else
-    fprintf(stderr, "WARNING: HP-GL/2 \'NP\' command with invalid number of parameters (%d)!\n",
-            num_params);
+    fprintf(stderr,
+            "DEBUG: HP-GL/2 \'NP\' command with invalid number of "
+           "parameters (%d)!\n", num_params);
 
-  for (i = 0; i <= PenCount; i ++)
+  for (i = 0; i < PenCount; i ++)
     Pens[i].width = PenWidth;
 
   PC_pen_color(0, NULL);
@@ -229,20 +232,20 @@ PC_pen_color(int     num_params,  /* I - Number of parameters */
   int          i;                      /* Looping var */
   static float standard_colors[8][3] = /* Standard colors for first 8 pens */
                {
-                 { 1.0, 1.0, 1.0 },    /* White */
                  { 0.0, 0.0, 0.0 },    /* Black */
                  { 1.0, 0.0, 0.0 },    /* Red */
                  { 0.0, 1.0, 0.0 },    /* Green */
                  { 1.0, 1.0, 0.0 },    /* Yellow */
                  { 0.0, 0.0, 1.0 },    /* Blue */
                  { 1.0, 0.0, 1.0 },    /* Magenta */
-                 { 0.0, 1.0, 1.0 }     /* Cyan */
+                 { 0.0, 1.0, 1.0 },    /* Cyan */
+                 { 1.0, 1.0, 1.0 }     /* White */
                };
 
 
   if (num_params == 0)
   {
-    for (i = 0; i <= PenCount; i ++)
+    for (i = 0; i < PenCount; i ++)
       if (i < 8)
       {
         Pens[i].rgb[0] = standard_colors[i][0];
@@ -263,7 +266,14 @@ PC_pen_color(int     num_params,   /* I - Number of parameters */
   }
   else if (num_params == 1 || num_params == 4)
   {
-    i = (int)params[0].value.number;
+    i = (int)params[0].value.number - 1;
+
+    if (i < 0 || i >= PenCount)
+    {
+      fprintf(stderr,
+              "DEBUG: HP-GL/2 \'PC\' command with invalid pen (%d)!\n", i + 1);
+      return;
+    }
 
     if (num_params == 1)
     {
@@ -292,8 +302,9 @@ PC_pen_color(int     num_params,    /* I - Number of parameters */
             Pens[PenNumber].width * PenScaling);
   }
   else
-    fprintf(stderr, "WARNING: HP-GL/2 \'PC\' command with invalid number of parameters (%d)!\n",
-            num_params);
+    fprintf(stderr,
+            "DEBUG: HP-GL/2 \'PC\' command with invalid number of "
+           "parameters (%d)!\n", num_params);
 }
 
 
@@ -336,7 +347,15 @@ PW_pen_width(int     num_params,   /* I - Number of parameters */
 
   if (num_params == 2)
   {
-    pen = (int)params[1].value.number;
+    pen = (int)params[1].value.number - 1;
+
+    if (pen < 0 || pen >= PenCount)
+    {
+      fprintf(stderr,
+              "DEBUG: HP-GL/2 \'PW\' command with invalid pen (%d)!\n",
+             pen + 1);
+      return;
+    }
 
     Pens[pen].width = w;
 
@@ -351,7 +370,7 @@ PW_pen_width(int     num_params,    /* I - Number of parameters */
     * Set width for all pens...
     */
 
-    for (pen = 0; pen <= PenCount; pen ++)
+    for (pen = 0; pen < PenCount; pen ++)
       Pens[pen].width = w;
 
     if (PageDirty)
@@ -360,8 +379,9 @@ PW_pen_width(int     num_params,    /* I - Number of parameters */
             Pens[PenNumber].width * PenScaling);
   }
   else
-    fprintf(stderr, "WARNING: HP-GL/2 \'PW\' command with invalid number of parameters (%d)!\n",
-            num_params);
+    fprintf(stderr,
+            "DEBUG: HP-GL/2 \'PW\' command with invalid number of "
+           "parameters (%d)!\n", num_params);
 }
 
 
@@ -404,12 +424,16 @@ SP_select_pen(int     num_params, /* I - Number of parameters */
               param_t *params)         /* I - Parameters */
 {
   if (num_params == 0)
-    PenNumber = 1;
-  else if (params[0].value.number <= PenCount)
-    PenNumber = (int)params[0].value.number;
+    PenNumber = 0;
+  else if (num_params > 1)
+    fprintf(stderr,
+            "DEBUG: HP-GL/2 \'SP\' command with invalid number of parameters "
+           "(%d)!\n", num_params);
+  else if (params[0].value.number <= 0 || params[0].value.number >= PenCount)
+    fprintf(stderr, "DEBUG: HP-GL/2 \'SP\' command with invalid pen (%d)!\n",
+           (int)params[0].value.number);
   else
-    fprintf(stderr, "WARNING: HP-GL/2 \'SP\' command with invalid number or value of parameters (%d, %d)!\n",
-            num_params, (int)params[0].value.number);
+    PenNumber = (int)params[0].value.number - 1;
 
   if (PageDirty)
     printf("%.3f %.3f %.3f %.2f SP\n", Pens[PenNumber].rgb[0],
@@ -444,11 +468,12 @@ WU_width_units(int     num_params,        /* I - Number of parameters */
   else if (num_params == 1)
     WidthUnits = (int)params[0].value.number;
   else
-    fprintf(stderr, "WARNING: HP-GL/2 \'WU\' command with invalid number of parameters (%d)!\n",
-            num_params);
+    fprintf(stderr,
+            "DEBUG: HP-GL/2 \'WU\' command with invalid number of "
+           "parameters (%d)!\n", num_params);
 }
 
 
 /*
- * End of "$Id: hpgl-attr.c 4494 2005-02-18 02:18:11Z mike $".
+ * End of "$Id: hpgl-attr.c 6649 2007-07-11 21:46:42Z mike $".
  */