Back to index

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

#include <nsFontMetricsOS2.h>

Inheritance diagram for nsFontMetricsOS2:
Inheritance graph
[legend]
Collaboration diagram for nsFontMetricsOS2:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS 
nsFontMetricsOS2 ()
virtual ~nsFontMetricsOS2 ()
NS_IMETHOD Init (const nsFont &aFont, nsIAtom *aLangGroup, nsIDeviceContext *aContext)
 Initialize the font metrics.
NS_IMETHOD Destroy ()
 Destroy this font metrics.
NS_IMETHOD GetXHeight (nscoord &aResult)
 Return the font's xheight property, scaled into app-units.
NS_IMETHOD GetSuperscriptOffset (nscoord &aResult)
 Return the font's superscript offset (the distance from the baseline to where a superscript's baseline should be placed).
NS_IMETHOD GetSubscriptOffset (nscoord &aResult)
 Return the font's subscript offset (the distance from the baseline to where a subscript's baseline should be placed).
NS_IMETHOD GetStrikeout (nscoord &aOffset, nscoord &aSize)
 Return the font's strikeout offset (the distance from the baseline to where a strikeout should be placed) and size Positive values are above the baseline, negative below.
NS_IMETHOD GetUnderline (nscoord &aOffset, nscoord &aSize)
 Return the font's underline offset (the distance from the baseline to where a underline should be placed) and size.
NS_IMETHOD GetHeight (nscoord &aHeight)
 Returns the height (in app units) of the font.
NS_IMETHOD GetLeading (nscoord &aLeading)
 Returns the amount of internal leading (in app units) for the font.
NS_IMETHOD GetNormalLineHeight (nscoord &aHeight)
 Returns the normal line height (em height + leading).
NS_IMETHOD GetEmHeight (nscoord &aHeight)
 Returns the height (in app units) of the Western font's em square.
NS_IMETHOD GetEmAscent (nscoord &aAscent)
 Returns, in app units, the ascent part of the Western font's em square.
NS_IMETHOD GetEmDescent (nscoord &aDescent)
 Returns, in app units, the descent part of the Western font's em square.
NS_IMETHOD GetMaxHeight (nscoord &aHeight)
 Returns the height (in app units) of the Western font's bounding box.
NS_IMETHOD GetMaxAscent (nscoord &aAscent)
 Returns, in app units, the maximum distance characters in this font extend above the base line.
NS_IMETHOD GetMaxDescent (nscoord &aDescent)
 Returns, in app units, the maximum distance characters in this font extend below the base line.
NS_IMETHOD GetMaxAdvance (nscoord &aAdvance)
 Returns, in app units, the maximum character advance for the font.
NS_IMETHOD GetLangGroup (nsIAtom **aLangGroup)
 Returns the language group associated with these metrics.
NS_IMETHOD GetFontHandle (nsFontHandle &aHandle)
 Returns the font handle associated with these metrics.
NS_IMETHOD GetAveCharWidth (nscoord &aAveCharWidth)
 Returns the average character width.
NS_IMETHOD GetSpaceWidth (nscoord &aSpaceWidth)
 Returns the often needed width of the space character.
virtual PRInt32 GetMaxStringLength ()
virtual nsresult ResolveForwards (HPS aPS, const PRUnichar *aString, PRUint32 aLength, nsFontSwitchCallback aFunc, void *aData)
virtual nsresult ResolveBackwards (HPS aPS, const PRUnichar *aString, PRUint32 aLength, nsFontSwitchCallback aFunc, void *aData)
nsFontOS2FindFont (HPS aPS, PRUint32 aChar)
nsFontOS2FindUserDefinedFont (HPS aPS, PRUint32 aChar)
nsFontOS2FindLocalFont (HPS aPS, PRUint32 aChar)
nsFontOS2FindGenericFont (HPS aPS, PRUint32 aChar)
virtual nsFontOS2FindPrefFont (HPS aPS, PRUint32 aChar)
virtual nsFontOS2FindGlobalFont (HPS aPS, PRUint32 aChar)
virtual nsFontOS2FindSubstituteFont (HPS aPS, PRUint32 aChar)
nsFontOS2LoadFont (HPS aPS, const nsAString &aName)
nsFontOS2LoadGenericFont (HPS aPS, PRUint32 aChar, const nsAString &aName)
nsFontOS2LoadUnicodeFont (HPS aPS, const nsAString &aName)
const nsFontFont ()
 Returns the font associated with these metrics.

Static Public Member Functions

static nsresult InitializeGlobalFonts ()

Public Attributes

nsCOMPtr< nsIAtommLangGroup
nsStringArray mFonts
PRInt32 mFontsIndex
nsVoidArray mLoadedFonts
nsFontOS2mUnicodeFont
nsFontOS2mWesternFont
PRInt32 mGenericIndex
nsString mGeneric
nsString mUserDefined
PRBool mTriedAllGenerics
PRBool mTriedAllPref
PRBool mIsUserDefined
int mConvertCodePage

Static Public Attributes

static nsTHashtable
< GlobalFontEntry > * 
gGlobalFonts = nsnull
static PLHashTablegFamilyNames = nsnull
static PRBool gSubstituteVectorFonts = PR_TRUE
static PRBool gUseFTFunctions = PR_FALSE

Protected Member Functions

nsresult RealizeFont (void)
PRBool GetVectorSubstitute (HPS aPS, const nsAString &aFacename, nsAString &aAlias)
void FindUnicodeFont (HPS aPS)
void FindWesternFont ()
nsFontOS2SetFontHandle (HPS aPS, GlobalFontEntry *aEntry, nsMiniMetrics *aMetrics, PRBool aDoFakeEffects)
PLHashTableInitializeFamilyNames (void)

Protected Attributes

nscoord mSuperscriptYOffset
nscoord mSubscriptYOffset
nscoord mStrikeoutPosition
nscoord mStrikeoutSize
nscoord mUnderlinePosition
nscoord mUnderlineSize
nscoord mExternalLeading
nscoord mInternalLeading
nscoord mEmHeight
nscoord mEmAscent
nscoord mEmDescent
nscoord mMaxHeight
nscoord mMaxAscent
nscoord mMaxDescent
nscoord mMaxAdvance
nscoord mSpaceWidth
nscoord mXHeight
nscoord mAveCharWidth
nsFontOS2mFontHandle
nsDeviceContextOS2mDeviceContext
nsFont mFont

Detailed Description

Definition at line 216 of file nsFontMetricsOS2.h.


Constructor & Destructor Documentation

Definition at line 341 of file nsFontMetricsOS2.cpp.

{
#ifdef DEBUG_FONT_STRUCT_ALLOCS
  mRefCount++;
  printf("+++ nsFontMetricsOS2 total = %d\n", mRefCount);
#endif
}

Definition at line 349 of file nsFontMetricsOS2.cpp.

{
  mFontHandle = nsnull; // released below
  mUnicodeFont = nsnull; // release below
  mWesternFont = nsnull; // release below

  for (PRInt32 i = mLoadedFonts.Count()-1; i >= 0; --i) {
    delete (nsFontOS2*)mLoadedFonts[i];
  }
  mLoadedFonts.Clear();

  if (mDeviceContext) {
    // Notify our device context that owns us so that it can update its font cache
    mDeviceContext->FontMetricsDeleted(this);
    mDeviceContext = nsnull;
  }
#ifdef DEBUG_FONT_STRUCT_ALLOCS
  mRefCount--;
  printf("--- nsFontMetricsOS2 total = %d\n", mRefCount);
#endif
}

Member Function Documentation

Destroy this font metrics.

This breaks the association between the font metrics and the device context.

Implements nsIFontMetrics.

Definition at line 394 of file nsFontMetricsOS2.cpp.

{
  mDeviceContext = nsnull;
  return NS_OK;
}
nsFontOS2 * nsFontMetricsOS2::FindFont ( HPS  aPS,
PRUint32  aChar 
)

Definition at line 1232 of file nsFontMetricsOS2.cpp.

{
  nsFontOS2* font = FindUserDefinedFont(aPS, aChar);
  if (!font) {
    font = FindLocalFont(aPS, aChar);
    if (!font) {
      font = FindGenericFont(aPS, aChar);
      if (!font) {
        font = FindPrefFont(aPS, aChar);
        if (!font) {
          font = FindGlobalFont(aPS, aChar);
#ifdef USE_FREETYPE
          if (!font) {
            font = FindSubstituteFont(aPS, aChar);
          }
#endif
        }
      }
    }
  }
#ifdef DEBUG_FONT_SELECTION
  if (font) {
    printf(" FindFont(): found font %s for char 0x%04x\n",
           font->mFattrs.szFacename, aChar);
  }
#endif
  return font;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1141 of file nsFontMetricsOS2.cpp.

{
  if (mTriedAllGenerics) {
    // don't bother anymore because mLoadedFonts[] already has all our generic fonts
    return nsnull;
  }

  // This is a nifty hook that we will use to just iterate over
  // the list of names using the callback mechanism of nsFont...
  nsFont font("", 0, 0, 0, 0, 0);

  if (mLangGroup) {
    const char* langGroup;
    mLangGroup->GetUTF8String(&langGroup);
  
    // x-unicode pseudo-langGroup should be the last resort to turn to.
    // That is, it should be refered to only when we don't  recognize 
    // |langGroup| specified by the authors of documents and  the 
    // determination of |langGroup| based  on Unicode range also fails 
    // in |FindPrefFont|. 

    if (!strcmp(langGroup, "x-unicode")) {
      mTriedAllGenerics = 1;
      return nsnull;
    }

    AppendGenericFontFromPref(font.name, langGroup, 
                              NS_ConvertUCS2toUTF8(mGeneric).get());
  }

  // Iterate over the list of names using the callback mechanism of nsFont...
  GenericFontEnumContext context = {aPS, aChar, nsnull, this};
  font.EnumerateFamilies(GenericFontEnumCallback, &context);
  if (context.mFont) { // a suitable font was found
    return context.mFont;
  }

  mTriedAllGenerics = 1;
  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsFontOS2 * nsFontMetricsOS2::FindGlobalFont ( HPS  aPS,
PRUint32  aChar 
) [virtual]

Reimplemented in nsFontMetricsOS2FT.

Definition at line 887 of file nsFontMetricsOS2.cpp.

{
  nsFontOS2* fh = nsnull;
  nsAutoString fontname;
  if (!IsDBCS())
    fontname.AssignLiteral("Helv");
  else
    fontname.AssignLiteral("Helv Combined");
  fh = LoadFont(aPS, fontname);
  NS_ASSERTION(fh, "Couldn't load default font - BAD things are happening");
  return fh;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1025 of file nsFontMetricsOS2.cpp.

{
  if (!gFamilyNames) {
    if (!InitializeFamilyNames()) {
      return nsnull;
    }
  }
  while (mFontsIndex < mFonts.Count()) {
    if (mFontsIndex == mGenericIndex) {
      return nsnull;
    }

    nsString* name = mFonts.StringAt(mFontsIndex++);
    nsAutoString low(*name);
    ToLowerCase(low);
    nsString* winName = (nsString*) PL_HashTableLookup(gFamilyNames, &low);
    if (!winName) {
      winName = name;
    }
#ifdef DEBUG_FONT_SELECTION
    printf(" FindLocalFont(): attempting to load %s\n",
           NS_LossyConvertUCS2toASCII(*winName).get());
#endif
    nsFontOS2* font = LoadFont(aPS, *winName);
    if (font && font->HasGlyph(aPS, aChar)) {
      return font;
    }
  }
  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsFontOS2 * nsFontMetricsOS2::FindPrefFont ( HPS  aPS,
PRUint32  aChar 
) [virtual]

Reimplemented in nsFontMetricsOS2FT.

Definition at line 1183 of file nsFontMetricsOS2.cpp.

{
  if (mTriedAllPref) {
    // don't bother anymore because mLoadedFonts[] already has all our pref fonts
    return nsnull;
  }
  nsFont font("", 0, 0, 0, 0, 0);
  // Try the pref of the user's ui lang group
  // For example, if the ui language is Japanese, try pref from "ja"
  // Make localized build work better on other OS
  if (gUsersLocale != mLangGroup) {
    nsAutoString langGroup;
    gUsersLocale->ToString(langGroup);
    AppendGenericFontFromPref(font.name, 
                              NS_ConvertUCS2toUTF8(langGroup).get(), 
                              NS_ConvertUCS2toUTF8(mGeneric).get());
  }
  // Try the pref of the user's system lang group
  // For example, if the os language is Simplified Chinese, 
  // try pref from "zh-CN"
  // Make English build work better on other OS
  if ((gSystemLocale != mLangGroup) && (gSystemLocale != gUsersLocale)) {
    nsAutoString langGroup;
    gSystemLocale->ToString(langGroup);
    AppendGenericFontFromPref(font.name, 
                              NS_ConvertUCS2toUTF8(langGroup).get(), 
                              NS_ConvertUCS2toUTF8(mGeneric).get());
  }

  // Also try all the default pref fonts enlisted from other languages
  for (int i = 1; i < eCharset_COUNT; ++i) {
    nsIAtom* langGroup = NS_NewAtom(gCharsetInfo[i].mLangGroup); 
    if((gUsersLocale != langGroup) && (gSystemLocale != langGroup)) {
      AppendGenericFontFromPref(font.name, gCharsetInfo[i].mLangGroup, 
                                NS_ConvertUCS2toUTF8(mGeneric).get());
    }
    NS_IF_RELEASE(langGroup);
  }
  GenericFontEnumContext context = {aPS, aChar, nsnull, this};
  font.EnumerateFamilies(GenericFontEnumCallback, &context);
  if (context.mFont) { // a suitable font was found
    return context.mFont;
  }
  mTriedAllPref = 1;
  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual nsFontOS2* nsFontMetricsOS2::FindSubstituteFont ( HPS  aPS,
PRUint32  aChar 
) [inline, virtual]

Reimplemented in nsFontMetricsOS2FT.

Definition at line 277 of file nsFontMetricsOS2.h.

      { return nsnull; };

Here is the caller graph for this function:

void nsFontMetricsOS2::FindUnicodeFont ( HPS  aPS) [protected]

Definition at line 1627 of file nsFontMetricsOS2.cpp.

{
  nsresult res;
  nsCAutoString pref, generic;
  nsXPIDLString value;

  generic.Assign(NS_ConvertUCS2toUTF8(mGeneric));

  pref.Assign("font.name.");
  pref.Append(generic);
  pref.Append(".x-unicode");
   
  res = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
  if (NS_FAILED(res))
    return;

  nsAutoString fontname;
  fontname.Assign(value);

  nsFontOS2* fh = nsnull;
  fh = LoadUnicodeFont(aPS, fontname);
  if (!fh)
  {
     // User defined unicode font did not load.  Fall back to font
     // specified in font.name-list.%.x-unicode
    pref.Assign("font.name-list.");
    pref.Append(generic);
    pref.Append(".x-unicode");

    res = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
    if (NS_FAILED(res))
      return;

    nsFont font("", 0, 0, 0, 0, 0);
    font.name.Assign(value);

     // Iterate over the list of names using the callback mechanism of nsFont
    UnicodeFontEnumContext context = {aPS, nsnull, this};
    font.EnumerateFamilies(UnicodeFontEnumCallback, &context);
    fh = context.mFont;
  }

  if (fh) {   // a suitable font was found
    fh->mFattrs.usCodePage = 1208;
    fh->mConvertCodePage = 1208;
    mUnicodeFont = fh;
#ifdef DEBUG_FONT_SELECTION
    printf(" FindUnicodeFont(): found new Unicode font %s\n",
           mUnicodeFont->mFattrs.szFacename);
#endif
  } else {
    NS_ERROR("Could not find a Unicode font");
  }
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 901 of file nsFontMetricsOS2.cpp.

{
  if (mIsUserDefined) {
    // the user-defined font is always loaded as the first font
    nsFontOS2* font = LoadFont(aPS, mUserDefined);
    mIsUserDefined = PR_FALSE;
    if (font && font->HasGlyph(aPS, aChar)) {
      return font;
    }
  }
  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1684 of file nsFontMetricsOS2.cpp.

{
  // Create a 'western' font by making a copy of the currently selected font
  // and changing the codepage 1252
  nsFontOS2* font = new nsFontOS2();
  font->mFattrs = mFontHandle->mFattrs;
  font->mFattrs.usCodePage = 1252;
  font->mCharbox = mFontHandle->mCharbox;
  font->mMaxAscent = mFontHandle->mMaxAscent;
  font->mMaxDescent = mFontHandle->mMaxDescent;
  font->mConvertCodePage = 1252;
  mLoadedFonts.AppendElement(font);
  mWesternFont = font;
}

Here is the caller graph for this function:

const nsFont& nsIFontMetrics::Font ( ) [inline, inherited]

Returns the font associated with these metrics.

The return value is only defined after Init() has been called.

Definition at line 214 of file nsIFontMetrics.h.

{ return mFont; }

Here is the caller graph for this function:

Returns the average character width.

Implements nsIFontMetrics.

Definition at line 1586 of file nsFontMetricsOS2.cpp.

{
  aAveCharWidth = mAveCharWidth;
  return NS_OK;
}

Here is the caller graph for this function:

Returns, in app units, the ascent part of the Western font's em square.

Implements nsIFontMetrics.

Definition at line 1565 of file nsFontMetricsOS2.cpp.

{
  aAscent = mEmAscent;
  return NS_OK;
}

Returns, in app units, the descent part of the Western font's em square.

Implements nsIFontMetrics.

Definition at line 1572 of file nsFontMetricsOS2.cpp.

{
  aDescent = mEmDescent;
  return NS_OK;
}

Returns the height (in app units) of the Western font's em square.

This is em ascent plus em descent.

Implements nsIFontMetrics.

Definition at line 1558 of file nsFontMetricsOS2.cpp.

{
  aHeight = mEmHeight;
  return NS_OK;
}

Returns the font handle associated with these metrics.

Implements nsIFontMetrics.

Definition at line 1543 of file nsFontMetricsOS2.cpp.

{
  aHandle = mFontHandle;
  return NS_OK;
}

Returns the height (in app units) of the font.

This is ascent plus descent plus any internal leading

This method will be removed once the callers have been moved over to the new GetEmHeight (and possibly GetMaxHeight).

Implements nsIFontMetrics.

Definition at line 1490 of file nsFontMetricsOS2.cpp.

{
  aHeight = mMaxHeight;
  return NS_OK;
}

Returns the language group associated with these metrics.

Implements nsIFontMetrics.

Definition at line 1549 of file nsFontMetricsOS2.cpp.

{
  NS_ENSURE_ARG_POINTER(aLangGroup);
  *aLangGroup = mLangGroup;
  NS_IF_ADDREF(*aLangGroup);
  return NS_OK;
}

Returns the amount of internal leading (in app units) for the font.

This is computed as the "height - (ascent + descent)"

Implements nsIFontMetrics.

Definition at line 1511 of file nsFontMetricsOS2.cpp.

{
   aLeading = mInternalLeading;
   return NS_OK;
}

Returns, in app units, the maximum character advance for the font.

Implements nsIFontMetrics.

Definition at line 1537 of file nsFontMetricsOS2.cpp.

{
  aAdvance = mMaxAdvance;
  return NS_OK;
}

Returns, in app units, the maximum distance characters in this font extend above the base line.

Implements nsIFontMetrics.

Definition at line 1525 of file nsFontMetricsOS2.cpp.

{
  aAscent = mMaxAscent;
  return NS_OK;
}

Returns, in app units, the maximum distance characters in this font extend below the base line.

Implements nsIFontMetrics.

Definition at line 1531 of file nsFontMetricsOS2.cpp.

{
  aDescent = mMaxDescent;
  return NS_OK;
}

Returns the height (in app units) of the Western font's bounding box.

This is max ascent plus max descent.

Implements nsIFontMetrics.

Definition at line 1579 of file nsFontMetricsOS2.cpp.

{
  aHeight = mMaxHeight;
  return NS_OK;
}
virtual PRInt32 nsFontMetricsOS2::GetMaxStringLength ( ) [inline, virtual]

Definition at line 254 of file nsFontMetricsOS2.h.

{ return PR_INT32_MAX; }

Returns the normal line height (em height + leading).

Implements nsIFontMetrics.

Definition at line 1518 of file nsFontMetricsOS2.cpp.

{
  aHeight = mEmHeight + mInternalLeading;
  return NS_OK;
}
NS_IMETHODIMP nsFontMetricsOS2::GetSpaceWidth ( nscoord aSpaceCharWidth) [virtual]

Returns the often needed width of the space character.

Implements nsIFontMetrics.

Definition at line 1451 of file nsFontMetricsOS2.cpp.

{
  aSpaceWidth = mSpaceWidth;
  return NS_OK;
}

Here is the caller graph for this function:

NS_IMETHODIMP nsFontMetricsOS2::GetStrikeout ( nscoord aOffset,
nscoord aSize 
) [virtual]

Return the font's strikeout offset (the distance from the baseline to where a strikeout should be placed) and size Positive values are above the baseline, negative below.

Implements nsIFontMetrics.

Definition at line 1476 of file nsFontMetricsOS2.cpp.

{
  aOffset = mStrikeoutPosition;
  aSize = mStrikeoutSize;
  return NS_OK;
}

Return the font's subscript offset (the distance from the baseline to where a subscript's baseline should be placed).

The value returned will be a positive value.

Implements nsIFontMetrics.

Definition at line 1470 of file nsFontMetricsOS2.cpp.

Return the font's superscript offset (the distance from the baseline to where a superscript's baseline should be placed).

The value returned will be a positive value.

Implements nsIFontMetrics.

Definition at line 1464 of file nsFontMetricsOS2.cpp.

NS_IMETHODIMP nsFontMetricsOS2::GetUnderline ( nscoord aOffset,
nscoord aSize 
) [virtual]

Return the font's underline offset (the distance from the baseline to where a underline should be placed) and size.

Positive values are above the baseline, negative below.

Implements nsIFontMetrics.

Definition at line 1483 of file nsFontMetricsOS2.cpp.

{
  aOffset = mUnderlinePosition;
  aSize = mUnderlineSize;
  return NS_OK;
}
PRBool nsFontMetricsOS2::GetVectorSubstitute ( HPS  aPS,
const nsAString &  aFacename,
nsAString &  aAlias 
) [protected]

Definition at line 1294 of file nsFontMetricsOS2.cpp.

{
  if (aFamilyname.EqualsLiteral("Tms Rmn")) {
    aAlias.AssignLiteral("Times New Roman");
  } else if (aFamilyname.EqualsLiteral("Helv")) {
    aAlias.AssignLiteral("Helvetica");
  }

  // When printing, substitute vector fonts for these common bitmap fonts
  if (!mDeviceContext->SupportsRasterFonts()) {
    if (aFamilyname.EqualsLiteral("System Proportional") ||
        aFamilyname.EqualsLiteral("WarpSans"))
    {
      aAlias.AssignLiteral("Helvetica");
    } else if (aFamilyname.EqualsLiteral("System Monospaced") ||
               aFamilyname.EqualsLiteral("System VIO"))
    {
      aAlias.AssignLiteral("Courier");
    }
  }

  if (aAlias.IsEmpty())
    return PR_FALSE;
  else
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Return the font's xheight property, scaled into app-units.

Implements nsIFontMetrics.

Definition at line 1458 of file nsFontMetricsOS2.cpp.

{
  aResult = mXHeight;
  return NS_OK;
}
NS_IMETHODIMP nsFontMetricsOS2::Init ( const nsFont aFont,
nsIAtom aLangGroup,
nsIDeviceContext aContext 
) [virtual]

Initialize the font metrics.

Call this after creating the font metrics. Font metrics you get from the font cache do NOT need to be initialized

See also:
nsIDeviceContext::GetMetricsFor()

Implements nsIFontMetrics.

Definition at line 374 of file nsFontMetricsOS2.cpp.

{
  nsresult res;
  if (!gInitialized) {
    res = InitGlobals();
    if (NS_FAILED(res)) {
      return res;
    }
  }

  mFont = aFont;
  mLangGroup = aLangGroup;

  //don't addref this to avoid circular refs
  mDeviceContext = (nsDeviceContextOS2 *) aContext;
  return RealizeFont();
}

Here is the call graph for this function:

Definition at line 987 of file nsFontMetricsOS2.cpp.

{
  if (!gFamilyNames) {
    gFamilyNames = PL_NewHashTable( 0, HashKey, CompareKeys, nsnull,
                                    &familyname_HashAllocOps, nsnull );
    if (!gFamilyNames) {
      return nsnull;
    }

    nsFontFamilyName* f;
    if (!IsDBCS()) {
      f = gFamilyNameTable;
    } else {
      f = gFamilyNameTableDBCS;
    }

    while (f->mName) {
      nsString* name = new nsString;
      nsString* winName = new nsString;
      if (name && winName) {
        name->AssignWithConversion(f->mName);
        winName->AssignWithConversion(f->mWinName);
        if (PL_HashTableAdd(gFamilyNames, name, (void*) winName)) { 
          ++f;
          continue;
        }
      }
      // if we reach here, no FamilyName was added to the hashtable
      if (name) delete name;
      if (winName) delete winName;
      return nsnull;
    }
  }

  return gFamilyNames;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 766 of file nsFontMetricsOS2.cpp.

{
  gGlobalFonts = new nsTHashtable<GlobalFontEntry>;
  if (!gGlobalFonts->Init(64))
    return NS_ERROR_OUT_OF_MEMORY;

  HPS ps = ::WinGetScreenPS(HWND_DESKTOP);
  LONG lRemFonts = 0, lNumFonts;
  lNumFonts = GFX (::GpiQueryFonts(ps, QF_PUBLIC, NULL, &lRemFonts, 0, 0),
                   GPI_ALTERROR);
  FONTMETRICS* pFontMetrics = (PFONTMETRICS) nsMemory::Alloc(lNumFonts * sizeof(FONTMETRICS));
  lRemFonts = GFX (::GpiQueryFonts(ps, QF_PUBLIC, NULL, &lNumFonts,
                                   sizeof (FONTMETRICS), pFontMetrics),
                   GPI_ALTERROR);
  ::WinReleasePS(ps);

  for (int i = 0; i < lNumFonts; i++) {
    FONTMETRICS* font = &(pFontMetrics[i]);

    // The discrepencies between the Courier bitmap and outline fonts are
    // too much to deal with, so we only use the outline font
    if (strcmp(font->szFamilyname, "Courier") == 0 &&
        !(font->fsDefn & FM_DEFN_OUTLINE)) {
      continue;
    }

    // The facenames for Roman are "Tms Rmn...", for Swiss "Helv...".  This
    // conflicts with the actual "Tms Rmn" and "Helv" font families.  So, we
    // skip over these.
    if (strcmp(pFontMetrics[i].szFamilyname, "Roman") == 0 ||
        strcmp(pFontMetrics[i].szFamilyname, "Swiss") == 0) {
      continue;
    }

     // Problem:  OS/2 has many non-standard fonts that do not follow the
     //           normal Family-name/Face-name conventions (i.e. 'foo',
     //           'foo bold', 'foo italic', 'foo bold italic').  This is
     //           especially true for DBCS fonts (i.e. the 'WarpSans' family
     //           can contain the 'WarpSans', 'WarpSans Bold', and 'WarpSans
     //           Combined' faces).
     // Solution: Unfortunately, there is no perfect way to handle this.  After
     //           many attempts, we will attempt to remedy the situation by
     //           searching the Facename for certain indicators ('bold',
     //           'italic', 'oblique', 'regular').  If the Facename contains
     //           one of these indicators, then we will create the sort key
     //           based on the Familyname.  Otherwise, use the Facename.
    char* f;
    if (PL_strcasestr(font->szFacename, "bold") != nsnull ||
        PL_strcasestr(font->szFacename, "italic") != nsnull ||
        PL_strcasestr(font->szFacename, "oblique") != nsnull ||
        PL_strcasestr(font->szFacename, "regular") != nsnull ||
        PL_strcasestr(font->szFacename, "-normal") != nsnull)
    {
      f = NS_STATIC_CAST(char*, font->szFamilyname);
    } else {
      f = NS_STATIC_CAST(char*, font->szFacename);
    }
    nsAutoChar16Buffer fontname;
    PRInt32 len;
    MultiByteToWideChar(0, f, strlen(f), fontname, len);
    nsAutoString fontptr(fontname.get());

    // The fonts in gBadDBCSFontMapping do not display well in non-Chinese
    //   systems.  Map them to a more intelligible name.
    if (font->fsType & FM_TYPE_DBCS)
    {
      if ((gSystemCodePage != 1386) &&
          (gSystemCodePage != 1381) &&
          (gSystemCodePage != 950))
      {
        for (int i = 0; gBadDBCSFontMapping[i].mName != nsnull; i++) {
          if (strcmp(f, gBadDBCSFontMapping[i].mName) == 0)
          {
            CopyASCIItoUCS2(nsDependentCString(gBadDBCSFontMapping[i].mWinName),
                            fontptr);
            break;
          }
        }
      }
    }

    // Create entry for family name, or retrieve already created entry
    GlobalFontEntry* globalEntry = gGlobalFonts->PutEntry(fontptr);
    if (!globalEntry)
      return NS_ERROR_OUT_OF_MEMORY;

    // Init the nsMiniMetrics structure...
    nsMiniMetrics* metrics = new nsMiniMetrics;
    strcpy(metrics->szFacename, font->szFacename);
    metrics->fsType = font->fsType;
    metrics->fsDefn = font->fsDefn;
    metrics->fsSelection = font->fsSelection;
     // Set the FM_SEL_BOLD flag in fsSelection.  This makes the check for
     // bold and italic much easier in LoadFont
    if (font->usWeightClass > 5)
      metrics->fsSelection |= FM_SEL_BOLD;

    // The 'Lucida' set of fonts does not set the bold flag correctly on OS/2,
    // so we'll just set it properly.
    if (strncmp(font->szFamilyname, "Lucida", 6) == 0 &&
        PL_strcasestr(font->szFacename, "bold") != nsnull) {
      metrics->fsSelection |= FM_SEL_BOLD;
    }

    // ... and add it to globalEntry
    metrics->mNext = globalEntry->mMetrics;
    globalEntry->mMetrics = metrics;
    globalEntry->mCodePage = font->usCodePage;
  }

#ifdef DEBUG_pedemonte
  gGlobalFonts->EnumerateEntries(DebugOutputEnumFunc, nsnull);
  fflush(stdout);
#endif

  nsMemory::Free(pFontMetrics);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsFontOS2 * nsFontMetricsOS2::LoadFont ( HPS  aPS,
const nsAString &  aName 
)

Definition at line 607 of file nsFontMetricsOS2.cpp.

{
  nsFontOS2* font = nsnull;

   // set style flags
  PRBool bBold = mFont.weight > NS_FONT_WEIGHT_NORMAL;
  PRBool bItalic = (mFont.style & (NS_FONT_STYLE_ITALIC | NS_FONT_STYLE_OBLIQUE));
  USHORT flags = bBold ? FM_SEL_BOLD : 0;
  flags |= bItalic ? FM_SEL_ITALIC : 0;

  // always pass vector fonts to the printer
  nsAutoString fontptr;
  if (mDeviceContext->SupportsRasterFonts() ||
      !GetVectorSubstitute(aPS, aFontname, fontptr))
  {
    fontptr = aFontname;
  }

  GlobalFontEntry* globalEntry = gGlobalFonts->GetEntry(fontptr);
  if (globalEntry) {
    nsMiniMetrics* metrics = globalEntry->mMetrics;
    nsMiniMetrics* plainFont = nsnull;
    while (metrics) {
      if ((metrics->fsSelection & (FM_SEL_ITALIC | FM_SEL_BOLD)) == flags) {
        font = SetFontHandle(aPS, globalEntry, metrics, PR_FALSE);
        break;
      }

      // Save ref to 'plain' font (non-bold, non-italic)
      if (!plainFont && !(metrics->fsSelection & (FM_SEL_ITALIC | FM_SEL_BOLD)))
        plainFont = metrics;

      metrics = metrics->mNext;
    }

    // A font of family "familyname" and with the applied effects (bold &
    // italic) was not found.  Therefore, just look for a 'regular' font
    // (that is not italic and not bold), and then have the
    // system simulate the appropriate effects (see RealizeFont()).
    if (!font && plainFont) {
      font = SetFontHandle(aPS, globalEntry, plainFont, PR_TRUE);
    }
  }

  if (!font) {
    // If a font was not found, then maybe "familyname" is really a face name.
    // See if a font with that facename exists on system and load the font.
    long lFonts = 0;
    nsAutoCharBuffer facename;
    PRInt32 len;
    WideCharToMultiByte(0, PromiseFlatString(aFontname).get(),
                        aFontname.Length(), facename, len);
    FONTMETRICS* pMetrics = getMetrics(lFonts, facename.get(), aPS);

    if (lFonts > 0) {
      nsAutoChar16Buffer familyname;
      MultiByteToWideChar(0, pMetrics[0].szFamilyname,
                          strlen(pMetrics[0].szFamilyname), familyname, len);
      nsAutoString name(familyname.get());
      GlobalFontEntry* globalEntry = gGlobalFonts->GetEntry(name);
      if (globalEntry) {
        // Look through metrics for one that matches given facename
        nsMiniMetrics* metrics = globalEntry->mMetrics;
        while (metrics) {
          if (stricmp(metrics->szFacename, facename.get()) == 0) {
            font = SetFontHandle(aPS, globalEntry, metrics, PR_TRUE);
            break;
          }
          metrics = metrics->mNext;
        }
      }
    }
    nsMemory::Free(pMetrics);
  }

  if (font) {
    mLoadedFonts.AppendElement(font);
  }

  return font;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsFontOS2 * nsFontMetricsOS2::LoadGenericFont ( HPS  aPS,
PRUint32  aChar,
const nsAString &  aName 
)

Definition at line 1057 of file nsFontMetricsOS2.cpp.

{
  for (int i = mLoadedFonts.Count()-1; i >= 0; --i) {
    // woah, this seems bad
    const nsACString& fontName =
      nsDependentCString(((nsFontOS2*)mLoadedFonts[i])->mFattrs.szFacename);
    if (aName.Equals(NS_ConvertASCIItoUCS2(fontName),
                     nsCaseInsensitiveStringComparator()))
      return nsnull;

  }
#ifdef DEBUG_FONT_SELECTION
  printf(" LoadGenericFont(): attempting to load %s\n",
         NS_LossyConvertUCS2toASCII(aName).get());
#endif
  nsFontOS2* font = LoadFont(aPS, aName);
  if (font && font->HasGlyph(aPS, aChar)) {
    return font;
  }
  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsFontOS2 * nsFontMetricsOS2::LoadUnicodeFont ( HPS  aPS,
const nsAString &  aName 
)

Definition at line 1593 of file nsFontMetricsOS2.cpp.

{
#ifdef DEBUG_FONT_SELECTION
  printf(" LoadUnicodeFont(): attempting to load %s\n",
         NS_LossyConvertUCS2toASCII(aName).get());
#endif
  nsFontOS2* font = LoadFont(aPS, aName);
  if (font) {
    return font;
  }
  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1323 of file nsFontMetricsOS2.cpp.

{
  nsresult  rv;
  HPS       ps = NULL;

  if (mDeviceContext->mPrintDC){
    ps = mDeviceContext->mPrintPS;
  } else {
    HWND win = (HWND)mDeviceContext->mWidget;
    ps = ::WinGetPS(win);
    if (!ps) {
      ps = ::WinGetPS(HWND_DESKTOP);
    }
  }

  mFont.EnumerateFamilies(FontEnumCallback, this);

  nsCAutoString pref;
  nsXPIDLString value;

  // set a fallback generic font if the font-family list didn't have one
  if (mGeneric.IsEmpty()) {
    const char* langGroup = nsnull;
    mLangGroup->GetUTF8String(&langGroup);
    pref.Assign("font.default.");
    pref.Append(langGroup);
    rv = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
    if (NS_SUCCEEDED(rv)) {
      mGeneric.Assign(value);
    }
    else {
      mGeneric.AssignLiteral("serif");
    }
  }

  if (mLangGroup.get() == gUserDefined) {
    // See if this is a special user-defined font encoding by checking:
    // font.name.[generic].x-user-def
    pref.Assign("font.name.");
    pref.AppendWithConversion(mGeneric);
    pref.Append(".x-user-def");
    rv = gPref->CopyUnicharPref(pref.get(), getter_Copies(value));
    if (NS_SUCCEEDED(rv)) {
      mUserDefined.Assign(value);
      mIsUserDefined = 1;
    }
  }

  nsFontOS2* font = FindFont(ps, 'a');
  NS_ASSERTION(font, "FindFont() returned null.  THIS IS BAD!");
  if (!font) {
    if (mDeviceContext->mPrintDC == NULL) {
      ::WinReleasePS(ps);
    }
    return NS_ERROR_FAILURE;
  }

  font->mConvertCodePage = mConvertCodePage;

   // Record font handle & record various font metrics to cache
  mFontHandle = font;
  CHK_SUCCESS (::GpiCreateLogFont(ps, 0, 1, &(font->mFattrs)), FONT_MATCH);
  font->SelectIntoPS( ps, 1 );

  FONTMETRICS fm;
  GFX (::GpiQueryFontMetrics(ps, sizeof(fm), &fm), FALSE);
  /* Due to a bug in OS/2 MINCHO, need to cast lInternalLeading */
  fm.lInternalLeading = (signed short)fm.lInternalLeading;

  float dev2app;
  dev2app = mDeviceContext->DevUnitsToAppUnits();
  
  mMaxAscent  = NSToCoordRound( (fm.lMaxAscender-1) * dev2app );
  mMaxDescent = NSToCoordRound( (fm.lMaxDescender+1) * dev2app );
  mFontHandle->mMaxAscent = mMaxAscent;
  mFontHandle->mMaxDescent = mMaxDescent;

  mInternalLeading = NSToCoordRound( fm.lInternalLeading * dev2app );
  mExternalLeading = NSToCoordRound( fm.lExternalLeading * dev2app );
  
  /* These two values aren't really used by mozilla */
  mEmAscent = mMaxAscent - mInternalLeading;
  mEmDescent  = mMaxDescent;

  mMaxHeight  = mMaxAscent + mMaxDescent;
  mEmHeight = mEmAscent + mEmDescent;

  mMaxAdvance = NSToCoordRound( fm.lMaxCharInc * dev2app );
  mXHeight    = NSToCoordRound( fm.lXHeight * dev2app );

  nscoord onePixel = NSToCoordRound(1 * dev2app);

   // Not all fonts specify these two values correctly, and some not at all
  mSuperscriptYOffset = mXHeight;
  mSubscriptYOffset   = NSToCoordRound( mXHeight / 3.0f );

   // Using lStrikeoutPosition puts the strikeout too high
   // Use 50% of lXHeight instead
  mStrikeoutPosition  = NSToCoordRound( mXHeight / 2.0f);
  mStrikeoutSize      = PR_MAX(onePixel, NSToCoordRound(fm.lStrikeoutSize * dev2app));

#if 1
  // Can't trust the fonts to give us good results for the underline position
  //  and size.  This calculation, though, gives very good results.
  float height = fm.lMaxAscender + fm.lMaxDescender;
  mUnderlinePosition = -PR_MAX(onePixel, NSToIntRound(floor(0.1 * height + 0.5) * dev2app));
  mUnderlineSize = PR_MAX(onePixel, NSToIntRound(floor(0.05 * height + 0.5) * dev2app));
#else
  mUnderlinePosition  = -NSToCoordRound( fm.lUnderscorePosition * dev2app );
  mUnderlineSize      = PR_MAX(onePixel, NSToCoordRound(fm.lUnderscoreSize * dev2app));
#endif

  mAveCharWidth       = PR_MAX(1, NSToCoordRound(fm.lAveCharWidth * dev2app));

   // Cache the width of a single space.
  SIZEL  size;
  GetTextExtentPoint32(ps, " ", 1, &size);
  mSpaceWidth = NSToCoordRound(float(size.cx) * dev2app);

   // 10) Clean up
  GFX (::GpiSetCharSet (ps, LCID_DEFAULT), FALSE);
  GFX (::GpiDeleteSetId (ps, 1), FALSE);
  if (mDeviceContext->mPrintDC == NULL)
    ::WinReleasePS(ps);

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsFontMetricsOS2::ResolveBackwards ( HPS  aPS,
const PRUnichar aString,
PRUint32  aLength,
nsFontSwitchCallback  aFunc,
void aData 
) [virtual]

Reimplemented in nsFontMetricsOS2FT.

Definition at line 1790 of file nsFontMetricsOS2.cpp.

{
  NS_ASSERTION(aString || !aLength, "invalid call");
  const PRUnichar* firstChar = aString + aLength - 1;
  const PRUnichar* lastChar  = aString - 1;
  const PRUnichar* currChar  = firstChar;
  PRBool running = PR_TRUE;

  nsFontSwitch fontSwitch;
  fontSwitch.mFont = 0;
  
  if (mConvertCodePage == 1252)
  {
    while (running && firstChar > lastChar)
    {
      if ((*currChar > 0x00FF) && !IS_SPECIAL(*currChar))
      {
        if (!mUnicodeFont) {
          FindUnicodeFont(aPS);
          if (!mUnicodeFont) {
            mUnicodeFont = FindGlobalFont(aPS, *currChar);
          }
        }
        fontSwitch.mFont = mUnicodeFont;
        while( --currChar > lastChar ) {
          if (( *currChar <= 0x00FF ) || IS_SPECIAL(*currChar))
            break;
        }
        running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
      }
      else
      {
         // Use currently selected font
        fontSwitch.mFont = mFontHandle;
        while( --currChar > lastChar ) {
          if (( *currChar > 0x00FF ) && !IS_SPECIAL(*currChar))
            break;
        }
        running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
      }
      firstChar = currChar;
    }
  }
  else
  {
    while (running && firstChar > lastChar)
    {
      if ((*currChar >= 0x0080 && *currChar <= 0x00FF) || IS_SPECIAL(*currChar))
      { 
        if (!mWesternFont) {
          FindWesternFont();
        }
        fontSwitch.mFont = mWesternFont;
        while( --currChar > lastChar ) {
          if ((*currChar < 0x0080 || *currChar > 0x00FF) && !IS_SPECIAL(*currChar))
            break;
        }
        running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
      }
      else
      {
         // Use currently selected font
        fontSwitch.mFont = mFontHandle;
        while( --currChar > lastChar ) {
          if ((*currChar >= 0x0080 && *currChar <= 0x00FF) || IS_SPECIAL(*currChar))
            break;
        }
        running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
      }
      firstChar = currChar;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFontMetricsOS2::ResolveForwards ( HPS  aPS,
const PRUnichar aString,
PRUint32  aLength,
nsFontSwitchCallback  aFunc,
void aData 
) [virtual]

Reimplemented in nsFontMetricsOS2FT.

Definition at line 1714 of file nsFontMetricsOS2.cpp.

{
  NS_ASSERTION(aString || !aLength, "invalid call");
  const PRUnichar* firstChar = aString;
  const PRUnichar* currChar = firstChar;
  const PRUnichar* lastChar  = aString + aLength;
  PRBool running = PR_TRUE;

  nsFontSwitch fontSwitch;
  fontSwitch.mFont = 0;

  if (mConvertCodePage == 1252)
  {
    while (running && firstChar < lastChar)
    {
      if ((*currChar > 0x00FF) && !IS_SPECIAL(*currChar))
      {
        if (!mUnicodeFont) {
          FindUnicodeFont(aPS);
          if (!mUnicodeFont) {
            mUnicodeFont = FindGlobalFont(aPS, *currChar);
          }
        }
        fontSwitch.mFont = mUnicodeFont;
        while( ++currChar < lastChar ) {
          if (( *currChar <= 0x00FF ) || IS_SPECIAL(*currChar))
            break;
        }
        running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
      } else {
        // Use currently selected font
        fontSwitch.mFont = mFontHandle;
        while( ++currChar < lastChar ) {
          if (( *currChar > 0x00FF ) && !IS_SPECIAL(*currChar))
            break;
        }
        running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
      }
      firstChar = currChar;
    }
  }
  else
  {
    while (running && firstChar < lastChar)
    {
      if ((*currChar >= 0x0080 && *currChar <= 0x00FF) || IS_SPECIAL_WO_ELLIPSE(*currChar))
      { 
        if (!mWesternFont) {
          FindWesternFont();
        }
        fontSwitch.mFont = mWesternFont;
        while( ++currChar < lastChar ) {
          if ((*currChar < 0x0080 || *currChar > 0x00FF) && !IS_SPECIAL_WO_ELLIPSE(*currChar))
            break;
        }
        running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
      } else {
        // Use currently selected font
        fontSwitch.mFont = mFontHandle;
        while( ++currChar < lastChar ) {
          if ((*currChar >= 0x0080 && *currChar <= 0x00FF) || IS_SPECIAL_WO_ELLIPSE(*currChar))
            break;
        }
        running = (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
      }
      firstChar = currChar;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsFontOS2 * nsFontMetricsOS2::SetFontHandle ( HPS  aPS,
GlobalFontEntry aEntry,
nsMiniMetrics aMetrics,
PRBool  aDoFakeEffects 
) [protected]

Definition at line 424 of file nsFontMetricsOS2.cpp.

{
  nsFontOS2* font;
#ifdef USE_FREETYPE
  if (gUseFTFunctions) {
    font = new nsFontOS2FT();
  } else
#endif
  {
    font = new nsFontOS2();
  }

  strcpy(font->mFattrs.szFacename, aMetrics->szFacename);
  if (aMetrics->fsDefn & FM_DEFN_OUTLINE ||
      !mDeviceContext->SupportsRasterFonts()) {
    font->mFattrs.fsFontUse = FATTR_FONTUSE_OUTLINE |
                               FATTR_FONTUSE_TRANSFORMABLE;
  }
  if (aMetrics->fsType & FM_TYPE_MBCS)
    font->mFattrs.fsType |= FATTR_TYPE_MBCS;
  if (aMetrics->fsType & FM_TYPE_DBCS)
    font->mFattrs.fsType |= FATTR_TYPE_DBCS;

  if (aDoFakeEffects) {
    // fake the effects
    if (mFont.weight > NS_FONT_WEIGHT_NORMAL)
      font->mFattrs.fsSelection |= FATTR_SEL_BOLD;
    if (mFont.style & (NS_FONT_STYLE_ITALIC | NS_FONT_STYLE_OBLIQUE))
      font->mFattrs.fsSelection |= FATTR_SEL_ITALIC;
  }

#ifdef USE_FREETYPE
  // We only want to set the codepage in the freetype case if the codepage for
  // the font is 65400 (a symbol font).
  if (!gUseFTFunctions || aEntry->mCodePage == 65400)
#endif
    font->mFattrs.usCodePage = aEntry->mCodePage;

#ifdef PERF_HASGLYPH_CHAR_MAP
  if (gUseFTFunctions) {
    if (aEntry->mHaveCheckedCharMap == nsnull) {
      aEntry->mHaveCheckedCharMap = (PRUint32*)calloc(UCS2_MAP_LEN, sizeof(PRUint32));
      aEntry->mRepresentableCharMap = (PRUint32*)calloc(UCS2_MAP_LEN, sizeof(PRUint32));
    }
    font->mHaveCheckedCharMap = aEntry->mHaveCheckedCharMap;
    font->mRepresentableCharMap = aEntry->mRepresentableCharMap;
  }
#endif

  float app2dev, reqEmHeight;
  app2dev = mDeviceContext->AppUnitsToDevUnits();
  reqEmHeight = mFont.size * app2dev;

  FATTRS* fattrs = &(font->mFattrs);
  if (fattrs->fsFontUse == 0)  // if image font
  {
    long lFonts = 0;
    FONTMETRICS* pMetrics = getMetrics( lFonts, fattrs->szFacename, aPS);

    int reqPointSize = NSTwipsToIntPoints(mFont.size);
    int browserRes = mDeviceContext->GetDPI();

    int minSize = 99, maxSize = 0, curEmHeight = 0;
    for (int i = 0; i < lFonts; i++)
    {
      // If we are asked for a specific point size for which we have an
      // appropriate font, use it.  This avoids us choosing an incorrect
      // size due to rounding issues
      if (pMetrics[i].sYDeviceRes == browserRes &&
          pMetrics[i].sNominalPointSize / 10 == reqPointSize)
      {
        // image face found fine, set required size in fattrs.
        curEmHeight = pMetrics[i].lEmHeight;
        fattrs->lMaxBaselineExt = pMetrics[i].lMaxBaselineExt;
        fattrs->lAveCharWidth = pMetrics[i].lAveCharWidth;
        minSize = maxSize = pMetrics[i].lEmHeight;
        break;
      }
      else
      {
        if (fabs(pMetrics[i].lEmHeight - reqEmHeight) < 
            fabs(curEmHeight - reqEmHeight))
        {
          curEmHeight = pMetrics[i].lEmHeight;
          fattrs->lMaxBaselineExt = pMetrics[i].lMaxBaselineExt;
          fattrs->lAveCharWidth = pMetrics[i].lAveCharWidth;
        }
        else if (fabs(pMetrics[i].lEmHeight - reqEmHeight) == 
                 fabs(curEmHeight - reqEmHeight))
        {
          if ((pMetrics[i].lEmHeight) > curEmHeight)
          {
            curEmHeight = pMetrics[i].lEmHeight;
            fattrs->lMaxBaselineExt = pMetrics[i].lMaxBaselineExt;
            fattrs->lAveCharWidth = pMetrics[i].lAveCharWidth;
          }
        }
      }
      
      // record the min/max point size available for given font
      if (pMetrics[i].lEmHeight > maxSize)
        maxSize = pMetrics[i].lEmHeight;
      if (pMetrics[i].lEmHeight < minSize)
        minSize = pMetrics[i].lEmHeight;
    }

    nsMemory::Free(pMetrics);
    
    // Enable font substitution if the requested size is outside of the range
    //  of available sizes by more than 3
    if (reqEmHeight < minSize - 3 ||
        reqEmHeight > maxSize + 3)
    {
      // If the browser.display.substitute_vector_fonts pref is set, then we
      //  exchange Times New Roman for Tms Rmn and Helvetica for Helv if the 
      //  requested points size is less than the minimum or more than the 
      //  maximum point size available for Tms Rmn and Helv.
      nsAutoString alias;
      if (gSubstituteVectorFonts &&
          GetVectorSubstitute(aPS, aEntry->GetKey(), alias))
      {
        strcpy(fattrs->szFacename, NS_LossyConvertUCS2toASCII(alias).get());
        fattrs->fsFontUse = FATTR_FONTUSE_OUTLINE | FATTR_FONTUSE_TRANSFORMABLE;
        fattrs->fsSelection &= ~(FM_SEL_BOLD | FM_SEL_ITALIC);
      }
    }
    
    if (fattrs->fsFontUse == 0) {    // if still image font
      reqEmHeight = curEmHeight;
    }
  }

   // Add effects
  if (mFont.decorations & NS_FONT_DECORATION_UNDERLINE) {
    fattrs->fsSelection |= FATTR_SEL_UNDERSCORE;
  }
  if (mFont.decorations & NS_FONT_DECORATION_LINE_THROUGH) {
    fattrs->fsSelection |= FATTR_SEL_STRIKEOUT;
  }

#ifdef USE_FREETYPE
  if (!gUseFTFunctions)
#endif
  {
     // Encoding:
     //  There doesn't seem to be any encoding stuff yet, so guess.
     //  (XXX unicode hack; use same codepage as converter!)
    const char* langGroup;
    mLangGroup->GetUTF8String(&langGroup);
    for (int j=0; j < eCharset_COUNT; j++)
    {
      if (langGroup[0] == gCharsetInfo[j].mLangGroup[0])
      {
        if (!strcmp(langGroup, gCharsetInfo[j].mLangGroup))
        {
          mConvertCodePage = gCharsetInfo[j].mCodePage;
          break;
        }
      }
    }
  
    // Symbols fonts must be created with codepage 65400,
    // so use 65400 for the fattrs codepage. We still do
    // conversions with the charset codepage
    if (fattrs->usCodePage != 65400) {
      fattrs->usCodePage = mConvertCodePage;
    }
  }

  // set up the charbox;  set for image fonts also, in case we need to
  //  substitute a vector font later on (for UTF-8, etc)
  long lFloor = NSToIntFloor(reqEmHeight); 
  font->mCharbox.cx = MAKEFIXED(lFloor, (reqEmHeight - (float)lFloor) * 65536.0f);
  font->mCharbox.cy = font->mCharbox.cx;

  return font;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 287 of file nsFontMetricsOS2.h.

Definition at line 286 of file nsFontMetricsOS2.h.

Definition at line 288 of file nsFontMetricsOS2.h.

Definition at line 290 of file nsFontMetricsOS2.h.

Definition at line 337 of file nsFontMetricsOS2.h.

Definition at line 308 of file nsFontMetricsOS2.h.

Definition at line 340 of file nsFontMetricsOS2.h.

Definition at line 329 of file nsFontMetricsOS2.h.

Definition at line 330 of file nsFontMetricsOS2.h.

Definition at line 328 of file nsFontMetricsOS2.h.

Definition at line 326 of file nsFontMetricsOS2.h.

nsFont nsIFontMetrics::mFont [protected, inherited]

Definition at line 238 of file nsIFontMetrics.h.

Definition at line 339 of file nsFontMetricsOS2.h.

nsStringArray nsFontMetricsOS2::mFonts

Definition at line 294 of file nsFontMetricsOS2.h.

Definition at line 295 of file nsFontMetricsOS2.h.

Definition at line 301 of file nsFontMetricsOS2.h.

Definition at line 300 of file nsFontMetricsOS2.h.

Definition at line 327 of file nsFontMetricsOS2.h.

Definition at line 306 of file nsFontMetricsOS2.h.

Definition at line 293 of file nsFontMetricsOS2.h.

Definition at line 296 of file nsFontMetricsOS2.h.

Definition at line 334 of file nsFontMetricsOS2.h.

Definition at line 332 of file nsFontMetricsOS2.h.

Definition at line 333 of file nsFontMetricsOS2.h.

Definition at line 331 of file nsFontMetricsOS2.h.

Definition at line 335 of file nsFontMetricsOS2.h.

Definition at line 322 of file nsFontMetricsOS2.h.

Definition at line 323 of file nsFontMetricsOS2.h.

Definition at line 321 of file nsFontMetricsOS2.h.

Definition at line 320 of file nsFontMetricsOS2.h.

Definition at line 304 of file nsFontMetricsOS2.h.

Definition at line 305 of file nsFontMetricsOS2.h.

Definition at line 324 of file nsFontMetricsOS2.h.

Definition at line 325 of file nsFontMetricsOS2.h.

Definition at line 297 of file nsFontMetricsOS2.h.

Definition at line 302 of file nsFontMetricsOS2.h.

Definition at line 298 of file nsFontMetricsOS2.h.

Definition at line 336 of file nsFontMetricsOS2.h.


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