ReactOS 0.4.16-dev-250-g3ecd236
font.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winreg.h"
#include "wine/debug.h"
#include "msipriv.h"
Include dependency graph for font.c:

Go to the source code of this file.

Classes

struct  offset_table
 
struct  table_directory
 
struct  name_table_header
 
struct  name_record
 

Macros

#define NAME_ID_FULL_FONT_NAME   4
 
#define NAME_ID_VERSION   5
 
#define SWAPWORD(x)   MAKEWORD(HIBYTE(x), LOBYTE(x))
 
#define SWAPLONG(x)   MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msi)
 
static WCHARload_ttf_name_id (MSIPACKAGE *package, const WCHAR *filename, DWORD id)
 
static WCHARfont_name_from_file (MSIPACKAGE *package, const WCHAR *filename)
 
WCHARmsi_get_font_file_version (MSIPACKAGE *package, const WCHAR *filename)
 
static UINT ITERATE_RegisterFonts (MSIRECORD *row, LPVOID param)
 
UINT ACTION_RegisterFonts (MSIPACKAGE *package)
 
static UINT ITERATE_UnregisterFonts (MSIRECORD *row, LPVOID param)
 
UINT ACTION_UnregisterFonts (MSIPACKAGE *package)
 

Macro Definition Documentation

◆ NAME_ID_FULL_FONT_NAME

#define NAME_ID_FULL_FONT_NAME   4

Definition at line 56 of file font.c.

◆ NAME_ID_VERSION

#define NAME_ID_VERSION   5

Definition at line 57 of file font.c.

◆ SWAPLONG

#define SWAPLONG (   x)    MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))

Definition at line 70 of file font.c.

◆ SWAPWORD

#define SWAPWORD (   x)    MAKEWORD(HIBYTE(x), LOBYTE(x))

Definition at line 69 of file font.c.

Function Documentation

◆ ACTION_RegisterFonts()

UINT ACTION_RegisterFonts ( MSIPACKAGE package)

Definition at line 279 of file font.c.

280{
281 MSIQUERY *view;
282 UINT rc;
283
284 if (package->script == SCRIPT_NONE)
285 return msi_schedule_action(package, SCRIPT_INSTALL, L"RegisterFonts");
286
287 rc = MSI_DatabaseOpenViewW(package->db, L"SELECT * FROM `Font`", &view);
288 if (rc != ERROR_SUCCESS)
289 return ERROR_SUCCESS;
290
292 msiobj_release(&view->hdr);
293 return rc;
294}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
UINT msi_schedule_action(MSIPACKAGE *package, UINT script, const WCHAR *action)
Definition: custom.c:90
static UINT ITERATE_RegisterFonts(MSIRECORD *row, LPVOID param)
Definition: font.c:215
int msiobj_release(MSIOBJECTHDR *info)
Definition: handle.c:241
@ SCRIPT_INSTALL
Definition: msipriv.h:385
@ SCRIPT_NONE
Definition: msipriv.h:384
UINT MSI_DatabaseOpenViewW(MSIDATABASE *, LPCWSTR, MSIQUERY **)
UINT MSI_IterateRecords(MSIQUERY *, LPDWORD, record_func, LPVOID)
Definition: msiquery.c:163
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
MSIDATABASE * db
Definition: msipriv.h:394
enum script script
Definition: msipriv.h:432

◆ ACTION_UnregisterFonts()

UINT ACTION_UnregisterFonts ( MSIPACKAGE package)

Definition at line 360 of file font.c.

361{
362 MSIQUERY *view;
363 UINT r;
364
365 if (package->script == SCRIPT_NONE)
366 return msi_schedule_action(package, SCRIPT_INSTALL, L"UnregisterFonts");
367
368 r = MSI_DatabaseOpenViewW( package->db, L"SELECT * FROM `Font`", &view );
369 if (r != ERROR_SUCCESS)
370 return ERROR_SUCCESS;
371
373 msiobj_release( &view->hdr );
374 return r;
375}
static UINT ITERATE_UnregisterFonts(MSIRECORD *row, LPVOID param)
Definition: font.c:296
GLdouble GLdouble GLdouble r
Definition: gl.h:2055

◆ font_name_from_file()

static WCHAR * font_name_from_file ( MSIPACKAGE package,
const WCHAR filename 
)
static

Definition at line 169 of file font.c.

170{
171 WCHAR *name, *ret = NULL;
172
174 {
175 if (!name[0])
176 {
177 WARN("empty font name\n");
178 free( name );
179 return NULL;
180 }
181 ret = malloc( wcslen( name ) * sizeof(WCHAR) + sizeof( L" (TrueType)" ) );
182 lstrcpyW( ret, name );
183 lstrcatW( ret, L" (TrueType)" );
184 free( name );
185 }
186 return ret;
187}
#define WARN(fmt,...)
Definition: precomp.h:61
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define lstrcpyW
Definition: compat.h:749
#define NAME_ID_FULL_FONT_NAME
Definition: font.c:1185
static WCHAR * load_ttf_name_id(const BYTE *mem, DWORD_PTR size, DWORD id)
Definition: font.c:1426
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
const char * filename
Definition: ioapi.h:137
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
Definition: name.c:39
int ret
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ITERATE_RegisterFonts(), and ITERATE_UnregisterFonts().

◆ ITERATE_RegisterFonts()

static UINT ITERATE_RegisterFonts ( MSIRECORD row,
LPVOID  param 
)
static

Definition at line 215 of file font.c.

216{
217 MSIPACKAGE *package = param;
218 LPWSTR name;
220 MSIFILE *file;
221 MSICOMPONENT *comp;
222 HKEY hkey1, hkey2;
223 MSIRECORD *uirow;
224 LPWSTR uipath, p;
225
227 file = msi_get_loaded_file( package, filename );
228 if (!file)
229 {
230 WARN("unable to find file %s\n", debugstr_w(filename));
231 return ERROR_SUCCESS;
232 }
233 comp = msi_get_loaded_component( package, file->Component->Component );
234 if (!comp)
235 {
236 WARN("unable to find component %s\n", debugstr_w(file->Component->Component));
237 return ERROR_SUCCESS;
238 }
239 comp->Action = msi_get_component_action( package, comp );
240 if (comp->Action != INSTALLSTATE_LOCAL)
241 {
242 TRACE("component not scheduled for installation %s\n", debugstr_w(comp->Component));
243 return ERROR_SUCCESS;
244 }
245
246 RegCreateKeyW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts" ,&hkey1 );
247 RegCreateKeyW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Fonts", &hkey2 );
248
249 if (MSI_RecordIsNull(row,2))
250 name = font_name_from_file( package, file->TargetPath );
251 else
253
254 if (name)
255 {
256 msi_reg_set_val_str( hkey1, name, file->TargetPath);
257 msi_reg_set_val_str( hkey2, name, file->TargetPath);
258 }
259
260 free(name);
261 RegCloseKey(hkey1);
262 RegCloseKey(hkey2);
263
264 /* the UI chunk */
265 uirow = MSI_CreateRecord( 1 );
266 uipath = wcsdup( file->TargetPath );
267 p = wcsrchr(uipath,'\\');
268 if (p) p++;
269 else p = uipath;
270 MSI_RecordSetStringW( uirow, 1, p );
272 msiobj_release( &uirow->hdr );
273 free( uipath );
274 /* FIXME: call msi_ui_progress? */
275
276 return ERROR_SUCCESS;
277}
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1201
#define wcsrchr
Definition: compat.h:16
INSTALLSTATE msi_get_component_action(MSIPACKAGE *package, MSICOMPONENT *comp)
Definition: action.c:609
MSICOMPONENT * msi_get_loaded_component(MSIPACKAGE *package, const WCHAR *Component)
Definition: action.c:550
MSIFILE * msi_get_loaded_file(MSIPACKAGE *package, const WCHAR *key)
Definition: action.c:572
static WCHAR * font_name_from_file(MSIPACKAGE *package, const WCHAR *filename)
Definition: font.c:169
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
GLfloat GLfloat p
Definition: glext.h:8902
#define debugstr_w
Definition: kernel32.h:32
@ INSTALLMESSAGE_ACTIONDATA
Definition: msi.h:103
@ INSTALLSTATE_LOCAL
Definition: msi.h:46
WCHAR * msi_dup_record_field(MSIRECORD *row, INT index)
Definition: record.c:1002
const WCHAR * MSI_RecordGetString(const MSIRECORD *, UINT)
Definition: record.c:433
LONG msi_reg_set_val_str(HKEY hkey, LPCWSTR name, LPCWSTR value)
Definition: registry.c:209
BOOL MSI_RecordIsNull(MSIRECORD *, UINT)
Definition: record.c:321
INT MSI_ProcessMessage(MSIPACKAGE *, INSTALLMESSAGE, MSIRECORD *)
Definition: package.c:1909
UINT MSI_RecordSetStringW(MSIRECORD *, UINT, LPCWSTR)
Definition: record.c:597
MSIRECORD * MSI_CreateRecord(UINT)
Definition: record.c:76
_Check_return_ _CRTIMP wchar_t *__cdecl wcsdup(_In_z_ const wchar_t *_Str)
#define TRACE(s)
Definition: solgame.cpp:4
Definition: fci.c:127
LPWSTR Component
Definition: msipriv.h:524
INSTALLSTATE Action
Definition: msipriv.h:532
MSIOBJECTHDR hdr
Definition: msipriv.h:151
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by ACTION_RegisterFonts().

◆ ITERATE_UnregisterFonts()

static UINT ITERATE_UnregisterFonts ( MSIRECORD row,
LPVOID  param 
)
static

Definition at line 296 of file font.c.

297{
298 MSIPACKAGE *package = param;
299 LPWSTR name;
301 MSIFILE *file;
302 MSICOMPONENT *comp;
303 HKEY hkey1, hkey2;
304 MSIRECORD *uirow;
305 LPWSTR uipath, p;
306
308 file = msi_get_loaded_file( package, filename );
309 if (!file)
310 {
311 WARN("unable to find file %s\n", debugstr_w(filename));
312 return ERROR_SUCCESS;
313 }
314 comp = msi_get_loaded_component( package, file->Component->Component );
315 if (!comp)
316 {
317 WARN("unable to find component %s\n", debugstr_w(file->Component->Component));
318 return ERROR_SUCCESS;
319 }
320 comp->Action = msi_get_component_action( package, comp );
321 if (comp->Action != INSTALLSTATE_ABSENT)
322 {
323 TRACE("component not scheduled for removal %s\n", debugstr_w(comp->Component));
324 return ERROR_SUCCESS;
325 }
326
327 RegCreateKeyW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", &hkey1 );
328 RegCreateKeyW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Fonts", &hkey2 );
329
330 if (MSI_RecordIsNull( row, 2 ))
331 name = font_name_from_file( package, file->TargetPath );
332 else
334
335 if (name)
336 {
337 RegDeleteValueW( hkey1, name );
338 RegDeleteValueW( hkey2, name );
339 }
340
341 free( name );
342 RegCloseKey( hkey1 );
343 RegCloseKey( hkey2 );
344
345 /* the UI chunk */
346 uirow = MSI_CreateRecord( 1 );
347 uipath = wcsdup( file->TargetPath );
348 p = wcsrchr( uipath,'\\' );
349 if (p) p++;
350 else p = uipath;
351 MSI_RecordSetStringW( uirow, 1, p );
353 msiobj_release( &uirow->hdr );
354 free( uipath );
355 /* FIXME: call msi_ui_progress? */
356
357 return ERROR_SUCCESS;
358}
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
@ INSTALLSTATE_ABSENT
Definition: msi.h:45

Referenced by ACTION_UnregisterFonts().

◆ load_ttf_name_id()

static WCHAR * load_ttf_name_id ( MSIPACKAGE package,
const WCHAR filename,
DWORD  id 
)
static

Definition at line 76 of file font.c.

77{
78 struct table_directory tblDir;
79 BOOL bFound = FALSE;
80 struct offset_table ttOffsetTable;
81 struct name_table_header ttNTHeader;
82 struct name_record ttRecord;
83 DWORD dwRead;
85 LPWSTR ret = NULL;
86 int i;
87
88 if (package)
90 else
93 {
94 ERR("Unable to open font file %s\n", debugstr_w(filename));
95 return NULL;
96 }
97
98 if (!ReadFile(handle,&ttOffsetTable, sizeof(struct offset_table),&dwRead,NULL))
99 goto end;
100
101 ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
102 ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
103 ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
104
105 if ((ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0) &&
106 (ttOffsetTable.uMajorVersion != 0x4f54 || ttOffsetTable.uMinorVersion != 0x544f))
107 goto end;
108
109 for (i=0; i< ttOffsetTable.uNumOfTables; i++)
110 {
111 if (!ReadFile(handle, &tblDir, sizeof(tblDir), &dwRead, NULL))
112 break;
113 if (memcmp(tblDir.szTag,"name",4)==0)
114 {
115 bFound = TRUE;
116 tblDir.uLength = SWAPLONG(tblDir.uLength);
117 tblDir.uOffset = SWAPLONG(tblDir.uOffset);
118 break;
119 }
120 }
121
122 if (!bFound)
123 goto end;
124
125 SetFilePointer(handle, tblDir.uOffset, NULL, FILE_BEGIN);
126 if (!ReadFile(handle, &ttNTHeader, sizeof(ttNTHeader), &dwRead, NULL))
127 goto end;
128
129 ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
130 ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
131 for(i=0; i<ttNTHeader.uNRCount; i++)
132 {
133 if (!ReadFile(handle, &ttRecord, sizeof(ttRecord), &dwRead, NULL))
134 break;
135
136 ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
137 ttRecord.uPlatformID = SWAPWORD(ttRecord.uPlatformID);
138 ttRecord.uEncodingID = SWAPWORD(ttRecord.uEncodingID);
139 if (ttRecord.uNameID == id && ttRecord.uPlatformID == 3 &&
140 (ttRecord.uEncodingID == 0 || ttRecord.uEncodingID == 1))
141 {
142 WCHAR *buf;
143 unsigned int i;
144
145 ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
146 ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
147 SetFilePointer(handle, tblDir.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset,
149 if (!(buf = calloc(ttRecord.uStringLength, sizeof(WCHAR)))) goto end;
150 dwRead = 0;
151 ReadFile(handle, buf, ttRecord.uStringLength, &dwRead, NULL);
152 if (dwRead % sizeof(WCHAR))
153 {
154 free(buf);
155 goto end;
156 }
157 for (i = 0; i < dwRead / sizeof(WCHAR); i++) buf[i] = SWAPWORD(buf[i]);
158 ret = wcsdup(buf);
159 free(buf);
160 break;
161 }
162 }
163
164end:
166 return ret;
167}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ERR(fmt,...)
Definition: precomp.h:57
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define FILE_BEGIN
Definition: compat.h:761
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
HANDLE msi_create_file(MSIPACKAGE *package, const WCHAR *filename, DWORD access, DWORD sharing, DWORD creation, DWORD flags)
Definition: files.c:60
#define SWAPLONG(x)
Definition: font.c:70
#define SWAPWORD(x)
Definition: font.c:69
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint end
Definition: gl.h:1545
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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 calloc
Definition: rosglue.h:14

◆ msi_get_font_file_version()

WCHAR * msi_get_font_file_version ( MSIPACKAGE package,
const WCHAR filename 
)

Definition at line 189 of file font.c.

190{
191 WCHAR *version, *p, *q, *ret = NULL;
192
194 {
195 int len, major = 0, minor = 0;
196 if ((p = wcschr( version, ';' ))) *p = 0;
197 p = version;
198 while (*p && !iswdigit( *p )) p++;
199 if ((q = wcschr( p, '.' )))
200 {
201 major = wcstol( p, NULL, 10 );
202 p = ++q;
203 while (*q && iswdigit( *q )) q++;
204 if (!*q || *q == ' ') minor = wcstol( p, NULL, 10 );
205 else major = 0;
206 }
207 len = lstrlenW( L"%u.%u.0.0" ) + 20;
208 ret = malloc( len * sizeof(WCHAR) );
209 swprintf( ret, len, L"%u.%u.0.0", major, minor );
210 free( version );
211 }
212 return ret;
213}
#define wcschr
Definition: compat.h:17
#define lstrlenW
Definition: compat.h:750
static const WCHAR version[]
Definition: asmname.c:66
#define NAME_ID_VERSION
Definition: font.c:57
#define swprintf
Definition: precomp.h:40
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLenum GLsizei len
Definition: glext.h:6722
#define iswdigit(_c)
Definition: ctype.h:667
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define minor(rdev)
Definition: propsheet.cpp:929
#define major(rdev)
Definition: propsheet.cpp:928

Referenced by calculate_file_cost(), calculate_install_state(), and MsiGetFileVersionW().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msi  )