当前位置: 首页>>代码示例>>C#>>正文


C# RectangleGeometry.GetAsPathGeometry方法代码示例

本文整理汇总了C#中System.Windows.Media.RectangleGeometry.GetAsPathGeometry方法的典型用法代码示例。如果您正苦于以下问题:C# RectangleGeometry.GetAsPathGeometry方法的具体用法?C# RectangleGeometry.GetAsPathGeometry怎么用?C# RectangleGeometry.GetAsPathGeometry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.RectangleGeometry的用法示例。


在下文中一共展示了RectangleGeometry.GetAsPathGeometry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildHighlightGeometry

        /// <summary>
        /// Builds a highlight geometry object for a given character range.
        /// </summary>
        /// <param name="origin">The origin of the highlight region.</param>
        /// <param name="startIndex">The start index of initial character the bounds should be obtained for.</param>
        /// <param name="count">The number of characters the bounds should be obtained for.</param>
        /// <returns>Geometry that surrounds the specified character range.</returns>
        public Geometry BuildHighlightGeometry(Point origin, int startIndex, int count)
        {
            ValidateRange(startIndex, count);

            PathGeometry accumulatedBounds = null;
            using (LineEnumerator enumerator = GetEnumerator())
            {

                Point lineOrigin = origin;

                while (enumerator.MoveNext())
                {
                    using (TextLine currentLine = enumerator.Current)
                    {
                        int x0 = Math.Max(enumerator.Position, startIndex);
                        int x1 = Math.Min(enumerator.Position + enumerator.Length, startIndex + count);

                        // check if this line is intersects with the specified character range
                        if (x0 < x1)
                        {
                            IList<TextBounds> highlightBounds = currentLine.GetTextBounds(
                                x0,
                                x1 - x0
                                );

                            if (highlightBounds != null)
                            {
                                foreach (TextBounds bound in highlightBounds)
                                {
                                    Rect rect = bound.Rectangle;

                                    if (FlowDirection == FlowDirection.RightToLeft)
                                    {
                                        // Convert logical units (which extend leftward from the right edge
                                        // of the paragraph) to physical units.
                                        //
                                        // Note that since rect is in logical units, rect.Right corresponds to 
                                        // the visual *left* edge of the rectangle in the RTL case. Specifically,
                                        // is the distance leftward from the right edge of the formatting rectangle
                                        // whose width is the paragraph width passed to FormatLine.
                                        //
                                        rect.X = enumerator.CurrentParagraphWidth - rect.Right;
                                    }

                                    rect.X += lineOrigin.X;
                                    rect.Y += lineOrigin.Y;

                                    RectangleGeometry rectangleGeometry = new RectangleGeometry(rect);
                                    if (accumulatedBounds == null)
                                        accumulatedBounds = rectangleGeometry.GetAsPathGeometry();
                                    else
                                        accumulatedBounds = Geometry.Combine(accumulatedBounds, rectangleGeometry, GeometryCombineMode.Union, null);
                                }
                            }
                        }
                        AdvanceLineOrigin(ref lineOrigin, currentLine);
                    }
                }
            }

            if (accumulatedBounds == null  ||  accumulatedBounds.IsEmpty())
                return null;

            return accumulatedBounds;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:72,代码来源:FormattedText.cs


注:本文中的System.Windows.Media.RectangleGeometry.GetAsPathGeometry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。