/* * Copyright(c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System; using System.ComponentModel; using Tizen.NUI.Text; using System.Collections.Generic; namespace Tizen.NUI.BaseComponents { /// /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public static class TextGeometry { private static void ValidateRange(int start, int end) { if (start < 0) throw new global::System.ArgumentOutOfRangeException(nameof(start), "Value is less than zero"); if (end < 0) throw new global::System.ArgumentOutOfRangeException(nameof(end), "Value is less than zero"); } private static List GetSizeListFromNativeVector(System.IntPtr ptr) { using (VectorVector2 sizeVector = new VectorVector2 (ptr, true)) { int count = sizeVector.Size(); List list = new List(); for(int i = 0; i < count; i++) list.Add(sizeVector.ValueOfIndex( (uint)i )); return list; } } private static List GetPositionListFromNativeVector(System.IntPtr ptr) { using (VectorVector2 positionVector = new VectorVector2 (ptr, true)) { int count = positionVector.Size(); List list = new List(); for(int i = 0; i < count; i++) list.Add(positionVector.ValueOfIndex( (uint)i )); return list; } } private static void CheckSWIGPendingException() { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Get the rendered size of the text between start and end (included).
/// if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
/// if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
///
/// The TextEditor control containing the text. /// The start index of the text to get the size for /// The end index of the text to get the size for. // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public static List GetTextSize(TextEditor textEditor, int start, int end) { if (textEditor == null) { throw new ArgumentNullException(null, "textEditor object is null"); } ValidateRange(start, end); List list = GetSizeListFromNativeVector(Interop.TextEditor.GetTextSize(textEditor.SwigCPtr, (uint)start, (uint)end)); CheckSWIGPendingException(); return list; } /// /// Get the rendered size of the text between start and end (included).
/// if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
/// if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
///
/// The TextField control containing the text. /// The start index of the text to get the size for /// The end index of the text to get the size for. // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public static List GetTextSize(TextField textField, int start, int end) { if (textField == null) { throw new ArgumentNullException(null, "textField object is null"); } ValidateRange(start, end); List list = GetSizeListFromNativeVector(Interop.TextField.GetTextSize(textField.SwigCPtr, (uint)start, (uint)end)); CheckSWIGPendingException(); return list; } /// /// Get the rendered size of the text between start and end (included).
/// if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
/// if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
///
/// The TextLabel control containing the text. /// The start index of the text to get the size for /// The end index of the text to get the size for. // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public static List GetTextSize(TextLabel textLabel, int start, int end) { if (textLabel == null) { throw new ArgumentNullException(null, "textLabel object is null"); } ValidateRange(start, end); List list = GetSizeListFromNativeVector(Interop.TextLabel.GetTextSize(textLabel.SwigCPtr, (uint)start, (uint)end)); CheckSWIGPendingException(); return list; } /// /// Get the rendered position (top-left) of the text between start and end (included).
/// if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
/// if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
///
/// The TextEditor control containing the text. /// The start index of the text to get the position for /// The end index of the text to get the position for. // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public static List GetTextPosition(TextEditor textEditor, int start, int end) { if (textEditor == null) { throw new ArgumentNullException(null, "textEditor object is null"); } ValidateRange(start, end); List list = GetPositionListFromNativeVector(Interop.TextEditor.GetTextPosition(textEditor.SwigCPtr, (uint)start, (uint)end)); CheckSWIGPendingException(); return list; } /// /// Get the rendered position (top-left) of the text between start and end (included).
/// if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
/// if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
///
/// The TextField control containing the text. /// The start index of the text to get the position for /// The end index of the text to get the position for. // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public static List GetTextPosition(TextField textField, int start, int end) { if (textField == null) { throw new ArgumentNullException(null, "textField object is null"); } ValidateRange(start, end); List list = GetPositionListFromNativeVector(Interop.TextField.GetTextPosition(textField.SwigCPtr, (uint)start, (uint)end)); CheckSWIGPendingException(); return list; } /// /// Get the rendered position (top-left) of the text between start and end (included).
/// if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
/// if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
///
/// The TextLabel control containing the text. /// The start index of the text to get the position for /// The end index of the text to get the position for. // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public static List GetTextPosition(TextLabel textLabel, int start, int end) { if (textLabel == null) { throw new ArgumentNullException(null, "textLabel object is null"); } ValidateRange(start, end); List list = GetPositionListFromNativeVector(Interop.TextLabel.GetTextPosition(textLabel.SwigCPtr, (uint)start, (uint)end)); CheckSWIGPendingException(); return list; } } }