- 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
This commit is contained in:
Timo Kreuzer 2007-09-07 03:33:00 +00:00
parent 19aed1070b
commit 2dbf3f528e
2 changed files with 35 additions and 39 deletions

View file

@ -1321,59 +1321,67 @@ NewEnumFontFamiliesExW(
LPARAM lParam, LPARAM lParam,
DWORD dwFlags) DWORD dwFlags)
{ {
ULONG_PTR idEnum, ulCount, ulSize; ULONG_PTR idEnum, cbDataSize, cbRetSize;
PENUMFONTDATAW pEfdw; PENUMFONTDATAW pEfdw;
PBYTE pBuffer; PBYTE pBuffer;
PBYTE pMax; PBYTE pMax;
INT ret = 1; INT ret = 1;
/* Open enumeration handle and find out how much memory we need */
idEnum = NtGdiEnumFontOpen(hDC, idEnum = NtGdiEnumFontOpen(hDC,
EfdFontFamilies, EfdFontFamilies,
0, 0,
LF_FACESIZE, LF_FACESIZE,
lpLogfont->lfFaceName, (lpLogfont && lpLogfont->lfFaceName[0])? lpLogfont->lfFaceName : NULL,
lpLogfont->lfCharSet, lpLogfont? lpLogfont->lfCharSet : DEFAULT_CHARSET,
&ulCount); &cbDataSize);
if (idEnum == 0) if (idEnum == 0)
{ {
return 0; return 0;
} }
if (ulCount == 0) if (cbDataSize == 0)
{ {
NtGdiEnumFontClose(idEnum); NtGdiEnumFontClose(idEnum);
return 0; return 0;
} }
pBuffer = HeapAlloc(GetProcessHeap(), 0, ulCount); /* Allocate memory */
pBuffer = HeapAlloc(GetProcessHeap(), 0, cbDataSize);
if (pBuffer == NULL) if (pBuffer == NULL)
{ {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
NtGdiEnumFontClose(idEnum); NtGdiEnumFontClose(idEnum);
return 0; 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); HeapFree(GetProcessHeap(), 0, pBuffer);
NtGdiEnumFontClose(idEnum); NtGdiEnumFontClose(idEnum);
return 0; return 0;
} }
/* Iterate through the structures */ /* Get start and end address */
for (pEfdw = (PENUMFONTDATAW)pBuffer; pEfdw = (PENUMFONTDATAW)pBuffer;
(PBYTE)pEfdw < pMax && pEfdw->cbSize != 0 && ret != 0; pMax = pBuffer + cbDataSize;
pEfdw = (PENUMFONTDATAW)((PBYTE)pEfdw + pEfdw->cbSize))
{ /* Iterate through the structures */
ENUMLOGFONTEXW *pElfew = &pEfdw->efdi.elfex; while ((PBYTE)pEfdw < pMax && ret)
NEWTEXTMETRICEXW *pNtmew = (NEWTEXTMETRICEXW*)((PBYTE)&pEfdw->efdi + pEfdw->efdi.cbSize + sizeof(DWORD)); // FIXME {
DWORD dwFontType = pEfdw->efdi.dwFontType; PNTMW_INTERNAL pNtmwi = (PNTMW_INTERNAL)((ULONG_PTR)pEfdw + pEfdw->ulNtmwiOffset);
ret = lpEnumFontFamExProcW(pElfew, pNtmew, dwFontType, lParam);
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); HeapFree(GetProcessHeap(), 0, pBuffer);
NtGdiEnumFontClose(idEnum); NtGdiEnumFontClose(idEnum);
return ret; return ret;
} }

View file

@ -120,33 +120,21 @@ typedef struct _TMW_INTERNAL
TMDIFF Diff; TMDIFF Diff;
} TMW_INTERNAL, *PTMW_INTERNAL; } TMW_INTERNAL, *PTMW_INTERNAL;
typedef struct typedef struct _NTMW_INTERNAL
{ {
ULONG cbSize; TMDIFF tmd;
DWORD dwFontType; NEWTEXTMETRICEXW ntmw;
ENUMLOGFONTEXW elfex; } NTMW_INTERNAL, *PNTMW_INTERNAL;
/*
* 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;
/* 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 typedef struct _ENUMFONTDATAW
{ {
ULONG cbSize; ULONG cbSize;
ENUMFONTDATAINTW efdi; ULONG ulNtmwiOffset;
/* The following 2 members do not have a constant offset! */ DWORD dwFontType;
/* DWORD dwFlags; ENUMLOGFONTEXDVW elfexdv; /* variable size! */
ENUMTEXTMETRICW etm; */ /* NTMW_INTERNAL ntmwi; use ulNtwmOffset */
} ENUMFONTDATAW, *PENUMFONTDATAW; } ENUMFONTDATAW, *PENUMFONTDATAW;
/* Number Representation */ /* Number Representation */
typedef struct _EFLOAT_S typedef struct _EFLOAT_S
{ {