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


C# ITextPointer.GetCharacterRect方法代码示例

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


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

示例1: GetLineBounds

        /// <summary>
        /// Computes the bounds for a given text segment, provided that the entire segment
        /// is located on a single text line.
        /// </summary>
        private static Rect GetLineBounds(ITextPointer start, ITextPointer end)
        {
            // Get the line range.
            if (!start.HasValidLayout || !end.HasValidLayout)
            {
                return Rect.Empty;
            }

            // Get the left and the width of the range bounds.
            Rect lineBounds = start.GetCharacterRect(LogicalDirection.Forward);
            lineBounds.Union(end.GetCharacterRect(LogicalDirection.Backward));

            // Scan the line range and compute the top and the height of the bounding rectangle.
            ITextPointer navigator = start.CreatePointer(LogicalDirection.Forward);
            while (navigator.MoveToNextContextPosition(LogicalDirection.Forward) == true && navigator.CompareTo(end) < 0)
            {
                TextPointerContext context = navigator.GetPointerContext(LogicalDirection.Backward);
                switch (context)
                {
                    case TextPointerContext.ElementStart:
                        lineBounds.Union(navigator.GetCharacterRect(LogicalDirection.Backward));
                        navigator.MoveToElementEdge(ElementEdge.AfterEnd);
                        break;
                    case TextPointerContext.ElementEnd:
                    case TextPointerContext.EmbeddedElement:
                        lineBounds.Union(navigator.GetCharacterRect(LogicalDirection.Backward));
                        break;
                    case TextPointerContext.Text:
                        break;
                    default:
                        // Unexpected
                        Invariant.Assert(context != TextPointerContext.None);
                        break;
                }
            }

            return lineBounds;
        }
开发者ID:mind0n,项目名称:hive,代码行数:42,代码来源:TextStore.cs

示例2: GetClippedPositionOffsets

        private static void GetClippedPositionOffsets(TextEditor This, ITextPointer position, LogicalDirection direction,
            out double horizontalOffset, out double verticalOffset)
        {
            // GetCharacterRect will return the position that base on UiScope.
            Rect positionRect = position.GetCharacterRect(direction);

            // Get the base offsets for our ContextMenu.
            horizontalOffset = positionRect.X;
            verticalOffset = positionRect.Y + positionRect.Height;

            // Clip to the child render scope.
            FrameworkElement element = This.TextView.RenderScope as FrameworkElement;
            if (element != null)
            {
                GeneralTransform transform = element.TransformToAncestor(This.UiScope);
                if (transform != null)
                {
                    ClipToElement(element, transform, ref horizontalOffset, ref verticalOffset);
                }
            }

            // Clip to parent visuals.
            // This is unintuitive -- you might expect parents to have increasingly
            // larger viewports.  But any parent that behaves like a ScrollViewer
            // will have a smaller view port that we need to clip against.
            for (Visual visual = This.UiScope; visual != null; visual = VisualTreeHelper.GetParent(visual) as Visual)
            {
                element = visual as FrameworkElement;
                if (element != null)
                {
                    GeneralTransform transform = visual.TransformToDescendant(This.UiScope);
                    if (transform != null)
                    {
                        ClipToElement(element, transform, ref horizontalOffset, ref verticalOffset);
                    }
                }
            }

            // Clip to the window client rect.
            PresentationSource source = PresentationSource.CriticalFromVisual(This.UiScope);
            IWin32Window window = source as IWin32Window;
            if (window != null)
            {
                IntPtr hwnd = IntPtr.Zero;
                new UIPermission(UIPermissionWindow.AllWindows).Assert(); // BlessedAssert
                try
                {
                    hwnd = window.Handle;
                }
                finally
                {
                    CodeAccessPermission.RevertAssert();
                }

                NativeMethods.RECT rc = new NativeMethods.RECT(0, 0, 0, 0);
                SafeNativeMethods.GetClientRect(new HandleRef(null, hwnd), ref rc);

                // Convert to mil measure units.
                Point minPoint = new Point(rc.left, rc.top);
                Point maxPoint = new Point(rc.right, rc.bottom);

                CompositionTarget compositionTarget = source.CompositionTarget;
                minPoint = compositionTarget.TransformFromDevice.Transform(minPoint);
                maxPoint = compositionTarget.TransformFromDevice.Transform(maxPoint);

                // Convert to local coordinates.
                GeneralTransform transform = compositionTarget.RootVisual.TransformToDescendant(This.UiScope);
                if (transform != null)
                {
                    transform.TryTransform(minPoint, out minPoint);
                    transform.TryTransform(maxPoint, out maxPoint);

                    // Finally, do the clip.
                    horizontalOffset = ClipToBounds(minPoint.X, horizontalOffset, maxPoint.X);
                    verticalOffset = ClipToBounds(minPoint.Y, verticalOffset, maxPoint.Y);
                }

                // ContextMenu code takes care of clipping to desktop.
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:80,代码来源:TextEditorContextMenu.cs


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