diff --git a/mozilla/gfx/src/qt/nsRenderingContextQT.cpp b/mozilla/gfx/src/qt/nsRenderingContextQT.cpp index 3ceb5fd0780..863587e4e75 100644 --- a/mozilla/gfx/src/qt/nsRenderingContextQT.cpp +++ b/mozilla/gfx/src/qt/nsRenderingContextQT.cpp @@ -1069,56 +1069,57 @@ NS_IMETHODIMP nsRenderingContextQT::GetWidth(const PRUnichar *aString, PRUint32 aLength,nscoord &aWidth, PRInt32 *aFontID) { - if (0 == aLength) + if (aFontID) + *aFontID = 0; + if (0 == aLength) { aWidth = 0; - else if (nsnull == aString) + return NS_OK; + } + if (!aString || !mFontMetrics) return NS_ERROR_FAILURE; - else { - nsFontMetricsQT *metrics = (nsFontMetricsQT*)mFontMetrics; - nsFontQT *prevFont = nsnull; - int rawWidth = 0; - PRUint32 start = 0; - PRUint32 i; - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontQT* currFont = nsnull; - if (mCurrentFont->SupportsChar(c)) { - currFont = mCurrentFont; - goto FoundFont; - } - else { - nsFontQT **font = metrics->mLoadedFonts; - nsFontQT **lastFont = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < lastFont) { - if ((*font)->SupportsChar(c)) { - currFont = *font; - goto FoundFont; // for speed -- avoid "if" statement - } - font++; + nsFontMetricsQT *metrics = (nsFontMetricsQT*)mFontMetrics; + nsFontQT *prevFont = nsnull; + int rawWidth = 0; + PRUint32 start = 0; + PRUint32 i; + + for (i = 0; i < aLength; i++) { + PRUnichar c = aString[i]; + nsFontQT* currFont = nsnull; + if (mCurrentFont->SupportsChar(c)) { + currFont = mCurrentFont; + goto FoundFont; + } + else { + nsFontQT **font = metrics->mLoadedFonts; + nsFontQT **lastFont = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; + while (font < lastFont) { + if ((*font)->SupportsChar(c)) { + currFont = *font; + goto FoundFont; // for speed -- avoid "if" statement } - currFont = metrics->FindFont(c); + font++; } + currFont = metrics->FindFont(c); + } FoundFont: - if (prevFont) { - if (currFont != prevFont) { - rawWidth += prevFont->GetWidth(&aString[start], i - start); - prevFont = currFont; - start = i; - } - } - else { + if (prevFont) { + if (currFont != prevFont) { + rawWidth += prevFont->GetWidth(&aString[start], i - start); prevFont = currFont; start = i; } - } - if (prevFont) { - rawWidth += prevFont->GetWidth(&aString[start], i - start); } - aWidth = NSToCoordRound(rawWidth * mP2T); + else { + prevFont = currFont; + start = i; + } + } + if (prevFont) { + rawWidth += prevFont->GetWidth(&aString[start], i - start); } - if (nsnull != aFontID) - *aFontID = 0; + aWidth = NSToCoordRound(rawWidth * mP2T); return NS_OK; } @@ -1170,7 +1171,7 @@ nsRenderingContextQT::GetTextDimensions(const PRUnichar *aString, currFont = metrics->FindFont(c); } FoundFont: - if (prevFont) { + if (prevFont && prevFont->mFontMetrics) { if (currFont != prevFont) { rawWidth += prevFont->GetWidth(&aString[start], i - start); if (rawAscent < prevFont->mFontMetrics->ascent()) @@ -1186,7 +1187,7 @@ FoundFont: start = i; } } - if (prevFont) { + if (prevFont && prevFont->mFontMetrics) { rawWidth += prevFont->GetWidth(&aString[start], i - start); if (rawAscent < prevFont->mFontMetrics->ascent()) rawAscent = prevFont->mFontMetrics->ascent();