From 2dbf3f528edf38ea6ef45172b414bb8da447912e Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Fri, 7 Sep 2007 03:33:00 +0000 Subject: [PATCH] - add NTMW_INTERNAL structure - better structure implementation for ENUMFONTDATAW - change NewEnumFontFamiliesEx to use the new structure - some fixes and comments svn path=/trunk/; revision=28911 --- reactos/dll/win32/gdi32/objects/font.c | 46 +++++++++++++---------- reactos/include/reactos/win32k/ntgdityp.h | 28 ++++---------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/reactos/dll/win32/gdi32/objects/font.c b/reactos/dll/win32/gdi32/objects/font.c index 230bd61bcdb..bf719067ef8 100644 --- a/reactos/dll/win32/gdi32/objects/font.c +++ b/reactos/dll/win32/gdi32/objects/font.c @@ -1321,59 +1321,67 @@ NewEnumFontFamiliesExW( LPARAM lParam, DWORD dwFlags) { - ULONG_PTR idEnum, ulCount, ulSize; + ULONG_PTR idEnum, cbDataSize, cbRetSize; PENUMFONTDATAW pEfdw; PBYTE pBuffer; PBYTE pMax; INT ret = 1; + /* Open enumeration handle and find out how much memory we need */ idEnum = NtGdiEnumFontOpen(hDC, EfdFontFamilies, 0, LF_FACESIZE, - lpLogfont->lfFaceName, - lpLogfont->lfCharSet, - &ulCount); + (lpLogfont && lpLogfont->lfFaceName[0])? lpLogfont->lfFaceName : NULL, + lpLogfont? lpLogfont->lfCharSet : DEFAULT_CHARSET, + &cbDataSize); if (idEnum == 0) { return 0; } - if (ulCount == 0) + if (cbDataSize == 0) { NtGdiEnumFontClose(idEnum); return 0; } - pBuffer = HeapAlloc(GetProcessHeap(), 0, ulCount); + /* Allocate memory */ + pBuffer = HeapAlloc(GetProcessHeap(), 0, cbDataSize); if (pBuffer == NULL) { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); NtGdiEnumFontClose(idEnum); return 0; } - pMax = pBuffer + ulCount; - if (!NtGdiEnumFontChunk(hDC, idEnum, ulCount, &ulSize, (PVOID)pBuffer)) + /* Do the enumeration */ + if (!NtGdiEnumFontChunk(hDC, idEnum, cbDataSize, &cbRetSize, (PVOID)pBuffer)) { HeapFree(GetProcessHeap(), 0, pBuffer); NtGdiEnumFontClose(idEnum); return 0; } - /* Iterate through the structures */ - for (pEfdw = (PENUMFONTDATAW)pBuffer; - (PBYTE)pEfdw < pMax && pEfdw->cbSize != 0 && ret != 0; - pEfdw = (PENUMFONTDATAW)((PBYTE)pEfdw + pEfdw->cbSize)) - { - ENUMLOGFONTEXW *pElfew = &pEfdw->efdi.elfex; - NEWTEXTMETRICEXW *pNtmew = (NEWTEXTMETRICEXW*)((PBYTE)&pEfdw->efdi + pEfdw->efdi.cbSize + sizeof(DWORD)); // FIXME - DWORD dwFontType = pEfdw->efdi.dwFontType; - ret = lpEnumFontFamExProcW(pElfew, pNtmew, dwFontType, lParam); + /* Get start and end address */ + pEfdw = (PENUMFONTDATAW)pBuffer; + pMax = pBuffer + cbDataSize; + + /* Iterate through the structures */ + while ((PBYTE)pEfdw < pMax && ret) + { + PNTMW_INTERNAL pNtmwi = (PNTMW_INTERNAL)((ULONG_PTR)pEfdw + pEfdw->ulNtmwiOffset); + + ret = lpEnumFontFamExProcW(&pEfdw->elfexdv.elfEnumLogfontEx, + &pNtmwi->ntmw, + pEfdw->dwFontType, + lParam); + + pEfdw = (PENUMFONTDATAW)((ULONG_PTR)pEfdw + pEfdw->cbSize); } + /* Release the memory and close handle */ HeapFree(GetProcessHeap(), 0, pBuffer); NtGdiEnumFontClose(idEnum); return ret; } - - diff --git a/reactos/include/reactos/win32k/ntgdityp.h b/reactos/include/reactos/win32k/ntgdityp.h index cbaae8ef849..59c177309d2 100644 --- a/reactos/include/reactos/win32k/ntgdityp.h +++ b/reactos/include/reactos/win32k/ntgdityp.h @@ -120,33 +120,21 @@ typedef struct _TMW_INTERNAL TMDIFF Diff; } TMW_INTERNAL, *PTMW_INTERNAL; -typedef struct +typedef struct _NTMW_INTERNAL { - ULONG cbSize; - DWORD dwFontType; - ENUMLOGFONTEXW elfex; -/* - * Yuan 14.5: - * DESIGNVECTOR is a variable-size data structure that specifies the number of - * axes and a value for each axis. - * So it maybe smaller than MM_MAX_NUMAXES. - */ - DESIGNVECTOR dv; -} ENUMFONTDATAINTW, *PENUMFONTDATAINTW; + TMDIFF tmd; + NEWTEXTMETRICEXW ntmw; +} NTMW_INTERNAL, *PNTMW_INTERNAL; -/* Warning: this structure is of variable size! - * It is only to access the cbSize and efdi member. - * The rest of the structure has to be parsed. */ typedef struct _ENUMFONTDATAW { ULONG cbSize; - ENUMFONTDATAINTW efdi; -/* The following 2 members do not have a constant offset! */ -/* DWORD dwFlags; - ENUMTEXTMETRICW etm; */ + ULONG ulNtmwiOffset; + DWORD dwFontType; + ENUMLOGFONTEXDVW elfexdv; /* variable size! */ + /* NTMW_INTERNAL ntmwi; use ulNtwmOffset */ } ENUMFONTDATAW, *PENUMFONTDATAW; - /* Number Representation */ typedef struct _EFLOAT_S {