// Token: 0x06006603 RID: 26115 RVA: 0x001CABCC File Offset: 0x001C8DCC
        internal override void Arrange(VisualCollection vc, Vector lineOffset)
        {
            int num = this._dcp;
            IList <TextSpan <TextRun> > textRunSpans = this._line.GetTextRunSpans();
            double num2 = lineOffset.X + base.CalculateXOffsetShift();

            foreach (TextSpan <TextRun> textSpan in textRunSpans)
            {
                TextRun value = textSpan.Value;
                if (value is InlineObject)
                {
                    InlineObject inlineObject = value as InlineObject;
                    Visual       visual       = VisualTreeHelper.GetParent(inlineObject.Element) as Visual;
                    if (visual != null)
                    {
                        ContainerVisual containerVisual = visual as ContainerVisual;
                        Invariant.Assert(containerVisual != null, "parent should always derives from ContainerVisual");
                        containerVisual.Children.Remove(inlineObject.Element);
                    }
                    FlowDirection   flowDirection;
                    Rect            boundsFromPosition = base.GetBoundsFromPosition(num, inlineObject.Length, out flowDirection);
                    ContainerVisual containerVisual2   = new ContainerVisual();
                    if (inlineObject.Element is FrameworkElement)
                    {
                        FlowDirection    childFD = this._owner.FlowDirection;
                        DependencyObject parent  = ((FrameworkElement)inlineObject.Element).Parent;
                        if (parent != null)
                        {
                            childFD = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                        }
                        PtsHelper.UpdateMirroringTransform(this._owner.FlowDirection, childFD, containerVisual2, boundsFromPosition.Width);
                    }
                    vc.Add(containerVisual2);
                    if (this._owner.UseLayoutRounding)
                    {
                        DpiScale dpi = this._owner.GetDpi();
                        containerVisual2.Offset = new Vector(UIElement.RoundLayoutValue(lineOffset.X + boundsFromPosition.Left, dpi.DpiScaleX), UIElement.RoundLayoutValue(lineOffset.Y + boundsFromPosition.Top, dpi.DpiScaleY));
                    }
                    else
                    {
                        containerVisual2.Offset = new Vector(lineOffset.X + boundsFromPosition.Left, lineOffset.Y + boundsFromPosition.Top);
                    }
                    containerVisual2.Children.Add(inlineObject.Element);
                    inlineObject.Element.Arrange(new Rect(inlineObject.Element.DesiredSize));
                }
                num += textSpan.Length;
            }
        }
예제 #2
0
        // Token: 0x06007033 RID: 28723 RVA: 0x00203B70 File Offset: 0x00201D70
        protected sealed override Size ArrangeOverride(Size arrangeSize)
        {
            Rect empty = Rect.Empty;
            bool flag  = false;
            Size size  = arrangeSize;

            if (!this._suspendLayout)
            {
                TextDpi.SnapToTextDpi(ref size);
                if (this.Document != null)
                {
                    this.EnsureFormatter();
                    if (this._scrollData != null)
                    {
                        if (!DoubleUtil.AreClose(this._scrollData.Viewport, size))
                        {
                            this._scrollData.Viewport = size;
                            flag = true;
                        }
                        if (!DoubleUtil.AreClose(this._scrollData.Extent, this._formatter.DocumentPage.Size))
                        {
                            this._scrollData.Extent = this._formatter.DocumentPage.Size;
                            flag = true;
                            if (Math.Abs(this._scrollData.ExtentWidth - this._scrollData.ViewportWidth) < 1.0)
                            {
                                this._scrollData.ExtentWidth = this._scrollData.ViewportWidth;
                            }
                            if (Math.Abs(this._scrollData.ExtentHeight - this._scrollData.ViewportHeight) < 1.0)
                            {
                                this._scrollData.ExtentHeight = this._scrollData.ViewportHeight;
                            }
                        }
                        Vector vector = new Vector(Math.Max(0.0, Math.Min(this._scrollData.ExtentWidth - this._scrollData.ViewportWidth, this._scrollData.HorizontalOffset)), Math.Max(0.0, Math.Min(this._scrollData.ExtentHeight - this._scrollData.ViewportHeight, this._scrollData.VerticalOffset)));
                        if (!DoubleUtil.AreClose(vector, this._scrollData.Offset))
                        {
                            this._scrollData.Offset = vector;
                            flag = true;
                        }
                        if (flag && this._scrollData.ScrollOwner != null)
                        {
                            this._scrollData.ScrollOwner.InvalidateScrollInfo();
                        }
                        empty = new Rect(this._scrollData.HorizontalOffset, this._scrollData.VerticalOffset, size.Width, size.Height);
                    }
                    this._formatter.Arrange(size, empty);
                    if (this._pageVisual != this._formatter.DocumentPage.Visual)
                    {
                        if (this._textView != null)
                        {
                            this._textView.OnPageConnected();
                        }
                        if (this._pageVisual != null)
                        {
                            base.RemoveVisualChild(this._pageVisual);
                        }
                        this._pageVisual = (PageVisual)this._formatter.DocumentPage.Visual;
                        base.AddVisualChild(this._pageVisual);
                    }
                    if (this._scrollData != null)
                    {
                        this._pageVisual.Offset = new Vector(-this._scrollData.HorizontalOffset, -this._scrollData.VerticalOffset);
                    }
                    PtsHelper.UpdateMirroringTransform(base.FlowDirection, FlowDirection.LeftToRight, this._pageVisual, size.Width);
                }
                else
                {
                    if (this._pageVisual != null)
                    {
                        if (this._textView != null)
                        {
                            this._textView.OnPageDisconnected();
                        }
                        base.RemoveVisualChild(this._pageVisual);
                        this._pageVisual = null;
                    }
                    if (this._scrollData != null)
                    {
                        if (!DoubleUtil.AreClose(this._scrollData.Viewport, size))
                        {
                            this._scrollData.Viewport = size;
                            flag = true;
                        }
                        if (!DoubleUtil.AreClose(this._scrollData.Extent, default(Size)))
                        {
                            this._scrollData.Extent = default(Size);
                            flag = true;
                        }
                        if (!DoubleUtil.AreClose(this._scrollData.Offset, default(Vector)))
                        {
                            this._scrollData.Offset = default(Vector);
                            flag = true;
                        }
                        if (flag && this._scrollData.ScrollOwner != null)
                        {
                            this._scrollData.ScrollOwner.InvalidateScrollInfo();
                        }
                    }
                }
            }
            return(arrangeSize);
        }
예제 #3
0
        // ------------------------------------------------------------------
        // Arrange content of formatted line.
        //
        //      vc - Visual collection of the parent.
        //      lineOffset - Offset of the line.
        // ------------------------------------------------------------------
        internal override void Arrange(VisualCollection vc, Vector lineOffset)
        {
            // Arrange inline objects
            int runDcp = _dcp;
            IList <TextSpan <TextRun> > runs = _line.GetTextRunSpans();

            Debug.Assert(runs != null, "Cannot retrieve runs collection.");

            // Calculate offset shift due to trailing spaces
            double adjustedXOffset = lineOffset.X + CalculateXOffsetShift();

            foreach (TextSpan <TextRun> textSpan in runs)
            {
                TextRun run = textSpan.Value;
                if (run is InlineObject)
                {
                    InlineObject inlineObject = run as InlineObject;

                    // Disconnect visual from its old parent, if necessary.
                    Visual currentParent = VisualTreeHelper.GetParent(inlineObject.Element) as Visual;
                    if (currentParent != null)
                    {
                        ContainerVisual parent = currentParent as ContainerVisual;
                        Invariant.Assert(parent != null, "parent should always derives from ContainerVisual");
                        parent.Children.Remove(inlineObject.Element);
                    }

                    // Get position of inline object withing the text line.
                    FlowDirection flowDirection;
                    Rect          rect = GetBoundsFromPosition(runDcp, inlineObject.Length, out flowDirection);
                    Debug.Assert(DoubleUtil.GreaterThanOrClose(rect.Width, 0), "Negative inline object's width.");

                    ContainerVisual proxyVisual = new ContainerVisual();
                    if (inlineObject.Element is FrameworkElement)
                    {
                        FlowDirection parentFlowDirection = _owner.FlowDirection;
                        // Check parent's FlowDirection to determine if mirroring is needed

                        DependencyObject parent = ((FrameworkElement)inlineObject.Element).Parent;
                        if (parent != null)
                        {
                            parentFlowDirection = (FlowDirection)parent.GetValue(FrameworkElement.FlowDirectionProperty);
                        }

                        PtsHelper.UpdateMirroringTransform(_owner.FlowDirection, parentFlowDirection, proxyVisual, rect.Width);
                    }
                    vc.Add(proxyVisual);

                    if (_owner.UseLayoutRounding)
                    {
                        // If using layout rounding, check whether rounding needs to compensate for high DPI
                        proxyVisual.Offset = new Vector(UIElement.RoundLayoutValue(lineOffset.X + rect.Left, FrameworkElement.DpiScaleX),
                                                        UIElement.RoundLayoutValue(lineOffset.Y + rect.Top, FrameworkElement.DpiScaleY));
                    }
                    else
                    {
                        proxyVisual.Offset = new Vector(lineOffset.X + rect.Left, lineOffset.Y + rect.Top);
                    }
                    proxyVisual.Children.Add(inlineObject.Element);

                    // Combine text line offset (relative to the Text control) with inline object
                    // offset (relative to the line) and set transorm on the visual. Trailing spaces
                    // shift is not added here because it is returned by GetBoundsFromPosition
                    inlineObject.Element.Arrange(new Rect(inlineObject.Element.DesiredSize));
                }

                // Do not use TextRun.Length, because it gives total length of the run.
                // So, if the run is broken between lines, it gives incorrect value.
                // Use length of the TextSpan instead, which gives the correct length here.
                runDcp += textSpan.Length;
            }
        }
예제 #4
0
        /// <summary>
        /// Content arrangement.
        /// </summary>
        /// <param name="arrangeSize">Size that element should use to arrange itself and its children.</param>
        protected sealed override Size ArrangeOverride(Size arrangeSize)
        {
            Rect   viewport = Rect.Empty;
            Vector offset;
            bool   invalidateScrollInfo = false;
            Size   safeArrangeSize      = arrangeSize;

            if (!_suspendLayout)
            {
                // Convert to TextDpi and convert back to double, to make sure that we are not
                // getting rounding errors later.
                TextDpi.SnapToTextDpi(ref safeArrangeSize);

                if (Document != null)
                {
                    // Create bottomless formatter, if necessary.
                    EnsureFormatter();

                    // Arrange bottomless content.
                    if (_scrollData != null)
                    {
                        if (!DoubleUtil.AreClose(_scrollData.Viewport, safeArrangeSize))
                        {
                            _scrollData.Viewport = safeArrangeSize;
                            invalidateScrollInfo = true;
                        }

                        if (!DoubleUtil.AreClose(_scrollData.Extent, _formatter.DocumentPage.Size))
                        {
                            _scrollData.Extent   = _formatter.DocumentPage.Size;
                            invalidateScrollInfo = true;
                            // DocumentPage Size is calculated by converting double to int and then back to double.
                            // This conversion may produce rounding errors and force us to show scrollbars in cases
                            // when extent is within 1px from viewport. To workaround this issue, snap extent to viewport
                            // if we are within 1px range.
                            if (Math.Abs(_scrollData.ExtentWidth - _scrollData.ViewportWidth) < 1)
                            {
                                _scrollData.ExtentWidth = _scrollData.ViewportWidth;
                            }
                            if (Math.Abs(_scrollData.ExtentHeight - _scrollData.ViewportHeight) < 1)
                            {
                                _scrollData.ExtentHeight = _scrollData.ViewportHeight;
                            }
                        }
                        offset = new Vector(
                            Math.Max(0, Math.Min(_scrollData.ExtentWidth - _scrollData.ViewportWidth, _scrollData.HorizontalOffset)),
                            Math.Max(0, Math.Min(_scrollData.ExtentHeight - _scrollData.ViewportHeight, _scrollData.VerticalOffset)));
                        if (!DoubleUtil.AreClose(offset, _scrollData.Offset))
                        {
                            _scrollData.Offset   = offset;
                            invalidateScrollInfo = true;
                        }
                        if (invalidateScrollInfo && _scrollData.ScrollOwner != null)
                        {
                            _scrollData.ScrollOwner.InvalidateScrollInfo();
                        }
                        viewport = new Rect(_scrollData.HorizontalOffset, _scrollData.VerticalOffset, safeArrangeSize.Width, safeArrangeSize.Height);
                    }
                    _formatter.Arrange(safeArrangeSize, viewport);

                    // Connect to visual tree.
                    if (_pageVisual != _formatter.DocumentPage.Visual)
                    {
                        if (_textView != null)
                        {
                            _textView.OnPageConnected();
                        }
                        if (_pageVisual != null)
                        {
                            RemoveVisualChild(_pageVisual);
                        }
                        _pageVisual = (PageVisual)_formatter.DocumentPage.Visual;
                        AddVisualChild(_pageVisual);
                    }

                    // Set appropriate content offset
                    if (_scrollData != null)
                    {
                        _pageVisual.Offset = new Vector(-_scrollData.HorizontalOffset, -_scrollData.VerticalOffset);
                    }

                    // DocumentPage.Visual is always returned in LeftToRight FlowDirection.
                    // Hence, if the the current FlowDirection is RightToLeft,
                    // mirroring transform need to be applied to the content.
                    PtsHelper.UpdateMirroringTransform(FlowDirection, FlowDirection.LeftToRight, _pageVisual, safeArrangeSize.Width);
                }
                else
                {
                    if (_pageVisual != null)
                    {
                        if (_textView != null)
                        {
                            _textView.OnPageDisconnected();
                        }
                        RemoveVisualChild(_pageVisual);
                        _pageVisual = null;
                    }
                    // Arrange bottomless content.
                    if (_scrollData != null)
                    {
                        if (!DoubleUtil.AreClose(_scrollData.Viewport, safeArrangeSize))
                        {
                            _scrollData.Viewport = safeArrangeSize;
                            invalidateScrollInfo = true;
                        }
                        if (!DoubleUtil.AreClose(_scrollData.Extent, new Size()))
                        {
                            _scrollData.Extent   = new Size();
                            invalidateScrollInfo = true;
                        }
                        if (!DoubleUtil.AreClose(_scrollData.Offset, new Vector()))
                        {
                            _scrollData.Offset   = new Vector();
                            invalidateScrollInfo = true;
                        }
                        if (invalidateScrollInfo && _scrollData.ScrollOwner != null)
                        {
                            _scrollData.ScrollOwner.InvalidateScrollInfo();
                        }
                    }
                }
            }
            return(arrangeSize);
        }