]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Validate page size names.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 22 Apr 2011 06:37:54 +0000 (06:37 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 22 Apr 2011 06:37:54 +0000 (06:37 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@9708 7a7537e8-13f0-0310-91df-b6672ffda945

systemv/cupstestppd.c

index 378b62e822c4070082278fd3a8d032f5e2806ea1..8221ae8deb14c7b21de890558fa33fc7fe46fcee 100644 (file)
@@ -32,7 +32,7 @@
  *   check_translations() - Check translations in the PPD file.
  *   show_conflicts()     - Show option conflicts in a PPD file.
  *   test_raster()        - Test PostScript commands for raster printers.
- *   usage()              - Show program usage...
+ *   usage()              - Show program usage.
  *   valid_path()         - Check whether a path has the correct capitalization.
  *   valid_utf8()         - Check whether a string contains valid UTF-8 text.
  */
@@ -2923,13 +2923,25 @@ check_sizes(ppd_file_t *ppd,            /* I - PPD file */
            int        verbose,         /* I - Verbosity level */
            int        warn)            /* I - Warnings only? */
 {
-  int          i;                      /* Looping vars */
+  int          i;                      /* Looping var */
   ppd_size_t   *size;                  /* Current size */
   int          width,                  /* Custom width */
                length;                 /* Custom length */
   const char   *prefix;                /* WARN/FAIL prefix */
   ppd_option_t *page_size,             /* PageSize option */
                *page_region;           /* PageRegion option */
+  _pwg_media_t  *pwg_media;             /* PWG media */
+  char          buf[1024];              /* PapeSize name that is supposed to be */
+  const char   *ptr;                   /* Pointer into string */
+  int          width_2540ths,          /* PageSize width in 2540ths */
+               length_2540ths;         /* PageSize length in 2540ths */
+  int          is_ok;                  /* Flag for PageSize name verification */
+  double       width_tmp,              /* Width after rounded up */
+               length_tmp,             /* Length after rounded up */
+               width_inch,             /* Width in inches */
+               length_inch,            /* Length in inches */
+               width_mm,               /* Width in millimeters */
+               length_mm;              /* Length in millimeters */
 
 
   prefix = warn ? "  WARN  " : "**FAIL**";
@@ -3035,6 +3047,112 @@ check_sizes(ppd_file_t *ppd,            /* I - PPD file */
       if (!warn)
        errors ++;
     }
+
+   /*
+    * Verify that the size name is Adobe standard name if it's a standard size
+    * and the dementional name if it's not a standard size.  Suffix should be
+    * .Fullbleed, etc., or numeric, e.g., Letter, Letter.Fullbleed,
+    * Letter.Transverse, Letter1, Letter2, 4x8, 55x91mm, 55x91mm.Fullbleed, etc.
+    */
+
+    if (warn != 0)
+    {
+      is_ok          = 1;
+      width_2540ths  = (size->length > size->width) ?
+                           _PWG_FROMPTS(size->width) :
+                          _PWG_FROMPTS(size->length);
+      length_2540ths = (size->length > size->width) ?
+                           _PWG_FROMPTS(size->length) :
+                          _PWG_FROMPTS(size->width);
+      pwg_media      = _pwgMediaForSize(width_2540ths, length_2540ths);
+
+      if (pwg_media && pwg_media->ppd)
+      {
+        strlcpy(buf, pwg_media->ppd, sizeof(buf));
+
+        if (size->left == 0 && size->bottom == 0 &&
+           size->right == size->width && size->top == size->length)
+        {
+          snprintf(buf, sizeof(buf), "%s.Fullbleed", pwg_media->ppd);
+         if (strcmp(size->name, buf))
+           is_ok = 0;                                  
+        }
+        else if (size->width > size->length)
+        {
+         if ((ptr = pwg_media->ppd + strlen(pwg_media->ppd) - 7)
+                 >= pwg_media->ppd && !strcmp(ptr, "Rotated"))
+         {
+           if (strcmp(size->name, buf))
+             is_ok = 0;
+         }
+         else
+         {
+           snprintf(buf, sizeof(buf), "%sRotated", pwg_media->ppd);
+           if (strcmp(size->name, buf))
+           {
+             snprintf(buf, sizeof(buf), "%s.Transverse", pwg_media->ppd);
+             if (strcmp(size->name, buf))
+               is_ok = 0;                                      
+           }
+         }
+        }
+       else
+        {
+         if ((!strncmp(size->name, pwg_media->ppd, strlen(pwg_media->ppd))))
+          {
+            for (ptr = size->name + strlen(pwg_media->ppd); *ptr; ptr ++)
+            {
+              if (!isdigit(*ptr & 255))
+             {
+                is_ok = 0;
+               break;
+             }
+            }
+          }
+          else
+            is_ok = 0;
+        }
+        
+        if (!is_ok)
+          _cupsLangPrintf(stdout,
+                          _("      %s  Size \"%s\" should be the Adobe "
+                           "standard name \"%s\"."),
+                          prefix, size->name, buf);
+      }
+      else
+      {
+        width_tmp  = (fabs(size->width - ceil(size->width)) < 0.1) ?
+                        ceil(size->width) : size->width;
+        length_tmp = (fabs(size->length - ceil(size->length)) < 0.1) ?
+                        ceil(size->length) : size->length;
+
+        if (fmod(width_tmp, 18.0) == 0.0 && fmod(length_tmp, 18.0) == 0.0)
+        {
+          width_inch  = width_tmp / 72.0;
+          length_inch = length_tmp / 72.0;
+
+          snprintf(buf, sizeof(buf), "%gx%g", width_inch, length_inch);
+        }
+        else
+        {
+          width_mm  = size->width / 72.0 * 25.4;
+          length_mm = size->length / 72.0 * 25.4;
+
+          snprintf(buf, sizeof(buf), "%.0fx%.0fmm", width_mm, length_mm);
+        }
+
+        if (size->left == 0 && size->bottom == 0 &&
+           size->right == size->width && size->top == size->length)
+          strlcat(buf, ".Fullbleed", sizeof(buf));
+        else if (size->width > size->length)
+          strlcat(buf, ".Transverse", sizeof(buf));
+
+        if (strcmp(size->name, buf))
+          _cupsLangPrintf(stdout,
+                          _("      %s  Size \"%s\" should be \"%s\"."),
+                          prefix, size->name, buf);
+      }
+    }
   }
 
   return (errors);
@@ -3485,7 +3603,7 @@ test_raster(ppd_file_t *ppd,              /* I - PPD file */
 
 
 /*
- * 'usage()' - Show program usage...
+ * 'usage()' - Show program usage.
  */
 
 static void