Any input on these issues?
The following code details my implementation of the solution.
// Get the count of names.
ATSUCountFontNames(fontID,&the_FontNameCount);
//! iterate till you fetch the right name.
for ( k=0;k<the_FontNameCount;k++)
{
err=ATSUGetIndFontName(fontID,k,1024,fontName,&len,&(fontNameCode),&
(fontNam
ePlatform),&(fontNameScript),&(fontNameLanguage));
if(err==0 && fontNameLanguage ==kFontKoreanLanguage &&
fontNameCode==kFontFamilyName)
{
//! Convert text to Unicode
TextToUnicodeInfo unicodeInfo;
UnicodeMapping unicodemap;
TextEncoding teforUnicode;
OSStatus ugerr=0,uinfoerr=0,converr=0;
ByteCount
bufferCount=2048,oeuLength=0,oeuRead=0;
UniChar unicodeString[2048]={0,};
CFStringRef localizedName;
//! 1. create text encoding to convert text
ugerr=UpgradeScriptInfoToTextEncoding
(fontNameScript,fontNameLanguage,kTextR
egionDontCare,NULL,&teforUnicode);
//! Create mapping
unicodemap.unicodeEncoding=CreateTextEncoding
(kTextEncodingUnicodeV3_0,kText
EncodingDefaultVariant,kUnicode16BitFormat);
unicodemap.otherEncoding=GetTextEncodingBase
(teforUnicode);
unicodemap.mappingVersion=kUnicodeUseLatestMapping;
//! use mapping to create info
uinfoerr=CreateTextToUnicodeInfo
(&unicodemap,&unicodeInfo);
//! convert text
converr=ConvertFromTextToUnicode(unicodeInfo,len,fontName,
0,0,NULL,NULL,NULL
,&bufferCount,&oeuRead,&oeuLength,unicodeString);
if(converr==0)
{
localizedName
=CFStringCreateWithCharacters(NULL,unicodeString,
oeuLength/sizeof(UniChar));
break;
}
}
Thanks & Regards,
Rahul.
I am developing an application that supports East-Asian
languages.
There is a requirement that the font names should be displayed in
the
language of the current locale . That is if the system is currently
running
using the Korean locale , the names of fonts should be displayed in
Korean.
I have tried the following method .
ATSUFindFontName(fontID, kFontFamilyName,
kFontNoPlatformCode,kFontKoreanScript, kFontKoreanLanguage,1024,
localizedfontName, &length, &fontNameIndex);
CFStringCreateWithBytes(NULL,(UInt8 *) localizedfontName,
length,kCFStringEncodingUnicode,false)
Is this the right method to procure the localized name of the font?
If not
what would be the prescribed method?
(a) Try a series of ATSUFindFontName calls, starting with the
platform/script/language codes that most closely match the locale you
want, and falling back to other options if the name is not found.
Take the first one that actually returns a result; and then if the
platform was Unicode, you can use kCFStringEncodingUnicode in the
CFStringCreateWithBytes call, but if it was a Mac OS encoding, you'll
need to create an appropriate TextEncoding (same as CFStringEncoding)
value to pass. You can use ATSUGetIndFontName with the fontNameIndex
from FindFont in order to retrieve the actual script and language
codes to use in making the TextEncoding, if you didn't find a name
with your preferred language and had to resort to kFontNoLanguage to
get a result.
(b) Alternatively, instead of calling ATSUFindFontName with various
parameters until it returns a name you can use, try iterating over
all the font names with ATSUGetIndFontName. Convert the non-Unicode
ones to Unicode (using TextEncoding values based on the platform/
script/language from ATSUGetIndFontName). Skip those that don't match
the name ID you want (kFontFamilyName, in this case). Of those that
do match, compare their language/script with the preferred locale to
choose the best match.
It's all a bit of a pain, to be honest. File a bug requesting
"ATSGetFontNameForCurrentLocale" or similar!
-------------------------------------------------------
Robosoft Technologies - Partners in Product Development