Commit c9b21a57 authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Add a helper function to create a font from a face.

parent ef77b388
...@@ -1016,7 +1016,7 @@ static void free_font_handle( DWORD handle ) ...@@ -1016,7 +1016,7 @@ static void free_font_handle( DWORD handle )
} }
} }
struct gdi_font *alloc_gdi_font( const WCHAR *file, void *data_ptr, SIZE_T data_size ) static struct gdi_font *alloc_gdi_font( const WCHAR *file, void *data_ptr, SIZE_T data_size )
{ {
UINT len = file ? strlenW(file) : 0; UINT len = file ? strlenW(file) : 0;
struct gdi_font *font = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, struct gdi_font *font = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
...@@ -1083,6 +1083,25 @@ void set_gdi_font_names( struct gdi_font *font, const WCHAR *family_name, const ...@@ -1083,6 +1083,25 @@ void set_gdi_font_names( struct gdi_font *font, const WCHAR *family_name, const
font->otm.otmpFaceName = (char *)strdupW( full_name ); font->otm.otmpFaceName = (char *)strdupW( full_name );
} }
struct gdi_font *create_gdi_font( const struct gdi_font_face *face, const WCHAR *family_name,
const LOGFONTW *lf )
{
struct gdi_font *font;
if (!(font = alloc_gdi_font( face->file, face->data_ptr, face->data_size ))) return NULL;
font->fs = face->fs;
font->lf = *lf;
font->fake_italic = (lf->lfItalic && !(face->ntmFlags & NTM_ITALIC));
font->fake_bold = (lf->lfWeight > 550 && !(face->ntmFlags & NTM_BOLD));
font->scalable = face->scalable;
font->face_index = face->face_index;
font->ntmFlags = face->ntmFlags;
font->aa_flags = HIWORD( face->flags );
if (!family_name) family_name = face->family->family_name;
set_gdi_font_names( font, family_name, face->style_name, face->full_name );
return font;
}
struct glyph_metrics struct glyph_metrics
{ {
GLYPHMETRICS gm; GLYPHMETRICS gm;
...@@ -1490,22 +1509,14 @@ static void add_child_font( struct gdi_font *font, const WCHAR *family_name ) ...@@ -1490,22 +1509,14 @@ static void add_child_font( struct gdi_font *font, const WCHAR *family_name )
} }
if (!best_face) return; if (!best_face) return;
child = alloc_gdi_font( best_face->file, best_face->data_ptr, best_face->data_size ); if (!(child = create_gdi_font( best_face, family_name, &font->lf ))) return;
child->fake_italic = italic && !(best_face->ntmFlags & NTM_ITALIC);
child->fake_bold = bold && !(best_face->ntmFlags & NTM_BOLD);
child->lf = font->lf;
child->matrix = font->matrix; child->matrix = font->matrix;
child->can_use_bitmap = font->can_use_bitmap; child->can_use_bitmap = font->can_use_bitmap;
child->face_index = best_face->face_index;
child->ntmFlags = best_face->ntmFlags;
child->aa_flags = HIWORD( best_face->flags );
child->scale_y = font->scale_y; child->scale_y = font->scale_y;
child->aveWidth = font->aveWidth; child->aveWidth = font->aveWidth;
child->charset = font->charset; child->charset = font->charset;
child->codepage = font->codepage; child->codepage = font->codepage;
child->base_font = font; child->base_font = font;
set_gdi_font_names( child, family_name, best_face->style_name, best_face->full_name );
list_add_tail( &font->child_fonts, &child->entry ); list_add_tail( &font->child_fonts, &child->entry );
TRACE( "created child font %p for base %p\n", child, font ); TRACE( "created child font %p for base %p\n", child, font );
} }
......
...@@ -3274,20 +3274,10 @@ found_face: ...@@ -3274,20 +3274,10 @@ found_face:
height = lf.lfHeight; height = lf.lfHeight;
TRACE("not in cache\n"); TRACE("not in cache\n");
font = alloc_gdi_font( face->file, face->data_ptr, face->data_size ); font = create_gdi_font( face, orig_name, &lf );
font->matrix = dcmat; font->matrix = dcmat;
font->lf = lf;
font->can_use_bitmap = can_use_bitmap; font->can_use_bitmap = can_use_bitmap;
font->fake_italic = (it && !(face->ntmFlags & NTM_ITALIC));
font->fake_bold = (bd && !(face->ntmFlags & NTM_BOLD));
font->fs = face->fs;
font->face_index = face->face_index;
font->ntmFlags = face->ntmFlags;
font->aa_flags = HIWORD( face->flags );
set_gdi_font_names( font, orig_name ? orig_name : family->family_name,
face->style_name, face->full_name );
if(csi.fs.fsCsb[0]) { if(csi.fs.fsCsb[0]) {
font->charset = lf.lfCharSet; font->charset = lf.lfCharSet;
font->codepage = csi.ciACP; font->codepage = csi.ciACP;
...@@ -3506,6 +3496,7 @@ static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEX ...@@ -3506,6 +3496,7 @@ static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEX
NEWTEXTMETRICEXW *pntm) NEWTEXTMETRICEXW *pntm)
{ {
struct gdi_font *font; struct gdi_font *font;
LOGFONTW lf = { .lfHeight = 100 };
if (face->cached_enum_data) if (face->cached_enum_data)
{ {
...@@ -3515,11 +3506,7 @@ static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEX ...@@ -3515,11 +3506,7 @@ static void GetEnumStructs(Face *face, const WCHAR *family_name, LPENUMLOGFONTEX
return; return;
} }
font = alloc_gdi_font( face->file, face->data_ptr, face->data_size ); if (!(font = create_gdi_font( face, family_name, &lf ))) return;
font->lf.lfHeight = 100;
font->face_index = face->face_index;
font->ntmFlags = face->ntmFlags;
set_gdi_font_names( font, family_name, face->style_name, face->full_name );
if (!freetype_load_font( font )) if (!freetype_load_font( font ))
{ {
......
...@@ -474,7 +474,6 @@ extern struct gdi_font_family *find_family_from_font_links( const WCHAR *name, c ...@@ -474,7 +474,6 @@ extern struct gdi_font_family *find_family_from_font_links( const WCHAR *name, c
FONTSIGNATURE fs ) DECLSPEC_HIDDEN; FONTSIGNATURE fs ) DECLSPEC_HIDDEN;
extern void create_child_font_list( struct gdi_font *font ) DECLSPEC_HIDDEN; extern void create_child_font_list( struct gdi_font *font ) DECLSPEC_HIDDEN;
extern struct gdi_font *alloc_gdi_font( const WCHAR *file, void *data_ptr, SIZE_T data_size ) DECLSPEC_HIDDEN;
extern void free_gdi_font( struct gdi_font *font ) DECLSPEC_HIDDEN; extern void free_gdi_font( struct gdi_font *font ) DECLSPEC_HIDDEN;
extern void cache_gdi_font( struct gdi_font *font ) DECLSPEC_HIDDEN; extern void cache_gdi_font( struct gdi_font *font ) DECLSPEC_HIDDEN;
extern struct gdi_font *find_cached_gdi_font( const LOGFONTW *lf, const FMAT2 *matrix, extern struct gdi_font *find_cached_gdi_font( const LOGFONTW *lf, const FMAT2 *matrix,
...@@ -482,6 +481,8 @@ extern struct gdi_font *find_cached_gdi_font( const LOGFONTW *lf, const FMAT2 *m ...@@ -482,6 +481,8 @@ extern struct gdi_font *find_cached_gdi_font( const LOGFONTW *lf, const FMAT2 *m
static inline const WCHAR *get_gdi_font_name( struct gdi_font *font ) { return (WCHAR *)font->otm.otmpFamilyName; } static inline const WCHAR *get_gdi_font_name( struct gdi_font *font ) { return (WCHAR *)font->otm.otmpFamilyName; }
extern void set_gdi_font_names( struct gdi_font *font, const WCHAR *family_name, const WCHAR *style_name, extern void set_gdi_font_names( struct gdi_font *font, const WCHAR *family_name, const WCHAR *style_name,
const WCHAR *full_name ) DECLSPEC_HIDDEN; const WCHAR *full_name ) DECLSPEC_HIDDEN;
extern struct gdi_font *create_gdi_font( const struct gdi_font_face *face, const WCHAR *family_name,
const LOGFONTW *lf ) DECLSPEC_HIDDEN;
extern void *get_GSUB_vert_feature( struct gdi_font *font ) DECLSPEC_HIDDEN; extern void *get_GSUB_vert_feature( struct gdi_font *font ) DECLSPEC_HIDDEN;
extern void font_init(void) DECLSPEC_HIDDEN; extern void font_init(void) DECLSPEC_HIDDEN;
extern CRITICAL_SECTION font_cs DECLSPEC_HIDDEN; extern CRITICAL_SECTION font_cs DECLSPEC_HIDDEN;
......
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