GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_binres_font_load.c Lines: 14 17 82.4 %
Date: 2026-03-06 19:21:09 Branches: 4 6 66.7 %

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