Пример #1
0
        // ------------------------------------------------------------------
        // Fetch the next run at UIElment position.
        //
        //      position - current position in the text array
        //      dcp - current position in the text array
        // ------------------------------------------------------------------
        private TextRun HandleInlineObject(StaticTextPointer position, int dcp)
        {
            Debug.Assert(position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.EmbeddedElement, "TextPointer does not point to embedded object.");

            TextRun          run     = null;
            DependencyObject element = position.GetAdjacentElement(LogicalDirection.Forward) as DependencyObject;

            if (element is UIElement)
            {
                //


                TextRunProperties textProps = new TextProperties(element, position, true /* inline objects */, true /* get background */);

                // Create object run.
                run = new InlineObject(dcp, TextContainerHelper.EmbeddedObjectLength, (UIElement)element, textProps, _owner);
            }
            else
            {
                // If the embedded object is of an unknown type (not UIElement),
                // treat it as element edge.
                run = HandleElementEndEdge(position);
            }
            return(run);
        }
        // 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;
            }
        }
        // Token: 0x06006609 RID: 26121 RVA: 0x001CB1DC File Offset: 0x001C93DC
        private TextRun HandleInlineObject(StaticTextPointer position, int dcp)
        {
            DependencyObject dependencyObject = position.GetAdjacentElement(LogicalDirection.Forward) as DependencyObject;
            TextRun          result;

            if (dependencyObject is UIElement)
            {
                TextRunProperties textProps = new TextProperties(dependencyObject, position, true, true, base.PixelsPerDip);
                result = new InlineObject(dcp, TextContainerHelper.EmbeddedObjectLength, (UIElement)dependencyObject, textProps, this._owner);
            }
            else
            {
                result = this.HandleElementEndEdge(position);
            }
            return(result);
        }
Пример #4
0
        //-------------------------------------------------------------------
        // Measure child UIElement.
        //
        //      inlineObject - hosted inline object to measure.
        //
        // Returns: Size of the inline object.
        //-------------------------------------------------------------------
        internal Size MeasureChild(InlineObject inlineObject)
        {
            Debug.Assert(_complexContent != null, "Inline objects are supported only in complex content.");

            Size desiredSize;
            // Measure child only during measure pass. If not during measuring
            // use RenderSize.
            if (CheckFlags(Flags.MeasureInProgress))
            {
                // Measure inline objects. Original size constraint is passed,
                // because inline object size should not be dependent on position
                // inside a text line. It should not be also bigger than Text itself.
                Thickness padding = this.Padding;
                Size contentSize = new Size(Math.Max(0.0, _referenceSize.Width - (padding.Left + padding.Right)),
                                            Math.Max(0.0, _referenceSize.Height - (padding.Top + padding.Bottom)));
                inlineObject.Element.Measure(contentSize);
                desiredSize = inlineObject.Element.DesiredSize;

                // Store inline object in the cache.
                ArrayList inlineObjects = InlineObjects;
                bool alreadyCached = false;
                if (inlineObjects == null)
                {
                    InlineObjects = inlineObjects = new ArrayList(1);
                }
                else
                {
                    // Find out if inline object is already cached.
                    for (int index = 0; index < inlineObjects.Count; index++)
                    {
                        if (((InlineObject)inlineObjects[index]).Dcp == inlineObject.Dcp)
                        {
                            Debug.Assert(((InlineObject)inlineObjects[index]).Element == inlineObject.Element, "InlineObject cache is out of [....].");
                            alreadyCached = true;
                            break;
                        }
                    }
                }
                if (!alreadyCached)
                {
                    inlineObjects.Add(inlineObject);
                }
            }
            else
            {
                desiredSize = inlineObject.Element.DesiredSize;
            }
            return desiredSize;
        }
Пример #5
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;
            }
        }