ReactOS  0.4.15-dev-1377-ga59cecd
GetGlyphIndices.c File Reference
#include "precomp.h"
Include dependency graph for GetGlyphIndices.c:

Go to the source code of this file.

Macros

#define ok_lasterrornotchanged()   ok_err(0x12345)
 
#define MAX_BMP_GLYPHS   0xFFFF
 

Functions

static LPVOID GetResource (LPCWSTR FontName, LPDWORD Size)
 
static BOOL ExtractTTFFile (LPCWSTR FontName, LPWSTR TempFile)
 
static BOOL InstallTempFont (LPWSTR TempFile)
 
static VOID RemoveTempFont (LPWSTR TempFile)
 
static HFONT IntCreateFont (LPWSTR FontName)
 
 START_TEST (GetGlyphIndices)
 

Macro Definition Documentation

◆ MAX_BMP_GLYPHS

#define MAX_BMP_GLYPHS   0xFFFF

Definition at line 13 of file GetGlyphIndices.c.

◆ ok_lasterrornotchanged

#define ok_lasterrornotchanged ( )    ok_err(0x12345)

Definition at line 10 of file GetGlyphIndices.c.

Function Documentation

◆ ExtractTTFFile()

static BOOL ExtractTTFFile ( LPCWSTR  FontName,
LPWSTR  TempFile 
)
static

Definition at line 32 of file GetGlyphIndices.c.

33 {
34  WCHAR TempPath[MAX_PATH];
35  HANDLE hFile;
36  void *Data;
37  DWORD Size;
38  BOOL ret;
39 
40  Data = GetResource(FontName, &Size);
41  if (!Data) return FALSE;
42 
43  GetTempPathW(MAX_PATH, TempPath);
44  GetTempFileNameW(TempPath, L"ttf", 0, TempFile);
45 
47  if (hFile == INVALID_HANDLE_VALUE) return FALSE;
48 
50 
52  return ret;
53 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CloseHandle
Definition: compat.h:598
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static const WCHAR L[]
Definition: oid.c:1250
static LPVOID GetResource(LPCWSTR FontName, LPDWORD Size)
_In_ HANDLE hFile
Definition: mswsock.h:90
#define CREATE_ALWAYS
Definition: disk.h:72
#define NULL
Definition: types.h:112
#define CreateFileW
Definition: compat.h:600

Referenced by InstallTempFont().

◆ GetResource()

static LPVOID GetResource ( LPCWSTR  FontName,
LPDWORD  Size 
)
static

Definition at line 15 of file GetGlyphIndices.c.

16 {
17  HRSRC hRsrc;
18  LPVOID Data;
19 
20  hRsrc = FindResourceW(GetModuleHandleW(NULL), FontName, (LPCWSTR)RT_RCDATA);
21  if (!hRsrc) return NULL;
22 
24  if (!Data) return NULL;
25 
27  if (*Size == 0) return NULL;
28 
29  return Data;
30 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
#define RT_RCDATA
Definition: pedump.c:372
#define NULL
Definition: types.h:112
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838

Referenced by DECLARE_INTERFACE_(), and ExtractTTFFile().

◆ InstallTempFont()

static BOOL InstallTempFont ( LPWSTR  TempFile)
static

Definition at line 55 of file GetGlyphIndices.c.

56 {
57  if (ExtractTTFFile(L"ReactOSTestTahoma.ttf", TempFile))
58  {
59  if (AddFontResourceExW(TempFile, FR_PRIVATE, 0) > 0)
60  {
61  return TRUE;
62  }
63  }
64 
65  return FALSE;
66 }
#define TRUE
Definition: types.h:120
static BOOL ExtractTTFFile(LPCWSTR FontName, LPWSTR TempFile)
#define FALSE
Definition: types.h:117
INT WINAPI AddFontResourceExW(_In_ LPCWSTR pszFilename, _In_ DWORD fl, _Reserved_ PVOID pvReserved)
static const WCHAR L[]
Definition: oid.c:1250

Referenced by START_TEST().

◆ IntCreateFont()

static HFONT IntCreateFont ( LPWSTR  FontName)
static

Definition at line 76 of file GetGlyphIndices.c.

77 {
78  LOGFONTW Font = { 0 };
79  Font.lfCharSet = DEFAULT_CHARSET;
80  wcsncpy(Font.lfFaceName, FontName, sizeof(Font.lfFaceName) / sizeof(Font.lfFaceName[0]));
81  return CreateFontIndirectW(&Font);
82 }
#define DEFAULT_CHARSET
Definition: wingdi.h:383
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)

Referenced by START_TEST().

◆ RemoveTempFont()

static VOID RemoveTempFont ( LPWSTR  TempFile)
static

Definition at line 68 of file GetGlyphIndices.c.

69 {
70  BOOL Success;
71  Success = RemoveFontResourceExW(TempFile, FR_PRIVATE, 0);
72  ok(Success, "RemoveFontResourceEx() failed, we're leaving fonts installed : %lu\n", GetLastError());
73  DeleteFileW(TempFile);
74 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI RemoveFontResourceExW(LPCWSTR lpFileName, DWORD fl, PVOID pdv)
Definition: font.c:2098

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( GetGlyphIndices  )

Definition at line 84 of file GetGlyphIndices.c.

85 {
86  WCHAR Glyphs[MAX_BMP_GLYPHS];
87  WORD Indices[MAX_BMP_GLYPHS];
88  WCHAR Single[2] = { L' ', UNICODE_NULL };
89  WCHAR TempTTFFile[MAX_PATH];
90  HFONT hFont;
91  HDC hdc;
92  int i;
93  DWORD ret;
94  static const WCHAR s_invalids[] = {0xFEFE, 0xFEFF, 0xFFFE, 0};
95 
96  if (!InstallTempFont(TempTTFFile))
97  {
98  skip("Failed to create ttf file for testing\n");
99  return;
100  }
101 
103  ok(hdc != 0, "CreateCompatibleDC failed, skipping tests.\n");
104  if (!hdc) return;
105 
106  hFont = IntCreateFont(L"ReactOSTestTahoma");
107  ok(hFont != NULL, "Failed to open the test font");
109 
110  SetLastError(0x12345);
111 
112  /* Test NULL DC */
113  ok_int(GetGlyphIndicesW(NULL, Single, 1, Indices, 0), GDI_ERROR);
115 
116  /* Test invalid DC */
117  ok_int(GetGlyphIndicesW((HDC)(ULONG_PTR)0x12345, Single, 1, Indices, 0), GDI_ERROR);
119 
120  /* Test invalid params */
125  ok_int(GetGlyphIndicesW(hdc, NULL, 0, Indices, 0), GDI_ERROR);
127  ok_int(GetGlyphIndicesW(hdc, NULL, 1, Indices, 0), GDI_ERROR);
129  ok_int(GetGlyphIndicesW(hdc, NULL, 32, Indices, 0), GDI_ERROR);
135  ok_int(GetGlyphIndicesW(hdc, Glyphs, 32, NULL, 0), GDI_ERROR);
137  ok_int(GetGlyphIndicesW(hdc, Single, 0, Indices, 0), GDI_ERROR);
139  ok_int(GetGlyphIndicesW(hdc, Single, 1, Indices, 0xFFFFFFFF), 1);
141 
142  /* Test an exceptional case that does not seem to return an error */
143  /* In this case, it returns the number of glyphs */
144  ret = GetGlyphIndicesW(hdc, NULL, 0, NULL, 0);
145  ok(ret == 988,
146  "GetGlyphIndicesW(hdc, NULL, 0, NULL, 0) return expected 988, but got %ld\n", ret);
148 
149  /* Test a single valid char */
150  Single[0] = L'a';
151  ok_int(GetGlyphIndicesW(hdc, Single, 1, Indices, 0), 1);
153  ok_int(Indices[0], 68);
154 
155  /* Setup an array of all possible BMP glyphs */
156  for (i = 0; i < 4; i++)
157  Glyphs[i] = (WCHAR)i;
158 
159  /* Test a string of valid chars */
160  StringCchCopyW(Glyphs, MAX_BMP_GLYPHS, L"0123");
161  ok_int(GetGlyphIndicesW(hdc, Glyphs, 4, Indices, 0), 4);
163  ok_int(Indices[0], 19);
164  ok_int(Indices[1], 20);
165  ok_int(Indices[2], 21);
166  ok_int(Indices[3], 22);
167 
168  ok_int(GetGlyphIndicesW(hdc, s_invalids, 3, Indices, 0), 3);
170  ok_int(Indices[0], 0);
171  ok_int(Indices[1], 0);
172  ok_int(Indices[2], 0);
173 
174  ok_int(GetGlyphIndicesW(hdc, s_invalids, 3, Indices, GGI_MARK_NONEXISTING_GLYPHS), 3);
176  ok_int(Indices[0], 0xFFFF);
177  ok_int(Indices[1], 0xFFFF);
178  ok_int(Indices[2], 0xFFFF);
179 
180  /* Setup an array of all possible BMP glyphs */
181  for (i = 0; i < MAX_BMP_GLYPHS; i++)
182  Glyphs[i] = (WCHAR)i;
183 
184  /* Get all the glyphs */
186  Glyphs,
188  Indices,
190 
191  /* The first 32 are invalid and should contain 0xffff */
192  for (i = 0; i < 32; i++)
193  ok_int(Indices[i], 0xffff);
194 
195  /* These are the first 2 valid chars */
196  ok(Indices[32] != 0xffff, "ascii char ' ' should be a valid char");
197  ok(Indices[33] != 0xffff, "ascii char '!' should be a valid char");
198 
199  RemoveTempFont(TempTTFFile);
200 }
Definition: halhw.h:165
static VOID RemoveTempFont(LPWSTR TempFile)
static BOOL InstallTempFont(LPWSTR TempFile)
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HFONT hFont
Definition: main.c:53
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define UNICODE_NULL
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define ok_lasterrornotchanged()
#define ok_int(expression, result)
Definition: atltest.h:134
#define MAX_BMP_GLYPHS
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
#define GGI_MARK_NONEXISTING_GLYPHS
Definition: wingdi.h:1084
int ret
static HFONT IntCreateFont(LPWSTR FontName)
static const WCHAR L[]
Definition: oid.c:1250
HDC hdc
Definition: main.c:9
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define skip(...)
Definition: atltest.h:64
DWORD WINAPI GetGlyphIndicesW(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpstr, _In_ int c, _Out_writes_(c) LPWORD pgi, _In_ DWORD fl)
#define GDI_ERROR
Definition: wingdi.h:1308