fixing crash when trying to measure or draw 0-length strings.
removing HDC param/member that is no longer used. bug 329574. r=vlad git-svn-id: svn://10.0.0.236/trunk@191940 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -95,7 +95,7 @@ nsThebesFontMetrics::Init(const nsFont& aFont, nsIAtom* aLangGroup,
|
||||
aFont.systemFont, aFont.familyNameQuirks);
|
||||
|
||||
#if defined(XP_WIN)
|
||||
mFontGroup = new gfxWindowsFontGroup(aFont.name, mFontStyle, (HDC)mDeviceContext->GetHDC());
|
||||
mFontGroup = new gfxWindowsFontGroup(aFont.name, mFontStyle);
|
||||
#elif defined(MOZ_ENABLE_PANGO)
|
||||
mFontGroup = new gfxPangoFontGroup(aFont.name, mFontStyle);
|
||||
#elif defined(XP_MACOSX)
|
||||
@@ -276,6 +276,11 @@ nsresult
|
||||
nsThebesFontMetrics::GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth,
|
||||
nsThebesRenderingContext *aContext)
|
||||
{
|
||||
if (aLength == 0) {
|
||||
aWidth = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsDependentCSubstring& theString = nsDependentCSubstring(aString, aString+aLength);
|
||||
nsRefPtr<gfxTextRun> textrun = mFontGroup->MakeTextRun(theString);
|
||||
|
||||
@@ -291,6 +296,11 @@ nsThebesFontMetrics::GetWidth(const PRUnichar* aString, PRUint32 aLength,
|
||||
nscoord& aWidth, PRInt32 *aFontID,
|
||||
nsThebesRenderingContext *aContext)
|
||||
{
|
||||
if (aLength == 0) {
|
||||
aWidth = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsDependentSubstring& theString = nsDependentSubstring(aString, aString+aLength);
|
||||
nsRefPtr<gfxTextRun> textrun = mFontGroup->MakeTextRun(theString);
|
||||
|
||||
@@ -346,6 +356,9 @@ nsThebesFontMetrics::DrawString(const char *aString, PRUint32 aLength,
|
||||
const nscoord* aSpacing,
|
||||
nsThebesRenderingContext *aContext)
|
||||
{
|
||||
if (aLength == 0)
|
||||
return NS_OK;
|
||||
|
||||
float app2dev = mDeviceContext->AppUnitsToDevUnits();
|
||||
|
||||
const nsDependentCSubstring& theString = nsDependentCSubstring(aString, aString+aLength);
|
||||
@@ -366,6 +379,9 @@ nsThebesFontMetrics::DrawString(const PRUnichar* aString, PRUint32 aLength,
|
||||
const nscoord* aSpacing,
|
||||
nsThebesRenderingContext *aContext)
|
||||
{
|
||||
if (aLength == 0)
|
||||
return NS_OK;
|
||||
|
||||
float app2dev = mDeviceContext->AppUnitsToDevUnits();
|
||||
|
||||
const nsDependentSubstring& theString = nsDependentSubstring(aString, aString+aLength);
|
||||
|
||||
@@ -56,7 +56,7 @@ class gfxWindowsFont : public gfxFont {
|
||||
THEBES_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
public:
|
||||
gfxWindowsFont(const nsAString &aName, const gfxFontGroup *aFontGroup, HDC aHWnd);
|
||||
gfxWindowsFont(const nsAString &aName, const gfxFontGroup *aFontGroup);
|
||||
gfxWindowsFont(HFONT aFont, const gfxFontGroup *aFontGroup, PRBool aIsMLangFont);
|
||||
|
||||
virtual ~gfxWindowsFont();
|
||||
@@ -100,7 +100,7 @@ private:
|
||||
class NS_EXPORT gfxWindowsFontGroup : public gfxFontGroup {
|
||||
|
||||
public:
|
||||
gfxWindowsFontGroup(const nsAString& aFamilies, const gfxFontStyle* aStyle, HDC hwnd);
|
||||
gfxWindowsFontGroup(const nsAString& aFamilies, const gfxFontStyle* aStyle);
|
||||
virtual ~gfxWindowsFontGroup();
|
||||
|
||||
virtual gfxTextRun *MakeTextRun(const nsAString& aString);
|
||||
@@ -114,8 +114,6 @@ protected:
|
||||
static PRBool MakeFont(const nsAString& fontName, const nsAString& genericName, void *closure);
|
||||
|
||||
private:
|
||||
HDC mDC;
|
||||
|
||||
friend class gfxWindowsTextRun;
|
||||
};
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
|
||||
THEBES_IMPL_REFCOUNTING(gfxWindowsFont)
|
||||
|
||||
gfxWindowsFont::gfxWindowsFont(const nsAString &aName, const gfxFontGroup *aFontGroup, HDC aDC)
|
||||
gfxWindowsFont::gfxWindowsFont(const nsAString &aName, const gfxFontGroup *aFontGroup)
|
||||
: mFont(nsnull), mScriptCache(nsnull), mMetrics(nsnull), mIsMLangFont(PR_FALSE)
|
||||
{
|
||||
mName = aName;
|
||||
@@ -319,14 +319,14 @@ PRBool
|
||||
gfxWindowsFontGroup::MakeFont(const nsAString& aName, const nsAString& aGenericName, void *closure)
|
||||
{
|
||||
gfxWindowsFontGroup *fg = NS_STATIC_CAST(gfxWindowsFontGroup*, closure);
|
||||
gfxFont *font = new gfxWindowsFont(aName, fg, fg->mDC);
|
||||
gfxFont *font = new gfxWindowsFont(aName, fg);
|
||||
fg->mFonts.AppendElement(font);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
gfxWindowsFontGroup::gfxWindowsFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyle, HDC dc)
|
||||
: gfxFontGroup(aFamilies, aStyle), mDC(dc)
|
||||
gfxWindowsFontGroup::gfxWindowsFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyle)
|
||||
: gfxFontGroup(aFamilies, aStyle)
|
||||
{
|
||||
ForEachFont(MakeFont, this);
|
||||
}
|
||||
@@ -339,12 +339,20 @@ gfxWindowsFontGroup::~gfxWindowsFontGroup()
|
||||
gfxTextRun *
|
||||
gfxWindowsFontGroup::MakeTextRun(const nsAString& aString)
|
||||
{
|
||||
if (aString.IsEmpty()) {
|
||||
NS_WARNING("It is illegal to create a gfxTextRun with empty strings");
|
||||
return nsnull;
|
||||
}
|
||||
return new gfxWindowsTextRun(aString, this);
|
||||
}
|
||||
|
||||
gfxTextRun *
|
||||
gfxWindowsFontGroup::MakeTextRun(const nsACString& aString)
|
||||
{
|
||||
if (aString.IsEmpty()) {
|
||||
NS_WARNING("It is illegal to create a gfxTextRun with empty strings");
|
||||
return nsnull;
|
||||
}
|
||||
return new gfxWindowsTextRun(aString, this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user