Bail out of gfxFont::Draw if setting up the Cairo font fails. b=390476 r+sr=pavlov a19=pavlov

This commit is contained in:
mats.palmgren@bredband.net 2007-08-06 05:30:13 -07:00
parent b5f416731c
commit c7a065333e
10 changed files with 49 additions and 22 deletions

View File

@ -93,10 +93,7 @@ protected:
void InitMetrics(ATSUFontID aFontID, ATSFontRef aFontRef);
virtual void SetupCairoFont(cairo_t *aCR)
{
cairo_set_scaled_font (aCR, CairoScaledFont());
}
virtual PRBool SetupCairoFont(cairo_t *aCR);
};
class THEBES_API gfxAtsuiFontGroup : public gfxFontGroup {

View File

@ -418,7 +418,7 @@ protected:
gfxFontStyle mStyle;
// This is called by the default Draw() implementation above.
virtual void SetupCairoFont(cairo_t *aCR) = 0;
virtual PRBool SetupCairoFont(cairo_t *aCR) = 0;
};
class THEBES_API gfxTextRunFactory {

View File

@ -72,7 +72,7 @@ public:
protected:
gfxMatrix mCTM;
virtual void SetupCairoFont(cairo_t *aCR);
virtual PRBool SetupCairoFont(cairo_t *aCR);
private:
cairo_font_face_t *mFontFace;

View File

@ -111,7 +111,7 @@ protected:
void GetCharSize(const char aChar, gfxSize& aInkSize, gfxSize& aLogSize,
PRUint32 *aGlyphID = nsnull);
virtual void SetupCairoFont(cairo_t *aCR);
virtual PRBool SetupCairoFont(cairo_t *aCR);
};
class FontSelector;

View File

@ -533,7 +533,7 @@ private:
nsRefPtr<FontEntry> mFontEntry;
virtual void SetupCairoFont(cairo_t *aCR);
virtual PRBool SetupCairoFont(cairo_t *aCR);
};
/**********************************************************************

View File

@ -223,6 +223,17 @@ gfxAtsuiFont::InitMetrics(ATSUFontID aFontID, ATSFontRef aFontRef)
#endif
}
PRBool
gfxAtsuiFont::SetupCairoFont(cairo_t *aCR)
{
cairo_scaled_font_t *scaledFont = CairoScaledFont();
if (NS_LIKELY(scaledFont)) {
cairo_set_scaled_font(aCR, scaledFont);
return PR_TRUE;
}
return PR_FALSE;
}
nsString
gfxAtsuiFont::GetUniqueName()
{

View File

@ -213,10 +213,10 @@ gfxFont::Draw(gfxTextRun *aTextRun, PRUint32 aStart, PRUint32 aEnd,
double x = aPt->x;
double y = aPt->y;
NS_ASSERTION(appUnitsPerDevUnit != 0, "Invalid app unit scale");
cairo_t *cr = aContext->GetCairo();
SetupCairoFont(cr);
PRBool success = SetupCairoFont(cr);
if (NS_UNLIKELY(!success))
return;
GlyphBuffer glyphs;
cairo_glyph_t *glyph;
@ -679,6 +679,7 @@ gfxTextRun::gfxTextRun(const gfxTextRunFactory::Parameters *aParams, const void
mAppUnitsPerDevUnit(aParams->mAppUnitsPerDevUnit),
mFlags(aFlags), mCharacterCount(aLength), mHashCode(0)
{
NS_ASSERTION(mAppUnitsPerDevUnit != 0, "Invalid app unit scale");
MOZ_COUNT_CTOR(gfxTextRun);
NS_ADDREF(mFontGroup);
if (aParams->mSkipChars) {

View File

@ -337,7 +337,7 @@ nsString gfxOS2Font::GetUniqueName()
return mName;
}
void gfxOS2Font::SetupCairoFont(cairo_t *aCR)
PRBool gfxOS2Font::SetupCairoFont(cairo_t *aCR)
{
#ifdef DEBUG_thebes_2
printf("gfxOS2Font[%#x]::SetupCairoFont(%#x)\n",
@ -346,7 +346,12 @@ void gfxOS2Font::SetupCairoFont(cairo_t *aCR)
// gfxPangoFont checks the CTM but Windows doesn't so leave away here, too
// this implicitely ensures that mScaledFont is created if NULL
cairo_set_scaled_font(aCR, CairoScaledFont());
cairo_scaled_font_t *scaledFont = CairoScaledFont();
if (NS_LIKELY(scaledFont)) {
cairo_set_scaled_font(aCR, scaledFont);
return PR_TRUE;
}
return PR_FALSE;
}
/**********************************************************************

View File

@ -914,7 +914,7 @@ CreateScaledFont(cairo_t *aCR, cairo_matrix_t *aCTM, PangoFont *aPangoFont)
return scaledFont;
}
void
PRBool
gfxPangoFont::SetupCairoFont(cairo_t *aCR)
{
cairo_matrix_t currentCTM;
@ -927,7 +927,7 @@ gfxPangoFont::SetupCairoFont(cairo_t *aCR)
if (fontCTM.xx == currentCTM.xx && fontCTM.yy == currentCTM.yy &&
fontCTM.xy == currentCTM.xy && fontCTM.yx == currentCTM.yx) {
cairo_set_scaled_font(aCR, mCairoFont);
return;
return PR_TRUE;
}
// Just recreate it from scratch, simplest way
@ -935,7 +935,11 @@ gfxPangoFont::SetupCairoFont(cairo_t *aCR)
}
mCairoFont = CreateScaledFont(aCR, &currentCTM, GetPangoFont());
cairo_set_scaled_font(aCR, mCairoFont);
if (NS_LIKELY(mCairoFont)) {
cairo_set_scaled_font(aCR, mCairoFont);
return PR_TRUE;
}
return PR_FALSE;
}
static void

View File

@ -159,7 +159,8 @@ gfxWindowsFont::CairoScaledFont()
cairo_font_options_destroy(fontOptions);
}
NS_ASSERTION(mScaledFont, "Failed to make scaled font");
NS_ASSERTION(mScaledFont || mAdjustedSize == 0.0,
"Failed to make scaled font");
return mScaledFont;
}
@ -414,10 +415,15 @@ gfxWindowsFont::Draw(gfxTextRun *aTextRun, PRUint32 aStart, PRUint32 aEnd,
aSpacing);
}
void
PRBool
gfxWindowsFont::SetupCairoFont(cairo_t *aCR)
{
cairo_set_scaled_font(aCR, CairoScaledFont());
cairo_scaled_font_t *scaledFont = CairoScaledFont();
if (NS_LIKELY(scaledFont)) {
cairo_set_scaled_font(aCR, scaledFont);
return PR_TRUE;
}
return PR_FALSE;
}
/**********************************************************************
@ -1105,7 +1111,9 @@ public:
void SetCurrentFont(gfxWindowsFont *aFont) {
if (mCurrentFont != aFont) {
mCurrentFont = aFont;
cairo_win32_scaled_font_done_font(mCurrentFont->CairoScaledFont());
cairo_scaled_font_t *scaledFont = mCurrentFont->CairoScaledFont();
if (scaledFont)
cairo_win32_scaled_font_done_font(scaledFont);
mFontSelected = PR_FALSE;
}
}
@ -1122,8 +1130,9 @@ public:
cairo_set_font_face(cr, mCurrentFont->CairoFontFace());
cairo_set_font_size(cr, mCurrentFont->GetAdjustedSize());
cairo_win32_scaled_font_select_font(mCurrentFont->CairoScaledFont(), mDC);
cairo_scaled_font_t *scaledFont = mCurrentFont->CairoScaledFont();
if (scaledFont)
cairo_win32_scaled_font_select_font(scaledFont, mDC);
mFontSelected = PR_TRUE;
}