Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Private Attributes | Static Private Attributes
nsUnicodeMappingUtil Class Reference

#include <nsUnicodeMappingUtil.h>

Collaboration diagram for nsUnicodeMappingUtil:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsUnicodeMappingUtil ()
 ~nsUnicodeMappingUtil ()
void Init ()
void CleanUp ()
void Reset ()
ScriptCode BlockToScript (nsUnicodeBlock blockID)
short ScriptFont (ScriptCode script)
nsGenericFontNameType MapGenericFontNameType (const nsString &aGenericName)
nsStringGenericFontNameForScript (ScriptCode aScript, nsGenericFontNameType aType) const
ScriptCode MapLangGroupToScriptCode (const char *aLangGroup)

Static Public Member Functions

static nsUnicodeMappingUtilGetSingleton ()
static void FreeSingleton ()

Public Attributes

nsStringmGenericFontMapping [smPseudoTotalScripts][kUknownGenericFontName]

Protected Member Functions

void InitGenericFontMapping ()
void InitBlockToScriptMapping ()
void InitScriptFontMapping ()
void InitFromPref ()

Static Protected Member Functions

static int PR_CALLBACK_DECL PrefChangedCallback (const char *aPrefName, void *instance_data)
static void PR_CALLBACK_DECL PrefEnumCallback (const char *aName, void *aClosure)

Private Attributes

short mScriptFontMapping [smPseudoTotalScripts]
PRInt8 mBlockToScriptMapping [kUnicodeBlockSize]
nsCOMPtr< nsIPrefmPref

Static Private Attributes

static nsUnicodeMappingUtilgSingleton = nsnull

Detailed Description

Definition at line 59 of file nsUnicodeMappingUtil.h.


Constructor & Destructor Documentation

Definition at line 68 of file nsUnicodeMappingUtil.cpp.

{
       Init();
       MOZ_COUNT_CTOR(nsUnicodeMappingUtil);
#ifdef DEBUG
       ++gUnicodeMappingUtilCount;
       NS_ASSERTION(gUnicodeMappingUtilCount == 1, "not singleton");
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 100 of file nsUnicodeMappingUtil.cpp.

{
       CleanUp();

#ifdef DEBUG
       --gUnicodeMappingUtilCount;
#endif
       mPref->UnregisterCallback("font.name.", nsUnicodeMappingUtil::PrefChangedCallback, (void*) nsnull);
       MOZ_COUNT_DTOR(nsUnicodeMappingUtil);
}

Here is the call graph for this function:


Member Function Documentation

ScriptCode nsUnicodeMappingUtil::BlockToScript ( nsUnicodeBlock  blockID) [inline]

Definition at line 66 of file nsUnicodeMappingUtil.h.

              { 
                     NS_PRECONDITION(blockID < kUnicodeBlockSize, "illegal value");
                     return (ScriptCode) mBlockToScriptMapping[blockID]; 
              };

Here is the caller graph for this function:

Definition at line 89 of file nsUnicodeMappingUtil.cpp.

{
       for(int i= 0 ; i < smPseudoTotalScripts; i ++) {
              for(int j=0; j < 5; j++) {
                     if(mGenericFontMapping[i][j])
                      delete mGenericFontMapping[i][j];
              }
       }
}

Here is the caller graph for this function:

Definition at line 490 of file nsUnicodeMappingUtil.cpp.

{
    delete gSingleton;
    gSingleton = nsnull;
}

Here is the caller graph for this function:

nsString* nsUnicodeMappingUtil::GenericFontNameForScript ( ScriptCode  aScript,
nsGenericFontNameType  aType 
) const [inline]

Definition at line 77 of file nsUnicodeMappingUtil.h.

       {
                     NS_PRECONDITION(aScript < smPseudoTotalScripts, "bad script code");
                     NS_PRECONDITION(aType <= kUknownGenericFontName, "illegal value");
                     if( aType >= kUknownGenericFontName)
                            return nsnull;
                     else
                            return mGenericFontMapping[aScript][aType]; 
       }

Here is the caller graph for this function:

Definition at line 482 of file nsUnicodeMappingUtil.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 82 of file nsUnicodeMappingUtil.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 434 of file nsUnicodeMappingUtil.cpp.

{
       static ScriptCode prebuildMapping[kUnicodeBlockSize] = 
       {
              // start the fixed section
              smGreek,      smCyrillic,          smArmenian, 
              smHebrew,     smArabic,     smDevanagari, smBengali,    
              smGurmukhi, smGujarati, smOriya,          smTamil,      
              smTelugu,     smKannada,    smMalayalam,  smThai,
              smLao,        smTibetan,    smGeorgian,          smKorean,
              smTradChinese, smEthiopic, smKhmer,
              smPseudoUnicode,  // for Unified Canadian Syllable
              smPseudoUserDef,
              
              // start the variable section
              smRoman,      smRoman,      smJapanese,   smJapanese,          smJapanese,
              smRoman
       };
       for(PRUint32 i= 0; i < kUnicodeBlockSize; i++) 
       {
    mBlockToScriptMapping[i] = prebuildMapping[i];
  }
}

Here is the caller graph for this function:

Definition at line 360 of file nsUnicodeMappingUtil.cpp.

{
  if (!mPref) {
    mPref = do_GetService(kPrefCID);
    if (!mPref)
      return;
    mPref->RegisterCallback("font.name.", nsUnicodeMappingUtil::PrefChangedCallback, (void*) nsnull);
  }
  mPref->EnumerateChildren("font.name.", nsUnicodeMappingUtil::PrefEnumCallback, this);
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 113 of file nsUnicodeMappingUtil.cpp.

{
       for(int i= 0 ; i < smPseudoTotalScripts; i ++)
              for(int j=0; j < 5; j++)
                      mGenericFontMapping[i][j] = nsnull;

       // We probabaly should put the following info into resource ....
       // smRoman
       mGenericFontMapping[smRoman][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Times") );
       mGenericFontMapping[smRoman][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Helvetica") ); // note: MRJ use Geneva for Sans-Serif
       mGenericFontMapping[smRoman][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Courier") );
       mGenericFontMapping[smRoman][kCursive]   = new nsAutoString( NS_LITERAL_STRING("Zapf Chancery") );
       mGenericFontMapping[smRoman][kFantasy]   = new nsAutoString( NS_LITERAL_STRING("New Century Schlbk") );

       // smJapanese
       static PRUnichar jfontname1[] = {
       0x672C, 0x660E, 0x671D, 0x2212, 0xFF2D, 0x0000 //    –{–¾’©|‚l
       };
       static PRUnichar jfontname2[] = {
       0x4E38, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x2212, 0xFF2D, 0x0000 //    ŠÛƒSƒVƒbƒN|‚l
       };
       static PRUnichar jfontname3[] = {
       0x004F, 0x0073, 0x0061, 0x006B, 0x0061, 0x2212, 0x7B49, 0x5E45, 0x0000 //    Osaka|“™•
       };   

       mGenericFontMapping[smJapanese][kSerif]     = new nsAutoString(jfontname1);
       mGenericFontMapping[smJapanese][kSansSerif] = new nsAutoString(jfontname2); 
       mGenericFontMapping[smJapanese][kMonospace] = new nsAutoString(jfontname3);

       // smTradChinese
       mGenericFontMapping[smTradChinese][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Apple LiSung Light") );
       mGenericFontMapping[smTradChinese][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Apple LiGothic Medium") );
       mGenericFontMapping[smTradChinese][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Apple LiGothic Medium") );

       // smKorean
       mGenericFontMapping[smKorean][kSerif]     = new nsAutoString( NS_LITERAL_STRING("AppleMyungjo") );
       mGenericFontMapping[smKorean][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("AppleGothic") );
       mGenericFontMapping[smKorean][kMonospace] = new nsAutoString( NS_LITERAL_STRING("AppleGothic") );

       // smArabic  
       mGenericFontMapping[smArabic][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") );
       mGenericFontMapping[smArabic][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") );
       mGenericFontMapping[smArabic][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Monaco") );

       // smHebrew
       mGenericFontMapping[smHebrew][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") );
       mGenericFontMapping[smHebrew][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Lucida Grande") );
       mGenericFontMapping[smHebrew][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Monaco") );

       // smCyrillic
       mGenericFontMapping[smCyrillic][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Latinski") );
       mGenericFontMapping[smCyrillic][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Pryamoy Prop") );
       mGenericFontMapping[smCyrillic][kMonospace] = new nsAutoString( NS_LITERAL_STRING("APC Courier") );

       // smDevanagari
       mGenericFontMapping[smDevanagari][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Devanagari MT") );
       mGenericFontMapping[smDevanagari][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Devanagari MT") );
       mGenericFontMapping[smDevanagari][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Devanagari MT") );

       // smGurmukhi
       mGenericFontMapping[smGurmukhi][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Gurmukhi MT") );
       mGenericFontMapping[smGurmukhi][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Gurmukhi MT") );
       mGenericFontMapping[smGurmukhi][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Gurmukhi MT") );

       // smGujarati
       mGenericFontMapping[smGujarati][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Gujarati MT") );
       mGenericFontMapping[smGujarati][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Gujarati MT") );
       mGenericFontMapping[smGujarati][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Gujarati MT") );

       // smThai
       mGenericFontMapping[smThai][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Thonburi") );
       mGenericFontMapping[smThai][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Krungthep") );
       mGenericFontMapping[smThai][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Ayuthaya") );

       // smSimpChinese
       mGenericFontMapping[smSimpChinese][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Song") );
       mGenericFontMapping[smSimpChinese][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Hei") );
       mGenericFontMapping[smSimpChinese][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Hei") );

       // smCentralEuroRoman
       mGenericFontMapping[smCentralEuroRoman][kSerif]     = new nsAutoString( NS_LITERAL_STRING("Times CE") );
       mGenericFontMapping[smCentralEuroRoman][kSansSerif] = new nsAutoString( NS_LITERAL_STRING("Helvetica CE") );
       mGenericFontMapping[smCentralEuroRoman][kMonospace] = new nsAutoString( NS_LITERAL_STRING("Courier CE") );
}

Here is the caller graph for this function:

Definition at line 373 of file nsUnicodeMappingUtil.cpp.

{
       // Get font from Script manager
       for(ScriptCode script = 0; script< smPseudoTotalScripts ; script++)
       {
              mScriptFontMapping[script] = BAD_FONT_NUM;                     
              short fontNum;
              if ((smPseudoUnicode == script) || (smPseudoUserDef == script))
              {
                     char   *theNeededPreference;

                     if (smPseudoUnicode == script)
                            theNeededPreference = "font.name.serif.x-unicode";
                     else
                            theNeededPreference = "font.name.serif.x-user-def";

                     char   *valueInUTF8 = nsnull;

                     mPref->CopyCharPref (theNeededPreference,&valueInUTF8);

                     if (valueInUTF8)
                     {
                            if (!*valueInUTF8)
                                   Recycle (valueInUTF8);
                            else
                            {
                                   PRUnichar     valueInUCS2[FACESIZE]= { 0 };
                                   PRUnichar     format[] = { '%', 's', 0 };
                                   PRUint32      n = nsTextFormatter::snprintf(valueInUCS2, FACESIZE, format, valueInUTF8);

                                   Recycle (valueInUTF8);
                                   if (n != 0)
                                   {
                                          nsString      *fontname = new nsAutoString (valueInUCS2);

                                          if (nsnull != fontname)
                                          {
                                                 short  fontID = 0;

                                                 if (nsDeviceContextMac::GetMacFontNumber (*fontname,fontID))
                                                        mScriptFontMapping[script] = fontID;

                                                 delete fontname;
                                          }
                                   }
                            }
                     }
              }
              else {
                     long fondsize = ::GetScriptVariable(script, smScriptPrefFondSize);
                     if (!fondsize)
                       fondsize = ::GetScriptVariable(smUnicodeScript, smScriptPrefFondSize);

                     if((fondsize) && ((fondsize >> 16))) {
                            fontNum = (fondsize >> 16);
                            mScriptFontMapping[script] = fontNum;
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 459 of file nsUnicodeMappingUtil.cpp.

{
       if (aGenericName.LowerCaseEqualsLiteral("serif"))
         return kSerif;
       if (aGenericName.LowerCaseEqualsLiteral("sans-serif"))
         return kSansSerif;
       if (aGenericName.LowerCaseEqualsLiteral("monospace"))
         return kMonospace;
       if (aGenericName.LowerCaseEqualsLiteral("-moz-fixed"))
         return kMonospace;
       if (aGenericName.LowerCaseEqualsLiteral("cursive"))
         return kCursive;
       if (aGenericName.LowerCaseEqualsLiteral("fantasy"))
         return kFantasy;
         
       return kUknownGenericFontName;                   
}

Here is the caller graph for this function:

ScriptCode nsUnicodeMappingUtil::MapLangGroupToScriptCode ( const char *  aLangGroup)

Definition at line 205 of file nsUnicodeMappingUtil.cpp.

{
       if(0==nsCRT::strcmp(aLangGroup,  "x-western")) {
              return smRoman;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-central-euro")) {
              return smCentralEuroRoman;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-cyrillic")) {
              return smCyrillic;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "el")) {
              return smGreek;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "tr")) {
              return smRoman;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "he")) {
              return smHebrew;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "ar")) {
              return smArabic;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-baltic")) {
              return smRoman;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "th")) {
              return smThai;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "ja")) {
              return smJapanese;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "zh-CN")) {
              return smSimpChinese;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "ko")) {
              return smKorean;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "zh-TW")) {
              return smTradChinese;
       }
    // No separate script code for zh-HK. Use smTradChinese.
       if(0==nsCRT::strcmp(aLangGroup,  "zh-HK")) {
              return smTradChinese;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-devanag")) {
              return smDevanagari;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-tamil")) {
              return smTamil;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-beng")) {
              return smBengali;;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-armn")) {
              return smArmenian;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-geor")) {
              return smGeorgian;;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-gujr")) {
              return smGujarati;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-guru")) {
              return smGurmukhi;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-mlym")) {
              return smMalayalam;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-khmr")) {
              return smKhmer;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-ethi")) {
              return smEthiopic;
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-cans")) {
              return (smPseudoUnicode);  // XXX : no script code for UCA
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-unicode")) {
              return (smPseudoUnicode);
       }
       if(0==nsCRT::strcmp(aLangGroup,  "x-user-def")) {
              return (smPseudoUserDef);
       }
       {
              return smRoman;
       }
}

Here is the caller graph for this function:

int PR_CALLBACK nsUnicodeMappingUtil::PrefChangedCallback ( const char *  aPrefName,
void instance_data 
) [static, protected]

Definition at line 59 of file nsUnicodeMappingUtil.cpp.

{
       //printf("PrefChangeCallback \n");
       nsUnicodeMappingUtil::GetSingleton()->Reset();
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PR_CALLBACK nsUnicodeMappingUtil::PrefEnumCallback ( const char *  aName,
void aClosure 
) [static, protected]

Definition at line 296 of file nsUnicodeMappingUtil.cpp.

{      
  nsUnicodeMappingUtil* Self = (nsUnicodeMappingUtil*)aClosure;
  nsCAutoString curPrefName(aName);
  
  PRInt32 p1 = curPrefName.RFindChar('.');
  if(-1==p1)
       return;
  PRInt32 p2 = curPrefName.RFindChar('.', p1-1);
  if(-1==p1)
       return;
  
  nsCAutoString genName("");
  nsCAutoString langGroup("");
  
  curPrefName.Mid(langGroup,  p1+1, curPrefName.Length()-p1-1);
  curPrefName.Mid(genName, p2+1, p1-p2-1);
  
  ScriptCode script = Self->MapLangGroupToScriptCode(langGroup.get());
  if(script >= (smPseudoTotalScripts))
  {
       // Because of the pseudo-scripts of Unicode and User-Defined, we have to handle
       // the expanded ScriptCode value.
       return;
  }
  if((script == smRoman) && !langGroup.Equals(nsCAutoString("x-western"))) {
       // need special processing for t,r x-baltic, x-usr-defined
       return;
  }
  
  nsString genNameString;
  genNameString.AssignWithConversion(genName);
  nsGenericFontNameType type = Self->MapGenericFontNameType(genNameString);
  if(type >= kUknownGenericFontName)
       return;
       
  char* valueInUTF8 = nsnull;
  Self->mPref->CopyCharPref(aName, &valueInUTF8);
  if(!valueInUTF8)
    return;
  if(!*valueInUTF8)
  {
    Recycle(valueInUTF8);
    return;
  }
  PRUnichar valueInUCS2[FACESIZE]= { 0 };
  PRUnichar format[] = { '%', 's', 0 };
  PRUint32 n = nsTextFormatter::snprintf(valueInUCS2, FACESIZE, format, valueInUTF8);
  Recycle(valueInUTF8);
  if(n == 0)
       return;     
  nsString *fontname = new nsAutoString(valueInUCS2);
  if(nsnull == fontname)
       return;
  if( Self->mGenericFontMapping[script][type] )
       delete Self->mGenericFontMapping[script][type];
  Self->mGenericFontMapping[script][type] = fontname;
#ifdef DEBUG_ftang_font
  char* utf8 = ToNewUTF8String(*fontname);
  printf("font %d %d %s= %s\n",script , type, aName,utf8);
  if (utf8)
    Recycle(utf8); 
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 77 of file nsUnicodeMappingUtil.cpp.

{
       CleanUp();
       Init();
}

Here is the call graph for this function:

Here is the caller graph for this function:

short nsUnicodeMappingUtil::ScriptFont ( ScriptCode  script) [inline]

Definition at line 71 of file nsUnicodeMappingUtil.h.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 106 of file nsUnicodeMappingUtil.h.

Definition at line 103 of file nsUnicodeMappingUtil.h.

Definition at line 90 of file nsUnicodeMappingUtil.h.

Definition at line 104 of file nsUnicodeMappingUtil.h.

Definition at line 102 of file nsUnicodeMappingUtil.h.


The documentation for this class was generated from the following files: