Commit da604dce authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Use Windows paths in add/remove_font_resource().

parent 6d582ed5
...@@ -2301,14 +2301,29 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_ ...@@ -2301,14 +2301,29 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_
return ret; return ret;
} }
static int remove_font_resource( const char *file, DWORD flags ) static int add_font_resource( const WCHAR *file, DWORD flags )
{
int ret = 0;
char *unixname = wine_get_unix_file_name( file );
if (unixname)
{
ret = AddFontToList( unixname, NULL, 0, flags );
HeapFree( GetProcessHeap(), 0, unixname );
}
return ret;
}
static int remove_font_resource( const WCHAR *file, DWORD flags )
{ {
Family *family, *family_next; Family *family, *family_next;
Face *face, *face_next; Face *face, *face_next;
struct stat st; struct stat st;
int count = 0; int count = 0;
char *unixname;
if (stat( file, &st ) == -1) return 0; if (!(unixname = wine_get_unix_file_name( file ))) return 0;
if (stat( unixname, &st ) == -1) goto done;
LIST_FOR_EACH_ENTRY_SAFE( family, family_next, &font_list, Family, entry ) LIST_FOR_EACH_ENTRY_SAFE( family, family_next, &font_list, Family, entry )
{ {
family->refcount++; family->refcount++;
...@@ -2325,6 +2340,8 @@ static int remove_font_resource( const char *file, DWORD flags ) ...@@ -2325,6 +2340,8 @@ static int remove_font_resource( const char *file, DWORD flags )
} }
release_family( family ); release_family( family );
} }
done:
HeapFree( GetProcessHeap(), 0, unixname );
return count; return count;
} }
...@@ -3030,77 +3047,50 @@ static char *get_font_dir(void) ...@@ -3030,77 +3047,50 @@ static char *get_font_dir(void)
return name; return name;
} }
static char *get_data_dir_path( LPCWSTR file ) static void get_data_dir_path( LPCWSTR file, WCHAR *path )
{ {
char *unix_name = NULL; static const WCHAR slashW[] = {'\\','\0'};
char *font_dir = get_font_dir(); char *font_dir = get_font_dir();
if (font_dir) if (font_dir)
{ {
INT len = WideCharToMultiByte(CP_UNIXCP, 0, file, -1, NULL, 0, NULL, NULL); WCHAR *dirW = wine_get_dos_file_name( font_dir );
strcpyW( path, dirW );
unix_name = HeapAlloc(GetProcessHeap(), 0, strlen(font_dir) + len + 1 ); strcatW( path, slashW );
strcpy(unix_name, font_dir); strcatW( path, file );
strcat(unix_name, "/"); HeapFree( GetProcessHeap(), 0, dirW );
WideCharToMultiByte(CP_UNIXCP, 0, file, -1, unix_name + strlen(unix_name), len, NULL, NULL);
HeapFree( GetProcessHeap(), 0, font_dir ); HeapFree( GetProcessHeap(), 0, font_dir );
} }
return unix_name;
} }
static BOOL load_font_from_data_dir(LPCWSTR file) static void get_winfonts_dir_path(LPCWSTR file, WCHAR *path)
{
BOOL ret = FALSE;
char *unix_name = get_data_dir_path( file );
if (unix_name)
{
EnterCriticalSection( &freetype_cs );
ret = AddFontToList(unix_name, NULL, 0, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE);
LeaveCriticalSection( &freetype_cs );
HeapFree(GetProcessHeap(), 0, unix_name);
}
return ret;
}
static char *get_winfonts_dir_path(LPCWSTR file)
{ {
static const WCHAR slashW[] = {'\\','\0'}; static const WCHAR slashW[] = {'\\','\0'};
WCHAR windowsdir[MAX_PATH];
GetWindowsDirectoryW(windowsdir, ARRAY_SIZE(windowsdir)); GetWindowsDirectoryW(path, MAX_PATH);
strcatW(windowsdir, fontsW); strcatW(path, fontsW);
strcatW(windowsdir, slashW); strcatW(path, slashW);
strcatW(windowsdir, file); strcatW(path, file);
return wine_get_unix_file_name( windowsdir );
} }
static void load_system_fonts(void) static void load_system_fonts(void)
{ {
HKEY hkey; HKEY hkey;
WCHAR data[MAX_PATH], windowsdir[MAX_PATH], pathW[MAX_PATH]; WCHAR data[MAX_PATH], pathW[MAX_PATH];
const WCHAR * const *value; const WCHAR * const *value;
DWORD dlen, type; DWORD dlen, type;
static const WCHAR fmtW[] = {'%','s','\\','%','s','\0'};
char *unixname;
if(RegOpenKeyW(HKEY_CURRENT_CONFIG, system_fonts_reg_key, &hkey) == ERROR_SUCCESS) { if(RegOpenKeyW(HKEY_CURRENT_CONFIG, system_fonts_reg_key, &hkey) == ERROR_SUCCESS) {
GetWindowsDirectoryW(windowsdir, ARRAY_SIZE(windowsdir));
strcatW(windowsdir, fontsW);
for(value = SystemFontValues; *value; value++) { for(value = SystemFontValues; *value; value++) {
dlen = sizeof(data); dlen = sizeof(data);
if(RegQueryValueExW(hkey, *value, 0, &type, (void*)data, &dlen) == ERROR_SUCCESS && if(RegQueryValueExW(hkey, *value, 0, &type, (void*)data, &dlen) == ERROR_SUCCESS &&
type == REG_SZ) { type == REG_SZ) {
BOOL added = FALSE; get_winfonts_dir_path( data, pathW );
if (!add_font_resource( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE ))
sprintfW(pathW, fmtW, windowsdir, data); {
if((unixname = wine_get_unix_file_name(pathW))) { get_data_dir_path( data, pathW );
added = AddFontToList(unixname, NULL, 0, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE); add_font_resource( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE );
HeapFree(GetProcessHeap(), 0, unixname);
} }
if (!added)
load_font_from_data_dir(data);
} }
} }
RegCloseKey(hkey); RegCloseKey(hkey);
...@@ -3299,36 +3289,29 @@ static void delete_external_font_keys(void) ...@@ -3299,36 +3289,29 @@ static void delete_external_font_keys(void)
*/ */
INT WineEngAddFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv) INT WineEngAddFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv)
{ {
WCHAR path[MAX_PATH];
INT ret = 0; INT ret = 0;
GDI_CheckNotLock(); GDI_CheckNotLock();
if (ft_handle) /* do it only if we have freetype up and running */ if (ft_handle) /* do it only if we have freetype up and running */
{ {
char *unixname; DWORD addfont_flags = ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE;
EnterCriticalSection( &freetype_cs ); EnterCriticalSection( &freetype_cs );
if((unixname = wine_get_unix_file_name(file))) if (!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE;
{ ret = add_font_resource( file, addfont_flags );
DWORD addfont_flags = ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE;
if(!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE;
ret = AddFontToList(unixname, NULL, 0, addfont_flags);
HeapFree(GetProcessHeap(), 0, unixname);
}
if (!ret && !strchrW(file, '\\')) { if (!ret && !strchrW(file, '\\')) {
/* Try in %WINDIR%/fonts, needed for Fotobuch Designer */ /* Try in %WINDIR%/fonts, needed for Fotobuch Designer */
if ((unixname = get_winfonts_dir_path( file ))) get_winfonts_dir_path( file, path );
{ ret = add_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE );
ret = AddFontToList(unixname, NULL, 0, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE);
HeapFree(GetProcessHeap(), 0, unixname);
}
/* Try in datadir/fonts (or builddir/fonts), needed for Magic the Gathering Online */ /* Try in datadir/fonts (or builddir/fonts), needed for Magic the Gathering Online */
if (!ret && (unixname = get_data_dir_path( file ))) if (!ret)
{ {
ret = AddFontToList(unixname, NULL, 0, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE); get_data_dir_path( file, path );
HeapFree(GetProcessHeap(), 0, unixname); ret = add_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE );
} }
} }
...@@ -3379,35 +3362,28 @@ HANDLE WineEngAddFontMemResourceEx(PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD ...@@ -3379,35 +3362,28 @@ HANDLE WineEngAddFontMemResourceEx(PVOID pbFont, DWORD cbFont, PVOID pdv, DWORD
*/ */
BOOL WineEngRemoveFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv) BOOL WineEngRemoveFontResourceEx(LPCWSTR file, DWORD flags, PVOID pdv)
{ {
WCHAR path[MAX_PATH];
INT ret = 0; INT ret = 0;
GDI_CheckNotLock(); GDI_CheckNotLock();
if (ft_handle) /* do it only if we have freetype up and running */ if (ft_handle) /* do it only if we have freetype up and running */
{ {
char *unixname; DWORD addfont_flags = ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE;
EnterCriticalSection( &freetype_cs ); EnterCriticalSection( &freetype_cs );
if ((unixname = wine_get_unix_file_name(file))) if(!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE;
{ ret = remove_font_resource( file, addfont_flags );
DWORD addfont_flags = ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE;
if(!(flags & FR_PRIVATE)) addfont_flags |= ADDFONT_ADD_TO_CACHE;
ret = remove_font_resource( unixname, addfont_flags );
HeapFree(GetProcessHeap(), 0, unixname);
}
if (!ret && !strchrW(file, '\\')) if (!ret && !strchrW(file, '\\'))
{ {
if ((unixname = get_winfonts_dir_path( file ))) get_winfonts_dir_path( file, path );
ret = remove_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE );
if (!ret)
{ {
ret = remove_font_resource( unixname, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE ); get_data_dir_path( file, path );
HeapFree(GetProcessHeap(), 0, unixname); ret = remove_font_resource( path, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE );
}
if (!ret && (unixname = get_data_dir_path( file )))
{
ret = remove_font_resource( unixname, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_RESOURCE );
HeapFree(GetProcessHeap(), 0, unixname);
} }
} }
...@@ -4288,26 +4264,18 @@ static void init_font_list(void) ...@@ -4288,26 +4264,18 @@ static void init_font_list(void)
{ {
if(data[0] && (data[1] == ':')) if(data[0] && (data[1] == ':'))
{ {
if((unixname = wine_get_unix_file_name(data))) add_font_resource( data, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE);
{
AddFontToList(unixname, NULL, 0, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE);
HeapFree(GetProcessHeap(), 0, unixname);
}
} }
else if(dlen / 2 >= 6 && !strcmpiW(data + dlen / 2 - 5, dot_fonW)) else if(dlen / 2 >= 6 && !strcmpiW(data + dlen / 2 - 5, dot_fonW))
{ {
WCHAR pathW[MAX_PATH]; WCHAR pathW[MAX_PATH];
static const WCHAR fmtW[] = {'%','s','\\','%','s','\0'};
BOOL added = FALSE;
sprintfW(pathW, fmtW, windowsdir, data); get_winfonts_dir_path( data, pathW );
if((unixname = wine_get_unix_file_name(pathW))) if (!add_font_resource( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE ))
{ {
added = AddFontToList(unixname, NULL, 0, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE); get_data_dir_path( data, pathW );
HeapFree(GetProcessHeap(), 0, unixname); add_font_resource( pathW, ADDFONT_ALLOW_BITMAP | ADDFONT_ADD_TO_CACHE );
} }
if (!added)
load_font_from_data_dir(data);
} }
/* reset dlen and vlen */ /* reset dlen and vlen */
dlen = datalen; dlen = datalen;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment