Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Localized font name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Localized font name



On 17 Dec 2005, at 8:11 am, Rahul Shetty wrote:

Hi Jonathan,

Thank you for such a detailed reply.

I have tried out one of your methods ( to be specific , it is choice (b) ).
Again I have tried it for the Korean language.
The result is still the same . I still get the names of fonts in English.
For example lets consider "Apple Gothic". The conversion here returns the
English name.



This is correct; the "Korean" localized name of the font is "AppleGothic"!


You can dump the 'name' table of the font using ftxdumperfuser (from the Apple font tools suite, see http://developer.apple.com/fonts) to see exactly what is there. Here's an excerpt from the 'name' table in AppleGothic.dfont:

<nameTableEntry nameTypeID="1" nameTypeName="Family">
<localizedName platformID="1" platformName="Macintosh" scriptID="0" scriptName="Roman" languageID="0" languageName="English" isRawHex="NO">AppleGothic</localizedName>
<localizedName platformID="1" platformName="Macintosh" scriptID="3" scriptName="Korean" languageID="23" languageName="Korean" isRawHex="NO">AppleGothic</localizedName>
</nameTableEntry>
<nameTableEntry nameTypeID="2" nameTypeName="Style">
<localizedName platformID="1" platformName="Macintosh" scriptID="0" scriptName="Roman" languageID="0" languageName="English" isRawHex="NO">Regular</localizedName>
<localizedName platformID="1" platformName="Macintosh" scriptID="3" scriptName="Korean" languageID="23" languageName="Korean" isRawHex="NO">일반체</localizedName>
</nameTableEntry>


From this, it's clear that the only Family name you'll ever get is "AppleGothic". The family name has not been translated; the string tagged with script ID 3, language ID 23 [Korean] is still "AppleGothic". The style name "Regular", on the other hand, has been translated, so if you were fetching that name, you should see Korean characters.

Another observation is that for some of the fonts, it returns an error
stating that the output buffer is full. Though the length is considerably
smaller than 2048 ( that I have allocated by default) , I still get the
error.

You mean you get a buffer full error from ATSUGetIndFontName? I don't know why this is. Can you give a specific example of a font and name ID where this happens?


Jonathan


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



_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: Localized font name (From: Rahul Shetty <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.