-CHANGES.txt - 1.7b1 - 2013-01-30
+CHANGES.txt - 1.7b1 - 2013-03-11
--------------------------------
CHANGES IN CUPS V1.7b1
- Added a new "-x" option to the cancel command (STR #4103)
+ - Made the PWG media handling APIs public (STR #4267)
- Added new ippCreateRequestedArray API for generating a array of
attributes from the requested-attributes attribute.
- The ipptool utility now supports compression, conditional tests based
ipp.h \
language.h \
ppd.h \
+ pwg.h \
raster.h \
sidechannel.h \
transcode.h \
--css ../doc/cups-printable.css \
--header api-cups.header --intro api-cups.shtml \
api-cups.xml \
- cups.h adminutil.c dest*.c language.c notify.c \
- options.c tempfile.c usersys.c \
+ cups.h pwg.h adminutil.c dest*.c language.c notify.c \
+ options.c pwg-media.c tempfile.c usersys.c \
util.c >../doc/help/api-cups.html
mxmldoc --tokens help/api-cups.html api-cups.xml >../doc/help/api-cups.tokens
$(RM) api-cups.xml
cups_array_t *leg_size_lut, /* Lookup table for legacy names */
*ppd_size_lut, /* Lookup table for PPD names */
*pwg_size_lut; /* Lookup table for PWG names */
- _pwg_media_t pwg_media; /* PWG media data for custom size */
+ pwg_media_t pwg_media; /* PWG media data for custom size */
char pwg_name[65]; /* PWG media name for custom size */
/* request.c */
*
* API definitions for CUPS.
*
- * Copyright 2007-2012 by Apple Inc.
+ * Copyright 2007-2013 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
# include "file.h"
# include "ipp.h"
# include "language.h"
+# include "pwg.h"
/*
static void cups_create_media_db(cups_dinfo_t *dinfo);
static void cups_free_media_db(_cups_media_db_t *mdb);
static int cups_get_media_db(cups_dinfo_t *dinfo,
- _pwg_media_t *pwg, unsigned flags,
+ pwg_media_t *pwg, unsigned flags,
cups_size_t *size);
static int cups_is_close_media_db(_cups_media_db_t *a,
_cups_media_db_t *b);
* Check range of custom media sizes...
*/
- _pwg_media_t *pwg; /* Current PWG media size info */
+ pwg_media_t *pwg; /* Current PWG media size info */
int min_width, /* Minimum width */
min_length, /* Minimum length */
max_width, /* Maximum width */
i --, attrval ++)
{
if (!strncmp(attrval->string.text, "custom_min_", 11) &&
- (pwg = _pwgMediaForPWG(attrval->string.text)) != NULL)
+ (pwg = pwgMediaForPWG(attrval->string.text)) != NULL)
{
min_width = pwg->width;
min_length = pwg->length;
}
else if (!strncmp(attrval->string.text, "custom_max_", 11) &&
- (pwg = _pwgMediaForPWG(attrval->string.text)) != NULL)
+ (pwg = pwgMediaForPWG(attrval->string.text)) != NULL)
{
max_width = pwg->width;
max_length = pwg->length;
*/
if (min_width < INT_MAX && max_width > 0 &&
- (pwg = _pwgMediaForPWG(value)) != NULL &&
+ (pwg = pwgMediaForPWG(value)) != NULL &&
pwg->width >= min_width && pwg->width <= max_width &&
pwg->length >= min_length && pwg->length <= max_length)
return (1);
unsigned flags, /* I - Media matching flags */
cups_size_t *size) /* O - Media size information */
{
- _pwg_media_t *pwg; /* PWG media info */
+ pwg_media_t *pwg; /* PWG media info */
/*
* Lookup the media size name...
*/
- if ((pwg = _pwgMediaForPWG(media)) == NULL)
- if ((pwg = _pwgMediaForLegacy(media)) == NULL)
+ if ((pwg = pwgMediaForPWG(media)) == NULL)
+ if ((pwg = pwgMediaForLegacy(media)) == NULL)
{
DEBUG_printf(("1cupsGetDestMediaByName: Unknown size '%s'.", media));
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unknown media size name."), 1);
unsigned flags, /* I - Media matching flags */
cups_size_t *size) /* O - Media size information */
{
- _pwg_media_t *pwg; /* PWG media info */
+ pwg_media_t *pwg; /* PWG media info */
/*
* Lookup the media size name...
*/
- if ((pwg = _pwgMediaForSize(width, length)) == NULL)
+ if ((pwg = pwgMediaForSize(width, length)) == NULL)
{
DEBUG_printf(("1cupsGetDestMediaBySize: Invalid size %dx%d.", width,
length));
*media_attr, /* media-xxx */
*x_dimension, /* x-dimension */
*y_dimension; /* y-dimension */
- _pwg_media_t *pwg; /* PWG media info */
+ pwg_media_t *pwg; /* PWG media info */
_cups_media_db_t mdb; /* Media entry */
i > 0;
i --, val ++)
{
- if ((pwg = _pwgMediaForPWG(val->string.text)) == NULL)
- if ((pwg = _pwgMediaForLegacy(val->string.text)) == NULL)
+ 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));
static int /* O - 1 on match, 0 on failure */
cups_get_media_db(cups_dinfo_t *dinfo, /* I - Destination information */
- _pwg_media_t *pwg, /* I - PWG media info */
+ pwg_media_t *pwg, /* I - PWG media info */
unsigned flags, /* I - Media matching flags */
cups_size_t *size) /* O - Media size/margin/name info */
{
int namesize) /* I - Size of buffer */
{
CFStringRef defaultPaperID; /* Default paper ID */
- _pwg_media_t *pwgmedia; /* PWG media size */
+ pwg_media_t *pwgmedia; /* PWG media size */
defaultPaperID = _cupsAppleCopyDefaultPaperID();
!CFStringGetCString(defaultPaperID, name, namesize,
kCFStringEncodingUTF8))
name[0] = '\0';
- else if ((pwgmedia = _pwgMediaForLegacy(name)) != NULL)
+ else if ((pwgmedia = pwgMediaForLegacy(name)) != NULL)
strlcpy(name, pwgmedia->pwg, namesize);
if (defaultPaperID)
* _ppdCacheWriteFile() - Write PWG mapping data to a file.
* _pwgInputSlotForSource() - Get the InputSlot name for the given PWG
* media-source.
- * _pwgMediaTypeForType() - Get the MediaType name for the given PWG
+ * pwgMediaTypeForType() - Get the MediaType name for the given PWG
* media-type.
* _pwgPageSizeForMedia() - Get the PageSize name for the given media.
* pwg_ppdize_name() - Convert an IPP keyword to a PPD keyword.
{
cups_file_t *fp; /* File */
_ppd_cache_t *pc; /* PWG mapping data */
- _pwg_size_t *size; /* Current size */
- _pwg_map_t *map; /* Current map */
+ pwg_size_t *size; /* Current size */
+ pwg_map_t *map; /* Current map */
_pwg_finishings_t *finishings; /* Current finishings option */
int linenum, /* Current line number */
num_bins, /* Number of bins in file */
goto create_error;
}
- if ((pc->bins = calloc(num_bins, sizeof(_pwg_map_t))) == NULL)
+ if ((pc->bins = calloc(num_bins, sizeof(pwg_map_t))) == NULL)
{
DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d bins.",
num_sizes));
if (num_sizes > 0)
{
- if ((pc->sizes = calloc(num_sizes, sizeof(_pwg_size_t))) == NULL)
+ if ((pc->sizes = calloc(num_sizes, sizeof(pwg_size_t))) == NULL)
{
DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sizes.",
num_sizes));
goto create_error;
}
- _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), "custom", "max",
- pc->custom_max_width, pc->custom_max_length);
+ pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "max",
+ pc->custom_max_width, pc->custom_max_length, NULL);
pc->custom_max_keyword = _cupsStrAlloc(pwg_keyword);
- _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), "custom", "min",
- pc->custom_min_width, pc->custom_min_length);
+ pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "min",
+ pc->custom_min_width, pc->custom_min_length, NULL);
pc->custom_min_keyword = _cupsStrAlloc(pwg_keyword);
}
else if (!_cups_strcasecmp(line, "SourceOption"))
goto create_error;
}
- if ((pc->sources = calloc(num_sources, sizeof(_pwg_map_t))) == NULL)
+ if ((pc->sources = calloc(num_sources, sizeof(pwg_map_t))) == NULL)
{
DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d sources.",
num_sources));
goto create_error;
}
- if ((pc->types = calloc(num_types, sizeof(_pwg_map_t))) == NULL)
+ if ((pc->types = calloc(num_types, sizeof(pwg_map_t))) == NULL)
{
DEBUG_printf(("_ppdCacheCreateWithFile: Unable to allocate %d types.",
num_types));
*color_model, /* ColorModel option */
*duplex; /* Duplex option */
ppd_choice_t *choice; /* Current InputSlot/MediaType */
- _pwg_map_t *map; /* Current source/type map */
+ pwg_map_t *map; /* Current source/type map */
ppd_attr_t *ppd_attr; /* Current PPD preset attribute */
int num_options; /* Number of preset options and props */
cups_option_t *options; /* Preset options and properties */
ppd_size_t *ppd_size; /* Current PPD size */
- _pwg_size_t *pwg_size; /* Current PWG size */
+ pwg_size_t *pwg_size; /* Current PWG size */
char pwg_keyword[3 + PPD_MAX_NAME + 1 + 12 + 1 + 12 + 3],
/* PWG keyword string */
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_print_color_mode_t pwg_print_color_mode;
/* print-color-mode index */
_pwg_print_quality_t pwg_print_quality;
/* print-quality index */
int similar; /* Are the old and new size similar? */
- _pwg_size_t *old_size; /* Current old size */
+ pwg_size_t *old_size; /* Current old size */
int old_imageable, /* Old imageable length in 2540ths */
old_borderless, /* Old borderless state */
old_known_pwg; /* Old PWG name is well-known */
new_imageable, /* New imageable length in 2540ths */
new_borderless, /* New borderless state */
new_known_pwg; /* New PWG name is well-known */
- _pwg_size_t *new_size; /* New size to add, if any */
+ pwg_size_t *new_size; /* New size to add, if any */
const char *filter; /* Current filter */
_pwg_finishings_t *finishings; /* Current finishings value */
if (ppd->num_sizes > 0)
{
- if ((pc->sizes = calloc(ppd->num_sizes, sizeof(_pwg_size_t))) == NULL)
+ if ((pc->sizes = calloc(ppd->num_sizes, sizeof(pwg_size_t))) == NULL)
{
DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
- "_pwg_size_t's.", ppd->num_sizes));
+ "pwg_size_t's.", ppd->num_sizes));
goto create_error;
}
* Convert the PPD size name to the corresponding PWG keyword name.
*/
- if ((pwg_media = _pwgMediaForPPD(ppd_size->name)) != NULL)
+ if ((pwg_media = pwgMediaForPPD(ppd_size->name)) != NULL)
{
/*
* Standard name, do we have conflicts?
new_known_pwg = 0;
pwg_unppdize_name(ppd_size->name, ppd_name, sizeof(ppd_name), "_.");
- _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), NULL, ppd_name,
- _PWG_FROMPTS(ppd_size->width),
- _PWG_FROMPTS(ppd_size->length));
+ pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), NULL, ppd_name,
+ PWG_FROM_POINTS(ppd_size->width),
+ PWG_FROM_POINTS(ppd_size->length), NULL);
}
/*
* dimensions that are <= 0...
*/
- if ((pwg_media = _pwgMediaForSize(_PWG_FROMPTS(ppd_size->width),
- _PWG_FROMPTS(ppd_size->length))) == NULL)
+ if ((pwg_media = pwgMediaForSize(PWG_FROM_POINTS(ppd_size->width),
+ PWG_FROM_POINTS(ppd_size->length))) == NULL)
continue;
new_width = pwg_media->width;
new_length = pwg_media->length;
- new_left = _PWG_FROMPTS(ppd_size->left);
- new_bottom = _PWG_FROMPTS(ppd_size->bottom);
- new_right = _PWG_FROMPTS(ppd_size->width - ppd_size->right);
- new_top = _PWG_FROMPTS(ppd_size->length - ppd_size->top);
+ new_left = PWG_FROM_POINTS(ppd_size->left);
+ new_bottom = PWG_FROM_POINTS(ppd_size->bottom);
+ new_right = PWG_FROM_POINTS(ppd_size->width - ppd_size->right);
+ new_top = PWG_FROM_POINTS(ppd_size->length - ppd_size->top);
new_imageable = new_length - new_top - new_bottom;
new_borderless = new_bottom == 0 && new_top == 0 &&
new_left == 0 && new_right == 0;
* Generate custom size data...
*/
- _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), "custom", "max",
- _PWG_FROMPTS(ppd->custom_max[0]),
- _PWG_FROMPTS(ppd->custom_max[1]));
+ pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "max",
+ PWG_FROM_POINTS(ppd->custom_max[0]),
+ PWG_FROM_POINTS(ppd->custom_max[1]), NULL);
pc->custom_max_keyword = _cupsStrAlloc(pwg_keyword);
- pc->custom_max_width = _PWG_FROMPTS(ppd->custom_max[0]);
- pc->custom_max_length = _PWG_FROMPTS(ppd->custom_max[1]);
+ pc->custom_max_width = PWG_FROM_POINTS(ppd->custom_max[0]);
+ pc->custom_max_length = PWG_FROM_POINTS(ppd->custom_max[1]);
- _pwgGenerateSize(pwg_keyword, sizeof(pwg_keyword), "custom", "min",
- _PWG_FROMPTS(ppd->custom_min[0]),
- _PWG_FROMPTS(ppd->custom_min[1]));
+ pwgFormatSizeName(pwg_keyword, sizeof(pwg_keyword), "custom", "min",
+ PWG_FROM_POINTS(ppd->custom_min[0]),
+ PWG_FROM_POINTS(ppd->custom_min[1]), NULL);
pc->custom_min_keyword = _cupsStrAlloc(pwg_keyword);
- pc->custom_min_width = _PWG_FROMPTS(ppd->custom_min[0]);
- pc->custom_min_length = _PWG_FROMPTS(ppd->custom_min[1]);
+ pc->custom_min_width = PWG_FROM_POINTS(ppd->custom_min[0]);
+ pc->custom_min_length = PWG_FROM_POINTS(ppd->custom_min[1]);
- pc->custom_size.left = _PWG_FROMPTS(ppd->custom_margins[0]);
- pc->custom_size.bottom = _PWG_FROMPTS(ppd->custom_margins[1]);
- pc->custom_size.right = _PWG_FROMPTS(ppd->custom_margins[2]);
- pc->custom_size.top = _PWG_FROMPTS(ppd->custom_margins[3]);
+ pc->custom_size.left = PWG_FROM_POINTS(ppd->custom_margins[0]);
+ pc->custom_size.bottom = PWG_FROM_POINTS(ppd->custom_margins[1]);
+ pc->custom_size.right = PWG_FROM_POINTS(ppd->custom_margins[2]);
+ pc->custom_size.top = PWG_FROM_POINTS(ppd->custom_margins[3]);
}
/*
pc->source_option = _cupsStrAlloc(input_slot->keyword);
if ((pc->sources = calloc(input_slot->num_choices,
- sizeof(_pwg_map_t))) == NULL)
+ sizeof(pwg_map_t))) == NULL)
{
DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
- "_pwg_map_t's for InputSlot.", input_slot->num_choices));
+ "pwg_map_t's for InputSlot.", input_slot->num_choices));
goto create_error;
}
if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL)
{
if ((pc->types = calloc(media_type->num_choices,
- sizeof(_pwg_map_t))) == NULL)
+ sizeof(pwg_map_t))) == NULL)
{
DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
- "_pwg_map_t's for MediaType.", media_type->num_choices));
+ "pwg_map_t's for MediaType.", media_type->num_choices));
goto create_error;
}
if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
{
if ((pc->bins = calloc(output_bin->num_choices,
- sizeof(_pwg_map_t))) == NULL)
+ sizeof(pwg_map_t))) == NULL)
{
DEBUG_printf(("_ppdCacheCreateWithPPD: Unable to allocate %d "
- "_pwg_map_t's for OutputBin.", output_bin->num_choices));
+ "pwg_map_t's for OutputBin.", output_bin->num_choices));
goto create_error;
}
_ppdCacheDestroy(_ppd_cache_t *pc) /* I - PPD cache and mapping data */
{
int i; /* Looping var */
- _pwg_map_t *map; /* Current map */
- _pwg_size_t *size; /* Current size */
+ pwg_map_t *map; /* Current map */
+ pwg_size_t *size; /* Current size */
/*
ipp_attribute_t *media_col, /* media-col attribute */
*media_source; /* media-source attribute */
- _pwg_size_t size; /* Dimensional size */
+ pwg_size_t size; /* Dimensional size */
int margins_set; /* Were the margins set? */
media_col = ippFindAttribute(job, "media-col", IPP_TAG_BEGIN_COLLECTION);
keyword = ippGetString(media_source, 0, NULL);
}
- else if (_pwgInitSize(&size, job, &margins_set))
+ else if (pwgInitSize(&size, job, &margins_set))
{
/*
* For media <= 5x7, look for a photo tray...
int *exact) /* O - 1 if exact match, 0 otherwise */
{
int i; /* Looping var */
- _pwg_size_t *size, /* Current size */
+ pwg_size_t *size, /* Current size */
*closest, /* Closest size */
jobsize; /* Size data from job */
int margins_set, /* Were the margins set? */
* media-col.
*/
- if (!_pwgInitSize(&jobsize, job, &margins_set))
+ if (!pwgInitSize(&jobsize, job, &margins_set))
return (NULL);
}
else
* Get the size using a media keyword...
*/
- _pwg_media_t *media; /* Media definition */
+ pwg_media_t *media; /* Media definition */
- if ((media = _pwgMediaForPWG(keyword)) == NULL)
- if ((media = _pwgMediaForLegacy(keyword)) == NULL)
- if ((media = _pwgMediaForPPD(keyword)) == NULL)
+ if ((media = pwgMediaForPWG(keyword)) == NULL)
+ if ((media = pwgMediaForLegacy(keyword)) == NULL)
+ if ((media = pwgMediaForPPD(keyword)) == NULL)
return (NULL);
jobsize.width = media->width;
*/
snprintf(pc->custom_ppd_size, sizeof(pc->custom_ppd_size), "Custom.%dx%d",
- (int)_PWG_TOPTS(jobsize.width), (int)_PWG_TOPTS(jobsize.length));
+ (int)PWG_TO_POINTS(jobsize.width), (int)PWG_TO_POINTS(jobsize.length));
if (margins_set && exact)
{
* '_ppdCacheGetSize()' - Get the PWG size associated with a PPD PageSize.
*/
-_pwg_size_t * /* O - PWG size or NULL */
+pwg_size_t * /* O - PWG size or NULL */
_ppdCacheGetSize(
_ppd_cache_t *pc, /* I - PPD cache and mapping data */
const char *page_size) /* I - PPD PageSize */
{
int i; /* Looping var */
- _pwg_media_t *media; /* Media */
- _pwg_size_t *size; /* Current size */
+ pwg_media_t *media; /* Media */
+ pwg_size_t *size; /* Current size */
/*
* Look up standard sizes...
*/
- if ((media = _pwgMediaForPPD(page_size)) == NULL)
- if ((media = _pwgMediaForLegacy(page_size)) == NULL)
- media = _pwgMediaForPWG(page_size);
+ if ((media = pwgMediaForPPD(page_size)) == NULL)
+ if ((media = pwgMediaForLegacy(page_size)) == NULL)
+ media = pwgMediaForPWG(page_size);
if (media)
{
const char *input_slot) /* I - PPD InputSlot */
{
int i; /* Looping var */
- _pwg_map_t *source; /* Current source */
+ pwg_map_t *source; /* Current source */
/*
const char *media_type) /* I - PPD MediaType */
{
int i; /* Looping var */
- _pwg_map_t *type; /* Current type */
+ pwg_map_t *type; /* Current type */
/*
{
int i, j, k; /* Looping vars */
cups_file_t *fp; /* Output file */
- _pwg_size_t *size; /* Current size */
- _pwg_map_t *map; /* Current map */
+ pwg_size_t *size; /* Current size */
+ pwg_map_t *map; /* Current map */
_pwg_finishings_t *f; /* Current finishing option */
cups_option_t *option; /* Current option */
const char *value; /* Filter/pre-filter value */
/*
- * '_pwgMediaTypeForType()' - Get the MediaType name for the given PWG
+ * 'pwgMediaTypeForType()' - Get the MediaType name for the given PWG
* media-type.
*/
const char * /* O - MediaType name */
-_pwgMediaTypeForType(
+pwgMediaTypeForType(
const char *media_type, /* I - PWG media-type */
char *name, /* I - Name buffer */
size_t namesize) /* I - Size of name buffer */
const char * /* O - PageSize name */
_pwgPageSizeForMedia(
- _pwg_media_t *media, /* I - Media */
+ pwg_media_t *media, /* I - Media */
char *name, /* I - PageSize name buffer */
size_t namesize) /* I - Size of name buffer */
{
* Use a name of the form "wNNNhNNN"...
*/
- snprintf(name, namesize, "w%dh%d", (int)_PWG_TOPTS(media->width),
- (int)_PWG_TOPTS(media->length));
+ snprintf(name, namesize, "w%dh%d", (int)PWG_TO_POINTS(media->width),
+ (int)PWG_TO_POINTS(media->length));
}
else
{
*
* Private PPD definitions for CUPS.
*
- * Copyright 2007-2011 by Apple Inc.
+ * Copyright 2007-2013 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
struct _ppd_cache_s /**** PPD cache and PWG conversion data ****/
{
int num_bins; /* Number of output bins */
- _pwg_map_t *bins; /* Output bins */
+ pwg_map_t *bins; /* Output bins */
int num_sizes; /* Number of media sizes */
- _pwg_size_t *sizes; /* Media sizes */
+ pwg_size_t *sizes; /* Media sizes */
int custom_max_width, /* Maximum custom width in 2540ths */
custom_max_length, /* Maximum custom length in 2540ths */
custom_min_width, /* Minimum custom width in 2540ths */
char *custom_max_keyword, /* Maximum custom size PWG keyword */
*custom_min_keyword, /* Minimum custom size PWG keyword */
custom_ppd_size[41]; /* Custom PPD size name */
- _pwg_size_t custom_size; /* Custom size record */
+ pwg_size_t custom_size; /* Custom size record */
char *source_option; /* PPD option for media source */
int num_sources; /* Number of media sources */
- _pwg_map_t *sources; /* Media sources */
+ pwg_map_t *sources; /* Media sources */
int num_types; /* Number of media types */
- _pwg_map_t *types; /* Media types */
+ pwg_map_t *types; /* Media types */
int num_presets[_PWG_PRINT_COLOR_MODE_MAX][_PWG_PRINT_QUALITY_MAX];
/* Number of print-color-mode/print-quality options */
cups_option_t *presets[_PWG_PRINT_COLOR_MODE_MAX][_PWG_PRINT_QUALITY_MAX];
const char *keyword);
extern const char *_ppdCacheGetPageSize(_ppd_cache_t *pc, ipp_t *job,
const char *keyword, int *exact);
-extern _pwg_size_t *_ppdCacheGetSize(_ppd_cache_t *pc,
+extern pwg_size_t *_ppdCacheGetSize(_ppd_cache_t *pc,
const char *page_size);
extern const char *_ppdCacheGetSource(_ppd_cache_t *pc,
const char *input_slot);
char *name, size_t namesize);
extern const char *_pwgMediaTypeForType(const char *media_type,
char *name, size_t namesize);
-extern const char *_pwgPageSizeForMedia(_pwg_media_t *media,
+extern const char *_pwgPageSizeForMedia(pwg_media_t *media,
char *name, size_t namesize);
*
* PWG media name API implementation for CUPS.
*
- * Copyright 2009-2012 by Apple Inc.
+ * Copyright 2009-2013 by Apple Inc.
*
* These coded instructions, statements, and computer programs are the
* property of Apple Inc. and are protected by Federal copyright
*
* Contents:
*
- * _pwgFormatInches() - Convert and format PWG units as inches.
- * _pwgFormatMillimeters() - Convert and format PWG units as millimeters.
- * _pwgGenerateSize() - Generate a PWG size keyword.
- * _pwgInitSize() - Initialize a PWG size using IPP job template
- * attributes.
- * _pwgMediaForLegacy() - Find a PWG media size by ISO/IPP legacy name.
- * _pwgMediaForPPD() - Find a PWG media size by Adobe PPD name.
- * _pwgMediaForPWG() - Find a PWG media size by 5101.1 self-describing
- * name.
- * _pwgMediaForSize() - Get the PWG media name for a given size.
- * pwg_compare_legacy() - Compare two sizes using the legacy names.
- * pwg_compare_ppd() - Compare two sizes using the PPD names.
- * pwg_compare_pwg() - Compare two sizes using the PWG names.
+ * pwgFormatSizeName() - Generate a PWG self-describing media size name.
+ * pwgInitSize() - Initialize a pwg_size_t structure using IPP Job
+ * Template attributes.
+ * pwgMediaForLegacy() - Find a PWG media size by ISO/IPP legacy name.
+ * pwgMediaForPPD() - Find a PWG media size by Adobe PPD name.
+ * pwgMediaForPWG() - Find a PWG media size by 5101.1 self-describing
+ * name.
+ * pwgMediaForSize() - Get the PWG media size for the given
+ * dimensions.
+ * pwg_compare_legacy() - Compare two sizes using the legacy names.
+ * pwg_compare_ppd() - Compare two sizes using the PPD names.
+ * pwg_compare_pwg() - Compare two sizes using the PWG names.
+ * pwg_format_inches() - Convert and format PWG units as inches.
+ * pwg_format_millimeters() - Convert and format PWG units as millimeters.
*/
/*
* Local functions...
*/
-static int pwg_compare_legacy(_pwg_media_t *a, _pwg_media_t *b);
-static int pwg_compare_pwg(_pwg_media_t *a, _pwg_media_t *b);
-static int pwg_compare_ppd(_pwg_media_t *a, _pwg_media_t *b);
+static int pwg_compare_legacy(pwg_media_t *a, pwg_media_t *b);
+static int pwg_compare_pwg(pwg_media_t *a, pwg_media_t *b);
+static int pwg_compare_ppd(pwg_media_t *a, pwg_media_t *b);
+static char *pwg_format_inches(char *buf, size_t bufsize, int val);
+static char *pwg_format_millimeters(char *buf, size_t bufsize, int val);
/*
* Local globals...
*/
-static _pwg_media_t const cups_pwg_media[] =
+static pwg_media_t const cups_pwg_media[] =
{ /* Media size lookup table */
/* North American Standard Sheet Media Sizes */
_PWG_MEDIA_IN("na_index-3x5_3x5in", NULL, "3x5", 3, 5),
/*
- * '_pwgFormatInches()' - Convert and format PWG units as inches.
+ * 'pwgFormatSizeName()' - Generate a PWG self-describing media size name.
+ *
+ * This function generates a PWG self-describing media size name of the form
+ * "prefix_name_WIDTHxLENGTHunits". The prefix is typically "custom" or "roll"
+ * for user-supplied sizes but can also be "disc", "iso", "jis", "jpn", "na",
+ * "oe", "om", "prc", or "roc". A value of @code NULL@ automatically chooses
+ * "oe" or "om" depending on the units.
+ *
+ * The size name may only contain lowercase letters, numbers, "-", and ".". If
+ * @code NULL@ is passed, the size name will contain the formatted dimensions.
+ *
+ * The width and length are specified in hundredths of millimeters, equivalent
+ * to 1/100000th of a meter or 1/2540th of an inch. The width, length, and
+ * units used for the generated size name are calculated automatically if the
+ * units string is @code NULL@, otherwise inches ("in") or millimeters ("mm")
+ * are used.
+ *
+ * @since CUPS 1.7@
*/
-char * /* O - String */
-_pwgFormatInches(char *buf, /* I - Buffer */
- size_t bufsize, /* I - Size of buffer */
- int val) /* I - Value in hundredths of millimeters */
+int /* O - 1 on success, 0 on failure */
+pwgFormatSizeName(char *keyword, /* I - Keyword buffer */
+ size_t keysize, /* I - Size of keyword buffer */
+ const char *prefix, /* I - Prefix for PWG size or @code NULL@ for automatic */
+ const char *name, /* I - Size name or @code NULL@ */
+ int width, /* I - Width of page in 2540ths */
+ int length, /* I - Length of page in 2540ths */
+ const char *units) /* I - Units - "in", "mm", or @code NULL@ for automatic */
{
- int thousandths, /* Thousandths of inches */
- integer, /* Integer portion */
- fraction; /* Fractional portion */
+ char usize[12 + 1 + 12 + 3], /* Unit size: NNNNNNNNNNNNxNNNNNNNNNNNNuu */
+ *uptr; /* Pointer into unit size */
+ char *(*format)(char *, size_t, int);
+ /* Formatting function */
/*
- * Convert hundredths of millimeters to thousandths of inches and round to
- * the nearest thousandth.
+ * Range check input...
*/
- thousandths = (val * 1000 + 1270) / 2540;
- integer = thousandths / 1000;
- fraction = thousandths % 1000;
+ DEBUG_printf(("pwgFormatSize(keyword=%p, keysize=" CUPS_LLFMT
+ ", prefix=\"%s\", name=\"%s\", width=%d, length=%d, "
+ "units=\"%s\")", keyword, CUPS_LLCAST keysize, prefix, name,
+ width, length, units));
- /*
- * Format as a pair of integers (avoids locale stuff), avoiding trailing
- * zeros...
- */
+ if (keyword)
+ *keyword = '\0';
- if (fraction == 0)
- snprintf(buf, bufsize, "%d", integer);
- else if (fraction % 10)
- snprintf(buf, bufsize, "%d.%03d", integer, fraction);
- else if (fraction % 100)
- snprintf(buf, bufsize, "%d.%02d", integer, fraction / 10);
- else
- snprintf(buf, bufsize, "%d.%01d", integer, fraction / 100);
-
- return (buf);
-}
-
-
-/*
- * '_pwgFormatMillimeters()' - Convert and format PWG units as millimeters.
- */
-
-char * /* O - String */
-_pwgFormatMillimeters(char *buf, /* I - Buffer */
- size_t bufsize, /* I - Size of buffer */
- int val) /* I - Value in hundredths of millimeters */
-{
- int integer, /* Integer portion */
- fraction; /* Fractional portion */
-
-
- /*
- * Convert hundredths of millimeters to integer and fractional portions.
- */
+ if (!keyword || keysize < 32 || width < 0 || length < 0 ||
+ (units && strcmp(units, "in") && strcmp(units, "mm")))
+ {
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Invalid media name arguments."),
+ 1);
+ return (0);
+ }
- integer = val / 100;
- fraction = val % 100;
+ if (name)
+ {
+ /*
+ * Validate name...
+ */
- /*
- * Format as a pair of integers (avoids locale stuff), avoiding trailing
- * zeros...
- */
+ const char *nameptr; /* Pointer into name */
- if (fraction == 0)
- snprintf(buf, bufsize, "%d", integer);
- else if (fraction % 10)
- snprintf(buf, bufsize, "%d.%02d", integer, fraction);
+ for (nameptr = name; *nameptr; nameptr ++)
+ if (!(*nameptr >= 'a' && *nameptr <= 'z') &&
+ !(*nameptr >= '0' && *nameptr <= '9') &&
+ *nameptr != '.' && *nameptr != '-')
+ {
+ _cupsSetError(IPP_STATUS_ERROR_INTERNAL,
+ _("Invalid media name arguments."), 1);
+ return (0);
+ }
+ }
else
- snprintf(buf, bufsize, "%d.%01d", integer, fraction / 10);
-
- return (buf);
-}
+ name = usize;
-/*
- * '_pwgGenerateSize()' - Generate a PWG size keyword.
- */
+ if (!units)
+ {
+ if ((width % 635) == 0 && (length % 635) == 0)
+ {
+ /*
+ * Use inches since the size is a multiple of 1/4 inch.
+ */
-void
-_pwgGenerateSize(char *keyword, /* I - Keyword buffer */
- size_t keysize, /* I - Size of keyword buffer */
- const char *prefix, /* I - Prefix for PWG size or NULL */
- const char *name, /* I - Size name or NULL */
- int width, /* I - Width of page in 2540ths */
- int length) /* I - Length of page in 2540ths */
-{
- const char *units; /* Units to report */
- char usize[12 + 1 + 12 + 3], /* Unit size: NNNNNNNNNNNNxNNNNNNNNNNNNuu */
- *uptr; /* Pointer into unit size */
- char *(*format)(char *, size_t, int);
- /* Formatting function */
+ units = "in";
+ }
+ else
+ {
+ /*
+ * Use millimeters since the size is not a multiple of 1/4 inch.
+ */
+ units = "mm";
+ }
+ }
- if ((width % 635) == 0 && (length % 635) == 0)
+ if (!strcmp(units, "in"))
{
- /*
- * Use inches since the size is a multiple of 1/4 inch.
- */
-
- units = "in";
- format = _pwgFormatInches;
+ format = pwg_format_inches;
if (!prefix)
prefix = "oe";
}
else
{
- /*
- * Use millimeters since the size is not a multiple of 1/4 inch.
- */
-
- units = "mm";
- format = _pwgFormatMillimeters;
+ format = pwg_format_millimeters;
if (!prefix)
prefix = "om";
}
+ /*
+ * Format the size string...
+ */
+
uptr = usize;
(*format)(uptr, sizeof(usize) - (uptr - usize), width);
uptr += strlen(uptr);
memcpy(uptr, units, 3);
- if (!name)
- name = usize;
-
/*
* Format the name...
*/
snprintf(keyword, keysize, "%s_%s_%s", prefix, name, usize);
+
+ return (1);
}
+/* For OS X 10.8 and earlier... */
+void _pwgGenerateSize(char *keyword, size_t keysize, const char *prefix,
+ const char *name, int width, int length)
+{ pwgFormatSizeName(keyword, keysize, prefix, name, width, length, NULL); }
+
/*
- * '_pwgInitSize()' - Initialize a PWG size using IPP job template attributes.
+ * 'pwgInitSize()' - Initialize a pwg_size_t structure using IPP Job Template
+ * attributes.
+ *
+ * This function initializes a pwg_size_t structure from an IPP "media" or
+ * "media-col" attribute in the specified IPP message. 0 is returned if neither
+ * attribute is found in the message or the values are not valid.
+ *
+ * The "margins_set" variable is initialized to 1 if any "media-xxx-margin"
+ * member attribute was specified in the "media-col" Job Template attribute,
+ * otherwise it is initialized to 0.
+ *
+ * @since CUPS 1.7@
*/
-int /* O - 1 if size was initialize, 0 otherwise */
-_pwgInitSize(_pwg_size_t *size, /* I - Size to initialize */
- ipp_t *job, /* I - Job template attributes */
- int *margins_set) /* O - 1 if margins were set, 0 otherwise */
+int /* O - 1 if size was initialized, 0 otherwise */
+pwgInitSize(pwg_size_t *size, /* I - Size to initialize */
+ ipp_t *job, /* I - Job template attributes */
+ int *margins_set) /* O - 1 if margins were set, 0 otherwise */
{
ipp_attribute_t *media, /* media attribute */
*media_bottom_margin, /* media-bottom-margin member attribute */
*media_top_margin, /* media-top-margin member attribute */
*x_dimension, /* x-dimension member attribute */
*y_dimension; /* y-dimension member attribute */
- _pwg_media_t *pwg; /* PWG media value */
+ pwg_media_t *pwg; /* PWG media value */
/*
* Look for media-col and then media...
*/
- memset(size, 0, sizeof(_pwg_size_t));
+ memset(size, 0, sizeof(pwg_size_t));
*margins_set = 0;
if ((media_col = ippFindAttribute(job, "media-col",
const char *name = media->values[0].string.text;
/* Name string */
- if ((pwg = _pwgMediaForPWG(name)) == NULL)
+ if ((pwg = pwgMediaForPWG(name)) == NULL)
{
/*
* Not a PWG name, try a legacy name...
*/
- if ((pwg = _pwgMediaForLegacy(name)) == NULL)
+ if ((pwg = pwgMediaForLegacy(name)) == NULL)
{
/*
* Not a legacy name, try a PPD name...
const char *suffix; /* Suffix on media string */
- pwg = _pwgMediaForPPD(name);
+ pwg = pwgMediaForPPD(name);
if (pwg &&
(suffix = name + strlen(name) - 10 /* .FullBleed */) > name &&
!_cups_strcasecmp(suffix, ".FullBleed"))
return (1);
}
+/* For OS X 10.8 and earlier */
+int _pwgInitSize(pwg_size_t *size, ipp_t *job, int *margins_set)
+{ return (pwgInitSize(size, job, margins_set)); }
+
/*
- * '_pwgMediaForLegacy()' - Find a PWG media size by ISO/IPP legacy name.
+ * 'pwgMediaForLegacy()' - Find a PWG media size by ISO/IPP legacy name.
+ *
+ * The "name" argument specifies the legacy ISO media size name, for example
+ * "iso-a4" or "na-letter".
+ *
+ * @since CUPS 1.7@
*/
-_pwg_media_t * /* O - Matching size or NULL */
-_pwgMediaForLegacy(
- const char *legacy) /* I - Legacy size name */
+pwg_media_t * /* O - Matching size or NULL */
+pwgMediaForLegacy(const char *legacy) /* I - Legacy size name */
{
- _pwg_media_t key; /* Search key */
+ pwg_media_t key; /* Search key */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
if (!cg->leg_size_lut)
{
int i; /* Looping var */
- _pwg_media_t *size; /* Current size */
+ pwg_media_t *size; /* Current size */
cg->leg_size_lut = cupsArrayNew((cups_array_func_t)pwg_compare_legacy,
NULL);
for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])),
- size = (_pwg_media_t *)cups_pwg_media;
+ size = (pwg_media_t *)cups_pwg_media;
i > 0;
i --, size ++)
if (size->legacy)
*/
key.legacy = legacy;
- return ((_pwg_media_t *)cupsArrayFind(cg->leg_size_lut, &key));
+ return ((pwg_media_t *)cupsArrayFind(cg->leg_size_lut, &key));
}
+/* For OS X 10.8 and earlier */
+pwg_media_t *_pwgMediaForLegacy(const char *legacy)
+{ return (pwgMediaForLegacy(legacy)); }
+
/*
- * '_pwgMediaForPPD()' - Find a PWG media size by Adobe PPD name.
+ * 'pwgMediaForPPD()' - Find a PWG media size by Adobe PPD name.
+ *
+ * The "ppd" argument specifies an Adobe page size name as defined in Table B.1
+ * of the Adobe PostScript Printer Description File Format Specification Version
+ * 4.3.
+ *
+ * If the name is non-standard, the returned PWG media size is stored in
+ * thread-local storage and is overwritten by each call to the function in the
+ * thread. Custom names can be of the form "Custom.WIDTHxLENGTH[units]" or
+ * "WIDTHxLENGTH[units]".
+ *
+ * @since CUPS 1.7@
*/
-_pwg_media_t * /* O - Matching size or NULL */
-_pwgMediaForPPD(const char *ppd) /* I - PPD size name */
+pwg_media_t * /* O - Matching size or NULL */
+pwgMediaForPPD(const char *ppd) /* I - PPD size name */
{
- _pwg_media_t key, /* Search key */
+ pwg_media_t key, /* Search key */
*size; /* Matching size */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
cg->ppd_size_lut = cupsArrayNew((cups_array_func_t)pwg_compare_ppd, NULL);
for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])),
- size = (_pwg_media_t *)cups_pwg_media;
+ size = (pwg_media_t *)cups_pwg_media;
i > 0;
i --, size ++)
if (size->ppd)
*/
key.ppd = ppd;
- if ((size = (_pwg_media_t *)cupsArrayFind(cg->ppd_size_lut, &key)) == NULL)
+ if ((size = (pwg_media_t *)cupsArrayFind(cg->ppd_size_lut, &key)) == NULL)
{
/*
* See if the name is of the form:
size->length = (int)(l * factor);
size->pwg = cg->pwg_name;
- _pwgGenerateSize(cg->pwg_name, sizeof(cg->pwg_name),
- custom ? "custom" : NULL, custom ? ppd + 7 : NULL,
- size->width, size->length);
+ pwgFormatSizeName(cg->pwg_name, sizeof(cg->pwg_name),
+ custom ? "custom" : NULL, custom ? ppd + 7 : NULL,
+ size->width, size->length, NULL);
}
}
}
return (size);
}
+/* For OS X 10.8 and earlier */
+pwg_media_t *_pwgMediaForPPD(const char *ppd)
+{ return (pwgMediaForPPD(ppd)); }
+
/*
- * '_pwgMediaForPWG()' - Find a PWG media size by 5101.1 self-describing name.
+ * 'pwgMediaForPWG()' - Find a PWG media size by 5101.1 self-describing name.
+ *
+ * The "pwg" argument specifies a self-describing media size name of the form
+ * "prefix_name_WIDTHxLENGTHunits" as defined in PWG 5101.1.
+ *
+ * If the name is non-standard, the returned PWG media size is stored in
+ * thread-local storage and is overwritten by each call to the function in the
+ * thread.
+ *
+ * @since CUPS 1.7@
*/
-_pwg_media_t * /* O - Matching size or NULL */
-_pwgMediaForPWG(const char *pwg) /* I - PWG size name */
+pwg_media_t * /* O - Matching size or NULL */
+pwgMediaForPWG(const char *pwg) /* I - PWG size name */
{
char *ptr; /* Pointer into name */
- _pwg_media_t key, /* Search key */
+ pwg_media_t key, /* Search key */
*size; /* Matching size */
_cups_globals_t *cg = _cupsGlobals(); /* Global data */
cg->pwg_size_lut = cupsArrayNew((cups_array_func_t)pwg_compare_pwg, NULL);
for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])),
- size = (_pwg_media_t *)cups_pwg_media;
+ size = (pwg_media_t *)cups_pwg_media;
i > 0;
i --, size ++)
cupsArrayAdd(cg->pwg_size_lut, size);
*/
key.pwg = pwg;
- if ((size = (_pwg_media_t *)cupsArrayFind(cg->pwg_size_lut, &key)) == NULL &&
+ if ((size = (pwg_media_t *)cupsArrayFind(cg->pwg_size_lut, &key)) == NULL &&
(ptr = (char *)strchr(pwg, '_')) != NULL &&
(ptr = (char *)strchr(ptr + 1, '_')) != NULL)
{
return (size);
}
+/* For OS X 10.8 and earlier */
+pwg_media_t *_pwgMediaForPWG(const char *pwg)
+{ return (pwgMediaForPWG(pwg)); }
+
/*
- * '_pwgMediaForSize()' - Get the PWG media name for a given size.
+ * 'pwgMediaForSize()' - Get the PWG media size for the given dimensions.
+ *
+ * The "width" and "length" are in hundredths of millimeters, equivalent to
+ * 1/100000th of a meter or 1/2540th of an inch.
+ *
+ * If the dimensions are non-standard, the returned PWG media size is stored in
+ * thread-local storage and is overwritten by each call to the function in the
+ * thread.
+ *
+ * @since CUPS 1.7@
*/
-_pwg_media_t * /* O - PWG media name */
-_pwgMediaForSize(int width, /* I - Width in 2540ths */
- int length) /* I - Length in 2540ths */
+pwg_media_t * /* O - PWG media name */
+pwgMediaForSize(int width, /* I - Width in hundredths of millimeters */
+ int length) /* I - Length in hundredths of millimeters */
{
int i; /* Looping var */
- _pwg_media_t *media, /* Current media */
+ pwg_media_t *media, /* Current media */
*best_media = NULL; /* Best match */
int dw, dl, /* Difference in width and length */
best_dw = 999, /* Best difference in width and length */
*/
for (i = (int)(sizeof(cups_pwg_media) / sizeof(cups_pwg_media[0])),
- media = (_pwg_media_t *)cups_pwg_media;
+ media = (pwg_media_t *)cups_pwg_media;
i > 0;
i --, media ++)
{
* custom_WIDTHxHEIGHTuu_WIDTHxHEIGHTuu
*/
- _pwgGenerateSize(cg->pwg_name, sizeof(cg->pwg_name), "custom", NULL, width,
- length);
+ pwgFormatSizeName(cg->pwg_name, sizeof(cg->pwg_name), "custom", NULL, width,
+ length, NULL);
cg->pwg_media.pwg = cg->pwg_name;
cg->pwg_media.width = width;
return (&(cg->pwg_media));
}
+/* For OS X 10.8 and earlier */
+pwg_media_t *_pwgMediaForSize(int width, int length)
+{ return (pwgMediaForSize(width, length)); }
+
/*
* 'pwg_compare_legacy()' - Compare two sizes using the legacy names.
*/
static int /* O - Result of comparison */
-pwg_compare_legacy(_pwg_media_t *a, /* I - First size */
- _pwg_media_t *b) /* I - Second size */
+pwg_compare_legacy(pwg_media_t *a, /* I - First size */
+ pwg_media_t *b) /* I - Second size */
{
return (strcmp(a->legacy, b->legacy));
}
*/
static int /* O - Result of comparison */
-pwg_compare_ppd(_pwg_media_t *a, /* I - First size */
- _pwg_media_t *b) /* I - Second size */
+pwg_compare_ppd(pwg_media_t *a, /* I - First size */
+ pwg_media_t *b) /* I - Second size */
{
return (strcmp(a->ppd, b->ppd));
}
*/
static int /* O - Result of comparison */
-pwg_compare_pwg(_pwg_media_t *a, /* I - First size */
- _pwg_media_t *b) /* I - Second size */
+pwg_compare_pwg(pwg_media_t *a, /* I - First size */
+ pwg_media_t *b) /* I - Second size */
{
return (strcmp(a->pwg, b->pwg));
}
+/*
+ * 'pwg_format_inches()' - Convert and format PWG units as inches.
+ */
+
+static char * /* O - String */
+pwg_format_inches(char *buf, /* I - Buffer */
+ size_t bufsize, /* I - Size of buffer */
+ int val) /* I - Value in hundredths of millimeters */
+{
+ int thousandths, /* Thousandths of inches */
+ integer, /* Integer portion */
+ fraction; /* Fractional portion */
+
+
+ /*
+ * Convert hundredths of millimeters to thousandths of inches and round to
+ * the nearest thousandth.
+ */
+
+ thousandths = (val * 1000 + 1270) / 2540;
+ integer = thousandths / 1000;
+ fraction = thousandths % 1000;
+
+ /*
+ * Format as a pair of integers (avoids locale stuff), avoiding trailing
+ * zeros...
+ */
+
+ if (fraction == 0)
+ snprintf(buf, bufsize, "%d", integer);
+ else if (fraction % 10)
+ snprintf(buf, bufsize, "%d.%03d", integer, fraction);
+ else if (fraction % 100)
+ snprintf(buf, bufsize, "%d.%02d", integer, fraction / 10);
+ else
+ snprintf(buf, bufsize, "%d.%01d", integer, fraction / 100);
+
+ return (buf);
+}
+
+
+/*
+ * 'pwg_format_millimeters()' - Convert and format PWG units as millimeters.
+ */
+
+static char * /* O - String */
+pwg_format_millimeters(char *buf, /* I - Buffer */
+ size_t bufsize, /* I - Size of buffer */
+ int val) /* I - Value in hundredths of millimeters */
+{
+ int integer, /* Integer portion */
+ fraction; /* Fractional portion */
+
+
+ /*
+ * Convert hundredths of millimeters to integer and fractional portions.
+ */
+
+ integer = val / 100;
+ fraction = val % 100;
+
+ /*
+ * Format as a pair of integers (avoids locale stuff), avoiding trailing
+ * zeros...
+ */
+
+ if (fraction == 0)
+ snprintf(buf, bufsize, "%d", integer);
+ else if (fraction % 10)
+ snprintf(buf, bufsize, "%d.%02d", integer, fraction);
+ else
+ snprintf(buf, bufsize, "%d.%01d", integer, fraction / 10);
+
+ return (buf);
+}
+
+
/*
* End of "$Id$".
*/
*
* Private PWG media API definitions for CUPS.
*
- * Copyright 2009-2012 by Apple Inc.
+ * Copyright 2009-2013 by Apple Inc.
*
* These coded instructions, statements, and computer programs are the
* property of Apple Inc. and are protected by Federal copyright
/*
- * Macros...
+ * Deprecated stuff for prior users of the private PWG media API...
*/
-/* Convert from points to 2540ths */
-# define _PWG_FROMPTS(n) (int)(((n) * 2540 + 36) / 72)
-/* Convert from 2540ths to points */
-# define _PWG_TOPTS(n) ((n) * 72.0 / 2540.0)
-
-
-/*
- * Types and structures...
- */
-
-typedef struct _pwg_map_s /**** Map element - PPD to/from PWG */
-{
- char *pwg, /* PWG media keyword */
- *ppd; /* PPD option keyword */
-} _pwg_map_t;
-
-typedef struct _pwg_media_s /**** Common media size data ****/
-{
- const char *pwg, /* PWG 5101.1 "self describing" name */
- *legacy, /* IPP/ISO legacy name */
- *ppd; /* Standard Adobe PPD name */
- int width, /* Width in 2540ths */
- length; /* Length in 2540ths */
-} _pwg_media_t;
-
-typedef struct _pwg_size_s /**** Size element - PPD to/from PWG */
-{
- _pwg_map_t map; /* Map element */
- int width, /* Width in 2540ths */
- length, /* Length in 2540ths */
- left, /* Left margin in 2540ths */
- bottom, /* Bottom margin in 2540ths */
- right, /* Right margin in 2540ths */
- top; /* Top margin in 2540ths */
-} _pwg_size_t;
+# ifndef _CUPS_NO_DEPRECATED
+typedef struct pwg_map_s _pwg_map_t;
+typedef struct pwg_media_s _pwg_media_t;
+typedef struct pwg_size_s _pwg_size_t;
+# endif /* _CUPS_NO_DEPRECATED */
/*
* Functions...
*/
-extern char *_pwgFormatInches(char *buf, size_t bufsize, int val);
-extern char *_pwgFormatMillimeters(char *buf, size_t bufsize,
- int val);
extern void _pwgGenerateSize(char *keyword, size_t keysize,
const char *prefix,
const char *name,
- int width, int length);
-extern int _pwgInitSize(_pwg_size_t *size, ipp_t *job,
- int *margins_set);
-extern _pwg_media_t *_pwgMediaForLegacy(const char *legacy);
-extern _pwg_media_t *_pwgMediaForPPD(const char *ppd);
-extern _pwg_media_t *_pwgMediaForPWG(const char *pwg);
-extern _pwg_media_t *_pwgMediaForSize(int width, int length);
+ int width, int length)
+ _CUPS_INTERNAL_MSG("Use pwgFormatSizeName instead.");
+extern int _pwgInitSize(pwg_size_t *size, ipp_t *job,
+ int *margins_set)
+ _CUPS_INTERNAL_MSG("Use pwgInitSize instead.");
+extern pwg_media_t *_pwgMediaForLegacy(const char *legacy)
+ _CUPS_INTERNAL_MSG("Use pwgMediaForLegacy instead.");
+extern pwg_media_t *_pwgMediaForPPD(const char *ppd)
+ _CUPS_INTERNAL_MSG("Use pwgMediaForPPD instead.");
+extern pwg_media_t *_pwgMediaForPWG(const char *pwg)
+ _CUPS_INTERNAL_MSG("Use pwgMediaForPWG instead.");
+extern pwg_media_t *_pwgMediaForSize(int width, int length)
+ _CUPS_INTERNAL_MSG("Use pwgMediaForSize instead.");
# ifdef __cplusplus
}
--- /dev/null
+/*
+ * "$Id$"
+ *
+ * PWG media API definitions for CUPS.
+ *
+ * Copyright 2009-2013 by Apple Inc.
+ *
+ * These coded instructions, statements, and computer programs are the
+ * 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/".
+ *
+ * This file is subject to the Apple OS-Developed Software exception.
+ */
+
+#ifndef _CUPS_PWG_H_
+# define _CUPS_PWG_H_
+
+
+/*
+ * C++ magic...
+ */
+
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+
+
+/*
+ * Macros...
+ */
+
+/* Convert from points to hundredths of millimeters */
+# define PWG_FROM_POINTS(n) (int)(((n) * 2540 + 36) / 72)
+/* Convert from hundredths of millimeters to points */
+# define PWG_TO_POINTS(n) ((n) * 72.0 / 2540.0)
+
+
+/*
+ * Types and structures...
+ */
+
+typedef struct pwg_map_s /**** Map element - PPD to/from PWG */
+{
+ char *pwg, /* PWG media keyword */
+ *ppd; /* PPD option keyword */
+} pwg_map_t;
+
+typedef struct pwg_media_s /**** Common media size data ****/
+{
+ const char *pwg, /* PWG 5101.1 "self describing" name */
+ *legacy, /* IPP/ISO legacy name */
+ *ppd; /* Standard Adobe PPD name */
+ int width, /* Width in 2540ths */
+ length; /* Length in 2540ths */
+} pwg_media_t;
+
+typedef struct pwg_size_s /**** Size element - PPD to/from PWG */
+{
+ pwg_map_t map; /* Map element */
+ int width, /* Width in 2540ths */
+ length, /* Length in 2540ths */
+ left, /* Left margin in 2540ths */
+ bottom, /* Bottom margin in 2540ths */
+ right, /* Right margin in 2540ths */
+ top; /* Top margin in 2540ths */
+} pwg_size_t;
+
+
+/*
+ * Functions...
+ */
+
+extern int pwgFormatSizeName(char *keyword, size_t keysize,
+ const char *prefix, const char *name,
+ int width, int length,
+ const char *units) _CUPS_API_1_7;
+extern int pwgInitSize(pwg_size_t *size, ipp_t *job,
+ int *margins_set) _CUPS_API_1_7;
+extern pwg_media_t *pwgMediaForLegacy(const char *legacy) _CUPS_API_1_7;
+extern pwg_media_t *pwgMediaForPPD(const char *ppd) _CUPS_API_1_7;
+extern pwg_media_t *pwgMediaForPWG(const char *pwg) _CUPS_API_1_7;
+extern pwg_media_t *pwgMediaForSize(int width, int length) _CUPS_API_1_7;
+
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+
+#endif /* !_CUPS_PWG_H_ */
+
+/*
+ * End of "$Id$".
+ */
*
* PWG test program for CUPS.
*
- * Copyright 2009-2012 by Apple Inc.
+ * Copyright 2009-2013 by Apple Inc.
*
* These coded instructions, statements, and computer programs are the
* property of Apple Inc. and are protected by Federal copyright
const char *ppdfile; /* PPD filename */
ppd_file_t *ppd; /* PPD file */
_ppd_cache_t *pc; /* PPD cache and PWG mapping data */
- _pwg_media_t *pwgmedia; /* PWG media size */
+ pwg_media_t *pwgmedia; /* PWG media size */
status = 0;
puts("PASS");
}
- fputs("_pwgMediaForPWG(\"iso_a4_210x297mm\"): ", stdout);
- if ((pwgmedia = _pwgMediaForPWG("iso_a4_210x297mm")) == NULL)
+ fputs("pwgMediaForPWG(\"iso_a4_210x297mm\"): ", stdout);
+ if ((pwgmedia = pwgMediaForPWG("iso_a4_210x297mm")) == NULL)
{
puts("FAIL (not found)");
status ++;
else
puts("PASS");
- fputs("_pwgMediaForLegacy(\"na-letter\"): ", stdout);
- if ((pwgmedia = _pwgMediaForLegacy("na-letter")) == NULL)
+ fputs("pwgMediaForLegacy(\"na-letter\"): ", stdout);
+ if ((pwgmedia = pwgMediaForLegacy("na-letter")) == NULL)
{
puts("FAIL (not found)");
status ++;
else
puts("PASS");
- fputs("_pwgMediaForPPD(\"4x6\"): ", stdout);
- if ((pwgmedia = _pwgMediaForPPD("4x6")) == NULL)
+ fputs("pwgMediaForPPD(\"4x6\"): ", stdout);
+ if ((pwgmedia = pwgMediaForPPD("4x6")) == NULL)
{
puts("FAIL (not found)");
status ++;
else
puts("PASS");
- fputs("_pwgMediaForPPD(\"10x15cm\"): ", stdout);
- if ((pwgmedia = _pwgMediaForPPD("10x15cm")) == NULL)
+ fputs("pwgMediaForPPD(\"10x15cm\"): ", stdout);
+ if ((pwgmedia = pwgMediaForPPD("10x15cm")) == NULL)
{
puts("FAIL (not found)");
status ++;
else
puts("PASS");
- fputs("_pwgMediaForPPD(\"Custom.10x15cm\"): ", stdout);
- if ((pwgmedia = _pwgMediaForPPD("Custom.10x15cm")) == NULL)
+ fputs("pwgMediaForPPD(\"Custom.10x15cm\"): ", stdout);
+ if ((pwgmedia = pwgMediaForPPD("Custom.10x15cm")) == NULL)
{
puts("FAIL (not found)");
status ++;
else
puts("PASS");
- fputs("_pwgMediaForSize(29700, 42000): ", stdout);
- if ((pwgmedia = _pwgMediaForSize(29700, 42000)) == NULL)
+ fputs("pwgMediaForSize(29700, 42000): ", stdout);
+ if ((pwgmedia = pwgMediaForSize(29700, 42000)) == NULL)
{
puts("FAIL (not found)");
status ++;
else
puts("PASS");
- fputs("_pwgMediaForSize(9842, 19050): ", stdout);
- if ((pwgmedia = _pwgMediaForSize(9842, 19050)) == NULL)
+ fputs("pwgMediaForSize(9842, 19050): ", stdout);
+ if ((pwgmedia = pwgMediaForSize(9842, 19050)) == NULL)
{
puts("FAIL (not found)");
status ++;
else
printf("PASS (%s)\n", pwgmedia->pwg);
- fputs("_pwgMediaForSize(9800, 19000): ", stdout);
- if ((pwgmedia = _pwgMediaForSize(9800, 19000)) == NULL)
+ fputs("pwgMediaForSize(9800, 19000): ", stdout);
+ if ((pwgmedia = pwgMediaForSize(9800, 19000)) == NULL)
{
puts("FAIL (not found)");
status ++;
int i, /* Looping var */
status = 0; /* Return status */
_ppd_cache_t *pc2; /* Loaded data */
- _pwg_size_t *size, /* Size from original */
+ pwg_size_t *size, /* Size from original */
*size2; /* Size from saved */
- _pwg_map_t *map, /* Map from original */
+ pwg_map_t *map, /* Map from original */
*map2; /* Map from saved */
*
* PPD test program for CUPS.
*
- * Copyright 2007-2012 by Apple Inc.
+ * Copyright 2007-2013 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
{
is_ok = 1;
width_2540ths = (size->length > size->width) ?
- _PWG_FROMPTS(size->width) :
- _PWG_FROMPTS(size->length);
+ PWG_FROM_POINTS(size->width) :
+ PWG_FROM_POINTS(size->length);
length_2540ths = (size->length > size->width) ?
- _PWG_FROMPTS(size->length) :
- _PWG_FROMPTS(size->width);
+ PWG_FROM_POINTS(size->length) :
+ PWG_FROM_POINTS(size->width);
pwg_media = _pwgMediaForSize(width_2540ths, length_2540ths);
if (pwg_media &&