1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** GUIX Component */
16 /** */
17 /** Binres Loader Management (Binres Loader) */
18 /** */
19 /**************************************************************************/
20
21 #define GX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "gx_api.h"
27 #include "gx_binres_loader.h"
28 #include "gx_utility.h"
29
30 /**************************************************************************/
31 /* */
32 /* FUNCTION RELEASE */
33 /* */
34 /* _gx_binres_font_load PORTABLE C */
35 /* 6.3.0 */
36 /* AUTHOR */
37 /* */
38 /* Ting Zhu, Microsoft Corporation */
39 /* */
40 /* DESCRIPTION */
41 /* */
42 /* This service loads a font from a resource data memory. */
43 /* */
44 /* INPUT */
45 /* */
46 /* root_address Pointer to the binary data */
47 /* memory */
48 /* font_index Resource index of the font */
49 /* to be loaded */
50 /* buffer Pointer to the buffer to */
51 /* store the loaded font */
52 /* buffer_size Size of the buffer. It will */
53 /* be overwritten with the */
54 /* required buffer size if the */
55 /* input buffer size is */
56 /* insufficient */
57 /* */
58 /* OUTPUT */
59 /* */
60 /* Status Completion status */
61 /* */
62 /* CALLS */
63 /* */
64 /* _gx_binres_standalone_resource_seek Locate the resource data */
65 /* _gx_binres_font_buffer_size_get Get the required font buffer */
66 /* size */
67 /* _gx_binres_one_font_load Load one font */
68 /* */
69 /* CALLED BY */
70 /* */
71 /* Application Code */
72 /* */
73 /* RELEASE HISTORY */
74 /* */
75 /* DATE NAME DESCRIPTION */
76 /* */
77 /* 10-31-2023 Ting Zhu Initial Version 6.3.0 */
78 /* */
79 /**************************************************************************/
_gx_binres_font_load(GX_UBYTE * root_address,UINT font_index,GX_UBYTE * buffer,ULONG * buffer_size)80 UINT _gx_binres_font_load(GX_UBYTE *root_address, UINT font_index, GX_UBYTE *buffer, ULONG *buffer_size)
81 {
82 UINT status = GX_SUCCESS;
83 GX_BINRES_DATA_INFO info;
84 UINT required_size;
85
86 /* file format
87 +--------+
88 | | <-- represents one bytes
89 +--------+
90
91 |+========+
92 | | <-- represents a variable number of bytes
93 |+========+
94
95 |+--------+--------+--------+--------+
96 | magic number | resource count |
97 |+--------+--------+--------+--------+
98 |+--------+--------+--------+--------+
99 | resource offset |
100 |+--------+--------+--------+--------+
101 |+--------+--------+--------+--------+
102 | ... |
103 |+--------+--------+--------+--------+
104 |+===================================+
105 | resource data |
106 |+===================================+
107 */
108
109 memset(&info, 0, sizeof(GX_BINRES_DATA_INFO));
110
111 info.gx_binres_root_address = (GX_UBYTE *)root_address;
112 info.gx_binres_buffer = (GX_UBYTE *)buffer;
113 info.gx_binres_buffer_size = *buffer_size;
114
115 status = _gx_binres_standalone_resource_seek(&info, font_index);
116
117 if (status != GX_SUCCESS)
118 {
119 return status;
120 }
121
122 status = _gx_binres_font_buffer_size_get(&info, &required_size, GX_TRUE);
123
124 if (status != GX_SUCCESS)
125 {
126 return status;
127 }
128
129 if (required_size > *buffer_size)
130 {
131 *buffer_size = required_size;
132 return GX_INVALID_MEMORY_SIZE;
133 }
134
135 status = _gx_binres_one_font_load(&info, GX_NULL);
136
137 return status;
138 }
139
140