Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
nsDeviceContextMac.cpp File Reference
#include "nsDeviceContextMac.h"
#include "nsRenderingContextMac.h"
#include "nsDeviceContextSpecX.h"
#include "nsIPrintingContext.h"
#include "nsString.h"
#include "nsHashtable.h"
#include "nsFont.h"
#include <Gestalt.h>
#include <Appearance.h>
#include <TextEncodingConverter.h>
#include <TextCommon.h>
#include <StringCompare.h>
#include <Fonts.h>
#include <Resources.h>
#include <MacWindows.h>
#include <FixMath.h>
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "nsQuickSort.h"
#include "nsUnicodeMappingUtil.h"
#include "nsCarbonHelpers.h"
#include "nsRegionMac.h"
#include "nsIScreenManager.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"

Go to the source code of this file.

Classes

class  FontNameKey
struct  EnumerateFamilyInfo
struct  EnumerateFontInfo

Defines

#define APPEARANCE_MIN_VERSION   0x0110
#define FONTNAME_MAX_UNICHRS   sizeof(fontName255) * 2

Typedefs

typedef struct EnumerateFamilyInfo EnumerateFamilyInfo
typedef struct EnumerateFontInfo EnumerateFontInfo

Functions

static bool HasAppearanceManager ()
 

nsresult GetSystemFontForScript (ThemeFontID aFontID, ScriptCode aScriptCode, nsAFlatString &aFontName, SInt16 &aFontSize, Style &aFontStyle)
static NS_DEFINE_CID (kPrefCID, NS_PREF_CID)
static int CompareFontNames (const void *aArg1, const void *aArg2, void *aClosure)
static PRBool EnumerateFamily (nsHashKey *aKey, void *aData, void *closure)
static PRBool EnumerateFont (nsHashKey *aKey, void *aData, void *closure)

Class Documentation

struct EnumerateFamilyInfo

Definition at line 970 of file nsDeviceContextMac.cpp.

Collaboration diagram for EnumerateFamilyInfo:
Class Members
PRUnichar ** mArray
int mIndex
struct EnumerateFontInfo

Definition at line 976 of file nsDeviceContextMac.cpp.

Collaboration diagram for EnumerateFontInfo:
Class Members
PRUnichar ** mArray
int mCount
int mIndex
ScriptCode mScript
nsGenericFontNameType mType

Define Documentation

#define FONTNAME_MAX_UNICHRS   sizeof(fontName255) * 2

Definition at line 234 of file nsDeviceContextMac.cpp.


Typedef Documentation


Function Documentation

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

Definition at line 988 of file nsDeviceContextMac.cpp.

{
  const PRUnichar* str1 = *((const PRUnichar**) aArg1);
  const PRUnichar* str2 = *((const PRUnichar**) aArg2);

  // XXX add nsICollation stuff

  return nsCRT::strcmp(str1, str2);
}
static PRBool EnumerateFamily ( nsHashKey *  aKey,
void aData,
void closure 
) [static]

Definition at line 998 of file nsDeviceContextMac.cpp.

{
  EnumerateFamilyInfo* info = (EnumerateFamilyInfo*) closure;
  PRUnichar** array = info->mArray;
  int j = info->mIndex;
  
  
  PRUnichar* str = ToNewUnicode(((FontNameKey*)aKey)->mString);
  if (!str) {
    for (j = j - 1; j >= 0; j--) {
      nsMemory::Free(array[j]);
    }
    info->mIndex = 0;
    return PR_FALSE;
  }
  array[j] = str;
  info->mIndex++;

  return PR_TRUE;
}

Here is the call graph for this function:

static PRBool EnumerateFont ( nsHashKey *  aKey,
void aData,
void closure 
) [static]

Definition at line 1065 of file nsDeviceContextMac.cpp.

{
  EnumerateFontInfo* info = (EnumerateFontInfo*) closure;
  PRUnichar** array = info->mArray;
  int j = info->mCount;
  PRBool match = PR_FALSE;

  // we need to match the cast of FMFontFamily in nsDeviceContextMac :: InitFontInfoList()
  FMFontFamily fontFamily = (FMFontFamily) NS_PTR_TO_INT32(aData);
  TextEncoding fontEncoding;
  OSStatus status = ::FMGetFontFamilyTextEncoding(fontFamily, &fontEncoding);
  if (noErr == status) {
    ScriptCode script;
    status = ::RevertTextEncodingToScriptInfo(fontEncoding, &script, nsnull, nsnull);
    match = ((noErr == status) && (script == info->mScript));
  }

  if (match) {
         PRUnichar* str = ToNewUnicode(((FontNameKey*)aKey)->mString);
         if (!str) {
           for (j = j - 1; j >= 0; j--) {
             nsMemory::Free(array[j]);
           }
           info->mIndex = 0;
           return PR_FALSE;
         }
         array[j] = str;
         info->mCount++;
       }
       info->mIndex++;
  return PR_TRUE;
}

Here is the call graph for this function:

nsresult GetSystemFontForScript ( ThemeFontID  aFontID,
ScriptCode  aScriptCode,
nsAFlatString aFontName,
SInt16 &  aFontSize,
Style &  aFontStyle 
)

Definition at line 236 of file nsDeviceContextMac.cpp.

{
  Str255 fontName255;
  ::GetThemeFont(aFontID, aScriptCode, fontName255, &aFontSize, &aFontStyle);
  if (fontName255[0] == 255) {
    NS_WARNING("Too long fong name (> 254 chrs)");
    return NS_ERROR_FAILURE;
  }
  fontName255[fontName255[0]+1] = 0;
        
  OSStatus err;
  // the theme font could contains font name in different encoding. 
  // we need to convert them to unicode according to the font's text encoding.

  TECObjectRef converter = 0;
  TextEncoding unicodeEncoding = 
    ::CreateTextEncoding(kTextEncodingUnicodeDefault, 
                         kTextEncodingDefaultVariant,
                         kTextEncodingDefaultFormat);
                                                              
  FMFontFamily fontFamily = ::FMGetFontFamilyFromName(fontName255);;
  TextEncoding fontEncoding = 0;
  err = ::FMGetFontFamilyTextEncoding(fontFamily, &fontEncoding);

  if (err != noErr) {
    NS_WARNING("Could not get the encoding for the font.");
    return NS_ERROR_FAILURE;
  }
  err = ::TECCreateConverter(&converter, fontEncoding, unicodeEncoding);
  if (err != noErr) {
    NS_WARNING("Could not create the converter.");
    return NS_ERROR_FAILURE;
  }
  PRUnichar unicodeFontName[FONTNAME_MAX_UNICHRS + 1];
  ByteCount actualInputLength, actualOutputLength;
  err = ::TECConvertText(converter, &fontName255[1], fontName255[0], 
                         &actualInputLength, 
                         (TextPtr)unicodeFontName,
                         FONTNAME_MAX_UNICHRS * sizeof(PRUnichar),
                         &actualOutputLength);  
  if (err != noErr) {
    NS_WARNING("Could not convert the font name.");
    return NS_ERROR_FAILURE;
  }

  ::TECDisposeConverter(converter);

  unicodeFontName[actualOutputLength / sizeof(PRUnichar)] = PRUnichar('\0');
  aFontName = nsDependentString(unicodeFontName);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool HasAppearanceManager ( ) [static]


Definition at line 209 of file nsDeviceContextMac.cpp.

{

#define APPEARANCE_MIN_VERSION     0x0110        // we require version 1.1
       
       static bool inited = false;
       static bool hasAppearanceManager = false;

       if (inited)
              return hasAppearanceManager;
       inited = true;

       SInt32 result;
       if (::Gestalt(gestaltAppearanceAttr, &result) != noErr)
              return false;        // no Appearance Mgr

       if (::Gestalt(gestaltAppearanceVersion, &result) != noErr)
              return false;        // still version 1.0

       hasAppearanceManager = (result >= APPEARANCE_MIN_VERSION);

       return hasAppearanceManager;
}

Here is the caller graph for this function:

static NS_DEFINE_CID ( kPrefCID  ,
NS_PREF_CID   
) [static]