1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   Binres Loader Management (Binres Loader)                            */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_binres_loader.h"
29 #include "gx_system.h"
30 #include "gx_utility.h"
31 
32 extern GX_CONST GX_FONT _gx_system_font_mono;
33 extern GX_CONST GX_FONT _gx_system_font_4bpp;
34 extern GX_CONST GX_FONT _gx_system_font_8bpp;
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _gx_binres_theme_header_load                        PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Kenneth Maxwell, Microsoft Corporation                              */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function reads theme header from a binary data buffer.         */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    info                                  Binary read control block     */
53 /*    header                                Returned theme header         */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    Status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    None                                                                */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    GUIX Internal Code                                                  */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            removed use of memcpy,      */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
77 #ifdef GX_BINARY_RESOURCE_SUPPORT
78 
_gx_binres_theme_header_load(GX_BINRES_DATA_INFO * info,GX_THEME_HEADER * header)79 static UINT _gx_binres_theme_header_load(GX_BINRES_DATA_INFO *info, GX_THEME_HEADER *header)
80 {
81     GX_BINRES_READ_USHORT(header -> gx_theme_header_magic_number, info -> gx_binres_root_address + info -> gx_binres_read_offset);
82     info -> gx_binres_read_offset += sizeof(USHORT);
83 
84     GX_BINRES_READ_USHORT(header -> gx_theme_header_index, info -> gx_binres_root_address + info -> gx_binres_read_offset);
85     info -> gx_binres_read_offset += sizeof(USHORT);
86 
87     GX_BINRES_READ_USHORT(header -> gx_theme_header_color_count, info -> gx_binres_root_address + info -> gx_binres_read_offset);
88     info -> gx_binres_read_offset += sizeof(USHORT);
89 
90     GX_BINRES_READ_USHORT(header -> gx_theme_header_palette_count, info -> gx_binres_root_address + info -> gx_binres_read_offset);
91     info -> gx_binres_read_offset += sizeof(USHORT);
92 
93     GX_BINRES_READ_USHORT(header -> gx_theme_header_font_count, info -> gx_binres_root_address + info -> gx_binres_read_offset);
94     info -> gx_binres_read_offset += sizeof(USHORT);
95 
96     GX_BINRES_READ_USHORT(header -> gx_theme_header_pixelmap_count, info -> gx_binres_root_address + info -> gx_binres_read_offset);
97     info -> gx_binres_read_offset += sizeof(USHORT);
98 
99     GX_BINRES_READ_GX_VALUE(header -> gx_theme_header_vscroll_appearance.gx_scroll_width, info -> gx_binres_root_address + info -> gx_binres_read_offset);
100     info -> gx_binres_read_offset += sizeof(GX_VALUE);
101 
102     GX_BINRES_READ_GX_VALUE(header -> gx_theme_header_vscroll_appearance.gx_scroll_thumb_width, info -> gx_binres_root_address + info -> gx_binres_read_offset);
103     info -> gx_binres_read_offset += sizeof(GX_VALUE);
104 
105     GX_BINRES_READ_GX_VALUE(header -> gx_theme_header_vscroll_appearance.gx_scroll_thumb_travel_min, info -> gx_binres_root_address + info -> gx_binres_read_offset);
106     info -> gx_binres_read_offset += sizeof(GX_VALUE);
107 
108     GX_BINRES_READ_GX_VALUE(header -> gx_theme_header_vscroll_appearance.gx_scroll_thumb_travel_max, info -> gx_binres_root_address + info -> gx_binres_read_offset);
109     info -> gx_binres_read_offset += sizeof(GX_VALUE);
110 
111     GX_BINRES_READ_GX_UBYTE(header -> gx_theme_header_vscroll_appearance.gx_scroll_thumb_border_style, info -> gx_binres_root_address + info -> gx_binres_read_offset);
112     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
113 
114     GX_BINRES_READ_ULONG(header -> gx_theme_header_vscroll_appearance.gx_scroll_fill_pixelmap, info -> gx_binres_root_address + info -> gx_binres_read_offset);
115     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
116 
117     GX_BINRES_READ_ULONG(header -> gx_theme_header_vscroll_appearance.gx_scroll_thumb_pixelmap, info -> gx_binres_root_address + info -> gx_binres_read_offset);
118     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
119 
120     GX_BINRES_READ_ULONG(header -> gx_theme_header_vscroll_appearance.gx_scroll_up_pixelmap, info -> gx_binres_root_address + info -> gx_binres_read_offset);
121     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
122 
123     GX_BINRES_READ_ULONG(header -> gx_theme_header_vscroll_appearance.gx_scroll_down_pixelmap, info -> gx_binres_root_address + info -> gx_binres_read_offset);
124     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
125 
126     GX_BINRES_READ_ULONG(header -> gx_theme_header_vscroll_appearance.gx_scroll_thumb_color, info -> gx_binres_root_address + info -> gx_binres_read_offset);
127     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
128 
129     GX_BINRES_READ_ULONG(header -> gx_theme_header_vscroll_appearance.gx_scroll_thumb_border_color, info -> gx_binres_root_address + info -> gx_binres_read_offset);
130     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
131 
132     GX_BINRES_READ_ULONG(header -> gx_theme_header_vscroll_appearance.gx_scroll_button_color, info -> gx_binres_root_address + info -> gx_binres_read_offset);
133     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
134 
135     GX_BINRES_READ_GX_VALUE(header -> gx_theme_header_hscroll_appearance.gx_scroll_width, info -> gx_binres_root_address + info -> gx_binres_read_offset);
136     info -> gx_binres_read_offset += sizeof(GX_VALUE);
137 
138     GX_BINRES_READ_GX_VALUE(header -> gx_theme_header_hscroll_appearance.gx_scroll_thumb_width, info -> gx_binres_root_address + info -> gx_binres_read_offset);
139     info -> gx_binres_read_offset += sizeof(GX_VALUE);
140 
141     GX_BINRES_READ_GX_VALUE(header -> gx_theme_header_hscroll_appearance.gx_scroll_thumb_travel_min, info -> gx_binres_root_address + info -> gx_binres_read_offset);
142     info -> gx_binres_read_offset += sizeof(GX_VALUE);
143 
144     GX_BINRES_READ_GX_VALUE(header -> gx_theme_header_hscroll_appearance.gx_scroll_thumb_travel_max, info -> gx_binres_root_address + info -> gx_binres_read_offset);
145     info -> gx_binres_read_offset += sizeof(GX_VALUE);
146 
147     GX_BINRES_READ_GX_UBYTE(header -> gx_theme_header_hscroll_appearance.gx_scroll_thumb_border_style, info -> gx_binres_root_address + info -> gx_binres_read_offset);
148     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
149 
150     GX_BINRES_READ_ULONG(header -> gx_theme_header_hscroll_appearance.gx_scroll_fill_pixelmap, info -> gx_binres_root_address + info -> gx_binres_read_offset);
151     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
152 
153     GX_BINRES_READ_ULONG(header -> gx_theme_header_hscroll_appearance.gx_scroll_thumb_pixelmap, info -> gx_binres_root_address + info -> gx_binres_read_offset);
154     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
155 
156     GX_BINRES_READ_ULONG(header -> gx_theme_header_hscroll_appearance.gx_scroll_up_pixelmap, info -> gx_binres_root_address + info -> gx_binres_read_offset);
157     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
158 
159     GX_BINRES_READ_ULONG(header -> gx_theme_header_hscroll_appearance.gx_scroll_down_pixelmap, info -> gx_binres_root_address + info -> gx_binres_read_offset);
160     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
161 
162     GX_BINRES_READ_ULONG(header -> gx_theme_header_hscroll_appearance.gx_scroll_thumb_color, info -> gx_binres_root_address + info -> gx_binres_read_offset);
163     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
164 
165     GX_BINRES_READ_ULONG(header -> gx_theme_header_hscroll_appearance.gx_scroll_thumb_border_color, info -> gx_binres_root_address + info -> gx_binres_read_offset);
166     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
167 
168     GX_BINRES_READ_ULONG(header -> gx_theme_header_hscroll_appearance.gx_scroll_button_color, info -> gx_binres_root_address + info -> gx_binres_read_offset);
169     info -> gx_binres_read_offset += sizeof(GX_RESOURCE_ID);
170 
171     GX_BINRES_READ_ULONG(header -> gx_theme_header_vscroll_style, info -> gx_binres_root_address + info -> gx_binres_read_offset);
172     info -> gx_binres_read_offset += sizeof(ULONG);
173 
174     GX_BINRES_READ_ULONG(header -> gx_theme_header_hscroll_style, info -> gx_binres_root_address + info -> gx_binres_read_offset);
175     info -> gx_binres_read_offset += sizeof(ULONG);
176 
177     GX_BINRES_READ_ULONG(header -> gx_theme_header_color_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
178     info -> gx_binres_read_offset += sizeof(ULONG);
179 
180     GX_BINRES_READ_ULONG(header -> gx_theme_header_palette_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
181     info -> gx_binres_read_offset += sizeof(ULONG);
182 
183     GX_BINRES_READ_ULONG(header -> gx_theme_header_font_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
184     info -> gx_binres_read_offset += sizeof(ULONG);
185 
186     GX_BINRES_READ_ULONG(header -> gx_theme_header_pixelmap_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
187     info -> gx_binres_read_offset += sizeof(ULONG);
188 
189     GX_BINRES_READ_ULONG(header -> gx_theme_header_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
190     info -> gx_binres_read_offset += sizeof(ULONG);
191 
192     return GX_SUCCESS;
193 }
194 #endif
195 
196 /**************************************************************************/
197 /*                                                                        */
198 /*  FUNCTION                                               RELEASE        */
199 /*                                                                        */
200 /*    _gx_binres_color_header_load                        PORTABLE C      */
201 /*                                                           6.1          */
202 /*  AUTHOR                                                                */
203 /*                                                                        */
204 /*    Kenneth Maxwell, Microsoft Corporation                              */
205 /*                                                                        */
206 /*  DESCRIPTION                                                           */
207 /*                                                                        */
208 /*    This function reads color header from a binary data buffer.         */
209 /*                                                                        */
210 /*  INPUT                                                                 */
211 /*                                                                        */
212 /*    info                                  Binary read control block     */
213 /*    header                                Returned color header         */
214 /*                                                                        */
215 /*  OUTPUT                                                                */
216 /*                                                                        */
217 /*    Status                                Completion status             */
218 /*                                                                        */
219 /*  CALLS                                                                 */
220 /*                                                                        */
221 /*    None                                                                */
222 /*                                                                        */
223 /*  CALLED BY                                                             */
224 /*                                                                        */
225 /*    GUIX Internal Code                                                  */
226 /*                                                                        */
227 /*  RELEASE HISTORY                                                       */
228 /*                                                                        */
229 /*    DATE              NAME                      DESCRIPTION             */
230 /*                                                                        */
231 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
232 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
233 /*                                            removed use of memcpy,      */
234 /*                                            resulting in version 6.1    */
235 /*                                                                        */
236 /**************************************************************************/
237 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_color_header_load(GX_BINRES_DATA_INFO * info,GX_COLOR_HEADER * header)238 static UINT _gx_binres_color_header_load(GX_BINRES_DATA_INFO *info, GX_COLOR_HEADER *header)
239 {
240     GX_BINRES_READ_USHORT(header -> gx_color_header_magic_number, info -> gx_binres_root_address + info -> gx_binres_read_offset);
241     info -> gx_binres_read_offset += sizeof(USHORT);
242 
243     GX_BINRES_READ_USHORT(header -> gx_color_header_color_count, info -> gx_binres_root_address + info -> gx_binres_read_offset);
244     info -> gx_binres_read_offset += sizeof(USHORT);
245 
246     GX_BINRES_READ_ULONG(header -> gx_color_header_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
247     info -> gx_binres_read_offset += sizeof(ULONG);
248 
249     return GX_SUCCESS;
250 }
251 #endif
252 
253 /**************************************************************************/
254 /*                                                                        */
255 /*  FUNCTION                                               RELEASE        */
256 /*                                                                        */
257 /*    _gx_binres_palette_header_load                      PORTABLE C      */
258 /*                                                           6.1          */
259 /*  AUTHOR                                                                */
260 /*                                                                        */
261 /*    Kenneth Maxwell, Microsoft Corporation                              */
262 /*                                                                        */
263 /*  DESCRIPTION                                                           */
264 /*                                                                        */
265 /*    This function reads palette header from a binary data buffer.       */
266 /*                                                                        */
267 /*  INPUT                                                                 */
268 /*                                                                        */
269 /*    info                                  Binary read control block     */
270 /*    header                                Returned palette header       */
271 /*                                                                        */
272 /*  OUTPUT                                                                */
273 /*                                                                        */
274 /*    Status                                Completion status             */
275 /*                                                                        */
276 /*  CALLS                                                                 */
277 /*                                                                        */
278 /*    None                                                                */
279 /*                                                                        */
280 /*  CALLED BY                                                             */
281 /*                                                                        */
282 /*    GUIX Internal Code                                                  */
283 /*                                                                        */
284 /*  RELEASE HISTORY                                                       */
285 /*                                                                        */
286 /*    DATE              NAME                      DESCRIPTION             */
287 /*                                                                        */
288 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
289 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
290 /*                                            removed use of memcpy,      */
291 /*                                            resulting in version 6.1    */
292 /*                                                                        */
293 /**************************************************************************/
294 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_palette_header_load(GX_BINRES_DATA_INFO * info,GX_PALETTE_HEADER * header)295 static UINT _gx_binres_palette_header_load(GX_BINRES_DATA_INFO *info, GX_PALETTE_HEADER *header)
296 {
297     GX_BINRES_READ_USHORT(header -> gx_palette_header_magic_number, info -> gx_binres_root_address + info -> gx_binres_read_offset);
298     info -> gx_binres_read_offset += sizeof(USHORT);
299 
300     GX_BINRES_READ_USHORT(header -> gx_palette_header_color_count, info -> gx_binres_root_address + info -> gx_binres_read_offset);
301     info -> gx_binres_read_offset += sizeof(USHORT);
302 
303     GX_BINRES_READ_ULONG(header -> gx_palette_header_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
304     info -> gx_binres_read_offset += sizeof(ULONG);
305 
306     return GX_SUCCESS;
307 }
308 #endif
309 
310 /**************************************************************************/
311 /*                                                                        */
312 /*  FUNCTION                                               RELEASE        */
313 /*                                                                        */
314 /*    _gx_binres_font_header_load                         PORTABLE C      */
315 /*                                                           6.1          */
316 /*  AUTHOR                                                                */
317 /*                                                                        */
318 /*    Kenneth Maxwell, Microsoft Corporation                              */
319 /*                                                                        */
320 /*  DESCRIPTION                                                           */
321 /*                                                                        */
322 /*    This function reads font header from a binary data buffer.          */
323 /*                                                                        */
324 /*  INPUT                                                                 */
325 /*                                                                        */
326 /*    info                                  Binary read control block     */
327 /*    header                                Returned font header          */
328 /*                                                                        */
329 /*  OUTPUT                                                                */
330 /*                                                                        */
331 /*    Status                                Completion status             */
332 /*                                                                        */
333 /*  CALLS                                                                 */
334 /*                                                                        */
335 /*    None                                                                */
336 /*                                                                        */
337 /*  CALLED BY                                                             */
338 /*                                                                        */
339 /*    GUIX Internal Code                                                  */
340 /*                                                                        */
341 /*  RELEASE HISTORY                                                       */
342 /*                                                                        */
343 /*    DATE              NAME                      DESCRIPTION             */
344 /*                                                                        */
345 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
346 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
347 /*                                            removed use of memcpy,      */
348 /*                                            resulting in version 6.1    */
349 /*                                                                        */
350 /**************************************************************************/
351 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_font_header_load(GX_BINRES_DATA_INFO * info,GX_FONT_HEADER * header)352 static UINT _gx_binres_font_header_load(GX_BINRES_DATA_INFO *info, GX_FONT_HEADER *header)
353 {
354     GX_BINRES_READ_USHORT(header -> gx_font_header_magic_number, info -> gx_binres_root_address + info -> gx_binres_read_offset);
355     info -> gx_binres_read_offset += sizeof(USHORT);
356 
357     GX_BINRES_READ_USHORT(header -> gx_font_header_index, info -> gx_binres_root_address + info -> gx_binres_read_offset);
358     info -> gx_binres_read_offset += sizeof(USHORT);
359 
360     GX_BINRES_READ_USHORT(header -> gx_font_header_page_count, info -> gx_binres_root_address + info -> gx_binres_read_offset);
361     info -> gx_binres_read_offset += sizeof(USHORT);
362 
363     GX_BINRES_READ_GX_UBYTE(header -> gx_font_header_deault, info -> gx_binres_root_address + info -> gx_binres_read_offset);
364     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
365 
366     GX_BINRES_READ_GX_UBYTE(header -> gx_font_header_bits, info -> gx_binres_root_address + info -> gx_binres_read_offset);
367     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
368 
369     GX_BINRES_READ_ULONG(header -> gx_font_header_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
370     info -> gx_binres_read_offset += sizeof(ULONG);
371 
372     GX_BINRES_READ_ULONG(header -> gx_font_header_data_offset, info -> gx_binres_root_address + info -> gx_binres_read_offset);
373     info -> gx_binres_read_offset += sizeof(ULONG);
374 
375     return GX_SUCCESS;
376 }
377 #endif
378 
379 /**************************************************************************/
380 /*                                                                        */
381 /*  FUNCTION                                               RELEASE        */
382 /*                                                                        */
383 /*    _gx_binres_page_header_load                         PORTABLE C      */
384 /*                                                           6.1          */
385 /*  AUTHOR                                                                */
386 /*                                                                        */
387 /*    Kenneth Maxwell, Microsoft Corporation                              */
388 /*                                                                        */
389 /*  DESCRIPTION                                                           */
390 /*                                                                        */
391 /*    This function reads page header from a binary data buffer.          */
392 /*                                                                        */
393 /*  INPUT                                                                 */
394 /*                                                                        */
395 /*    info                                  Binary read control block     */
396 /*    header                                Returned page header          */
397 /*                                                                        */
398 /*  OUTPUT                                                                */
399 /*                                                                        */
400 /*    Status                                Completion status             */
401 /*                                                                        */
402 /*  CALLS                                                                 */
403 /*                                                                        */
404 /*    None                                                                */
405 /*                                                                        */
406 /*  CALLED BY                                                             */
407 /*                                                                        */
408 /*    GUIX Internal Code                                                  */
409 /*                                                                        */
410 /*  RELEASE HISTORY                                                       */
411 /*                                                                        */
412 /*    DATE              NAME                      DESCRIPTION             */
413 /*                                                                        */
414 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
415 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
416 /*                                            removed use of memcpy,      */
417 /*                                            resulting in version 6.1    */
418 /*                                                                        */
419 /**************************************************************************/
420 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_page_header_load(GX_BINRES_DATA_INFO * info,GX_PAGE_HEADER * header)421 static UINT _gx_binres_page_header_load(GX_BINRES_DATA_INFO *info, GX_PAGE_HEADER *header)
422 {
423 ULONG read_data = 0;
424 
425     GX_BINRES_READ_USHORT(header -> gx_page_header_magic_number, info -> gx_binres_root_address + info -> gx_binres_read_offset);
426     info -> gx_binres_read_offset += sizeof(USHORT);
427 
428     GX_BINRES_READ_USHORT(header -> gx_page_header_index, info -> gx_binres_root_address + info -> gx_binres_read_offset);
429     info -> gx_binres_read_offset += sizeof(USHORT);
430 
431     GX_BINRES_READ_GX_UBYTE(header -> gx_page_header_format, info -> gx_binres_root_address + info -> gx_binres_read_offset);
432     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
433 
434     GX_BINRES_READ_GX_UBYTE(header -> gx_page_header_prespace, info -> gx_binres_root_address + info -> gx_binres_read_offset);
435     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
436 
437     GX_BINRES_READ_GX_UBYTE(header -> gx_page_header_postspace, info -> gx_binres_root_address + info -> gx_binres_read_offset);
438     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
439 
440     GX_BINRES_READ_GX_UBYTE(header -> gx_page_header_line_height, info -> gx_binres_root_address + info -> gx_binres_read_offset);
441     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
442 
443     GX_BINRES_READ_GX_UBYTE(header -> gx_page_header_baseline, info -> gx_binres_root_address + info -> gx_binres_read_offset);
444     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
445 
446     /* In the binary resource file, CHAR_CODE is always stored as 4-byte value. */
447     GX_BINRES_READ_ULONG(read_data, info -> gx_binres_root_address + info -> gx_binres_read_offset);
448     info -> gx_binres_read_offset += sizeof(ULONG);
449     header -> gx_page_header_first_glyph = (GX_CHAR_CODE)read_data;
450 
451     /* In the binary resource file, CHAR_CODE is always stored as 4-byte value. */
452     GX_BINRES_READ_ULONG(read_data, info -> gx_binres_root_address + info -> gx_binres_read_offset);
453     info -> gx_binres_read_offset += sizeof(ULONG);
454     header -> gx_page_header_last_glyph = (GX_CHAR_CODE)read_data;
455 
456     GX_BINRES_READ_ULONG(header -> gx_page_header_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
457     info -> gx_binres_read_offset += sizeof(ULONG);
458 
459     return GX_SUCCESS;
460 }
461 #endif
462 
463 /**************************************************************************/
464 /*                                                                        */
465 /*  FUNCTION                                               RELEASE        */
466 /*                                                                        */
467 /*    _gx_binres_glyph_header_load                        PORTABLE C      */
468 /*                                                           6.1          */
469 /*  AUTHOR                                                                */
470 /*                                                                        */
471 /*    Kenneth Maxwell, Microsoft Corporation                              */
472 /*                                                                        */
473 /*  DESCRIPTION                                                           */
474 /*                                                                        */
475 /*    This function reads glyph header from a binary data buffer.         */
476 /*                                                                        */
477 /*  INPUT                                                                 */
478 /*                                                                        */
479 /*    info                                  Binary read control block     */
480 /*    header                                Returned glyph header         */
481 /*                                                                        */
482 /*  OUTPUT                                                                */
483 /*                                                                        */
484 /*    Status                                Completion status             */
485 /*                                                                        */
486 /*  CALLS                                                                 */
487 /*                                                                        */
488 /*    None                                                                */
489 /*                                                                        */
490 /*  CALLED BY                                                             */
491 /*                                                                        */
492 /*    GUIX Internal Code                                                  */
493 /*                                                                        */
494 /*  RELEASE HISTORY                                                       */
495 /*                                                                        */
496 /*    DATE              NAME                      DESCRIPTION             */
497 /*                                                                        */
498 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
499 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
500 /*                                            removed use of memcpy, and  */
501 /*                                            updated with binary         */
502 /*                                            resource layout change,     */
503 /*                                            resulting in version 6.1    */
504 /*                                                                        */
505 /**************************************************************************/
506 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_glyph_header_load(GX_BINRES_DATA_INFO * info,GX_GLYPH_HEADER * header)507 static UINT _gx_binres_glyph_header_load(GX_BINRES_DATA_INFO *info, GX_GLYPH_HEADER *header)
508 {
509     GX_BINRES_READ_USHORT(header -> gx_glyph_header_magic_number, info -> gx_binres_root_address + info -> gx_binres_read_offset);
510     info -> gx_binres_read_offset += sizeof(USHORT);
511 
512     GX_BINRES_READ_USHORT(header -> gx_glyph_header_map_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
513     info -> gx_binres_read_offset += sizeof(USHORT);
514 
515     GX_BINRES_READ_ULONG(header -> gx_glyph_header_map_offset, info -> gx_binres_root_address + info -> gx_binres_read_offset);
516     info -> gx_binres_read_offset += sizeof(ULONG);
517 
518 	GX_BINRES_READ_USHORT(header -> gx_glyph_header_index, info -> gx_binres_root_address + info -> gx_binres_read_offset);
519     info -> gx_binres_read_offset += sizeof(USHORT);
520 
521     GX_BINRES_READ_SHORT(header -> gx_glyph_header_ascent, info -> gx_binres_root_address + info -> gx_binres_read_offset);
522     info -> gx_binres_read_offset += sizeof(SHORT);
523 
524     GX_BINRES_READ_SHORT(header -> gx_glyph_header_descent, info -> gx_binres_root_address + info -> gx_binres_read_offset);
525     info -> gx_binres_read_offset += sizeof(SHORT);
526 
527     GX_BINRES_READ_GX_UBYTE(header -> gx_glyph_header_advance, info -> gx_binres_root_address + info -> gx_binres_read_offset);
528     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
529 
530     GX_BINRES_READ_GX_BYTE(header -> gx_glyph_header_leading, info -> gx_binres_root_address + info -> gx_binres_read_offset);
531     info -> gx_binres_read_offset += sizeof(GX_BYTE);
532 
533     GX_BINRES_READ_GX_UBYTE(header -> gx_glyph_header_width, info -> gx_binres_root_address + info -> gx_binres_read_offset);
534     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
535 
536     GX_BINRES_READ_GX_UBYTE(header -> gx_glyph_header_height, info -> gx_binres_root_address + info -> gx_binres_read_offset);
537     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
538 
539     GX_BINRES_READ_ULONG(header -> gx_glyph_header_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
540     info -> gx_binres_read_offset += sizeof(ULONG);
541 
542     return GX_SUCCESS;
543 }
544 #endif
545 
546 
547 /**************************************************************************/
548 /*                                                                        */
549 /*  FUNCTION                                               RELEASE        */
550 /*                                                                        */
551 /*    _gx_binres_kerning_glyph_header_load                PORTABLE C      */
552 /*                                                           6.1          */
553 /*  AUTHOR                                                                */
554 /*                                                                        */
555 /*    Kenneth Maxwell, Microsoft Corporation                              */
556 /*                                                                        */
557 /*  DESCRIPTION                                                           */
558 /*                                                                        */
559 /*    This function reads glyph header from a binary data buffer.         */
560 /*                                                                        */
561 /*  INPUT                                                                 */
562 /*                                                                        */
563 /*    info                                  Binary read control block     */
564 /*    header                                Returned glyph header         */
565 /*                                                                        */
566 /*  OUTPUT                                                                */
567 /*                                                                        */
568 /*    Status                                Completion status             */
569 /*                                                                        */
570 /*  CALLS                                                                 */
571 /*                                                                        */
572 /*    None                                                                */
573 /*                                                                        */
574 /*  CALLED BY                                                             */
575 /*                                                                        */
576 /*    GUIX Internal Code                                                  */
577 /*                                                                        */
578 /*  RELEASE HISTORY                                                       */
579 /*                                                                        */
580 /*    DATE              NAME                      DESCRIPTION             */
581 /*                                                                        */
582 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
583 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
584 /*                                            removed use of memcpy,      */
585 /*                                            resulting in version 6.1    */
586 /*                                                                        */
587 /**************************************************************************/
588 #ifdef GX_FONT_KERNING_SUPPORT
589 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_kerning_glyph_header_load(GX_BINRES_DATA_INFO * info,GX_KERNING_GLYPH_HEADER * header)590 static UINT _gx_binres_kerning_glyph_header_load(GX_BINRES_DATA_INFO *info, GX_KERNING_GLYPH_HEADER *header)
591 {
592     _gx_binres_glyph_header_load(info, (GX_GLYPH_HEADER *)header);
593 
594     GX_BINRES_READ_USHORT(header -> gx_glyph_header_kerning_table_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
595     info -> gx_binres_read_offset += sizeof(USHORT);
596 
597     return GX_SUCCESS;
598 }
599 #endif
600 #endif
601 
602 /**************************************************************************/
603 /*                                                                        */
604 /*  FUNCTION                                               RELEASE        */
605 /*                                                                        */
606 /*    _gx_binres_pixelmap_header_load                     PORTABLE C      */
607 /*                                                           6.1          */
608 /*  AUTHOR                                                                */
609 /*                                                                        */
610 /*    Kenneth Maxwell, Microsoft Corporation                              */
611 /*                                                                        */
612 /*  DESCRIPTION                                                           */
613 /*                                                                        */
614 /*    This function reads pixelmap header from a binary data buffer.      */
615 /*                                                                        */
616 /*  INPUT                                                                 */
617 /*                                                                        */
618 /*    info                                  Binary read control block     */
619 /*    header                                Returned pixelmap header      */
620 /*                                                                        */
621 /*  OUTPUT                                                                */
622 /*                                                                        */
623 /*    Status                                Completion status             */
624 /*                                                                        */
625 /*  CALLS                                                                 */
626 /*                                                                        */
627 /*    None                                                                */
628 /*                                                                        */
629 /*  CALLED BY                                                             */
630 /*                                                                        */
631 /*    GUIX Internal Code                                                  */
632 /*                                                                        */
633 /*  RELEASE HISTORY                                                       */
634 /*                                                                        */
635 /*    DATE              NAME                      DESCRIPTION             */
636 /*                                                                        */
637 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
638 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
639 /*                                            removed use of memcpy,      */
640 /*                                            resulting in version 6.1    */
641 /*                                                                        */
642 /**************************************************************************/
643 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_pixelmap_header_load(GX_BINRES_DATA_INFO * info,GX_PIXELMAP_HEADER * header)644 static UINT _gx_binres_pixelmap_header_load(GX_BINRES_DATA_INFO *info, GX_PIXELMAP_HEADER *header)
645 {
646     GX_BINRES_READ_USHORT(header -> gx_pixelmap_header_magic_number, info -> gx_binres_root_address + info -> gx_binres_read_offset);
647     info -> gx_binres_read_offset += sizeof(USHORT);
648 
649     GX_BINRES_READ_USHORT(header -> gx_pixelmap_header_index, info -> gx_binres_root_address + info -> gx_binres_read_offset);
650     info -> gx_binres_read_offset += sizeof(USHORT);
651 
652     GX_BINRES_READ_GX_UBYTE(header -> gx_pixelmap_header_version_major, info -> gx_binres_root_address + info -> gx_binres_read_offset);
653     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
654 
655     GX_BINRES_READ_GX_UBYTE(header -> gx_pixelmap_header_version_minor, info -> gx_binres_root_address + info -> gx_binres_read_offset);
656     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
657 
658     GX_BINRES_READ_GX_UBYTE(header -> gx_pixelmap_header_flags, info -> gx_binres_root_address + info -> gx_binres_read_offset);
659     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
660 
661     GX_BINRES_READ_GX_UBYTE(header -> gx_pixelmap_header_format, info -> gx_binres_root_address + info -> gx_binres_read_offset);
662     info -> gx_binres_read_offset += sizeof(GX_UBYTE);
663 
664     GX_BINRES_READ_ULONG(header -> gx_pixelmap_header_map_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
665     info -> gx_binres_read_offset += sizeof(ULONG);
666 
667     GX_BINRES_READ_ULONG(header -> gx_pixelmap_header_aux_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
668     info -> gx_binres_read_offset += sizeof(ULONG);
669 
670     GX_BINRES_READ_ULONG(header -> gx_pixelmap_header_transparent_color, info -> gx_binres_root_address + info -> gx_binres_read_offset);
671     info -> gx_binres_read_offset += sizeof(GX_COLOR);
672 
673     GX_BINRES_READ_USHORT(header -> gx_pixelmap_header_width, info -> gx_binres_root_address + info -> gx_binres_read_offset);
674     info -> gx_binres_read_offset += sizeof(USHORT);
675 
676     GX_BINRES_READ_USHORT(header -> gx_pixelmap_header_height, info -> gx_binres_root_address + info -> gx_binres_read_offset);
677     info -> gx_binres_read_offset += sizeof(USHORT);
678 
679     GX_BINRES_READ_ULONG(header -> gx_pixelmap_header_data_size, info -> gx_binres_root_address + info -> gx_binres_read_offset);
680     info -> gx_binres_read_offset += sizeof(ULONG);
681 
682     GX_BINRES_READ_ULONG(header -> gx_pixelmap_header_data_offset, info -> gx_binres_root_address + info -> gx_binres_read_offset);
683     info -> gx_binres_read_offset += sizeof(ULONG);
684 
685     return GX_SUCCESS;
686 }
687 #endif
688 
689 /**************************************************************************/
690 /*                                                                        */
691 /*  FUNCTION                                               RELEASE        */
692 /*                                                                        */
693 /*    _gx_binres_theme_table_buffer_allocate              PORTABLE C      */
694 /*                                                           6.1          */
695 /*  AUTHOR                                                                */
696 /*                                                                        */
697 /*    Kenneth Maxwell, Microsoft Corporation                              */
698 /*                                                                        */
699 /*  DESCRIPTION                                                           */
700 /*                                                                        */
701 /*    This function allocates needed memory buffer for loading theme      */
702 /*    table.                                                              */
703 /*                                                                        */
704 /*  INPUT                                                                 */
705 /*                                                                        */
706 /*    info                                  Binary resource control block */
707 /*                                                                        */
708 /*  OUTPUT                                                                */
709 /*                                                                        */
710 /*    Status                                Completion status             */
711 /*                                                                        */
712 /*  CALLS                                                                 */
713 /*                                                                        */
714 /*    _gx_system_memory_allocator           Application defined memory    */
715 /*                                            allocation function         */
716 /*    _gx_binres_resource_header_load       Read resource header          */
717 /*    _gx_binres_theme_header_load          Read theme header             */
718 /*    _gx_binres_font_header_load           Read font header              */
719 /*    _gx_binres_page_header_load           Read font page header         */
720 /*                                                                        */
721 /*  CALLED BY                                                             */
722 /*                                                                        */
723 /*    GUIX Internal Code                                                  */
724 /*                                                                        */
725 /*  RELEASE HISTORY                                                       */
726 /*                                                                        */
727 /*    DATE              NAME                      DESCRIPTION             */
728 /*                                                                        */
729 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
730 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
731 /*                                            resulting in version 6.1    */
732 /*                                                                        */
733 /**************************************************************************/
734 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_theme_buffer_allocate(GX_BINRES_DATA_INFO * info,INT theme_id)735 static UINT _gx_binres_theme_buffer_allocate(GX_BINRES_DATA_INFO *info, INT theme_id)
736 {
737 GX_RESOURCE_HEADER res_header;
738 GX_THEME_HEADER    theme_header;
739 GX_FONT_HEADER     font_header;
740 GX_PAGE_HEADER     page_header;
741 USHORT             theme_index;
742 USHORT             font_index;
743 USHORT             page_index;
744 UINT               glyph_count;
745 UINT               read_offset = 0;
746 UINT               temp;
747 
748     /* Read resource header.  */
749     info -> gx_binres_read_offset = 0;
750 
751     _gx_binres_resource_header_load(info, &res_header);
752 
753     if (res_header.gx_resource_header_magic_number != GX_MAGIC_NUMBER)
754     {
755         return GX_INVALID_FORMAT;
756     }
757 
758     info -> gx_binres_buffer_size = 0;
759 
760     for (theme_index = 0; theme_index < res_header.gx_resource_header_theme_count; theme_index++)
761     {
762         _gx_binres_theme_header_load(info, &theme_header);
763 
764         if (theme_header.gx_theme_header_magic_number != GX_MAGIC_NUMBER)
765         {
766             return GX_INVALID_FORMAT;
767         }
768 
769         if (theme_index == theme_id)
770         {
771             info -> gx_binres_buffer_size = sizeof(GX_THEME);
772 
773             /* Color table buffer size.  */
774             if (theme_header.gx_theme_header_color_data_size)
775             {
776                 info -> gx_binres_read_offset += theme_header.gx_theme_header_color_data_size;
777             }
778 
779             /* Palette table buffer size.  */
780             if (theme_header.gx_theme_header_palette_data_size)
781             {
782                 info -> gx_binres_read_offset += theme_header.gx_theme_header_palette_data_size;
783             }
784 
785             /* Font table buffer size.  */
786             if (theme_header.gx_theme_header_font_data_size)
787             {
788                 /* Font count is USHORT type, overflow cannot occur. */
789                 info -> gx_binres_buffer_size += sizeof(GX_FONT *) * theme_header.gx_theme_header_font_count;
790 
791                 for (font_index = 0; font_index < theme_header.gx_theme_header_font_count; font_index++)
792                 {
793                     _gx_binres_font_header_load(info, &font_header);
794 
795                     if (font_header.gx_font_header_magic_number != GX_MAGIC_NUMBER)
796                     {
797                         return GX_INVALID_FORMAT;
798                     }
799 
800                     if (font_header.gx_font_header_data_offset)
801                     {
802                         /* The font data is not follow the header directly,
803                            the data offset gives the position where the font
804                            data located. */
805 
806                         /* Record current data offset. */
807                         read_offset = info -> gx_binres_read_offset;
808 
809                         /* Temporarily reset data offset of access font data. */
810                         info -> gx_binres_read_offset = font_header.gx_font_header_data_offset;
811 
812                         /* Load font header. */
813                         _gx_binres_font_header_load(info, &font_header);
814                     }
815 
816                     for (page_index = 0; page_index < font_header.gx_font_header_page_count; page_index++)
817                     {
818                         /* Load page header. */
819                         _gx_binres_page_header_load(info, &page_header);
820                         info -> gx_binres_read_offset += page_header.gx_page_header_data_size;
821 
822                         if (page_header.gx_page_header_magic_number != GX_MAGIC_NUMBER)
823                         {
824                             return GX_INVALID_FORMAT;
825                         }
826 #if defined(GX_EXTENDED_UNICODE_SUPPORT)
827                         if (page_header.gx_page_header_last_glyph > GX_MAX_GLYPH_CODE)
828                         {
829                             return GX_INVALID_FONT;
830                         }
831 #endif
832 
833                         /* Max glyph code is 0x10f000, overflow cannot occur. */
834                         glyph_count = (UINT)(page_header.gx_page_header_last_glyph - page_header.gx_page_header_first_glyph + 1);
835 
836                         /* Calculate size for loading font page. */
837                         temp = sizeof(GX_FONT);
838 
839                         /* Calculate size for loading glyphs. */
840                         if (page_header.gx_page_header_format & GX_FONT_FORMAT_COMPRESSED)
841                         {
842                             temp += sizeof(GX_COMPRESSED_GLYPH) * glyph_count;
843                         }
844 #if defined(GX_FONT_KERNING_SUPPORT)
845                         else if (page_header.gx_page_header_format & GX_FONT_FORMAT_KERNING)
846                         {
847                             temp += sizeof(GX_KERNING_GLYPH) * glyph_count;
848                         }
849 #endif
850                         else
851                         {
852                             temp += sizeof(GX_GLYPH) * glyph_count;
853                         }
854 
855                         GX_UTILITY_MATH_UINT_ADD(info -> gx_binres_buffer_size, temp, info -> gx_binres_buffer_size);
856                     }
857 
858                     if (read_offset)
859                     {
860                         /* Restore data offset. */
861                         info -> gx_binres_read_offset = read_offset;
862                         read_offset = 0;
863                     }
864                 }
865             }
866 
867             /* Pixelmap table buffer size.  */
868             if (theme_header.gx_theme_header_pixelmap_data_size)
869             {
870                 /* Pixelmap count is USHORT type, overflow can not occur. */
871                 temp = ((UINT)(theme_header.gx_theme_header_pixelmap_count + 1)) * sizeof(GX_PIXELMAP *);
872                 temp += sizeof(GX_PIXELMAP) * theme_header.gx_theme_header_pixelmap_count;
873 
874                 GX_UTILITY_MATH_UINT_ADD(info -> gx_binres_buffer_size, temp, info -> gx_binres_buffer_size);
875 
876                 info -> gx_binres_read_offset += theme_header.gx_theme_header_pixelmap_data_size;
877             }
878 
879             break;
880         }
881         else
882         {
883             info -> gx_binres_read_offset += theme_header.gx_theme_header_data_size;
884         }
885     }
886 
887     info -> gx_binres_buffer = (GX_UBYTE *)_gx_system_memory_allocator(info -> gx_binres_buffer_size);
888 
889     if (!info -> gx_binres_buffer)
890     {
891         return GX_SYSTEM_MEMORY_ERROR;
892     }
893 
894     memset(info -> gx_binres_buffer, 0, info -> gx_binres_buffer_size);
895     info -> gx_binres_buffer_index = 0;
896 
897     return GX_SUCCESS;
898 }
899 #endif
900 
901 /**************************************************************************/
902 /*                                                                        */
903 /*  FUNCTION                                               RELEASE        */
904 /*                                                                        */
905 /*    _gx_binres_glyphs_address_get                       PORTABLE C      */
906 /*                                                           6.1          */
907 /*  AUTHOR                                                                */
908 /*                                                                        */
909 /*    Kenneth Maxwell, Microsoft Corporation                              */
910 /*                                                                        */
911 /*  DESCRIPTION                                                           */
912 /*                                                                        */
913 /*    This function finds the memory address of specified glyph data from */
914 /*    a binary data buffer.                                               */
915 /*                                                                        */
916 /*  INPUT                                                                 */
917 /*                                                                        */
918 /*    info                                  Binary resource control block */
919 /*    glyph_count                           The number of glyphs that the */
920 /*                                            font page contains.         */
921 /*    returned_glyphs                       Returned glyph address        */
922 /*                                                                        */
923 /*  OUTPUT                                                                */
924 /*                                                                        */
925 /*    Status                                Completion status             */
926 /*                                                                        */
927 /*  CALLS                                                                 */
928 /*                                                                        */
929 /*    _gx_binres_glyph_header_load          Read glyph data header        */
930 /*                                                                        */
931 /*  CALLED BY                                                             */
932 /*                                                                        */
933 /*    GUIX Internal Code                                                  */
934 /*                                                                        */
935 /*  RELEASE HISTORY                                                       */
936 /*                                                                        */
937 /*    DATE              NAME                      DESCRIPTION             */
938 /*                                                                        */
939 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
940 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
941 /*                                            updated with binary         */
942 /*                                            resource layout change,     */
943 /*                                            resulting in version 6.1    */
944 /*                                                                        */
945 /**************************************************************************/
946 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_glyphs_address_get(GX_BINRES_DATA_INFO * info,USHORT glyph_count,GX_CONST GX_GLYPH ** returned_glyphs)947 static UINT _gx_binres_glyphs_address_get(GX_BINRES_DATA_INFO *info, USHORT glyph_count, GX_CONST GX_GLYPH **returned_glyphs)
948 {
949 GX_GLYPH_HEADER header;
950 GX_GLYPH       *glyphs;
951 USHORT          index = 0;
952 
953     glyphs = (GX_GLYPH *)(info -> gx_binres_buffer + info -> gx_binres_buffer_index);
954     info -> gx_binres_buffer_index += sizeof(GX_GLYPH) * glyph_count;
955 
956     for (index = 0; index < glyph_count; index++)
957     {
958         _gx_binres_glyph_header_load(info, &header);
959 
960         if (header.gx_glyph_header_magic_number != GX_MAGIC_NUMBER)
961         {
962             return GX_INVALID_FORMAT;
963         }
964 
965         glyphs[index].gx_glyph_advance = header.gx_glyph_header_advance;
966         glyphs[index].gx_glyph_ascent = header.gx_glyph_header_ascent;
967         glyphs[index].gx_glyph_descent = header.gx_glyph_header_descent;
968         glyphs[index].gx_glyph_height = header.gx_glyph_header_height;
969         glyphs[index].gx_glyph_leading = header.gx_glyph_header_leading;
970         glyphs[index].gx_glyph_width = header.gx_glyph_header_width;
971 
972         /* Read glyph data.  */
973         if (header.gx_glyph_header_data_size)
974         {
975             glyphs[index].gx_glyph_map = (GX_UBYTE *)(info -> gx_binres_root_address + header.gx_glyph_header_map_offset);
976             info -> gx_binres_read_offset += header.gx_glyph_header_data_size;
977         }
978         else
979         {
980             glyphs[index].gx_glyph_map = GX_NULL;
981         }
982     }
983 
984     *returned_glyphs = glyphs;
985 
986     return GX_SUCCESS;
987 }
988 #endif
989 
990 /**************************************************************************/
991 /*                                                                        */
992 /*  FUNCTION                                               RELEASE        */
993 /*                                                                        */
994 /*    _gx_binres_kerning_glyphs_address_get               PORTABLE C      */
995 /*                                                           6.1          */
996 /*  AUTHOR                                                                */
997 /*                                                                        */
998 /*    Kenneth Maxwell, Microsoft Corporation                              */
999 /*                                                                        */
1000 /*  DESCRIPTION                                                           */
1001 /*                                                                        */
1002 /*    This service gets the memory address of specified kerning glyph     */
1003 /*      from a binary data buffer.                                        */
1004 /*                                                                        */
1005 /*  INPUT                                                                 */
1006 /*                                                                        */
1007 /*    info                                  Binary resource control block */
1008 /*    glyph_count                           The number of glyphs that the */
1009 /*                                            font page contains.         */
1010 /*    returned_glyphs                       Returned glyph address        */
1011 /*                                                                        */
1012 /*  OUTPUT                                                                */
1013 /*                                                                        */
1014 /*    Status                                Completion status             */
1015 /*                                                                        */
1016 /*  CALLS                                                                 */
1017 /*                                                                        */
1018 /*    _gx_binres_kerning_glyph_header_load                                */
1019 /*                                                                        */
1020 /*  CALLED BY                                                             */
1021 /*                                                                        */
1022 /*    Application Code                                                    */
1023 /*    GUIX Internal Code                                                  */
1024 /*                                                                        */
1025 /*  RELEASE HISTORY                                                       */
1026 /*                                                                        */
1027 /*    DATE              NAME                      DESCRIPTION             */
1028 /*                                                                        */
1029 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1030 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1031 /*                                            updated with binary         */
1032 /*                                            resource layout change,     */
1033 /*                                            resulting in version 6.1    */
1034 /*                                                                        */
1035 /**************************************************************************/
1036 #ifdef GX_FONT_KERNING_SUPPORT
1037 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_kerning_glyphs_address_get(GX_BINRES_DATA_INFO * info,USHORT glyph_count,GX_CONST GX_KERNING_GLYPH ** returned_glyphs)1038 static UINT _gx_binres_kerning_glyphs_address_get(GX_BINRES_DATA_INFO *info, USHORT glyph_count,
1039                                                   GX_CONST GX_KERNING_GLYPH **returned_glyphs)
1040 {
1041 GX_KERNING_GLYPH_HEADER header;
1042 GX_KERNING_GLYPH       *glyphs;
1043 USHORT                  index = 0;
1044 
1045     glyphs = (GX_KERNING_GLYPH *)(info -> gx_binres_buffer + info -> gx_binres_buffer_index);
1046     info -> gx_binres_buffer_index += sizeof(GX_KERNING_GLYPH) * glyph_count;
1047 
1048     for (index = 0; index < glyph_count; index++)
1049     {
1050         _gx_binres_kerning_glyph_header_load(info, &header);
1051 
1052         if (header.gx_glyph_header_magic_number != GX_MAGIC_NUMBER)
1053         {
1054             return GX_INVALID_FORMAT;
1055         }
1056 
1057         glyphs[index].gx_glyph_advance = header.gx_glyph_header_advance;
1058         glyphs[index].gx_glyph_ascent = header.gx_glyph_header_ascent;
1059         glyphs[index].gx_glyph_descent = header.gx_glyph_header_descent;
1060         glyphs[index].gx_glyph_height = header.gx_glyph_header_height;
1061         glyphs[index].gx_glyph_leading = header.gx_glyph_header_leading;
1062         glyphs[index].gx_glyph_width = header.gx_glyph_header_width;
1063 
1064         /* Read glyph data.  */
1065         if (header.gx_glyph_header_data_size)
1066         {
1067             glyphs[index].gx_glyph_map = (GX_UBYTE *)(info -> gx_binres_root_address + header.gx_glyph_header_map_offset);
1068             info -> gx_binres_read_offset += header.gx_glyph_header_data_size;
1069         }
1070         else
1071         {
1072             glyphs[index].gx_glyph_map = GX_NULL;
1073         }
1074 
1075         /* Set glyph kerning table. */
1076         if (header.gx_glyph_header_kerning_table_size)
1077         {
1078             glyphs[index].gx_kerning_table = (GX_UBYTE *)(info -> gx_binres_root_address + info -> gx_binres_read_offset);
1079             info -> gx_binres_read_offset += header.gx_glyph_header_kerning_table_size;
1080         }
1081     }
1082 
1083     *returned_glyphs = glyphs;
1084 
1085     return GX_SUCCESS;
1086 }
1087 #endif
1088 #endif
1089 
1090 /**************************************************************************/
1091 /*                                                                        */
1092 /*  FUNCTION                                               RELEASE        */
1093 /*                                                                        */
1094 /*    _gx_binres_compressed_glyphs_address_get            PORTABLE C      */
1095 /*                                                           6.1          */
1096 /*  AUTHOR                                                                */
1097 /*                                                                        */
1098 /*    Kenneth Maxwell, Microsoft Corporation                              */
1099 /*                                                                        */
1100 /*  DESCRIPTION                                                           */
1101 /*                                                                        */
1102 /*    This service gets the memory address of specified compressed glyph  */
1103 /*    from a binary data buffer.                                          */
1104 /*                                                                        */
1105 /*  INPUT                                                                 */
1106 /*                                                                        */
1107 /*    info                                  Binary resource control block */
1108 /*    glyph_count                           The number of glyphs that the */
1109 /*                                            font page contains.         */
1110 /*    returned_glyphs                       Returned glyph address        */
1111 /*                                                                        */
1112 /*  OUTPUT                                                                */
1113 /*                                                                        */
1114 /*    Status                                Completion status             */
1115 /*                                                                        */
1116 /*  CALLS                                                                 */
1117 /*                                                                        */
1118 /*    _gx_binres_glyph_header_load          Read glyph data header        */
1119 /*                                                                        */
1120 /*  CALLED BY                                                             */
1121 /*                                                                        */
1122 /*    GUIX Internal Code                                                  */
1123 /*                                                                        */
1124 /*  RELEASE HISTORY                                                       */
1125 /*                                                                        */
1126 /*    DATE              NAME                      DESCRIPTION             */
1127 /*                                                                        */
1128 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1129 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1130 /*                                            updated with binary         */
1131 /*                                            resource layout change,     */
1132 /*                                            resulting in version 6.1    */
1133 /*                                                                        */
1134 /**************************************************************************/
1135 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_compressed_glyphs_address_get(GX_BINRES_DATA_INFO * info,USHORT glyph_count,GX_CONST GX_COMPRESSED_GLYPH ** returned_glyphs)1136 static UINT _gx_binres_compressed_glyphs_address_get(GX_BINRES_DATA_INFO *info, USHORT glyph_count,
1137                                                      GX_CONST GX_COMPRESSED_GLYPH **returned_glyphs)
1138 {
1139 GX_GLYPH_HEADER      header;
1140 GX_COMPRESSED_GLYPH *glyphs;
1141 USHORT               index = 0;
1142 
1143     glyphs = (GX_COMPRESSED_GLYPH *)(info -> gx_binres_buffer + info -> gx_binres_buffer_index);
1144     info -> gx_binres_buffer_index += sizeof(GX_COMPRESSED_GLYPH) * glyph_count;
1145 
1146     for (index = 0; index < glyph_count; index++)
1147     {
1148         _gx_binres_glyph_header_load(info, &header);
1149 
1150         if (header.gx_glyph_header_magic_number != GX_MAGIC_NUMBER)
1151         {
1152             return GX_INVALID_FORMAT;
1153         }
1154 
1155         glyphs[index].gx_glyph_advance = header.gx_glyph_header_advance;
1156         glyphs[index].gx_glyph_ascent = header.gx_glyph_header_ascent;
1157         glyphs[index].gx_glyph_descent = header.gx_glyph_header_descent;
1158         glyphs[index].gx_glyph_height = header.gx_glyph_header_height;
1159         glyphs[index].gx_glyph_leading = header.gx_glyph_header_leading;
1160         glyphs[index].gx_glyph_map_size = header.gx_glyph_header_map_size;
1161         glyphs[index].gx_glyph_width = header.gx_glyph_header_width;
1162 
1163         /* Read glyph data.  */
1164         if (header.gx_glyph_header_data_size)
1165         {
1166             glyphs[index].gx_glyph_map = (GX_UBYTE *)(info -> gx_binres_root_address + header.gx_glyph_header_map_offset);
1167             info -> gx_binres_read_offset += header.gx_glyph_header_data_size;
1168         }
1169         else
1170         {
1171             glyphs[index].gx_glyph_map = GX_NULL;
1172         }
1173     }
1174 
1175     *returned_glyphs = glyphs;
1176 
1177     return GX_SUCCESS;
1178 }
1179 #endif
1180 
1181 /**************************************************************************/
1182 /*                                                                        */
1183 /*  FUNCTION                                               RELEASE        */
1184 /*                                                                        */
1185 /*    _gx_binres_font_load                                PORTABLE C      */
1186 /*                                                           6.1          */
1187 /*  AUTHOR                                                                */
1188 /*                                                                        */
1189 /*    Kenneth Maxwell, Microsoft Corporation                              */
1190 /*                                                                        */
1191 /*  DESCRIPTION                                                           */
1192 /*                                                                        */
1193 /*    This service loads a font table from a binary data buffer.          */
1194 /*                                                                        */
1195 /*  INPUT                                                                 */
1196 /*                                                                        */
1197 /*    info                                  Binary resource control block */
1198 /*    page_count                            The number of pages that a    */
1199 /*                                            font contains.              */
1200 /*    return_font                           Returned font                 */
1201 /*                                                                        */
1202 /*  OUTPUT                                                                */
1203 /*                                                                        */
1204 /*    Status                                Completion status             */
1205 /*                                                                        */
1206 /*  CALLS                                                                 */
1207 /*                                                                        */
1208 /*    _gx_binres_page_header_load           Read font page header         */
1209 /*    _gx_binres_compressed_glyphs_read     Read compressed glyph data    */
1210 /*    _gx_binres_glyphs_read                Read glyph data               */
1211 /*                                                                        */
1212 /*  CALLED BY                                                             */
1213 /*                                                                        */
1214 /*    GUIX Internal Code                                                  */
1215 /*                                                                        */
1216 /*  RELEASE HISTORY                                                       */
1217 /*                                                                        */
1218 /*    DATE              NAME                      DESCRIPTION             */
1219 /*                                                                        */
1220 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1221 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1222 /*                                            resulting in version 6.1    */
1223 /*                                                                        */
1224 /**************************************************************************/
1225 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_font_load(GX_BINRES_DATA_INFO * info,USHORT page_count,GX_FONT ** return_font)1226 static UINT _gx_binres_font_load(GX_BINRES_DATA_INFO *info, USHORT page_count, GX_FONT **return_font)
1227 {
1228 UINT           status = GX_SUCCESS;
1229 GX_PAGE_HEADER header;
1230 GX_FONT       *font;
1231 GX_FONT       *head_page = GX_NULL;
1232 GX_FONT       *pre_page = GX_NULL;
1233 USHORT         index;
1234 USHORT         glyph_count;
1235 
1236     for (index = 0; index < page_count; index++)
1237     {
1238         /* Read page header.  */
1239         _gx_binres_page_header_load(info, &header);
1240 
1241         font = (GX_FONT *)(info -> gx_binres_buffer + info -> gx_binres_buffer_index);
1242         info -> gx_binres_buffer_index += sizeof(GX_FONT);
1243 
1244         font -> gx_font_baseline = header.gx_page_header_baseline;
1245         font -> gx_font_first_glyph = header.gx_page_header_first_glyph;
1246         font -> gx_font_format = header.gx_page_header_format;
1247         font -> gx_font_last_glyph = header.gx_page_header_last_glyph;
1248         font -> gx_font_line_height = header.gx_page_header_line_height;
1249         font -> gx_font_postspace = header.gx_page_header_postspace;
1250         font -> gx_font_prespace = header.gx_page_header_prespace;
1251 
1252         /* Read glyphs data.  */
1253         glyph_count = (USHORT)(font -> gx_font_last_glyph - font -> gx_font_first_glyph + 1);
1254 
1255         if (font -> gx_font_format & GX_FONT_FORMAT_COMPRESSED)
1256         {
1257             status = _gx_binres_compressed_glyphs_address_get(info, glyph_count, &font -> gx_font_glyphs.gx_font_compressed_glyphs);
1258         }
1259 #if defined(GX_FONT_KERNING_SUPPORT)
1260         else if (font -> gx_font_format & GX_FONT_FORMAT_KERNING)
1261         {
1262             status = _gx_binres_kerning_glyphs_address_get(info, glyph_count, &font -> gx_font_glyphs.gx_font_kerning_glyphs);
1263         }
1264 #endif /* GX_FONT_KERNING_SUPPORT */
1265         else
1266         {
1267             status = _gx_binres_glyphs_address_get(info, glyph_count, &font -> gx_font_glyphs.gx_font_normal_glyphs);
1268         }
1269 
1270         if (status != GX_SUCCESS)
1271         {
1272             break;
1273         }
1274 
1275         font -> gx_font_next_page = NULL;
1276 
1277         if (!head_page)
1278         {
1279             head_page = font;
1280         }
1281 
1282         if (pre_page)
1283         {
1284             pre_page -> gx_font_next_page = font;
1285         }
1286 
1287         pre_page = font;
1288     }
1289 
1290     *return_font = head_page;
1291 
1292     return status;
1293 }
1294 #endif
1295 /**************************************************************************/
1296 /*                                                                        */
1297 /*  FUNCTION                                               RELEASE        */
1298 /*                                                                        */
1299 /*    _gx_binres_color_table_load                         PORTABLE C      */
1300 /*                                                           6.1          */
1301 /*  AUTHOR                                                                */
1302 /*                                                                        */
1303 /*    Kenneth Maxwell, Microsoft Corporation                              */
1304 /*                                                                        */
1305 /*  DESCRIPTION                                                           */
1306 /*                                                                        */
1307 /*    This function loads a color table from a binary data buffer.        */
1308 /*                                                                        */
1309 /*  INPUT                                                                 */
1310 /*                                                                        */
1311 /*    info                                  Binary resource control block */
1312 /*    color_count                           The number of colors to read  */
1313 /*    returned_color_table                  Returned color table          */
1314 /*                                                                        */
1315 /*  OUTPUT                                                                */
1316 /*                                                                        */
1317 /*    Status                                Completion status             */
1318 /*                                                                        */
1319 /*  CALLS                                                                 */
1320 /*                                                                        */
1321 /*    _gx_binres_color_header_load          Read color data header        */
1322 /*                                                                        */
1323 /*  CALLED BY                                                             */
1324 /*                                                                        */
1325 /*    GUIX Internal Code                                                  */
1326 /*                                                                        */
1327 /*  RELEASE HISTORY                                                       */
1328 /*                                                                        */
1329 /*    DATE              NAME                      DESCRIPTION             */
1330 /*                                                                        */
1331 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1332 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1333 /*                                            resulting in version 6.1    */
1334 /*                                                                        */
1335 /**************************************************************************/
1336 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_color_table_load(GX_BINRES_DATA_INFO * info,USHORT color_count,GX_COLOR ** returned_color_table)1337 static UINT _gx_binres_color_table_load(GX_BINRES_DATA_INFO *info, USHORT color_count, GX_COLOR **returned_color_table)
1338 {
1339 GX_COLOR_HEADER header;
1340 GX_COLOR       *color_table = GX_NULL;
1341 
1342     if (!color_count)
1343     {
1344         return GX_SUCCESS;
1345     }
1346 
1347     /* Read color table header.  */
1348     _gx_binres_color_header_load(info, &header);
1349 
1350     if (header.gx_color_header_magic_number != GX_MAGIC_NUMBER)
1351     {
1352         return GX_INVALID_FORMAT;
1353     }
1354 
1355     color_table = (GX_COLOR *)(info -> gx_binres_root_address + info -> gx_binres_read_offset);
1356     info -> gx_binres_read_offset += header.gx_color_header_data_size;
1357 
1358     *returned_color_table = color_table;
1359 
1360     return GX_SUCCESS;
1361 }
1362 #endif
1363 
1364 /**************************************************************************/
1365 /*                                                                        */
1366 /*  FUNCTION                                               RELEASE        */
1367 /*                                                                        */
1368 /*    _gx_binres_palette_table_load                       PORTABLE C      */
1369 /*                                                           6.1          */
1370 /*  AUTHOR                                                                */
1371 /*                                                                        */
1372 /*    Kenneth Maxwell, Microsoft Corporation                              */
1373 /*                                                                        */
1374 /*  DESCRIPTION                                                           */
1375 /*                                                                        */
1376 /*    This function loads a palette table from a binary data buffer.      */
1377 /*                                                                        */
1378 /*  INPUT                                                                 */
1379 /*                                                                        */
1380 /*    info                                  Binary resource control block */
1381 /*    color_count                           The number of colors to read  */
1382 /*    returned_palette_table                Returned palette table        */
1383 /*                                                                        */
1384 /*  OUTPUT                                                                */
1385 /*                                                                        */
1386 /*    Status                                Completion status             */
1387 /*                                                                        */
1388 /*  CALLS                                                                 */
1389 /*                                                                        */
1390 /*    _gx_binres_palette_header_load        Read palette data header      */
1391 /*                                                                        */
1392 /*  CALLED BY                                                             */
1393 /*                                                                        */
1394 /*    GUIX Internal Code                                                  */
1395 /*                                                                        */
1396 /*  RELEASE HISTORY                                                       */
1397 /*                                                                        */
1398 /*    DATE              NAME                      DESCRIPTION             */
1399 /*                                                                        */
1400 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1401 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1402 /*                                            resulting in version 6.1    */
1403 /*                                                                        */
1404 /**************************************************************************/
1405 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_palette_table_load(GX_BINRES_DATA_INFO * info,USHORT color_count,GX_COLOR ** returned_palette_table)1406 static UINT _gx_binres_palette_table_load(GX_BINRES_DATA_INFO *info, USHORT color_count, GX_COLOR **returned_palette_table)
1407 {
1408 GX_PALETTE_HEADER header;
1409 GX_COLOR         *palette_table = GX_NULL;
1410 
1411     if (!color_count)
1412     {
1413         return GX_SUCCESS;
1414     }
1415 
1416     /* Read palette table header.  */
1417     _gx_binres_palette_header_load(info, &header);
1418 
1419     if (header.gx_palette_header_magic_number != GX_MAGIC_NUMBER)
1420     {
1421         return GX_INVALID_FORMAT;
1422     }
1423 
1424     palette_table = (GX_COLOR *)(info -> gx_binres_root_address + info -> gx_binres_read_offset);
1425     info -> gx_binres_read_offset += header.gx_palette_header_data_size;
1426 
1427     *returned_palette_table = palette_table;
1428 
1429     return GX_SUCCESS;
1430 }
1431 #endif
1432 
1433 /**************************************************************************/
1434 /*                                                                        */
1435 /*  FUNCTION                                               RELEASE        */
1436 /*                                                                        */
1437 /*    _gx_binres_font_table_load                          PORTABLE C      */
1438 /*                                                           6.1          */
1439 /*  AUTHOR                                                                */
1440 /*                                                                        */
1441 /*    Kenneth Maxwell, Microsoft Corporation                              */
1442 /*                                                                        */
1443 /*  DESCRIPTION                                                           */
1444 /*                                                                        */
1445 /*    This function loads a font table from resource data memory.         */
1446 /*                                                                        */
1447 /*  INPUT                                                                 */
1448 /*                                                                        */
1449 /*    info                                  Binary resource control block */
1450 /*    table_size                            Font table size               */
1451 /*    returned_font_table                   Returned font table           */
1452 /*                                                                        */
1453 /*  OUTPUT                                                                */
1454 /*                                                                        */
1455 /*    Status                                Completion status             */
1456 /*                                                                        */
1457 /*  CALLS                                                                 */
1458 /*                                                                        */
1459 /*    _gx_binres_font_header_load           Read font header              */
1460 /*    _gx_binres_font_read                  Read font data                */
1461 /*                                                                        */
1462 /*  CALLED BY                                                             */
1463 /*                                                                        */
1464 /*    GUIX Internal Code                                                  */
1465 /*                                                                        */
1466 /*  RELEASE HISTORY                                                       */
1467 /*                                                                        */
1468 /*    DATE              NAME                      DESCRIPTION             */
1469 /*                                                                        */
1470 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1471 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1472 /*                                            resulting in version 6.1    */
1473 /*                                                                        */
1474 /**************************************************************************/
1475 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_font_table_load(GX_BINRES_DATA_INFO * info,USHORT table_size,GX_FONT *** returned_font_table)1476 static UINT _gx_binres_font_table_load(GX_BINRES_DATA_INFO *info, USHORT table_size, GX_FONT ***returned_font_table)
1477 {
1478 UINT           status = GX_SUCCESS;
1479 GX_FONT_HEADER header;
1480 GX_FONT      **font_table = GX_NULL;
1481 USHORT         index;
1482 UINT           read_offset = 0;
1483 
1484     if (!table_size)
1485     {
1486         return status;
1487     }
1488 
1489     font_table = (GX_FONT **)(info -> gx_binres_buffer + info -> gx_binres_buffer_index);
1490     info -> gx_binres_buffer_index += sizeof(GX_FONT *) * table_size;
1491 
1492     for (index = 0; index < table_size; index++)
1493     {
1494         /* Read font header.  */
1495         _gx_binres_font_header_load(info, &header);
1496 
1497         if (header.gx_font_header_deault)
1498         {
1499             switch (header.gx_font_header_bits)
1500             {
1501             case 1:
1502                 font_table[index] = (GX_FONT *)&_gx_system_font_mono;
1503                 break;
1504 
1505             case 4:
1506                 font_table[index] = (GX_FONT *)&_gx_system_font_4bpp;
1507                 break;
1508 
1509             case 8:
1510                 font_table[index] = (GX_FONT *)&_gx_system_font_8bpp;
1511                 break;
1512             }
1513         }
1514         else
1515         {
1516             if (header.gx_font_header_data_offset)
1517             {
1518                 /* The font data is not follow the header directly,
1519                    the data offset gives the position where the font
1520                    data located. */
1521 
1522                 /* Record current data offset. */
1523                 read_offset = info -> gx_binres_read_offset;
1524 
1525                 /* Temporarily reset data offset to access font data. */
1526                 info -> gx_binres_read_offset = header.gx_font_header_data_offset;
1527 
1528                 /* Read font header. */
1529                 _gx_binres_font_header_load(info, &header);
1530             }
1531 
1532             status = _gx_binres_font_load(info, header.gx_font_header_page_count, &font_table[index]);
1533 
1534             if (status != GX_SUCCESS)
1535             {
1536                 break;
1537             }
1538 
1539             if (read_offset)
1540             {
1541                 /* Restore data offset. */
1542                 info -> gx_binres_read_offset = read_offset;
1543                 read_offset = 0;
1544             }
1545         }
1546     }
1547 
1548     *returned_font_table = font_table;
1549 
1550     return status;
1551 }
1552 #endif
1553 
1554 /**************************************************************************/
1555 /*                                                                        */
1556 /*  FUNCTION                                               RELEASE        */
1557 /*                                                                        */
1558 /*    _gx_binres_pixelmap_table_load                      PORTABLE C      */
1559 /*                                                           6.1          */
1560 /*  AUTHOR                                                                */
1561 /*                                                                        */
1562 /*    Kenneth Maxwell, Microsoft Corporation                              */
1563 /*                                                                        */
1564 /*  DESCRIPTION                                                           */
1565 /*                                                                        */
1566 /*    This function loads a pixelmap table from resource data memory.     */
1567 /*                                                                        */
1568 /*  INPUT                                                                 */
1569 /*                                                                        */
1570 /*    info                                  Binary resource control block */
1571 /*    table_size                            Pixelmap table size           */
1572 /*    returned_pixelmp_table                Returned pixelmap table       */
1573 /*                                                                        */
1574 /*  OUTPUT                                                                */
1575 /*                                                                        */
1576 /*    Status                                Completion status             */
1577 /*                                                                        */
1578 /*  CALLS                                                                 */
1579 /*                                                                        */
1580 /*    _gx_binres_pixelmap_header_load       Read pixelmap header          */
1581 /*                                                                        */
1582 /*  CALLED BY                                                             */
1583 /*                                                                        */
1584 /*    GUIX Internal Code                                                  */
1585 /*                                                                        */
1586 /*  RELEASE HISTORY                                                       */
1587 /*                                                                        */
1588 /*    DATE              NAME                      DESCRIPTION             */
1589 /*                                                                        */
1590 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1591 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1592 /*                                            resulting in version 6.1    */
1593 /*                                                                        */
1594 /**************************************************************************/
1595 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_pixelmap_table_load(GX_BINRES_DATA_INFO * info,USHORT table_size,GX_PIXELMAP *** returned_pixelmap_table)1596 static UINT _gx_binres_pixelmap_table_load(GX_BINRES_DATA_INFO *info, USHORT table_size, GX_PIXELMAP ***returned_pixelmap_table)
1597 {
1598 UINT               status = GX_SUCCESS;
1599 GX_PIXELMAP_HEADER header;
1600 GX_PIXELMAP      **pixelmap_table = GX_NULL;
1601 USHORT             index;
1602 ULONG              size;
1603 GX_BOOL            keep_looping;
1604 UINT               read_offset = 0;
1605 
1606     if (table_size <= 1)
1607     {
1608         return GX_SUCCESS;
1609     }
1610 
1611     pixelmap_table = (GX_PIXELMAP **)(info -> gx_binres_buffer + info -> gx_binres_buffer_index);
1612     info -> gx_binres_buffer_index += sizeof(GX_PIXELMAP *) * table_size;
1613 
1614     for (index = 1; index < table_size; index++)
1615     {
1616         /* Read pixelmap header.  */
1617         _gx_binres_pixelmap_header_load(info, &header);
1618 
1619         if (header.gx_pixelmap_header_magic_number != GX_MAGIC_NUMBER)
1620         {
1621             return GX_INVALID_FORMAT;
1622         }
1623 
1624         if (header.gx_pixelmap_header_data_offset)
1625         {
1626             /* The pixelmap data is not follow the header directly,
1627                the data offset gives the position where the pixelmap
1628                data located. */
1629 
1630             /* Record current data offset. */
1631             read_offset = info -> gx_binres_read_offset;
1632 
1633             /* Temporarily reset data offset to access pixelmap data. */
1634             info -> gx_binres_read_offset = header.gx_pixelmap_header_data_offset;
1635 
1636             /* Read pixelmap header. */
1637             _gx_binres_pixelmap_header_load(info, &header);
1638         }
1639 
1640         keep_looping = GX_TRUE;
1641 
1642         while (keep_looping)
1643         {
1644             keep_looping = GX_FALSE;
1645 
1646             /* Allocate memory for pixelmap.  */
1647             pixelmap_table[index] = (GX_PIXELMAP *)(info -> gx_binres_buffer + info -> gx_binres_buffer_index);
1648             info -> gx_binres_buffer_index += sizeof(GX_PIXELMAP);
1649 
1650             switch (index)
1651             {
1652             case GX_PIXELMAP_RADIO_ON_ID:
1653             case GX_PIXELMAP_RADIO_OFF_ID:
1654             case GX_PIXELMAP_CHECKBOX_ON_ID:
1655             case GX_PIXELMAP_CHECKBOX_OFF_ID:
1656                 if (index != header.gx_pixelmap_header_index)
1657                 {
1658                     pixelmap_table[index++] = GX_NULL;
1659                     keep_looping = GX_TRUE;
1660                 }
1661             }
1662         }
1663 
1664         pixelmap_table[index] -> gx_pixelmap_aux_data_size = header.gx_pixelmap_header_aux_data_size;
1665         pixelmap_table[index] -> gx_pixelmap_data_size = header.gx_pixelmap_header_map_size;
1666         pixelmap_table[index] -> gx_pixelmap_flags = header.gx_pixelmap_header_flags;
1667         pixelmap_table[index] -> gx_pixelmap_format = header.gx_pixelmap_header_format;
1668         pixelmap_table[index] -> gx_pixelmap_width = (GX_VALUE)header.gx_pixelmap_header_width;
1669         pixelmap_table[index] -> gx_pixelmap_height = (GX_VALUE)header.gx_pixelmap_header_height;
1670         pixelmap_table[index] -> gx_pixelmap_transparent_color = header.gx_pixelmap_header_transparent_color;
1671         pixelmap_table[index] -> gx_pixelmap_version_major = header.gx_pixelmap_header_version_major;
1672         pixelmap_table[index] -> gx_pixelmap_version_minor = header.gx_pixelmap_header_version_minor;
1673 
1674         /* Skip padding bytes. */
1675         info -> gx_binres_read_offset = (info -> gx_binres_read_offset + 3) & (~0x03UL);
1676 
1677         /* Read pixelmap data.  */
1678         size = pixelmap_table[index] -> gx_pixelmap_data_size;
1679         if (size)
1680         {
1681             pixelmap_table[index] -> gx_pixelmap_data = (GX_UBYTE *)(info -> gx_binres_root_address + info -> gx_binres_read_offset);
1682             info -> gx_binres_read_offset += size;
1683         }
1684 
1685         /* Read pixelmap aux data.  */
1686         size = pixelmap_table[index] -> gx_pixelmap_aux_data_size;
1687         if (size)
1688         {
1689             pixelmap_table[index] -> gx_pixelmap_aux_data = (GX_UBYTE *)(info -> gx_binres_root_address + info -> gx_binres_read_offset);
1690             info -> gx_binres_read_offset += size;
1691         }
1692 
1693         if (read_offset)
1694         {
1695             /* Restore data offset. */
1696             info -> gx_binres_read_offset = read_offset;
1697             read_offset = 0;
1698         }
1699     }
1700 
1701     *returned_pixelmap_table = pixelmap_table;
1702 
1703     return status;
1704 }
1705 #endif
1706 
1707 /**************************************************************************/
1708 /*                                                                        */
1709 /*  FUNCTION                                               RELEASE        */
1710 /*                                                                        */
1711 /*    _gx_binres_theme_load                               PORTABLE C      */
1712 /*                                                           6.1          */
1713 /*  AUTHOR                                                                */
1714 /*                                                                        */
1715 /*    Kenneth Maxwell, Microsoft Corporation                              */
1716 /*                                                                        */
1717 /*  DESCRIPTION                                                           */
1718 /*                                                                        */
1719 /*    This service loads a theme table from a resource data memory.       */
1720 /*                                                                        */
1721 /*  INPUT                                                                 */
1722 /*                                                                        */
1723 /*    root_address                          Root address of binary        */
1724 /*                                            resource data               */
1725 /*    theme_id                              The indentifier of the theme  */
1726 /*    returned_theme                        Pointer to loaded theme       */
1727 /*                                                                        */
1728 /*  OUTPUT                                                                */
1729 /*                                                                        */
1730 /*    Status                                Completion status             */
1731 /*                                                                        */
1732 /*  CALLS                                                                 */
1733 /*                                                                        */
1734 /*    _gx_binres_theme_buffer_allocate      Allocate needed buffer for    */
1735 /*                                            loading theme table         */
1736 /*    _gx_binres_resource_header_load       Read resource header          */
1737 /*    _gx_binres_theme_header_load          Read theme header             */
1738 /*    _gx_binres_color_table_load           Load color table              */
1739 /*    _gx_binres_palette_table_load         Load palette table            */
1740 /*    _gx_binres_font_table_load            Load font table               */
1741 /*    _gx_binres_pixelmap_table_load        Load pixelmap table           */
1742 /*    _gx_system_memory_free                Memory free function          */
1743 /*                                                                        */
1744 /*  CALLED BY                                                             */
1745 /*                                                                        */
1746 /*    Application Code                                                    */
1747 /*                                                                        */
1748 /*  RELEASE HISTORY                                                       */
1749 /*                                                                        */
1750 /*    DATE              NAME                      DESCRIPTION             */
1751 /*                                                                        */
1752 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
1753 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
1754 /*                                            resulting in version 6.1    */
1755 /*                                                                        */
1756 /**************************************************************************/
1757 #ifdef GX_BINARY_RESOURCE_SUPPORT
_gx_binres_theme_load(GX_UBYTE * root_address,INT theme_id,GX_THEME ** returned_theme)1758 UINT _gx_binres_theme_load(GX_UBYTE *root_address, INT theme_id, GX_THEME **returned_theme)
1759 {
1760 UINT                status;
1761 GX_BINRES_DATA_INFO info;
1762 GX_RESOURCE_HEADER  header;
1763 GX_THEME_HEADER     theme_header;
1764 GX_THEME           *theme;
1765 INT                 index;
1766 
1767     memset(&info, 0, sizeof(GX_BINRES_DATA_INFO));
1768     memset(&theme_header, 0, sizeof(GX_THEME_HEADER));
1769 
1770     info.gx_binres_root_address = (GX_UBYTE *)root_address;
1771 
1772     /* Allocate memory that needed for theme table.  */
1773     status = _gx_binres_theme_buffer_allocate(&info, theme_id);
1774 
1775     /* Read binary resource header.  */
1776 
1777     if (status == GX_SUCCESS)
1778     {
1779         info.gx_binres_read_offset = 0;
1780         status = _gx_binres_resource_header_load(&info, &header);
1781     }
1782 
1783     /* Read theme table.  */
1784     if (status == GX_SUCCESS)
1785     {
1786         for (index = 0;; index++)
1787         {
1788 
1789             /* Read theme header.  */
1790             _gx_binres_theme_header_load(&info, &theme_header);
1791 
1792             if (index == theme_id)
1793             {
1794                 theme = (GX_THEME *)(info.gx_binres_buffer + info.gx_binres_buffer_index);
1795                 info.gx_binres_buffer_index += sizeof(GX_THEME);
1796 
1797                 theme -> theme_color_table_size = theme_header.gx_theme_header_color_count;
1798                 theme -> theme_palette_size = theme_header.gx_theme_header_palette_count;
1799                 theme -> theme_font_table_size = theme_header.gx_theme_header_font_count;
1800                 theme -> theme_pixelmap_table_size = (USHORT)(theme_header.gx_theme_header_pixelmap_count + 1);
1801                 theme -> theme_vertical_scrollbar_appearance = theme_header.gx_theme_header_vscroll_appearance;
1802                 theme -> theme_horizontal_scrollbar_appearance = theme_header.gx_theme_header_hscroll_appearance;
1803                 theme -> theme_vertical_scroll_style = theme_header.gx_theme_header_hscroll_style;
1804                 theme -> theme_horizontal_scroll_style = theme_header.gx_theme_header_hscroll_style;
1805 
1806                 /* Read color table.  */
1807                 status = _gx_binres_color_table_load(&info,
1808                                                      theme_header.gx_theme_header_color_count,
1809                                                      &theme -> theme_color_table);
1810 
1811                 /* Read palette table.  */
1812                 if ((status == GX_SUCCESS) && theme_header.gx_theme_header_palette_data_size)
1813                 {
1814                     status = _gx_binres_palette_table_load(&info,
1815                                                            theme_header.gx_theme_header_palette_count,
1816                                                            &theme -> theme_palette);
1817                 }
1818 
1819                 /* Read font table.  */
1820                 if ((status == GX_SUCCESS) && theme_header.gx_theme_header_font_data_size)
1821                 {
1822                     status = _gx_binres_font_table_load(&info,
1823                                                         theme_header.gx_theme_header_font_count,
1824                                                         &theme -> theme_font_table);
1825                 }
1826 
1827                 /* Read pixelmap table.  */
1828                 if ((status == GX_SUCCESS) && theme_header.gx_theme_header_pixelmap_data_size)
1829                 {
1830                     status = _gx_binres_pixelmap_table_load(&info,
1831                                                             (USHORT)(theme_header.gx_theme_header_pixelmap_count + 1),
1832                                                             &theme -> theme_pixelmap_table);
1833                 }
1834 
1835                 if (status == GX_SUCCESS)
1836                 {
1837                     *returned_theme = theme;
1838                 }
1839                 else
1840                 {
1841                     /* Free allocated buffer if theme loading failed.  */
1842                     _gx_system_memory_free(info.gx_binres_buffer);
1843 
1844                     *returned_theme = GX_NULL;
1845                 }
1846 
1847                 break;
1848             }
1849             else
1850             {
1851                 info.gx_binres_read_offset += theme_header.gx_theme_header_data_size;
1852             }
1853         }
1854     }
1855 
1856     return status;
1857 }
1858 #endif
1859 
1860