NtGdiExtTextOut(): fixed some double-frees I introduced, initialize variables that need it, put {} around DPRINT(1) where needed

svn path=/trunk/; revision=12205
This commit is contained in:
Royce Mitchell III 2004-12-18 21:35:35 +00:00
parent ef53a44b8a
commit de1d28fabc

View file

@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: text.c,v 1.121 2004/12/18 18:21:02 royce Exp $ */
/* $Id: text.c,v 1.122 2004/12/18 21:35:35 royce Exp $ */
#include <w32k.h>
#include <ft2build.h>
@ -184,7 +184,7 @@ IntLoadSystemFonts(VOID)
ZwClose(hDirectory);
return;
}
FileName.Buffer = ExAllocatePool(PagedPool, MAX_PATH);
if (FileName.Buffer == NULL)
{
@ -424,7 +424,7 @@ IntEnableFontRendering(BOOL Enable)
FT_Render_Mode FASTCALL
IntGetFontRenderMode(LOGFONTW *logfont)
{
{
switch(logfont->lfQuality)
{
//case ANTIALIASED_QUALITY:
@ -449,7 +449,7 @@ NtGdiAddFontResource(PUNICODE_STRING Filename, DWORD fl)
PWSTR src;
NTSTATUS Status;
int Ret;
/* Copy the UNICODE_STRING structure */
Status = MmCopyFromCaller(&SafeFileName, Filename, sizeof(UNICODE_STRING));
if(!NT_SUCCESS(Status))
@ -461,7 +461,7 @@ NtGdiAddFontResource(PUNICODE_STRING Filename, DWORD fl)
/* Reserve for prepending '\??\' */
SafeFileName.Length += 4 * sizeof(WCHAR);
SafeFileName.MaximumLength += 4 * sizeof(WCHAR);
src = SafeFileName.Buffer;
SafeFileName.Buffer = (PWSTR)ExAllocatePoolWithTag(PagedPool, SafeFileName.MaximumLength, TAG_STRING);
if(!SafeFileName.Buffer)
@ -469,7 +469,7 @@ NtGdiAddFontResource(PUNICODE_STRING Filename, DWORD fl)
SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
/* Prepend '\??\' */
RtlCopyMemory(SafeFileName.Buffer, L"\\??\\", 4 * sizeof(WCHAR));
@ -480,9 +480,9 @@ NtGdiAddFontResource(PUNICODE_STRING Filename, DWORD fl)
SetLastNtError(Status);
return 0;
}
Ret = IntGdiAddFontResource(&SafeFileName, fl);
ExFreePool(SafeFileName.Buffer);
return Ret;
}
@ -511,7 +511,7 @@ TextIntCreateFontIndirect(CONST LPLOGFONTW lf, HFONT *NewFont)
{
/* FIXME */
/* ASSERT(FALSE);*/
Status = STATUS_INVALID_HANDLE;
Status = STATUS_INVALID_HANDLE;
}
}
else
@ -809,7 +809,7 @@ IntGetOutlineTextMetrics(PFONTGDI FontGDI, UINT Size,
TM->tmAveCharWidth = (FT_MulFix(pOS2->xAvgCharWidth, XScale) + 32) >> 6;
if (0 == TM->tmAveCharWidth)
{
TM->tmAveCharWidth = 1;
TM->tmAveCharWidth = 1;
}
TM->tmMaxCharWidth = (FT_MulFix(FontGDI->face->bbox.xMax - FontGDI->face->bbox.xMin,
XScale) + 32) >> 6;
@ -972,7 +972,7 @@ FindFaceNameInList(PUNICODE_STRING FaceName, PLIST_ENTRY Head)
FontGDI = CurrentEntry->Font;
ASSERT(FontGDI);
RtlInitAnsiString(&EntryFaceNameA, FontGDI->face->family_name);
RtlAnsiStringToUnicodeString(&EntryFaceNameW, &EntryFaceNameA, TRUE);
if ((LF_FACESIZE - 1) * sizeof(WCHAR) < EntryFaceNameW.Length)
@ -1032,7 +1032,7 @@ FontFamilyFillInfo(PFONTFAMILYINFO Info, PCWSTR FaceName, PFONTGDI FontGDI)
LOGFONTW *Lf;
TEXTMETRICW *TM;
NEWTEXTMETRICW *Ntm;
ZeroMemory(Info, sizeof(FONTFAMILYINFO));
Size = IntGetOutlineTextMetrics(FontGDI, 0, NULL);
Otm = ExAllocatePoolWithTag(PagedPool, Size, TAG_GDITEXT);
@ -1124,7 +1124,7 @@ FontFamilyFillInfo(PFONTFAMILYINFO Info, PCWSTR FaceName, PFONTGDI FontGDI)
if (0 == pOS2->version)
{
FT_UInt Dummy;
if (FT_Get_First_Char(FontGDI->face, &Dummy) < 0x100)
{
fs_fsCsb0 |= 1;
@ -1411,7 +1411,7 @@ NtGdiGetFontFamilyInfo(HDC Dc,
/* Enumerate font families in the process local list */
Win32Process = PsGetWin32Process();
IntLockProcessPrivateFonts(Win32Process);
if (! GetFontFamilyInfoForList(&LogFont, Info, &Count, Size,
if (! GetFontFamilyInfoForList(&LogFont, Info, &Count, Size,
&Win32Process->PrivateFontListHead))
{
IntUnLockProcessPrivateFonts(Win32Process);
@ -1499,7 +1499,7 @@ NtGdiExtTextOut(
PFONTGDI FontGDI;
PTEXTOBJ TextObj = NULL;
PPALGDI PalDestGDI;
XLATEOBJ *XlateObj, *XlateObj2;
XLATEOBJ *XlateObj=NULL, *XlateObj2=NULL;
ULONG Mode;
FT_Render_Mode RenderMode;
BOOLEAN Render;
@ -1513,7 +1513,7 @@ NtGdiExtTextOut(
SetLastWin32Error(ERROR_INVALID_HANDLE);
return FALSE;
}
if (NULL != UnsafeDx && Count > 0)
{
Dx = ExAllocatePoolWithTag(PagedPool, Count * sizeof(INT), TAG_GDITEXT);
@ -1527,10 +1527,12 @@ NtGdiExtTextOut(
goto fail;
}
}
BitmapObj = BITMAPOBJ_LockBitmap(dc->w.hBitmap);
if ( !BitmapObj )
{
goto fail;
}
SurfObj = &BitmapObj->SurfObj;
ASSERT(SurfObj);
@ -1543,35 +1545,47 @@ NtGdiExtTextOut(
/* Create the brushes */
PalDestGDI = PALETTE_LockPalette(dc->w.hPalette);
if ( !PalDestGDI )
Mode = PAL_RGB;
Mode = PAL_RGB;
else
{
Mode = PalDestGDI->Mode;
PALETTE_UnlockPalette(dc->w.hPalette);
Mode = PalDestGDI->Mode;
PALETTE_UnlockPalette(dc->w.hPalette);
}
XlateObj = (XLATEOBJ*)IntEngCreateXlate(Mode, PAL_RGB, dc->w.hPalette, NULL);
if ( !XlateObj )
{
goto fail;
}
hBrushFg = NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj, dc->w.textColor));
if ( !hBrushFg )
{
goto fail;
}
BrushFg = BRUSHOBJ_LockBrush(hBrushFg);
if ( !BrushFg )
{
goto fail;
}
IntGdiInitBrushInstance(&BrushFgInst, BrushFg, NULL);
if ((fuOptions & ETO_OPAQUE) || dc->w.backgroundMode == OPAQUE)
{
hBrushBg = NtGdiCreateSolidBrush(XLATEOBJ_iXlate(XlateObj, dc->w.backgroundColor));
if ( !hBrushBg )
{
goto fail;
}
BrushBg = BRUSHOBJ_LockBrush(hBrushBg);
if ( !BrushBg )
{
goto fail;
}
IntGdiInitBrushInstance(&BrushBgInst, BrushBg, NULL);
}
XlateObj2 = (XLATEOBJ*)IntEngCreateXlate(PAL_RGB, Mode, NULL, dc->w.hPalette);
if ( !XlateObj2 )
{
goto fail;
}
SourcePoint.x = 0;
SourcePoint.y = 0;
@ -1612,7 +1626,7 @@ NtGdiExtTextOut(
TextObj = TEXTOBJ_LockText(dc->w.hFont);
if(TextObj == NULL)
{
goto fail;
goto fail;
}
FontObj = TextObj->Font;
@ -1637,12 +1651,16 @@ NtGdiExtTextOut(
}
}
if (!found)
{
DPRINT1("WARNING: Could not find desired charmap!\n");
}
IntLockFreeType;
error = FT_Set_Charmap(face, found);
IntUnLockFreeType;
if (error)
{
DPRINT1("WARNING: Could not set the charmap!\n");
}
}
Render = IntIsFontRenderingEnabled();
@ -1650,7 +1668,7 @@ NtGdiExtTextOut(
RenderMode = IntGetFontRenderMode(&TextObj->logfont);
else
RenderMode = FT_RENDER_MODE_MONO;
IntLockFreeType;
error = FT_Set_Pixel_Sizes(
face,
@ -1711,7 +1729,7 @@ NtGdiExtTextOut(
glyph_index = FT_Get_Char_Index(face, *TempText);
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
IntUnLockFreeType;
if (error)
{
DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index);
@ -1764,8 +1782,6 @@ NtGdiExtTextOut(
if (error)
{
EngDeleteXlate(XlateObj);
EngDeleteXlate(XlateObj2);
DPRINT1("WARNING: Failed to load and render glyph! [index: %u]\n", glyph_index);
goto fail;
}
@ -1789,8 +1805,6 @@ NtGdiExtTextOut(
IntUnLockFreeType;
if (error)
{
EngDeleteXlate(XlateObj);
EngDeleteXlate(XlateObj2);
DPRINT1("WARNING: Failed to render glyph!\n");
goto fail;
}
@ -1824,12 +1838,12 @@ NtGdiExtTextOut(
DestRect.right = DestRect.left + glyph->bitmap.width;
DestRect.top = TextTop + yoff - glyph->bitmap_top;
DestRect.bottom = DestRect.top + glyph->bitmap.rows;
bitSize.cx = glyph->bitmap.width;
bitSize.cy = glyph->bitmap.rows;
MaskRect.right = glyph->bitmap.width;
MaskRect.bottom = glyph->bitmap.rows;
/*
* We should create the bitmap out of the loop at the biggest possible
* glyph size. Then use memset with 0 to clear it and sourcerect to
@ -1839,8 +1853,6 @@ NtGdiExtTextOut(
HSourceGlyph = EngCreateBitmap(bitSize, pitch, (glyph->bitmap.pixel_mode == ft_pixel_mode_grays) ? BMF_8BPP : BMF_1BPP, BMF_TOPDOWN, glyph->bitmap.buffer);
if ( !HSourceGlyph )
{
EngDeleteXlate(XlateObj);
EngDeleteXlate(XlateObj2);
DPRINT1("WARNING: EngLockSurface() failed!\n");
goto fail;
}
@ -1848,12 +1860,10 @@ NtGdiExtTextOut(
if ( !SourceGlyphSurf )
{
EngDeleteSurface((HSURF)HSourceGlyph);
EngDeleteXlate(XlateObj);
EngDeleteXlate(XlateObj2);
DPRINT1("WARNING: EngLockSurface() failed!\n");
goto fail;
}
/*
* Use the font data as a mask to paint onto the DCs surface using a
* brush.
@ -1904,7 +1914,7 @@ NtGdiExtTextOut(
ExFreePool(Dx);
}
DC_UnlockDc( hDC );
return TRUE;
fail:
@ -2027,7 +2037,7 @@ NtGdiGetCharWidth32(HDC hDC,
}
FontGDI = ObjToGDI(TextObj->Font, FONT);
face = FontGDI->face;
if (face->charmap == NULL)
{
@ -2554,7 +2564,7 @@ NtGdiGetTextMetrics(HDC hDC,
SetLastWin32Error(STATUS_INVALID_PARAMETER);
return FALSE;
}
if(!(dc = DC_LockDc(hDC)))
{
SetLastWin32Error(ERROR_INVALID_HANDLE);
@ -2612,13 +2622,13 @@ NtGdiGetTextMetrics(HDC hDC,
Status = STATUS_INVALID_HANDLE;
}
DC_UnlockDc(hDC);
if(!NT_SUCCESS(Status))
{
SetLastNtError(Status);
return FALSE;
}
return TRUE;
}
@ -2742,9 +2752,9 @@ NtGdiGetFontData(
SetLastWin32Error(ERROR_INVALID_HANDLE);
return GDI_ERROR;
}
FontGdi = ObjToGDI(TextObj->Font, FONT);
IntLockFreeType;
if (FT_IS_SFNT(FontGdi->face))
@ -2764,7 +2774,7 @@ NtGdiGetFontData(
TEXTOBJ_UnlockText(hFont);
return Result;
return Result;
}
static UINT FASTCALL
@ -2777,7 +2787,7 @@ GetFontScore(LOGFONTW *LogFont, PUNICODE_STRING FaceName, PFONTGDI FontGDI)
LONG WeightDiff;
NTSTATUS Status;
UINT Score = 1;
RtlInitAnsiString(&EntryFaceNameA, FontGDI->face->family_name);
Status = RtlAnsiStringToUnicodeString(&EntryFaceNameW, &EntryFaceNameA, TRUE);
if (NT_SUCCESS(Status))
@ -2923,7 +2933,7 @@ TextIntRealizeFont(HFONT FontHandle)
SubstituteFontFamily(&FaceName, 0);
MatchScore = 0;
TextObj->Font = NULL;
/* First search private fonts */
Win32Process = PsGetWin32Process();
IntLockProcessPrivateFonts(Win32Process);
@ -2931,7 +2941,7 @@ TextIntRealizeFont(HFONT FontHandle)
&TextObj->logfont, &FaceName,
&Win32Process->PrivateFontListHead);
IntUnLockProcessPrivateFonts(Win32Process);
/* Search system fonts */
IntLockGlobalFonts;
FindBestFontFromList(&TextObj->Font, &MatchScore,
@ -2952,7 +2962,7 @@ TextIntRealizeFont(HFONT FontHandle)
RtlFreeUnicodeString(&FaceName);
TEXTOBJ_UnlockText(FontHandle);
ASSERT((NT_SUCCESS(Status) ^ (NULL == TextObj->Font)) != 0);
return Status;