Beispiel #1
0
        internal int GetPageNumber(ITextPointer textPointer)
        {
            FixedTextPointer fixedTextPointer = textPointer as FixedTextPointer;
            int pageNumber = int.MaxValue;

            if (fixedTextPointer != null)
            {
                if (fixedTextPointer.CompareTo(((ITextContainer)this).Start) == 0)
                {
                    pageNumber = 0;
                }
                else if (fixedTextPointer.CompareTo(((ITextContainer)this).End) == 0)
                {
                    pageNumber = this.FixedDocument.PageCount - 1;
                }
                else
                {
                    FlowNode flowNode;
                    int      flowOffset;

                    fixedTextPointer.FlowPosition.GetFlowNode(fixedTextPointer.LogicalDirection, out flowNode, out flowOffset);

                    FixedElement fixedElement = flowNode.Cookie as FixedElement;

                    if (flowNode.Type == FlowNodeType.Boundary)
                    {
                        if (flowNode.Fp > 0)
                        {
                            //Document end boundary node
                            pageNumber = this.FixedDocument.PageCount - 1;
                        }
                        else
                        {
                            //Document start boundary node
                            pageNumber = 0;
                        }
                    }
                    else if (flowNode.Type == FlowNodeType.Virtual || flowNode.Type == FlowNodeType.Noop)
                    {
                        pageNumber = (int)flowNode.Cookie;
                    }
                    else if (fixedElement != null)
                    {
                        pageNumber = (int)fixedElement.PageIndex;
                    }
                    else
                    {
                        FixedPosition fixPos;
                        bool          res = FixedTextBuilder.GetFixedPosition(fixedTextPointer.FlowPosition, fixedTextPointer.LogicalDirection, out fixPos);
                        Debug.Assert(res);
                        if (res)
                        {
                            pageNumber = fixPos.Page;
                        }
                    }
                }
            }

            return(pageNumber);
        }
Beispiel #2
0
        //--------------------------------------------------------------------
        //
        // Private Methods
        //
        //---------------------------------------------------------------------

        #region Private Methods

        //--------------------------------------------------------------------
        // Initilization
        //---------------------------------------------------------------------
        private void _CreateEmptyContainer()
        {
            // new text builder with map
            _fixedTextBuilder = new FixedTextBuilder(this);

            // create initial TextPointer and container element
            _start = new  FixedTextPointer(false, LogicalDirection.Backward, new FlowPosition(this, this.FixedTextBuilder.FixedFlowMap.FlowStartEdge, 1));
            _end   = new FixedTextPointer(false, LogicalDirection.Forward, new FlowPosition(this, this.FixedTextBuilder.FixedFlowMap.FlowEndEdge, 0));

            _containerElement = new FixedElement(FixedElement.ElementType.Container, _start, _end, int.MaxValue);
            _start.FlowPosition.AttachElement(_containerElement);
            _end.FlowPosition.AttachElement(_containerElement);
        }
        int IComparable.CompareTo(object comparedObj)
        {
            FixedSOMTextRun otherRun = comparedObj as FixedSOMTextRun;

            Debug.Assert(otherRun != null);
            int result = 0;

            if (_fixedBlock.IsRTL)
            {
                Rect thisRect  = this.BoundingRect;
                Rect otherRect = otherRun.BoundingRect;

                if (!this.Matrix.IsIdentity)
                {
                    Matrix inversionMat = _mat;
                    inversionMat.Invert();
                    thisRect.Transform(inversionMat);
                    thisRect.Offset(_mat.OffsetX, _mat.OffsetY);

                    otherRect.Transform(inversionMat);
                    otherRect.Offset(_mat.OffsetX, _mat.OffsetY);
                }

                thisRect.Offset(_mat.OffsetX, _mat.OffsetY);
                otherRect.Offset(otherRun.Matrix.OffsetX, otherRun.Matrix.OffsetY);

                if (FixedTextBuilder.IsSameLine(otherRect.Top - thisRect.Top, thisRect.Height, otherRect.Height))
                {
                    result = (thisRect.Left < otherRect.Left) ? 1 : -1;
                }
                else
                {
                    result = (thisRect.Top < otherRect.Top) ? -1 : +1;
                }
            }

            else
            {
                //Markup order for LTR languages

                List <FixedNode> markupOrder = this.FixedBlock.FixedSOMPage.MarkupOrder;
                result = markupOrder.IndexOf(this.FixedNode) - markupOrder.IndexOf(otherRun.FixedNode);
            }

            return(result);
        }
Beispiel #4
0
        public void ConstructFlowNodes(FixedTextBuilder.FlowModelBuilder flowBuilder, List<FixedNode> fixedNodes)
        {
            //
            // Initialize some variables inside this class.
            //
            _fixedNodes = fixedNodes;
            _visitedArray = new BitArray(fixedNodes.Count);
            _flowBuilder = flowBuilder;

            List<StoryFragment> StoryFragmentList = StoryFragments.StoryFragmentList;
            foreach (StoryFragment storyFragme in StoryFragmentList)
            {
                List<BlockElement> blockElementList = storyFragme.BlockElementList;
                foreach (BlockElement be in blockElementList)
                {
                    _CreateFlowNodes(be);
                }
            }
            //
            // After all the document structure referenced elements, we will go over
            // the FixedNodes again to take out all the un-referenced elements and put 
            // them in the end of the story. 
            //
            // Add the start node in the flow array.
            //
            _flowBuilder.AddStartNode(FixedElement.ElementType.Paragraph);

            for (int i = 0; i< _visitedArray.Count; i++ )
            {
                if (_visitedArray[i] == false)
                {
                    AddFixedNodeInFlow(i, null);
                }
            }

            _flowBuilder.AddEndNode();

            //Add any undiscovered hyperlinks at the end of the page
            _flowBuilder.AddLeftoverHyperlinks();

        }
Beispiel #5
0
        // Token: 0x06002E36 RID: 11830 RVA: 0x000D0CC4 File Offset: 0x000CEEC4
        int IComparable.CompareTo(object comparedObj)
        {
            FixedSOMTextRun fixedSOMTextRun = comparedObj as FixedSOMTextRun;
            int             result;

            if (this._fixedBlock.IsRTL)
            {
                Rect boundingRect  = base.BoundingRect;
                Rect boundingRect2 = fixedSOMTextRun.BoundingRect;
                if (!base.Matrix.IsIdentity)
                {
                    Matrix mat = this._mat;
                    mat.Invert();
                    boundingRect.Transform(mat);
                    boundingRect.Offset(this._mat.OffsetX, this._mat.OffsetY);
                    boundingRect2.Transform(mat);
                    boundingRect2.Offset(this._mat.OffsetX, this._mat.OffsetY);
                }
                boundingRect.Offset(this._mat.OffsetX, this._mat.OffsetY);
                boundingRect2.Offset(fixedSOMTextRun.Matrix.OffsetX, fixedSOMTextRun.Matrix.OffsetY);
                if (FixedTextBuilder.IsSameLine(boundingRect2.Top - boundingRect.Top, boundingRect.Height, boundingRect2.Height))
                {
                    result = ((boundingRect.Left < boundingRect2.Left) ? 1 : -1);
                }
                else
                {
                    result = ((boundingRect.Top < boundingRect2.Top) ? -1 : 1);
                }
            }
            else
            {
                List <FixedNode> markupOrder = this.FixedBlock.FixedSOMPage.MarkupOrder;
                result = markupOrder.IndexOf(base.FixedNode) - markupOrder.IndexOf(fixedSOMTextRun.FixedNode);
            }
            return(result);
        }
Beispiel #6
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));
            }
        }
        //--------------------------------------------------------------------
        //
        // Public Methods
        //
        //---------------------------------------------------------------------

        #region public Methods

        public static FixedSOMTextRun Create(Rect boundingRect, GeneralTransform transform, Glyphs glyphs, FixedNode fixedNode, int startIndex, int endIndex, bool allowReverseGlyphs)
        {
            if (String.IsNullOrEmpty(glyphs.UnicodeString) ||
                glyphs.FontRenderingEmSize <= 0)
            {
                return(null);
            }
            FixedSOMTextRun run = new FixedSOMTextRun(boundingRect, transform, fixedNode, startIndex, endIndex);

            run._fontUri     = glyphs.FontUri;
            run._cultureInfo = glyphs.Language.GetCompatibleCulture();
            run._bidiLevel   = glyphs.BidiLevel;
            run._isSideways  = glyphs.IsSideways;
            run._fontSize    = glyphs.FontRenderingEmSize;

            GlyphRun glyphRun = glyphs.ToGlyphRun();

            GlyphTypeface gtf = glyphRun.GlyphTypeface;

            // Find font family
            // glyphs.FontUri, glyphRun.glyphTypeface

            gtf.FamilyNames.TryGetValue(run._cultureInfo, out run._fontFamily);
            if (run._fontFamily == null)
            {
                //Try getting the English name
                gtf.FamilyNames.TryGetValue(System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS, out run._fontFamily);
            }

            // Find font style (normal, italics, Oblique)
            // need to open Font file.
            run._fontStyle = gtf.Style;

            // Find font weight (bold, semibold, ExtraLight)
            run._fontWeight = gtf.Weight;

            // Find font stretch (UltraCondensed, SemiExpanded, etc)
            run._fontStretch = gtf.Stretch;

            //Height and width should be the same for x character
            run._defaultCharWidth = gtf.XHeight > 0 ? gtf.XHeight * glyphs.FontRenderingEmSize : glyphRun.AdvanceWidths[startIndex];

            Transform trans = transform.AffineTransform;

            if (trans != null &&
                !(trans.Value.IsIdentity))
            {
                Matrix mat    = trans.Value;
                double yScale = Math.Sqrt(mat.M12 * mat.M12 + mat.M22 * mat.M22);
                double xScale = Math.Sqrt(mat.M11 * mat.M11 + mat.M21 * mat.M21);
                run._fontSize         *= yScale;
                run._defaultCharWidth *= xScale;
            }

            run._foreground = glyphs.Fill;
            String s = glyphs.UnicodeString;

            run.Text = s.Substring(startIndex, endIndex - startIndex);

            if (allowReverseGlyphs && run._bidiLevel == 0 && !run._isSideways &&
                startIndex == 0 && endIndex == s.Length &&
                String.IsNullOrEmpty(glyphs.CaretStops) &&
                FixedTextBuilder.MostlyRTL(s))
            {
                run._isReversed = true;
                run.Text        = string.Create(run.Text.Length, run.Text, (destination, runText) =>
                {
                    for (int i = 0; i < destination.Length; i++)
                    {
                        destination[i] = runText[runText.Length - 1 - i];
                    }
                });
            }

            if (s == "" && glyphs.Indices != null && glyphs.Indices.Length > 0)
            {
                run._isWhiteSpace = false;
            }
            else
            {
                run._isWhiteSpace = true;
                for (int i = 0; i < s.Length; i++)
                {
                    if (!Char.IsWhiteSpace(s[i]))
                    {
                        run._isWhiteSpace = false;
                        break;
                    }
                }
            }
            return(run);
        }
Beispiel #8
0
        //--------------------------------------------------------------------
        //
        // Private Methods
        //
        //---------------------------------------------------------------------

        #region Private Methods

        //--------------------------------------------------------------------
        // Initilization
        //---------------------------------------------------------------------
        private void _CreateEmptyContainer()
        {
            // new text builder with map
            _fixedTextBuilder = new FixedTextBuilder(this);

            // create initial TextPointer and container element
            _start = new  FixedTextPointer(false, LogicalDirection.Backward, new FlowPosition(this, this.FixedTextBuilder.FixedFlowMap.FlowStartEdge, 1));
            _end = new FixedTextPointer(false, LogicalDirection.Forward, new FlowPosition(this, this.FixedTextBuilder.FixedFlowMap.FlowEndEdge, 0));

            _containerElement = new FixedElement(FixedElement.ElementType.Container, _start, _end, int.MaxValue);
            _start.FlowPosition.AttachElement(_containerElement);
            _end.FlowPosition.AttachElement(_containerElement);

        }
Beispiel #9
0
        // Token: 0x06002E76 RID: 11894 RVA: 0x000D289C File Offset: 0x000D0A9C
        private static string _ConstructPageString(Stream pageStream, bool reverseRTL)
        {
            XmlTextReader baseReader = new XmlTextReader(pageStream);
            XmlReader     xmlReader  = new XmlCompatibilityReader(baseReader, FixedFindEngine._predefinedNamespaces);

            xmlReader = XmlReader.Create(xmlReader, new XmlReaderSettings
            {
                IgnoreWhitespace = true,
                IgnoreComments   = true,
                ProhibitDtd      = true
            });
            xmlReader.MoveToContent();
            StringBuilder stringBuilder = new StringBuilder();
            bool          flag          = false;
            string        text          = null;

            while (xmlReader.Read())
            {
                XmlNodeType nodeType = xmlReader.NodeType;
                if (nodeType == XmlNodeType.Element && xmlReader.Name == "Glyphs")
                {
                    text = xmlReader.GetAttribute("UnicodeString");
                    if (!string.IsNullOrEmpty(text))
                    {
                        string attribute = xmlReader.GetAttribute("IsSideways");
                        flag = false;
                        if (attribute != null && string.Compare(attribute, bool.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            flag = true;
                        }
                        if (reverseRTL)
                        {
                            string attribute2 = xmlReader.GetAttribute("BidiLevel");
                            int    num        = 0;
                            if (!string.IsNullOrEmpty(attribute2))
                            {
                                try
                                {
                                    num = Convert.ToInt32(attribute2, CultureInfo.InvariantCulture);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            string attribute3 = xmlReader.GetAttribute("CaretStops");
                            if (num == 0 && !flag && string.IsNullOrEmpty(attribute3) && FixedTextBuilder.MostlyRTL(text))
                            {
                                char[] array = text.ToCharArray();
                                Array.Reverse(array);
                                text = new string(array);
                            }
                        }
                        stringBuilder.Append(text);
                    }
                }
            }
            return(stringBuilder.ToString());
        }
Beispiel #10
0
        // Token: 0x06002E71 RID: 11889 RVA: 0x000D23C8 File Offset: 0x000D05C8
        internal static TextRange Find(ITextPointer start, ITextPointer end, string findPattern, CultureInfo cultureInfo, bool matchCase, bool matchWholeWord, bool matchLast, bool matchDiacritics, bool matchKashida, bool matchAlefHamza)
        {
            if (findPattern.Length == 0)
            {
                return(null);
            }
            IDocumentPaginatorSource documentPaginatorSource  = start.TextContainer.Parent as IDocumentPaginatorSource;
            DynamicDocumentPaginator dynamicDocumentPaginator = documentPaginatorSource.DocumentPaginator as DynamicDocumentPaginator;
            int pageNumber;
            int num;

            if (matchLast)
            {
                pageNumber = dynamicDocumentPaginator.GetPageNumber((ContentPosition)start);
                num        = dynamicDocumentPaginator.GetPageNumber((ContentPosition)end);
            }
            else
            {
                pageNumber = dynamicDocumentPaginator.GetPageNumber((ContentPosition)end);
                num        = dynamicDocumentPaginator.GetPageNumber((ContentPosition)start);
            }
            TextRange                textRange   = null;
            CompareInfo              compareInfo = cultureInfo.CompareInfo;
            bool                     replaceAlefWithAlefHamza = false;
            CompareOptions           compareOptions           = FixedFindEngine._InitializeSearch(cultureInfo, matchCase, matchAlefHamza, matchDiacritics, ref findPattern, out replaceAlefWithAlefHamza);
            int                      num2 = num;
            FixedDocumentSequence    fixedDocumentSequence     = documentPaginatorSource as FixedDocumentSequence;
            DynamicDocumentPaginator dynamicDocumentPaginator2 = null;

            if (fixedDocumentSequence != null)
            {
                fixedDocumentSequence.TranslatePageNumber(num, out dynamicDocumentPaginator2, out num2);
            }
            if (num - pageNumber != 0)
            {
                ITextPointer startPosition = null;
                ITextPointer endPosition   = null;
                FixedFindEngine._GetFirstPageSearchPointers(start, end, num2, matchLast, out startPosition, out endPosition);
                textRange = TextFindEngine.InternalFind(startPosition, endPosition, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza);
                if (textRange == null)
                {
                    num = (matchLast ? (num - 1) : (num + 1));
                    int num3 = matchLast ? -1 : 1;
                    while (matchLast ? (num >= pageNumber) : (num <= pageNumber))
                    {
                        num2 = num;
                        dynamicDocumentPaginator2 = null;
                        FixedDocument fixedDocument;
                        if (fixedDocumentSequence != null)
                        {
                            fixedDocumentSequence.TranslatePageNumber(num, out dynamicDocumentPaginator2, out num2);
                            fixedDocument = (FixedDocument)dynamicDocumentPaginator2.Source;
                        }
                        else
                        {
                            fixedDocument = (documentPaginatorSource as FixedDocument);
                        }
                        string text = FixedFindEngine._GetPageString(fixedDocument, num2, replaceAlefWithAlefHamza);
                        if (text == null)
                        {
                            return(TextFindEngine.InternalFind(start, end, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza));
                        }
                        if (FixedFindEngine._FoundOnPage(text, findPattern, cultureInfo, compareOptions))
                        {
                            if (fixedDocumentSequence != null)
                            {
                                ChildDocumentBlock childBlock = fixedDocumentSequence.TextContainer.FindChildBlock(fixedDocument.DocumentReference);
                                if (matchLast)
                                {
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDocument.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(num2)));
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDocument.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(num2)));
                                }
                                else
                                {
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDocument.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(num2)));
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDocument.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(num2)));
                                }
                            }
                            else
                            {
                                FixedTextBuilder fixedTextBuilder = ((FixedDocument)documentPaginatorSource).FixedContainer.FixedTextBuilder;
                                if (matchLast)
                                {
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, fixedTextBuilder.GetPageEndFlowPosition(num));
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, fixedTextBuilder.GetPageStartFlowPosition(num));
                                }
                                else
                                {
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, fixedTextBuilder.GetPageStartFlowPosition(num));
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, fixedTextBuilder.GetPageEndFlowPosition(num));
                                }
                            }
                            textRange = TextFindEngine.InternalFind(start, end, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza);
                            if (textRange != null)
                            {
                                return(textRange);
                            }
                        }
                        num += num3;
                    }
                }
            }
            else
            {
                FixedDocument doc   = (dynamicDocumentPaginator2 != null) ? (dynamicDocumentPaginator2.Source as FixedDocument) : (documentPaginatorSource as FixedDocument);
                string        text2 = FixedFindEngine._GetPageString(doc, num2, replaceAlefWithAlefHamza);
                if (text2 == null || FixedFindEngine._FoundOnPage(text2, findPattern, cultureInfo, compareOptions))
                {
                    textRange = TextFindEngine.InternalFind(start, end, findPattern, cultureInfo, matchCase, matchWholeWord, matchLast, matchDiacritics, matchKashida, matchAlefHamza);
                }
            }
            return(textRange);
        }
Beispiel #11
0
        // Token: 0x06002E37 RID: 11831 RVA: 0x000D0E28 File Offset: 0x000CF028
        public static FixedSOMTextRun Create(Rect boundingRect, GeneralTransform transform, Glyphs glyphs, FixedNode fixedNode, int startIndex, int endIndex, bool allowReverseGlyphs)
        {
            if (string.IsNullOrEmpty(glyphs.UnicodeString) || glyphs.FontRenderingEmSize <= 0.0)
            {
                return(null);
            }
            FixedSOMTextRun fixedSOMTextRun = new FixedSOMTextRun(boundingRect, transform, fixedNode, startIndex, endIndex);

            fixedSOMTextRun._fontUri     = glyphs.FontUri;
            fixedSOMTextRun._cultureInfo = glyphs.Language.GetCompatibleCulture();
            fixedSOMTextRun._bidiLevel   = glyphs.BidiLevel;
            fixedSOMTextRun._isSideways  = glyphs.IsSideways;
            fixedSOMTextRun._fontSize    = glyphs.FontRenderingEmSize;
            GlyphRun      glyphRun      = glyphs.ToGlyphRun();
            GlyphTypeface glyphTypeface = glyphRun.GlyphTypeface;

            glyphTypeface.FamilyNames.TryGetValue(fixedSOMTextRun._cultureInfo, out fixedSOMTextRun._fontFamily);
            if (fixedSOMTextRun._fontFamily == null)
            {
                glyphTypeface.FamilyNames.TryGetValue(TypeConverterHelper.InvariantEnglishUS, out fixedSOMTextRun._fontFamily);
            }
            fixedSOMTextRun._fontStyle        = glyphTypeface.Style;
            fixedSOMTextRun._fontWeight       = glyphTypeface.Weight;
            fixedSOMTextRun._fontStretch      = glyphTypeface.Stretch;
            fixedSOMTextRun._defaultCharWidth = ((glyphTypeface.XHeight > 0.0) ? (glyphTypeface.XHeight * glyphs.FontRenderingEmSize) : glyphRun.AdvanceWidths[startIndex]);
            Transform affineTransform = transform.AffineTransform;

            if (affineTransform != null && !affineTransform.Value.IsIdentity)
            {
                Matrix value = affineTransform.Value;
                double num   = Math.Sqrt(value.M12 * value.M12 + value.M22 * value.M22);
                double num2  = Math.Sqrt(value.M11 * value.M11 + value.M21 * value.M21);
                fixedSOMTextRun._fontSize         *= num;
                fixedSOMTextRun._defaultCharWidth *= num2;
            }
            fixedSOMTextRun._foreground = glyphs.Fill;
            string unicodeString = glyphs.UnicodeString;

            fixedSOMTextRun.Text = unicodeString.Substring(startIndex, endIndex - startIndex);
            if (allowReverseGlyphs && fixedSOMTextRun._bidiLevel == 0 && !fixedSOMTextRun._isSideways && startIndex == 0 && endIndex == unicodeString.Length && string.IsNullOrEmpty(glyphs.CaretStops) && FixedTextBuilder.MostlyRTL(unicodeString))
            {
                char[] array = new char[fixedSOMTextRun.Text.Length];
                for (int i = 0; i < fixedSOMTextRun.Text.Length; i++)
                {
                    array[i] = fixedSOMTextRun.Text[fixedSOMTextRun.Text.Length - 1 - i];
                }
                fixedSOMTextRun._isReversed = true;
                fixedSOMTextRun.Text        = new string(array);
            }
            if (unicodeString == "" && glyphs.Indices != null && glyphs.Indices.Length > 0)
            {
                fixedSOMTextRun._isWhiteSpace = false;
            }
            else
            {
                fixedSOMTextRun._isWhiteSpace = true;
                for (int j = 0; j < unicodeString.Length; j++)
                {
                    if (!char.IsWhiteSpace(unicodeString[j]))
                    {
                        fixedSOMTextRun._isWhiteSpace = false;
                        break;
                    }
                }
            }
            return(fixedSOMTextRun);
        }
        private static String _ConstructPageString(Stream pageStream, bool reverseRTL)
        {
            Debug.Assert(pageStream != null);

            XmlTextReader xmlTextReader = new XmlTextReader(pageStream);

            //Wrap around a compatibility reader
            XmlReader xmlReader = new XmlCompatibilityReader(xmlTextReader, _predefinedNamespaces);

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;
            settings.ProhibitDtd      = true;

            xmlReader = XmlReader.Create(xmlReader, settings);

            xmlReader.MoveToContent();

            StringBuilder pageString = new StringBuilder();
            bool          isSideways = false;
            string        unicodeStr = null;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    if (xmlReader.Name == "Glyphs")
                    {
                        unicodeStr = xmlReader.GetAttribute("UnicodeString");

                        if (!String.IsNullOrEmpty(unicodeStr))
                        {
                            string sidewaysString = xmlReader.GetAttribute("IsSideways");
                            isSideways = false;
                            if (sidewaysString != null &&
                                String.Compare(sidewaysString, Boolean.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                isSideways = true;
                            }

                            if (reverseRTL)
                            {
                                //This is to cover for MXDW generation
                                //RTL Glyphs are saved LTR and bidi level is not set
                                //In this case we need to reverse the UnicodeString
                                string bidiLevelAsString = xmlReader.GetAttribute("BidiLevel");
                                int    bidiLevel         = 0;
                                if (!String.IsNullOrEmpty(bidiLevelAsString))
                                {
                                    try
                                    {
                                        bidiLevel = Convert.ToInt32(bidiLevelAsString, CultureInfo.InvariantCulture);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }

                                string caretStops = xmlReader.GetAttribute("CaretStops");

                                if (bidiLevel == 0 &&
                                    !isSideways &&
                                    String.IsNullOrEmpty(caretStops) &&
                                    FixedTextBuilder.MostlyRTL(unicodeStr))
                                {
                                    char[] chars = unicodeStr.ToCharArray();
                                    Array.Reverse(chars);
                                    unicodeStr = new String(chars);
                                }
                            }


                            pageString.Append(unicodeStr);
                        }
                    }
                }
                break;
                }
            }
            return(pageString.ToString());
        }
        //Searches for the specified pattern and updates start *or* end pointers depending on search direction
        //At the end of the operation, start or end should be pointing to the beginning/end of the page
        //of occurance of pattern respectively
        internal static TextRange Find(ITextPointer start,
                                       ITextPointer end,
                                       string findPattern,
                                       CultureInfo cultureInfo,
                                       bool matchCase,
                                       bool matchWholeWord,
                                       bool matchLast,
                                       bool matchDiacritics,
                                       bool matchKashida,
                                       bool matchAlefHamza)
        {
            Debug.Assert(start != null);
            Debug.Assert(end != null);
            Debug.Assert(((start is DocumentSequenceTextPointer) && (end is DocumentSequenceTextPointer)) ||
                         ((start is FixedTextPointer) && (end is FixedTextPointer)));
            Debug.Assert(findPattern != null);

            if (findPattern.Length == 0)
            {
                return(null);
            }

            IDocumentPaginatorSource paginatorSource = start.TextContainer.Parent as IDocumentPaginatorSource;
            DynamicDocumentPaginator paginator       = paginatorSource.DocumentPaginator as DynamicDocumentPaginator;

            Debug.Assert(paginator != null);

            int pageNumber    = -1;
            int endPageNumber = -1;

            if (matchLast)
            {
                endPageNumber = paginator.GetPageNumber((ContentPosition)start);
                pageNumber    = paginator.GetPageNumber((ContentPosition)end);
            }
            else
            {
                endPageNumber = paginator.GetPageNumber((ContentPosition)end);
                pageNumber    = paginator.GetPageNumber((ContentPosition)start);
            }

            TextRange result = null;

            CompareInfo    compareInfo = cultureInfo.CompareInfo;
            bool           replaceAlefWithAlefHamza = false;
            CompareOptions compareOptions           = _InitializeSearch(cultureInfo, matchCase, matchAlefHamza, matchDiacritics, ref findPattern, out replaceAlefWithAlefHamza);

            //Translate the page number
            int translatedPageNumber = pageNumber;
            //If this is a DocumentSequence, we need to pass translated page number to the below call
            FixedDocumentSequence    documentSequence = paginatorSource as FixedDocumentSequence;
            DynamicDocumentPaginator childPaginator   = null;

            if (documentSequence != null)
            {
                documentSequence.TranslatePageNumber(pageNumber, out childPaginator, out translatedPageNumber);
            }

            if (pageNumber - endPageNumber != 0)
            {
                ITextPointer firstSearchPageStart = null;
                ITextPointer firstSearchPageEnd   = null;

                _GetFirstPageSearchPointers(start, end, translatedPageNumber, matchLast, out firstSearchPageStart, out firstSearchPageEnd);

                Debug.Assert(firstSearchPageStart != null);
                Debug.Assert(firstSearchPageEnd != null);

                //Need to search the first page using TextFindEngine to start exactly from the requested search location to avoid false positives
                result = TextFindEngine.InternalFind(firstSearchPageStart,
                                                     firstSearchPageEnd,
                                                     findPattern,
                                                     cultureInfo,
                                                     matchCase,
                                                     matchWholeWord,
                                                     matchLast,
                                                     matchDiacritics,
                                                     matchKashida,
                                                     matchAlefHamza);
                if (result == null)
                {
                    //Start from the next page and check all pages until the end
                    pageNumber = matchLast ? pageNumber - 1 : pageNumber + 1;
                    int increment = matchLast ? -1 : 1;
                    for (; matchLast?pageNumber >= endPageNumber : pageNumber <= endPageNumber; pageNumber += increment)
                    {
                        FixedDocument fixedDoc = null;

                        translatedPageNumber = pageNumber;
                        childPaginator       = null;
                        if (documentSequence != null)
                        {
                            documentSequence.TranslatePageNumber(pageNumber, out childPaginator, out translatedPageNumber);
                            fixedDoc = (FixedDocument)childPaginator.Source;
                        }
                        else
                        {
                            fixedDoc = paginatorSource as FixedDocument;
                        }

                        Debug.Assert(fixedDoc != null);

                        String pageString = _GetPageString(fixedDoc, translatedPageNumber, replaceAlefWithAlefHamza);

                        if (pageString == null)
                        {
                            //This is not a page-per-stream
                            //Default back to slow search
                            return(TextFindEngine.InternalFind(start,
                                                               end,
                                                               findPattern,
                                                               cultureInfo,
                                                               matchCase,
                                                               matchWholeWord,
                                                               matchLast,
                                                               matchDiacritics,
                                                               matchKashida,
                                                               matchAlefHamza));
                        }

                        if (_FoundOnPage(pageString, findPattern, cultureInfo, compareOptions))
                        {
                            //Update end or start pointer depending on search direction
                            if (documentSequence != null)
                            {
                                ChildDocumentBlock childBlock = documentSequence.TextContainer.FindChildBlock(fixedDoc.DocumentReference);
                                if (matchLast)
                                {
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(translatedPageNumber)));
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(translatedPageNumber)));
                                }
                                else
                                {
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(translatedPageNumber)));
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(translatedPageNumber)));
                                }
                            }
                            else
                            {
                                //We are working on a FixedDocument
                                FixedTextBuilder textBuilder = ((FixedDocument)(paginatorSource)).FixedContainer.FixedTextBuilder;
                                if (matchLast)
                                {
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, textBuilder.GetPageEndFlowPosition(pageNumber));
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, textBuilder.GetPageStartFlowPosition(pageNumber));
                                }
                                else
                                {
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, textBuilder.GetPageStartFlowPosition(pageNumber));
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, textBuilder.GetPageEndFlowPosition(pageNumber));
                                }
                            }
                            result = TextFindEngine.InternalFind(start,
                                                                 end,
                                                                 findPattern,
                                                                 cultureInfo,
                                                                 matchCase,
                                                                 matchWholeWord,
                                                                 matchLast,
                                                                 matchDiacritics,
                                                                 matchKashida,
                                                                 matchAlefHamza);

                            //If the result is null, this means we had a false positive
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }

            else
            {
                //Make sure fast search result and slow search result are consistent
                FixedDocument fixedDoc   = childPaginator != null ? childPaginator.Source as FixedDocument : paginatorSource as FixedDocument;
                String        pageString = _GetPageString(fixedDoc, translatedPageNumber, replaceAlefWithAlefHamza);
                if (pageString == null ||
                    _FoundOnPage(pageString, findPattern, cultureInfo, compareOptions))
                {
                    //The search is only limited to the current page
                    result = TextFindEngine.InternalFind(start,
                                                         end,
                                                         findPattern,
                                                         cultureInfo,
                                                         matchCase,
                                                         matchWholeWord,
                                                         matchLast,
                                                         matchDiacritics,
                                                         matchKashida,
                                                         matchAlefHamza);
                }
            }

            return(result);
        }
Beispiel #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));
        }