示例#1
0
        //Creates a FixedSOMTextRun, and updates containing structures
        private void _CreateTextRun(Rect boundingRect, GeneralTransform trans, Glyphs glyphs, FixedNode node, int startIndex, int endIndex)
        {
            if (startIndex < endIndex)
            {
                FixedSOMTextRun textRun = FixedSOMTextRun.Create(boundingRect,
                                                                 trans,
                                                                 glyphs,
                                                                 node,
                                                                 startIndex,
                                                                 endIndex,
                                                                 true);


                FixedSOMFixedBlock fixedBlock = _GetContainingFixedBlock(textRun);

                if (fixedBlock == null)
                {
                    fixedBlock = new FixedSOMFixedBlock(_fixedSOMPage);
                    fixedBlock.AddTextRun(textRun);
                    _fixedSOMPage.AddFixedBlock(fixedBlock);
                }
                else
                {
                    fixedBlock.AddTextRun(textRun);
                }
                _currentFixedBlock = fixedBlock;
            }
        }
示例#2
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);
        }
示例#3
0
        //Find and return a FixedBlock that would contain this TextRun
        private FixedSOMFixedBlock _GetContainingFixedBlock(FixedSOMTextRun textRun)
        {
            FixedSOMFixedBlock fixedBlock = null;

            if (_currentFixedBlock == null)
            {
                return(null);
            }

            if (_currentFixedBlock != null && _IsCombinable(_currentFixedBlock, textRun))
            {
                fixedBlock = _currentFixedBlock;
            }
            else
            {
                //If this is aligned with the previous block, simply create a new block
                Rect textRunRect    = textRun.BoundingRect;
                Rect fixedBlockRect = _currentFixedBlock.BoundingRect;
                if (Math.Abs(textRunRect.Left - fixedBlockRect.Left) <= textRun.DefaultCharWidth ||
                    Math.Abs(textRunRect.Right - fixedBlockRect.Right) <= textRun.DefaultCharWidth)
                {
                    return(null);
                }
                foreach (FixedSOMSemanticBox box in _fixedSOMPage.SemanticBoxes)
                {
                    if ((box is FixedSOMFixedBlock) && _IsCombinable(box as FixedSOMFixedBlock, textRun))
                    {
                        fixedBlock = box as FixedSOMFixedBlock;
                    }
                }
            }
            return(fixedBlock);
        }
示例#4
0
        // Token: 0x06002DFB RID: 11771 RVA: 0x000CED00 File Offset: 0x000CCF00
        private FixedSOMFixedBlock _GetContainingFixedBlock(FixedSOMTextRun textRun)
        {
            FixedSOMFixedBlock result = null;

            if (this._currentFixedBlock == null)
            {
                return(null);
            }
            if (this._currentFixedBlock != null && this._IsCombinable(this._currentFixedBlock, textRun))
            {
                result = this._currentFixedBlock;
            }
            else
            {
                Rect boundingRect  = textRun.BoundingRect;
                Rect boundingRect2 = this._currentFixedBlock.BoundingRect;
                if (Math.Abs(boundingRect.Left - boundingRect2.Left) <= textRun.DefaultCharWidth || Math.Abs(boundingRect.Right - boundingRect2.Right) <= textRun.DefaultCharWidth)
                {
                    return(null);
                }
                foreach (FixedSOMSemanticBox fixedSOMSemanticBox in this._fixedSOMPage.SemanticBoxes)
                {
                    if (fixedSOMSemanticBox is FixedSOMFixedBlock && this._IsCombinable(fixedSOMSemanticBox as FixedSOMFixedBlock, textRun))
                    {
                        result = (fixedSOMSemanticBox as FixedSOMFixedBlock);
                    }
                }
            }
            return(result);
        }
示例#5
0
 // Token: 0x06002E38 RID: 11832 RVA: 0x000D1100 File Offset: 0x000CF300
 public bool HasSameRichProperties(FixedSOMTextRun run)
 {
     if (run.FontRenderingEmSize == this.FontRenderingEmSize && run.CultureInfo.Equals(this.CultureInfo) && run.FontStyle.Equals(this.FontStyle) && run.FontStretch.Equals(this.FontStretch) && run.FontWeight.Equals(this.FontWeight) && run.FontFamily == this.FontFamily && run.IsRTL == this.IsRTL)
     {
         SolidColorBrush solidColorBrush  = this.Foreground as SolidColorBrush;
         SolidColorBrush solidColorBrush2 = run.Foreground as SolidColorBrush;
         if ((run.Foreground == null && this.Foreground == null) || (solidColorBrush != null && solidColorBrush2 != null && solidColorBrush.Color == solidColorBrush2.Color && solidColorBrush.Opacity == solidColorBrush2.Opacity))
         {
             return(true);
         }
     }
     return(false);
 }
示例#6
0
 // Token: 0x06002DBD RID: 11709 RVA: 0x000CDCB8 File Offset: 0x000CBEB8
 public void AddTextRun(FixedSOMTextRun textRun)
 {
     this._AddElement(textRun);
     textRun.FixedBlock = this;
     if (!textRun.IsWhiteSpace)
     {
         if (textRun.IsLTR)
         {
             this._LTRCount++;
             return;
         }
         this._RTLCount++;
     }
 }
示例#7
0
 public void CombineWith(FixedSOMFixedBlock block)
 {
     foreach (FixedSOMSemanticBox box in block.SemanticBoxes)
     {
         FixedSOMTextRun run = box as FixedSOMTextRun;
         if (run != null)
         {
             AddTextRun(run);
         }
         else
         {
             base.Add(box);
         }
     }
 }
示例#8
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            foreach (FixedSOMSemanticBox box in _semanticBoxes)
            {
                FixedSOMTextRun run = box as FixedSOMTextRun;
                if (run != null)
                {
                    builder.Append(run.Text);
                    builder.Append(" ");
                }
            }
            return(builder.ToString());
        }
示例#9
0
 // Token: 0x06002DBC RID: 11708 RVA: 0x000CDC50 File Offset: 0x000CBE50
 public void CombineWith(FixedSOMFixedBlock block)
 {
     foreach (FixedSOMSemanticBox fixedSOMSemanticBox in block.SemanticBoxes)
     {
         FixedSOMTextRun fixedSOMTextRun = fixedSOMSemanticBox as FixedSOMTextRun;
         if (fixedSOMTextRun != null)
         {
             this.AddTextRun(fixedSOMTextRun);
         }
         else
         {
             base.Add(fixedSOMSemanticBox);
         }
     }
 }
        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);
        }
示例#11
0
        public void AddTextRun(FixedSOMTextRun textRun)
        {
            _AddElement(textRun);
            textRun.FixedBlock = this;

            if (!textRun.IsWhiteSpace)
            {
                if (textRun.IsLTR)
                {
                    _LTRCount++;
                }
                else
                {
                    _RTLCount++;
                }
            }
        }
示例#12
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);
        }
示例#13
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));
            }
        }
示例#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));
        }
        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));
            } 
        }
        //Find and return a FixedBlock that would contain this TextRun
        private FixedSOMFixedBlock _GetContainingFixedBlock(FixedSOMTextRun textRun) 
        {
            FixedSOMFixedBlock fixedBlock = null;

            if (_currentFixedBlock == null) 
            {
                return null; 
            } 

            if (_currentFixedBlock != null && _IsCombinable(_currentFixedBlock, textRun)) 
            {
                fixedBlock = _currentFixedBlock;
            }
            else 
            {
                //If this is aligned with the previous block, simply create a new block 
                Rect textRunRect = textRun.BoundingRect; 
                Rect fixedBlockRect = _currentFixedBlock.BoundingRect;
                if (Math.Abs(textRunRect.Left - fixedBlockRect.Left) <= textRun.DefaultCharWidth || 
                    Math.Abs(textRunRect.Right - fixedBlockRect.Right) <= textRun.DefaultCharWidth)
                {
                    return null;
                } 
                foreach (FixedSOMSemanticBox box in _fixedSOMPage.SemanticBoxes)
                { 
                    if ((box is FixedSOMFixedBlock) && _IsCombinable(box as FixedSOMFixedBlock, textRun)) 
                    {
                        fixedBlock = box as FixedSOMFixedBlock; 
                    }
                }
            }
            return fixedBlock; 
        }
        //--------------------------------------------------------------------
        //
        // 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);
        }
示例#18
0
 public bool HasSameRichProperties(FixedSOMTextRun run)
 {
     if (run.FontRenderingEmSize == this.FontRenderingEmSize &&
         run.CultureInfo.Equals(this.CultureInfo) &&
         run.FontStyle.Equals(this.FontStyle) &&
         run.FontStretch.Equals(this.FontStretch) &&
         run.FontWeight.Equals(this.FontWeight) &&
         run.FontFamily == this.FontFamily &&
         run.IsRTL == this.IsRTL)
     {
         SolidColorBrush thisBrush = this.Foreground as SolidColorBrush;
         SolidColorBrush otherBrush = run.Foreground as SolidColorBrush;
         if ((run.Foreground == null && this.Foreground == null) ||
              thisBrush != null && otherBrush != null && thisBrush.Color == otherBrush.Color && thisBrush.Opacity == otherBrush.Opacity)
         {
             return true;    
         }
     }
     return false;
 }
示例#19
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);
        }
示例#20
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 :;
                }
            }
        }
示例#21
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);
                }
            }
        }
示例#22
0
        //--------------------------------------------------------------------
        //
        // 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))
            {
                char[] chars = new char[run.Text.Length];
                for (int i=0; i<run.Text.Length; i++)
                {
                    chars[i] = run.Text[run.Text.Length - 1 - i];
                }
                run._isReversed = true;
                run.Text = new string(chars);
            }

            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;
        }
示例#23
0
        public void AddTextRun(FixedSOMTextRun textRun)
        {
            _AddElement(textRun);
            textRun.FixedBlock = this; 

            if (!textRun.IsWhiteSpace) 
            { 
                if (textRun.IsLTR)
                { 
                    _LTRCount++;
                }
                else
                { 
                    _RTLCount++;
                } 
            } 
        }