// Obtain a wide representation of the MLU, on depending on current locale settings cmsUInt32Number CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu, const char LanguageCode[3], const char CountryCode[3], wchar_t* Buffer, cmsUInt32Number BufferSize) { const wchar_t *Wide; cmsUInt32Number StrLen = 0; cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode); cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode); // Sanitize if (mlu == NULL) return 0; Wide = _cmsMLUgetWide(mlu, &StrLen, Lang, Cntry, NULL, NULL); if (Wide == NULL) return 0; // Maybe we want only to know the len? if (Buffer == NULL) return StrLen + sizeof(wchar_t); // No buffer size means no data if (BufferSize <= 0) return 0; // Some clipping may be required if (BufferSize < StrLen + sizeof(wchar_t)) StrLen = BufferSize - + sizeof(wchar_t); memmove(Buffer, Wide, StrLen); Buffer[StrLen / sizeof(wchar_t)] = 0; return StrLen + sizeof(wchar_t); }
// Obtain an ASCII representation of the wide string. Setting buffer to NULL returns the len cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu, const char LanguageCode[3], const char CountryCode[3], char* Buffer, cmsUInt32Number BufferSize) { const wchar_t *Wide; cmsUInt32Number StrLen = 0; cmsUInt32Number ASCIIlen, i; cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode); cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode); // Sanitize if (mlu == NULL) return 0; // Get WideChar Wide = _cmsMLUgetWide(mlu, &StrLen, Lang, Cntry, NULL, NULL); if (Wide == NULL) return 0; ASCIIlen = StrLen / sizeof(wchar_t); // Maybe we want only to know the len? if (Buffer == NULL) return ASCIIlen + 1; // Note the zero at the end // No buffer size means no data if (BufferSize <= 0) return 0; // Some clipping may be required if (BufferSize < ASCIIlen + 1) ASCIIlen = BufferSize - 1; // Precess each character for (i=0; i < ASCIIlen; i++) { if (Wide[i] == 0) Buffer[i] = 0; else Buffer[i] = (char) Wide[i]; } // We put a termination "\0" Buffer[ASCIIlen] = 0; return ASCIIlen + 1; }
// Get also the language and country CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu, const char LanguageCode[3], const char CountryCode[3], char ObtainedLanguage[3], char ObtainedCountry[3]) { const wchar_t *Wide; cmsUInt16Number Lang = strTo16(LanguageCode); cmsUInt16Number Cntry = strTo16(CountryCode); cmsUInt16Number ObtLang, ObtCode; // Sanitize if (mlu == NULL) return FALSE; Wide = _cmsMLUgetWide(mlu, NULL, Lang, Cntry, &ObtLang, &ObtCode); if (Wide == NULL) return FALSE; // Get used language and code strFrom16(ObtainedLanguage, ObtLang); strFrom16(ObtainedCountry, ObtCode); return TRUE; }
// Get also the language and country CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu, const char LanguageCode[3], const char CountryCode[3], char ObtainedLanguage[3], char ObtainedCountry[3]) { const wchar_t *Wide; cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode); cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode); cmsUInt16Number ObtLang, ObtCode; // Sanitize if (mlu == NULL) return FALSE; Wide = _cmsMLUgetWide(mlu, NULL, Lang, Cntry, &ObtLang, &ObtCode); if (Wide == NULL) return FALSE; // Get used language and code *(cmsUInt16Number *)ObtainedLanguage = _cmsAdjustEndianess16(ObtLang); *(cmsUInt16Number *)ObtainedCountry = _cmsAdjustEndianess16(ObtCode); ObtainedLanguage[2] = ObtainedCountry[2] = 0; return TRUE; }