/*
- * "$Id: page.c 5238 2006-03-07 04:41:42Z mike $"
+ * "$Id: page.c 7791 2008-07-24 00:55:30Z mike $"
*
* Page size functions for the Common UNIX Printing System (CUPS).
*
- * Copyright 1997-2005 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2010 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* 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/".
*
* PostScript is a trademark of Adobe Systems, Inc.
*
*
* Contents:
*
- * ppdPageSize() - Get the page size record for the given size.
- * ppdPageWidth() - Get the page width for the given size.
- * ppdPageLength() - Get the page length for the given size.
+ * ppdPageSize() - Get the page size record for the given size.
+ * ppdPageSizeLimits() - Return the custom page size limits.
+ * ppdPageWidth() - Get the page width for the given size.
+ * ppdPageLength() - Get the page length for the given size.
*/
/*
#include "ppd.h"
#include "string.h"
#include <ctype.h>
+#include "debug.h"
/*
const char *name) /* I - Size name */
{
int i; /* Looping var */
+ ppd_size_t *size; /* Current page size */
float w, l; /* Width and length of page */
char *nameptr; /* Pointer into name */
struct lconv *loc; /* Locale data */
+ ppd_coption_t *coption; /* Custom option for page size */
+ ppd_cparam_t *cparam; /* Custom option parameter */
+
+ DEBUG_printf(("2ppdPageSize(ppd=%p, name=\"%s\")", ppd, name));
if (!ppd)
+ {
+ DEBUG_puts("3ppdPageSize: Bad PPD pointer, returning NULL...");
return (NULL);
+ }
if (name)
{
* Find the custom page size...
*/
- for (i = 0; i < ppd->num_sizes; i ++)
- if (!strcmp("Custom", ppd->sizes[i].name))
+ for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
+ if (!strcmp("Custom", size->name))
break;
- if (i == ppd->num_sizes)
+ if (!i)
+ {
+ DEBUG_puts("3ppdPageSize: No custom sizes, returning NULL...");
return (NULL);
+ }
/*
* Variable size; size name can be one of the following:
*/
loc = localeconv();
- w = _cupsStrScand(name + 7, &nameptr, loc);
+ w = (float)_cupsStrScand(name + 7, &nameptr, loc);
if (!nameptr || *nameptr != 'x')
return (NULL);
- l = _cupsStrScand(nameptr, &nameptr, loc);
+ l = (float)_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;
- ppd->sizes[i].left = ppd->custom_margins[0];
- ppd->sizes[i].bottom = ppd->custom_margins[1];
- ppd->sizes[i].right = w * 72.0f - ppd->custom_margins[2];
- ppd->sizes[i].top = l * 72.0f - ppd->custom_margins[3];
+ w *= 72.0f;
+ l *= 72.0f;
}
- else if (!strcasecmp(nameptr, "cm"))
+ else if (!strcasecmp(nameptr, "ft"))
{
- ppd->sizes[i].width = w / 2.54f * 72.0f;
- ppd->sizes[i].length = l / 2.54f * 72.0f;
- ppd->sizes[i].left = ppd->custom_margins[0];
- ppd->sizes[i].bottom = ppd->custom_margins[1];
- 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];
+ w *= 12.0f * 72.0f;
+ l *= 12.0f * 72.0f;
}
else if (!strcasecmp(nameptr, "mm"))
{
- ppd->sizes[i].width = w / 25.4f * 72.0f;
- ppd->sizes[i].length = l / 25.4f * 72.0f;
- ppd->sizes[i].left = ppd->custom_margins[0];
- ppd->sizes[i].bottom = ppd->custom_margins[1];
- ppd->sizes[i].right = w / 25.4f * 72.0f - ppd->custom_margins[2];
- ppd->sizes[i].top = l / 25.4f * 72.0f - ppd->custom_margins[3];
+ w *= 72.0f / 25.4f;
+ l *= 72.0f / 25.4f;
+ }
+ else if (!strcasecmp(nameptr, "cm"))
+ {
+ w *= 72.0f / 2.54f;
+ l *= 72.0f / 2.54f;
+ }
+ else if (!strcasecmp(nameptr, "m"))
+ {
+ w *= 72.0f / 0.0254f;
+ l *= 72.0f / 0.0254f;
}
- else
+
+ size->width = w;
+ size->length = l;
+ size->left = ppd->custom_margins[0];
+ size->bottom = ppd->custom_margins[1];
+ size->right = w - ppd->custom_margins[2];
+ size->top = l - ppd->custom_margins[3];
+
+ /*
+ * Update the custom option records for the page size, too...
+ */
+
+ if ((coption = ppdFindCustomOption(ppd, "PageSize")) != NULL)
{
- ppd->sizes[i].width = w;
- ppd->sizes[i].length = l;
- ppd->sizes[i].left = ppd->custom_margins[0];
- ppd->sizes[i].bottom = ppd->custom_margins[1];
- ppd->sizes[i].right = w - ppd->custom_margins[2];
- ppd->sizes[i].top = l - ppd->custom_margins[3];
+ if ((cparam = ppdFindCustomParam(coption, "Width")) != NULL)
+ cparam->current.custom_points = w;
+
+ if ((cparam = ppdFindCustomParam(coption, "Height")) != NULL)
+ cparam->current.custom_points = l;
}
- return (ppd->sizes + i);
+ /*
+ * Return the page size...
+ */
+
+ DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size,
+ size->name, size->width, size->length));
+
+ return (size);
}
else
{
* Lookup by name...
*/
- for (i = 0; i < ppd->num_sizes; i ++)
- if (!strcasecmp(name, ppd->sizes[i].name))
- return (ppd->sizes + i);
+ for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
+ if (!strcasecmp(name, size->name))
+ {
+ DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size,
+ size->name, size->width, size->length));
+
+ return (size);
+ }
}
}
else
* Find default...
*/
- for (i = 0; i < ppd->num_sizes; i ++)
- if (ppd->sizes[i].marked)
- return (ppd->sizes + i);
+ for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
+ if (size->marked)
+ {
+ DEBUG_printf(("3ppdPageSize: Returning %p (\"%s\", %gx%g)", size,
+ size->name, size->width, size->length));
+
+ return (size);
+ }
}
+ DEBUG_puts("3ppdPageSize: Size not found, returning NULL");
+
return (NULL);
}
+/*
+ * 'ppdPageSizeLimits()' - Return the custom page size limits.
+ *
+ * This function returns the minimum and maximum custom page sizes and printable
+ * areas based on the currently-marked (selected) options.
+ *
+ * If the specified PPD file does not support custom page sizes, both
+ * "minimum" and "maximum" are filled with zeroes.
+ *
+ * @since CUPS 1.4/Mac OS X 10.6@
+ */
+
+int /* O - 1 if custom sizes are supported, 0 otherwise */
+ppdPageSizeLimits(ppd_file_t *ppd, /* I - PPD file record */
+ ppd_size_t *minimum, /* O - Minimum custom size */
+ ppd_size_t *maximum) /* O - Maximum custom size */
+{
+ ppd_choice_t *qualifier2, /* Second media qualifier */
+ *qualifier3; /* Third media qualifier */
+ ppd_attr_t *attr; /* Attribute */
+ float width, /* Min/max width */
+ length; /* Min/max length */
+ char spec[PPD_MAX_NAME]; /* Selector for min/max */
+
+
+ /*
+ * Range check input...
+ */
+
+ if (!ppd || !ppd->variable_sizes || !minimum || !maximum)
+ {
+ if (minimum)
+ memset(minimum, 0, sizeof(ppd_size_t));
+
+ if (maximum)
+ memset(maximum, 0, sizeof(ppd_size_t));
+
+ return (0);
+ }
+
+ /*
+ * See if we have the cupsMediaQualifier2 and cupsMediaQualifier3 attributes...
+ */
+
+ cupsArraySave(ppd->sorted_attrs);
+
+ if ((attr = ppdFindAttr(ppd, "cupsMediaQualifier2", NULL)) != NULL &&
+ attr->value)
+ qualifier2 = ppdFindMarkedChoice(ppd, attr->value);
+ else
+ qualifier2 = NULL;
+
+ if ((attr = ppdFindAttr(ppd, "cupsMediaQualifier3", NULL)) != NULL &&
+ attr->value)
+ qualifier3 = ppdFindMarkedChoice(ppd, attr->value);
+ else
+ qualifier3 = NULL;
+
+ /*
+ * Figure out the current minimum width and length...
+ */
+
+ width = ppd->custom_min[0];
+ length = ppd->custom_min[1];
+
+ if (qualifier2)
+ {
+ /*
+ * Try getting cupsMinSize...
+ */
+
+ if (qualifier3)
+ {
+ snprintf(spec, sizeof(spec), ".%s.%s", qualifier2->choice,
+ qualifier3->choice);
+ attr = ppdFindAttr(ppd, "cupsMinSize", spec);
+ }
+ else
+ attr = NULL;
+
+ if (!attr)
+ {
+ snprintf(spec, sizeof(spec), ".%s.", qualifier2->choice);
+ attr = ppdFindAttr(ppd, "cupsMinSize", spec);
+ }
+
+ if (!attr && qualifier3)
+ {
+ snprintf(spec, sizeof(spec), "..%s", qualifier3->choice);
+ attr = ppdFindAttr(ppd, "cupsMinSize", spec);
+ }
+
+ if ((attr && attr->value &&
+ sscanf(attr->value, "%f%f", &width, &length) != 2) || !attr)
+ {
+ width = ppd->custom_min[0];
+ length = ppd->custom_min[1];
+ }
+ }
+
+ minimum->width = width;
+ minimum->length = length;
+ minimum->left = ppd->custom_margins[0];
+ minimum->bottom = ppd->custom_margins[1];
+ minimum->right = width - ppd->custom_margins[2];
+ minimum->top = length - ppd->custom_margins[3];
+
+ /*
+ * Figure out the current maximum width and length...
+ */
+
+ width = ppd->custom_max[0];
+ length = ppd->custom_max[1];
+
+ if (qualifier2)
+ {
+ /*
+ * Try getting cupsMaxSize...
+ */
+
+ if (qualifier3)
+ {
+ snprintf(spec, sizeof(spec), ".%s.%s", qualifier2->choice,
+ qualifier3->choice);
+ attr = ppdFindAttr(ppd, "cupsMaxSize", spec);
+ }
+ else
+ attr = NULL;
+
+ if (!attr)
+ {
+ snprintf(spec, sizeof(spec), ".%s.", qualifier2->choice);
+ attr = ppdFindAttr(ppd, "cupsMaxSize", spec);
+ }
+
+ if (!attr && qualifier3)
+ {
+ snprintf(spec, sizeof(spec), "..%s", qualifier3->choice);
+ attr = ppdFindAttr(ppd, "cupsMaxSize", spec);
+ }
+
+ if (!attr ||
+ (attr->value && sscanf(attr->value, "%f%f", &width, &length) != 2))
+ {
+ width = ppd->custom_max[0];
+ length = ppd->custom_max[1];
+ }
+ }
+
+ maximum->width = width;
+ maximum->length = length;
+ maximum->left = ppd->custom_margins[0];
+ maximum->bottom = ppd->custom_margins[1];
+ maximum->right = width - ppd->custom_margins[2];
+ maximum->top = length - ppd->custom_margins[3];
+
+ /*
+ * Return the min and max...
+ */
+
+ cupsArrayRestore(ppd->sorted_attrs);
+
+ return (1);
+}
+
+
/*
* 'ppdPageWidth()' - Get the page width for the given size.
*/
/*
- * End of "$Id: page.c 5238 2006-03-07 04:41:42Z mike $".
+ * End of "$Id: page.c 7791 2008-07-24 00:55:30Z mike $".
*/