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 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_canvas.h"
28 #include "gx_system.h"
29 #include "gx_utility.h"
30 
31 /* Bring in externs for caller checking code.  */
32 GX_CALLER_CHECKING_EXTERNS
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _gxe_canvas_text_draw                               PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Kenneth Maxwell, Microsoft Corporation                              */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function checks errors in the screen text draw function call.  */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    x_start                               x coordinate, text left edge  */
51 /*    y_start                               y coordinate, text baseline   */
52 /*    string                                String to draw                */
53 /*    length                                Length of string to draw      */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _gx_canvas_text_draw                  The actual function           */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
72 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
76 #if defined(GX_ENABLE_DEPRECATED_STRING_API)
_gxe_canvas_text_draw(GX_VALUE x_start,GX_VALUE y_start,GX_CONST GX_CHAR * string,INT length)77 UINT  _gxe_canvas_text_draw(GX_VALUE x_start, GX_VALUE y_start, GX_CONST GX_CHAR *string, INT length)
78 {
79 UINT status;
80 
81     /* Check for appropriate caller.  */
82     GX_INIT_AND_THREADS_CALLER_CHECKING
83 
84     /* Check for invalid input pointers.  */
85     if (string == GX_NULL)
86     {
87         return(GX_PTR_ERROR);
88     }
89 
90     if (_gx_system_current_draw_context == GX_NULL)
91     {
92         return GX_INVALID_CONTEXT;
93     }
94 
95     /* Call actual widget height get function.  */
96     status = _gx_canvas_text_draw(x_start, y_start, string, length);
97 
98     /* Return successful completion.  */
99     return(status);
100 }
101 #endif
102 
103 /**************************************************************************/
104 /*                                                                        */
105 /*  FUNCTION                                               RELEASE        */
106 /*                                                                        */
107 /*    _gxe_canvas_text_draw_ext                           PORTABLE C      */
108 /*                                                           6.1          */
109 /*  AUTHOR                                                                */
110 /*                                                                        */
111 /*    Kenneth Maxwell, Microsoft Corporation                              */
112 /*                                                                        */
113 /*  DESCRIPTION                                                           */
114 /*                                                                        */
115 /*    This function checks errors in the screen text draw function call.  */
116 /*                                                                        */
117 /*  INPUT                                                                 */
118 /*                                                                        */
119 /*    x_start                               x coordinate, text left edge  */
120 /*    y_start                               y coordinate, text baseline   */
121 /*    string                                String to draw                */
122 /*                                                                        */
123 /*  OUTPUT                                                                */
124 /*                                                                        */
125 /*    status                                Completion status             */
126 /*                                                                        */
127 /*  CALLS                                                                 */
128 /*                                                                        */
129 /*    _gx_canvas_text_draw_ext              The actual function           */
130 /*                                                                        */
131 /*  CALLED BY                                                             */
132 /*                                                                        */
133 /*    Application Code                                                    */
134 /*                                                                        */
135 /*  RELEASE HISTORY                                                       */
136 /*                                                                        */
137 /*    DATE              NAME                      DESCRIPTION             */
138 /*                                                                        */
139 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
140 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
141 /*                                            resulting in version 6.1    */
142 /*                                                                        */
143 /**************************************************************************/
_gxe_canvas_text_draw_ext(GX_VALUE x_start,GX_VALUE y_start,GX_CONST GX_STRING * string)144 UINT _gxe_canvas_text_draw_ext(GX_VALUE x_start, GX_VALUE y_start, GX_CONST GX_STRING *string)
145 {
146 UINT status;
147 UINT text_length = 0;
148 
149     /* Check for appropriate caller.  */
150     GX_INIT_AND_THREADS_CALLER_CHECKING
151 
152     /* Check for invalid input pointers.  */
153     if ((string == GX_NULL) || (string -> gx_string_ptr == GX_NULL))
154     {
155         return(GX_PTR_ERROR);
156     }
157 
158     if (_gx_system_current_draw_context == GX_NULL)
159     {
160         return GX_INVALID_CONTEXT;
161     }
162 
163     status = _gx_utility_string_length_check(string -> gx_string_ptr, &text_length, string -> gx_string_length);
164 
165     if (status != GX_SUCCESS)
166     {
167         return status;
168     }
169 
170     if (text_length < string -> gx_string_length)
171     {
172         return GX_INVALID_STRING_LENGTH;
173     }
174 
175     /* Call actual widget height get function.  */
176     status = _gx_canvas_text_draw_ext(x_start, y_start, string);
177 
178     /* Return successful completion.  */
179     return(status);
180 }
181 
182 /**************************************************************************/
183 /*                                                                        */
184 /*  FUNCTION                                               RELEASE        */
185 /*                                                                        */
186 /*    _gxe_canvas_aligned_text_draw_ext                   PORTABLE C      */
187 /*                                                           6.1.11       */
188 /*  AUTHOR                                                                */
189 /*                                                                        */
190 /*    Ting Zhu, Microsoft Corporation                                     */
191 /*                                                                        */
192 /*  DESCRIPTION                                                           */
193 /*                                                                        */
194 /*    This function checks errors in the canvas aligned text draw         */
195 /*    function call.                                                      */
196 /*                                                                        */
197 /*  INPUT                                                                 */
198 /*                                                                        */
199 /*    string                                String to draw                */
200 /*    rectangle                             Drawing area                  */
201 /*    alignment                             Alignment style               */
202 /*                                                                        */
203 /*  OUTPUT                                                                */
204 /*                                                                        */
205 /*    status                                Completion status             */
206 /*                                                                        */
207 /*  CALLS                                                                 */
208 /*                                                                        */
209 /*    _gx_canvas_aligned_text_draw_ext      The actual function           */
210 /*                                                                        */
211 /*  CALLED BY                                                             */
212 /*                                                                        */
213 /*    Application Code                                                    */
214 /*                                                                        */
215 /*  RELEASE HISTORY                                                       */
216 /*                                                                        */
217 /*    DATE              NAME                      DESCRIPTION             */
218 /*                                                                        */
219 /*  04-25-2022     Ting Zhu                 Initial Version 6.1.11        */
220 /*                                                                        */
221 /**************************************************************************/
_gxe_canvas_aligned_text_draw(GX_CONST GX_STRING * string,GX_RECTANGLE * rectangle,ULONG alignment)222 UINT _gxe_canvas_aligned_text_draw(GX_CONST GX_STRING *string, GX_RECTANGLE *rectangle, ULONG alignment)
223 {
224 UINT status;
225 UINT text_length = 0;
226 
227     /* Check for appropriate caller.  */
228     GX_INIT_AND_THREADS_CALLER_CHECKING
229 
230     /* Check for invalid input pointers.  */
231     if ((string == GX_NULL) || (rectangle == GX_NULL) || (string -> gx_string_ptr == GX_NULL))
232     {
233         return GX_PTR_ERROR;
234     }
235 
236     if (_gx_system_current_draw_context == GX_NULL)
237     {
238         return GX_INVALID_CONTEXT;
239     }
240 
241     status = _gx_utility_string_length_check(string -> gx_string_ptr, &text_length, string -> gx_string_length);
242 
243     if (status != GX_SUCCESS)
244     {
245         return status;
246     }
247 
248     if (text_length < string -> gx_string_length)
249     {
250         return GX_INVALID_STRING_LENGTH;
251     }
252 
253     /* Call actual widget height get function.  */
254     status = _gx_canvas_aligned_text_draw(string, rectangle, alignment);
255 
256     /* Return successful completion.  */
257     return(status);
258 }
259 
260