GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_canvas_rotated_text_draw.c Lines: 33 33 100.0 %
Date: 2024-12-05 08:52:37 Branches: 16 16 100.0 %

Line Branch Exec Source
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
/**   Canvas Management (Canvas)                                          */
18
/**                                                                       */
19
/**************************************************************************/
20
21
#define GX_SOURCE_CODE
22
23
/* Include necessary system files.  */
24
25
#include "gx_api.h"
26
#include "gx_system.h"
27
#include "gx_utility.h"
28
#include "gx_canvas.h"
29
30
/**************************************************************************/
31
/*                                                                        */
32
/*  FUNCTION                                               RELEASE        */
33
/*                                                                        */
34
/*    _gx_canvas_rotated_text_draw                        PORTABLE C      */
35
/*                                                           6.1          */
36
/*  AUTHOR                                                                */
37
/*                                                                        */
38
/*    Kenneth Maxwell, Microsoft Corporation                              */
39
/*                                                                        */
40
/*  DESCRIPTION (deprecated)                                              */
41
/*                                                                        */
42
/*    This function draws rotated text.                                   */
43
/*    This function is superseded by gx_canvas_rotated_text_draw_ext()    */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    text                                  Pointer to string             */
48
/*    xcenter                               Center point for text drawing */
49
/*    ycenter                               Center point for text drawing */
50
/*    angle                                 Angle at which to rotate text */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    status                                Completion status             */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_utility_string_length_check       Calculate string length       */
59
/*    _gx_canvas_rotated_text_draw_ext      Extended rotated text draw    */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    Application Software                                                */
64
/*                                                                        */
65
/*  RELEASE HISTORY                                                       */
66
/*                                                                        */
67
/*    DATE              NAME                      DESCRIPTION             */
68
/*                                                                        */
69
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
70
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
71
/*                                            resulting in version 6.1    */
72
/*                                                                        */
73
/**************************************************************************/
74
#if defined(GX_ENABLE_DEPRECATED_STRING_API)
75
6
UINT _gx_canvas_rotated_text_draw(GX_CONST GX_CHAR *text,
76
                                  GX_VALUE xcenter,
77
                                  GX_VALUE ycenter,
78
                                  INT angle)
79
{
80
GX_STRING string;
81
UINT      status;
82
83
6
    string.gx_string_ptr = text;
84
85
    /* Calcualte text length. */
86
6
    status = _gx_utility_string_length_check(text, &string.gx_string_length, GX_MAX_STRING_LENGTH);
87
6
    if (status != GX_SUCCESS)
88
    {
89
1
        return status;
90
    }
91
92
5
    status = _gx_canvas_rotated_text_draw_ext(&string, xcenter, ycenter, angle);
93
94
5
    return status;
95
}
96
#endif
97
98
/**************************************************************************/
99
/*                                                                        */
100
/*  FUNCTION                                               RELEASE        */
101
/*                                                                        */
102
/*    _gx_canvas_rotated_text_draw_ext                    PORTABLE C      */
103
/*                                                           6.1.7        */
104
/*  AUTHOR                                                                */
105
/*                                                                        */
106
/*    Kenneth Maxwell, Microsoft Corporation                              */
107
/*                                                                        */
108
/*  DESCRIPTION                                                           */
109
/*                                                                        */
110
/*    This function draws rotated text.                                   */
111
/*                                                                        */
112
/*  INPUT                                                                 */
113
/*                                                                        */
114
/*    text                                  Pointer to string             */
115
/*    xcenter                               Center point for text drawing */
116
/*    ycenter                               Center point for text drawing */
117
/*    angle                                 Angle at which to rotate text */
118
/*                                                                        */
119
/*  OUTPUT                                                                */
120
/*                                                                        */
121
/*    status                                Completion status             */
122
/*                                                                        */
123
/*  CALLS                                                                 */
124
/*                                                                        */
125
/*    _gx_system_string_width_get_ext       Get width of the string in    */
126
/*                                           pixels                       */
127
/*    _gx_canvas_text_draw                  Draw glyphs on canvas         */
128
/*    _gx_utility_string_to_alphamap        Convert string to alpha-map   */
129
/*    _gx_utiity_pixelmap_rotate            Rotate alphaap to desired     */
130
/*                                           angle                        */
131
/*    _gx_canvas_pixelmap_draw              Draw text alphamap            */
132
/*    _gx_system_memory_free                Free memory used for rotated  */
133
/*                                           alphamap and canvas          */
134
/*                                                                        */
135
/*  CALLED BY                                                             */
136
/*                                                                        */
137
/*    Application Software                                                */
138
/*                                                                        */
139
/*  RELEASE HISTORY                                                       */
140
/*                                                                        */
141
/*    DATE              NAME                      DESCRIPTION             */
142
/*                                                                        */
143
/*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
144
/*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
145
/*                                            resulting in version 6.1    */
146
/*  06-02-2021     Kenneth Maxwell          Modified comment(s),          */
147
/*                                            rename RENESAS_DAVE2D       */
148
/*                                            support conditional,        */
149
/*                                            resulting in version 6.1.7  */
150
/*                                                                        */
151
/**************************************************************************/
152
368
UINT _gx_canvas_rotated_text_draw_ext(GX_CONST GX_STRING *text,
153
                                      GX_VALUE xcenter,
154
                                      GX_VALUE ycenter,
155
                                      INT angle)
156
{
157
GX_PIXELMAP textmap;
158
GX_PIXELMAP rotated_map;
159
INT         x_pos;
160
INT         y_pos;
161
GX_FONT    *font;
162
GX_VALUE    alphamap_width;
163
164
/* pickup pointer to current context */
165
368
GX_DRAW_CONTEXT *context = _gx_system_current_draw_context;
166
167
368
    if (!context)
168
    {
169
1
        return GX_FAILURE;
170
    }
171
172
    /* get pointer to current font */
173
367
    font = context -> gx_draw_context_brush.gx_brush_font;
174
175
367
    if (!font)
176
    {
177
1
        return GX_FAILURE;
178
    }
179
180
547
    while (angle >= 360)
181
    {
182
181
        angle -= 360;
183
    }
184
545
    while (angle <= -360)
185
    {
186
179
        angle += 360;
187
    }
188
189
366
    if (!angle)
190
    {
191
1
        _gx_system_string_width_get_ext(font, text, &alphamap_width);
192
1
        x_pos = xcenter - (alphamap_width / 2);
193
1
        y_pos = ycenter - (font -> gx_font_line_height / 2);
194
195
1
        _gx_canvas_text_draw_ext((GX_VALUE)x_pos, (GX_VALUE)y_pos, text);
196
1
        return GX_SUCCESS;
197
    }
198
199
365
    if (_gx_utility_string_to_alphamap_ext(text, font, &textmap) == GX_SUCCESS)
200
    {
201
        /* Rotate the alpha map */
202
364
        x_pos = y_pos = 0;
203
204
364
        if (_gx_utility_pixelmap_rotate(&textmap, angle, &rotated_map, &x_pos, &y_pos) == GX_SUCCESS)
205
        {
206
363
            x_pos = xcenter - (rotated_map.gx_pixelmap_width / 2);
207
363
            y_pos = ycenter - (rotated_map.gx_pixelmap_height / 2);
208
209
            /* draw the alpha-map to render the text */
210
#if defined(GX_RENESAS_DAVE2D_DRAW)
211
            rotated_map.gx_pixelmap_flags |= GX_PIXELMAP_DYNAMICALLY_ALLOCATED;
212
#endif
213
363
            _gx_canvas_pixelmap_draw((GX_VALUE)x_pos, (GX_VALUE)y_pos, &rotated_map);
214
215
            /* free the rotated alphamap memory */
216
363
            _gx_system_memory_free((void *)rotated_map.gx_pixelmap_data);
217
        }
218
219
        /* free the temporary canvas memory */
220
364
        _gx_system_memory_free((void *)(textmap.gx_pixelmap_data));
221
    }
222
365
    return GX_SUCCESS;
223
}
224