GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_multi_line_text_view_display_info_get.c Lines: 55 55 100.0 %
Date: 2026-03-06 19:21:09 Branches: 38 38 100.0 %

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
/**   Multi Line Text View Management (Multi Line Text View)              */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
#include "gx_multi_line_text_view.h"
30
#include "gx_utility.h"
31
#include "gx_widget.h"
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _gx_multi_line_text_view_display_info_get           PORTABLE C      */
38
/*                                                           6.1          */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Kenneth Maxwell, Microsoft Corporation                              */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function gets the length and pixel width of one word or        */
46
/*      some characters can be displayed in one line.                     */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    text_view                             Multi line text view          */
51
/*                                            control block               */
52
/*    start_index                           Start character position in   */
53
/*                                            the input buffer            */
54
/*    end_index                             End character position in the */
55
/*                                            input buffer                */
56
/*    text_info                             Text and word information to  */
57
/*                                            be returned                 */
58
/*    available_width                       Width available to display    */
59
/*                                            text in current line        */
60
/*                                                                        */
61
/*  OUTPUT                                                                */
62
/*                                                                        */
63
/*    None                                                                */
64
/*                                                                        */
65
/*  CALLS                                                                 */
66
/*                                                                        */
67
/*    _gx_widget_font_get                   Retrieve font                 */
68
/*    _gx_system_string_width_get           Get the width of a string     */
69
/*    _gx_system_private_string_get         Get string pointer in a       */
70
/*                                            dynamically copied string   */
71
/*                                            buffer                      */
72
/*    _gx_utility_utf8_string_character_get Parse utf8 string to          */
73
/*                                            multi-byte glyph            */
74
/*                                                                        */
75
/*  CALLED BY                                                             */
76
/*                                                                        */
77
/*    GUIX Internal Code                                                  */
78
/*                                                                        */
79
/**************************************************************************/
80
133473
VOID _gx_multi_line_text_view_display_info_get(GX_MULTI_LINE_TEXT_VIEW *text_view, UINT start_index,
81
                                               UINT end_index, GX_MULTI_LINE_TEXT_INFO *text_info, GX_VALUE available_width)
82
{
83
#ifdef GX_UTF8_SUPPORT
84
133473
UINT      current_index = start_index;
85
#endif
86
GX_STRING string;
87
GX_STRING ch;
88
GX_VALUE  char_width;
89
USHORT    display_width;
90
USHORT    display_number;
91
133473
UINT      glyph_len = 1;
92
GX_FONT  *font;
93
94
133473
    text_info -> gx_text_display_width = 0;
95
133473
    text_info -> gx_text_display_number = 0;
96
97
133473
    if (text_view -> gx_multi_line_text_view_text_id)
98
    {
99
1749
        _gx_widget_string_get_ext((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_text_id, &string);
100
    }
101
    else
102
    {
103
131724
        _gx_system_private_string_get(&text_view -> gx_multi_line_text_view_text, &string, text_view -> gx_widget_style);
104
    }
105
106
107
133473
    string.gx_string_ptr += start_index;
108
133473
    string.gx_string_length = end_index - start_index;
109
110
133473
    if (text_view -> gx_widget_status & GX_STATUS_LINE_BREAK_PROCESSED)
111
    {
112
        /* Line breaking alreay preprocessed, only need to search for line break characters to do line break. */
113
447
        while (string.gx_string_length > 0)
114
        {
115
434
            if (string.gx_string_ptr[0] == GX_KEY_CARRIAGE_RETURN)
116
            {
117
16
                text_info -> gx_text_display_number++;
118
119

16
                if ((string.gx_string_length > 1) && string.gx_string_ptr[1] == GX_KEY_LINE_FEED)
120
                {
121
1
                    text_info -> gx_text_display_number++;
122
                }
123
16
                break;
124
            }
125
418
            else if (string.gx_string_ptr[0] == GX_KEY_LINE_FEED)
126
            {
127
1
                text_info -> gx_text_display_number++;
128
1
                break;
129
            }
130
            else
131
            {
132
417
                text_info -> gx_text_display_number++;
133
            }
134
135
417
            string.gx_string_length--;
136
417
            string.gx_string_ptr++;
137
        }
138
    }
139
    else
140
    {
141
133443
        _gx_widget_font_get((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_font_id, &font);
142
143
133443
        if (!font)
144
        {
145
1
            return;
146
        }
147
148
133442
        display_width = 0;
149
133442
        display_number = 0;
150
151
1244702
        while (string.gx_string_length > 0)
152
        {
153
1238984
            ch = string;
154
155
#ifdef GX_UTF8_SUPPORT
156
1238984
            _gx_utility_utf8_string_character_get(&string, GX_NULL, &glyph_len);
157
1238984
            current_index += glyph_len;
158
#else
159
            string.gx_string_ptr++;
160
            string.gx_string_length--;
161
#endif /* GX_UTF8_SUPPORT */
162
163
1238984
            ch.gx_string_length = glyph_len;
164
1238984
            _gx_system_string_width_get_ext(font, &ch, &char_width);
165
166
1238984
            if (ch.gx_string_ptr[0] == GX_KEY_CARRIAGE_RETURN)
167
            {
168
90375
                if (ch.gx_string_ptr[1] == GX_KEY_LINE_FEED)
169
                {
170
1869
                    text_info -> gx_text_display_number = (USHORT)(text_info -> gx_text_display_number + 2);
171
                }
172
                else
173
                {
174
88506
                    text_info -> gx_text_display_number++;
175
                }
176
90375
                break;
177
            }
178
1148609
            else if (ch.gx_string_ptr[0] == GX_KEY_LINE_FEED)
179
            {
180
11472
                text_info -> gx_text_display_number++;
181
11472
                break;
182
            }
183
1137137
            else if (((text_info -> gx_text_display_width + char_width) > available_width - 1) &&
184
52916
                     (text_info -> gx_text_display_number > 0) &&
185
52730
                     (ch.gx_string_ptr[0] != ' '))
186
            {
187
25877
                if (display_number == 0)
188
                {
189
8028
                    break;
190
                }
191
17849
                text_info -> gx_text_display_width = display_width;
192
17849
                text_info -> gx_text_display_number = display_number;
193
17849
                break;
194
            }
195
1111260
            text_info -> gx_text_display_width = (USHORT)(text_info -> gx_text_display_width + char_width);
196
1111260
            text_info -> gx_text_display_number = (USHORT)(text_info -> gx_text_display_number + glyph_len);
197
198

1111260
            if ((ch.gx_string_ptr[0] == ' ') || (ch.gx_string_ptr[0] == ',') || (ch.gx_string_ptr[0] == ';'))
199
            {
200
211442
                display_width = text_info -> gx_text_display_width;
201
211442
                display_number = text_info -> gx_text_display_number;
202
            }
203
        }
204
    }
205
}
206