public void RenderTextLayout(NativeTextLayout layout, float x, float y, float opacity)
 {
     if (!DrawingEngine_RenderTextLayout(_native, layout.NativePointer, x, y, opacity, out var error))
     {
         throw new InvalidOperationException("Couldn't render text layout: " + error);
     }
 }
Example #2
0
        /// <summary>
        /// The application calls this function to get the pixel location relative to the top-left of the layout box
        /// given the text position and the logical side of the position.
        /// This function is normally used as part of caret positioning of text where the caret is drawn
        /// at the location corresponding to the current text editing position.
        /// It may also be used as a way to programmatically obtain the geometry of a particular text position in UI automation.</summary>
        /// <param name="textPosition">The text position used to get the pixel location</param>
        /// <param name="isTrailingHit">A Boolean flag that whether the pixel location is of the leading or
        /// the trailing side of the specified text position</param>
        /// <returns>HitTestMetrics of given text position</returns>
        public HitTestMetrics HitTestTextPosition(int textPosition, bool isTrailingHit)
        {
            float x, y;
            var   hitTestMetrics = NativeTextLayout.HitTestTextPosition(textPosition, isTrailingHit, out x, out y);
            var   result         = new HitTestMetrics
            {
                TextPosition = hitTestMetrics.TextPosition,
                Length       = hitTestMetrics.Length,
                Point        = new PointF(x, y),
                Width        = hitTestMetrics.Width,
                Height       = hitTestMetrics.Height
            };

            return(result);
        }
Example #3
0
        /// <summary>
        /// The application calls this function passing in a specific pixel location relative to the top-left location
        /// of the layout box and obtains the information about the correspondent hit-test metrics of the text string
        /// where the hit-test has occurred. When the specified pixel location is outside the text string,
        /// the function sets the output value IsInside to False.</summary>
        /// <param name="x">The pixel location X to hit-test, relative to the top-left location of the layout box.</param>
        /// <param name="y">The pixel location Y to hit-test, relative to the top-left location of the layout box.</param>
        /// <returns>HitTestMetrics of text string where hit test occurs</returns>
        public HitTestMetrics HitTestPoint(float x, float y)
        {
            Bool isTrailingHit;
            Bool isInside;
            var  hitTestMetrics = NativeTextLayout.HitTestPoint(x, y, out isTrailingHit, out isInside);
            var  result         = new HitTestMetrics
            {
                IsInside      = isInside,
                IsTrailingHit = isTrailingHit,
                TextPosition  = hitTestMetrics.TextPosition,
                Length        = hitTestMetrics.Length
            };

            return(result);
        }
Example #4
0
        /// <summary>
        /// Retrieves information about each individual text line of the text string</summary>
        /// <returns>Array of LineMetrics for each text line</returns>
        public LineMetrics[] GetLineMetrics()
        {
            var lineMetrics = NativeTextLayout.GetLineMetrics();
            var result      = new LineMetrics[lineMetrics.Length];

            for (int i = 0; i < lineMetrics.Length; ++i)
            {
                result[i].Baseline  = lineMetrics[i].Baseline;
                result[i].Height    = lineMetrics[i].Height;
                result[i].IsTrimmed = lineMetrics[i].IsTrimmed;
                result[i].Length    = lineMetrics[i].Length;
                result[i].TrailingWhitespaceLength = lineMetrics[i].TrailingWhitespaceLength;
                result[i].NewlineLength            = lineMetrics[i].NewlineLength;
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// The application calls this function to get a set of hit-test metrics corresponding to a range of text positions.
        /// One of the main usages is to implement highlight selection of the text string.</summary>
        /// <param name="textPosition">The first text position of the specified range.</param>
        /// <param name="textLength">The number of positions of the specified range.</param>
        /// <param name="originX">The origin pixel location X at the left of the layout box.
        /// This offset is added to the hit-test metrics returned. </param>
        /// <param name="originY">The origin pixel location Y at the top of the layout box.
        /// This offset is added to the hit-test metrics returned. </param>
        /// <returns>An array of D2dTextHitTestMetrics fully enclosing the specified position range.</returns>
        public HitTestMetrics[] HitTestTextRange(int textPosition, int textLength, float originX, float originY)
        {
            var hitTestMetrics = NativeTextLayout.HitTestTextRange(textPosition, textLength, originX, originY);
            var result         = new HitTestMetrics[hitTestMetrics.Length];

            for (int i = 0; i < hitTestMetrics.Length; ++i)
            {
                result[i].TextPosition = hitTestMetrics[i].TextPosition;
                result[i].Length       = hitTestMetrics[i].Length;
                result[i].Point        = new PointF(hitTestMetrics[i].Left, hitTestMetrics[i].Top);
                result[i].Height       = hitTestMetrics[i].Height;
                result[i].Width        = hitTestMetrics[i].Width;
                result[i].Top          = hitTestMetrics[i].Top;
            }
            return(result);
        }
Example #6
0
        /// <summary>
        /// Retrieves logical properties and measurements of each glyph cluster</summary>
        /// <returns>Metrics, such as line-break or total advance width, for a glyph cluster</returns>
        public ClusterMetrics[] GetClusterMetrics()
        {
            var clusterMetrics = NativeTextLayout.GetClusterMetrics();
            var result         = new ClusterMetrics[clusterMetrics.Length];

            for (int i = 0; i < clusterMetrics.Length; ++i)
            {
                result[i].Length           = clusterMetrics[i].Length;
                result[i].Width            = clusterMetrics[i].Width;
                result[i].CanWrapLineAfter = clusterMetrics[i].CanWrapLineAfter;
                result[i].IsNewline        = clusterMetrics[i].IsNewline;
                result[i].IsRightToLeft    = clusterMetrics[i].IsRightToLeft;
                result[i].IsSoftHyphen     = clusterMetrics[i].IsSoftHyphen;
                result[i].IsWhitespace     = clusterMetrics[i].IsWhitespace;
            }
            return(result);
        }
Example #7
0
        /// <summary>
        /// The application calls this function passing in a specific pixel location relative to the top-left location
        /// of the layout box and obtains the information about the correspondent hit-test metrics of the text string
        /// where the hit-test has occurred. When the specified pixel location is outside the text string,
        /// the function sets the output value IsInside to False.</summary>
        /// <param name="x">The pixel location X to hit-test, relative to the top-left location of the layout box.</param>
        /// <param name="y">The pixel location Y to hit-test, relative to the top-left location of the layout box.</param>
        /// <returns>HitTestMetrics of text string where hit test occurs</returns>
        public HitTestMetrics HitTestPoint(float x, float y)
        {
#if WITH_SGD
            SharpDX.Mathematics.Interop.RawBool isTrailingHit;
            SharpDX.Mathematics.Interop.RawBool isInside;
#else
            Bool isTrailingHit;
            Bool isInside;
#endif
            var hitTestMetrics = NativeTextLayout.HitTestPoint(x, y, out isTrailingHit, out isInside);
            var result         = new HitTestMetrics
            {
                IsInside      = isInside,
                IsTrailingHit = isTrailingHit,
                TextPosition  = hitTestMetrics.TextPosition,
                Length        = hitTestMetrics.Length
            };

            return(result);
        }
 public TextLayout(NativeTextLayout layout)
 {
     _lineMetrics     = Array.Empty <NativeLineMetrics>();
     NativeTextLayout = layout;
 }