Debian Codegraph @

gcc/testsuite/gcc.dg/lto/20091013-1_2.c

raw
1 /* { dg-options "-std=gnu17 -Wno-stringop-overread" } */
2
3 typedef struct HDC__ { int unused; } *HDC;
4 typedef struct HFONT__ { int unused; } *HFONT;
5
6 void* HeapAlloc(void*,unsigned int,unsigned long);
7 extern int memcmp (const void *, const void *, __SIZE_TYPE__);
8
9 typedef struct tagLOGFONTW
10 {
11 int lfPitchAndFamily;
12 unsigned short lfFaceName[32];
13 } LOGFONTW, *PLOGFONTW, *LPLOGFONTW;
14
15 typedef struct tagGdiFont GdiFont;
16 typedef struct tagDC DC;
17
18 extern unsigned int WineEngGetFontData(GdiFont*, unsigned int, unsigned int, void*, unsigned int);
19
20 struct list
21 {
22 struct list *next;
23 struct list *prev;
24 };
25
26 typedef struct FT_FaceRec_
27 {
28 signed long face_flags;
29 } FT_FaceRec, *FT_Face;
30
31 typedef struct { } GM;
32
33 typedef struct { } FMAT2;
34
35 typedef struct {
36 unsigned int hash;
37 LOGFONTW lf;
38 int can_use_bitmap;
39 } FONT_DESC;
40
41
42
43 typedef struct tagHFONTLIST {
44 struct list entry;
45 HFONT hfont;
46 } HFONTLIST;
47
48 typedef struct {
49 struct list entry;
50 void *face;
51 GdiFont *font;
52 } CHILD_FONT;
53
54
55 struct tagGdiFont {
56 struct list entry;
57 GM **gm;
58 struct list hfontlist;
59 struct list child_fonts;
60
61 FT_Face ft_face;
62 FONT_DESC font_desc;
63 long ppem;
64 };
65
66
67
68 static struct list gdi_font_list = { &(gdi_font_list), &(gdi_font_list) };
69
70
71
72
73 static int get_glyph_index_linked(GdiFont *font, unsigned int c, GdiFont **linked_font, unsigned int *glyph);
74 static long load_VDMX(GdiFont*, long);
75
76 extern int f1(void*,int);
77 extern int strcmpiW (const void*,const void*);
78
79 static FT_Face OpenFontFace(GdiFont *font, void *face, long width, long height)
80 {
81 FT_Face ft_face;
82
83 font->ppem = load_VDMX(font, height);
84 if(font->ppem == 0)
85 font->ppem = f1(ft_face, height);
86 return ft_face;
87 }
88
89
90 static GdiFont *alloc_font(void)
91 {
92 GdiFont *ret = HeapAlloc(0, 0x00000008, sizeof(*ret));
93 ret->gm = HeapAlloc(0, 0x00000008, sizeof(GM*));
94 return ret;
95 }
96
97
98 static long load_VDMX(GdiFont *font,long height)
99 {
100 unsigned short hdr[3];
101
102 WineEngGetFontData(font, 0x42424242, 0, hdr, 6);
103 return 0;
104 }
105
106 static int fontcmp(const GdiFont *font, FONT_DESC *fd)
107 {
108 if(font->font_desc.hash != fd->hash) return 1;
109 if(memcmp(&font->font_desc.lf, &fd->lf, __builtin_offsetof (LOGFONTW, lfFaceName))) return 1;
110 if(!font->font_desc.can_use_bitmap != !fd->can_use_bitmap) return 1;
111 return strcmpiW(font->font_desc.lf.lfFaceName, fd->lf.lfFaceName);
112 }
113
114 static GdiFont *find_in_cache(HFONT hfont, const LOGFONTW *plf, const FMAT2 *pmat, int can_use_bitmap)
115 {
116 GdiFont *ret;
117 FONT_DESC fd;
118 HFONTLIST *hflist;
119 struct list *font_elem_ptr, *hfontlist_elem_ptr;
120
121 fd.lf = *plf;
122 fd.can_use_bitmap = can_use_bitmap;
123
124
125 for ((font_elem_ptr) = (&gdi_font_list)->next; (font_elem_ptr) != (&gdi_font_list); (font_elem_ptr) = (font_elem_ptr)->next) {
126 ret = ((struct tagGdiFont *)((char *)(font_elem_ptr) - (unsigned long)(&((struct tagGdiFont *)0)->entry)));
127 if(!fontcmp(ret, &fd)) {
128 if(!can_use_bitmap && !( ret->ft_face->face_flags & ( 1L << 0 ) )) continue;
129 for ((hfontlist_elem_ptr) = (&ret->hfontlist)->next; (hfontlist_elem_ptr) != (&ret->hfontlist); (hfontlist_elem_ptr) = (hfontlist_elem_ptr)->next) {
130 hflist = ((struct tagHFONTLIST *)((char *)(hfontlist_elem_ptr) - (unsigned long)(&((struct tagHFONTLIST *)0)->entry)));
131 if(hflist->hfont == hfont)
132 return ret;
133 }
134 hflist = HeapAlloc(0, 0, sizeof(*hflist));
135 hflist->hfont = hfont;
136 return ret;
137 }
138 }
139
140 while(font_elem_ptr) {
141 ret = ((struct tagGdiFont *)((char *)(font_elem_ptr) - (unsigned long)(&((struct tagGdiFont *)0)->entry)));
142 if(!fontcmp(ret, &fd)) {
143 if(!can_use_bitmap && !( ret->ft_face->face_flags & ( 1L << 0 ) )) continue;
144 hflist = HeapAlloc(0, 0, sizeof(*hflist));
145 hflist->hfont = hfont;
146 return ret;
147 }
148 }
149 return ((void *)0);
150 }
151
152
153
154
155 GdiFont *WineEngCreateFontInstance(DC *dc, HFONT hfont)
156 {
157 GdiFont *ret;
158 int can_use_bitmap;
159 LOGFONTW lf;
160 FMAT2 dcmat;
161
162 if((ret = find_in_cache(hfont, &lf, &dcmat, can_use_bitmap)) != ((void *)0))
163 return ret;
164 return alloc_font();
165 }
166
167 extern unsigned int f(void*,unsigned int g);
168
169 static unsigned int get_glyph_index(void*font, unsigned int glyph)
170 {
171 return f(font, glyph);
172 }
173
174 unsigned int WineEngGetGlyphOutline(GdiFont *incoming_font, unsigned int glyph, unsigned int format,
175 void* lpgm, unsigned int buflen, void* buf,
176 const void* lpmat)
177 {
178 unsigned int glyph_index;
179
180 get_glyph_index_linked(incoming_font, glyph, &incoming_font, &glyph_index);
181 return 0;
182 }
183
184 static int load_child_font(GdiFont *font, CHILD_FONT *child)
185 {
186 child->font = alloc_font();
187 child->font->ft_face = OpenFontFace(child->font, child->face, 0, -font->ppem);
188 if(!child->font->ft_face)
189 return 0;
190 return 1;
191 }
192
193 static int get_glyph_index_linked(GdiFont *font, unsigned int c, GdiFont **linked_font, unsigned int *glyph)
194 {
195 unsigned int g;
196 CHILD_FONT *child_font;
197
198 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))))
199 {
200 if(!load_child_font(font, child_font))
201 continue;
202
203 g = get_glyph_index(child_font->font, c);
204 if(g) {
205 *glyph = g;
206 *linked_font = child_font->font;
207 return 1;
208 }
209 }
210 return 0;
211 }
212
213 void load_sfnt_table ();
214
215 unsigned int WineEngGetFontData(GdiFont *font, unsigned int table, unsigned int offset, void* buf,
216 unsigned int cbData)
217 {
218 unsigned long len;
219 load_sfnt_table(font->ft_face, table, offset, buf, &len);
220 return len;
221 }
222
223 int WineEngGetLinkedHFont(DC *dc, unsigned short c, HFONT *new_hfont, unsigned int *glyph) {
224 return get_glyph_index_linked(0, 0, 0, 0);
225 }
226