]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/page.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / page.c
index 0c340297a39d82a17d4067d09ed1fbd64f886e32..f835c41c0f9585d43eb3f485babe3c26b587d069 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: page.c 4494 2005-02-18 02:18:11Z mike $"
+ * "$Id: page.c 5548 2006-05-19 19:38:31Z mike $"
  *
  *   Page size functions for the Common UNIX Printing System (CUPS).
  *
  * 'ppdPageSize()' - Get the page size record for the given size.
  */
 
-ppd_size_t *                   /* O - Size record for page or NULL */
-ppdPageSize(ppd_file_t *ppd,   /* I - PPD file record */
-            const char *name)  /* I - Size name */
+ppd_size_t *                           /* O - Size record for page or NULL */
+ppdPageSize(ppd_file_t *ppd,           /* I - PPD file record */
+            const char *name)          /* I - Size name */
 {
-  int  i;                      /* Looping var */
-  float        w, l;                   /* Width and length of page */
-  char units[255];             /* Page size units... */
+  int          i;                      /* Looping var */
+  float                w, l;                   /* Width and length of page */
+  char         *nameptr;               /* Pointer into name */
+  struct lconv *loc;                   /* Locale data */
 
 
-  if (ppd == NULL)
+  if (!ppd)
     return (NULL);
 
-  if (name != NULL)
+  if (name)
   {
-    if (strncmp(name, "Custom.", 7) == 0 && ppd->variable_sizes)
+    if (!strncmp(name, "Custom.", 7) && ppd->variable_sizes)
     {
      /*
       * Find the custom page size...
       */
 
       for (i = 0; i < ppd->num_sizes; i ++)
-       if (strcmp("Custom", ppd->sizes[i].name) == 0)
+       if (!strcmp("Custom", ppd->sizes[i].name))
           break;
 
       if (i == ppd->num_sizes)
@@ -81,11 +82,16 @@ ppdPageSize(ppd_file_t *ppd,        /* I - PPD file record */
       *    Custom.WIDTHxLENGTH[pt]  - Size in points
       */
 
-      units[0] = '\0';
-      if (sscanf(name + 7, "%fx%f%254s", &w, &l, units) < 2)
+      loc = localeconv();
+      w   = _cupsStrScand(name + 7, &nameptr, loc);
+      if (!nameptr || *nameptr != 'x')
         return (NULL);
 
-      if (strcasecmp(units, "in") == 0)
+      l = _cupsStrScand(nameptr + 1, &nameptr, loc);
+      if (!nameptr)
+        return (NULL);
+
+      if (!strcasecmp(nameptr, "in"))
       {
         ppd->sizes[i].width  = w * 72.0f;
        ppd->sizes[i].length = l * 72.0f;
@@ -94,7 +100,7 @@ ppdPageSize(ppd_file_t *ppd, /* I - PPD file record */
        ppd->sizes[i].right  = w * 72.0f - ppd->custom_margins[2];
        ppd->sizes[i].top    = l * 72.0f - ppd->custom_margins[3];
       }
-      else if (strcasecmp(units, "cm") == 0)
+      else if (!strcasecmp(nameptr, "cm"))
       {
         ppd->sizes[i].width  = w / 2.54f * 72.0f;
        ppd->sizes[i].length = l / 2.54f * 72.0f;
@@ -103,7 +109,7 @@ ppdPageSize(ppd_file_t *ppd,        /* I - PPD file record */
        ppd->sizes[i].right  = w / 2.54f * 72.0f - ppd->custom_margins[2];
        ppd->sizes[i].top    = l / 2.54f * 72.0f - ppd->custom_margins[3];
       }
-      else if (strcasecmp(units, "mm") == 0)
+      else if (!strcasecmp(nameptr, "mm"))
       {
         ppd->sizes[i].width  = w / 25.4f * 72.0f;
        ppd->sizes[i].length = l / 25.4f * 72.0f;
@@ -131,7 +137,7 @@ ppdPageSize(ppd_file_t *ppd,        /* I - PPD file record */
       */
 
       for (i = 0; i < ppd->num_sizes; i ++)
-       if (strcmp(name, ppd->sizes[i].name) == 0)
+       if (!strcasecmp(name, ppd->sizes[i].name))
           return (ppd->sizes + i);
     }
   }
@@ -187,5 +193,5 @@ ppdPageLength(ppd_file_t *ppd,      /* I - PPD file */
 
 
 /*
- * End of "$Id: page.c 4494 2005-02-18 02:18:11Z mike $".
+ * End of "$Id: page.c 5548 2006-05-19 19:38:31Z mike $".
  */