Make it not depend on FreeType so we can also use it for face creation from registry cache.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/gdi32/freetype.c | 120 +++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 60 deletions(-)
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 960c2dc745c..6ed4e52c70e 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 *face_create( 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 )) 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; @@ -1677,21 +1719,18 @@ static inline LONG reg_save_dword(HKEY hkey, const WCHAR *value, DWORD data)
static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family, void *buffer, DWORD buffer_size) { - DWORD needed, strike_index = 0; + DWORD face_index, flags, needed, strike_index = 0; HKEY hkey_strike; + Face *face;
/* If we have a File Name key then this is a real font, not just the parent key of a bunch of non-scalable strikes */ needed = buffer_size; - if (RegQueryValueExW( hkey_face, face_unix_name_value, NULL, NULL, buffer, &needed ) == ERROR_SUCCESS) + if (RegQueryValueExW( hkey_face, face_unix_name_value, NULL, NULL, buffer, &needed ) == ERROR_SUCCESS && + reg_load_dword( hkey_face, face_index_value, &face_index ) == ERROR_SUCCESS && + reg_load_dword( hkey_face, face_flags_value, &flags ) == ERROR_SUCCESS && + (face = face_create( buffer, face_index, NULL, 0, flags ))) { - Face *face; - face = HeapAlloc(GetProcessHeap(), 0, sizeof(*face)); - face->cached_enum_data = NULL; - face->family = NULL; - - face->refcount = 1; - face->file = towstr( CP_UNIXCP, buffer ); face->style_name = strdupW( face_name );
needed = buffer_size; @@ -1704,22 +1743,16 @@ static void load_face(HKEY hkey_face, WCHAR *face_name, Family *family, void *bu } face->full_name = strdupW( buffer );
- reg_load_ftlong(hkey_face, face_index_value, &face->face_index); reg_load_dword(hkey_face, face_ntmflags_value, &face->ntmFlags); reg_load_ftlong(hkey_face, face_version_value, &face->font_version); - reg_load_dword(hkey_face, face_flags_value, &face->flags);
needed = sizeof(face->fs); RegQueryValueExW(hkey_face, face_font_sig_value, NULL, NULL, (BYTE*)&face->fs, &needed);
if(reg_load_ftshort(hkey_face, face_height_value, &face->size.height) != ERROR_SUCCESS) - { face->scalable = TRUE; - memset(&face->size, 0, sizeof(face->size)); - } else { - face->scalable = FALSE; reg_load_ftshort(hkey_face, face_width_value, &face->size.width); reg_load_ftlong(hkey_face, face_size_value, &face->size.size); reg_load_ftlong(hkey_face, face_x_ppem_value, &face->size.x_ppem); @@ -2115,57 +2148,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 *face_create_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 = face_create( 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], @@ -2181,9 +2180,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 = face_create_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) @@ -3527,7 +3527,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 = face_create_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 );