]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/dest-localization.c
Stop parsing the Emulators keywords in PPD files (Issue #5475)
[thirdparty/cups.git] / cups / dest-localization.c
index 1eef3ea7a8798a11206fb6e8ca68593ab5beab80..67d01f496f6736fbbf95a89e9ffb50df758b1cd1 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include "cups-private.h"
+#include "debug-internal.h"
 
 
 /*
@@ -44,7 +45,7 @@ cupsLocalizeDestMedia(
   pwg_media_t          *pwg;           /* PWG media information */
   cups_array_t         *db;            /* Media database */
   _cups_media_db_t     *mdb;           /* Media database entry */
-  char                 name[1024],     /* Size name */
+  char                 lstr[1024],     /* Localized size name */
                        temp[256];      /* Temporary string */
   const char           *lsize,         /* Localized media size */
                        *lsource,       /* Localized media source */
@@ -65,41 +66,79 @@ cupsLocalizeDestMedia(
   }
 
  /*
-  * See if the localization is cached...
+  * Find the matching media database entry...
   */
 
-  if (!dinfo->localizations)
-    cups_create_localizations(http, dinfo);
+  if (flags & CUPS_MEDIA_FLAGS_READY)
+    db = dinfo->ready_db;
+  else
+    db = dinfo->media_db;
 
-  key.msg = size->media;
-  if ((match = (_cups_message_t *)cupsArrayFind(dinfo->localizations, &key)) != NULL)
+  DEBUG_printf(("1cupsLocalizeDestMedia: size->media=\"%s\"", size->media));
+
+  for (mdb = (_cups_media_db_t *)cupsArrayFirst(db); mdb; mdb = (_cups_media_db_t *)cupsArrayNext(db))
   {
-    DEBUG_printf(("1cupsLocalizeDestMedia: Returning \"%s\".", match->str));
-    return (match->str);
+    if (mdb->key && !strcmp(mdb->key, size->media))
+      break;
+    else if (mdb->size_name && !strcmp(mdb->size_name, size->media))
+      break;
+  }
+
+  if (!mdb)
+  {
+    for (mdb = (_cups_media_db_t *)cupsArrayFirst(db); mdb; mdb = (_cups_media_db_t *)cupsArrayNext(db))
+    {
+      if (mdb->width == size->width && mdb->length == size->length && mdb->bottom == size->bottom && mdb->left == size->left && mdb->right == size->right && mdb->top == size->top)
+       break;
+    }
   }
 
  /*
-  * If not, get the localized size, source, and type strings...
+  * See if the localization is cached...
   */
 
   lang = cupsLangDefault();
 
+  if (!dinfo->localizations)
+    cups_create_localizations(http, dinfo);
+
   snprintf(temp, sizeof(temp), "media.%s", size->media);
-  if ((lsize = _cupsLangString(lang, temp)) != NULL && strcmp(lsize, temp))
+  key.msg = temp;
+
+  if ((match = (_cups_message_t *)cupsArrayFind(dinfo->localizations, &key)) != NULL)
   {
-    DEBUG_printf(("1cupsLocalizeDestMedia: Returning standard localization \"%s\".", lsize));
-    return (lsize);
+    lsize = match->str;
+  }
+  else
+  {
+   /*
+    * Not a media name, try a media-key name...
+    */
+
+    snprintf(temp, sizeof(temp), "media-key.%s", size->media);
+    if ((match = (_cups_message_t *)cupsArrayFind(dinfo->localizations, &key)) != NULL)
+      lsize = match->str;
+    else
+      lsize = NULL;
   }
 
-  pwg  = pwgMediaForSize(size->width, size->length);
+  if (!lsize && (pwg = pwgMediaForSize(size->width, size->length)) != NULL && pwg->ppd)
+  {
+   /*
+    * Get a standard localization...
+    */
 
-  if (pwg->ppd)
-    lsize = _cupsLangString(lang, pwg->ppd);
-  else
-    lsize = NULL;
+    snprintf(temp, sizeof(temp), "media.%s", pwg->pwg);
+    if ((lsize = _cupsLangString(lang, temp)) == temp)
+      lsize = NULL;
+  }
 
   if (!lsize)
   {
+   /*
+    * Make a dimensional localization...
+    */
+
     if ((size->width % 635) == 0 && (size->length % 635) == 0)
     {
      /*
@@ -120,36 +159,14 @@ cupsLocalizeDestMedia(
     lsize = temp;
   }
 
-  if (flags & CUPS_MEDIA_FLAGS_READY)
-    db = dinfo->ready_db;
-  else
-    db = dinfo->media_db;
-
-  DEBUG_printf(("1cupsLocalizeDestMedia: size->media=\"%s\"", size->media));
-
-  for (mdb = (_cups_media_db_t *)cupsArrayFirst(db); mdb; mdb = (_cups_media_db_t *)cupsArrayNext(db))
-  {
-    if (mdb->key && !strcmp(mdb->key, size->media))
-      break;
-    else if (mdb->size_name && !strcmp(mdb->size_name, size->media))
-      break;
-  }
-
-  if (!mdb)
-  {
-    for (mdb = (_cups_media_db_t *)cupsArrayFirst(db); mdb; mdb = (_cups_media_db_t *)cupsArrayNext(db))
-    {
-      if (mdb->width == size->width && mdb->length == size->length && mdb->bottom == size->bottom && mdb->left == size->left && mdb->right == size->right && mdb->top == size->top)
-       break;
-    }
-  }
-
   if (mdb)
   {
     DEBUG_printf(("1cupsLocalizeDestMedia: MATCH mdb%p [key=\"%s\" size_name=\"%s\" source=\"%s\" type=\"%s\" width=%d length=%d B%d L%d R%d T%d]", (void *)mdb, mdb->key, mdb->size_name, mdb->source, mdb->type, mdb->width, mdb->length, mdb->bottom, mdb->left, mdb->right, mdb->top));
 
-    lsource = cupsLocalizeDestValue(http, dest, dinfo, "media-source", mdb->source);
-    ltype   = cupsLocalizeDestValue(http, dest, dinfo, "media-type", mdb->type);
+    if ((lsource = cupsLocalizeDestValue(http, dest, dinfo, "media-source", mdb->source)) == mdb->source && mdb->source)
+      lsource = _cupsLangString(lang, _("Other Tray"));
+    if ((ltype = cupsLocalizeDestValue(http, dest, dinfo, "media-type", mdb->type)) == mdb->type && mdb->type)
+      ltype = _cupsLangString(lang, _("Other Media"));
   }
   else
   {
@@ -159,38 +176,38 @@ cupsLocalizeDestMedia(
 
   if (!lsource && !ltype)
   {
-    if (size->bottom || size->left || size->right || size->top)
-      snprintf(name, sizeof(name), _cupsLangString(lang, _("%s (Borderless)")), lsize);
+    if (!size->bottom && !size->left && !size->right && !size->top)
+      snprintf(lstr, sizeof(lstr), _cupsLangString(lang, _("%s (Borderless)")), lsize);
     else
-      strlcpy(name, lsize, sizeof(name));
+      strlcpy(lstr, lsize, sizeof(lstr));
   }
   else if (!lsource)
   {
-    if (size->bottom || size->left || size->right || size->top)
-      snprintf(name, sizeof(name), _cupsLangString(lang, _("%s (Borderless, %s)")), lsize, ltype);
+    if (!size->bottom && !size->left && !size->right && !size->top)
+      snprintf(lstr, sizeof(lstr), _cupsLangString(lang, _("%s (Borderless, %s)")), lsize, ltype);
     else
-      snprintf(name, sizeof(name), _cupsLangString(lang, _("%s (%s)")), lsize, ltype);
+      snprintf(lstr, sizeof(lstr), _cupsLangString(lang, _("%s (%s)")), lsize, ltype);
   }
   else if (!ltype)
   {
-    if (size->bottom || size->left || size->right || size->top)
-      snprintf(name, sizeof(name), _cupsLangString(lang, _("%s (Borderless, %s)")), lsize, lsource);
+    if (!size->bottom && !size->left && !size->right && !size->top)
+      snprintf(lstr, sizeof(lstr), _cupsLangString(lang, _("%s (Borderless, %s)")), lsize, lsource);
     else
-      snprintf(name, sizeof(name), _cupsLangString(lang, _("%s (%s)")), lsize, lsource);
+      snprintf(lstr, sizeof(lstr), _cupsLangString(lang, _("%s (%s)")), lsize, lsource);
   }
   else
   {
-    if (size->bottom || size->left || size->right || size->top)
-      snprintf(name, sizeof(name), _cupsLangString(lang, _("%s (Borderless, %s, %s)")), lsize, ltype, lsource);
+    if (!size->bottom && !size->left && !size->right && !size->top)
+      snprintf(lstr, sizeof(lstr), _cupsLangString(lang, _("%s (Borderless, %s, %s)")), lsize, ltype, lsource);
     else
-      snprintf(name, sizeof(name), _cupsLangString(lang, _("%s (%s, %s)")), lsize, ltype, lsource);
+      snprintf(lstr, sizeof(lstr), _cupsLangString(lang, _("%s (%s, %s)")), lsize, ltype, lsource);
   }
 
   if ((match = (_cups_message_t *)calloc(1, sizeof(_cups_message_t))) == NULL)
     return (NULL);
 
   match->msg = strdup(size->media);
-  match->str = strdup(name);
+  match->str = strdup(lstr);
 
   cupsArrayAdd(dinfo->localizations, match);