Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / gcc.dg / lto / 20091013-1_2.c
blob55f8ca1b46de235e27b19d75e3ad2503b2730c41
1 typedef struct HDC__ { int unused; } *HDC;
2 typedef struct HFONT__ { int unused; } *HFONT;
4 void* HeapAlloc(void*,unsigned int,unsigned long);
6 typedef struct tagLOGFONTW
8 int lfPitchAndFamily;
9 unsigned short lfFaceName[32];
10 } LOGFONTW, *PLOGFONTW, *LPLOGFONTW;
12 typedef struct tagGdiFont GdiFont;
13 typedef struct tagDC DC;
15 extern unsigned int WineEngGetFontData(GdiFont*, unsigned int, unsigned int, void*, unsigned int);
17 struct list
19 struct list *next;
20 struct list *prev;
23 typedef struct FT_FaceRec_
25 signed long face_flags;
26 } FT_FaceRec, *FT_Face;
28 typedef struct { } GM;
30 typedef struct { } FMAT2;
32 typedef struct {
33 unsigned int hash;
34 LOGFONTW lf;
35 int can_use_bitmap;
36 } FONT_DESC;
40 typedef struct tagHFONTLIST {
41 struct list entry;
42 HFONT hfont;
43 } HFONTLIST;
45 typedef struct {
46 struct list entry;
47 void *face;
48 GdiFont *font;
49 } CHILD_FONT;
52 struct tagGdiFont {
53 struct list entry;
54 GM **gm;
55 struct list hfontlist;
56 struct list child_fonts;
58 FT_Face ft_face;
59 FONT_DESC font_desc;
60 long ppem;
65 static struct list gdi_font_list = { &(gdi_font_list), &(gdi_font_list) };
70 static int get_glyph_index_linked(GdiFont *font, unsigned int c, GdiFont **linked_font, unsigned int *glyph);
71 static long load_VDMX(GdiFont*, long);
73 extern int f1(void*,int);
75 static FT_Face OpenFontFace(GdiFont *font, void *face, long width, long height)
77 FT_Face ft_face;
79 font->ppem = load_VDMX(font, height);
80 if(font->ppem == 0)
81 font->ppem = f1(ft_face, height);
82 return ft_face;
86 static GdiFont *alloc_font(void)
88 GdiFont *ret = HeapAlloc(0, 0x00000008, sizeof(*ret));
89 ret->gm = HeapAlloc(0, 0x00000008, sizeof(GM*));
90 return ret;
94 static long load_VDMX(GdiFont *font,long height)
96 unsigned short hdr[3];
98 WineEngGetFontData(font, 0x42424242, 0, hdr, 6);
99 return 0;
102 static int fontcmp(const GdiFont *font, FONT_DESC *fd)
104 if(font->font_desc.hash != fd->hash) return 1;
105 if(memcmp(&font->font_desc.lf, &fd->lf, __builtin_offsetof (LOGFONTW, lfFaceName))) return 1;
106 if(!font->font_desc.can_use_bitmap != !fd->can_use_bitmap) return 1;
107 return strcmpiW(font->font_desc.lf.lfFaceName, fd->lf.lfFaceName);
110 static GdiFont *find_in_cache(HFONT hfont, const LOGFONTW *plf, const FMAT2 *pmat, int can_use_bitmap)
112 GdiFont *ret;
113 FONT_DESC fd;
114 HFONTLIST *hflist;
115 struct list *font_elem_ptr, *hfontlist_elem_ptr;
117 fd.lf = *plf;
118 fd.can_use_bitmap = can_use_bitmap;
121 for ((font_elem_ptr) = (&gdi_font_list)->next; (font_elem_ptr) != (&gdi_font_list); (font_elem_ptr) = (font_elem_ptr)->next) {
122 ret = ((struct tagGdiFont *)((char *)(font_elem_ptr) - (unsigned long)(&((struct tagGdiFont *)0)->entry)));
123 if(!fontcmp(ret, &fd)) {
124 if(!can_use_bitmap && !( ret->ft_face->face_flags & ( 1L << 0 ) )) continue;
125 for ((hfontlist_elem_ptr) = (&ret->hfontlist)->next; (hfontlist_elem_ptr) != (&ret->hfontlist); (hfontlist_elem_ptr) = (hfontlist_elem_ptr)->next) {
126 hflist = ((struct tagHFONTLIST *)((char *)(hfontlist_elem_ptr) - (unsigned long)(&((struct tagHFONTLIST *)0)->entry)));
127 if(hflist->hfont == hfont)
128 return ret;
130 hflist = HeapAlloc(0, 0, sizeof(*hflist));
131 hflist->hfont = hfont;
132 return ret;
136 while(font_elem_ptr) {
137 ret = ((struct tagGdiFont *)((char *)(font_elem_ptr) - (unsigned long)(&((struct tagGdiFont *)0)->entry)));
138 if(!fontcmp(ret, &fd)) {
139 if(!can_use_bitmap && !( ret->ft_face->face_flags & ( 1L << 0 ) )) continue;
140 hflist = HeapAlloc(0, 0, sizeof(*hflist));
141 hflist->hfont = hfont;
142 return ret;
145 return ((void *)0);
151 GdiFont *WineEngCreateFontInstance(DC *dc, HFONT hfont)
153 GdiFont *ret;
154 int can_use_bitmap;
155 LOGFONTW lf;
156 FMAT2 dcmat;
158 if((ret = find_in_cache(hfont, &lf, &dcmat, can_use_bitmap)) != ((void *)0))
159 return ret;
160 return alloc_font();
163 extern unsigned int f(void*,unsigned int g);
165 static unsigned int get_glyph_index(void*font, unsigned int glyph)
167 return f(font, glyph);
170 unsigned int WineEngGetGlyphOutline(GdiFont *incoming_font, unsigned int glyph, unsigned int format,
171 void* lpgm, unsigned int buflen, void* buf,
172 const void* lpmat)
174 unsigned int glyph_index;
176 get_glyph_index_linked(incoming_font, glyph, &incoming_font, &glyph_index);
177 return 0;
180 static int load_child_font(GdiFont *font, CHILD_FONT *child)
182 child->font = alloc_font();
183 child->font->ft_face = OpenFontFace(child->font, child->face, 0, -font->ppem);
184 if(!child->font->ft_face)
185 return 0;
186 return 1;
189 static int get_glyph_index_linked(GdiFont *font, unsigned int c, GdiFont **linked_font, unsigned int *glyph)
191 unsigned int g;
192 CHILD_FONT *child_font;
194 for ((child_font) = ((CHILD_FONT *)((char *)((&font->child_fonts)->next) - (unsigned long)(&((CHILD_FONT *)0)->entry))); &(child_font)->entry != (&font->child_fonts); (child_font) = ((CHILD_FONT *)((char *)((child_font)->entry.next) - (unsigned long)(&((CHILD_FONT *)0)->entry))))
196 if(!load_child_font(font, child_font))
197 continue;
199 g = get_glyph_index(child_font->font, c);
200 if(g) {
201 *glyph = g;
202 *linked_font = child_font->font;
203 return 1;
206 return 0;
209 unsigned int WineEngGetFontData(GdiFont *font, unsigned int table, unsigned int offset, void* buf,
210 unsigned int cbData)
212 unsigned long len;
213 load_sfnt_table(font->ft_face, table, offset, buf, &len);
214 return len;
217 int WineEngGetLinkedHFont(DC *dc, unsigned short c, HFONT *new_hfont, unsigned int *glyph) {
218 return get_glyph_index_linked(0, 0, 0, 0);