Performance improvements. Reduce the number of ::SelectObject() calls
when measuring text and displaying text
This commit is contained in:
troy%netscape.com 2000-02-19 01:59:18 +00:00
Родитель 3356cbea97
Коммит f7fb63eb17
2 изменённых файлов: 36 добавлений и 14 удалений

Просмотреть файл

@ -1937,10 +1937,8 @@ nsFontWinUnicode::~nsFontWinUnicode()
PRInt32
nsFontWinUnicode::GetWidth(HDC aDC, const PRUnichar* aString, PRUint32 aLength)
{
HFONT oldFont = (HFONT) ::SelectObject(aDC, mFont);
SIZE size;
::GetTextExtentPoint32W(aDC, aString, aLength, &size);
::SelectObject(aDC, oldFont);
return size.cx;
}
@ -1949,9 +1947,7 @@ void
nsFontWinUnicode::DrawString(HDC aDC, PRInt32 aX, PRInt32 aY,
const PRUnichar* aString, PRUint32 aLength)
{
HFONT oldFont = (HFONT) ::SelectObject(aDC, mFont);
::ExtTextOutW(aDC, aX, aY, 0, NULL, aString, aLength, NULL);
::SelectObject(aDC, oldFont);
}
#ifdef MOZ_MATHML
@ -2064,10 +2060,8 @@ nsFontWinNonUnicode::GetWidth(HDC aDC, const PRUnichar* aString,
pstr[i] = mConverter[aString[i]];
}
HFONT oldFont = (HFONT) ::SelectObject(aDC, mFont);
SIZE size;
::GetTextExtentPoint32A(aDC, pstr, aLength, &size);
::SelectObject(aDC, oldFont);
if (pstr != str) {
delete[] pstr;
@ -2092,9 +2086,7 @@ nsFontWinNonUnicode::DrawString(HDC aDC, PRInt32 aX, PRInt32 aY,
pstr[i] = mConverter[aString[i]];
}
HFONT oldFont = (HFONT) ::SelectObject(aDC, mFont);
::ExtTextOutA(aDC, aX, aY, 0, NULL, pstr, aLength, NULL);
::SelectObject(aDC, oldFont);
if (pstr != str) {
delete[] pstr;
@ -2728,7 +2720,6 @@ nsFontSubset::GetWidth(HDC aDC, const PRUnichar* aString, PRUint32 aLength)
int len = WideCharToMultiByte(mCodePage, 0, aString, aLength, str,
sizeof(str), nsnull, nsnull);
if (len) {
::SelectObject(aDC, mFont);
SIZE size;
::GetTextExtentPoint32A(aDC, str, len, &size);
return size.cx;
@ -2746,7 +2737,6 @@ nsFontSubset::DrawString(HDC aDC, PRInt32 aX, PRInt32 aY,
int len = WideCharToMultiByte(mCodePage, 0, aString, aLength, str,
sizeof(str), nsnull, nsnull);
if (len) {
::SelectObject(aDC, mFont);
::ExtTextOutA(aDC, aX, aY, 0, NULL, str, len, NULL);
}
}

Просмотреть файл

@ -1663,6 +1663,7 @@ NS_IMETHODIMP nsRenderingContextWin :: GetWidth(const PRUnichar *aString,
nsFontWin* prevFont = nsnull;
SetupFontAndColor();
HFONT selectedFont = mCurrFont;
#ifdef ARABIC_HEBREW_RENDERING
PRUnichar buf[8192];
PRUint32 len;
@ -1687,6 +1688,10 @@ FoundFont:
// XXX avoid this test by duplicating code
if (prevFont) {
if (currFont != prevFont) {
if (prevFont->mFont != selectedFont) {
::SelectObject(mDC, prevFont->mFont);
selectedFont = prevFont->mFont;
}
#ifdef ARABIC_HEBREW_RENDERING
PRBool bArabic=PR_FALSE;
PRBool bHebrew=PR_FALSE;
@ -1700,7 +1705,7 @@ FoundFont:
} else if (bArabic) {
ArabicShaping(&aString[start], i-start, buf, len, prevFont->mMap);
}
width += prevFont->GetWidth(mDC, buf, len);
width += prevFont->GetWidth(mDC, buf, len);
}
else
#endif // ARABIC_HEBREW_RENDERING
@ -1718,6 +1723,10 @@ FoundFont:
}
if (prevFont) {
if (prevFont->mFont != selectedFont) {
::SelectObject(mDC, prevFont->mFont);
selectedFont = prevFont->mFont;
}
#ifdef ARABIC_HEBREW_RENDERING
PRBool bArabic=PR_FALSE;
PRBool bHebrew=PR_FALSE;
@ -1731,17 +1740,22 @@ FoundFont:
} else if (bArabic) {
ArabicShaping(&aString[start], i-start, buf, len, prevFont->mMap);
}
width += prevFont->GetWidth(mDC, buf, len);
width += prevFont->GetWidth(mDC, buf, len);
}
else
#endif // ARABIC_HEBREW_RENDERING
{
width += prevFont->GetWidth(mDC, &aString[start], i - start);
width += prevFont->GetWidth(mDC, &aString[start], i - start);
}
}
aWidth = NSToCoordRound(float(width) * mP2T);
if (selectedFont != mCurrFont) {
// Restore the font
::SelectObject(mDC, mCurrFont);
}
if (nsnull != aFontID)
*aFontID = 0;
@ -1805,6 +1819,7 @@ NS_IMETHODIMP nsRenderingContextWin :: DrawString(const PRUnichar *aString, PRUi
nsFontWin* prevFont = nsnull;
SetupFontAndColor();
HFONT selectedFont = mCurrFont;
#ifdef ARABIC_HEBREW_RENDERING
PRUnichar buf[8192];
PRUint32 len;
@ -1827,6 +1842,10 @@ NS_IMETHODIMP nsRenderingContextWin :: DrawString(const PRUnichar *aString, PRUi
FoundFont:
if (prevFont) {
if (currFont != prevFont) {
if (prevFont->mFont != selectedFont) {
::SelectObject(mDC, prevFont->mFont);
selectedFont = prevFont->mFont;
}
if (aSpacing) {
// XXX Fix path to use a twips transform in the DC and use the
// spacing values directly and let windows deal with the sub-pixel
@ -1881,6 +1900,10 @@ FoundFont:
}
if (prevFont) {
if (prevFont->mFont != selectedFont) {
::SelectObject(mDC, prevFont->mFont);
selectedFont = prevFont->mFont;
}
if (aSpacing) {
// XXX Fix path to use a twips transform in the DC and use the
// spacing values directly and let windows deal with the sub-pixel
@ -1919,11 +1942,16 @@ FoundFont:
else
#endif // ARABIC_HEBREW_RENDERING
{
prevFont->DrawString(mDC, x, y, &aString[start], i - start);
prevFont->DrawString(mDC, x, y, &aString[start], i - start);
}
}
}
if (selectedFont != mCurrFont) {
// Restore the font
::SelectObject(mDC, mCurrFont);
}
return NS_OK;
}
else
@ -2548,6 +2576,7 @@ FoundFont:
// XXX avoid this test by duplicating code
if (prevFont) {
if (currFont != prevFont) {
::SelectObject(mDC, prevFont->mFont);
width += prevFont->GetWidth(mDC, &aString[start], i - start);
prevFont = currFont;
start = i;
@ -2560,6 +2589,7 @@ FoundFont:
}
if (prevFont) {
::SelectObject(mDC, prevFont->mFont);
width += prevFont->GetWidth(mDC, &aString[start], i - start);
}
@ -2626,6 +2656,7 @@ NS_IMETHODIMP nsRenderingContextWinA :: DrawString(const PRUnichar *aString, PRU
FoundFont:
if (prevFont) {
if (currFont != prevFont) {
::SelectObject(mDC, prevFont->mFont);
if (aSpacing) {
// XXX Fix path to use a twips transform in the DC and use the
// spacing values directly and let windows deal with the sub-pixel
@ -2660,6 +2691,7 @@ FoundFont:
}
if (prevFont) {
::SelectObject(mDC, prevFont->mFont);
if (aSpacing) {
// XXX Fix path to use a twips transform in the DC and use the
// spacing values directly and let windows deal with the sub-pixel