ppd_attr_t * /* O - Localized attribute or @code NULL@ if none exists */ ppdLocalizeAttr(ppd_file_t *ppd, /* I - PPD file */ const char *keyword, /* I - Main keyword */ const char *spec) /* I - Option keyword or @code NULL@ for none */ { ppd_attr_t *locattr; /* Localized attribute */ char ll_CC[6]; /* Language + country locale */ /* * Get the default language... */ ppd_ll_CC(ll_CC, sizeof(ll_CC)); /* * Find the localized attribute... */ if (spec) locattr = _ppdLocalizedAttr(ppd, keyword, spec, ll_CC); else locattr = _ppdLocalizedAttr(ppd, "Translation", keyword, ll_CC); if (!locattr) locattr = ppdFindAttr(ppd, keyword, spec); return (locattr); }
const char * /* O - Value or @code NULL@ if not found */ ppdLocalizeMarkerName( ppd_file_t *ppd, /* I - PPD file */ const char *name) /* I - Marker name to look up */ { ppd_attr_t *locattr; /* Localized attribute */ char ll_CC[6]; /* Language + country locale */ /* * Range check input... */ if (!ppd || !name) return (NULL); /* * Get the default language... */ ppd_ll_CC(ll_CC, sizeof(ll_CC)); /* * Find the localized attribute... */ if ((locattr = _ppdLocalizedAttr(ppd, "cupsMarkerName", name, ll_CC)) == NULL) locattr = ppdFindAttr(ppd, "cupsMarkerName", name); return (locattr ? locattr->text : NULL); }
int /* O - 0 on success, -1 on error */ ppdLocalize(ppd_file_t *ppd) /* I - PPD file */ { int i, j, k; /* Looping vars */ ppd_group_t *group; /* Current group */ ppd_option_t *option; /* Current option */ ppd_choice_t *choice; /* Current choice */ ppd_coption_t *coption; /* Current custom option */ ppd_cparam_t *cparam; /* Current custom parameter */ ppd_attr_t *attr, /* Current attribute */ *locattr; /* Localized attribute */ char ckeyword[PPD_MAX_NAME], /* Custom keyword */ ll_CC[6]; /* Language + country locale */ /* * Range check input... */ DEBUG_printf(("ppdLocalize(ppd=%p)", ppd)); if (!ppd) return (-1); /* * Get the default language... */ ppd_ll_CC(ll_CC, sizeof(ll_CC)); /* * Now lookup all of the groups, options, choices, etc. */ for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++) { if ((locattr = _ppdLocalizedAttr(ppd, "Translation", group->name, ll_CC)) != NULL) strlcpy(group->text, locattr->text, sizeof(group->text)); for (j = group->num_options, option = group->options; j > 0; j --, option ++) { if ((locattr = _ppdLocalizedAttr(ppd, "Translation", option->keyword, ll_CC)) != NULL) strlcpy(option->text, locattr->text, sizeof(option->text)); for (k = option->num_choices, choice = option->choices; k > 0; k --, choice ++) { if (strcmp(choice->choice, "Custom") || !ppdFindCustomOption(ppd, option->keyword)) locattr = _ppdLocalizedAttr(ppd, option->keyword, choice->choice, ll_CC); else { snprintf(ckeyword, sizeof(ckeyword), "Custom%s", option->keyword); locattr = _ppdLocalizedAttr(ppd, ckeyword, "True", ll_CC); } if (locattr) strlcpy(choice->text, locattr->text, sizeof(choice->text)); } } } /* * Translate any custom parameters... */ for (coption = (ppd_coption_t *)cupsArrayFirst(ppd->coptions); coption; coption = (ppd_coption_t *)cupsArrayNext(ppd->coptions)) { for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params); cparam; cparam = (ppd_cparam_t *)cupsArrayNext(coption->params)) { snprintf(ckeyword, sizeof(ckeyword), "ParamCustom%s", coption->keyword); if ((locattr = _ppdLocalizedAttr(ppd, ckeyword, cparam->name, ll_CC)) != NULL) strlcpy(cparam->text, locattr->text, sizeof(cparam->text)); } } /* * Translate ICC profile names... */ if ((attr = ppdFindAttr(ppd, "APCustomColorMatchingName", NULL)) != NULL) { if ((locattr = _ppdLocalizedAttr(ppd, "APCustomColorMatchingName", attr->spec, ll_CC)) != NULL) strlcpy(attr->text, locattr->text, sizeof(attr->text)); } for (attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); attr; attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL)) { cupsArraySave(ppd->sorted_attrs); if ((locattr = _ppdLocalizedAttr(ppd, "cupsICCProfile", attr->spec, ll_CC)) != NULL) strlcpy(attr->text, locattr->text, sizeof(attr->text)); cupsArrayRestore(ppd->sorted_attrs); } /* * Translate printer presets... */ for (attr = ppdFindAttr(ppd, "APPrinterPreset", NULL); attr; attr = ppdFindNextAttr(ppd, "APPrinterPreset", NULL)) { cupsArraySave(ppd->sorted_attrs); if ((locattr = _ppdLocalizedAttr(ppd, "APPrinterPreset", attr->spec, ll_CC)) != NULL) strlcpy(attr->text, locattr->text, sizeof(attr->text)); cupsArrayRestore(ppd->sorted_attrs); } return (0); }
const char * /* O - Value or NULL if not found */ ppdLocalizeIPPReason( ppd_file_t *ppd, /* I - PPD file */ const char *reason, /* I - IPP reason keyword to look up */ const char *scheme, /* I - URI scheme or NULL for text */ char *buffer, /* I - Value buffer */ size_t bufsize) /* I - Size of value buffer */ { cups_lang_t *lang; /* Current language */ ppd_attr_t *locattr; /* Localized attribute */ char ll_CC[6], /* Language + country locale */ *bufptr, /* Pointer into buffer */ *bufend, /* Pointer to end of buffer */ *valptr; /* Pointer into value */ int ch; /* Hex-encoded character */ size_t schemelen; /* Length of scheme name */ /* * Range check input... */ if (buffer) *buffer = '\0'; if (!ppd || !reason || (scheme && !*scheme) || !buffer || bufsize < PPD_MAX_TEXT) return (NULL); /* * Get the default language... */ lang = ppd_ll_CC(ll_CC, sizeof(ll_CC)); /* * Find the localized attribute... */ if ((locattr = _ppdLocalizedAttr(ppd, "cupsIPPReason", reason, ll_CC)) == NULL) locattr = ppdFindAttr(ppd, "cupsIPPReason", reason); if (!locattr) { if (lang && (!scheme || !strcmp(scheme, "text"))) { /* * Try to localize a standard printer-state-reason keyword... */ const char *message = NULL; /* Localized message */ if (!strncmp(reason, "media-needed", 12)) message = _("Load paper."); else if (!strncmp(reason, "media-jam", 9)) message = _("Paper jam."); else if (!strncmp(reason, "offline", 7) || !strncmp(reason, "shutdown", 8)) message = _("The printer is not connected."); else if (!strncmp(reason, "toner-low", 9)) message = _("The printer is low on toner."); else if (!strncmp(reason, "toner-empty", 11)) message = _("The printer may be out of toner."); else if (!strncmp(reason, "cover-open", 10)) message = _("The printer's cover is open."); else if (!strncmp(reason, "interlock-open", 14)) message = _("The printer's interlock is open."); else if (!strncmp(reason, "door-open", 9)) message = _("The printer's door is open."); else if (!strncmp(reason, "input-tray-missing", 18)) message = _("Paper tray is missing."); else if (!strncmp(reason, "media-low", 9)) message = _("Paper tray is almost empty."); else if (!strncmp(reason, "media-empty", 11)) message = _("Paper tray is empty."); else if (!strncmp(reason, "output-tray-missing", 19)) message = _("Output bin is missing."); else if (!strncmp(reason, "output-area-almost-full", 23)) message = _("Output bin is almost full."); else if (!strncmp(reason, "output-area-full", 16)) message = _("Output bin is full."); else if (!strncmp(reason, "marker-supply-low", 17)) message = _("The printer is low on ink."); else if (!strncmp(reason, "marker-supply-empty", 19)) message = _("The printer may be out of ink."); else if (!strncmp(reason, "marker-waste-almost-full", 24)) message = _("The printer's waste bin is almost full."); else if (!strncmp(reason, "marker-waste-full", 17)) message = _("The printer's waste bin is full."); else if (!strncmp(reason, "fuser-over-temp", 15)) message = _("The fuser's temperature is high."); else if (!strncmp(reason, "fuser-under-temp", 16)) message = _("The fuser's temperature is low."); else if (!strncmp(reason, "opc-near-eol", 12)) message = _("The optical photoconductor will need to be replaced soon."); else if (!strncmp(reason, "opc-life-over", 13)) message = _("The optical photoconductor needs to be replaced."); else if (!strncmp(reason, "developer-low", 13)) message = _("The developer unit will need to be replaced soon."); else if (!strncmp(reason, "developer-empty", 15)) message = _("The developer unit needs to be replaced."); if (message) { strlcpy(buffer, _cupsLangString(lang, message), bufsize); return (buffer); } } return (NULL); } /* * Now find the value we need... */ bufend = buffer + bufsize - 1; if (!scheme || !strcmp(scheme, "text")) { /* * Copy a text value (either the translation text or text:... URIs from * the value... */ strlcpy(buffer, locattr->text, bufsize); for (valptr = locattr->value, bufptr = buffer; *valptr && bufptr < bufend;) { if (!strncmp(valptr, "text:", 5)) { /* * Decode text: URI and add to the buffer... */ valptr += 5; while (*valptr && !_cups_isspace(*valptr) && bufptr < bufend) { if (*valptr == '%' && isxdigit(valptr[1] & 255) && isxdigit(valptr[2] & 255)) { /* * Pull a hex-encoded character from the URI... */ valptr ++; if (isdigit(*valptr & 255)) ch = (*valptr - '0') << 4; else ch = (tolower(*valptr) - 'a' + 10) << 4; valptr ++; if (isdigit(*valptr & 255)) *bufptr++ = (char)(ch | (*valptr - '0')); else *bufptr++ = (char)(ch | (tolower(*valptr) - 'a' + 10)); valptr ++; } else if (*valptr == '+') { *bufptr++ = ' '; valptr ++; } else *bufptr++ = *valptr++; } } else { /* * Skip this URI... */ while (*valptr && !_cups_isspace(*valptr)) valptr++; } /* * Skip whitespace... */ while (_cups_isspace(*valptr)) valptr ++; } if (bufptr > buffer) *bufptr = '\0'; return (buffer); } else { /* * Copy a URI... */ schemelen = strlen(scheme); if (scheme[schemelen - 1] == ':') /* Force scheme to be just the name */ schemelen --; for (valptr = locattr->value, bufptr = buffer; *valptr && bufptr < bufend;) { if ((!strncmp(valptr, scheme, schemelen) && valptr[schemelen] == ':') || (*valptr == '/' && !strcmp(scheme, "file"))) { /* * Copy URI... */ while (*valptr && !_cups_isspace(*valptr) && bufptr < bufend) *bufptr++ = *valptr++; *bufptr = '\0'; return (buffer); } else { /* * Skip this URI... */ while (*valptr && !_cups_isspace(*valptr)) valptr++; } /* * Skip whitespace... */ while (_cups_isspace(*valptr)) valptr ++; } return (NULL); } }
static void apple_init_profile( ppd_file_t *ppd, /* I - PPD file */ cups_array_t *languages, /* I - Languages in the PPD file */ CFMutableDictionaryRef profile, /* I - Profile dictionary */ unsigned id, /* I - Profile ID */ const char *name, /* I - Profile name */ const char *text, /* I - Profile UI text */ const char *iccfile) /* I - ICC filename */ { CFURLRef url; /* URL for profile filename */ CFMutableDictionaryRef dict; /* Dictionary for name */ char *language; /* Current language */ ppd_attr_t *attr; /* Profile attribute */ CFStringRef cflang, /* Language string */ cftext; /* Localized text */ (void)id; /* * Build the profile name dictionary... */ dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!dict) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to initialize profile \"%s\".", iccfile); return; } cftext = CFStringCreateWithCString(kCFAllocatorDefault, text, kCFStringEncodingUTF8); if (cftext) { CFDictionarySetValue(dict, CFSTR("en_US"), cftext); CFRelease(cftext); } if (languages) { /* * Find localized names for the color profiles... */ cupsArraySave(ppd->sorted_attrs); for (language = (char *)cupsArrayFirst(languages); language; language = (char *)cupsArrayNext(languages)) { if (iccfile) { if ((attr = _ppdLocalizedAttr(ppd, "cupsICCProfile", name, language)) == NULL) attr = _ppdLocalizedAttr(ppd, "APTiogaProfile", name, language); } else attr = _ppdLocalizedAttr(ppd, "ColorModel", name, language); if (attr && attr->text[0]) { cflang = CFStringCreateWithCString(kCFAllocatorDefault, language, kCFStringEncodingUTF8); cftext = CFStringCreateWithCString(kCFAllocatorDefault, attr->text, kCFStringEncodingUTF8); if (cflang && cftext) CFDictionarySetValue(dict, cflang, cftext); if (cflang) CFRelease(cflang); if (cftext) CFRelease(cftext); } } cupsArrayRestore(ppd->sorted_attrs); } /* * Fill in the profile data... */ if (iccfile && *iccfile) { url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)iccfile, (CFIndex)strlen(iccfile), false); if (url) { CFDictionarySetValue(profile, kColorSyncDeviceProfileURL, url); CFRelease(url); } } CFDictionarySetValue(profile, kColorSyncDeviceModeDescriptions, dict); CFRelease(dict); }