void QPpdPrintDevice::loadPageSizes() const { m_pageSizes.clear(); m_printableMargins.clear(); ppd_option_t *pageSizes = ppdFindOption(m_ppd, "PageSize"); if (pageSizes) { for (int i = 0; i < pageSizes->num_choices; ++i) { const ppd_size_t *ppdSize = ppdPageSize(m_ppd, pageSizes->choices[i].choice); if (ppdSize) { // Returned size is in points QString key = QString::fromUtf8(ppdSize->name); QSize size = QSize(qRound(ppdSize->width), qRound(ppdSize->length)); QString name = QString::fromUtf8(pageSizes->choices[i].text); if (!size.isEmpty()) { QPageSize ps = createPageSize(key, size, name); if (ps.isValid()) { m_pageSizes.append(ps); m_printableMargins.insert(key, QMarginsF(ppdSize->left, ppdSize->length - ppdSize->top, ppdSize->width - ppdSize->right, ppdSize->bottom)); } } } } m_havePageSizes = true; } }
int /* O - Non-zero if option is marked */ ppdIsMarked(ppd_file_t *ppd, /* I - PPD file data */ const char *option, /* I - Option/Keyword name */ const char *choice) /* I - Choice name */ { ppd_choice_t key, /* Search key */ *c; /* Choice pointer */ if (!ppd) return (0); if ((key.option = ppdFindOption(ppd, option)) == NULL) return (0); if ((c = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) == NULL) return (0); return (!strcmp(c->choice, choice)); }
ppd_choice_t * /* O - Pointer to choice or @code NULL@ */ ppdFindMarkedChoice(ppd_file_t *ppd, /* I - PPD file */ const char *option) /* I - Keyword/option name */ { ppd_choice_t key, /* Search key for choice */ *marked; /* Marked choice */ DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd, option)); if ((key.option = ppdFindOption(ppd, option)) == NULL) { DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL"); return (NULL); } marked = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key); DEBUG_printf(("3ppdFindMarkedChoice: Returning %p(%s)...", marked, marked ? marked->choice : "NULL")); return (marked); }
GList *dt_get_media_type(const dt_printer_info_t *printer) { const char *printer_name = printer->name; GList *result = NULL; // check now PPD media type const char *PPDFile = cupsGetPPD(printer_name); ppd_file_t *ppd = ppdOpenFile(PPDFile); if (ppd) { ppd_option_t *opt = ppdFindOption(ppd, "MediaType"); if (opt) { ppd_choice_t *choice = opt->choices; for (int k=0; k<opt->num_choices; k++) { dt_medium_info_t *media = (dt_medium_info_t*)malloc(sizeof(dt_medium_info_t)); g_strlcpy(media->name, choice->choice, MAX_NAME); g_strlcpy(media->common_name, choice->text, MAX_NAME); result = g_list_append (result, media); dt_print(DT_DEBUG_PRINT, "[print] new media %2d (%s) (%s)\n", k, media->name, media->common_name); choice++; } } } ppdClose(ppd); g_unlink(PPDFile); return result; }
static void ppd_mark_option(ppd_file_t *ppd, /* I - PPD file */ const char *option, /* I - Option name */ const char *choice) /* I - Choice name */ { int i, j; /* Looping vars */ ppd_option_t *o; /* Option pointer */ ppd_choice_t *c, /* Choice pointer */ *oldc, /* Old choice pointer */ key; /* Search key for choice */ struct lconv *loc; /* Locale data */ DEBUG_printf(("7ppd_mark_option(ppd=%p, option=\"%s\", choice=\"%s\")", ppd, option, choice)); /* * AP_D_InputSlot is the "default input slot" on MacOS X, and setting * it clears the regular InputSlot choices... */ if (!_cups_strcasecmp(option, "AP_D_InputSlot")) { cupsArraySave(ppd->options); if ((o = ppdFindOption(ppd, "InputSlot")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } cupsArrayRestore(ppd->options); } /* * Check for custom options... */ cupsArraySave(ppd->options); o = ppdFindOption(ppd, option); cupsArrayRestore(ppd->options); if (!o) return; loc = localeconv(); if (!_cups_strncasecmp(choice, "Custom.", 7)) { /* * Handle a custom option... */ if ((c = ppdFindChoice(o, "Custom")) == NULL) return; if (!_cups_strcasecmp(option, "PageSize")) { /* * Handle custom page sizes... */ ppdPageSize(ppd, choice); } else { /* * Handle other custom options... */ ppd_coption_t *coption; /* Custom option */ ppd_cparam_t *cparam; /* Custom parameter */ char *units; /* Custom points units */ if ((coption = ppdFindCustomOption(ppd, option)) != NULL) { if ((cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params)) == NULL) return; switch (cparam->type) { case PPD_CUSTOM_CURVE : case PPD_CUSTOM_INVCURVE : case PPD_CUSTOM_REAL : cparam->current.custom_real = (float)_cupsStrScand(choice + 7, NULL, loc); break; case PPD_CUSTOM_POINTS : cparam->current.custom_points = (float)_cupsStrScand(choice + 7, &units, loc); if (units) { if (!_cups_strcasecmp(units, "cm")) cparam->current.custom_points *= 72.0f / 2.54f; else if (!_cups_strcasecmp(units, "mm")) cparam->current.custom_points *= 72.0f / 25.4f; else if (!_cups_strcasecmp(units, "m")) cparam->current.custom_points *= 72.0f / 0.0254f; else if (!_cups_strcasecmp(units, "in")) cparam->current.custom_points *= 72.0f; else if (!_cups_strcasecmp(units, "ft")) cparam->current.custom_points *= 12.0f * 72.0f; } break; case PPD_CUSTOM_INT : cparam->current.custom_int = atoi(choice + 7); break; case PPD_CUSTOM_PASSCODE : case PPD_CUSTOM_PASSWORD : case PPD_CUSTOM_STRING : if (cparam->current.custom_string) _cupsStrFree(cparam->current.custom_string); cparam->current.custom_string = _cupsStrAlloc(choice + 7); break; } } } /* * Make sure that we keep the option marked below... */ choice = "Custom"; } else if (choice[0] == '{') { /* * Handle multi-value custom options... */ ppd_coption_t *coption; /* Custom option */ ppd_cparam_t *cparam; /* Custom parameter */ char *units; /* Custom points units */ int num_vals; /* Number of values */ cups_option_t *vals, /* Values */ *val; /* Value */ if ((c = ppdFindChoice(o, "Custom")) == NULL) return; if ((coption = ppdFindCustomOption(ppd, option)) != NULL) { num_vals = cupsParseOptions(choice, 0, &vals); for (i = 0, val = vals; i < num_vals; i ++, val ++) { if ((cparam = ppdFindCustomParam(coption, val->name)) == NULL) continue; switch (cparam->type) { case PPD_CUSTOM_CURVE : case PPD_CUSTOM_INVCURVE : case PPD_CUSTOM_REAL : cparam->current.custom_real = (float)_cupsStrScand(val->value, NULL, loc); break; case PPD_CUSTOM_POINTS : cparam->current.custom_points = (float)_cupsStrScand(val->value, &units, loc); if (units) { if (!_cups_strcasecmp(units, "cm")) cparam->current.custom_points *= 72.0f / 2.54f; else if (!_cups_strcasecmp(units, "mm")) cparam->current.custom_points *= 72.0f / 25.4f; else if (!_cups_strcasecmp(units, "m")) cparam->current.custom_points *= 72.0f / 0.0254f; else if (!_cups_strcasecmp(units, "in")) cparam->current.custom_points *= 72.0f; else if (!_cups_strcasecmp(units, "ft")) cparam->current.custom_points *= 12.0f * 72.0f; } break; case PPD_CUSTOM_INT : cparam->current.custom_int = atoi(val->value); break; case PPD_CUSTOM_PASSCODE : case PPD_CUSTOM_PASSWORD : case PPD_CUSTOM_STRING : if (cparam->current.custom_string) _cupsStrFree(cparam->current.custom_string); cparam->current.custom_string = _cupsStrRetain(val->value); break; } } cupsFreeOptions(num_vals, vals); } } else { for (i = o->num_choices, c = o->choices; i > 0; i --, c ++) if (!_cups_strcasecmp(c->choice, choice)) break; if (!i) return; } /* * Option found; mark it and then handle unmarking any other options. */ if (o->ui != PPD_UI_PICKMANY) { /* * Unmark all other choices... */ if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, c)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } if (!_cups_strcasecmp(option, "PageSize") || !_cups_strcasecmp(option, "PageRegion")) { /* * Mark current page size... */ for (j = 0; j < ppd->num_sizes; j ++) ppd->sizes[j].marked = !_cups_strcasecmp(ppd->sizes[j].name, choice); /* * Unmark the current PageSize or PageRegion setting, as * appropriate... */ cupsArraySave(ppd->options); if (!_cups_strcasecmp(option, "PageSize")) { if ((o = ppdFindOption(ppd, "PageRegion")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } } else { if ((o = ppdFindOption(ppd, "PageSize")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } } cupsArrayRestore(ppd->options); } else if (!_cups_strcasecmp(option, "InputSlot")) { /* * Unmark ManualFeed option... */ cupsArraySave(ppd->options); if ((o = ppdFindOption(ppd, "ManualFeed")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } cupsArrayRestore(ppd->options); } else if (!_cups_strcasecmp(option, "ManualFeed") && !_cups_strcasecmp(choice, "True")) { /* * Unmark InputSlot option... */ cupsArraySave(ppd->options); if ((o = ppdFindOption(ppd, "InputSlot")) != NULL) { key.option = o; if ((oldc = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) != NULL) { oldc->marked = 0; cupsArrayRemove(ppd->marked, oldc); } } cupsArrayRestore(ppd->options); } } c->marked = 1; cupsArrayAdd(ppd->marked, c); }
int /* O - 1 if conflicts exist, 0 otherwise */ cupsMarkOptions( ppd_file_t *ppd, /* I - PPD file */ int num_options, /* I - Number of options */ cups_option_t *options) /* I - Options */ { int i, j; /* Looping vars */ char *ptr, /* Pointer into string */ s[255]; /* Temporary string */ const char *val, /* Pointer into value */ *media, /* media option */ *output_bin, /* output-bin option */ *page_size, /* PageSize option */ *ppd_keyword, /* PPD keyword */ *print_color_mode, /* print-color-mode option */ *print_quality, /* print-quality option */ *sides; /* sides option */ cups_option_t *optptr; /* Current option */ ppd_attr_t *attr; /* PPD attribute */ _ppd_cache_t *cache; /* PPD cache and mapping data */ /* * Check arguments... */ if (!ppd || num_options <= 0 || !options) return (0); ppd_debug_marked(ppd, "Before..."); /* * Do special handling for finishings, media, output-bin, output-mode, * print-color-mode, print-quality, and PageSize... */ media = cupsGetOption("media", num_options, options); output_bin = cupsGetOption("output-bin", num_options, options); page_size = cupsGetOption("PageSize", num_options, options); print_quality = cupsGetOption("print-quality", num_options, options); sides = cupsGetOption("sides", num_options, options); if ((print_color_mode = cupsGetOption("print-color-mode", num_options, options)) == NULL) print_color_mode = cupsGetOption("output-mode", num_options, options); if ((media || output_bin || print_color_mode || print_quality || sides) && !ppd->cache) { /* * Load PPD cache and mapping data as needed... */ ppd->cache = _ppdCacheCreateWithPPD(ppd); } cache = ppd->cache; if (media) { /* * Loop through the option string, separating it at commas and marking each * individual option as long as the corresponding PPD option (PageSize, * InputSlot, etc.) is not also set. * * For PageSize, we also check for an empty option value since some versions * of MacOS X use it to specify auto-selection of the media based solely on * the size. */ for (val = media; *val;) { /* * Extract the sub-option from the string... */ for (ptr = s; *val && *val != ',' && (ptr - s) < (sizeof(s) - 1);) *ptr++ = *val++; *ptr++ = '\0'; if (*val == ',') val ++; /* * Mark it... */ if (!page_size || !page_size[0]) { if (!_cups_strncasecmp(s, "Custom.", 7) || ppdPageSize(ppd, s)) ppd_mark_option(ppd, "PageSize", s); else if ((ppd_keyword = _ppdCacheGetPageSize(cache, NULL, s, NULL)) != NULL) ppd_mark_option(ppd, "PageSize", ppd_keyword); } if (cache && cache->source_option && !cupsGetOption(cache->source_option, num_options, options) && (ppd_keyword = _ppdCacheGetInputSlot(cache, NULL, s)) != NULL) ppd_mark_option(ppd, cache->source_option, ppd_keyword); if (!cupsGetOption("MediaType", num_options, options) && (ppd_keyword = _ppdCacheGetMediaType(cache, NULL, s)) != NULL) ppd_mark_option(ppd, "MediaType", ppd_keyword); } } if (cache) { if (!cupsGetOption("com.apple.print.DocumentTicket.PMSpoolFormat", num_options, options) && !cupsGetOption("APPrinterPreset", num_options, options) && (print_color_mode || print_quality)) { /* * Map output-mode and print-quality to a preset... */ _pwg_print_color_mode_t pwg_pcm;/* print-color-mode index */ _pwg_print_quality_t pwg_pq; /* print-quality index */ cups_option_t *preset;/* Current preset option */ if (print_color_mode && !strcmp(print_color_mode, "monochrome")) pwg_pcm = _PWG_PRINT_COLOR_MODE_MONOCHROME; else pwg_pcm = _PWG_PRINT_COLOR_MODE_COLOR; if (print_quality) { pwg_pq = atoi(print_quality) - IPP_QUALITY_DRAFT; if (pwg_pq < _PWG_PRINT_QUALITY_DRAFT) pwg_pq = _PWG_PRINT_QUALITY_DRAFT; else if (pwg_pq > _PWG_PRINT_QUALITY_HIGH) pwg_pq = _PWG_PRINT_QUALITY_HIGH; } else pwg_pq = _PWG_PRINT_QUALITY_NORMAL; if (cache->num_presets[pwg_pcm][pwg_pq] == 0) { /* * Try to find a preset that works so that we maximize the chances of us * getting a good print using IPP attributes. */ if (cache->num_presets[pwg_pcm][_PWG_PRINT_QUALITY_NORMAL] > 0) pwg_pq = _PWG_PRINT_QUALITY_NORMAL; else if (cache->num_presets[_PWG_PRINT_COLOR_MODE_COLOR][pwg_pq] > 0) pwg_pcm = _PWG_PRINT_COLOR_MODE_COLOR; else { pwg_pq = _PWG_PRINT_QUALITY_NORMAL; pwg_pcm = _PWG_PRINT_COLOR_MODE_COLOR; } } if (cache->num_presets[pwg_pcm][pwg_pq] > 0) { /* * Copy the preset options as long as the corresponding names are not * already defined in the IPP request... */ for (i = cache->num_presets[pwg_pcm][pwg_pq], preset = cache->presets[pwg_pcm][pwg_pq]; i > 0; i --, preset ++) { if (!cupsGetOption(preset->name, num_options, options)) ppd_mark_option(ppd, preset->name, preset->value); } } } if (output_bin && !cupsGetOption("OutputBin", num_options, options) && (ppd_keyword = _ppdCacheGetOutputBin(cache, output_bin)) != NULL) { /* * Map output-bin to OutputBin... */ ppd_mark_option(ppd, "OutputBin", ppd_keyword); } if (sides && cache->sides_option && !cupsGetOption(cache->sides_option, num_options, options)) { /* * Map sides to duplex option... */ if (!strcmp(sides, "one-sided") && cache->sides_1sided) ppd_mark_option(ppd, cache->sides_option, cache->sides_1sided); else if (!strcmp(sides, "two-sided-long-edge") && cache->sides_2sided_long) ppd_mark_option(ppd, cache->sides_option, cache->sides_2sided_long); else if (!strcmp(sides, "two-sided-short-edge") && cache->sides_2sided_short) ppd_mark_option(ppd, cache->sides_option, cache->sides_2sided_short); } } /* * Mark other options... */ for (i = num_options, optptr = options; i > 0; i --, optptr ++) if (!_cups_strcasecmp(optptr->name, "media") || !_cups_strcasecmp(optptr->name, "output-bin") || !_cups_strcasecmp(optptr->name, "output-mode") || !_cups_strcasecmp(optptr->name, "print-quality") || !_cups_strcasecmp(optptr->name, "sides")) continue; else if (!_cups_strcasecmp(optptr->name, "resolution") || !_cups_strcasecmp(optptr->name, "printer-resolution")) { ppd_mark_option(ppd, "Resolution", optptr->value); ppd_mark_option(ppd, "SetResolution", optptr->value); /* Calcomp, Linotype, QMS, Summagraphics, Tektronix, Varityper */ ppd_mark_option(ppd, "JCLResolution", optptr->value); /* HP */ ppd_mark_option(ppd, "CNRes_PGP", optptr->value); /* Canon */ } else if (!_cups_strcasecmp(optptr->name, "multiple-document-handling")) { if (!cupsGetOption("Collate", num_options, options) && ppdFindOption(ppd, "Collate")) { if (_cups_strcasecmp(optptr->value, "separate-documents-uncollated-copies")) ppd_mark_option(ppd, "Collate", "True"); else ppd_mark_option(ppd, "Collate", "False"); } } else if (!_cups_strcasecmp(optptr->name, "finishings")) { /* * Lookup cupsIPPFinishings attributes for each value... */ for (ptr = optptr->value; *ptr;) { /* * Get the next finishings number... */ if (!isdigit(*ptr & 255)) break; if ((j = strtol(ptr, &ptr, 10)) < 3) break; /* * Skip separator as needed... */ if (*ptr == ',') ptr ++; /* * Look it up in the PPD file... */ sprintf(s, "%d", j); if ((attr = ppdFindAttr(ppd, "cupsIPPFinishings", s)) == NULL) continue; /* * Apply "*Option Choice" settings from the attribute value... */ ppd_mark_choices(ppd, attr->value); } } else if (!_cups_strcasecmp(optptr->name, "APPrinterPreset")) { /* * Lookup APPrinterPreset value... */ if ((attr = ppdFindAttr(ppd, "APPrinterPreset", optptr->value)) != NULL) { /* * Apply "*Option Choice" settings from the attribute value... */ ppd_mark_choices(ppd, attr->value); } } else if (!_cups_strcasecmp(optptr->name, "mirror")) ppd_mark_option(ppd, "MirrorPrint", optptr->value); else ppd_mark_option(ppd, optptr->name, optptr->value); ppd_debug_marked(ppd, "After..."); return (ppdConflicts(ppd) > 0); }
static void apple_register_profiles( cupsd_printer_t *p) /* I - Printer */ { int i; /* Looping var */ char ppdfile[1024], /* PPD filename */ iccfile[1024], /* ICC filename */ selector[PPD_MAX_NAME]; /* Profile selection string */ ppd_file_t *ppd; /* PPD file */ ppd_attr_t *attr, /* Profile attributes */ *profileid_attr,/* cupsProfileID attribute */ *q1_attr, /* ColorModel (or other) qualifier */ *q2_attr, /* MediaType (or other) qualifier */ *q3_attr; /* Resolution (or other) qualifier */ char q_keyword[PPD_MAX_NAME]; /* Qualifier keyword */ const char *q1_choice, /* ColorModel (or other) choice */ *q2_choice, /* MediaType (or other) choice */ *q3_choice; /* Resolution (or other) choice */ ppd_option_t *cm_option; /* Color model option */ ppd_choice_t *cm_choice; /* Color model choice */ int num_profiles; /* Number of profiles */ OSStatus error = 0; /* Last error */ unsigned device_id, /* Printer device ID */ profile_id = 0, /* Profile ID */ default_profile_id = 0; /* Default profile ID */ CFMutableDictionaryRef device_name; /* Printer device name dictionary */ CFStringRef printer_name; /* Printer name string */ cups_array_t *languages; /* Languages array */ CFMutableDictionaryRef profiles, /* Dictionary of profiles */ profile; /* Current profile info dictionary */ CFStringRef dict_key; /* Key in factory profile dictionary */ /* * Make sure ColorSync is available... */ if (&ColorSyncRegisterDevice == NULL) return; /* * Try opening the PPD file for this printer... */ snprintf(ppdfile, sizeof(ppdfile), "%s/ppd/%s.ppd", ServerRoot, p->name); if ((ppd = _ppdOpenFile(ppdfile, _PPD_LOCALIZATION_ICC_PROFILES)) == NULL) return; /* * See if we have any profiles... */ for (num_profiles = 0, attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); attr; attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL)) if (attr->spec[0] && attr->value && attr->value[0]) { if (attr->value[0] != '/') snprintf(iccfile, sizeof(iccfile), "%s/profiles/%s", DataDir, attr->value); else strlcpy(iccfile, attr->value, sizeof(iccfile)); if (access(iccfile, 0)) { cupsdLogMessage(CUPSD_LOG_ERROR, "%s: ICC Profile \"%s\" does not exist.", p->name, iccfile); cupsdSetPrinterReasons(p, "+cups-missing-filter-warning"); continue; } num_profiles ++; } /* * Create a dictionary for the factory profiles... */ profiles = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!profiles) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to allocate memory for factory profiles."); ppdClose(ppd); return; } /* * If we have profiles, add them... */ if (num_profiles > 0) { /* * For CUPS PPDs, figure out the default profile selector values... */ if ((attr = ppdFindAttr(ppd, "cupsICCQualifier1", NULL)) != NULL && attr->value && attr->value[0]) { snprintf(q_keyword, sizeof(q_keyword), "Default%s", attr->value); q1_attr = ppdFindAttr(ppd, q_keyword, NULL); } else if ((q1_attr = ppdFindAttr(ppd, "DefaultColorModel", NULL)) == NULL) q1_attr = ppdFindAttr(ppd, "DefaultColorSpace", NULL); if (q1_attr && q1_attr->value && q1_attr->value[0]) q1_choice = q1_attr->value; else q1_choice = ""; if ((attr = ppdFindAttr(ppd, "cupsICCQualifier2", NULL)) != NULL && attr->value && attr->value[0]) { snprintf(q_keyword, sizeof(q_keyword), "Default%s", attr->value); q2_attr = ppdFindAttr(ppd, q_keyword, NULL); } else q2_attr = ppdFindAttr(ppd, "DefaultMediaType", NULL); if (q2_attr && q2_attr->value && q2_attr->value[0]) q2_choice = q2_attr->value; else q2_choice = NULL; if ((attr = ppdFindAttr(ppd, "cupsICCQualifier3", NULL)) != NULL && attr->value && attr->value[0]) { snprintf(q_keyword, sizeof(q_keyword), "Default%s", attr->value); q3_attr = ppdFindAttr(ppd, q_keyword, NULL); } else q3_attr = ppdFindAttr(ppd, "DefaultResolution", NULL); if (q3_attr && q3_attr->value && q3_attr->value[0]) q3_choice = q3_attr->value; else q3_choice = NULL; /* * Loop through the profiles listed in the PPD... */ languages = _ppdGetLanguages(ppd); for (attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); attr; attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL)) if (attr->spec[0] && attr->value && attr->value[0]) { /* * Add this profile... */ if (attr->value[0] != '/') snprintf(iccfile, sizeof(iccfile), "%s/profiles/%s", DataDir, attr->value); else strlcpy(iccfile, attr->value, sizeof(iccfile)); if (_cupsFileCheck(iccfile, _CUPS_FILE_CHECK_FILE, !RunUser, cupsdLogFCMessage, p)) iccfile[0] = '\0'; cupsArraySave(ppd->sorted_attrs); if ((profileid_attr = ppdFindAttr(ppd, "cupsProfileID", attr->spec)) != NULL && profileid_attr->value && isdigit(profileid_attr->value[0] & 255)) profile_id = (unsigned)strtoul(profileid_attr->value, NULL, 10); else profile_id = _ppdHashName(attr->spec); cupsArrayRestore(ppd->sorted_attrs); profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!profile) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to allocate memory for color profile."); CFRelease(profiles); ppdClose(ppd); return; } apple_init_profile(ppd, languages, profile, profile_id, attr->spec, attr->text[0] ? attr->text : attr->spec, iccfile); dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"), profile_id); if (dict_key) { CFDictionarySetValue(profiles, dict_key, profile); CFRelease(dict_key); } CFRelease(profile); /* * See if this is the default profile... */ if (!default_profile_id && q1_choice && q2_choice && q3_choice) { snprintf(selector, sizeof(selector), "%s.%s.%s", q1_choice, q2_choice, q3_choice); if (!strcmp(selector, attr->spec)) default_profile_id = profile_id; } if (!default_profile_id && q1_choice && q2_choice) { snprintf(selector, sizeof(selector), "%s.%s.", q1_choice, q2_choice); if (!strcmp(selector, attr->spec)) default_profile_id = profile_id; } if (!default_profile_id && q1_choice && q3_choice) { snprintf(selector, sizeof(selector), "%s..%s", q1_choice, q3_choice); if (!strcmp(selector, attr->spec)) default_profile_id = profile_id; } if (!default_profile_id && q1_choice) { snprintf(selector, sizeof(selector), "%s..", q1_choice); if (!strcmp(selector, attr->spec)) default_profile_id = profile_id; } if (!default_profile_id && q2_choice && q3_choice) { snprintf(selector, sizeof(selector), ".%s.%s", q2_choice, q3_choice); if (!strcmp(selector, attr->spec)) default_profile_id = profile_id; } if (!default_profile_id && q2_choice) { snprintf(selector, sizeof(selector), ".%s.", q2_choice); if (!strcmp(selector, attr->spec)) default_profile_id = profile_id; } if (!default_profile_id && q3_choice) { snprintf(selector, sizeof(selector), "..%s", q3_choice); if (!strcmp(selector, attr->spec)) default_profile_id = profile_id; } } _ppdFreeLanguages(languages); } else if ((cm_option = ppdFindOption(ppd, "ColorModel")) != NULL) { /* * Extract profiles from ColorModel option... */ const char *profile_name; /* Name of generic profile */ num_profiles = cm_option->num_choices; for (i = cm_option->num_choices, cm_choice = cm_option->choices; i > 0; i --, cm_choice ++) { if (!strcmp(cm_choice->choice, "Gray") || !strcmp(cm_choice->choice, "Black")) profile_name = "Gray"; else if (!strcmp(cm_choice->choice, "RGB") || !strcmp(cm_choice->choice, "CMY")) profile_name = "RGB"; else if (!strcmp(cm_choice->choice, "CMYK") || !strcmp(cm_choice->choice, "KCMY")) profile_name = "CMYK"; else profile_name = "DeviceN"; snprintf(selector, sizeof(selector), "%s..", profile_name); profile_id = _ppdHashName(selector); profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!profile) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to allocate memory for color profile."); CFRelease(profiles); ppdClose(ppd); return; } apple_init_profile(ppd, NULL, profile, profile_id, cm_choice->choice, cm_choice->text, NULL); dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"), profile_id); if (dict_key) { CFDictionarySetValue(profiles, dict_key, profile); CFRelease(dict_key); } CFRelease(profile); if (cm_choice->marked) default_profile_id = profile_id; } } else { /* * Use the default colorspace... */ attr = ppdFindAttr(ppd, "DefaultColorSpace", NULL); num_profiles = (attr && ppd->colorspace == PPD_CS_GRAY) ? 1 : 2; /* * Add the grayscale profile first. We always have a grayscale profile. */ profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!profile) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to allocate memory for color profile."); CFRelease(profiles); ppdClose(ppd); return; } profile_id = _ppdHashName("Gray.."); apple_init_profile(ppd, NULL, profile, profile_id, "Gray", "Gray", NULL); dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"), profile_id); if (dict_key) { CFDictionarySetValue(profiles, dict_key, profile); CFRelease(dict_key); } CFRelease(profile); /* * Then add the RGB/CMYK/DeviceN color profile... */ profile = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!profile) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to allocate memory for color profile."); CFRelease(profiles); ppdClose(ppd); return; } switch (ppd->colorspace) { default : case PPD_CS_RGB : case PPD_CS_CMY : profile_id = _ppdHashName("RGB.."); apple_init_profile(ppd, NULL, profile, profile_id, "RGB", "RGB", NULL); break; case PPD_CS_RGBK : case PPD_CS_CMYK : profile_id = _ppdHashName("CMYK.."); apple_init_profile(ppd, NULL, profile, profile_id, "CMYK", "CMYK", NULL); break; case PPD_CS_GRAY : if (attr) break; case PPD_CS_N : profile_id = _ppdHashName("DeviceN.."); apple_init_profile(ppd, NULL, profile, profile_id, "DeviceN", "DeviceN", NULL); break; } if (CFDictionaryGetCount(profile) > 0) { dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"), profile_id); if (dict_key) { CFDictionarySetValue(profiles, dict_key, profile); CFRelease(dict_key); } } CFRelease(profile); } if (num_profiles > 0) { /* * Make sure we have a default profile ID... */ if (!default_profile_id) default_profile_id = profile_id; /* Last profile */ dict_key = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"), default_profile_id); if (dict_key) { CFDictionarySetValue(profiles, kColorSyncDeviceDefaultProfileID, dict_key); CFRelease(dict_key); } /* * Get the device ID hash and pathelogical name dictionary. */ cupsdLogMessage(CUPSD_LOG_INFO, "Registering ICC color profiles for \"%s\"", p->name); device_id = _ppdHashName(p->name); device_name = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); printer_name = CFStringCreateWithCString(kCFAllocatorDefault, p->name, kCFStringEncodingUTF8); if (device_name && printer_name) { /* * Register the device with ColorSync... */ CFTypeRef deviceDictKeys[] = { /* Device keys */ kColorSyncDeviceDescriptions, kColorSyncFactoryProfiles, kColorSyncDeviceUserScope, kColorSyncDeviceHostScope }; CFTypeRef deviceDictVals[] = { /* Device values */ device_name, profiles, kCFPreferencesAnyUser, kCFPreferencesCurrentHost }; CFDictionaryRef deviceDict; /* Device dictionary */ CFUUIDRef deviceUUID; /* Device UUID */ CFDictionarySetValue(device_name, CFSTR("en_US"), printer_name); deviceDict = CFDictionaryCreate(kCFAllocatorDefault, (const void **)deviceDictKeys, (const void **)deviceDictVals, sizeof(deviceDictKeys) / sizeof(deviceDictKeys[0]), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); deviceUUID = ColorSyncCreateUUIDFromUInt32(device_id); if (!deviceDict || !deviceUUID || !ColorSyncRegisterDevice(kColorSyncPrinterDeviceClass, deviceUUID, deviceDict)) error = 1001; if (deviceUUID) CFRelease(deviceUUID); if (deviceDict) CFRelease(deviceDict); } else error = 1000; /* * Clean up... */ if (error != noErr) cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to register ICC color profiles for \"%s\": %d", p->name, (int)error); if (printer_name) CFRelease(printer_name); if (device_name) CFRelease(device_name); } /* * Free any memory we used... */ CFRelease(profiles); ppdClose(ppd); }
static void ppd_load_constraints(ppd_file_t *ppd) /* I - PPD file */ { int i; /* Looping var */ ppd_const_t *oldconst; /* Current UIConstraints data */ ppd_attr_t *constattr; /* Current cupsUIConstraints attribute */ _ppd_cups_uiconsts_t *consts; /* Current cupsUIConstraints data */ _ppd_cups_uiconst_t *constptr; /* Current constraint */ ppd_group_t *installable; /* Installable options group */ const char *vptr; /* Pointer into constraint value */ char option[PPD_MAX_NAME], /* Option name/MainKeyword */ choice[PPD_MAX_NAME], /* Choice/OptionKeyword */ *ptr; /* Pointer into option or choice */ DEBUG_printf(("7ppd_load_constraints(ppd=%p)", ppd)); /* * Create an array to hold the constraint data... */ ppd->cups_uiconstraints = cupsArrayNew(NULL, NULL); /* * Find the installable options group if it exists... */ for (i = ppd->num_groups, installable = ppd->groups; i > 0; i --, installable ++) if (!_cups_strcasecmp(installable->name, "InstallableOptions")) break; if (i <= 0) installable = NULL; /* * Load old-style [Non]UIConstraints data... */ for (i = ppd->num_consts, oldconst = ppd->consts; i > 0; i --, oldconst ++) { /* * Weed out nearby duplicates, since the PPD spec requires that you * define both "*Foo foo *Bar bar" and "*Bar bar *Foo foo"... */ if (i > 1 && !_cups_strcasecmp(oldconst[0].option1, oldconst[1].option2) && !_cups_strcasecmp(oldconst[0].choice1, oldconst[1].choice2) && !_cups_strcasecmp(oldconst[0].option2, oldconst[1].option1) && !_cups_strcasecmp(oldconst[0].choice2, oldconst[1].choice1)) continue; /* * Allocate memory... */ if ((consts = calloc(1, sizeof(_ppd_cups_uiconsts_t))) == NULL) { DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for " "UIConstraints!"); return; } if ((constptr = calloc(2, sizeof(_ppd_cups_uiconst_t))) == NULL) { free(consts); DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for " "UIConstraints!"); return; } /* * Fill in the information... */ consts->num_constraints = 2; consts->constraints = constptr; if (!_cups_strncasecmp(oldconst->option1, "Custom", 6) && !_cups_strcasecmp(oldconst->choice1, "True")) { constptr[0].option = ppdFindOption(ppd, oldconst->option1 + 6); constptr[0].choice = ppdFindChoice(constptr[0].option, "Custom"); constptr[0].installable = 0; } else { constptr[0].option = ppdFindOption(ppd, oldconst->option1); constptr[0].choice = ppdFindChoice(constptr[0].option, oldconst->choice1); constptr[0].installable = ppd_is_installable(installable, oldconst->option1); } if (!constptr[0].option || (!constptr[0].choice && oldconst->choice1[0])) { DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!", oldconst->option1, oldconst->choice1)); free(consts->constraints); free(consts); continue; } if (!_cups_strncasecmp(oldconst->option2, "Custom", 6) && !_cups_strcasecmp(oldconst->choice2, "True")) { constptr[1].option = ppdFindOption(ppd, oldconst->option2 + 6); constptr[1].choice = ppdFindChoice(constptr[1].option, "Custom"); constptr[1].installable = 0; } else { constptr[1].option = ppdFindOption(ppd, oldconst->option2); constptr[1].choice = ppdFindChoice(constptr[1].option, oldconst->choice2); constptr[1].installable = ppd_is_installable(installable, oldconst->option2); } if (!constptr[1].option || (!constptr[1].choice && oldconst->choice2[0])) { DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!", oldconst->option2, oldconst->choice2)); free(consts->constraints); free(consts); continue; } consts->installable = constptr[0].installable || constptr[1].installable; /* * Add it to the constraints array... */ cupsArrayAdd(ppd->cups_uiconstraints, consts); } /* * Then load new-style constraints... */ for (constattr = ppdFindAttr(ppd, "cupsUIConstraints", NULL); constattr; constattr = ppdFindNextAttr(ppd, "cupsUIConstraints", NULL)) { if (!constattr->value) { DEBUG_puts("8ppd_load_constraints: Bad cupsUIConstraints value!"); continue; } for (i = 0, vptr = strchr(constattr->value, '*'); vptr; i ++, vptr = strchr(vptr + 1, '*')); if (i == 0) { DEBUG_puts("8ppd_load_constraints: Bad cupsUIConstraints value!"); continue; } if ((consts = calloc(1, sizeof(_ppd_cups_uiconsts_t))) == NULL) { DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for " "cupsUIConstraints!"); return; } if ((constptr = calloc((size_t)i, sizeof(_ppd_cups_uiconst_t))) == NULL) { free(consts); DEBUG_puts("8ppd_load_constraints: Unable to allocate memory for " "cupsUIConstraints!"); return; } consts->num_constraints = i; consts->constraints = constptr; strlcpy(consts->resolver, constattr->spec, sizeof(consts->resolver)); for (i = 0, vptr = strchr(constattr->value, '*'); vptr; i ++, vptr = strchr(vptr, '*'), constptr ++) { /* * Extract "*Option Choice" or just "*Option"... */ for (vptr ++, ptr = option; *vptr && !_cups_isspace(*vptr); vptr ++) if (ptr < (option + sizeof(option) - 1)) *ptr++ = *vptr; *ptr = '\0'; while (_cups_isspace(*vptr)) vptr ++; if (*vptr == '*') choice[0] = '\0'; else { for (ptr = choice; *vptr && !_cups_isspace(*vptr); vptr ++) if (ptr < (choice + sizeof(choice) - 1)) *ptr++ = *vptr; *ptr = '\0'; } if (!_cups_strncasecmp(option, "Custom", 6) && !_cups_strcasecmp(choice, "True")) { _cups_strcpy(option, option + 6); strlcpy(choice, "Custom", sizeof(choice)); } constptr->option = ppdFindOption(ppd, option); constptr->choice = ppdFindChoice(constptr->option, choice); constptr->installable = ppd_is_installable(installable, option); consts->installable |= constptr->installable; if (!constptr->option || (!constptr->choice && choice[0])) { DEBUG_printf(("8ppd_load_constraints: Unknown option *%s %s!", option, choice)); break; } } if (!vptr) cupsArrayAdd(ppd->cups_uiconstraints, consts); else { free(consts->constraints); free(consts); } } }
int /* O - Exit status */ imagetops_main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { cups_image_t *img; /* Image to print */ float xprint, /* Printable area */ yprint, xinches, /* Total size in inches */ yinches; float xsize, /* Total size in points */ ysize, xsize2, ysize2; float aspect; /* Aspect ratio */ int xpages, /* # x pages */ ypages, /* # y pages */ xpage, /* Current x page */ ypage, /* Current y page */ page; /* Current page number */ int xc0, yc0, /* Corners of the page in image coords */ xc1, yc1; cups_ib_t *row; /* Current row */ int y; /* Current Y coordinate in image */ int colorspace; /* Output colorspace */ int out_offset, /* Offset into output buffer */ out_length; /* Length of output buffer */ ppd_file_t *ppd; /* PPD file */ ppd_choice_t *choice; /* PPD option choice */ int num_options; /* Number of print options */ cups_option_t *options; /* Print options */ const char *val; /* Option value */ int slowcollate; /* Collate copies the slow way */ float g; /* Gamma correction value */ float b; /* Brightness factor */ float zoom; /* Zoom facter */ int xppi, yppi; /* Pixels-per-inch */ int hue, sat; /* Hue and saturation adjustment */ int realcopies, /* Real copies being printed */ emit_jcl; /* Emit JCL? */ float left, top; /* Left and top of image */ char filename[1024]; /* Name of file to print */ time_t curtime; /* Current time */ struct tm *curtm; /* Current date */ char curdate[255]; /* Current date string */ int psFileMode = 0; //0:CREATE New ; 1: Append int outColorDevice = 1; //0 : monochrome print , 1:color print int count = 0,numFiles=1; int defout,outfd; /* * Make sure status messages are not buffered... */ int ii=0; for(;ii<argc;ii++) LOGI("imagetops : argv:%s",argv[ii]); fflush(stdout); Copies = 1; setbuf(stderr, NULL); /* * Ignore broken pipe signals... */ signal(SIGPIPE, SIG_IGN); /* * Process command-line options and write the prolog... */ zoom = 0.0; xppi = 0; yppi = 0; hue = 0; sat = 100; g = 1.0; b = 1.0; Copies = atoi(argv[4]); options = NULL; num_options = cupsParseOptions(argv[5], 0, &options); ppdFilePath = argv[6]; ContentType= argv[7]; psFilePath = argv[8]; outColorDevice = atoi(argv[9]); numFiles = argc - 10; LOGI("imagetops : numFiles=%d",numFiles); ppd = SetCommonOptions(num_options, options, 0); if ((val = cupsGetOption("multiple-document-handling", num_options, options)) != NULL) { /* * This IPP attribute is unnecessarily complicated... * * single-document, separate-documents-collated-copies, and * single-document-new-sheet all require collated copies. * * separate-documents-uncollated-copies allows for uncollated copies. */ Collate = _cups_strcasecmp(val, "separate-documents-uncollated-copies") != 0; } if ((val = cupsGetOption("Collate", num_options, options)) != NULL && _cups_strcasecmp(val, "True") == 0) Collate = 1; if ((val = cupsGetOption("gamma", num_options, options)) != NULL) { /* * Get gamma value from 1 to 10000... */ g = atoi(val) * 0.001f; if (g < 0.001f) g = 0.001f; else if (g > 10.0f) g = 10.0f; } if ((val = cupsGetOption("brightness", num_options, options)) != NULL) { /* * Get brightness value from 10 to 1000. */ b = atoi(val) * 0.01f; if (b < 0.1f) b = 0.1f; else if (b > 10.0f) b = 10.0f; } if ((val = cupsGetOption("scaling", num_options, options)) != NULL) zoom = atoi(val) * 0.01; else if ((val = cupsGetOption("fitplot", num_options, options)) != NULL && !_cups_strcasecmp(val, "true")) zoom = 1.0; else if ((val = cupsGetOption("fit-to-page", num_options, options)) != NULL && !_cups_strcasecmp(val, "true")) zoom = 1.0; if ((val = cupsGetOption("ppi", num_options, options)) != NULL) if (sscanf(val, "%dx%d", &xppi, &yppi) < 2) yppi = xppi; if ((val = cupsGetOption("position", num_options, options)) != NULL) { if (_cups_strcasecmp(val, "center") == 0) { XPosition = 0; YPosition = 0; } else if (_cups_strcasecmp(val, "top") == 0) { XPosition = 0; YPosition = 1; } else if (_cups_strcasecmp(val, "left") == 0) { XPosition = -1; YPosition = 0; } else if (_cups_strcasecmp(val, "right") == 0) { XPosition = 1; YPosition = 0; } else if (_cups_strcasecmp(val, "top-left") == 0) { XPosition = -1; YPosition = 1; } else if (_cups_strcasecmp(val, "top-right") == 0) { XPosition = 1; YPosition = 1; } else if (_cups_strcasecmp(val, "bottom") == 0) { XPosition = 0; YPosition = -1; } else if (_cups_strcasecmp(val, "bottom-left") == 0) { XPosition = -1; YPosition = -1; } else if (_cups_strcasecmp(val, "bottom-right") == 0) { XPosition = 1; YPosition = -1; } } if ((val = cupsGetOption("saturation", num_options, options)) != NULL) sat = atoi(val); if ((val = cupsGetOption("hue", num_options, options)) != NULL) hue = atoi(val); if ((choice = ppdFindMarkedChoice(ppd, "MirrorPrint")) != NULL) { val = choice->choice; choice->marked = 0; } else val = cupsGetOption("mirror", num_options, options); if (val && (!_cups_strcasecmp(val, "true") || !_cups_strcasecmp(val, "on") || !_cups_strcasecmp(val, "yes"))) Flip = 1; if ((val = cupsGetOption("emit-jcl", num_options, options)) != NULL && (!_cups_strcasecmp(val, "false") || !_cups_strcasecmp(val, "off") || !_cups_strcasecmp(val, "no") || !strcmp(val, "0"))) emit_jcl = 0; else emit_jcl = 1; LOGI("imagetops/Copies=%d , Collate=%d, gamma=%f, brightness=%f, zoom=%f",Copies,Collate,g,b,zoom); LOGI("imagetops/xppi=%d,yppi=%d,XPosition=%d,YPosition=%d,sat=%d,hue=%d,flip=%d,emit_jcl=%d",xppi,yppi,XPosition,YPosition,sat,hue,Flip,emit_jcl); /* * Open the input image to print... */ if(outColorDevice == 1) //added @ grv colorspace = CUPS_IMAGE_RGB_CMYK; else colorspace = CUPS_IMAGE_WHITE; LOGI("imagetops/ colorspace = %d",colorspace); for(count=0;count<numFiles;count++){ Copies = atoi(argv[4]); //do everything for both image files strlcpy(filename, argv[(10 + count)], sizeof(filename)); LOGI("imagetops : count=%d , filename=%s",count,filename); img = cupsImageOpen(filename, colorspace, CUPS_IMAGE_WHITE, sat, hue, NULL); if (img == NULL) { LOGI("imagetops:error:The print file could not be opened."); _cupsLangPrintFilter(stderr, "ERROR", _("The print file could not be opened.")); ppdClose(ppd); return (1); } colorspace = cupsImageGetColorSpace(img); LOGI("imagetops: cupsImageGetColorSpace finished : colorspace :%d",colorspace); /* * Scale as necessary... */ if (zoom == 0.0 && xppi == 0) { xppi = cupsImageGetXPPI(img); yppi = cupsImageGetYPPI(img); } LOGI("imagetops:xppi=%d",xppi); LOGI("imagetops:yppi=%d",yppi); if (yppi == 0) yppi = xppi; fprintf(stderr, "DEBUG: Before scaling: xppi=%d, yppi=%d, zoom=%.2f\n", xppi, yppi, zoom); if (xppi > 0) { /* * Scale the image as neccesary to match the desired pixels-per-inch. */ if (Orientation & 1) { xprint = (PageTop - PageBottom) / 72.0; yprint = (PageRight - PageLeft) / 72.0; } else { xprint = (PageRight - PageLeft) / 72.0; yprint = (PageTop - PageBottom) / 72.0; } fprintf(stderr, "DEBUG: Before scaling: xprint=%.1f, yprint=%.1f\n", xprint, yprint); xinches = (float)cupsImageGetWidth(img) / (float)xppi; yinches = (float)cupsImageGetHeight(img) / (float)yppi; fprintf(stderr, "DEBUG: Image size is %.1f x %.1f inches...\n", xinches, yinches); if ((val = cupsGetOption("natural-scaling", num_options, options)) != NULL) { xinches = xinches * atoi(val) / 100; yinches = yinches * atoi(val) / 100; } if (cupsGetOption("orientation-requested", num_options, options) == NULL && cupsGetOption("landscape", num_options, options) == NULL) { /* * Rotate the image if it will fit landscape but not portrait... */ fputs("DEBUG: Auto orientation...\n", stderr); LOGI("imagetops.c : Auto orientation..."); if ((xinches > xprint || yinches > yprint) && xinches <= yprint && yinches <= xprint) { /* * Rotate the image as needed... */ fputs("DEBUG: Using landscape orientation...\n", stderr); LOGI("imagetops.c : Auto orientation : Using landscape orientation"); Orientation = (Orientation + 1) & 3; xsize = yprint; yprint = xprint; xprint = xsize; } } }else{ /* * Scale percentage of page size... */ xprint = (PageRight - PageLeft) / 72.0; yprint = (PageTop - PageBottom) / 72.0; aspect = (float)cupsImageGetYPPI(img) / (float)cupsImageGetXPPI(img); fprintf(stderr, "DEBUG: Before scaling: xprint=%.1f, yprint=%.1f\n", xprint, yprint); fprintf(stderr, "DEBUG: cupsImageGetXPPI(img) = %d, cupsImageGetYPPI(img) = %d, aspect = %f\n", cupsImageGetXPPI(img), cupsImageGetYPPI(img), aspect); xsize = xprint * zoom; ysize = xsize * cupsImageGetHeight(img) / cupsImageGetWidth(img) / aspect; if (ysize > (yprint * zoom)) { ysize = yprint * zoom; xsize = ysize * cupsImageGetWidth(img) * aspect / cupsImageGetHeight(img); } xsize2 = yprint * zoom; ysize2 = xsize2 * cupsImageGetHeight(img) / cupsImageGetWidth(img) / aspect; if (ysize2 > (xprint * zoom)) { ysize2 = xprint * zoom; xsize2 = ysize2 * cupsImageGetWidth(img) * aspect / cupsImageGetHeight(img); } fprintf(stderr, "DEBUG: Portrait size is %.2f x %.2f inches\n", xsize, ysize); fprintf(stderr, "DEBUG: Landscape size is %.2f x %.2f inches\n", xsize2, ysize2); if (cupsGetOption("orientation-requested", num_options, options) == NULL && cupsGetOption("landscape", num_options, options) == NULL) { /* * Choose the rotation with the largest area, but prefer * portrait if they are equal... */ fputs("DEBUG: Auto orientation...\n", stderr); if ((xsize * ysize) < (xsize2 * xsize2)) { /* * Do landscape orientation... */ fputs("DEBUG: Using landscape orientation...\n", stderr); Orientation = 1; xinches = xsize2; yinches = ysize2; xprint = (PageTop - PageBottom) / 72.0; yprint = (PageRight - PageLeft) / 72.0; } else { /* * Do portrait orientation... */ fputs("DEBUG: Using portrait orientation...\n", stderr); Orientation = 0; xinches = xsize; yinches = ysize; } } else if (Orientation & 1) { fputs("DEBUG: Using landscape orientation...\n", stderr); xinches = xsize2; yinches = ysize2; xprint = (PageTop - PageBottom) / 72.0; yprint = (PageRight - PageLeft) / 72.0; } else { fputs("DEBUG: Using portrait orientation...\n", stderr); xinches = xsize; yinches = ysize; xprint = (PageRight - PageLeft) / 72.0; yprint = (PageTop - PageBottom) / 72.0; } } /* * Compute the number of pages to print and the size of the image on each * page... */ xpages = ceil(xinches / xprint); ypages = ceil(yinches / yprint); xprint = xinches / xpages; yprint = yinches / ypages; fprintf(stderr, "DEBUG: xpages = %dx%.2fin, ypages = %dx%.2fin\n",xpages, xprint, ypages, yprint); /* * Update the page size for custom sizes... */ if ((choice = ppdFindMarkedChoice(ppd, "PageSize")) != NULL && _cups_strcasecmp(choice->choice, "Custom") == 0) { float width, /* New width in points */ length; /* New length in points */ char s[255]; /* New custom page size... */ /* * Use the correct width and length for the current orientation... */ if (Orientation & 1) { width = yprint * 72.0; length = xprint * 72.0; } else { width = xprint * 72.0; length = yprint * 72.0; } /* * Add margins to page size... */ width += ppd->custom_margins[0] + ppd->custom_margins[2]; length += ppd->custom_margins[1] + ppd->custom_margins[3]; /* * Enforce minimums... */ if (width < ppd->custom_min[0]) width = ppd->custom_min[0]; if (length < ppd->custom_min[1]) length = ppd->custom_min[1]; fprintf(stderr, "DEBUG: Updated custom page size to %.2f x %.2f inches...\n",width / 72.0, length / 72.0); /* * Set the new custom size... */ sprintf(s, "Custom.%.0fx%.0f", width, length); ppdMarkOption(ppd, "PageSize", s); /* * Update page variables... */ PageWidth = width; PageLength = length; PageLeft = ppd->custom_margins[0]; PageRight = width - ppd->custom_margins[2]; PageBottom = ppd->custom_margins[1]; PageTop = length - ppd->custom_margins[3]; } /* * See if we need to collate, and if so how we need to do it... */ if (xpages == 1 && ypages == 1) Collate = 0; slowcollate = Collate && ppdFindOption(ppd, "Collate") == NULL; if (Copies > 1 && !slowcollate) { realcopies = Copies; Copies = 1; } else realcopies = 1; /* * Write any "exit server" options that have been selected... */ //Changes to create ps file -- start if(count == 0){//single side print defout = dup(1); outfd = open(psFilePath,O_RDWR | O_CREAT,S_IRWXU |S_IRWXG | S_IRWXO); dup2(outfd,1); } //Changes to create ps file -- end ppdEmit(ppd, stdout, PPD_ORDER_EXIT); /* * Write any JCL commands that are needed to print PostScript code... */ if (emit_jcl) ppdEmitJCL(ppd, stdout, atoi(argv[1]), argv[2], argv[3]); /* * Start sending the document with any commands needed... */ curtime = time(NULL); curtm = localtime(&curtime); ////////////////// if(count == 0){ puts("%!PS-Adobe-3.0"); printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft, PageBottom,PageRight, PageTop); printf("%%%%LanguageLevel: %d\n", LanguageLevel); printf("%%%%Pages: %d\n", xpages * ypages * Copies * numFiles); puts("%%DocumentData: Clean7Bit"); puts("%%DocumentNeededResources: font Helvetica-Bold"); puts("%%Creator: imagetops/" CUPS_SVERSION); strftime(curdate, sizeof(curdate), "%c", curtm); printf("%%%%CreationDate: %s\n", curdate); WriteTextComment("Title", argv[3]); WriteTextComment("For", argv[2]); if (Orientation & 1) puts("%%Orientation: Landscape"); else puts("%%Orientation: Portrait"); puts("%%EndComments"); puts("%%BeginProlog"); if (ppd != NULL && ppd->patches != NULL) puts(ppd->patches); ppdEmit(ppd, stdout, PPD_ORDER_DOCUMENT); ppdEmit(ppd, stdout, PPD_ORDER_ANY); ppdEmit(ppd, stdout, PPD_ORDER_PROLOG); if (g != 1.0 || b != 1.0) printf("{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } " "ifelse %.3f mul } bind settransfer\n", g, b); WriteCommon(); switch (Orientation) { case 0 : WriteLabelProlog(cupsGetOption("page-label", num_options, options), PageBottom, PageTop, PageWidth); break; case 1 : WriteLabelProlog(cupsGetOption("page-label", num_options, options), PageLeft, PageRight, PageLength); break; case 2 : WriteLabelProlog(cupsGetOption("page-label", num_options, options), PageLength - PageTop, PageLength - PageBottom, PageWidth); break; case 3 : WriteLabelProlog(cupsGetOption("page-label", num_options, options), PageWidth - PageRight, PageWidth - PageLeft,PageLength); break; } if (realcopies > 1) { if (ppd == NULL || ppd->language_level == 1) printf("/#copies %d def\n", realcopies); else printf("<</NumCopies %d>>setpagedevice\n", realcopies); } puts("%%EndProlog"); } /* * Output the pages... */ row = malloc(cupsImageGetWidth(img) * abs(colorspace) + 3); fprintf(stderr, "DEBUG: XPosition=%d, YPosition=%d, Orientation=%d\n",XPosition, YPosition, Orientation); fprintf(stderr, "DEBUG: xprint=%.0f, yprint=%.0f\n", xprint, yprint); fprintf(stderr, "DEBUG: PageLeft=%.0f, PageRight=%.0f, PageWidth=%.0f\n",PageLeft, PageRight, PageWidth); fprintf(stderr, "DEBUG: PageBottom=%.0f, PageTop=%.0f, PageLength=%.0f\n",PageBottom, PageTop, PageLength); switch (Orientation) { default : switch (XPosition) { case -1 : left = PageLeft; break; default : left = (PageRight + PageLeft - xprint * 72) / 2; break; case 1 : left = PageRight - xprint * 72; break; } switch (YPosition) { case -1 : top = PageBottom + yprint * 72; break; default : top = (PageTop + PageBottom + yprint * 72) / 2; break; case 1 : top = PageTop; break; } break; case 1 : switch (XPosition) { case -1 : left = PageBottom; break; default : left = (PageTop + PageBottom - xprint * 72) / 2; break; case 1 : left = PageTop - xprint * 72; break; } switch (YPosition) { case -1 : top = PageLeft + yprint * 72; break; default : top = (PageRight + PageLeft + yprint * 72) / 2; break; case 1 : top = PageRight; break; } break; case 2 : switch (XPosition) { case 1 : left = PageLeft; break; default : left = (PageRight + PageLeft - xprint * 72) / 2; break; case -1 : left = PageRight - xprint * 72; break; } switch (YPosition) { case 1 : top = PageBottom + yprint * 72; break; default : top = (PageTop + PageBottom + yprint * 72) / 2; break; case -1 : top = PageTop; break; } break; case 3 : switch (XPosition) { case 1 : left = PageBottom; break; default : left = (PageTop + PageBottom - xprint * 72) / 2; break; case -1 : left = PageTop - xprint * 72; break; } switch (YPosition) { case 1 : top = PageLeft + yprint * 72; break; default : top = (PageRight + PageLeft + yprint * 72) / 2; break; case -1 : top = PageRight; break; } break; } fprintf(stderr, "DEBUG: left=%.2f, top=%.2f\n", left, top); for (page = 1; Copies > 0; Copies --) for (xpage = 0; xpage < xpages; xpage ++) for (ypage = 0; ypage < ypages; ypage ++, page ++) { if (ppd && ppd->num_filters == 0) fprintf(stderr, "PAGE: %d %d\n", page, realcopies); _cupsLangPrintFilter(stderr, "INFO", _("Printing page %d."), page); printf("%%%%Page: %d %d\n", (page * (count+1)), (page*(count+1))); //TEST_TODO if(count>=1){ puts("%%BeginPageSetup"); if (Orientation & 1) puts("%%PageOrientation: Landscape"); else puts("%%PageOrientation: Portrait"); puts("%%EndPageSetup"); } ppdEmit(ppd, stdout, PPD_ORDER_PAGE); puts("gsave"); if (Flip) printf("%.0f 0 translate -1 1 scale\n", PageWidth); switch (Orientation) { case 1 : /* Landscape */ printf("%.0f 0 translate 90 rotate\n", PageWidth); break; case 2 : /* Reverse Portrait */ printf("%.0f %.0f translate 180 rotate\n", PageWidth, PageLength); break; case 3 : /* Reverse Landscape */ printf("0 %.0f translate -90 rotate\n", PageLength); break; } puts("gsave"); xc0 = cupsImageGetWidth(img) * xpage / xpages; xc1 = cupsImageGetWidth(img) * (xpage + 1) / xpages - 1; yc0 = cupsImageGetHeight(img) * ypage / ypages; yc1 = cupsImageGetHeight(img) * (ypage + 1) / ypages - 1; printf("%.1f %.1f translate\n", left, top); printf("%.3f %.3f scale\n\n",xprint * 72.0 / (xc1 - xc0 + 1),yprint * 72.0 / (yc1 - yc0 + 1)); if (LanguageLevel == 1) { printf("/picture %d string def\n", (xc1 - xc0 + 1) * abs(colorspace)); printf("%d %d 8[1 0 0 -1 0 1]", (xc1 - xc0 + 1), (yc1 - yc0 + 1)); if (colorspace == CUPS_IMAGE_WHITE) puts("{currentfile picture readhexstring pop} image"); else printf("{currentfile picture readhexstring pop} false %d colorimage\n",abs(colorspace)); for (y = yc0; y <= yc1; y ++) { cupsImageGetRow(img, xc0, y, xc1 - xc0 + 1, row); ps_hex(row, (xc1 - xc0 + 1) * abs(colorspace), y == yc1); } } else { switch (colorspace) { case CUPS_IMAGE_WHITE : puts("/DeviceGray setcolorspace"); break; case CUPS_IMAGE_RGB : puts("/DeviceRGB setcolorspace"); break; case CUPS_IMAGE_CMYK : puts("/DeviceCMYK setcolorspace"); break; } printf("<<" "/ImageType 1" "/Width %d" "/Height %d" "/BitsPerComponent 8", xc1 - xc0 + 1, yc1 - yc0 + 1); switch (colorspace) { case CUPS_IMAGE_WHITE : fputs("/Decode[0 1]", stdout); break; case CUPS_IMAGE_RGB : fputs("/Decode[0 1 0 1 0 1]", stdout); break; case CUPS_IMAGE_CMYK : fputs("/Decode[0 1 0 1 0 1 0 1]", stdout); break; } fputs("\n/DataSource currentfile/ASCII85Decode filter", stdout); if (((xc1 - xc0 + 1) / xprint) < 100.0) fputs("/Interpolate true", stdout); puts("/ImageMatrix[1 0 0 -1 0 1]>>image"); for (y = yc0, out_offset = 0; y <= yc1; y ++) { cupsImageGetRow(img, xc0, y, xc1 - xc0 + 1, row + out_offset); out_length = (xc1 - xc0 + 1) * abs(colorspace) + out_offset; out_offset = out_length & 3; ps_ascii85(row, out_length, y == yc1); if (out_offset > 0) memcpy(row, row + out_length - out_offset, out_offset); } } if(count==1){ puts("grestore"); WriteLabels(0); puts("grestore"); } puts("showpage"); puts("%%PageTrailer"); } } //end of big for loop puts("%%EOF"); /* * End the job with the appropriate JCL command or CTRL-D otherwise. */ if (emit_jcl) { if (ppd && ppd->jcl_end) ppdEmitJCLEnd(ppd, stdout); else putchar(0x04); } fflush(stdout); dup2(defout,1); close(outfd); close(defout); /* * Close files... */ LOGI("imagetops:Close files"); cupsImageClose(img); ppdClose(ppd); return (0); }
int DeviceAttributes_ ( ppd_file_t * ppd, oyOptions_s * options, oyConfig_s * device, const char * ppd_file_location ) { oyOption_s * o = 0; int error = !device; oyOption_s * value3 = oyOptions_Find( options, "device_context", oyNAME_PATTERN ); const char * device_name = oyConfig_FindString( device, "device_name", 0 ); if(!error) { char * manufacturer= 0, * model=0, * serial=0, * device_settings = 0; const char * system_port = 0, * host = 0; const char * keyword = 0; ppd_attr_t * attrs = 0; int attr_n, i, j; char ** color_key_words = 0, * tmp = 0; int color_key_words_n = 0; if(!device_name && !value3 && !ppd_file_location && !ppd) { message(oyMSG_WARN, (oyStruct_s*)options, _DBG_FORMAT_ "The \"device_name\" and \"device_context\" is\n" " missed to select a appropriate device.", _DBG_ARGS_ ); error = 1; return error; } if(!ppd) { message( oyMSG_DBG, (oyStruct_s*)0, _DBG_FORMAT_ "\n" "No PPD obtained for ", _DBG_ARGS_, device_name ); error = -1; return error; } manufacturer = ppd->manufacturer; model = ppd->modelname; serial = 0; /* Not known at this time. */ system_port = device_name; host = cupsServer(); attrs = ppdFindAttr(ppd, "cupsICCProfile", 0); if(attrs && attrs->text) device_settings = attrs->text; if(error <= 0) { size_t size = 0; char * data = 0; oyConfig_s * d = device; oyRankMap * rank_map = oyRankMapCopy( oyConfig_GetRankMap( device ), oyAllocateFunc_ ); if(!rank_map) rank_map = oyRankMapCopy( _api8.rank_map, oyAllocateFunc_ ); OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), manufacturer ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), model ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), serial ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), system_port ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), host ) OPTIONS_ADD( oyConfig_GetOptions(d,"backend_core"), device_settings ) if (value3) { /* open the PPD data */ if(ppd_file_location) { FILE * fp = fopen( ppd_file_location, "r" ); size_t lsize = 0; /* Find the total size. */ fseek(fp , 0, SEEK_END); lsize = ftell(fp); rewind (fp); /* Create buffer to read contents into a profile. */ data = (char*) malloc (sizeof(char)*lsize + 1); if (data == NULL) fputs ("Unable to open PPD size.",stderr); size = fread( data, 1, lsize, fp); data[size] = 0; } if(!error && data && size) { o = oyOption_FromRegistration( CMM_BASE_REG OY_SLASH "device_context.PPD.text", 0 ); error = !o; if(!error) error = oyOption_SetFromData( o, data, size ); if(!error) oyOptions_MoveIn( *oyConfig_GetOptions(device,"data"), &o, -1 ); } } /* Collect all ColorKeyWords. */ attr_n = ppd->num_attrs; for(i = 0; i < attr_n; i++) { char key[16]; keyword = ppd->attrs[i]->name; /* we support keys beginning with ColorKeyWords, e.g. "ColorKeyWords" "ColorKeyWords" ... */ snprintf( &key[0], 16, "%s", keyword ); key[14] = 0; if (strcmp(key, "ColorKeyWords") == 0) { if( tmp && tmp[oyStrlen_(tmp) - 1] != ';' ) STRING_ADD( tmp, ";" ); STRING_ADD( tmp, ppd->attrs[i]->value ); } } if(tmp) { color_key_words = oyStringSplit( tmp, ';', &color_key_words_n, oyAllocateFunc_); oyDeAllocateFunc_( tmp ); tmp = 0; } /* add the key/value pairs to the devices backend_core options. */ for(j = 0; j < color_key_words_n; ++j) { const char * keyword = color_key_words[j], * value = NULL; ppd_choice_t * c = ppdFindMarkedChoice( ppd, keyword ); ppd_option_t * o = ppdFindOption( ppd, keyword ); char * reg_name = 0; /* take the marked choice */ if(c) value = c->choice; /* fall back to a default */ else if(o) value = o->defchoice; else /* Scan PPD attributes for matching the ColorKeyWords and */ for(i = 0; i < attr_n; i++) if(oyStrcmp_( ppd->attrs[i]->name, keyword ) == 0) value = ppd->attrs[i]->value; STRING_ADD( reg_name, CMM_BASE_REG OY_SLASH ); STRING_ADD( reg_name, keyword ); if(value) { error= oyOptions_SetFromText( oyConfig_GetOptions(d,"backend_core"), reg_name, value, OY_CREATE_NEW ); oyRankMapAppend( &rank_map, reg_name, 2, -2, 0, 0,0 ); } if(reg_name) oyDeAllocateFunc_( reg_name ); reg_name = 0; } if( color_key_words && color_key_words_n) oyStringListRelease_( &color_key_words, color_key_words_n, oyDeAllocateFunc_ ); else { ppd_option_t * o; while((o = ppdNextOption(ppd)) != 0) { const char * value = 0; char * reg_name = 0; keyword = o->keyword; STRING_ADD( reg_name, CMM_BASE_REG OY_SLASH ); STRING_ADD( reg_name, keyword ); /* take the marked choice */ for(i = 0; i < o->num_choices; ++i) if(o->choices[i].marked) { value = o->choices[i].choice; break; } if(!value) value = o->defchoice; if(value) { error = oyOptions_SetFromText( oyConfig_GetOptions(d,"backend_core"), reg_name, value, OY_CREATE_NEW ); oyRankMapAppend( &rank_map, reg_name, 2, -2, 0, 0,0 ); } if(reg_name) oyDeAllocateFunc_( reg_name ); reg_name = 0; } } oyConfig_SetRankMap( device, rank_map ); oyRankMapRelease( &rank_map, oyDeAllocateFunc_ ); }
int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping var */ int errors = 0; /* Number of errors */ cups_lang_t *language; /* Message catalog */ cups_lang_t *language2; /* Message catalog */ struct lconv *loc; /* Locale data */ char buffer[1024]; /* String buffer */ double number; /* Number */ static const char * const tests[] = /* Test strings */ { "1", "-1", "3", "5.125" }; if (argc == 1) { language = cupsLangDefault(); language2 = cupsLangDefault(); } else { language = cupsLangGet(argv[1]); language2 = cupsLangGet(argv[1]); setenv("LANG", argv[1], 1); setenv("SOFTWARE", "CUPS/" CUPS_SVERSION, 1); } _cupsSetLocale(argv); if (language != language2) { errors ++; puts("**** ERROR: Language cache did not work! ****"); puts("First result from cupsLangGet:"); } printf("Language = \"%s\"\n", language->language); printf("Encoding = \"%s\"\n", _cupsEncodingName(language->encoding)); printf("No = \"%s\"\n", _cupsLangString(language, "No")); printf("Yes = \"%s\"\n", _cupsLangString(language, "Yes")); if (language != language2) { puts("Second result from cupsLangGet:"); printf("Language = \"%s\"\n", language2->language); printf("Encoding = \"%s\"\n", _cupsEncodingName(language2->encoding)); printf("No = \"%s\"\n", _cupsLangString(language2, "No")); printf("Yes = \"%s\"\n", _cupsLangString(language2, "Yes")); } loc = localeconv(); for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i ++) { number = _cupsStrScand(tests[i], NULL, loc); printf("_cupsStrScand(\"%s\") number=%f\n", tests[i], number); _cupsStrFormatd(buffer, buffer + sizeof(buffer), number, loc); printf("_cupsStrFormatd(%f) buffer=\"%s\"\n", number, buffer); if (strcmp(buffer, tests[i])) { errors ++; puts("**** ERROR: Bad formatted number! ****"); } } if (argc == 3) { ppd_file_t *ppd; /* PPD file */ ppd_option_t *option; /* PageSize option */ ppd_choice_t *choice; /* PageSize/Letter choice */ if ((ppd = ppdOpenFile(argv[2])) == NULL) { printf("Unable to open PPD file \"%s\".\n", argv[2]); errors ++; } else { ppdLocalize(ppd); if ((option = ppdFindOption(ppd, "PageSize")) == NULL) { puts("No PageSize option."); errors ++; } else { printf("PageSize: %s\n", option->text); if ((choice = ppdFindChoice(option, "Letter")) == NULL) { puts("No Letter PageSize choice."); errors ++; } else { printf("Letter: %s\n", choice->text); } } ppdClose(ppd); } } return (errors > 0); }
/* * Returns list of media: pages + trays */ JNIEXPORT jobjectArray JNICALL Java_sun_print_CUPSPrinter_getMedia(JNIEnv *env, jobject printObj, jstring printer) { ppd_file_t *ppd; ppd_option_t *optionTray, *optionPage; ppd_choice_t *choice; const char *name; const char *filename; int i, nTrays=0, nPages=0, nTotal=0; jstring utf_str; jclass cls; jobjectArray nameArray = NULL; name = (*env)->GetStringUTFChars(env, printer, NULL); if (name == NULL) { return NULL; } // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. // unlink() must be caled to remove the file when finished using it. filename = cupsGetPPD(name); (*env)->ReleaseStringUTFChars(env, printer, name); cls = (*env)->FindClass(env, "java/lang/String"); if (filename == NULL) { return NULL; } if ((ppd = ppdOpenFile(filename)) == NULL) { unlink(filename); DPRINTF("CUPSfuncs::unable to open PPD %s\n", filename); return NULL; } optionPage = ppdFindOption(ppd, "PageSize"); if (optionPage != NULL) { nPages = optionPage->num_choices; } optionTray = ppdFindOption(ppd, "InputSlot"); if (optionTray != NULL) { nTrays = optionTray->num_choices; } if ((nTotal = (nPages+nTrays) *2) > 0) { nameArray = (*env)->NewObjectArray(env, nTotal, cls, NULL); if (nameArray == NULL) { unlink(filename); ppdClose(ppd); DPRINTF("CUPSfuncs::bad alloc new array\n", "") JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); return NULL; } for (i = 0; optionPage!=NULL && i<nPages; i++) { choice = (optionPage->choices)+i; utf_str = JNU_NewStringPlatform(env, choice->text); if (utf_str == NULL) { unlink(filename); ppdClose(ppd); DPRINTF("CUPSfuncs::bad alloc new string ->text\n", "") JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); return NULL; } (*env)->SetObjectArrayElement(env, nameArray, i*2, utf_str); (*env)->DeleteLocalRef(env, utf_str); utf_str = JNU_NewStringPlatform(env, choice->choice); if (utf_str == NULL) { unlink(filename); ppdClose(ppd); DPRINTF("CUPSfuncs::bad alloc new string ->choice\n", "") JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); return NULL; } (*env)->SetObjectArrayElement(env, nameArray, i*2+1, utf_str); (*env)->DeleteLocalRef(env, utf_str); } for (i = 0; optionTray!=NULL && i<nTrays; i++) { choice = (optionTray->choices)+i; utf_str = JNU_NewStringPlatform(env, choice->text); if (utf_str == NULL) { unlink(filename); ppdClose(ppd); DPRINTF("CUPSfuncs::bad alloc new string text\n", "") JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); return NULL; } (*env)->SetObjectArrayElement(env, nameArray, (nPages+i)*2, utf_str); (*env)->DeleteLocalRef(env, utf_str); utf_str = JNU_NewStringPlatform(env, choice->choice); if (utf_str == NULL) { unlink(filename); ppdClose(ppd); DPRINTF("CUPSfuncs::bad alloc new string choice\n", "") JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); return NULL; } (*env)->SetObjectArrayElement(env, nameArray, (nPages+i)*2+1, utf_str); (*env)->DeleteLocalRef(env, utf_str); } } ppdClose(ppd); unlink(filename); return nameArray; }
jobjectArray sizeArray = NULL; jfloat *dims; // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. // unlink() must be called to remove the file after using it. filename = cupsGetPPD(name); (*env)->ReleaseStringUTFChars(env, printer, name); if (filename == NULL) { return NULL; } if ((ppd = ppdOpenFile(filename)) == NULL) { unlink(filename); DPRINTF("unable to open PPD %s\n", filename) return NULL; } option = ppdFindOption(ppd, "PageSize"); if (option != NULL && option->num_choices > 0) { // create array of dimensions - (num_choices * 6) //to cover length & height DPRINTF( "CUPSfuncs::option->num_choices %d\n", option->num_choices) sizeArray = (*env)->NewFloatArray(env, option->num_choices*6); if (sizeArray == NULL) { unlink(filename); ppdClose(ppd); DPRINTF("CUPSfuncs::bad alloc new float array\n", "") JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); return NULL; } dims = (*env)->GetFloatArrayElements(env, sizeArray, NULL); for (i = 0; i<option->num_choices; i++) {