Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
nsFontMetricsBeOS.cpp File Reference
#include "nsQuickSort.h"
#include "nsFontMetricsBeOS.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsISaveAsCharset.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsCOMPtr.h"
#include "nspr.h"
#include "nsReadableUtils.h"
#include <UnicodeBlockObjects.h>

Go to the source code of this file.

Classes

struct  nsFontEnumParamsBeOS

Defines

#define USER_DEFINED   "x-user-def"

Typedefs

typedef struct nsFontEnumParamsBeOS NS_FONT_ENUM_PARAMS_BEOS

Functions

static PRBool FontEnumCallback (const nsString &aFamily, PRBool aGeneric, void *aData)
uint32 utf8_char_len (uchar byte)
PRUint32 utf8_to_index (char *utf8char)
static int CompareFontNames (const void *aArg1, const void *aArg2, void *aClosure)
static int FontMatchesGenericType (font_family family, uint32 flags, const char *aGeneric, const char *aLangGroup)
static int MatchesLangGroup (font_family family, const char *aLangGroup)
static nsresult EnumFonts (const char *aLangGroup, const char *aGeneric, PRUint32 *aCount, PRUnichar ***aResult)

Class Documentation

struct nsFontEnumParamsBeOS

Definition at line 80 of file nsFontMetricsBeOS.cpp.

Collaboration diagram for nsFontEnumParamsBeOS:
Class Members
nsStringArray family
nsVoidArray isgeneric
nsFontMetricsBeOS * metrics

Define Documentation

#define USER_DEFINED   "x-user-def"

Definition at line 58 of file nsFontMetricsBeOS.cpp.


Typedef Documentation


Function Documentation

static int CompareFontNames ( const void aArg1,
const void aArg2,
void aClosure 
) [static]

Definition at line 477 of file nsFontMetricsBeOS.cpp.

{ 
  const PRUnichar* str1 = *((const PRUnichar**) aArg1); 
  const PRUnichar* str2 = *((const PRUnichar**) aArg2); 
 
  // XXX add nsICollation stuff 
 
  return nsCRT::strcmp(str1, str2); 
} 

Here is the caller graph for this function:

static nsresult EnumFonts ( const char *  aLangGroup,
const char *  aGeneric,
PRUint32 aCount,
PRUnichar ***  aResult 
) [static]

Definition at line 602 of file nsFontMetricsBeOS.cpp.

{ 
  int32 numFamilies = count_font_families(); 
 
  PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numFamilies * sizeof(PRUnichar*)); 
  NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);

  int j = 0;
  for(int32 i = 0; i < numFamilies; i++) 
  {
    font_family family; 
    uint32 flags; 
    if (get_font_family(i, &family, &flags) == B_OK) 
    {
      if (family && (!aLangGroup || MatchesLangGroup(family,  aLangGroup)))
      {
        if(FontMatchesGenericType(family, flags, aGeneric, aLangGroup))
        {
          if (!(array[j] = UTF8ToNewUnicode(nsDependentCString(family))))
            break; 
          ++j;
        }
      }
    }
  } 
  *aCount = j; 

  if (*aCount)
  {
    *aResult = array; 
    // Resizing array for real number of matching families after check for language and generic type
    if (*aCount < numFamilies)
    {
      array = (PRUnichar**) nsMemory::Realloc(array, *aCount * sizeof(PRUnichar*));
      NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
    }
    NS_QuickSort(array, j, sizeof(PRUnichar*), CompareFontNames, nsnull);
  }
  else 
  {
    nsMemory::Free(array); 
  }

  return NS_OK; 
} 

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool FontEnumCallback ( const nsString aFamily,
PRBool  aGeneric,
void aData 
) [static]

Definition at line 87 of file nsFontMetricsBeOS.cpp.

{
  NS_FONT_ENUM_PARAMS_BEOS *param = (NS_FONT_ENUM_PARAMS_BEOS *) aData;
  param->family.AppendString(aFamily);
  param->isgeneric.AppendElement((void*) aGeneric);
  if (aGeneric)
    return PR_FALSE;

  return PR_TRUE;
}

Here is the caller graph for this function:

static int FontMatchesGenericType ( font_family  family,
uint32  flags,
const char *  aGeneric,
const char *  aLangGroup 
) [static]

Definition at line 488 of file nsFontMetricsBeOS.cpp.

{
  //Call from EnumerateAllFonts. Matches all.
  //Return 1 immediately, because nsnull as argument of strstr causes crashes
  if(aGeneric == nsnull || aLangGroup == nsnull)
    return 1;
  if (!strcmp(aLangGroup, "ja"))    
    return 1;
  if (strstr(aLangGroup, "zh"))
    return 1;
  if (!strcmp(aLangGroup, "ko"))
    return 1;
  if (!strcmp(aLangGroup, "th"))
    return 1;
  if (!strcmp(aLangGroup, "he"))
    return 1;
  if (!strcmp(aLangGroup, "ar"))
    return 1;
  if (strstr(aLangGroup, "user-def"))
    return 1;
  if (!strcmp(aLangGroup, "unicode"))
    return 1;

  if (strstr(aGeneric, "fantasy") 
  // Let's use all possible fonts as decorative
#if 0
    && (strstr(family, "Baskerville") || 
        strstr(family, "Chicago") ||
        strstr(family, "Copprpl") ||
        strstr(family, "Embassy") ||
        strstr(family, "Europe") ||
        strstr(family, "Garmnd") ||
        strstr(family, "Impact") ||
        strstr(family, "ProFont") ||
        strstr(family, "VAGRounded"))
#endif      
    )
    return 1;
  // Hack. Sniffing is based on wide-spread names for serif and sansserif.   No function in BeOS to get full font-info.
  // NB! "Haru Tohaba" and "Haru" need EXACT match - !strcmp seems suspicious in that case, timeless !!!
  if (!strcmp(aGeneric, "serif") && 
     (strstr(family, "Dutch") || strstr(family, "Times") || strstr(family, "Roman") ||
      strstr(family, "CentSchbook") || strstr(family, "Georgia") || strstr(family, "Baskerville") ||
      strstr(family, "Garmnd") || strstr(family, "Cyberbit") || strcmp(family, "Haru Tohaba") == 0))
    return 1;
  if (!strcmp(aGeneric, "sans-serif") && 
     (strstr(family, "Arial") || strstr(family, "Chianti") || strstr(family, "Helv") ||
      strstr(family, "Humnst") || strstr(family, "Swiss") || strstr(family, "Tahoma") ||
      strstr(family, "Sans") || strstr(family, "sans") || strstr(family, "Verdana") || 
      strstr(family, "Zurich") || strcmp(family, "Haru") == 0))
    return 1;
  if ((strstr(aGeneric, "monospace") || strstr(aGeneric, "-moz-fixed")) && 
    (flags & B_IS_FIXED || strstr(family, "Cour") || strstr(family, "Consol") ||
     strstr(family, "Fixed") || strstr(family, "Kurier") || strstr(family, "Lucida") ||
     strstr(family, "Mono") || strstr(family, "console") || strstr(family, "mono") ||
     strstr(family, "fixed")))
    return 1;
  if (strstr(aGeneric, "cursive") && 
    (strstr(family, "Cursiv") || strstr(family, "Kursiv") || strstr(family, "Script") ||
     strstr(family, "kursiv") || strstr(family, "Embassy") || strstr(family, "script") || 
     strstr(family, "Brush")))
    return 1;

  return 0;
}

Here is the caller graph for this function:

static int MatchesLangGroup ( font_family  family,
const char *  aLangGroup 
) [static]

Definition at line 555 of file nsFontMetricsBeOS.cpp.

{
  BFont font;
  font.SetFamilyAndStyle(family, NULL);
  unicode_block lang = font.Blocks();
  int match = 0;

  //No restrictions
  if ((strstr(aLangGroup, "user-def") || strstr(aLangGroup, "unicode")))
    return 1; 
  // "tr" and "central-euro" need more testing, but seems OK
  if ((strstr(aLangGroup, "baltic") || strstr(aLangGroup, "central-euro") || strstr(aLangGroup, "western")) && 
    lang.Includes(B_LATIN1_SUPPLEMENT_BLOCK))
    return 1;
  if (strstr(aLangGroup, "tr") && lang.Includes(B_LATIN_EXTENDED_A_BLOCK))
    return 1;
  if (strstr(aLangGroup, "el") && lang.Includes(B_BASIC_GREEK_BLOCK))
    return 1;
  if (strstr(aLangGroup, "cyrillic") && lang.Includes(B_CYRILLIC_BLOCK))
    return 1;
  if (strstr(aLangGroup, "he") && lang.Includes(B_BASIC_HEBREW_BLOCK))
    return 1;
  if (strstr(aLangGroup, "ar") && lang.Includes(B_BASIC_ARABIC_BLOCK))
    return 1;
  if (strstr(aLangGroup, "th") && lang.Includes(B_THAI_BLOCK))
    return 1;
  // CKJ settings need more verification
  if ((strstr(aLangGroup, "ja") || strstr(aLangGroup, "ko") || strstr(aLangGroup, "zh") ) &&
    (lang.Includes(B_CJK_UNIFIED_IDEOGRAPHS_BLOCK) ||
     lang.Includes(B_CJK_MISCELLANEOUS_BLOCK) ||
     lang.Includes(B_ENCLOSED_CJK_LETTERS_AND_MONTHS_BLOCK) ||
     lang.Includes(B_CJK_COMPATIBILITY_BLOCK) ||
     lang.Includes(B_CJK_COMPATIBILITY_IDEOGRAPHS_BLOCK) ||
     lang.Includes(B_CJK_COMPATIBILITY_FORMS_BLOCK))) 
    match = 1;  
  // additional check for partial CKJ blocks
  if (strstr(aLangGroup, "ja") && (lang.Includes(B_HIRAGANA_BLOCK) || lang.Includes(B_KATAKANA_BLOCK) ))
    match = 1; 
  if (strstr(aLangGroup, "ko") && (lang.Includes(B_HANGUL_BLOCK)))
    match = 1;   
  if (strstr(aLangGroup, "zh") && (lang.Includes(B_HIGH_SURROGATES_BLOCK) || lang.Includes(B_LOW_SURROGATES_BLOCK) ))
    match = 1; 
   

 return match; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

uint32 utf8_char_len ( uchar  byte) [inline]

Definition at line 422 of file nsFontMetricsBeOS.cpp.

{
       return (((0xE5000000 >> ((byte >> 3) & 0x1E)) & 3) + 1);
}

Here is the caller graph for this function:

PRUint32 utf8_to_index ( char *  utf8char) [inline]

Definition at line 430 of file nsFontMetricsBeOS.cpp.

{
       PRUint32 ch = 0;
       switch (utf8_char_len(*utf8char) - 1) 
       {
              case 3: ch += *utf8char++; ch <<= 6;
              case 2: ch += *utf8char++; ch <<= 6;
              case 1: ch += *utf8char++; ch <<= 6;
              case 0: ch += *utf8char++;
       }
       return ch;
}

Here is the call graph for this function:

Here is the caller graph for this function: