Ejemplo n.º 1
0
        //--------------------------------------------------------------------
        //
        // Public Properties
        //
        //---------------------------------------------------------------------

        #region Static methods

        public static FixedSOMElement CreateFixedSOMElement(FixedPage page, UIElement uiElement, FixedNode fixedNode, int startIndex, int endIndex)
        {
            FixedSOMElement element = null;

            if (uiElement is Glyphs)
            {
                Glyphs glyphs = uiElement as Glyphs;
                if (glyphs.UnicodeString.Length > 0)
                {
                    GlyphRun glyphRun     = glyphs.ToGlyphRun();
                    Rect     alignmentBox = glyphRun.ComputeAlignmentBox();
                    alignmentBox.Offset(glyphs.OriginX, glyphs.OriginY);
                    GeneralTransform transform = glyphs.TransformToAncestor(page);

                    if (startIndex < 0)
                    {
                        startIndex = 0;
                    }
                    if (endIndex < 0)
                    {
                        endIndex = glyphRun.Characters == null ? 0 : glyphRun.Characters.Count;
                    }
                    element = FixedSOMTextRun.Create(alignmentBox, transform, glyphs, fixedNode, startIndex, endIndex, false);
                }
            }
            else if (uiElement is Image)
            {
                element = FixedSOMImage.Create(page, uiElement as Image, fixedNode);
            }
            else if (uiElement is Path)
            {
                element = FixedSOMImage.Create(page, uiElement as Path, fixedNode);
            }
            return(element);
        }
Ejemplo n.º 2
0
 // Token: 0x06002DC0 RID: 11712 RVA: 0x000CDD1C File Offset: 0x000CBF1C
 private void _AddElement(FixedSOMElement element)
 {
     base.Add(element);
     if (this._semanticBoxes.Count == 1)
     {
         this._matrix         = element.Matrix;
         this._matrix.OffsetX = 0.0;
         this._matrix.OffsetY = 0.0;
     }
 }
        // Token: 0x06002D36 RID: 11574 RVA: 0x000CC224 File Offset: 0x000CA424
        private void _AddEntry(FixedSOMElement element)
        {
            FixedNode fixedNode = element.FixedNode;
            List <FixedSOMElement> list;

            if (this._mapping.ContainsKey(fixedNode))
            {
                list = (List <FixedSOMElement>) this._mapping[fixedNode];
            }
            else
            {
                list = new List <FixedSOMElement>();
                this._mapping.Add(fixedNode, list);
            }
            list.Add(element);
        }
Ejemplo n.º 4
0
        private void _AddEntry(FixedSOMElement element)
        {
            FixedNode fn = element.FixedNode;
            List <FixedSOMElement> entry;

            if (_mapping.ContainsKey(fn))
            {
                entry = (List <FixedSOMElement>)_mapping[fn];
            }
            else
            {
                entry = new List <FixedSOMElement>();
                _mapping.Add(fn, entry);
            }

            entry.Add(element);
        }
        // Token: 0x06002D17 RID: 11543 RVA: 0x000CB760 File Offset: 0x000C9960
        private void AddFixedNodeInFlow(int index, UIElement e)
        {
            if (this._visitedArray[index])
            {
                return;
            }
            FixedNode fixedNode = this._fixedNodes[index];

            if (e == null)
            {
                e = (this._fixedPage.GetElement(fixedNode) as UIElement);
            }
            this._visitedArray[index] = true;
            FixedSOMElement fixedSOMElement = FixedSOMElement.CreateFixedSOMElement(this._fixedPage, e, fixedNode, -1, -1);

            if (fixedSOMElement != null)
            {
                this._flowBuilder.AddElement(fixedSOMElement);
            }
        }
Ejemplo n.º 6
0
 // Token: 0x06002E1D RID: 11805 RVA: 0x000D04A4 File Offset: 0x000CE6A4
 private void _ConstructFixedNodes()
 {
     this._fixedNodes = new List <FixedNode>();
     foreach (FixedSOMSemanticBox fixedSOMSemanticBox in this._semanticBoxes)
     {
         FixedSOMElement fixedSOMElement = fixedSOMSemanticBox as FixedSOMElement;
         if (fixedSOMElement != null)
         {
             this._fixedNodes.Add(fixedSOMElement.FixedNode);
         }
         else
         {
             FixedSOMContainer fixedSOMContainer = fixedSOMSemanticBox as FixedSOMContainer;
             List <FixedNode>  fixedNodes        = fixedSOMContainer.FixedNodes;
             foreach (FixedNode item in fixedNodes)
             {
                 this._fixedNodes.Add(item);
             }
         }
     }
 }
Ejemplo n.º 7
0
 void _ConstructFixedNodes()
 {
     _fixedNodes = new List <FixedNode>();
     foreach (FixedSOMSemanticBox box in _semanticBoxes)
     {
         FixedSOMElement element = box as FixedSOMElement;
         if (element != null)
         {
             _fixedNodes.Add(element.FixedNode);
         }
         else
         {
             FixedSOMContainer container = box as FixedSOMContainer;
             Debug.Assert(container != null);
             List <FixedNode> nodes = container.FixedNodes;
             foreach (FixedNode node in nodes)
             {
                 _fixedNodes.Add(node);
             }
         }
     }
 }
Ejemplo n.º 8
0
        private void AddFixedNodeInFlow(int index, UIElement e)
        {
            if (_visitedArray[index])
            {
                // this has already been added to the document structure
                // Debug.Assert(false, "An element is referenced in the document structure multiple times");
                return; // ignore this reference
            }
            FixedNode fn = (FixedNode)_fixedNodes[index];

            if (e == null)
            {
                e = _fixedPage.GetElement(fn) as UIElement;
            }

            _visitedArray[index] = true;

            FixedSOMElement somElement = FixedSOMElement.CreateFixedSOMElement(_fixedPage, e, fn, -1, -1);

            if (somElement != null)
            {
                _flowBuilder.AddElement(somElement);
            }
        }
Ejemplo n.º 9
0
 internal void AddFixedElement(FixedSOMElement element)
 {
     _AddEntry(element);
 }
Ejemplo n.º 10
0
        //--------------------------------------------------------------------
        // TextContainer Element
        //---------------------------------------------------------------------

        // given a TextPointer range, find out all fixed position included in this range and
        // offset into the begin and end fixed element
        private bool _GetFixedNodesForFlowRange(ITextPointer start, ITextPointer end, out FixedSOMElement[] elements, out int startIndex, out int endIndex)
        {
            Debug.Assert(start.CompareTo(end) <= 0);
            elements  = null;
            startIndex = 0;
            endIndex = 0;

            if (start.CompareTo(end) == 0)
            {
                return false;
            }

            FixedTextPointer pStart    = (FixedTextPointer)start;
            FixedTextPointer pEnd      = (FixedTextPointer)end;

            return this.FixedTextBuilder.GetFixedNodesForFlowRange(pStart.FlowPosition, pEnd.FlowPosition, out elements, out startIndex, out endIndex);
        } //endofGetFixedNodes
Ejemplo n.º 11
0
        // Token: 0x06002EA1 RID: 11937 RVA: 0x000D2BCC File Offset: 0x000D0DCC
        internal void GetMultiHighlights(FixedTextPointer start, FixedTextPointer end, Dictionary <FixedPage, ArrayList> highlights, FixedHighlightType t, Brush foregroundBrush, Brush backgroundBrush)
        {
            if (start.CompareTo(end) > 0)
            {
                FixedTextPointer fixedTextPointer = start;
                start = end;
                end   = fixedTextPointer;
            }
            int num  = 0;
            int num2 = 0;

            FixedSOMElement[] array;
            if (this._GetFixedNodesForFlowRange(start, end, out array, out num, out num2))
            {
                for (int i = 0; i < array.Length; i++)
                {
                    FixedSOMElement fixedSOMElement = array[i];
                    FixedNode       fixedNode       = fixedSOMElement.FixedNode;
                    FixedPage       fixedPage       = this.FixedDocument.SyncGetPageWithCheck(fixedNode.Page);
                    if (fixedPage != null)
                    {
                        DependencyObject element = fixedPage.GetElement(fixedNode);
                        if (element != null)
                        {
                            int       num3 = 0;
                            UIElement element2;
                            int       num4;
                            if (element is Image || element is Path)
                            {
                                element2 = (UIElement)element;
                                num4     = 1;
                            }
                            else
                            {
                                Glyphs glyphs = element as Glyphs;
                                if (glyphs == null)
                                {
                                    goto IL_144;
                                }
                                element2 = (UIElement)element;
                                num3     = fixedSOMElement.StartIndex;
                                num4     = fixedSOMElement.EndIndex;
                            }
                            if (i == 0)
                            {
                                num3 = num;
                            }
                            if (i == array.Length - 1)
                            {
                                num4 = num2;
                            }
                            ArrayList arrayList;
                            if (highlights.ContainsKey(fixedPage))
                            {
                                arrayList = highlights[fixedPage];
                            }
                            else
                            {
                                arrayList = new ArrayList();
                                highlights.Add(fixedPage, arrayList);
                            }
                            FixedSOMTextRun fixedSOMTextRun = fixedSOMElement as FixedSOMTextRun;
                            if (fixedSOMTextRun != null && fixedSOMTextRun.IsReversed)
                            {
                                int num5 = num3;
                                num3 = fixedSOMElement.EndIndex - num4;
                                num4 = fixedSOMElement.EndIndex - num5;
                            }
                            FixedHighlight value = new FixedHighlight(element2, num3, num4, t, foregroundBrush, backgroundBrush);
                            arrayList.Add(value);
                        }
                    }
                    IL_144 :;
                }
            }
        }
Ejemplo n.º 12
0
        // Get the highlights, in Glyphs granularity, that covers this range
        internal void GetMultiHighlights(FixedTextPointer start, FixedTextPointer end, Dictionary <FixedPage, ArrayList> highlights, FixedHighlightType t,
                                         Brush foregroundBrush, Brush backgroundBrush)
        {
            Debug.Assert(highlights != null);
            if (start.CompareTo(end) > 0)
            {
                // make sure start <= end
                FixedTextPointer temp = start;
                start = end;
                end   = temp;
            }

            FixedSOMElement[] elements;
            //Start and end indices in selection for first and last FixedSOMElements respectively
            int startIndex = 0;
            int endIndex   = 0;

            if (_GetFixedNodesForFlowRange(start, end, out elements, out startIndex, out endIndex))
            {
                for (int i = 0; i < elements.Length; i++)
                {
                    FixedSOMElement elem = elements[i];

                    FixedNode fn = elem.FixedNode;
                    // Get the FixedPage if possible
                    FixedPage page = this.FixedDocument.SyncGetPageWithCheck(fn.Page);
                    if (page == null)
                    {
                        continue;
                    }

                    DependencyObject o = page.GetElement(fn);
                    if (o == null)
                    {
                        continue;
                    }

                    int       beginOffset = 0;
                    int       endOffset;
                    UIElement e;
                    if (o is Image || o is Path)
                    {
                        e         = (UIElement)o;
                        endOffset = 1;
                    }
                    else
                    {
                        Glyphs g = o as Glyphs;
                        if (g == null)
                        {
                            continue;
                        }
                        e           = (UIElement)o;
                        beginOffset = elem.StartIndex;
                        endOffset   = elem.EndIndex;
                    }

                    if (i == 0)
                    {
                        beginOffset = startIndex;
                    }

                    if (i == elements.Length - 1)
                    {
                        endOffset = endIndex;
                    }

                    ArrayList lfs;
                    if (highlights.ContainsKey(page))
                    {
                        lfs = highlights[page];
                    }
                    else
                    {
                        lfs = new ArrayList();
                        highlights.Add(page, lfs);
                    }

                    FixedSOMTextRun textRun = elem as FixedSOMTextRun;
                    if (textRun != null && textRun.IsReversed)
                    {
                        int oldBeginOffset = beginOffset;
                        beginOffset = elem.EndIndex - endOffset;
                        endOffset   = elem.EndIndex - oldBeginOffset;
                    }

                    FixedHighlight fh = new FixedHighlight(e, beginOffset, endOffset, t, foregroundBrush, backgroundBrush);
                    lfs.Add(fh);
                }
            }
        }
Ejemplo n.º 13
0
 internal void AddFixedElement(FixedSOMElement element)
 {
     _AddEntry(element);
 }
Ejemplo n.º 14
0
        // Token: 0x06002DFC RID: 11772 RVA: 0x000CEDF0 File Offset: 0x000CCFF0
        private bool _IsCombinable(FixedSOMFixedBlock fixedBlock, FixedSOMTextRun textRun)
        {
            if (fixedBlock.SemanticBoxes.Count == 0)
            {
                return(false);
            }
            if (fixedBlock.IsFloatingImage)
            {
                return(false);
            }
            Rect            boundingRect     = textRun.BoundingRect;
            Rect            boundingRect2    = fixedBlock.BoundingRect;
            FixedSOMTextRun fixedSOMTextRun  = null;
            FixedSOMTextRun fixedSOMTextRun2 = fixedBlock.SemanticBoxes[fixedBlock.SemanticBoxes.Count - 1] as FixedSOMTextRun;

            if (fixedSOMTextRun2 != null && boundingRect.Bottom <= fixedSOMTextRun2.BoundingRect.Top)
            {
                return(false);
            }
            bool   flag  = false;
            bool   flag2 = false;
            double num   = boundingRect.Height * 0.2;

            if (boundingRect.Bottom - num < boundingRect2.Top)
            {
                flag            = true;
                fixedSOMTextRun = (fixedBlock.SemanticBoxes[0] as FixedSOMTextRun);
            }
            else if (boundingRect.Top + num > boundingRect2.Bottom)
            {
                flag2           = true;
                fixedSOMTextRun = (fixedBlock.SemanticBoxes[fixedBlock.SemanticBoxes.Count - 1] as FixedSOMTextRun);
            }
            if ((fixedBlock.IsWhiteSpace || textRun.IsWhiteSpace) && (fixedBlock != this._currentFixedBlock || fixedSOMTextRun != null || !this._IsSpatiallyCombinable(boundingRect2, boundingRect, textRun.DefaultCharWidth * 3.0, 0.0)))
            {
                return(false);
            }
            if (fixedBlock.Matrix.M11 != textRun.Matrix.M11 || fixedBlock.Matrix.M12 != textRun.Matrix.M12 || fixedBlock.Matrix.M21 != textRun.Matrix.M21 || fixedBlock.Matrix.M22 != textRun.Matrix.M22)
            {
                return(false);
            }
            if (fixedSOMTextRun != null)
            {
                double num2 = fixedBlock.LineHeight / boundingRect.Height;
                if (num2 < 1.0)
                {
                    num2 = 1.0 / num2;
                }
                if (num2 > 1.1 && !FixedTextBuilder.IsSameLine(fixedSOMTextRun.BoundingRect.Top - boundingRect.Top, boundingRect.Height, fixedSOMTextRun.BoundingRect.Height))
                {
                    return(false);
                }
            }
            double num3 = textRun.DefaultCharWidth;

            if (num3 < 1.0)
            {
                num3 = 1.0;
            }
            double num4 = fixedBlock.LineHeight / boundingRect.Height;

            if (num4 < 1.0)
            {
                num4 = 1.0 / num4;
            }
            double inflateH;

            if (fixedBlock == this._currentFixedBlock && fixedSOMTextRun == null && num4 < 1.5)
            {
                inflateH = 200.0;
            }
            else
            {
                inflateH = num3 * 1.5;
            }
            if (!this._IsSpatiallyCombinable(boundingRect2, boundingRect, inflateH, boundingRect.Height * 0.7))
            {
                return(false);
            }
            FixedSOMElement fixedSOMElement = fixedBlock.SemanticBoxes[fixedBlock.SemanticBoxes.Count - 1] as FixedSOMElement;

            if (fixedSOMElement != null && fixedSOMElement.FixedNode.CompareTo(textRun.FixedNode) == 0)
            {
                return(false);
            }
            if (flag || flag2)
            {
                double num5 = boundingRect.Height * 0.2;
                double top;
                double bottom;
                if (flag2)
                {
                    top    = boundingRect2.Bottom - num5;
                    bottom = boundingRect.Top + num5;
                }
                else
                {
                    top    = boundingRect.Bottom - num5;
                    bottom = boundingRect2.Top + num5;
                }
                double left  = (boundingRect2.Left > boundingRect.Left) ? boundingRect2.Left : boundingRect.Left;
                double right = (boundingRect2.Right < boundingRect.Right) ? boundingRect2.Right : boundingRect.Right;
                return(!this._lines.IsHorizontallySeparated(left, top, right, bottom));
            }
            double num6 = (boundingRect2.Right < boundingRect.Right) ? boundingRect2.Right : boundingRect.Right;
            double num7 = (boundingRect2.Left > boundingRect.Left) ? boundingRect2.Left : boundingRect.Left;

            if (FrameworkAppContextSwitches.OptOutOfFixedDocumentModelConstructionFix)
            {
                if (num6 > num7)
                {
                    double num8 = num6;
                    num6 = num7;
                    num7 = num8;
                }
                return(!this._lines.IsVerticallySeparated(num6, boundingRect.Top, num7, boundingRect.Bottom));
            }
            return(num6 >= num7 || !this._lines.IsVerticallySeparated(num6, boundingRect.Top, num7, boundingRect.Bottom));
        }
Ejemplo n.º 15
0
        private void _AddEntry(FixedSOMElement element)
        {
            FixedNode fn = element.FixedNode;
            List<FixedSOMElement> entry;
            if (_mapping.ContainsKey(fn))
            {
                entry = (List<FixedSOMElement>)_mapping[fn];
            }
            else
            {
                entry = new List<FixedSOMElement>();
                _mapping.Add(fn, entry);
            }

            entry.Add(element);
        }
Ejemplo n.º 16
0
        private bool _IsCombinable(FixedSOMFixedBlock fixedBlock, FixedSOMTextRun textRun)
        {
            Debug.Assert(fixedBlock.SemanticBoxes.Count > 0);
            if (fixedBlock.SemanticBoxes.Count == 0)
            {
                return(false);
            }

            //Currently we do not support inline images
            if (fixedBlock.IsFloatingImage)
            {
                return(false);
            }

            Rect textRunRect    = textRun.BoundingRect;
            Rect fixedBlockRect = fixedBlock.BoundingRect;

            FixedSOMTextRun compareLine = null;
            FixedSOMTextRun lastLine    = fixedBlock.SemanticBoxes[fixedBlock.SemanticBoxes.Count - 1] as FixedSOMTextRun;

            if (lastLine != null && textRunRect.Bottom <= lastLine.BoundingRect.Top)
            {
                //This run is above the last run of the fixed block. Can't be the same paragraph
                return(false);
            }

            bool fixedBlockBelow = false;
            bool textRunBelow    = false;
            //Allow 20% overlap
            double verticalOverlap = textRunRect.Height * 0.2;

            if (textRunRect.Bottom - verticalOverlap < fixedBlockRect.Top)
            {
                fixedBlockBelow = true;
                compareLine     = fixedBlock.SemanticBoxes[0] as FixedSOMTextRun;
            }
            else if (textRunRect.Top + verticalOverlap > fixedBlockRect.Bottom)
            {
                textRunBelow = true;
                compareLine  = fixedBlock.SemanticBoxes[fixedBlock.SemanticBoxes.Count - 1] as FixedSOMTextRun;
            }

            if ((fixedBlock.IsWhiteSpace || textRun.IsWhiteSpace) &&
                (fixedBlock != _currentFixedBlock || compareLine != null || !_IsSpatiallyCombinable(fixedBlockRect, textRunRect, textRun.DefaultCharWidth * 3, 0))
                )
            {
                //When combining with white spaces, they need to be consecutive in markup and need to be on the same line.
                return(false);
            }
            if (fixedBlock.Matrix.M11 != textRun.Matrix.M11 ||
                fixedBlock.Matrix.M12 != textRun.Matrix.M12 ||
                fixedBlock.Matrix.M21 != textRun.Matrix.M21 ||
                fixedBlock.Matrix.M22 != textRun.Matrix.M22)
            {
                //We don't allow combining TextRuns with different scale/rotation properties
                return(false);
            }

            Debug.Assert(textRunRect.Height != 0 && fixedBlock.LineHeight != 0);

            //Rect textRunRect = textRun.BoundingRect;

            if (compareLine != null) //Most probably different lines
            {
                double ratio = fixedBlock.LineHeight / textRunRect.Height;
                if (ratio < 1.0)
                {
                    ratio = 1.0 / ratio;
                }
                //Allow 10% height difference
                if ((ratio > 1.1) &&
                    !(FixedTextBuilder.IsSameLine(compareLine.BoundingRect.Top - textRunRect.Top, textRunRect.Height, compareLine.BoundingRect.Height)))
                {
                    return(false);
                }
            }

            double width = textRun.DefaultCharWidth;

            if (width < 1.0)
            {
                width = 1.0;
            }

            double dHorInflate = 0;
            double heightRatio = fixedBlock.LineHeight / textRunRect.Height;

            if (heightRatio < 1.0)
            {
                heightRatio = 1.0 / heightRatio;
            }

            //If consecutive in markup and seem to be on the same line, almost discard horizontal distance
            if (fixedBlock == _currentFixedBlock &&
                compareLine == null &&
                heightRatio < 1.5
                )
            {
                dHorInflate = 200;
            }
            else
            {
                dHorInflate = width * 1.5;
            }

            if (!_IsSpatiallyCombinable(fixedBlockRect, textRunRect, dHorInflate, textRunRect.Height * 0.7))
            {
                return(false);
            }

            //If these two have originated from the same Glyphs element, this means we intentionally separated them (separated by vertical lines).
            //Don't combine in this case.
            FixedSOMElement element = fixedBlock.SemanticBoxes[fixedBlock.SemanticBoxes.Count - 1] as FixedSOMElement;

            if (element != null && element.FixedNode.CompareTo(textRun.FixedNode) == 0)
            {
                return(false);
            }

            //Are these seperated by a line? Check only if they are not considered overlapping
            if (fixedBlockBelow || textRunBelow)
            {
                double bottom = 0.0;
                double top    = 0.0;
                double margin = textRunRect.Height * 0.2;

                if (textRunBelow)
                {
                    top    = fixedBlockRect.Bottom - margin;
                    bottom = textRunRect.Top + margin;
                }
                else
                {
                    top    = textRunRect.Bottom - margin;
                    bottom = fixedBlockRect.Top + margin;
                }
                double left  = (fixedBlockRect.Left > textRunRect.Left) ? fixedBlockRect.Left : textRunRect.Left;
                double right = (fixedBlockRect.Right < textRunRect.Right) ? fixedBlockRect.Right: textRunRect.Right;
                return(!_lines.IsHorizontallySeparated(left, top, right, bottom));
            }
            else
            {
                //These two overlap vertically. Let's check whether there is a vertical separator in between
                double left  = (fixedBlockRect.Right < textRunRect.Right) ? fixedBlockRect.Right: textRunRect.Right;
                double right = (fixedBlockRect.Left > textRunRect.Left) ? fixedBlockRect.Left: textRunRect.Left;
                if (left > right)
                {
                    double temp = left;
                    left  = right;
                    right = temp;
                }
                return(!_lines.IsVerticallySeparated(left, textRunRect.Top, right, textRunRect.Bottom));
            }
        }
Ejemplo n.º 17
0
        private void _AddElement(FixedSOMElement element) 
        {
            base.Add(element);

            if (_semanticBoxes.Count == 1) 
            {
                _matrix = element.Matrix; 
                _matrix.OffsetX = 0; 
                _matrix.OffsetY = 0;
            } 
        }