From fb749a80df0e7df95311e89da97e4b58aab42e05 Mon Sep 17 00:00:00 2001 From: "pavlov%pavlov.net" Date: Tue, 7 Mar 2006 23:45:52 +0000 Subject: [PATCH] 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 --- mozilla/gfx/src/thebes/nsThebesFontMetrics.cpp | 18 +++++++++++++++++- mozilla/gfx/thebes/public/gfxWindowsFonts.h | 6 ++---- mozilla/gfx/thebes/src/gfxWindowsFonts.cpp | 16 ++++++++++++---- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/mozilla/gfx/src/thebes/nsThebesFontMetrics.cpp b/mozilla/gfx/src/thebes/nsThebesFontMetrics.cpp index 8165aa7ea15..8a34a311d4b 100644 --- a/mozilla/gfx/src/thebes/nsThebesFontMetrics.cpp +++ b/mozilla/gfx/src/thebes/nsThebesFontMetrics.cpp @@ -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 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 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); diff --git a/mozilla/gfx/thebes/public/gfxWindowsFonts.h b/mozilla/gfx/thebes/public/gfxWindowsFonts.h index 353c472d889..24bc43b361f 100644 --- a/mozilla/gfx/thebes/public/gfxWindowsFonts.h +++ b/mozilla/gfx/thebes/public/gfxWindowsFonts.h @@ -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; }; diff --git a/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp b/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp index ae604277653..81cbe347594 100644 --- a/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp +++ b/mozilla/gfx/thebes/src/gfxWindowsFonts.cpp @@ -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); }