int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { int status; /* Status of tests (0 = success, 1 = fail) */ const char *ppdfile; /* PPD filename */ ppd_file_t *ppd; /* PPD file */ _pwg_t *pwg; /* PWG mapping data */ _pwg_media_t *pwgmedia; /* PWG media size */ status = 0; if (argc < 2 || argc > 3) { puts("Usage: ./testpwg filename.ppd [jobfile]"); return (1); } ppdfile = argv[1]; printf("ppdOpenFile(%s): ", ppdfile); if ((ppd = ppdOpenFile(ppdfile)) == NULL) { ppd_status_t err; /* Last error in file */ int line; /* Line number in file */ err = ppdLastError(&line); printf("FAIL (%s on line %d)\n", ppdErrorString(err), line); return (1); } else puts("PASS"); fputs("_pwgCreateWithPPD(ppd): ", stdout); if ((pwg = _pwgCreateWithPPD(ppd)) == NULL) { puts("FAIL"); status ++; } else { puts("PASS"); status += test_pwg(pwg, ppd); if (argc == 3) { /* * Test PageSize mapping code. */ int fd; /* Job file descriptor */ const char *pagesize; /* PageSize value */ ipp_t *job; /* Job attributes */ ipp_attribute_t *media; /* Media attribute */ if ((fd = open(argv[2], O_RDONLY)) >= 0) { job = ippNew(); ippReadFile(fd, job); close(fd); if ((media = ippFindAttribute(job, "media", IPP_TAG_ZERO)) != NULL && media->value_tag != IPP_TAG_NAME && media->value_tag != IPP_TAG_KEYWORD) media = NULL; if (media) printf("_pwgGetPageSize(media=%s): ", media->values[0].string.text); else fputs("_pwgGetPageSize(media-col): ", stdout); fflush(stdout); if ((pagesize = _pwgGetPageSize(pwg, job, NULL, NULL)) == NULL) { puts("FAIL (Not Found)"); status = 1; } else if (media && strcasecmp(pagesize, media->values[0].string.text)) { printf("FAIL (Got \"%s\", Expected \"%s\")\n", pagesize, media->values[0].string.text); status = 1; } else printf("PASS (%s)\n", pagesize); ippDelete(job); } else { perror(argv[2]); status = 1; } } /* * _pwgDestroy should never fail... */ fputs("_pwgDestroy(pwg): ", stdout); _pwgDestroy(pwg); puts("PASS"); } fputs("_pwgMediaForPWG(\"iso_a4_210x297mm\"): ", stdout); if ((pwgmedia = _pwgMediaForPWG("iso_a4_210x297mm")) == NULL) { puts("FAIL (not found)"); status ++; } else if (strcmp(pwgmedia->pwg, "iso_a4_210x297mm")) { printf("FAIL (%s)\n", pwgmedia->pwg); status ++; } else if (pwgmedia->width != 21000 || pwgmedia->length != 29700) { printf("FAIL (%dx%d)\n", pwgmedia->width, pwgmedia->length); status ++; } else puts("PASS"); fputs("_pwgMediaForLegacy(\"na-letter\"): ", stdout); if ((pwgmedia = _pwgMediaForLegacy("na-letter")) == NULL) { puts("FAIL (not found)"); status ++; } else if (strcmp(pwgmedia->pwg, "na_letter_8.5x11in")) { printf("FAIL (%s)\n", pwgmedia->pwg); status ++; } else if (pwgmedia->width != 21590 || pwgmedia->length != 27940) { printf("FAIL (%dx%d)\n", pwgmedia->width, pwgmedia->length); status ++; } else puts("PASS"); fputs("_pwgMediaForPPD(\"4x6\"): ", stdout); if ((pwgmedia = _pwgMediaForPPD("4x6")) == NULL) { puts("FAIL (not found)"); status ++; } else if (strcmp(pwgmedia->pwg, "na_index-4x6_4x6in")) { printf("FAIL (%s)\n", pwgmedia->pwg); status ++; } else if (pwgmedia->width != 10160 || pwgmedia->length != 15240) { printf("FAIL (%dx%d)\n", pwgmedia->width, pwgmedia->length); status ++; } else puts("PASS"); fputs("_pwgMediaForPPD(\"10x15cm\"): ", stdout); if ((pwgmedia = _pwgMediaForPPD("10x15cm")) == NULL) { puts("FAIL (not found)"); status ++; } else if (strcmp(pwgmedia->pwg, "om_100x150mm_100x150mm")) { printf("FAIL (%s)\n", pwgmedia->pwg); status ++; } else if (pwgmedia->width != 10000 || pwgmedia->length != 15000) { printf("FAIL (%dx%d)\n", pwgmedia->width, pwgmedia->length); status ++; } else puts("PASS"); fputs("_pwgMediaForPPD(\"Custom.10x15cm\"): ", stdout); if ((pwgmedia = _pwgMediaForPPD("Custom.10x15cm")) == NULL) { puts("FAIL (not found)"); status ++; } else if (strcmp(pwgmedia->pwg, "custom_10x15cm_100x150mm")) { printf("FAIL (%s)\n", pwgmedia->pwg); status ++; } else if (pwgmedia->width != 10000 || pwgmedia->length != 15000) { printf("FAIL (%dx%d)\n", pwgmedia->width, pwgmedia->length); status ++; } else puts("PASS"); fputs("_pwgMediaForSize(29700, 42000): ", stdout); if ((pwgmedia = _pwgMediaForSize(29700, 42000)) == NULL) { puts("FAIL (not found)"); status ++; } else if (strcmp(pwgmedia->pwg, "iso_a3_297x420mm")) { printf("FAIL (%s)\n", pwgmedia->pwg); status ++; } else puts("PASS"); return (status); }
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 */ { ipp_attribute_t *media, /* media attribute */ *media_bottom_margin, /* media-bottom-margin member attribute */ *media_col, /* media-col attribute */ *media_left_margin, /* media-left-margin member attribute */ *media_right_margin, /* media-right-margin member attribute */ *media_size, /* media-size 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 */ /* * Range check input... */ if (!size || !job || !margins_set) return (0); /* * Look for media-col and then media... */ memset(size, 0, sizeof(_pwg_size_t)); *margins_set = 0; if ((media_col = ippFindAttribute(job, "media-col", IPP_TAG_BEGIN_COLLECTION)) != NULL) { /* * Got media-col, look for media-size member attribute... */ if ((media_size = ippFindAttribute(media_col->values[0].collection, "media-size", IPP_TAG_BEGIN_COLLECTION)) != NULL) { /* * Got media-size, look for x-dimension and y-dimension member * attributes... */ x_dimension = ippFindAttribute(media_size->values[0].collection, "x-dimension", IPP_TAG_INTEGER); y_dimension = ippFindAttribute(media_size->values[0].collection, "y-dimension", IPP_TAG_INTEGER); if (x_dimension && y_dimension) { size->width = x_dimension->values[0].integer; size->length = y_dimension->values[0].integer; } else if (!x_dimension) { _cupsSetError(IPP_INTERNAL_ERROR, _("Missing x-dimension in media-size."), 1); return (0); } else if (!y_dimension) { _cupsSetError(IPP_INTERNAL_ERROR, _("Missing y-dimension in media-size."), 1); return (0); } } else { _cupsSetError(IPP_INTERNAL_ERROR, _("Missing media-size in media-col."), 1); return (0); } /* media-*-margin */ media_bottom_margin = ippFindAttribute(media_col->values[0].collection, "media-bottom-margin", IPP_TAG_INTEGER); media_left_margin = ippFindAttribute(media_col->values[0].collection, "media-left-margin", IPP_TAG_INTEGER); media_right_margin = ippFindAttribute(media_col->values[0].collection, "media-right-margin", IPP_TAG_INTEGER); media_top_margin = ippFindAttribute(media_col->values[0].collection, "media-top-margin", IPP_TAG_INTEGER); if (media_bottom_margin && media_left_margin && media_right_margin && media_top_margin) { *margins_set = 1; size->bottom = media_bottom_margin->values[0].integer; size->left = media_left_margin->values[0].integer; size->right = media_right_margin->values[0].integer; size->top = media_top_margin->values[0].integer; } } else { if ((media = ippFindAttribute(job, "media", IPP_TAG_NAME)) == NULL) if ((media = ippFindAttribute(job, "media", IPP_TAG_KEYWORD)) == NULL) if ((media = ippFindAttribute(job, "PageSize", IPP_TAG_NAME)) == NULL) media = ippFindAttribute(job, "PageRegion", IPP_TAG_NAME); if (media) { const char *name = media->values[0].string.text; /* Name string */ if ((pwg = _pwgMediaForPWG(name)) == NULL) { /* * Not a PWG name, try a legacy name... */ if ((pwg = _pwgMediaForLegacy(name)) == NULL) { /* * Not a legacy name, try a PPD name... */ const char *suffix; /* Suffix on media string */ pwg = _pwgMediaForPPD(name); if (pwg && (suffix = name + strlen(name) - 10 /* .FullBleed */) > name && !_cups_strcasecmp(suffix, ".FullBleed")) { /* * Indicate that margins are set with the default values of 0. */ *margins_set = 1; } } } if (pwg) { size->width = pwg->width; size->length = pwg->length; } else { _cupsSetError(IPP_INTERNAL_ERROR, _("Unsupported media value."), 1); return (0); } } else { _cupsSetError(IPP_INTERNAL_ERROR, _("Missing media or media-col."), 1); return (0); } } return (1); }