Back to index

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

#include <nsFontMetricsMac.h>

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

List of all members.

Public Member Functions

 nsFontMetricsMac ()
virtual ~nsFontMetricsMac ()
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS 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 GetNormalLineHeight (nscoord &aHeight)
 Returns the normal line height (em height + leading).
NS_IMETHOD GetLeading (nscoord &aLeading)
 Returns the amount of internal leading (in app units) for the font.
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 GetAveCharWidth (nscoord &aAveCharWidth)
 Returns the average character width.
NS_IMETHOD GetWidths (const nscoord *&aWidths)
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 GetSpaceWidth (nscoord &aSpaceCharWidth)
 Returns the often needed width of the space character.
virtual PRInt32 GetMaxStringLength ()
nsUnicodeFontMappingMacGetUnicodeFontMapping ()
const nsFontFont ()
 Returns the font associated with these metrics.

Protected Member Functions

void RealizeFont ()

Protected Attributes

short mFontNum
nsUnicodeFontMappingMacmFontMapping
nscoord mEmHeight
nscoord mEmAscent
nscoord mEmDescent
nscoord mMaxHeight
nscoord mLeading
nscoord mMaxAscent
nscoord mMaxDescent
nscoord mMaxAdvance
nscoord mAveCharWidth
nscoord mSpaceWidth
nscoord mXHeight
PRInt32 mMaxStringLength
nsCOMPtr< nsIAtommLangGroup
nsIDeviceContextmContext
nsFont mFont

Detailed Description

Definition at line 53 of file nsFontMetricsMac.h.


Constructor & Destructor Documentation

Definition at line 48 of file nsFontMetricsMac.cpp.

Definition at line 54 of file nsFontMetricsMac.cpp.

{
  if (mContext) {
    // Notify our device context that owns us so that it can update its font cache
    mContext->FontMetricsDeleted(this);
    mContext = nsnull;
  }
  if (mFontMapping) {
    delete mFontMapping;
  }
}

Here is the call graph for this function:


Member Function Documentation

Destroy this font metrics.

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

Implements nsIFontMetrics.

Definition at line 254 of file nsFontMetricsMac.cpp.

{
  mContext = nsnull;
  return NS_OK;
}
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 371 of file nsFontMetricsMac.cpp.

{
  aAveCharWidth = mAveCharWidth;
  return NS_OK;
}

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

Implements nsIFontMetrics.

Definition at line 333 of file nsFontMetricsMac.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 340 of file nsFontMetricsMac.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 326 of file nsFontMetricsMac.cpp.

{
  aHeight = mEmHeight;
  return NS_OK;
}

Returns the font handle associated with these metrics.

Implements nsIFontMetrics.

Definition at line 406 of file nsFontMetricsMac.cpp.

{
       // NOTE: the name in the mFont may be a comma-separated list of
       // font names, like "Verdana, Arial, sans-serif"
       // If you want to do the conversion again to a Mac font, you'll
       // have to EnumerateFamilies() to resolve it to an installed
       // font again.
       NS_PRECONDITION(mFontNum != BAD_FONT_NUM, "Font metrics have not been initialized");
       
       // We have no 'font handles' on Mac like they have on Windows
       // so let's use it for the fontNum.
       aHandle = (nsFontHandle)mFontNum;
       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 307 of file nsFontMetricsMac.cpp.

{
  aHeight = mMaxHeight;
  return NS_OK;
}

Returns the language group associated with these metrics.

Implements nsIFontMetrics.

Definition at line 388 of file nsFontMetricsMac.cpp.

{
  if (!aLangGroup) {
    return NS_ERROR_NULL_POINTER;
  }

  *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 319 of file nsFontMetricsMac.cpp.

{
  aLeading = mLeading;
  return NS_OK;
}

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

Implements nsIFontMetrics.

Definition at line 365 of file nsFontMetricsMac.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 353 of file nsFontMetricsMac.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 359 of file nsFontMetricsMac.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 347 of file nsFontMetricsMac.cpp.

{
  aHeight = mMaxHeight;
  return NS_OK;
}

Definition at line 377 of file nsFontMetricsMac.cpp.

{
  return mMaxStringLength;
}

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

Implements nsIFontMetrics.

Definition at line 313 of file nsFontMetricsMac.cpp.

{
  aHeight = mEmHeight + mLeading; // Mac's leading is external leading
  return NS_OK;
}
nsresult nsFontMetricsMac::GetSpaceWidth ( nscoord aSpaceCharWidth) [virtual]

Returns the often needed width of the space character.

Implements nsIFontMetrics.

Definition at line 382 of file nsFontMetricsMac.cpp.

{
  aSpaceWidth = mSpaceWidth;
  return NS_OK;
}
NS_IMETHODIMP nsFontMetricsMac::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 288 of file nsFontMetricsMac.cpp.

{
  float  dev2app;
  dev2app = mContext->DevUnitsToAppUnits();
  aOffset = NSToCoordRound(float(mMaxAscent / 2) - dev2app);
  aSize = NSToCoordRound(dev2app);
  return NS_OK;
}

Here is the call graph for this function:

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 279 of file nsFontMetricsMac.cpp.

{
  float  dev2app;
  dev2app = mContext->DevUnitsToAppUnits();
  aResult = NSToCoordRound(float(mMaxAscent / 2) - dev2app);
  return NS_OK;
}

Here is the call graph for this function:

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 270 of file nsFontMetricsMac.cpp.

{
  float  dev2app;
  dev2app = mContext->DevUnitsToAppUnits();
  aResult = NSToCoordRound(float(mMaxAscent / 2) - dev2app);
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsFontMetricsMac::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 298 of file nsFontMetricsMac.cpp.

{
  float  dev2app;
  dev2app = mContext->DevUnitsToAppUnits();
  aOffset = -NSToCoordRound( dev2app );
  aSize   = NSToCoordRound( dev2app );
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 121 of file nsFontMetricsMac.cpp.

{
  if (!mFontMapping)
  {
       // we should pass the documentCharset from the nsIDocument level and
       // the lang attribute from the tag level to here.
       // XXX hard code to some value till peterl pass them down.
       nsAutoString langGroup;
       if (mLangGroup)
              mLangGroup->ToString(langGroup);
    else
      langGroup.AssignLiteral("ja");
      
       nsString lang;
    mFontMapping = new nsUnicodeFontMappingMac(&mFont, mContext, langGroup, lang);
  }
  
       return mFontMapping;
}

Here is the caller graph for this function:

Definition at line 401 of file nsFontMetricsMac.cpp.

{
  return NS_ERROR_NOT_IMPLEMENTED; //XXX
}

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

Implements nsIFontMetrics.

Definition at line 263 of file nsFontMetricsMac.cpp.

{
  aResult = mXHeight;
  return NS_OK;
}
NS_IMETHODIMP nsFontMetricsMac::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 71 of file nsFontMetricsMac.cpp.

{
  NS_ASSERTION(!(nsnull == aCX), "attempt to init fontmetrics with null device context");

  mFont = aFont;
  mLangGroup = aLangGroup;
  mContext = aCX;
  RealizeFont();
       
       TextStyle            theStyle;
       nsFontUtils::GetNativeTextStyle(*this, *mContext, theStyle);
       
  StTextStyleSetter styleSetter(theStyle);
  
  FontInfo fInfo;
  GetFontInfo(&fInfo);
  
  float  dev2app;
  dev2app = mContext->DevUnitsToAppUnits();

  mLeading    = NSToCoordRound(float(fInfo.leading) * dev2app);
  mEmAscent   = NSToCoordRound(float(fInfo.ascent) * dev2app);
  mEmDescent  = NSToCoordRound(float(fInfo.descent) * dev2app);
  mEmHeight   = mEmAscent + mEmDescent;

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

  float maxCharWidth = float(::CharWidth('M'));  // don't use fInfo.widMax here
  mMaxAdvance = NSToCoordRound(maxCharWidth * dev2app);
  // If we try to measure draw more than ~32767 pixels
  // in one operation, the string may not be drawn:
  mMaxStringLength = PR_MAX(1, (PRInt32)floor(32767.0 / maxCharWidth));

  mAveCharWidth = NSToCoordRound(float(::CharWidth('x')) * dev2app);  
  mSpaceWidth = NSToCoordRound(float(::CharWidth(' ')) * dev2app);

  Point frac;
  frac.h = frac.v = 1;
  unsigned char x = 'x';
  short ascent;
  if (noErr == ::OutlineMetrics(1, &x, frac, frac, &ascent, 0, 0, 0, 0))
    mXHeight = NSToCoordRound(float(ascent) * dev2app);
  else
    mXHeight = NSToCoordRound(float(mMaxAscent) * 0.71f); // 0.71 = 5 / 7

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 223 of file nsFontMetricsMac.cpp.

{
       nsAutoString  fontName;
       nsUnicodeMappingUtil *unicodeMappingUtil;
       ScriptCode                         theScriptCode;

       unicodeMappingUtil = nsUnicodeMappingUtil::GetSingleton ();
       if (unicodeMappingUtil)
       {
              nsAutoString  theLangGroupString;

              if (mLangGroup)
                     mLangGroup->ToString(theLangGroupString);
              else
                     theLangGroupString.AssignLiteral("ja");

              theScriptCode = unicodeMappingUtil->MapLangGroupToScriptCode(
                  NS_ConvertUCS2toUTF8(theLangGroupString).get());

       }
       else
              theScriptCode = GetScriptManagerVariable (smSysScript);

       FontEnumData  fontData(mContext, fontName, theScriptCode);
       mFont.EnumerateFamilies(FontEnumCallback, &fontData);
  
       nsDeviceContextMac::GetMacFontNumber(fontName, mFontNum);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 103 of file nsFontMetricsMac.h.

Definition at line 108 of file nsFontMetricsMac.h.

Definition at line 96 of file nsFontMetricsMac.h.

Definition at line 97 of file nsFontMetricsMac.h.

Definition at line 95 of file nsFontMetricsMac.h.

nsFont nsIFontMetrics::mFont [protected, inherited]

Definition at line 238 of file nsIFontMetrics.h.

Definition at line 94 of file nsFontMetricsMac.h.

short nsFontMetricsMac::mFontNum [protected]

Definition at line 93 of file nsFontMetricsMac.h.

Definition at line 107 of file nsFontMetricsMac.h.

Definition at line 99 of file nsFontMetricsMac.h.

Definition at line 102 of file nsFontMetricsMac.h.

Definition at line 100 of file nsFontMetricsMac.h.

Definition at line 101 of file nsFontMetricsMac.h.

Definition at line 98 of file nsFontMetricsMac.h.

Definition at line 106 of file nsFontMetricsMac.h.

Definition at line 104 of file nsFontMetricsMac.h.

Definition at line 105 of file nsFontMetricsMac.h.


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