Back to index

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

#include <nsFontMetricsPh.h>

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

List of all members.

Public Member Functions

 nsFontMetricsPh ()
virtual ~nsFontMetricsPh ()
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_IMETHODIMP GetLangGroup (nsIAtom **aLangGroup)
 Returns the language group associated with these metrics.
NS_IMETHODIMP Destroy ()
 Destroy this font metrics.
NS_IMETHODIMP GetXHeight (nscoord &aResult)
 Return the font's xheight property, scaled into app-units.
NS_IMETHODIMP 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_IMETHODIMP GetHeight (nscoord &aHeight)
 Returns the height (in app units) of the font.
NS_IMETHODIMP GetNormalLineHeight (nscoord &aHeight)
 Returns the normal line height (em height + leading).
NS_IMETHODIMP GetLeading (nscoord &aLeading)
 Returns the amount of internal leading (in app units) for the font.
NS_IMETHODIMP GetEmHeight (nscoord &aHeight)
 Returns the height (in app units) of the Western font's em square.
NS_IMETHODIMP GetEmAscent (nscoord &aAscent)
 Returns, in app units, the ascent part of the Western font's em square.
NS_IMETHODIMP GetEmDescent (nscoord &aDescent)
 Returns, in app units, the descent part of the Western font's em square.
NS_IMETHODIMP GetMaxHeight (nscoord &aHeight)
 Returns the height (in app units) of the Western font's bounding box.
NS_IMETHODIMP GetMaxAscent (nscoord &aAscent)
 Returns, in app units, the maximum distance characters in this font extend above the base line.
NS_IMETHODIMP GetMaxDescent (nscoord &aDescent)
 Returns, in app units, the maximum distance characters in this font extend below the base line.
NS_IMETHODIMP GetMaxAdvance (nscoord &aAdvance)
 Returns, in app units, the maximum character advance for the font.
NS_IMETHODIMP GetAveCharWidth (nscoord &aAveCharWidth)
 Returns the average character width.
NS_IMETHODIMP GetFontHandle (nsFontHandle &aHandle)
 Returns the font handle associated with these metrics.
NS_IMETHODIMP GetSpaceWidth (nscoord &aSpaceWidth)
 Returns the often needed width of the space character.
virtual PRInt32 GetMaxStringLength ()
const nsFontFont ()
 Returns the font associated with these metrics.

Protected Member Functions

void RealizeFont ()

Protected Attributes

nsIDeviceContextmDeviceContext
char * mFontHandle
nscoord mHeight
nscoord mAscent
nscoord mDescent
nscoord mLeading
nscoord mEmHeight
nscoord mEmAscent
nscoord mEmDescent
nscoord mMaxHeight
nscoord mMaxAscent
nscoord mMaxDescent
nscoord mMaxAdvance
nscoord mXHeight
nscoord mSuperscriptOffset
nscoord mSubscriptOffset
nscoord mStrikeoutSize
nscoord mStrikeoutOffset
nscoord mUnderlineSize
nscoord mUnderlineOffset
nscoord mSpaceWidth
nscoord mAveCharWidth
nsCOMPtr< nsIAtommLangGroup
nsFont mFont

Detailed Description

Definition at line 53 of file nsFontMetricsPh.h.


Constructor & Destructor Documentation

Definition at line 118 of file nsFontMetricsPh.cpp.

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

Here is the call graph for this function:


Member Function Documentation

NS_IMETHODIMP nsFontMetricsPh::Destroy ( ) [inline, virtual]

Destroy this font metrics.

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

Implements nsIFontMetrics.

Definition at line 75 of file nsFontMetricsPh.h.

              {
              mDeviceContext = 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:

NS_IMETHODIMP nsFontMetricsPh::GetAveCharWidth ( nscoord aAveCharWidth) [inline, virtual]

Returns the average character width.

Implements nsIFontMetrics.

Definition at line 159 of file nsFontMetricsPh.h.

              {
              aAveCharWidth = mAveCharWidth;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetEmAscent ( nscoord aAscent) [inline, virtual]

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

Implements nsIFontMetrics.

Definition at line 129 of file nsFontMetricsPh.h.

              {
              aAscent = mEmAscent;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetEmDescent ( nscoord aDescent) [inline, virtual]

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

Implements nsIFontMetrics.

Definition at line 134 of file nsFontMetricsPh.h.

              {
              aDescent = mEmDescent;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetEmHeight ( nscoord aHeight) [inline, virtual]

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 124 of file nsFontMetricsPh.h.

              {
              aHeight = mEmHeight;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetFontHandle ( nsFontHandle aHandle) [inline, virtual]

Returns the font handle associated with these metrics.

Implements nsIFontMetrics.

Definition at line 164 of file nsFontMetricsPh.h.

NS_IMETHODIMP nsFontMetricsPh::GetHeight ( nscoord aHeight) [inline, virtual]

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 109 of file nsFontMetricsPh.h.

              {
              aHeight = mHeight;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetLangGroup ( nsIAtom **  aLangGroup) [inline, virtual]

Returns the language group associated with these metrics.

Implements nsIFontMetrics.

Definition at line 67 of file nsFontMetricsPh.h.

              {
              if( !aLangGroup ) return NS_ERROR_NULL_POINTER;
              *aLangGroup = mLangGroup;
              NS_IF_ADDREF(*aLangGroup);
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetLeading ( nscoord aLeading) [inline, virtual]

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 119 of file nsFontMetricsPh.h.

              {
              aLeading = mLeading;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetMaxAdvance ( nscoord aAdvance) [inline, virtual]

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

Implements nsIFontMetrics.

Definition at line 154 of file nsFontMetricsPh.h.

              {
              aAdvance = mMaxAdvance;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetMaxAscent ( nscoord aAscent) [inline, virtual]

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

Implements nsIFontMetrics.

Definition at line 144 of file nsFontMetricsPh.h.

              {
              aAscent = mMaxAscent;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetMaxDescent ( nscoord aDescent) [inline, virtual]

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

Implements nsIFontMetrics.

Definition at line 149 of file nsFontMetricsPh.h.

              {
              aDescent = mMaxDescent;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetMaxHeight ( nscoord aHeight) [inline, virtual]

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 139 of file nsFontMetricsPh.h.

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

Definition at line 175 of file nsFontMetricsPh.h.

{ return PR_INT32_MAX; }

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

Implements nsIFontMetrics.

Definition at line 114 of file nsFontMetricsPh.h.

              {
              aHeight = mEmHeight + mLeading;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetSpaceWidth ( nscoord aSpaceCharWidth) [inline, virtual]

Returns the often needed width of the space character.

Implements nsIFontMetrics.

Definition at line 169 of file nsFontMetricsPh.h.

              {
              aSpaceWidth = mSpaceWidth;
              return NS_OK;
              }
NS_IMETHOD nsFontMetricsPh::GetStrikeout ( nscoord aOffset,
nscoord aSize 
) [inline, 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 96 of file nsFontMetricsPh.h.

              {
              aOffset = mStrikeoutOffset;
              aSize = mStrikeoutSize;
              return NS_OK;
              }
NS_IMETHOD nsFontMetricsPh::GetSubscriptOffset ( nscoord aResult) [inline, virtual]

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 91 of file nsFontMetricsPh.h.

              {
              aResult = mSubscriptOffset;
              return NS_OK;
              }

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 86 of file nsFontMetricsPh.h.

NS_IMETHOD nsFontMetricsPh::GetUnderline ( nscoord aOffset,
nscoord aSize 
) [inline, 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 102 of file nsFontMetricsPh.h.

              {
              aOffset = mUnderlineOffset;
              aSize = mUnderlineSize;
              return NS_OK;
              }
NS_IMETHODIMP nsFontMetricsPh::GetXHeight ( nscoord aResult) [inline, virtual]

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

Implements nsIFontMetrics.

Definition at line 81 of file nsFontMetricsPh.h.

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

{
       NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null device context");
       
       nsAutoString  firstFace;
       char          *str = nsnull;
       nsresult      result;
       PhRect_t      extent;

       if( !gFontMetricsCache ) {
              nsresult res = InitGlobals( );
              if( NS_FAILED(res) ) return res;
              }
       
       mFont = aFont;
       mLangGroup = aLangGroup;
       
       mDeviceContext = aContext;
       
       result = aContext->FirstExistingFont(aFont, firstFace);

       str = ToNewCString(firstFace);

#ifdef DEBUG_Adrian
printf( "\n\n\t\t\tIn nsFontMetricsPh::Init str=%s\n", str );
#endif

       if( !str || !str[0] )
       {
              if( str ) free (str);
              str = strdup("serif");
       }
       
       const char *cstring;
       aLangGroup->GetUTF8String( &cstring );
       
       char prop[256];
       sprintf( prop, "font.name.%s.%s", str, cstring );

       char *font_default = NULL;
       gPref->CopyCharPref( prop, &font_default );
       if( font_default )
              {
              free (str);
              /* font_default was allocated. in CopyCharPref. */
              str = font_default;
              }

       float app2dev;
       app2dev = mDeviceContext->AppUnitsToDevUnits();

       PRInt32 sizePoints;
       if( mFont.systemFont == PR_TRUE )
              sizePoints = NSToIntRound( app2dev * mFont.size * 0.68 );
       else
              sizePoints = NSToIntRound( app2dev * mFont.size * 0.74 );
       
       char NSFullFontName[MAX_FONT_TAG];

       unsigned int uiFlags = 0L;

       if(aFont.weight > NS_FONT_WEIGHT_NORMAL)
          uiFlags |= PF_STYLE_BOLD;

       if(aFont.style & (NS_FONT_STYLE_ITALIC|NS_FONT_STYLE_OBLIQUE) )
          uiFlags |= PF_STYLE_ITALIC;

       PRInt32 antialias_pref = 0;
       gPref->GetIntPref("font.antialias_qnx", &antialias_pref);
       if(antialias_pref || aFont.style & NS_FONT_STYLE_ANTIALIAS)
              uiFlags |= PF_STYLE_ANTIALIAS;

       if( PfGenerateFontName( (char *)str, uiFlags, sizePoints, (char *)NSFullFontName ) == NULL )
         {
#ifdef DEBUG_Adrian
printf( "!!!!!!!!!!!! PfGenerateFontName failed\n" );
#endif
                PfGenerateFontName( "TextFont", uiFlags, sizePoints, (char *)NSFullFontName );
         }

       /* Once the Photon Font String is built get the attributes */
       FontQueryInfo *node;

       nsCStringKey key((char *)(NSFullFontName));
       node = (FontQueryInfo *) gFontMetricsCache->Get(&key);

#ifdef DEBUG_Adrian
printf( "\t\t\tThe generated font name is NSFullFontName=%s\n", NSFullFontName );
if( node ) printf( "\t\t\t( cached ) The real font is desc=%s\n", node->desc );
#endif

       if( !node )
         {
              node = (FontQueryInfo *)calloc(sizeof(FontQueryInfo), 1);
              PfQueryFont(NSFullFontName, node);

#ifdef DEBUG_Adrian
printf( "\t\t\t(not cached ) The real font is desc=%s\n", node->desc );
printf( "\tCall PfLoadMetrics for NSFullFontName=%s\n", NSFullFontName );
#endif

              gFontMetricsCache->Put(&key, node);

              PfLoadMetrics( NSFullFontName );
         }

       float dev2app;
       double height;
       nscoord onePixel;

       dev2app = mDeviceContext->DevUnitsToAppUnits();
       onePixel = NSToCoordRound(1 * dev2app);
       height = node->descender - node->ascender;
       PfExtent( &extent, NULL, NSFullFontName, 0L, 0L, " ", 1, PF_SIMPLE_METRICS, NULL );
       mSpaceWidth = NSToCoordRound((extent.lr.x - extent.ul.x + 1) * dev2app);

       mLeading = NSToCoordRound(0);
       mEmHeight = NSToCoordRound(height * dev2app);
       mEmAscent = NSToCoordRound(node->ascender * dev2app * -1.0);
       mEmDescent = NSToCoordRound(node->descender * dev2app);
       mHeight = mMaxHeight = NSToCoordRound(height * dev2app);
       mAscent = mMaxAscent = NSToCoordRound(node->ascender * dev2app * -1.0);
       mDescent = mMaxDescent = NSToCoordRound(node->descender * dev2app);
       mMaxAdvance = NSToCoordRound(node->width * dev2app);
       mAveCharWidth = mSpaceWidth;

       mXHeight = NSToCoordRound((float)node->ascender * dev2app * 0.56f * -1.0); // 56% of ascent, best guess for non-true type
       mSuperscriptOffset = mXHeight;     // XXX temporary code!
       mSubscriptOffset = mXHeight;     // XXX temporary code!

       mStrikeoutSize = onePixel; // XXX this is a guess
       mStrikeoutOffset = NSToCoordRound(mXHeight / 2.0f); // 50% of xHeight
       mUnderlineSize = onePixel; // XXX this is a guess
       mUnderlineOffset = -NSToCoordRound((float)node->descender * dev2app * 0.30f); // 30% of descent

       if (mFontHandle)
          free (mFontHandle);
       mFontHandle = strdup(NSFullFontName);

       free (str);
       return NS_OK;
}

Here is the call graph for this function:

Definition at line 285 of file nsFontMetricsPh.cpp.

{
#ifdef DEBUG_Adrian
printf( "In RealizeFont\n" );
#endif
}

Member Data Documentation

Definition at line 183 of file nsFontMetricsPh.h.

Definition at line 201 of file nsFontMetricsPh.h.

Definition at line 184 of file nsFontMetricsPh.h.

Definition at line 180 of file nsFontMetricsPh.h.

Definition at line 187 of file nsFontMetricsPh.h.

Definition at line 188 of file nsFontMetricsPh.h.

Definition at line 186 of file nsFontMetricsPh.h.

nsFont nsIFontMetrics::mFont [protected, inherited]

Definition at line 238 of file nsIFontMetrics.h.

char* nsFontMetricsPh::mFontHandle [protected]

Definition at line 181 of file nsFontMetricsPh.h.

Definition at line 182 of file nsFontMetricsPh.h.

Definition at line 203 of file nsFontMetricsPh.h.

Definition at line 185 of file nsFontMetricsPh.h.

Definition at line 192 of file nsFontMetricsPh.h.

Definition at line 190 of file nsFontMetricsPh.h.

Definition at line 191 of file nsFontMetricsPh.h.

Definition at line 189 of file nsFontMetricsPh.h.

Definition at line 200 of file nsFontMetricsPh.h.

Definition at line 197 of file nsFontMetricsPh.h.

Definition at line 196 of file nsFontMetricsPh.h.

Definition at line 195 of file nsFontMetricsPh.h.

Definition at line 194 of file nsFontMetricsPh.h.

Definition at line 199 of file nsFontMetricsPh.h.

Definition at line 198 of file nsFontMetricsPh.h.

Definition at line 193 of file nsFontMetricsPh.h.


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