GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_rich_text_view_text_total_height_calculate.c Lines: 34 34 100.0 %
Date: 2026-03-06 19:21:09 Branches: 8 8 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
/**   Rich Text View Management (Rich 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_widget.h"
29
#include "gx_system.h"
30
#include "gx_window.h"
31
#include "gx_rich_text_view.h"
32
#include "gx_utility.h"
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_rich_text_view_text_total_height_calculate      PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function calculates rich text view text total height.          */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    text_view                             Multi line text view          */
51
/*                                            control block               */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    None                                                                */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _gx_utility_rectangle_resize          Resize rectangle              */
59
/*    _gx_widget_string_get_ext             Detect and process rich text  */
60
/*                                            tag                         */
61
/*    _gx_widget_font_get                   Retrieve font by id           */
62
/*    _gx_utility_utf8_string_character_get Retrieve glyph length         */
63
/*    _gx_system_string_width_get           Get string width              */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    GUIX Internal Code                                                  */
68
/*                                                                        */
69
/**************************************************************************/
70
48
UINT _gx_rich_text_view_text_total_height_calculate(GX_RICH_TEXT_VIEW *text_view)
71
{
72
GX_STRING              text;
73
GX_FONT               *font;
74
GX_RICH_TEXT_LINE_INFO line_info;
75
GX_RICH_TEXT_FORMAT    format;
76
GX_VALUE               client_width;
77
GX_RECTANGLE           client;
78
48
INT                    total_height = 0;
79
80
48
    if (!text_view -> gx_multi_line_text_view_text.gx_string_length)
81
    {
82
5
        text_view -> gx_rich_text_view_text_total_height = 0;
83
5
        text_view -> gx_multi_line_text_view_line_index_old = GX_FALSE;
84
5
        return GX_SUCCESS;
85
    }
86
87
    /* Pick up client retangle. */
88
43
    client = text_view -> gx_window_client;
89
90
    /* Offset client area by the size of whitespace.  */
91
43
    _gx_utility_rectangle_resize(&client, (GX_VALUE)(-text_view -> gx_multi_line_text_view_whitespace));
92
93
    /* Calculate text display width. */
94
43
    client_width = (GX_VALUE)(client.gx_rectangle_right - client.gx_rectangle_left - 1);
95
96
    /* Set default draw style. */
97
43
    format.gx_rich_text_font_id = text_view -> gx_rich_text_view_fonts.gx_rich_text_fonts_normal_id;
98
43
    format.gx_rich_text_flags = 0;
99
100
    /* Pick up text for drawing. */
101
43
    if (text_view -> gx_multi_line_text_view_text_id)
102
    {
103
40
        _gx_widget_string_get_ext((GX_WIDGET *)text_view, text_view -> gx_multi_line_text_view_text_id, &text);
104
    }
105
    else
106
    {
107
3
        _gx_system_private_string_get(&text_view -> gx_multi_line_text_view_text, &text, text_view -> gx_widget_style);
108
    }
109
110
    /* Calculate the total rows of text view string. */
111
244
    while (text.gx_string_length > 0)
112
    {
113
        /* Pickup draw font. */
114
203
        _gx_widget_font_get((GX_WIDGET *)text_view, format.gx_rich_text_font_id, &font);
115
116
203
        if (!font)
117
        {
118
2
            return GX_INVALID_FONT;
119
        }
120
121
201
        line_info.gx_rich_text_line_info_text.gx_string_ptr = text.gx_string_ptr;
122
201
        line_info.gx_rich_text_line_info_text.gx_string_length = 0;
123
201
        line_info.gx_rich_text_line_info_start_format = format;
124
201
        line_info.gx_rich_text_line_info_end_format = format;
125
201
        line_info.gx_rich_text_line_info_line_height = font -> gx_font_line_height;
126
201
        line_info.gx_rich_text_line_info_text_width = 0;
127
128
201
        _gx_rich_text_view_line_info_get(text_view, text, &line_info, client_width);
129
130
201
        total_height += line_info.gx_rich_text_line_info_line_height;
131
201
        total_height += text_view -> gx_multi_line_text_view_line_space;
132
133
201
        format = line_info.gx_rich_text_line_info_end_format;
134
135
136
201
        text.gx_string_ptr += line_info.gx_rich_text_line_info_text.gx_string_length;
137
201
        text.gx_string_length -= line_info.gx_rich_text_line_info_text.gx_string_length;
138
    }
139
140
41
    _gx_rich_text_view_context_reset();
141
142
41
    text_view -> gx_rich_text_view_text_total_height = (UINT)total_height;
143
41
    text_view -> gx_multi_line_text_view_line_index_old = GX_FALSE;
144
41
    return GX_SUCCESS;
145
}
146