1 typedef struct HDC__ { int unused; } *HDC;
2 typedef struct HFONT__ { int unused; } *HFONT;
3
4 typedef struct
5 {
6 unsigned int ciACP;
7 } CHARSETINFO, *PCHARSETINFO, *LPCHARSETINFO;
8
9 typedef struct tagTEXTMETRICW
10 {
11 int tmCharSet;
12 } TEXTMETRICW, *LPTEXTMETRICW, *PTEXTMETRICW;
13
14 struct gdi_obj_funcs
15 {
16 void* (*pSelectObject)( void* handle, void* hdc );
17 };
18
19 typedef struct tagGdiFont GdiFont;
20
21 typedef struct tagDC
22 {
23 int xunused;
24 GdiFont *gdiFont;
25 unsigned int font_code_page;
26 } DC;
27
28 extern GdiFont* WineEngCreateFontInstance(DC*, HFONT);
29 extern unsigned int WineEngGetTextCharsetInfo(GdiFont *font, void* fs, unsigned int flags);
30 extern int WineEngGetTextMetrics(GdiFont*, LPTEXTMETRICW);
31 extern void* alloc_gdi_handle( void *obj, unsigned short type, const struct gdi_obj_funcs *funcs );
32
33 enum __wine_debug_class
34 {
35 __WINE_DBCL_FIXME,
36 __WINE_DBCL_ERR,
37 __WINE_DBCL_WARN,
38 __WINE_DBCL_TRACE,
39
40 __WINE_DBCL_INIT = 7
41 };
42
43 struct __wine_debug_channel
44 {
45 unsigned char flags;
46 char name[15];
47 };
48
49 extern int wine_dbg_log( enum __wine_debug_class cls, struct __wine_debug_channel *ch, const char *func,
50 const char *format, ... ) __attribute__((format (printf,4,5)));
51
52 static struct __wine_debug_channel __wine_dbch_font = { ~0, "font" };
53 static struct __wine_debug_channel * const __wine_dbch___default = &__wine_dbch_font;
54
55 static void* FONT_SelectObject( void* handle, void* hdc );
56 int TranslateCharsetInfo( void *, CHARSETINFO *, int );
57 unsigned int GetACP (void);
58
59 static const struct gdi_obj_funcs font_funcs =
60 {
61 FONT_SelectObject,
62 };
63
64 HFONT CreateFontIndirectW( const void *plf )
65 {
66 return alloc_gdi_handle( 0, 6, &font_funcs );
67 }
68
69 static void update_font_code_page( DC *dc )
70 {
71 CHARSETINFO csi;
72 int charset = (unsigned char)1;
73
74 if (dc->gdiFont)
75 charset = WineEngGetTextCharsetInfo( dc->gdiFont, ((void *)0), 0 );
76
77 if (TranslateCharsetInfo( ((void *)(unsigned long)((unsigned long)charset)), &csi, 1) )
78 dc->font_code_page = csi.ciACP;
79 else {
80 switch(charset) {
81 case (unsigned char)1:
82 dc->font_code_page = GetACP();
83 break;
84
85 case (unsigned char)246:
86 dc->font_code_page = 0;
87 break;
88
89 default:
90 do { if((((__wine_dbch___default))->flags & (1 << __WINE_DBCL_FIXME))) { struct __wine_debug_channel * const __dbch = (__wine_dbch___default); const enum __wine_debug_class __dbcl = __WINE_DBCL_FIXME; wine_dbg_log( __dbcl, __dbch, __FUNCTION__, "Can't find codepage for charset %d\n", charset); } } while(0);
91 dc->font_code_page = 0;
92 break;
93 }
94 }
95
96 do { if((((__wine_dbch___default))->flags & (1 << __WINE_DBCL_TRACE))) { struct __wine_debug_channel * const __dbch = (__wine_dbch___default); const enum __wine_debug_class __dbcl = __WINE_DBCL_TRACE; wine_dbg_log( __dbcl, __dbch, __FUNCTION__, "charset %d => cp %d\n", charset, dc->font_code_page); } } while(0);
97 }
98
99 static void* FONT_SelectObject( void* handle, void* hdc )
100 {
101 DC *dc;
102
103 dc->gdiFont = WineEngCreateFontInstance( dc, handle );
104 update_font_code_page( dc );
105 return 0;
106 }
107
108 int GetTextMetricsW( HDC hdc, TEXTMETRICW *metrics )
109 {
110 DC * dc;
111 return WineEngGetTextMetrics(dc->gdiFont, metrics);
112 }
113