[NUI] Implement missing properties for LottieAnimationView.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / TextGeometry.cs
1 /*
2  * Copyright(c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using Tizen.NUI.Text;
21 using System.Collections.Generic;
22
23 namespace Tizen.NUI.BaseComponents
24 {
25     /// <summary>
26     /// </summary>
27     // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
28     [EditorBrowsable(EditorBrowsableState.Never)]
29     public static class TextGeometry
30     {
31         private static void ValidateRange(int start, int end)
32         {
33             if (start < 0)
34                 throw new global::System.ArgumentOutOfRangeException(nameof(start), "Value is less than zero");
35             if (end < 0)
36                 throw new global::System.ArgumentOutOfRangeException(nameof(end), "Value is less than zero");
37         }
38
39         private static List<Size2D> GetSizeListFromNativeVector(System.IntPtr ptr)
40         {
41             using (VectorVector2 sizeVector = new VectorVector2 (ptr, true))
42             {
43                 int count = sizeVector.Size();
44                 List<Size2D> list = new List<Size2D>();
45
46                 for(int i = 0; i < count; i++)
47                     list.Add(sizeVector.ValueOfIndex( (uint)i ));
48
49                 return list;
50             }
51         }
52
53         private static List<Position2D> GetPositionListFromNativeVector(System.IntPtr ptr)
54         {
55             using (VectorVector2 positionVector = new VectorVector2 (ptr, true))
56             {
57                 int count = positionVector.Size();
58                 List<Position2D> list = new List<Position2D>();
59
60                 for(int i = 0; i < count; i++)
61                     list.Add(positionVector.ValueOfIndex( (uint)i ));
62
63                 return list;
64             }
65         }
66
67         private static void CheckSWIGPendingException()
68         {
69             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70         }
71
72         /// <summary>
73         /// Get the rendered size of the text between start and end (included). <br />
74         /// if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line. <br />
75         /// if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction. <br />
76         /// </summary>
77         /// <param name="textEditor">The TextEditor control containing the text.</param>
78         /// <param name="start">The start index of the text to get the size for</param>
79         /// <param name="end">The end index of the text to get the size for.</param>
80         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
81         [EditorBrowsable(EditorBrowsableState.Never)]
82         public static List<Size2D> GetTextSize(TextEditor textEditor, int start, int end)
83         {
84             if (textEditor == null)
85             {
86                 throw new ArgumentNullException(null, "textEditor object is null");
87             }
88
89             ValidateRange(start, end);
90
91             List<Size2D> list = GetSizeListFromNativeVector(Interop.TextEditor.GetTextSize(textEditor.SwigCPtr, (uint)start, (uint)end));
92             CheckSWIGPendingException();
93             return list;
94         }
95
96         /// <summary>
97         /// Get the rendered size of the text between start and end (included). <br />
98         /// if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line. <br />
99         /// if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction. <br />
100         /// </summary>
101         /// <param name="textField">The TextField control containing the text.</param>
102         /// <param name="start">The start index of the text to get the size for</param>
103         /// <param name="end">The end index of the text to get the size for.</param>
104         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public static List<Size2D> GetTextSize(TextField textField, int start, int end)
107         {
108             if (textField == null)
109             {
110                 throw new ArgumentNullException(null, "textField object is null");
111             }
112
113             ValidateRange(start, end);
114
115             List<Size2D> list = GetSizeListFromNativeVector(Interop.TextField.GetTextSize(textField.SwigCPtr, (uint)start, (uint)end));
116             CheckSWIGPendingException();
117             return list;
118         }
119
120         /// <summary>
121         /// Get the rendered size of the text between start and end (included). <br />
122         /// if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line. <br />
123         /// if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction. <br />
124         /// </summary>
125         /// <param name="textLabel">The TextLabel control containing the text.</param>
126         /// <param name="start">The start index of the text to get the size for</param>
127         /// <param name="end">The end index of the text to get the size for.</param>
128         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
129         [EditorBrowsable(EditorBrowsableState.Never)]
130         public static List<Size2D> GetTextSize(TextLabel textLabel, int start, int end)
131         {
132             if (textLabel == null)
133             {
134                 throw new ArgumentNullException(null, "textLabel object is null");
135             }
136
137             ValidateRange(start, end);
138
139             List<Size2D> list = GetSizeListFromNativeVector(Interop.TextLabel.GetTextSize(textLabel.SwigCPtr, (uint)start, (uint)end));
140             CheckSWIGPendingException();
141             return list;
142         }
143
144         /// <summary>
145         /// Get the rendered position (top-left) of the text between start and end (included). <br />
146         /// if the requested text is at multilines, multiple positions will be returned for each text located in a separate line. <br />
147         /// if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction. <br />
148         /// </summary>
149         /// <param name="textEditor">The TextEditor control containing the text.</param>
150         /// <param name="start">The start index of the text to get the position for</param>
151         /// <param name="end">The end index of the text to get the position for.</param>
152         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
153         [EditorBrowsable(EditorBrowsableState.Never)]
154         public static List<Position2D> GetTextPosition(TextEditor textEditor, int start, int end)
155         {
156             if (textEditor == null)
157             {
158                 throw new ArgumentNullException(null, "textEditor object is null");
159             }
160
161             ValidateRange(start, end);
162
163             List<Position2D> list = GetPositionListFromNativeVector(Interop.TextEditor.GetTextPosition(textEditor.SwigCPtr, (uint)start, (uint)end));
164             CheckSWIGPendingException();
165             return list;
166         }
167
168         /// <summary>
169         /// Get the rendered position (top-left) of the text between start and end (included). <br />
170         /// if the requested text is at multilines, multiple positions will be returned for each text located in a separate line. <br />
171         /// if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction. <br />
172         /// </summary>
173         /// <param name="textField">The TextField control containing the text.</param>
174         /// <param name="start">The start index of the text to get the position for</param>
175         /// <param name="end">The end index of the text to get the position for.</param>
176         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
177         [EditorBrowsable(EditorBrowsableState.Never)]
178         public static List<Position2D> GetTextPosition(TextField textField, int start, int end)
179         {
180             if (textField == null)
181             {
182                 throw new ArgumentNullException(null, "textField object is null");
183             }
184
185             ValidateRange(start, end);
186
187             List<Position2D> list = GetPositionListFromNativeVector(Interop.TextField.GetTextPosition(textField.SwigCPtr, (uint)start, (uint)end));
188             CheckSWIGPendingException();
189             return list;
190         }
191
192         /// <summary>
193         /// Get the rendered position (top-left) of the text between start and end (included). <br />
194         /// if the requested text is at multilines, multiple positions will be returned for each text located in a separate line. <br />
195         /// if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction. <br />
196         /// </summary>
197         /// <param name="textLabel">The TextLabel control containing the text.</param>
198         /// <param name="start">The start index of the text to get the position for</param>
199         /// <param name="end">The end index of the text to get the position for.</param>
200         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
201         [EditorBrowsable(EditorBrowsableState.Never)]
202         public static List<Position2D> GetTextPosition(TextLabel textLabel, int start, int end)
203         {
204             if (textLabel == null)
205             {
206                 throw new ArgumentNullException(null, "textLabel object is null");
207             }
208
209             ValidateRange(start, end);
210
211             List<Position2D> list = GetPositionListFromNativeVector(Interop.TextLabel.GetTextPosition(textLabel.SwigCPtr, (uint)start, (uint)end));
212             CheckSWIGPendingException();
213             return list;
214         }
215     }
216 }