Back to index

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

#include <nsRegressionTestFontMetrics.h>

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

List of all members.

Public Member Functions

virtual ~nsRegressionTestFontMetrics ()
NS_DECL_ISUPPORTS NS_IMETHOD Init (const nsFont &aFont, nsIDeviceContext *aContext)
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 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 GetFontHandle (nsFontHandle &aHandle)
 Returns the font handle associated with these metrics.
NS_METHOD GetWidth (const char aChar, nscoord &aWidth)
 This routine determines a character width without relying on the underlying OS.
NS_METHOD GetWidth (const PRUnichar aChar, nscoord &aWidth)
 This routine determines a character width without relying on the underlying OS.
NS_METHOD GetWidth (const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth)
 This routine determines width of a string without relying on the underlying OS.
NS_METHOD GetWidth (const char *aString, PRUint32 aLength, nscoord &aWidth)
 This routine determines width of a string without relying on the underlying OS.
NS_IMETHOD Init (const nsFont &aFont, nsIAtom *aLangGroup, nsIDeviceContext *aContext)=0
 Initialize the font metrics.
NS_IMETHOD GetNormalLineHeight (nscoord &aHeight)=0
 Returns the normal line height (em height + leading).
NS_IMETHOD GetEmHeight (nscoord &aHeight)=0
 Returns the height (in app units) of the Western font's em square.
NS_IMETHOD GetEmAscent (nscoord &aAscent)=0
 Returns, in app units, the ascent part of the Western font's em square.
NS_IMETHOD GetEmDescent (nscoord &aDescent)=0
 Returns, in app units, the descent part of the Western font's em square.
NS_IMETHOD GetMaxHeight (nscoord &aHeight)=0
 Returns the height (in app units) of the Western font's bounding box.
const nsFontFont ()
 Returns the font associated with these metrics.
NS_IMETHOD GetLangGroup (nsIAtom **aLangGroup)=0
 Returns the language group associated with these metrics.
NS_IMETHOD GetAveCharWidth (nscoord &aAveCharWidth)=0
 Returns the average character width.
NS_IMETHOD GetSpaceWidth (nscoord &aSpaceCharWidth)=0
 Returns the often needed width of the space character.

Protected Member Functions

 nsRegressionTestFontMetrics ()
void RealizeFont ()

Protected Attributes

nsIDeviceContextmDeviceContext
nscoord mHeight
nscoord mAscent
nscoord mDescent
nscoord mLeading
nscoord mMaxAscent
nscoord mMaxDescent
nscoord mMaxAdvance
nscoord mXHeight
nscoord mSuperscriptOffset
nscoord mSubscriptOffset
nscoord mStrikeoutSize
nscoord mStrikeoutOffset
nscoord mUnderlineSize
nscoord mUnderlineOffset
nsFont mFont

Friends

nsresult NS_NewRegressionTestFontMetrics (nsIFontMetrics **aMetrics)

Detailed Description

Definition at line 47 of file nsRegressionTestFontMetrics.h.


Constructor & Destructor Documentation

Definition at line 83 of file nsRegressionTestFontMetrics.cpp.


Member Function Documentation

Destroy this font metrics.

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

Implements nsIFontMetrics.

Definition at line 99 of file nsRegressionTestFontMetrics.cpp.

{
  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_IMETHOD nsIFontMetrics::GetAveCharWidth ( nscoord aAveCharWidth) [pure virtual, inherited]
NS_IMETHOD nsIFontMetrics::GetEmAscent ( nscoord aAscent) [pure virtual, inherited]
NS_IMETHOD nsIFontMetrics::GetEmDescent ( nscoord aDescent) [pure virtual, inherited]
NS_IMETHOD nsIFontMetrics::GetEmHeight ( nscoord aHeight) [pure virtual, inherited]

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

This is em ascent plus em descent.

Implemented in nsFontMetricsXlib, nsFontMetricsGTK, nsFontMetricsOS2, nsFontMetricsWin, nsFontMetricsQt, nsFontMetricsPh, nsFontMetricsXft, nsFontMetricsXft, nsFontMetricsPango, nsFontMetricsPS, nsFontMetricsBeOS, nsFontMetricsMac, and nsCairoFontMetrics.

Here is the caller graph for this function:

Returns the font handle associated with these metrics.

Implements nsIFontMetrics.

Definition at line 337 of file nsRegressionTestFontMetrics.cpp.

{
  //We don't have a font handler
  aHandle = NULL;
  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 303 of file nsRegressionTestFontMetrics.cpp.

{
  aHeight = mHeight;
  return NS_OK;
}
NS_IMETHOD nsIFontMetrics::GetLangGroup ( nsIAtom **  aLangGroup) [pure virtual, inherited]

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 310 of file nsRegressionTestFontMetrics.cpp.

{
  aLeading = mLeading;
  return NS_OK;
}

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

Implements nsIFontMetrics.

Definition at line 331 of file nsRegressionTestFontMetrics.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 317 of file nsRegressionTestFontMetrics.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 324 of file nsRegressionTestFontMetrics.cpp.

{
  aDescent = mMaxDescent;
  return NS_OK;
}
NS_IMETHOD nsIFontMetrics::GetMaxHeight ( nscoord aHeight) [pure virtual, inherited]

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

This is max ascent plus max descent.

Implemented in nsFontMetricsXlib, nsFontMetricsGTK, nsFontMetricsOS2, nsFontMetricsWin, nsFontMetricsPh, nsFontMetricsQt, nsFontMetricsXft, nsFontMetricsXft, nsFontMetricsPango, nsFontMetricsPS, nsFontMetricsBeOS, nsFontMetricsMac, and nsCairoFontMetrics.

NS_IMETHOD nsIFontMetrics::GetNormalLineHeight ( nscoord aHeight) [pure virtual, inherited]

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

Implemented in nsFontMetricsXlib, nsFontMetricsGTK, nsFontMetricsOS2, nsFontMetricsWin, nsFontMetricsQt, nsFontMetricsPh, nsFontMetricsXft, nsFontMetricsXft, nsFontMetricsPS, nsFontMetricsPango, nsCairoFontMetrics, nsFontMetricsBeOS, and nsFontMetricsMac.

Here is the caller graph for this function:

NS_IMETHOD nsIFontMetrics::GetSpaceWidth ( nscoord aSpaceCharWidth) [pure virtual, inherited]

Returns the often needed width of the space character.

Implemented in nsFontMetricsXlib, nsFontMetricsGTK, nsFontMetricsOS2, nsFontMetricsWin, nsFontMetricsPh, nsFontMetricsQt, nsFontMetricsXft, nsFontMetricsXft, nsFontMetricsPango, nsFontMetricsPS, nsFontMetricsBeOS, nsFontMetricsMac, and nsCairoFontMetrics.

Here is the caller graph for this function:

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 287 of file nsRegressionTestFontMetrics.cpp.

{
  aOffset = mStrikeoutOffset;
  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 280 of file nsRegressionTestFontMetrics.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 273 of file nsRegressionTestFontMetrics.cpp.

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 295 of file nsRegressionTestFontMetrics.cpp.

{
  aOffset = mUnderlineOffset;
  aSize = mUnderlineSize;
  return NS_OK;
}

This routine determines a character width without relying on the underlying OS.

harishd 02/07/1999

Parameters:
aChar-- A valid character whose width needs to be computed
aWidth-- Holds the computed character width

Definition at line 147 of file nsRegressionTestFontMetrics.cpp.

{
  float size = (float)mFont.size;
  aWidth = 0;

  if(aChar == ' ')
    size *= MAPPING_FACTOR_FOR_SPACE;
  else if(aChar >= 'a' && aChar <= 'z')
    size *= MAPPING_FACTOR_FOR_LOWER_CASE;
  else
    size *= MAPPING_FACTOR_FOR_OTHERS;
    
  aWidth = NSToCoordRound(size);

  return NS_OK;
}

Here is the call graph for this function:

This routine determines a character width without relying on the underlying OS.

harishd 02/07/1999

Parameters:
aChar-- A valid character whose width needs to be computed
aWidth-- Holds the computed character width

Definition at line 174 of file nsRegressionTestFontMetrics.cpp.

{
  float size = (float)mFont.size;
  aWidth = 0;

  if(aChar == ' ')
    size *= MAPPING_FACTOR_FOR_SPACE;
  else if(aChar >= 'a' && aChar <= 'z')
    size *= MAPPING_FACTOR_FOR_LOWER_CASE;
  else 
    size *= MAPPING_FACTOR_FOR_OTHERS;
      
  aWidth = NSToCoordRound(size);

  return NS_OK;
}

Here is the call graph for this function:

This routine determines width of a string without relying on the underlying OS.

harishd 02/07/1999

Parameters:
aString-- A string whose width needs to be computed
aLength-- Length of the string
aWidth-- Holds the computed string width
Returns:
error code -- 0 if success, non-zero if error

Definition at line 204 of file nsRegressionTestFontMetrics.cpp.

{
  aWidth = 0;
  
  if(aString == nsnull)
    return NS_ERROR_NULL_POINTER;
  
  float size;
  float totalsize = 0;
  
  for(PRUint32 index = 0; index < aLength; index++){
    size = (float)mFont.size;
    if(aString[index] == ' ')
      size *= MAPPING_FACTOR_FOR_SPACE;
    else if(aString[index] >= 'a' && aString[index] <= 'z')
      size *= MAPPING_FACTOR_FOR_LOWER_CASE;
    else 
      size *= MAPPING_FACTOR_FOR_OTHERS;
    totalsize += size;    
  }
  aWidth = NSToCoordRound(totalsize);
  return NS_OK;
}

Here is the call graph for this function:

NS_METHOD nsRegressionTestFontMetrics::GetWidth ( const char *  aString,
PRUint32  aLength,
nscoord aWidth 
)

This routine determines width of a string without relying on the underlying OS.

harishd 02/07/1999

Parameters:
aString-- A string whose width needs to be computed
aLength-- Length of the string
aWidth-- Holds the computed string width
Returns:
error code -- 0 if success, non-zero if error

Definition at line 241 of file nsRegressionTestFontMetrics.cpp.

{
  aWidth = 0;

  if(aString == nsnull)
    return NS_ERROR_NULL_POINTER;
  
  float size;
  float totalsize = 0;
 
  for(PRUint32 index=0; index < aLength; index++){
    size = (float)mFont.size;
    if(aString[index] == ' ')
      size *= MAPPING_FACTOR_FOR_SPACE;
    else if(aString[index] >= 'a' && aString[index] <= 'z')
      size *= MAPPING_FACTOR_FOR_LOWER_CASE;
    else
      size *= MAPPING_FACTOR_FOR_OTHERS;
    totalsize += size;    
  }
  aWidth += NSToCoordRound(totalsize);
  return NS_OK;
}

Here is the call graph for this function:

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

Implements nsIFontMetrics.

Definition at line 266 of file nsRegressionTestFontMetrics.cpp.

{
  aResult = mXHeight;
  return NS_OK;
}

Definition at line 90 of file nsRegressionTestFontMetrics.cpp.

{
  mFont = aFont;
  mDeviceContext = aContext;
  RealizeFont();
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHOD nsIFontMetrics::Init ( const nsFont aFont,
nsIAtom aLangGroup,
nsIDeviceContext aContext 
) [pure virtual, inherited]

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()

Implemented in nsFontMetricsXlib, nsFontMetricsGTK, nsFontMetricsOS2, nsFontMetricsWin, nsFontMetricsQt, nsFontMetricsPS, nsFontMetricsXft, nsFontMetricsXft, nsFontMetricsBeOS, nsFontMetricsPh, nsFontMetricsPango, nsFontMetricsMac, and nsCairoFontMetrics.

Definition at line 106 of file nsRegressionTestFontMetrics.cpp.

{
  float dev2app;
  dev2app = mDeviceContext->DevUnitsToAppUnits();
  nscoord onepixel = NSToCoordRound(1 * dev2app);
  PRUint32 fontsize = mFont.size;
 
  // Most of the numbers are just made up....
  // feel free to play around.

  mHeight = fontsize;
  mXHeight = NSToCoordRound((float)mHeight * 0.50f);
  mSuperscriptOffset = mXHeight;
  mSubscriptOffset = mXHeight;
  mStrikeoutSize = onepixel;
  mStrikeoutOffset = NSToCoordRound(mXHeight / 3.5f);

  
  mAscent = NSToCoordRound((float)fontsize * 0.60f);
  mDescent = NSToCoordRound((float)fontsize * 0.20f);

  mLeading = NSToCoordRound((float)fontsize * 0.10f);
  mMaxAscent = mAscent;
  mMaxDescent = mDescent;
  mMaxAdvance = NSToCoordRound((float)fontsize * 0.80f);
  mUnderlineSize = onepixel;
  mUnderlineOffset =  NSToCoordRound(fontsize / 100.0f);
  
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

Definition at line 46 of file nsRegressionTestFontMetrics.cpp.

{
  if (aMetrics == nsnull) {
    return NS_ERROR_NULL_POINTER;
  }

  nsRegressionTestFontMetrics  *fm = new nsRegressionTestFontMetrics();

  if (nsnull == fm) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  return CallQueryInterface(fm, aMetrics);
}

Member Data Documentation

Definition at line 83 of file nsRegressionTestFontMetrics.h.

Definition at line 84 of file nsRegressionTestFontMetrics.h.

Definition at line 81 of file nsRegressionTestFontMetrics.h.

nsFont nsIFontMetrics::mFont [protected, inherited]

Definition at line 238 of file nsIFontMetrics.h.

Definition at line 82 of file nsRegressionTestFontMetrics.h.

Definition at line 85 of file nsRegressionTestFontMetrics.h.

Definition at line 88 of file nsRegressionTestFontMetrics.h.

Definition at line 86 of file nsRegressionTestFontMetrics.h.

Definition at line 87 of file nsRegressionTestFontMetrics.h.

Definition at line 93 of file nsRegressionTestFontMetrics.h.

Definition at line 92 of file nsRegressionTestFontMetrics.h.

Definition at line 91 of file nsRegressionTestFontMetrics.h.

Definition at line 90 of file nsRegressionTestFontMetrics.h.

Definition at line 95 of file nsRegressionTestFontMetrics.h.

Definition at line 94 of file nsRegressionTestFontMetrics.h.

Definition at line 89 of file nsRegressionTestFontMetrics.h.


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