#142562 problem with <td align=right or align=center

We are observing langGroup in some place while ignor it in others. This patch
make all font metrics call consistent. nsIRenderingContext API is change to
make things neat.
r=rbs, sr=waterson
This commit is contained in:
shanjian%netscape.com 2002-05-24 20:11:14 +00:00
parent da74c12aef
commit 7f5900aa67
54 changed files with 168 additions and 190 deletions

View File

@ -52,6 +52,7 @@ class nsTransform2D;
class nsString;
class nsIDeviceContext;
class nsIRegion;
class nsIAtom;
struct nsFont;
struct nsPoint;
@ -287,7 +288,7 @@ public:
* Sets the font for the RenderingContext
* @param aFont The font to use in the RenderingContext
*/
NS_IMETHOD SetFont(const nsFont& aFont) = 0;
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup) = 0;
/**
* Sets the font for the RenderingContext

View File

@ -659,10 +659,10 @@ NS_IMETHODIMP nsRenderingContextGTK::GetColor(nscolor &aColor) const
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextGTK::SetFont(const nsFont& aFont)
NS_IMETHODIMP nsRenderingContextGTK::SetFont(const nsFont& aFont, nsIAtom* aLangGroup)
{
nsCOMPtr<nsIFontMetrics> newMetrics;
nsresult rv = mContext->GetMetricsFor(aFont, *getter_AddRefs(newMetrics));
nsresult rv = mContext->GetMetricsFor(aFont, aLangGroup, *getter_AddRefs(newMetrics));
if (NS_SUCCEEDED(rv)) {
rv = SetFont(newMetrics);
}

View File

@ -108,7 +108,7 @@ public:
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont);
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);

View File

@ -801,13 +801,13 @@ NS_IMETHODIMP nsRenderingContextMac::GetLineStyle(nsLineStyle &aLineStyle)
//------------------------------------------------------------------------
NS_IMETHODIMP nsRenderingContextMac::SetFont(const nsFont& aFont)
NS_IMETHODIMP nsRenderingContextMac::SetFont(const nsFont& aFont, nsIAtom* aLangGroup)
{
NS_IF_RELEASE(mGS->mFontMetrics);
if (mContext)
mContext->GetMetricsFor(aFont, mGS->mFontMetrics);
mContext->GetMetricsFor(aFont, aLangGroup, mGS->mFontMetrics);
mChanges |= kFontChanged;
return NS_OK;

View File

@ -96,7 +96,7 @@ public:
NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont);
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
NS_IMETHOD Translate(nscoord aX, nscoord aY);

View File

@ -769,10 +769,10 @@ NS_IMETHODIMP nsRenderingContextOS2::GetLineStyle( nsLineStyle &aLineStyle)
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextOS2::SetFont( const nsFont &aFont)
NS_IMETHODIMP nsRenderingContextOS2::SetFont( const nsFont &aFont, nsIAtom* aLangGroup)
{
NS_IF_RELEASE( mFontMetrics);
mContext->GetMetricsFor( aFont, mFontMetrics);
mContext->GetMetricsFor( aFont, aLangGroup, mFontMetrics);
return NS_OK;
}

View File

@ -92,7 +92,7 @@ public:
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont);
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);

View File

@ -529,10 +529,11 @@ NS_IMETHODIMP nsRenderingContextPh :: GetLineStyle( nsLineStyle &aLineStyle )
}
NS_IMETHODIMP nsRenderingContextPh :: SetFont( const nsFont& aFont )
NS_IMETHODIMP nsRenderingContextPh :: SetFont( const nsFont& aFont, nsIAtom* aLangGroup )
{
nsIFontMetrics* newMetrics;
nsresult rv = mContext->GetMetricsFor( aFont, newMetrics );
nsresult rv = mContext->GetMetricsFor( aFont, aLangGroup, newMetrics );
if( NS_SUCCEEDED( rv ) ) {
rv = SetFont( newMetrics );
NS_RELEASE( newMetrics );

View File

@ -100,7 +100,7 @@ public:
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont);
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);

View File

@ -516,10 +516,11 @@ nsRenderingContextPS :: GetLineStyle(nsLineStyle &aLineStyle)
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS::SetFont(const nsFont& aFont)
nsRenderingContextPS::SetFont(const nsFont& aFont, nsIAtom* aLangGroup)
{
nsCOMPtr<nsIFontMetrics> newMetrics;
nsresult rv = mContext->GetMetricsFor(aFont, *getter_AddRefs(newMetrics));
nsresult rv = mContext->GetMetricsFor( aFont, aLangGroup, *getter_AddRefs(newMetrics) );
if (NS_SUCCEEDED(rv)) {
rv = SetFont(newMetrics);
}

View File

@ -104,7 +104,7 @@ public:
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont);
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);

View File

@ -523,10 +523,11 @@ NS_IMETHODIMP nsRenderingContextQT::GetColor(nscolor &aColor) const
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextQT::SetFont(const nsFont &aFont)
NS_IMETHODIMP nsRenderingContextQT::SetFont(const nsFont &aFont, nsIAtom* aLangGroup)
{
nsCOMPtr<nsIFontMetrics> newMetrics;
nsresult rv = mContext->GetMetricsFor(aFont,*getter_AddRefs(newMetrics));
nsresult rv = mContext->GetMetricsFor(aFont, aLangGroup, *getter_AddRefs(newMetrics));
if (NS_SUCCEEDED(rv)) {
rv = SetFont(newMetrics);
}

View File

@ -107,7 +107,7 @@ public:
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont);
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);

View File

@ -991,10 +991,10 @@ NS_IMETHODIMP nsRenderingContextWin :: GetLineStyle(nsLineStyle &aLineStyle)
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextWin :: SetFont(const nsFont& aFont)
NS_IMETHODIMP nsRenderingContextWin :: SetFont(const nsFont& aFont, nsIAtom* aLangGroup)
{
NS_IF_RELEASE(mFontMetrics);
mContext->GetMetricsFor(aFont, mFontMetrics);
mContext->GetMetricsFor(aFont, aLangGroup, mFontMetrics);
return NS_OK;
}

View File

@ -83,7 +83,7 @@ public:
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont);
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);

View File

@ -600,10 +600,11 @@ nsRenderingContextXlib::GetColor(nscolor &aColor) const
}
NS_IMETHODIMP
nsRenderingContextXlib::SetFont(const nsFont& aFont)
nsRenderingContextXlib::SetFont(const nsFont& aFont, nsIAtom* aLangGroup)
{
nsCOMPtr<nsIFontMetrics> newMetrics;
nsresult rv = mContext->GetMetricsFor(aFont, *getter_AddRefs(newMetrics));
nsresult rv = mContext->GetMetricsFor( aFont, aLangGroup, *getter_AddRefs(newMetrics) );
if (NS_SUCCEEDED(rv)) {
rv = SetFont(newMetrics);
}

View File

@ -106,7 +106,7 @@ public:
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
NS_IMETHOD SetFont(const nsFont& aFont);
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);

View File

@ -973,8 +973,14 @@ void nsCaret::DrawCaret()
if (frameRect.height == 0)
{
const nsStyleFont* fontStyle;
const nsStyleVisibility* vis;
mLastCaretFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)fontStyle);
mRendContext->SetFont(fontStyle->mFont);
mLastCaretFrame->GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis);
nsCOMPtr<nsIAtom> langGroup;
if (vis && vis->mLanguage)
vis->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
mRendContext->SetFont(fontStyle->mFont, langGroup);
nsCOMPtr<nsIFontMetrics> fm;
mRendContext->GetFontMetrics(*getter_AddRefs(fm));
if (fm)

View File

@ -973,8 +973,14 @@ void nsCaret::DrawCaret()
if (frameRect.height == 0)
{
const nsStyleFont* fontStyle;
const nsStyleVisibility* vis;
mLastCaretFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)fontStyle);
mRendContext->SetFont(fontStyle->mFont);
mLastCaretFrame->GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis);
nsCOMPtr<nsIAtom> langGroup;
if (vis && vis->mLanguage)
vis->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
mRendContext->SetFont(fontStyle->mFont, langGroup);
nsCOMPtr<nsIFontMetrics> fm;
mRendContext->GetFontMetrics(*getter_AddRefs(fm));
if (fm)

View File

@ -158,9 +158,7 @@ BRFrame::Reflow(nsIPresContext* aPresContext,
// We also do this in strict mode because BR should act like a
// normal inline frame. That line-height is used is important
// here for cases where the line-height is less that 1.
const nsStyleFont* font = (const nsStyleFont*)
mStyleContext->GetStyleData(eStyleStruct_Font);
aReflowState.rendContext->SetFont(font->mFont);
SetFontFromStyle(aReflowState.rendContext, mStyleContext);
nsCOMPtr<nsIFontMetrics> fm;
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
if (fm) {

View File

@ -224,6 +224,27 @@ nsIFrameDebug::RootFrameList(nsIPresContext* aPresContext, FILE* out, PRInt32 aI
#endif
// end nsIFrameDebug
// a handy utility to set font
void SetFontFromStyle(nsIRenderingContext* aRC, nsIStyleContext* aSC)
{
const nsStyleFont *font = (const nsStyleFont*)
aSC->GetStyleData(eStyleStruct_Font);
NS_ASSERTION(font, "invalid font in style context");
if (font) {
const nsStyleVisibility* visibility = (const nsStyleVisibility*)
aSC->GetStyleData(eStyleStruct_Visibility);
NS_ASSERTION(visibility, "invalid visibility in style context");
nsCOMPtr<nsIAtom> langGroup;
if (visibility && visibility->mLanguage) {
visibility->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
}
aRC->SetFont(font->mFont, langGroup);
}
}
nsresult
NS_NewEmptyFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{

View File

@ -111,6 +111,8 @@
#define NS_FRAME_TRACE_REFLOW_OUT(_method, _status)
#endif
// handy utilities
extern void SetFontFromStyle(nsIRenderingContext* aRC, nsIStyleContext* aSC);
//----------------------------------------------------------------------

View File

@ -2378,7 +2378,7 @@ nsHTMLReflowState::CalcLineHeight(nsIPresContext* aPresContext,
lineHeight = font->mFont.size;
}
else {
aRenderingContext->SetFont(font->mFont);
SetFontFromStyle(aRenderingContext, sc);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext->GetFontMetrics(*getter_AddRefs(fm));
#ifdef NEW_FONT_HEIGHT_APIS
@ -2416,21 +2416,9 @@ nsHTMLReflowState::ComputeHorizontalValue(nscoord aContainingBlockWidth,
// pretend its zero...
}
else {
const nsStyleFont* font;
frame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&) font);
const nsStyleVisibility* vis;
frame->GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis);
nsCOMPtr<nsIDeviceContext> deviceContext;
rendContext->GetDeviceContext(*getter_AddRefs(deviceContext));
nsCOMPtr<nsIAtom> langGroup;
if (vis->mLanguage) {
vis->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
}
nsCOMPtr<nsIFontMetrics> fm;
deviceContext->GetMetricsFor(font->mFont, langGroup, *getter_AddRefs(fm));
rendContext->SetFont(fm);
nsCOMPtr<nsIStyleContext> styleContext;
frame->GetStyleContext(getter_AddRefs(styleContext));
SetFontFromStyle(rendContext, styleContext);
nscoord fontWidth;
rendContext->GetWidth('M', fontWidth);
aResult = aCoord.GetIntValue() * fontWidth;

View File

@ -1063,12 +1063,9 @@ nsImageFrame::DisplayAltText(nsIPresContext* aPresContext,
{
const nsStyleColor* color =
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
const nsStyleFont* font =
(const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
// Set font and color
aRenderingContext.SetColor(color->mColor);
aRenderingContext.SetFont(font->mFont);
SetFontFromStyle(&aRenderingContext, mStyleContext);
// Format the text to display within the formatting rect
nsIFontMetrics* fm;

View File

@ -601,15 +601,9 @@ nsInlineFrame::ReflowFrames(nsIPresContext* aPresContext,
aMetrics.width += aReflowState.mComputedBorderPadding.right;
}
SetFontFromStyle(aReflowState.rendContext, mStyleContext);
nsCOMPtr<nsIFontMetrics> fm;
const nsStyleFont* font;
GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font);
if (font) {
aReflowState.rendContext->SetFont(font->mFont);
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
} else {
NS_WARNING("No font retrieved from style context - sorry but font metrics are not available");
}
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
if (fm) {
// Compute final height of the frame.
@ -640,6 +634,8 @@ nsInlineFrame::ReflowFrames(nsIPresContext* aPresContext,
// little hack lets us override that behavior to allow for more
// precise layout in the face of imprecise fonts.
if (nsHTMLReflowState::UseComputedHeight()) {
const nsStyleFont* font;
GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font);
aMetrics.height = font->mFont.size +
aReflowState.mComputedBorderPadding.top +
aReflowState.mComputedBorderPadding.bottom;

View File

@ -2173,10 +2173,10 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
nsIFrame* spanFrame = spanFramePFD->mFrame;
// Get the parent frame's font for all of the frames in this span
const nsStyleFont* parentFont;
spanFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)parentFont);
nsCOMPtr<nsIStyleContext> styleContext;
spanFrame->GetStyleContext(getter_AddRefs(styleContext));
nsIRenderingContext* rc = mBlockReflowState->rendContext;
rc->SetFont(parentFont->mFont);
SetFontFromStyle(mBlockReflowState->rendContext, styleContext);
nsCOMPtr<nsIFontMetrics> fm;
rc->GetFontMetrics(*getter_AddRefs(fm));
@ -2705,6 +2705,8 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
nscoord fontAscent, fontHeight;
fm->GetMaxAscent(fontAscent);
if (nsHTMLReflowState::UseComputedHeight()) {
const nsStyleFont* parentFont;
spanFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)parentFont);
fontHeight = parentFont->mFont.size;
}
else

View File

@ -690,7 +690,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
rect.SetRect(0, 0, mRect.width - mPD->mShadowSize.width, mRect.height - mPD->mShadowSize.height);
aRenderingContext.SetFont(*mPD->mHeadFootFont);
aRenderingContext.SetFont(*mPD->mHeadFootFont, nsnull);
aRenderingContext.SetColor(NS_RGB(0,0,0));
// Get the FontMetrics to determine width.height of strings
@ -698,7 +698,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
aPresContext->GetDeviceContext(getter_AddRefs(deviceContext));
NS_ASSERTION(deviceContext, "Couldn't get the device context");
nsCOMPtr<nsIFontMetrics> fontMet;
deviceContext->GetMetricsFor(*mPD->mHeadFootFont, *getter_AddRefs(fontMet));
deviceContext->GetMetricsFor(*mPD->mHeadFootFont, nsnull, *getter_AddRefs(fontMet));
nscoord ascent = 0;
nscoord visibleHeight = 0;
if (fontMet) {

View File

@ -393,7 +393,6 @@ nsresult nsBlinkTimer::RemoveBlinkFrame(nsIFrame* aFrame)
return NS_OK;
}
//----------------------------------------------------------------------
#ifdef IBMBIDI
@ -560,15 +559,9 @@ public:
NS_ASSERTION(plainFont, "null plainFont: font problems in TextStyle::TextStyle");
PRUint8 originalDecorations = plainFont->decorations;
plainFont->decorations = NS_FONT_DECORATION_NONE;
nsCOMPtr<nsIDeviceContext> deviceContext;
aRenderingContext.GetDeviceContext(*getter_AddRefs(deviceContext));
nsCOMPtr<nsIAtom> langGroup;
if (mVisibility->mLanguage) {
mVisibility->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
}
mAveCharWidth = 0;
deviceContext->GetMetricsFor(*plainFont, langGroup, mNormalFont);
aRenderingContext.SetFont(mNormalFont); // some users of the struct expect this state
SetFontFromStyle(&aRenderingContext, sc); // some users of the struct expect this state
aRenderingContext.GetFontMetrics(mNormalFont);
mNormalFont->GetSpaceWidth(mSpaceWidth);
#if defined(_WIN32) || defined(XP_OS2)
mNormalFont->GetAveCharWidth(mAveCharWidth);
@ -3397,22 +3390,7 @@ nsTextFrame::GetPosition(nsIPresContext* aCX,
}
// Find the font metrics for this text
nsIStyleContext* styleContext;
GetStyleContext(&styleContext);
const nsStyleFont *font = (const nsStyleFont*)
styleContext->GetStyleData(eStyleStruct_Font);
const nsStyleVisibility* visibility = (const nsStyleVisibility*)
styleContext->GetStyleData(eStyleStruct_Visibility);
NS_RELEASE(styleContext);
nsCOMPtr<nsIAtom> langGroup;
if (visibility && visibility->mLanguage) {
visibility->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
}
nsCOMPtr<nsIFontMetrics> fm;
nsCOMPtr<nsIDeviceContext> dx;
aCX->GetDeviceContext(getter_AddRefs(dx));
dx->GetMetricsFor(font->mFont, langGroup, *getter_AddRefs(fm));
acx->SetFont(fm);
SetFontFromStyle(acx, mStyleContext);
// Get the renderable form of the text
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(aCX)));
@ -5405,8 +5383,7 @@ nsTextFrame::Reflow(nsIPresContext* aPresContext,
aData.Mid(aText, mContentOffset, mContentLength);
// Set the font
const nsStyleFont* font = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
aReflowState.rendContext->SetFont(font->mFont);
SetFontFromStyle(aReflowState.rendContext, mStyleContext);
// Now get the exact bounding metrics of the text
nsBoundingMetrics bm;
@ -5522,9 +5499,8 @@ nsTextFrame::TrimTrailingWhiteSpace(nsIPresContext* aPresContext,
if (XP_IS_SPACE(ch)) {
// Get font metrics for a space so we can adjust the width by the
// right amount.
const nsStyleFont* fontStyle = (const nsStyleFont*)
mStyleContext->GetStyleData(eStyleStruct_Font);
aRC.SetFont(fontStyle->mFont);
SetFontFromStyle(&aRC, mStyleContext);
aRC.GetWidth(' ', dw);
// NOTE: Trailing whitespace includes word and letter spacing!
nsStyleUnit unit;

View File

@ -158,9 +158,7 @@ BRFrame::Reflow(nsIPresContext* aPresContext,
// We also do this in strict mode because BR should act like a
// normal inline frame. That line-height is used is important
// here for cases where the line-height is less that 1.
const nsStyleFont* font = (const nsStyleFont*)
mStyleContext->GetStyleData(eStyleStruct_Font);
aReflowState.rendContext->SetFont(font->mFont);
SetFontFromStyle(aReflowState.rendContext, mStyleContext);
nsCOMPtr<nsIFontMetrics> fm;
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
if (fm) {

View File

@ -224,6 +224,27 @@ nsIFrameDebug::RootFrameList(nsIPresContext* aPresContext, FILE* out, PRInt32 aI
#endif
// end nsIFrameDebug
// a handy utility to set font
void SetFontFromStyle(nsIRenderingContext* aRC, nsIStyleContext* aSC)
{
const nsStyleFont *font = (const nsStyleFont*)
aSC->GetStyleData(eStyleStruct_Font);
NS_ASSERTION(font, "invalid font in style context");
if (font) {
const nsStyleVisibility* visibility = (const nsStyleVisibility*)
aSC->GetStyleData(eStyleStruct_Visibility);
NS_ASSERTION(visibility, "invalid visibility in style context");
nsCOMPtr<nsIAtom> langGroup;
if (visibility && visibility->mLanguage) {
visibility->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
}
aRC->SetFont(font->mFont, langGroup);
}
}
nsresult
NS_NewEmptyFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
{

View File

@ -111,6 +111,8 @@
#define NS_FRAME_TRACE_REFLOW_OUT(_method, _status)
#endif
// handy utilities
extern void SetFontFromStyle(nsIRenderingContext* aRC, nsIStyleContext* aSC);
//----------------------------------------------------------------------

View File

@ -2378,7 +2378,7 @@ nsHTMLReflowState::CalcLineHeight(nsIPresContext* aPresContext,
lineHeight = font->mFont.size;
}
else {
aRenderingContext->SetFont(font->mFont);
SetFontFromStyle(aRenderingContext, sc);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext->GetFontMetrics(*getter_AddRefs(fm));
#ifdef NEW_FONT_HEIGHT_APIS
@ -2416,21 +2416,9 @@ nsHTMLReflowState::ComputeHorizontalValue(nscoord aContainingBlockWidth,
// pretend its zero...
}
else {
const nsStyleFont* font;
frame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&) font);
const nsStyleVisibility* vis;
frame->GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis);
nsCOMPtr<nsIDeviceContext> deviceContext;
rendContext->GetDeviceContext(*getter_AddRefs(deviceContext));
nsCOMPtr<nsIAtom> langGroup;
if (vis->mLanguage) {
vis->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
}
nsCOMPtr<nsIFontMetrics> fm;
deviceContext->GetMetricsFor(font->mFont, langGroup, *getter_AddRefs(fm));
rendContext->SetFont(fm);
nsCOMPtr<nsIStyleContext> styleContext;
frame->GetStyleContext(getter_AddRefs(styleContext));
SetFontFromStyle(rendContext, styleContext);
nscoord fontWidth;
rendContext->GetWidth('M', fontWidth);
aResult = aCoord.GetIntValue() * fontWidth;

View File

@ -1063,12 +1063,9 @@ nsImageFrame::DisplayAltText(nsIPresContext* aPresContext,
{
const nsStyleColor* color =
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
const nsStyleFont* font =
(const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
// Set font and color
aRenderingContext.SetColor(color->mColor);
aRenderingContext.SetFont(font->mFont);
SetFontFromStyle(&aRenderingContext, mStyleContext);
// Format the text to display within the formatting rect
nsIFontMetrics* fm;

View File

@ -601,15 +601,9 @@ nsInlineFrame::ReflowFrames(nsIPresContext* aPresContext,
aMetrics.width += aReflowState.mComputedBorderPadding.right;
}
SetFontFromStyle(aReflowState.rendContext, mStyleContext);
nsCOMPtr<nsIFontMetrics> fm;
const nsStyleFont* font;
GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font);
if (font) {
aReflowState.rendContext->SetFont(font->mFont);
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
} else {
NS_WARNING("No font retrieved from style context - sorry but font metrics are not available");
}
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
if (fm) {
// Compute final height of the frame.
@ -640,6 +634,8 @@ nsInlineFrame::ReflowFrames(nsIPresContext* aPresContext,
// little hack lets us override that behavior to allow for more
// precise layout in the face of imprecise fonts.
if (nsHTMLReflowState::UseComputedHeight()) {
const nsStyleFont* font;
GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)font);
aMetrics.height = font->mFont.size +
aReflowState.mComputedBorderPadding.top +
aReflowState.mComputedBorderPadding.bottom;

View File

@ -2173,10 +2173,10 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
nsIFrame* spanFrame = spanFramePFD->mFrame;
// Get the parent frame's font for all of the frames in this span
const nsStyleFont* parentFont;
spanFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)parentFont);
nsCOMPtr<nsIStyleContext> styleContext;
spanFrame->GetStyleContext(getter_AddRefs(styleContext));
nsIRenderingContext* rc = mBlockReflowState->rendContext;
rc->SetFont(parentFont->mFont);
SetFontFromStyle(mBlockReflowState->rendContext, styleContext);
nsCOMPtr<nsIFontMetrics> fm;
rc->GetFontMetrics(*getter_AddRefs(fm));
@ -2705,6 +2705,8 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
nscoord fontAscent, fontHeight;
fm->GetMaxAscent(fontAscent);
if (nsHTMLReflowState::UseComputedHeight()) {
const nsStyleFont* parentFont;
spanFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)parentFont);
fontHeight = parentFont->mFont.size;
}
else

View File

@ -690,7 +690,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
rect.SetRect(0, 0, mRect.width - mPD->mShadowSize.width, mRect.height - mPD->mShadowSize.height);
aRenderingContext.SetFont(*mPD->mHeadFootFont);
aRenderingContext.SetFont(*mPD->mHeadFootFont, nsnull);
aRenderingContext.SetColor(NS_RGB(0,0,0));
// Get the FontMetrics to determine width.height of strings
@ -698,7 +698,7 @@ nsPageFrame::Paint(nsIPresContext* aPresContext,
aPresContext->GetDeviceContext(getter_AddRefs(deviceContext));
NS_ASSERTION(deviceContext, "Couldn't get the device context");
nsCOMPtr<nsIFontMetrics> fontMet;
deviceContext->GetMetricsFor(*mPD->mHeadFootFont, *getter_AddRefs(fontMet));
deviceContext->GetMetricsFor(*mPD->mHeadFootFont, nsnull, *getter_AddRefs(fontMet));
nscoord ascent = 0;
nscoord visibleHeight = 0;
if (fontMet) {

View File

@ -393,7 +393,6 @@ nsresult nsBlinkTimer::RemoveBlinkFrame(nsIFrame* aFrame)
return NS_OK;
}
//----------------------------------------------------------------------
#ifdef IBMBIDI
@ -560,15 +559,9 @@ public:
NS_ASSERTION(plainFont, "null plainFont: font problems in TextStyle::TextStyle");
PRUint8 originalDecorations = plainFont->decorations;
plainFont->decorations = NS_FONT_DECORATION_NONE;
nsCOMPtr<nsIDeviceContext> deviceContext;
aRenderingContext.GetDeviceContext(*getter_AddRefs(deviceContext));
nsCOMPtr<nsIAtom> langGroup;
if (mVisibility->mLanguage) {
mVisibility->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
}
mAveCharWidth = 0;
deviceContext->GetMetricsFor(*plainFont, langGroup, mNormalFont);
aRenderingContext.SetFont(mNormalFont); // some users of the struct expect this state
SetFontFromStyle(&aRenderingContext, sc); // some users of the struct expect this state
aRenderingContext.GetFontMetrics(mNormalFont);
mNormalFont->GetSpaceWidth(mSpaceWidth);
#if defined(_WIN32) || defined(XP_OS2)
mNormalFont->GetAveCharWidth(mAveCharWidth);
@ -3397,22 +3390,7 @@ nsTextFrame::GetPosition(nsIPresContext* aCX,
}
// Find the font metrics for this text
nsIStyleContext* styleContext;
GetStyleContext(&styleContext);
const nsStyleFont *font = (const nsStyleFont*)
styleContext->GetStyleData(eStyleStruct_Font);
const nsStyleVisibility* visibility = (const nsStyleVisibility*)
styleContext->GetStyleData(eStyleStruct_Visibility);
NS_RELEASE(styleContext);
nsCOMPtr<nsIAtom> langGroup;
if (visibility && visibility->mLanguage) {
visibility->mLanguage->GetLanguageGroup(getter_AddRefs(langGroup));
}
nsCOMPtr<nsIFontMetrics> fm;
nsCOMPtr<nsIDeviceContext> dx;
aCX->GetDeviceContext(getter_AddRefs(dx));
dx->GetMetricsFor(font->mFont, langGroup, *getter_AddRefs(fm));
acx->SetFont(fm);
SetFontFromStyle(acx, mStyleContext);
// Get the renderable form of the text
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(aCX)));
@ -5405,8 +5383,7 @@ nsTextFrame::Reflow(nsIPresContext* aPresContext,
aData.Mid(aText, mContentOffset, mContentLength);
// Set the font
const nsStyleFont* font = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font);
aReflowState.rendContext->SetFont(font->mFont);
SetFontFromStyle(aReflowState.rendContext, mStyleContext);
// Now get the exact bounding metrics of the text
nsBoundingMetrics bm;
@ -5522,9 +5499,8 @@ nsTextFrame::TrimTrailingWhiteSpace(nsIPresContext* aPresContext,
if (XP_IS_SPACE(ch)) {
// Get font metrics for a space so we can adjust the width by the
// right amount.
const nsStyleFont* fontStyle = (const nsStyleFont*)
mStyleContext->GetStyleData(eStyleStruct_Font);
aRC.SetFont(fontStyle->mFont);
SetFontFromStyle(&aRC, mStyleContext);
aRC.GetWidth(' ', dw);
// NOTE: Trailing whitespace includes word and letter spacing!
nsStyleUnit unit;

View File

@ -589,7 +589,7 @@ nsGlyphTable::GetBoundingMetrics(nsIRenderingContext& aRenderingContext,
if (aGlyphCode.font) {
// glyph not associated to our primary font, it comes from an external font
mFontName.StringAt(aGlyphCode.font, aFont.name);
aRenderingContext.SetFont(aFont);
aRenderingContext.SetFont(aFont, nsnull);
}
//if (mType == NS_TABLE_TYPE_UNICODE)
@ -601,7 +601,7 @@ nsGlyphTable::GetBoundingMetrics(nsIRenderingContext& aRenderingContext,
if (aGlyphCode.font) {
// restore our primary font in the rendering context
mFontName.StringAt(0, aFont.name);
aRenderingContext.SetFont(aFont);
aRenderingContext.SetFont(aFont, nsnull);
}
return rv;
}
@ -624,7 +624,7 @@ nsGlyphTable::DrawGlyph(nsIRenderingContext& aRenderingContext,
if (aGlyphCode.font) {
// glyph not associated to our primary font, it comes from an external font
mFontName.StringAt(aGlyphCode.font, aFont.name);
aRenderingContext.SetFont(aFont);
aRenderingContext.SetFont(aFont, nsnull);
}
//if (mType == NS_TABLE_TYPE_UNICODE)
@ -636,7 +636,7 @@ nsGlyphTable::DrawGlyph(nsIRenderingContext& aRenderingContext,
if (aGlyphCode.font) {
// restore our primary font in the rendering context
mFontName.StringAt(0, aFont.name);
aRenderingContext.SetFont(aFont);
aRenderingContext.SetFont(aFont, nsnull);
}
if (aClipRect) {
aRenderingContext.PopState(clipState);
@ -1480,7 +1480,7 @@ nsMathMLChar::Stretch(nsIPresContext* aPresContext,
fontName.Assign(NS_LITERAL_STRING("CMSY10")); // assumptions in the sqrt code, we need
SetFirstFamily(theFont, fontName); // to force precedence on this TeX font
}
aRenderingContext.SetFont(theFont);
aRenderingContext.SetFont(theFont, nsnull);
rv = aRenderingContext.GetBoundingMetrics(mData.get(),
PRUint32(mData.Length()),
mBoundingMetrics);
@ -1577,7 +1577,7 @@ nsMathMLChar::Stretch(nsIPresContext* aPresContext,
}
glyphTable->GetPrimaryFontName(fontName);
SetFirstFamily(theFont, fontName);
aRenderingContext.SetFont(theFont);
aRenderingContext.SetFont(theFont, nsnull);
#ifdef NOISY_SEARCH
char str[50];
fontName.ToCString(str, sizeof(str));
@ -1674,7 +1674,7 @@ nsMathMLChar::Stretch(nsIPresContext* aPresContext,
// See if the parts of this table fit in the desired space ///////////////////////
glyphTable->GetPrimaryFontName(fontName);
SetFirstFamily(theFont, fontName);
aRenderingContext.SetFont(theFont);
aRenderingContext.SetFont(theFont, nsnull);
// Compute the bounding metrics of all partial glyphs
PRInt32 i;
nsGlyphCode chdata[4];
@ -1956,7 +1956,7 @@ nsMathMLChar::Paint(nsIPresContext* aPresContext,
fontName.Assign(NS_LITERAL_STRING("CMSY10")); // assumptions in the sqrt code, we need
SetFirstFamily(theFont, fontName); // to force precedence on this TeX font
}
aRenderingContext.SetFont(theFont);
aRenderingContext.SetFont(theFont, nsnull);
//printf("Painting %04X like a normal char\n", mData[0]);
//aRenderingContext.SetColor(NS_RGB(255,0,0));
aRenderingContext.DrawString(mData.get(), len, mRect.x, mRect.y + mBoundingMetrics.ascent);
@ -1965,7 +1965,7 @@ nsMathMLChar::Paint(nsIPresContext* aPresContext,
// Set the stretchy font and grab some metrics to adjust the placements ...
mGlyphTable->GetPrimaryFontName(fontName);
SetFirstFamily(theFont, fontName);
aRenderingContext.SetFont(theFont);
aRenderingContext.SetFont(theFont, nsnull);
// if there is a glyph of appropriate size, paint that glyph
if (mGlyph) {
//printf("Painting %04X with a glyph of appropriate size\n", mData[0]);

View File

@ -78,7 +78,7 @@ nsMathMLContainerFrame::ReflowError(nsIPresContext* aPresContext,
// Set font
const nsStyleFont *font = NS_STATIC_CAST(const nsStyleFont*,
mStyleContext->GetStyleData(eStyleStruct_Font));
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
// bounding metrics
nsAutoString errorMsg; errorMsg.AssignWithConversion("invalid-markup");
@ -122,7 +122,7 @@ nsMathMLContainerFrame::PaintError(nsIPresContext* aPresContext,
// Set color and font ...
const nsStyleFont *font = NS_STATIC_CAST(const nsStyleFont*,
mStyleContext->GetStyleData(eStyleStruct_Font));
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
aRenderingContext.SetColor(NS_RGB(255,0,0));
aRenderingContext.FillRect(0, 0, mRect.width, mRect.height);

View File

@ -282,7 +282,7 @@ nsMathMLmfencedFrame::doReflow(nsIPresContext* aPresContext,
const nsStyleFont* font;
aForFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct *&)font);
nsCOMPtr<nsIFontMetrics> fm;
aReflowState.rendContext->SetFont(font->mFont);
aReflowState.rendContext->SetFont(font->mFont, nsnull);
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
nscoord axisHeight, em;
GetAxisHeight(*aReflowState.rendContext, fm, axisHeight);

View File

@ -290,7 +290,7 @@ nsMathMLmfracFrame::Place(nsIPresContext* aPresContext,
const nsStyleFont *font = NS_STATIC_CAST(const nsStyleFont*,
mStyleContext->GetStyleData(eStyleStruct_Font));
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));

View File

@ -168,7 +168,7 @@ nsMathMLmmultiscriptsFrame::Place(nsIPresContext* aPresContext,
// get x-height (an ex)
const nsStyleFont *font = NS_STATIC_CAST(const nsStyleFont*,
mStyleContext->GetStyleData(eStyleStruct_Font));
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));

View File

@ -605,7 +605,7 @@ nsMathMLmoFrame::Stretch(nsIPresContext* aPresContext,
const nsStyleFont *font = NS_STATIC_CAST(const nsStyleFont*,
mStyleContext->GetStyleData(eStyleStruct_Font));
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
nscoord leading = 0, axisHeight, height;
GetAxisHeight(aRenderingContext, fm, axisHeight);

View File

@ -301,7 +301,7 @@ nsMathMLmoverFrame::Place(nsIPresContext* aPresContext,
const nsStyleFont* font =
(const nsStyleFont*) mStyleContext->GetStyleData (eStyleStruct_Font);
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));

View File

@ -227,7 +227,7 @@ nsMathMLmrootFrame::Reflow(nsIPresContext* aPresContext,
const nsStyleFont *font = NS_STATIC_CAST(const nsStyleFont*,
mStyleContext->GetStyleData(eStyleStruct_Font));
renderingContext.SetFont(font->mFont);
renderingContext.SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
renderingContext.GetFontMetrics(*getter_AddRefs(fm));

View File

@ -199,7 +199,7 @@ nsMathMLmsqrtFrame::Reflow(nsIPresContext* aPresContext,
nsIRenderingContext& renderingContext = *aReflowState.rendContext;
const nsStyleFont *font = NS_STATIC_CAST(const nsStyleFont*,
mStyleContext->GetStyleData(eStyleStruct_Font));
renderingContext.SetFont(font->mFont);
renderingContext.SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
renderingContext.GetFontMetrics(*getter_AddRefs(fm));

View File

@ -209,7 +209,7 @@ nsMathMLmsubsupFrame::PlaceSubSupScript(nsIPresContext* aPresContext,
const nsStyleFont* font;
baseFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct *&)font);
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));

View File

@ -557,7 +557,7 @@ nsMathMLmtableOuterFrame::Reflow(nsIPresContext* aPresContext,
// XXX should instead use style data from the row of reference here ?
const nsStyleFont* font;
GetStyleData(eStyleStruct_Font, (const nsStyleStruct *&)font);
aReflowState.rendContext->SetFont(font->mFont);
aReflowState.rendContext->SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
nscoord axisHeight;

View File

@ -298,7 +298,7 @@ nsMathMLmunderFrame::Place(nsIPresContext* aPresContext,
const nsStyleFont* font =
(const nsStyleFont*) mStyleContext->GetStyleData (eStyleStruct_Font);
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));

View File

@ -341,7 +341,7 @@ nsMathMLmunderoverFrame::Place(nsIPresContext* aPresContext,
const nsStyleFont* font =
(const nsStyleFont*) mStyleContext->GetStyleData (eStyleStruct_Font);
aRenderingContext.SetFont(font->mFont);
aRenderingContext.SetFont(font->mFont, nsnull);
nsCOMPtr<nsIFontMetrics> fm;
aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));

View File

@ -425,7 +425,7 @@ nsTextBoxFrame::PaintTitle(nsIPresContext* aPresContext,
aRenderingContext.FillRect(textRect.x, textRect.y + baseline - offset, mRect.width, size);
}
aRenderingContext.SetFont(fontStyle->mFont);
aRenderingContext.SetFont(fontStyle->mFont, nsnull);
CalculateUnderline(aRenderingContext);

View File

@ -1532,7 +1532,7 @@ nsTreeBodyFrame::GetCellWidth(PRInt32 aRow, const nsAString& aColID,
mPresContext->GetShell(getter_AddRefs(shell));
nsCOMPtr<nsIRenderingContext> rc;
shell->CreateRenderingContext(this, getter_AddRefs(rc));
rc->SetFont(fontStyle->mFont);
rc->SetFont(fontStyle->mFont, nsnull);
// Get the width of the text itself
nscoord width;

View File

@ -278,15 +278,16 @@ NS_METHOD nsButton::Paint(nsIRenderingContext& aRenderingContext,
//DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1
//DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1
aRenderingContext.SetFont(*mFont);
nsIFontMetrics* metrics;
context->GetMetricsFor(*mFont, metrics);
aRenderingContext.SetFont(metrics);
nscoord textWidth;
nscoord textHeight;
aRenderingContext.GetWidth(mLabel, textWidth);
nsIFontMetrics* metrics;
context->GetMetricsFor(*mFont, metrics);
metrics->GetMaxAscent(textHeight);
nscoord x = ((rect.width - textWidth) / 2) + rect.x;

View File

@ -296,14 +296,14 @@ NS_METHOD nsTextWidget::Paint(nsIRenderingContext& aRenderingContext,
//DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1
aRenderingContext.SetFont(*mFont);
nsIFontMetrics* metrics;
context->GetMetricsFor(*mFont, metrics);
aRenderingContext.SetFont(metrics);
nscoord textWidth;
nscoord textHeight;
aRenderingContext.GetWidth(mText, textWidth);
nsIFontMetrics* metrics;
context->GetMetricsFor(*mFont, metrics);
metrics->GetMaxAscent(textHeight);
nscoord x = (twoPixels * 2) + rect.x;