#include "ppd.h"
#include "string.h"
#include <ctype.h>
ppd_size_t *
ppdPageSize(ppd_file_t *ppd,
const char *name)
{
int i;
ppd_size_t *size;
float w, l;
char *nameptr;
struct lconv *loc;
ppd_coption_t *coption;
ppd_cparam_t *cparam;
if (!ppd)
return (NULL);
if (name)
{
if (!strncmp(name, "Custom.", 7) && ppd->variable_sizes)
{
for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
if (!strcmp("Custom", size->name))
break;
if (!i)
return (NULL);
loc = localeconv();
w = (float)_cupsStrScand(name + 7, &nameptr, loc);
if (!nameptr || *nameptr != 'x')
return (NULL);
l = (float)_cupsStrScand(nameptr + 1, &nameptr, loc);
if (!nameptr)
return (NULL);
if (!strcasecmp(nameptr, "in"))
{
w *= 72.0f;
l *= 72.0f;
}
else if (!strcasecmp(nameptr, "ft"))
{
w *= 12.0f * 72.0f;
l *= 12.0f * 72.0f;
}
else if (!strcasecmp(nameptr, "mm"))
{
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;
}
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];
if ((coption = ppdFindCustomOption(ppd, "PageSize")) != NULL)
{
if ((cparam = ppdFindCustomParam(coption, "Width")) != NULL)
cparam->current.custom_points = w;
if ((cparam = ppdFindCustomParam(coption, "Height")) != NULL)
cparam->current.custom_points = l;
}
return (size);
}
else
{
for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
if (!strcmp(name, size->name))
return (size);
}
}
else
{
for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
if (size->marked)
return (size);
}
return (NULL);
}
float
ppdPageWidth(ppd_file_t *ppd,
const char *name)
{
ppd_size_t *size;
if ((size = ppdPageSize(ppd, name)) == NULL)
return (0.0);
else
return (size->width);
}
float
ppdPageLength(ppd_file_t *ppd,
const char *name)
{
ppd_size_t *size;
if ((size = ppdPageSize(ppd, name)) == NULL)
return (0.0);
else
return (size->length);
}