Fixing viewer crashes where prevFont->mFontMetrics is null

rearranged the code to use early returns/no else after returns.
moduleowner=me rs=bz a=roc
part of the Qt module which still doesn't build w/o patches in my tree.


git-svn-id: svn://10.0.0.236/trunk@135040 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
timeless%mozdev.org 2002-12-10 17:42:15 +00:00
parent e6e68328f4
commit a59dbd4beb

View File

@ -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();