* information.
*/
-/*
- * Include necessary headers...
- */
-
#include "cups-private.h"
#include "debug-internal.h"
*media_attr, /* media-xxx */
*x_dimension, /* x-dimension */
*y_dimension; /* y-dimension */
- pwg_media_t *pwg; /* PWG media info */
cups_array_t *db; /* New media database array */
_cups_media_db_t mdb; /* Media entry */
char media_key[256]; /* Synthesized media-key value */
if (!mdb.key)
{
- if (!mdb.size_name && (pwg = pwgMediaForSize(mdb.width, mdb.length)) != NULL)
- mdb.size_name = (char *)pwg->pwg;
+ pwg_media_t pwg; /* PWG media info */
+ char keyword[128], /* PWG size keyword */
+ ppdname[41]; /* PPD size name */
+
+ if (!mdb.size_name && _pwgMediaNearSize(&pwg, keyword, sizeof(keyword), ppdname, sizeof(ppdname), mdb.width, mdb.length, _PWG_EPSILON))
+ mdb.size_name = keyword;
if (!mdb.size_name)
{
i > 0;
i --, val ++)
{
+ pwg_media_t *pwg; /* PWG media information */
+
if ((pwg = pwgMediaForPWG(val->string.text)) == NULL)
+ {
if ((pwg = pwgMediaForLegacy(val->string.text)) == NULL)
{
DEBUG_printf("3cups_create_media_db: Ignoring unknown size '%s'.", val->string.text);
continue;
}
+ }
mdb.width = pwg->width;
mdb.length = pwg->length;
- if (flags != CUPS_MEDIA_FLAGS_READY &&
- !strncmp(val->string.text, "custom_min_", 11))
+ if (flags != CUPS_MEDIA_FLAGS_READY && !strncmp(val->string.text, "custom_min_", 11))
{
mdb.size_name = NULL;
dinfo->min_size = mdb;
}
- else if (flags != CUPS_MEDIA_FLAGS_READY &&
- !strncmp(val->string.text, "custom_max_", 11))
+ else if (flags != CUPS_MEDIA_FLAGS_READY && !strncmp(val->string.text, "custom_max_", 11))
{
mdb.size_name = NULL;
dinfo->max_size = mdb;
ppd_name[PPD_MAX_NAME];
/* Normalized PPD name */
const char *pwg_name; /* Standard PWG media name */
- pwg_media_t *pwg_media; /* PWG media data */
+ pwg_media_t *pwg_media, /* PWG media data */
+ pwg_mediatemp; /* PWG media data buffer */
_pwg_print_color_mode_t pwg_print_color_mode;
/* print-color-mode index */
_pwg_print_quality_t pwg_print_quality;
* dimensions that are <= 0...
*/
- if ((pwg_media = _pwgMediaNearSize(PWG_FROM_POINTS(ppd_size->width),
- PWG_FROM_POINTS(ppd_size->length),
- 0)) == NULL)
+ if ((pwg_media = _pwgMediaNearSize(&pwg_mediatemp, /*keyword*/NULL, /*keysize*/0, /*ppdname*/NULL, /*ppdsize*/0, PWG_FROM_POINTS(ppd_size->width), PWG_FROM_POINTS(ppd_size->length), /*epsilon*/0)) == NULL)
continue;
new_width = pwg_media->width;
#define _PWG_MEDIA_IN(p,l,a,x,y) {p, l, a, (int)(x * 2540), (int)(y * 2540)}
#define _PWG_MEDIA_MM(p,l,a,x,y) {p, l, a, (int)(x * 100), (int)(y * 100)}
-#define _PWG_EPSILON 50 /* Matching tolerance */
/*
pwgMediaForSize(int width, /* I - Width in hundredths of millimeters */
int length) /* I - Length in hundredths of millimeters */
{
+ _cups_globals_t *cg = _cupsGlobals(); /* Global data */
+
+
/*
* Adobe uses a size matching algorithm with an epsilon of 5 points, which
* is just about 176/2540ths... But a lot of international media sizes are
* very close so use 0.5mm (50/2540ths) as the maximum delta.
*/
- return (_pwgMediaNearSize(width, length, _PWG_EPSILON));
+ return (_pwgMediaNearSize(&cg->pwg_media, cg->pwg_name, sizeof(cg->pwg_name), cg->ppd_name, sizeof(cg->ppd_name), width, length, _PWG_EPSILON));
}
* '_pwgMediaNearSize()' - Get the PWG media size within the given tolerance.
*/
-pwg_media_t * /* O - PWG media name */
-_pwgMediaNearSize(int width, /* I - Width in hundredths of millimeters */
- int length, /* I - Length in hundredths of millimeters */
- int epsilon) /* I - Match within this tolernace. PWG units */
+pwg_media_t * /* O - PWG media */
+_pwgMediaNearSize(pwg_media_t *pwg, /* I - Media buffer */
+ char *keyword, /* I - Media keyword buffer */
+ size_t keysize, /* I - Size of media keyword buffer */
+ char *ppdname, /* I - PPD name buffer */
+ size_t ppdsize, /* I - Size of PPD name buffer */
+ int width, /* I - Width in hundredths of millimeters */
+ int length, /* I - Length in hundredths of millimeters */
+ int epsilon) /* I - Match within this tolernace. PWG units */
{
int i; /* Looping var */
pwg_media_t *media, /* Current media */
best_dw = 999, /* Best difference in width and length */
best_dl = 999;
char wstr[32], lstr[32]; /* Width and length as strings */
- _cups_globals_t *cg = _cupsGlobals(); /* Global data */
/*
* Look for a standard size...
*/
- for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])),
- media = (pwg_media_t *)cups_pwg_media;
- i > 0;
- i --, media ++)
+ for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])), media = (pwg_media_t *)cups_pwg_media; i > 0; i --, media ++)
{
-
dw = abs(media->width - width);
dl = abs(media->length - length);
if (!dw && !dl)
+ {
return (media);
+ }
else if (dw <= epsilon && dl <= epsilon)
{
if (dw <= best_dw && dl <= best_dl)
* custom_WIDTHxHEIGHTuu_WIDTHxHEIGHTuu
*/
- pwgFormatSizeName(cg->pwg_name, sizeof(cg->pwg_name), "custom", NULL, width,
- length, NULL);
+ if (keyword)
+ pwgFormatSizeName(keyword, keysize, "custom", NULL, width, length, NULL);
- cg->pwg_media.pwg = cg->pwg_name;
- cg->pwg_media.width = width;
- cg->pwg_media.length = length;
+ if (ppdname)
+ {
+ if ((width % 635) == 0 && (length % 635) == 0)
+ snprintf(ppdname, ppdsize, "%sx%s", pwg_format_inches(wstr, sizeof(wstr), width), pwg_format_inches(lstr, sizeof(lstr), length));
+ else
+ snprintf(ppdname, ppdsize, "%sx%smm", pwg_format_millimeters(wstr, sizeof(wstr), width), pwg_format_millimeters(lstr, sizeof(lstr), length));
+ }
- if ((width % 635) == 0 && (length % 635) == 0)
- snprintf(cg->ppd_name, sizeof(cg->ppd_name), "%sx%s", pwg_format_inches(wstr, sizeof(wstr), width), pwg_format_inches(lstr, sizeof(lstr), length));
- else
- snprintf(cg->ppd_name, sizeof(cg->ppd_name), "%sx%smm", pwg_format_millimeters(wstr, sizeof(wstr), width), pwg_format_millimeters(lstr, sizeof(lstr), length));
- cg->pwg_media.ppd = cg->ppd_name;
+ pwg->pwg = keyword;
+ pwg->ppd = ppdname;
+ pwg->width = width;
+ pwg->length = length;
- return (&(cg->pwg_media));
+ return (pwg);
}