// RichTextKit // Copyright © 2019-2020 Topten Software. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); you may // not use this product 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 SkiaSharp; using System; using System.Collections.Generic; using System.Text; namespace Topten.RichTextKit { /// /// Used to return caret positioning information from the /// method. /// public struct CaretInfo { /// /// Returns the index of the code point that this caret info refers to. /// public int CodePointIndex; /// /// Returns the line number that contains the caret /// public int LineIndex; /// /// The X-coordinate where the caret should be displayed for this code point. /// public float CaretXCoord; /// /// A rectangle describing where the caret should be drawn, relative to the top-left /// corner of the text block. The caret should be drawn from the returned rectangle's /// top-right to bottom-left. /// /// /// This will be based on the *previous* character on this line (or the same character /// if this is first character in the line). /// /// Usually this will be a zero-width rectangle describing the x, top and bottom /// coordinates of where the caret should be drawn. The width of the drawn caret /// isn't provided and should be determined by the client. /// /// When the caret is immediately following an italic character, the returned /// rectangle will be sloped to the right and should be drawn from the top-right /// coordinate to the bottom-left coordinate. /// /// If you don't want to draw a sloped caret for italics, use the top and bottom /// coordinates of the returned rectangle and get the x-coordinate from the /// property. /// public SKRect CaretRectangle; /// /// Checks if this caret info represents a caret position of none, or not found /// public bool IsNone => CodePointIndex < 0; /// /// Place holder caret info structure for no caret /// public static CaretInfo None = new CaretInfo() { CodePointIndex = -1, }; /* * Commented out as untested. * * /// /// The base line of this cluster, relative to the top of the text block /// public float ClusterBaseLine => FontRun.Line.YPosition + FontRun.Line.BaseLine; /// /// The cluster's ascent /// public float ClusterAscent => FontRun.Ascent; /// /// The cluster's descent /// public float ClusterDescent => FontRun.Descent; /// /// Get the left x-coord of this cluster /// public float ClusterLeftXCoord { get { return FontRun.GetCodePointXCoord(Direction == TextDirection.LTR ? CodePointIndex : NextCodePointIndex); } } /// /// Get the right x-coord of this cluster /// public float ClusterRightXCoord { get { return FontRun.GetCodePointXCoord(Direction == TextDirection.RTL ? CodePointIndex : NextCodePointIndex); } } /// /// The code point index of the next cluster. /// /// /// If the code point index refers to the last code point in the /// text block then this property returns the current code point index. /// public int NextCodePointIndex; /// /// The code point index of the previous cluster. /// /// /// If the code point index refers to the first code point in the /// text block then this property returns 0. /// public int PreviousCodePointIndex; /// /// The number of code points in this cluster. /// public int CodePointCount => NextCodePointIndex - CodePointIndex; /// /// The font run that contains the code point. /// public FontRun FontRun; /// /// The style run that contains the code point. /// public StyleRun StyleRun; */ } }