From: mike Date: Fri, 22 Apr 2011 06:37:54 +0000 (+0000) Subject: Validate page size names. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d59c3a4cf6c28df7421ac0021de79c6324d1522;p=thirdparty%2Fcups.git Validate page size names. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@9708 7a7537e8-13f0-0310-91df-b6672ffda945 --- diff --git a/systemv/cupstestppd.c b/systemv/cupstestppd.c index 378b62e822..8221ae8deb 100644 --- a/systemv/cupstestppd.c +++ b/systemv/cupstestppd.c @@ -32,7 +32,7 @@ * check_translations() - Check translations in the PPD file. * show_conflicts() - Show option conflicts in a PPD file. * test_raster() - Test PostScript commands for raster printers. - * usage() - Show program usage... + * usage() - Show program usage. * valid_path() - Check whether a path has the correct capitalization. * valid_utf8() - Check whether a string contains valid UTF-8 text. */ @@ -2923,13 +2923,25 @@ check_sizes(ppd_file_t *ppd, /* I - PPD file */ int verbose, /* I - Verbosity level */ int warn) /* I - Warnings only? */ { - int i; /* Looping vars */ + int i; /* Looping var */ ppd_size_t *size; /* Current size */ int width, /* Custom width */ length; /* Custom length */ const char *prefix; /* WARN/FAIL prefix */ ppd_option_t *page_size, /* PageSize option */ *page_region; /* PageRegion option */ + _pwg_media_t *pwg_media; /* PWG media */ + char buf[1024]; /* PapeSize name that is supposed to be */ + const char *ptr; /* Pointer into string */ + int width_2540ths, /* PageSize width in 2540ths */ + length_2540ths; /* PageSize length in 2540ths */ + int is_ok; /* Flag for PageSize name verification */ + double width_tmp, /* Width after rounded up */ + length_tmp, /* Length after rounded up */ + width_inch, /* Width in inches */ + length_inch, /* Length in inches */ + width_mm, /* Width in millimeters */ + length_mm; /* Length in millimeters */ prefix = warn ? " WARN " : "**FAIL**"; @@ -3035,6 +3047,112 @@ check_sizes(ppd_file_t *ppd, /* I - PPD file */ if (!warn) errors ++; } + + /* + * Verify that the size name is Adobe standard name if it's a standard size + * and the dementional name if it's not a standard size. Suffix should be + * .Fullbleed, etc., or numeric, e.g., Letter, Letter.Fullbleed, + * Letter.Transverse, Letter1, Letter2, 4x8, 55x91mm, 55x91mm.Fullbleed, etc. + */ + + if (warn != 0) + { + is_ok = 1; + width_2540ths = (size->length > size->width) ? + _PWG_FROMPTS(size->width) : + _PWG_FROMPTS(size->length); + length_2540ths = (size->length > size->width) ? + _PWG_FROMPTS(size->length) : + _PWG_FROMPTS(size->width); + pwg_media = _pwgMediaForSize(width_2540ths, length_2540ths); + + if (pwg_media && pwg_media->ppd) + { + strlcpy(buf, pwg_media->ppd, sizeof(buf)); + + if (size->left == 0 && size->bottom == 0 && + size->right == size->width && size->top == size->length) + { + snprintf(buf, sizeof(buf), "%s.Fullbleed", pwg_media->ppd); + if (strcmp(size->name, buf)) + is_ok = 0; + } + else if (size->width > size->length) + { + if ((ptr = pwg_media->ppd + strlen(pwg_media->ppd) - 7) + >= pwg_media->ppd && !strcmp(ptr, "Rotated")) + { + if (strcmp(size->name, buf)) + is_ok = 0; + } + else + { + snprintf(buf, sizeof(buf), "%sRotated", pwg_media->ppd); + if (strcmp(size->name, buf)) + { + snprintf(buf, sizeof(buf), "%s.Transverse", pwg_media->ppd); + if (strcmp(size->name, buf)) + is_ok = 0; + } + } + } + else + { + if ((!strncmp(size->name, pwg_media->ppd, strlen(pwg_media->ppd)))) + { + for (ptr = size->name + strlen(pwg_media->ppd); *ptr; ptr ++) + { + if (!isdigit(*ptr & 255)) + { + is_ok = 0; + break; + } + } + } + else + is_ok = 0; + } + + if (!is_ok) + _cupsLangPrintf(stdout, + _(" %s Size \"%s\" should be the Adobe " + "standard name \"%s\"."), + prefix, size->name, buf); + } + else + { + width_tmp = (fabs(size->width - ceil(size->width)) < 0.1) ? + ceil(size->width) : size->width; + length_tmp = (fabs(size->length - ceil(size->length)) < 0.1) ? + ceil(size->length) : size->length; + + if (fmod(width_tmp, 18.0) == 0.0 && fmod(length_tmp, 18.0) == 0.0) + { + width_inch = width_tmp / 72.0; + length_inch = length_tmp / 72.0; + + snprintf(buf, sizeof(buf), "%gx%g", width_inch, length_inch); + } + else + { + width_mm = size->width / 72.0 * 25.4; + length_mm = size->length / 72.0 * 25.4; + + snprintf(buf, sizeof(buf), "%.0fx%.0fmm", width_mm, length_mm); + } + + if (size->left == 0 && size->bottom == 0 && + size->right == size->width && size->top == size->length) + strlcat(buf, ".Fullbleed", sizeof(buf)); + else if (size->width > size->length) + strlcat(buf, ".Transverse", sizeof(buf)); + + if (strcmp(size->name, buf)) + _cupsLangPrintf(stdout, + _(" %s Size \"%s\" should be \"%s\"."), + prefix, size->name, buf); + } + } } return (errors); @@ -3485,7 +3603,7 @@ test_raster(ppd_file_t *ppd, /* I - PPD file */ /* - * 'usage()' - Show program usage... + * 'usage()' - Show program usage. */ static void