Commit ea42bb77 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

gdi32: Move the font substitution list to a standard Wine list

(based on a patch by Byeong-Sik Jeon).
parent 6280ab29
...@@ -280,6 +280,8 @@ static struct list unused_gdi_font_list = LIST_INIT(unused_gdi_font_list); ...@@ -280,6 +280,8 @@ static struct list unused_gdi_font_list = LIST_INIT(unused_gdi_font_list);
static struct list child_font_list = LIST_INIT(child_font_list); static struct list child_font_list = LIST_INIT(child_font_list);
static struct list system_links = LIST_INIT(system_links); static struct list system_links = LIST_INIT(system_links);
static struct list font_subst_list = LIST_INIT(font_subst_list);
static struct list font_list = LIST_INIT(font_list); static struct list font_list = LIST_INIT(font_list);
static const WCHAR defSerif[] = {'T','i','m','e','s',' ','N','e','w',' ', static const WCHAR defSerif[] = {'T','i','m','e','s',' ','N','e','w',' ',
...@@ -362,17 +364,16 @@ static const WCHAR *ElfScriptsW[32] = { /* these are in the order of the fsCsb[0 ...@@ -362,17 +364,16 @@ static const WCHAR *ElfScriptsW[32] = { /* these are in the order of the fsCsb[0
}; };
typedef struct { typedef struct {
WCHAR *name; WCHAR *name;
INT charset; INT charset;
} NameCs; } NameCs;
typedef struct tagFontSubst { typedef struct tagFontSubst {
NameCs from; struct list entry;
NameCs to; NameCs from;
struct tagFontSubst *next; NameCs to;
} FontSubst; } FontSubst;
static FontSubst *substlist = NULL;
static BOOL have_installed_roman_font = FALSE; /* CreateFontInstance will fail if this is still FALSE */ static BOOL have_installed_roman_font = FALSE; /* CreateFontInstance will fail if this is still FALSE */
static const WCHAR font_mutex_nameW[] = {'_','_','W','I','N','E','_','F','O','N','T','_','M','U','T','E','X','_','_','\0'}; static const WCHAR font_mutex_nameW[] = {'_','_','W','I','N','E','_','F','O','N','T','_','M','U','T','E','X','_','_','\0'};
...@@ -718,13 +719,15 @@ static void DumpSubstList(void) ...@@ -718,13 +719,15 @@ static void DumpSubstList(void)
{ {
FontSubst *psub; FontSubst *psub;
for(psub = substlist; psub; psub = psub->next) LIST_FOR_EACH_ENTRY(psub, &font_subst_list, FontSubst, entry)
{
if(psub->from.charset != -1 || psub->to.charset != -1) if(psub->from.charset != -1 || psub->to.charset != -1)
TRACE("%s:%d -> %s:%d\n", debugstr_w(psub->from.name), TRACE("%s:%d -> %s:%d\n", debugstr_w(psub->from.name),
psub->from.charset, debugstr_w(psub->to.name), psub->to.charset); psub->from.charset, debugstr_w(psub->to.name), psub->to.charset);
else else
TRACE("%s -> %s\n", debugstr_w(psub->from.name), TRACE("%s -> %s\n", debugstr_w(psub->from.name),
debugstr_w(psub->to.name)); debugstr_w(psub->to.name));
}
return; return;
} }
...@@ -746,6 +749,22 @@ static LPSTR strdupA(LPCSTR p) ...@@ -746,6 +749,22 @@ static LPSTR strdupA(LPCSTR p)
return ret; return ret;
} }
static FontSubst *get_font_subst(const struct list *subst_list, const WCHAR *from_name,
INT from_charset)
{
FontSubst *element;
LIST_FOR_EACH_ENTRY(element, subst_list, FontSubst, entry)
{
if(!strcmpiW(element->from.name, from_name) &&
(element->from.charset == from_charset ||
element->from.charset == -1))
return element;
}
return NULL;
}
static void split_subst_info(NameCs *nc, LPSTR str) static void split_subst_info(NameCs *nc, LPSTR str)
{ {
CHAR *p = strrchr(str, ','); CHAR *p = strrchr(str, ',');
...@@ -763,22 +782,22 @@ static void split_subst_info(NameCs *nc, LPSTR str) ...@@ -763,22 +782,22 @@ static void split_subst_info(NameCs *nc, LPSTR str)
static void LoadSubstList(void) static void LoadSubstList(void)
{ {
FontSubst *psub, **ppsub; FontSubst *psub;
HKEY hkey; HKEY hkey;
DWORD valuelen, datalen, i = 0, type, dlen, vlen; DWORD valuelen, datalen, i = 0, type, dlen, vlen;
LPSTR value; LPSTR value;
LPVOID data; LPVOID data;
if(substlist) { if(!list_empty(&font_subst_list))
for(psub = substlist; psub;) { {
FontSubst *ptmp; FontSubst *cursor2;
HeapFree(GetProcessHeap(), 0, psub->to.name); LIST_FOR_EACH_ENTRY_SAFE(psub, cursor2, &font_subst_list, FontSubst, entry)
HeapFree(GetProcessHeap(), 0, psub->from.name); {
ptmp = psub; HeapFree(GetProcessHeap(), 0, psub->to.name);
psub = psub->next; HeapFree(GetProcessHeap(), 0, psub->from.name);
HeapFree(GetProcessHeap(), 0, ptmp); list_remove(&psub->entry);
} HeapFree(GetProcessHeap(), 0, psub);
substlist = NULL; }
} }
if(RegOpenKeyA(HKEY_LOCAL_MACHINE, if(RegOpenKeyA(HKEY_LOCAL_MACHINE,
...@@ -794,26 +813,23 @@ static void LoadSubstList(void) ...@@ -794,26 +813,23 @@ static void LoadSubstList(void)
dlen = datalen; dlen = datalen;
vlen = valuelen; vlen = valuelen;
ppsub = &substlist;
while(RegEnumValueA(hkey, i++, value, &vlen, NULL, &type, data, while(RegEnumValueA(hkey, i++, value, &vlen, NULL, &type, data,
&dlen) == ERROR_SUCCESS) { &dlen) == ERROR_SUCCESS) {
TRACE("Got %s=%s\n", debugstr_a(value), debugstr_a(data)); TRACE("Got %s=%s\n", debugstr_a(value), debugstr_a(data));
*ppsub = HeapAlloc(GetProcessHeap(), 0, sizeof(**ppsub)); psub = HeapAlloc(GetProcessHeap(), 0, sizeof(*psub));
(*ppsub)->next = NULL; split_subst_info(&psub->from, value);
split_subst_info(&((*ppsub)->from), value); split_subst_info(&psub->to, data);
split_subst_info(&((*ppsub)->to), data);
/* Win 2000 doesn't allow mapping between different charsets /* Win 2000 doesn't allow mapping between different charsets
or mapping of DEFAULT_CHARSET */ or mapping of DEFAULT_CHARSET */
if(((*ppsub)->to.charset != (*ppsub)->from.charset) || if((psub->to.charset != psub->from.charset) ||
(*ppsub)->to.charset == DEFAULT_CHARSET) { psub->to.charset == DEFAULT_CHARSET) {
HeapFree(GetProcessHeap(), 0, (*ppsub)->to.name); HeapFree(GetProcessHeap(), 0, psub->to.name);
HeapFree(GetProcessHeap(), 0, (*ppsub)->from.name); HeapFree(GetProcessHeap(), 0, psub->from.name);
HeapFree(GetProcessHeap(), 0, *ppsub); HeapFree(GetProcessHeap(), 0, psub);
*ppsub = NULL;
} else { } else {
ppsub = &((*ppsub)->next); list_add_head(&font_subst_list, &psub->entry);
} }
/* reset dlen and vlen */ /* reset dlen and vlen */
dlen = datalen; dlen = datalen;
...@@ -2205,11 +2221,8 @@ GdiFont WineEngCreateFontInstance(DC *dc, HFONT hfont) ...@@ -2205,11 +2221,8 @@ GdiFont WineEngCreateFontInstance(DC *dc, HFONT hfont)
family = NULL; family = NULL;
if(lf.lfFaceName[0] != '\0') { if(lf.lfFaceName[0] != '\0') {
FontSubst *psub; FontSubst *psub;
for(psub = substlist; psub; psub = psub->next) psub = get_font_subst(&font_subst_list, lf.lfFaceName, lf.lfCharSet);
if(!strcmpiW(lf.lfFaceName, psub->from.name) &&
(psub->from.charset == -1 ||
psub->from.charset == lf.lfCharSet))
break;
if(psub) { if(psub) {
TRACE("substituting %s -> %s\n", debugstr_w(lf.lfFaceName), TRACE("substituting %s -> %s\n", debugstr_w(lf.lfFaceName),
debugstr_w(psub->to.name)); debugstr_w(psub->to.name));
...@@ -2628,11 +2641,8 @@ DWORD WineEngEnumFonts(LPLOGFONTW plf, FONTENUMPROCW proc, LPARAM lparam) ...@@ -2628,11 +2641,8 @@ DWORD WineEngEnumFonts(LPLOGFONTW plf, FONTENUMPROCW proc, LPARAM lparam)
if(plf->lfFaceName[0]) { if(plf->lfFaceName[0]) {
FontSubst *psub; FontSubst *psub;
for(psub = substlist; psub; psub = psub->next) psub = get_font_subst(&font_subst_list, plf->lfFaceName, plf->lfCharSet);
if(!strcmpiW(plf->lfFaceName, psub->from.name) &&
(psub->from.charset == -1 ||
psub->from.charset == plf->lfCharSet))
break;
if(psub) { if(psub) {
TRACE("substituting %s -> %s\n", debugstr_w(plf->lfFaceName), TRACE("substituting %s -> %s\n", debugstr_w(plf->lfFaceName),
debugstr_w(psub->to.name)); debugstr_w(psub->to.name));
......
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