Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
The whole series for this patchset lives here:
https://gitlab.com/rbernon/wine/-/commits/wip/freetype/v1/
I've renamed debugstr_face to debugstr_faceid, and dropped the FreeType cache manager use (in later patches), for now.
This patchset is mostly some cleanup to reorganise things a bit in preparation for the handmade opentype parsing replacing most FreeType calls in initial font list parsing.
dlls/gdi32/freetype.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 86585882342..ff5717394c0 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -288,6 +288,12 @@ typedef struct tagFace { struct enum_data *cached_enum_data; } Face;
+static inline const char *debugstr_faceid( Face *face ) +{ + if (face->file) return wine_dbg_sprintf( "%s (%ld)", debugstr_w(face->file), face->face_index ); + else return wine_dbg_sprintf( "%p-%p (%ld)", face->font_data_ptr, (char *)face->font_data_ptr + face->font_data_size, face->face_index ); +} + #define FS_DBCS_MASK (FS_JISJAPAN|FS_CHINESESIMP|FS_WANSUNG|FS_CHINESETRAD|FS_JOHAB)
#define ADDFONT_EXTERNAL_FONT 0x01 @@ -1585,20 +1591,17 @@ static BOOL insert_face_in_family_list( Face *face, Family *family ) if (face->file && face->dev == cursor->dev && face->ino == cursor->ino) { cursor->refcount++; - TRACE("Font %s already in list, refcount now %d\n", - debugstr_w(face->file), cursor->refcount); + TRACE( "face %s already in list, refcount now %d\n", debugstr_faceid(face), cursor->refcount ); return FALSE; } if (face->font_version <= cursor->font_version) { - TRACE("Original font %s is newer so skipping %s\n", - debugstr_w(cursor->file), debugstr_w(face->file)); + TRACE( "Original %s is newer so skipping %s\n", debugstr_faceid(cursor), debugstr_faceid(face) ); return FALSE; } else { - TRACE("Replacing original %s with %s\n", - debugstr_w(cursor->file), debugstr_w(face->file)); + TRACE( "Replacing original %s with %s\n", debugstr_faceid(cursor), debugstr_faceid(face) ); list_add_before( &cursor->entry, &face->entry ); face->family = family; family->refcount++; @@ -1612,7 +1615,7 @@ static BOOL insert_face_in_family_list( Face *face, Family *family ) }
TRACE( "Adding face %s in family %s from %s\n", debugstr_w(face->full_name), - debugstr_w(family->family_name), debugstr_w(face->file) ); + debugstr_w(family->family_name), debugstr_faceid(face) ); list_add_before( &cursor->entry, &face->entry ); face->family = family; family->refcount++; @@ -2356,7 +2359,7 @@ static int remove_font_resource( const WCHAR *file, DWORD flags ) if (LOWORD(face->flags) != LOWORD(flags)) continue; if (st.st_dev == face->dev && st.st_ino == face->ino) { - TRACE( "removing matching face %s refcount %d\n", debugstr_w(face->file), face->refcount ); + TRACE( "removing matching face %s refcount %d\n", debugstr_faceid(face), face->refcount ); release_face( face ); count++; } @@ -2623,8 +2626,7 @@ static void populate_system_links(const WCHAR *name, const WCHAR *const *values) child_font->font = NULL; font_link->fs.fsCsb[0] |= face->fs.fsCsb[0]; font_link->fs.fsCsb[1] |= face->fs.fsCsb[1]; - TRACE("Adding file %s index %ld\n", debugstr_w(child_font->face->file), - child_font->face->face_index); + TRACE( "Adding %s\n", debugstr_faceid(child_font->face) ); list_add_tail(&font_link->links, &child_font->entry);
TRACE("added internal SystemLink for %s to %s in %s\n", debugstr_w(name), debugstr_w(value),debugstr_w(file)); @@ -2704,8 +2706,7 @@ static void init_system_links(void) child_font->font = NULL; font_link->fs.fsCsb[0] |= face->fs.fsCsb[0]; font_link->fs.fsCsb[1] |= face->fs.fsCsb[1]; - TRACE("Adding file %s index %ld\n", - debugstr_w(child_font->face->file), child_font->face->face_index); + TRACE( "Adding %s\n", debugstr_faceid(child_font->face) ); list_add_tail(&font_link->links, &child_font->entry); } list_add_tail(&system_links, &font_link->entry); @@ -2763,8 +2764,7 @@ skip_internal: child_font->font = NULL; system_font_link->fs.fsCsb[0] |= face->fs.fsCsb[0]; system_font_link->fs.fsCsb[1] |= face->fs.fsCsb[1]; - TRACE("Found Tahoma in %s index %ld\n", - debugstr_w(child_font->face->file), child_font->face->face_index); + TRACE( "Found Tahoma in %s\n", debugstr_faceid(child_font->face) ); list_add_tail(&system_font_link->links, &child_font->entry); } font_link = find_font_link(Tahoma); @@ -4599,7 +4599,7 @@ static FT_Face OpenFontFace(GdiFont *font, Face *face, LONG width, LONG height) void *data_ptr; DWORD data_size;
- TRACE("%s/%p, %ld, %d x %d\n", debugstr_w(face->file), face->font_data_ptr, face->face_index, width, height); + TRACE( "%s, %d x %d\n", debugstr_faceid(face), width, height );
if (face->file) { @@ -4608,7 +4608,7 @@ static FT_Face OpenFontFace(GdiFont *font, Face *face, LONG width, LONG height) HeapFree( GetProcessHeap(), 0, filename ); if (!font->mapping) { - WARN("failed to map %s\n", debugstr_w(face->file)); + WARN( "failed to map %s\n", debugstr_faceid(face) ); return 0; } data_ptr = font->mapping->data; @@ -4700,8 +4700,7 @@ static int get_nearest_charset(const WCHAR *family_name, Face *face, int *cp) } }
- FIXME("returning DEFAULT_CHARSET face->fs.fsCsb[0] = %08x file = %s\n", - face->fs.fsCsb[0], debugstr_w(face->file)); + FIXME( "returning DEFAULT_CHARSET face->fs.fsCsb[0] = %08x %s\n", face->fs.fsCsb[0], debugstr_faceid(face) ); *cp = acp; return DEFAULT_CHARSET; } @@ -5134,7 +5133,7 @@ static BOOL create_child_font_list(GdiFont *font) new_child->font = NULL; new_child->face->refcount++; list_add_tail(&font->child_fonts, &new_child->entry); - TRACE("font %s %ld\n", debugstr_w(new_child->face->file), new_child->face->face_index); + TRACE( "face %s\n", debugstr_faceid(new_child->face) ); } ret = TRUE; } @@ -5157,7 +5156,7 @@ static BOOL create_child_font_list(GdiFont *font) new_child->font = NULL; new_child->face->refcount++; list_add_tail(&font->child_fonts, &new_child->entry); - TRACE("font %s %ld\n", debugstr_w(new_child->face->file), new_child->face->face_index); + TRACE( "face %s\n", debugstr_faceid(new_child->face) ); } ret = TRUE; } @@ -5894,8 +5893,7 @@ found_face: else ret->charset = get_nearest_charset( family->family_name, face, &ret->codepage );
- TRACE( "Chosen: %s (%s/%p:%ld)\n", debugstr_w(face->full_name), debugstr_w(face->file), - face->font_data_ptr, face->face_index ); + TRACE( "Chosen: %s from %s\n", debugstr_w(face->full_name), debugstr_faceid(face) );
ret->aveWidth = height ? lf.lfWidth : 0;
Make it not depend on FreeType so we can call it before creating FT_Face.
We also open and fstat the file first, checking for its existence, in preparation for mmap to parse the font info later.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/gdi32/freetype.c | 99 +++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 45 deletions(-)
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index ff5717394c0..e61f8a180c5 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -1542,6 +1542,48 @@ static void release_family( Family *family ) HeapFree( GetProcessHeap(), 0, family ); }
+static Face *create_face( const char *unix_name, DWORD face_index, void *font_data_ptr, + DWORD font_data_size, DWORD flags ) +{ + struct stat st; + Face *face; + int fd; + + TRACE( "unix_name %s, face_index %u, font_data_ptr %p, font_data_size %u, flags %#x\n", + unix_name, face_index, font_data_ptr, font_data_size, flags ); + + if (unix_name) + { + if ((fd = open( unix_name, O_RDONLY )) == -1) return NULL; + if (fstat( fd, &st ) == -1) return NULL; + close( fd ); + } + + if (!(face = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*face) ))) return NULL; + face->refcount = 1; + + list_init( &face->entry ); + + if (unix_name) + { + face->file = towstr( CP_UNIXCP, unix_name ); + face->dev = st.st_dev; + face->ino = st.st_ino; + } + else + { + face->font_data_ptr = font_data_ptr; + face->font_data_size = font_data_size; + } + + face->face_index = face_index; + + if (!HIWORD( flags )) flags |= ADDFONT_AA_FLAGS( default_aa_flags ); + face->flags = flags; + + return face; +} + static void release_face( Face *face ) { if (--face->refcount) return; @@ -2112,57 +2154,23 @@ static inline void get_fontsig( FT_Face ft_face, FONTSIGNATURE *fs ) } }
-static Face *create_face( FT_Face ft_face, FT_Long face_index, const char *file, void *font_data_ptr, DWORD font_data_size, - DWORD flags ) +static Face *create_face_from_ft_face( FT_Face ft_face, FT_Long face_index, const char *file, + void *font_data_ptr, DWORD font_data_size, DWORD flags ) { - struct stat st; - Face *face = HeapAlloc( GetProcessHeap(), 0, sizeof(*face) ); + Face *face; + + if (!(face = create_face( file, face_index, font_data_ptr, font_data_size, flags ))) + return NULL;
- face->refcount = 1; face->style_name = ft_face_get_style_name( ft_face, GetSystemDefaultLangID() ); face->full_name = ft_face_get_full_name( ft_face, GetSystemDefaultLangID() ); - if (flags & ADDFONT_VERTICAL_FONT) face->full_name = get_vertical_name( face->full_name ); + if (face->flags & ADDFONT_VERTICAL_FONT) face->full_name = get_vertical_name( face->full_name );
- face->dev = 0; - face->ino = 0; - if (file) - { - face->file = towstr( CP_UNIXCP, file ); - face->font_data_ptr = NULL; - face->font_data_size = 0; - if (!stat( file, &st )) - { - face->dev = st.st_dev; - face->ino = st.st_ino; - } - } - else - { - face->file = NULL; - face->font_data_ptr = font_data_ptr; - face->font_data_size = font_data_size; - } - - face->face_index = face_index; get_fontsig( ft_face, &face->fs ); face->ntmFlags = get_ntm_flags( ft_face ); face->font_version = get_font_version( ft_face );
- if (FT_IS_SCALABLE( ft_face )) - { - memset( &face->size, 0, sizeof(face->size) ); - face->scalable = TRUE; - } - else - { - get_bitmap_size( ft_face, &face->size ); - face->scalable = FALSE; - } - - if (!HIWORD( flags )) flags |= ADDFONT_AA_FLAGS( default_aa_flags ); - face->flags = flags; - face->family = NULL; - face->cached_enum_data = NULL; + if (!(face->scalable = FT_IS_SCALABLE( ft_face ))) get_bitmap_size( ft_face, &face->size );
TRACE("fsCsb = %08x %08x/%08x %08x %08x %08x\n", face->fs.fsCsb[0], face->fs.fsCsb[1], @@ -2178,9 +2186,10 @@ static void AddFaceToList(FT_Face ft_face, const char *file, void *font_data_ptr Face *face; Family *family;
- face = create_face( ft_face, face_index, file, font_data_ptr, font_data_size, flags ); - family = get_family( ft_face, flags & ADDFONT_VERTICAL_FONT ); + if (!(face = create_face_from_ft_face( ft_face, face_index, file, font_data_ptr, font_data_size, flags ))) + return;
+ family = get_family( ft_face, flags & ADDFONT_VERTICAL_FONT ); if (insert_face_in_family_list( face, family )) { if (flags & ADDFONT_ADD_TO_CACHE) @@ -3524,7 +3533,7 @@ static BOOL get_fontdir( const char *unix_name, struct fontdir *fd ) DWORD type;
if (!ft_face) return FALSE; - face = create_face( ft_face, 0, unix_name, NULL, 0, 0 ); + face = create_face_from_ft_face( ft_face, 0, unix_name, NULL, 0, 0 ); family_name = ft_face_get_family_name( ft_face, GetSystemDefaultLCID() ); pFT_Done_Face( ft_face );
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/gdi32/freetype.c | 83 ++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 40 deletions(-)
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index e61f8a180c5..51c67514856 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -2154,14 +2154,8 @@ static inline void get_fontsig( FT_Face ft_face, FONTSIGNATURE *fs ) } }
-static Face *create_face_from_ft_face( FT_Face ft_face, FT_Long face_index, const char *file, - void *font_data_ptr, DWORD font_data_size, DWORD flags ) +static void face_init_from_ft_face( Face *face, FT_Face ft_face ) { - Face *face; - - if (!(face = create_face( file, face_index, font_data_ptr, font_data_size, flags ))) - return NULL; - face->style_name = ft_face_get_style_name( ft_face, GetSystemDefaultLangID() ); face->full_name = ft_face_get_full_name( ft_face, GetSystemDefaultLangID() ); if (face->flags & ADDFONT_VERTICAL_FONT) face->full_name = get_vertical_name( face->full_name ); @@ -2176,28 +2170,21 @@ static Face *create_face_from_ft_face( FT_Face ft_face, FT_Long face_index, cons face->fs.fsCsb[0], face->fs.fsCsb[1], face->fs.fsUsb[0], face->fs.fsUsb[1], face->fs.fsUsb[2], face->fs.fsUsb[3]); - - return face; }
-static void AddFaceToList(FT_Face ft_face, const char *file, void *font_data_ptr, DWORD font_data_size, - FT_Long face_index, DWORD flags ) +static BOOL face_insert_in_family( Face *face, FT_Face ft_face ) { - Face *face; Family *family; + if (!(family = get_family( ft_face, face->flags & ADDFONT_VERTICAL_FONT ))) return FALSE;
- if (!(face = create_face_from_ft_face( ft_face, face_index, file, font_data_ptr, font_data_size, flags ))) - return; - - family = get_family( ft_face, flags & ADDFONT_VERTICAL_FONT ); if (insert_face_in_family_list( face, family )) { - if (flags & ADDFONT_ADD_TO_CACHE) - add_face_to_cache( face ); + if (face->flags & ADDFONT_ADD_TO_CACHE) add_face_to_cache( face ); TRACE( "Added face %s to family %s\n", debugstr_w(face->full_name), debugstr_w(family->family_name) ); } - release_face( face ); + release_family( family ); + return TRUE; }
static FT_Face new_ft_face( const char *file, void *font_data_ptr, DWORD font_data_size, @@ -2278,7 +2265,8 @@ fail:
static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_size, DWORD flags) { - FT_Face ft_face; + Face *face = NULL; + FT_Face ft_face = NULL; FT_Long face_index = 0, num_faces; INT ret = 0;
@@ -2306,34 +2294,44 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_ } #endif /* HAVE_CARBON_CARBON_H */
- do { - FONTSIGNATURE fs; - - ft_face = new_ft_face( file, font_data_ptr, font_data_size, face_index, flags & ADDFONT_ALLOW_BITMAP ); - if (!ft_face) return 0; + do + { + if (!(face = create_face( file, face_index, font_data_ptr, font_data_size, flags ))) + goto failed; + if (!(ft_face = new_ft_face( file, font_data_ptr, font_data_size, face_index, flags & ADDFONT_ALLOW_BITMAP ))) + goto failed;
- if(ft_face->family_name[0] == '.') /* Ignore fonts with names beginning with a dot */ + if (ft_face->family_name[0] == '.') /* Ignore fonts with names beginning with a dot */ { - TRACE("Ignoring %s since its family name begins with a dot\n", debugstr_a(file)); - pFT_Done_Face(ft_face); - return 0; + TRACE( "Ignoring %s since its family name begins with a dot\n", debugstr_a(file) ); + goto failed; }
- AddFaceToList(ft_face, file, font_data_ptr, font_data_size, face_index, flags); + face_init_from_ft_face( face, ft_face ); + if (!face_insert_in_family( face, ft_face )) goto failed; ++ret;
- get_fontsig(ft_face, &fs); - if (fs.fsCsb[0] & FS_DBCS_MASK) + if (face->fs.fsCsb[0] & FS_DBCS_MASK) { - AddFaceToList(ft_face, file, font_data_ptr, font_data_size, face_index, - flags | ADDFONT_VERTICAL_FONT); + release_face( face ); + if (!(face = create_face( file, face_index, font_data_ptr, font_data_size, flags | ADDFONT_VERTICAL_FONT ))) + goto failed; + face_init_from_ft_face( face, ft_face ); + if (!face_insert_in_family( face, ft_face )) goto failed; ++ret; }
- num_faces = ft_face->num_faces; - pFT_Done_Face(ft_face); - } while(num_faces > ++face_index); + num_faces = ft_face->num_faces; + pFT_Done_Face( ft_face ); + release_face( face ); + } while (num_faces > ++face_index); + return ret; + +failed: + if (ft_face) pFT_Done_Face( ft_face ); + if (face) release_face( face ); + return 0; }
static int add_font_resource( const WCHAR *file, DWORD flags ) @@ -3525,15 +3523,20 @@ static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEX
static BOOL get_fontdir( const char *unix_name, struct fontdir *fd ) { - FT_Face ft_face = new_ft_face( unix_name, NULL, 0, 0, FALSE ); + FT_Face ft_face; Face *face; WCHAR *family_name; ENUMLOGFONTEXW elf; NEWTEXTMETRICEXW ntm; DWORD type;
- if (!ft_face) return FALSE; - face = create_face_from_ft_face( ft_face, 0, unix_name, NULL, 0, 0 ); + if (!(face = create_face( unix_name, 0, NULL, 0, 0 ))) return FALSE; + if (!(ft_face = new_ft_face( unix_name, NULL, 0, 0, FALSE ))) + { + release_face( face ); + return FALSE; + } + face_init_from_ft_face( face, ft_face ); family_name = ft_face_get_family_name( ft_face, GetSystemDefaultLCID() ); pFT_Done_Face( ft_face );
We will use these names to find or create the corresponding family.
Keeping these names on the face will allow us to fill them when parsing the face by hand, or in the FreeType parsing fallback, making family creation independent of FreeType usage.
This also saves the GetEnumStructs family name parameter, making it independent of FreeType parsing too.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/gdi32/freetype.c | 113 ++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 58 deletions(-)
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 51c67514856..0071db3d4fc 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -269,6 +269,8 @@ struct enum_data typedef struct tagFace { struct list entry; unsigned int refcount; + WCHAR *family_name; + WCHAR *second_name; WCHAR *style_name; WCHAR *full_name; WCHAR *file; @@ -1594,6 +1596,8 @@ static void release_face( Face *face ) release_family( face->family ); } HeapFree( GetProcessHeap(), 0, face->file ); + HeapFree( GetProcessHeap(), 0, face->family_name ); + HeapFree( GetProcessHeap(), 0, face->second_name ); HeapFree( GetProcessHeap(), 0, face->style_name ); HeapFree( GetProcessHeap(), 0, face->full_name ); HeapFree( GetProcessHeap(), 0, face->cached_enum_data ); @@ -1717,7 +1721,8 @@ static inline LONG reg_save_dword(HKEY hkey, const WCHAR *value, DWORD data) return RegSetValueExW(hkey, value, 0, REG_DWORD, (BYTE*)&data, sizeof(DWORD)); }
-static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family, void *buffer, DWORD buffer_size) +static void load_face( HKEY hkey_face, WCHAR *face_name, WCHAR *family_name, WCHAR *second_name, + Family *family, void *buffer, DWORD buffer_size ) { DWORD needed, strike_index = 0; HKEY hkey_strike; @@ -1735,6 +1740,8 @@ static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family, void *bu face->refcount = 1; face->file = strdupW( buffer ); face->style_name = strdupW( face_name ); + face->family_name = strdupW( family_name ); + if (second_name) face->second_name = strdupW( second_name );
needed = buffer_size; if (RegQueryValueExW( hkey_face, face_full_name_value, NULL, NULL, buffer, &needed ) != ERROR_SUCCESS) @@ -1791,7 +1798,7 @@ static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family, void *bu { if (!RegOpenKeyExW(hkey_face, buffer, 0, KEY_ALL_ACCESS, &hkey_strike)) { - load_face(hkey_strike, face_name, family, buffer, buffer_size); + load_face( hkey_strike, face_name, family_name, second_name, family, buffer, buffer_size ); RegCloseKey(hkey_strike); } needed = buffer_size; @@ -1870,7 +1877,7 @@ static void load_font_list_from_cache(HKEY hkey_font_cache)
if (!RegOpenKeyExW(hkey_family, face_name, 0, KEY_ALL_ACCESS, &hkey_face)) { - load_face(hkey_face, face_name, family, buffer, sizeof(buffer)); + load_face( hkey_face, face_name, family_name, second_name, family, buffer, sizeof(buffer) ); RegCloseKey(hkey_face); } HeapFree( GetProcessHeap(), 0, face_name ); @@ -1913,11 +1920,11 @@ static void add_face_to_cache(Face *face) HKEY hkey_family, hkey_face; WCHAR *face_key_name;
- RegCreateKeyExW( hkey_font_cache, face->family->family_name, 0, NULL, REG_OPTION_VOLATILE, + RegCreateKeyExW( hkey_font_cache, face->family_name, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey_family, NULL ); - if (face->family->second_name[0]) - RegSetValueExW( hkey_family, second_name_value, 0, REG_SZ, (BYTE *)face->family->second_name, - (strlenW( face->family->second_name ) + 1) * sizeof(WCHAR) ); + if (face->second_name) + RegSetValueExW( hkey_family, second_name_value, 0, REG_SZ, (BYTE *)face->second_name, + (strlenW( face->second_name ) + 1) * sizeof(WCHAR) );
if (face->scalable) face_key_name = face->style_name; else @@ -1960,7 +1967,7 @@ static void remove_face_from_cache( Face *face ) { HKEY hkey_family;
- RegOpenKeyExW( hkey_font_cache, face->family->family_name, 0, KEY_ALL_ACCESS, &hkey_family ); + RegOpenKeyExW( hkey_font_cache, face->family_name, 0, KEY_ALL_ACCESS, &hkey_family );
if (face->scalable) { @@ -1990,47 +1997,21 @@ static WCHAR *get_vertical_name( WCHAR *name ) return name; }
-static Family *get_family( FT_Face ft_face, BOOL vertical ) +static Family *face_get_family( Face *face ) { Family *family; - WCHAR *family_name, *second_name; - - family_name = ft_face_get_family_name( ft_face, GetSystemDefaultLCID() ); - second_name = ft_face_get_family_name( ft_face, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT) ); - - /* try to find another secondary name, preferring the lowest langids */ - if (!strcmpiW( family_name, second_name )) - { - HeapFree( GetProcessHeap(), 0, second_name ); - second_name = ft_face_get_family_name( ft_face, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ); - } - - if (!strcmpiW( family_name, second_name )) - { - HeapFree( GetProcessHeap(), 0, second_name ); - second_name = NULL; - } - - if (vertical) - { - family_name = get_vertical_name( family_name ); - second_name = get_vertical_name( second_name ); - }
- if ((family = find_family_from_name( family_name ))) family->refcount++; - else if ((family = create_family( family_name, second_name )) && second_name) + if ((family = find_family_from_name( face->family_name ))) family->refcount++; + else if ((family = create_family( face->family_name, face->second_name )) && face->second_name) { FontSubst *subst = HeapAlloc( GetProcessHeap(), 0, sizeof(*subst) ); - subst->from.name = strdupW( second_name ); + subst->from.name = strdupW( face->second_name ); subst->from.charset = -1; - subst->to.name = strdupW( family_name ); + subst->to.name = strdupW( face->family_name ); subst->to.charset = -1; add_font_subst( &font_subst_list, subst, 0 ); }
- HeapFree( GetProcessHeap(), 0, family_name ); - HeapFree( GetProcessHeap(), 0, second_name ); - return family; }
@@ -2156,9 +2137,31 @@ static inline void get_fontsig( FT_Face ft_face, FONTSIGNATURE *fs )
static void face_init_from_ft_face( Face *face, FT_Face ft_face ) { + face->family_name = ft_face_get_family_name( ft_face, GetSystemDefaultLCID() ); + face->second_name = ft_face_get_family_name( ft_face, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT) ); + + /* try to find another secondary name, preferring the lowest langids */ + if (!strcmpiW( face->family_name, face->second_name )) + { + HeapFree( GetProcessHeap(), 0, face->second_name ); + face->second_name = ft_face_get_family_name( ft_face, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ); + } + + if (!strcmpiW( face->family_name, face->second_name )) + { + HeapFree( GetProcessHeap(), 0, face->second_name ); + face->second_name = NULL; + } + face->style_name = ft_face_get_style_name( ft_face, GetSystemDefaultLangID() ); face->full_name = ft_face_get_full_name( ft_face, GetSystemDefaultLangID() ); - if (face->flags & ADDFONT_VERTICAL_FONT) face->full_name = get_vertical_name( face->full_name ); + + if (face->flags & ADDFONT_VERTICAL_FONT) + { + face->family_name = get_vertical_name( face->family_name ); + face->second_name = get_vertical_name( face->second_name ); + face->full_name = get_vertical_name( face->full_name ); + }
get_fontsig( ft_face, &face->fs ); face->ntmFlags = get_ntm_flags( ft_face ); @@ -2172,10 +2175,10 @@ static void face_init_from_ft_face( Face *face, FT_Face ft_face ) face->fs.fsUsb[2], face->fs.fsUsb[3]); }
-static BOOL face_insert_in_family( Face *face, FT_Face ft_face ) +static BOOL face_insert_in_family( Face *face ) { Family *family; - if (!(family = get_family( ft_face, face->flags & ADDFONT_VERTICAL_FONT ))) return FALSE; + if (!(family = face_get_family( face ))) return FALSE;
if (insert_face_in_family_list( face, family )) { @@ -2301,14 +2304,13 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_ if (!(ft_face = new_ft_face( file, font_data_ptr, font_data_size, face_index, flags & ADDFONT_ALLOW_BITMAP ))) goto failed;
- if (ft_face->family_name[0] == '.') /* Ignore fonts with names beginning with a dot */ + face_init_from_ft_face( face, ft_face ); + if (face->family_name[0] == '.') /* Ignore fonts with names beginning with a dot */ { TRACE( "Ignoring %s since its family name begins with a dot\n", debugstr_a(file) ); goto failed; } - - face_init_from_ft_face( face, ft_face ); - if (!face_insert_in_family( face, ft_face )) goto failed; + if (!face_insert_in_family( face )) goto failed; ++ret;
if (face->fs.fsCsb[0] & FS_DBCS_MASK) @@ -2317,7 +2319,7 @@ static INT AddFontToList(const char *file, void *font_data_ptr, DWORD font_data_ if (!(face = create_face( file, face_index, font_data_ptr, font_data_size, flags | ADDFONT_VERTICAL_FONT ))) goto failed; face_init_from_ft_face( face, ft_face ); - if (!face_insert_in_family( face, ft_face )) goto failed; + if (!face_insert_in_family( face )) goto failed; ++ret; }
@@ -3518,14 +3520,12 @@ struct fontdir
#include <poppack.h>
-static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEXW pelf, - NEWTEXTMETRICEXW *pntm, LPDWORD ptype); +static void GetEnumStructs( Face *face, LPENUMLOGFONTEXW pelf, NEWTEXTMETRICEXW *pntm, LPDWORD ptype );
static BOOL get_fontdir( const char *unix_name, struct fontdir *fd ) { FT_Face ft_face; Face *face; - WCHAR *family_name; ENUMLOGFONTEXW elf; NEWTEXTMETRICEXW ntm; DWORD type; @@ -3537,12 +3537,10 @@ static BOOL get_fontdir( const char *unix_name, struct fontdir *fd ) return FALSE; } face_init_from_ft_face( face, ft_face ); - family_name = ft_face_get_family_name( ft_face, GetSystemDefaultLCID() ); pFT_Done_Face( ft_face );
- GetEnumStructs( face, family_name, &elf, &ntm, &type ); + GetEnumStructs( face, &elf, &ntm, &type ); release_face( face ); - HeapFree( GetProcessHeap(), 0, family_name );
if ((type & TRUETYPE_FONTTYPE) == 0) return FALSE;
@@ -6139,8 +6137,7 @@ static DWORD create_enum_charset_list(DWORD charset, struct enum_charset_list *l return n; }
-static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEXW pelf, - NEWTEXTMETRICEXW *pntm, LPDWORD ptype) +static void GetEnumStructs( Face *face, LPENUMLOGFONTEXW pelf, NEWTEXTMETRICEXW *pntm, LPDWORD ptype ) { GdiFont *font; LONG width, height; @@ -6171,7 +6168,7 @@ static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEX return; }
- font->name = strdupW( family_name ); + font->name = strdupW( face->family_name ); font->ntmFlags = face->ntmFlags;
if (get_outline_text_metrics(font)) @@ -6200,7 +6197,7 @@ static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEX pntm->ntmTm.ntmCellHeight = pntm->ntmTm.tmHeight; pntm->ntmTm.ntmAvgWidth = pntm->ntmTm.tmAveCharWidth;
- lstrcpynW(pelf->elfLogFont.lfFaceName, family_name, LF_FACESIZE); + lstrcpynW( pelf->elfLogFont.lfFaceName, face->family_name, LF_FACESIZE ); lstrcpynW( pelf->elfFullName, face->full_name, LF_FULLFACESIZE ); lstrcpynW( pelf->elfStyle, face->style_name, LF_FACESIZE ); } @@ -6271,7 +6268,7 @@ static BOOL enum_face_charsets(const Family *family, Face *face, struct enum_cha DWORD type = 0; DWORD i;
- GetEnumStructs( face, face->family->family_name, &elf, &ntm, &type ); + GetEnumStructs( face, &elf, &ntm, &type ); for(i = 0; i < list->total; i++) { if(!face->scalable && face->fs.fsCsb[0] == 0) { /* OEM bitmap */ elf.elfLogFont.lfCharSet = ntm.ntmTm.tmCharSet = OEM_CHARSET;
The first two patches supersede 192847-192848 (and related 191673 was committed already).