示例#1
0
        // If return false, nothing has been modified, which implies out of page boundary
        // The input of suggestedX is in the VisualRoot's cooridnate system
        private bool _GetNextLineGlyphs(ref FixedPosition fixedp, ref LogicalDirection edge, double suggestedX, LogicalDirection scanDir)
        {
            int  count     = 1;
            int  pageIndex = fixedp.Page;
            bool moved     = false;

            FixedNode[] fixedNodes = Container.FixedTextBuilder.GetNextLine(fixedp.Node, (scanDir == LogicalDirection.Forward), ref count);

            if (fixedNodes != null && fixedNodes.Length > 0)
            {
                FixedPage page = Container.FixedDocument.SyncGetPage(pageIndex, false);
                // This line contains multiple Glyhs. Scan backward
                // util we hit the first one whose OriginX is smaller
                // then suggestedX;
                if (Double.IsInfinity(suggestedX))
                {
                    suggestedX = 0;
                }
                Point topOfPage   = new Point(suggestedX, 0);
                Point secondPoint = new Point(suggestedX, 1000);

                FixedNode hitNode         = fixedNodes[0];
                Glyphs    hitGlyphs       = null;
                double    closestDistance = Double.MaxValue;
                double    xoffset         = 0;

                for (int i = fixedNodes.Length - 1; i >= 0; i--)
                {
                    FixedNode node = fixedNodes[i];
                    Glyphs    g    = page.GetGlyphsElement(node);
                    if (g != null)
                    {
                        GeneralTransform transform = page.TransformToDescendant(g);
                        Point            pt1       = topOfPage;
                        Point            pt2       = secondPoint;
                        if (transform != null)
                        {
                            transform.TryTransform(pt1, out pt1);
                            transform.TryTransform(pt2, out pt2);
                        }
                        double invSlope = (pt2.X - pt1.X) / (pt2.Y - pt1.Y);
                        double xoff, distance;

                        GlyphRun run = g.ToGlyphRun();
                        Rect     box = run.ComputeAlignmentBox();
                        box.Offset(g.OriginX, g.OriginY);

                        if (invSlope > 1000 || invSlope < -1000)
                        {
                            // special case for vertical text
                            xoff     = 0;
                            distance = (pt1.Y > box.Y) ? (pt1.Y - box.Bottom) : (box.Y - pt1.Y);
                        }
                        else
                        {
                            double centerY = (box.Top + box.Bottom) / 2;
                            xoff     = pt1.X + invSlope * (centerY - pt1.Y);
                            distance = (xoff > box.X) ? (xoff - box.Right) : (box.X - xoff);
                        }

                        if (distance < closestDistance)
                        {
                            closestDistance = distance;
                            xoffset         = xoff;
                            hitNode         = node;
                            hitGlyphs       = g;

                            if (distance <= 0)
                            {
                                break;
                            }
                        }
                    }
                }

                Debug.Assert(hitGlyphs != null);

                int charIdx;
                _GlyphRunHitTest(hitGlyphs, xoffset, out charIdx, out edge);

                fixedp = new FixedPosition(hitNode, charIdx);
                moved  = true;
            }

            return(moved);
        }
        // Token: 0x06002EF2 RID: 12018 RVA: 0x000D4194 File Offset: 0x000D2394
        private bool _GetNextLineGlyphs(ref FixedPosition fixedp, ref LogicalDirection edge, double suggestedX, LogicalDirection scanDir)
        {
            int  num    = 1;
            int  page   = fixedp.Page;
            bool result = false;

            FixedNode[] nextLine = this.Container.FixedTextBuilder.GetNextLine(fixedp.Node, scanDir == LogicalDirection.Forward, ref num);
            if (nextLine != null && nextLine.Length != 0)
            {
                FixedPage fixedPage = this.Container.FixedDocument.SyncGetPage(page, false);
                if (double.IsInfinity(suggestedX))
                {
                    suggestedX = 0.0;
                }
                Point     point     = new Point(suggestedX, 0.0);
                Point     point2    = new Point(suggestedX, 1000.0);
                FixedNode fixedNode = nextLine[0];
                Glyphs    g         = null;
                double    num2      = double.MaxValue;
                double    xoffset   = 0.0;
                for (int i = nextLine.Length - 1; i >= 0; i--)
                {
                    FixedNode fixedNode2    = nextLine[i];
                    Glyphs    glyphsElement = fixedPage.GetGlyphsElement(fixedNode2);
                    if (glyphsElement != null)
                    {
                        GeneralTransform generalTransform = fixedPage.TransformToDescendant(glyphsElement);
                        Point            inPoint          = point;
                        Point            inPoint2         = point2;
                        if (generalTransform != null)
                        {
                            generalTransform.TryTransform(inPoint, out inPoint);
                            generalTransform.TryTransform(inPoint2, out inPoint2);
                        }
                        double   num3     = (inPoint2.X - inPoint.X) / (inPoint2.Y - inPoint.Y);
                        GlyphRun glyphRun = glyphsElement.ToGlyphRun();
                        Rect     rect     = glyphRun.ComputeAlignmentBox();
                        rect.Offset(glyphsElement.OriginX, glyphsElement.OriginY);
                        double num4;
                        double num5;
                        if (num3 > 1000.0 || num3 < -1000.0)
                        {
                            num4 = 0.0;
                            num5 = ((inPoint.Y > rect.Y) ? (inPoint.Y - rect.Bottom) : (rect.Y - inPoint.Y));
                        }
                        else
                        {
                            double num6 = (rect.Top + rect.Bottom) / 2.0;
                            num4 = inPoint.X + num3 * (num6 - inPoint.Y);
                            num5 = ((num4 > rect.X) ? (num4 - rect.Right) : (rect.X - num4));
                        }
                        if (num5 < num2)
                        {
                            num2      = num5;
                            xoffset   = num4;
                            fixedNode = fixedNode2;
                            g         = glyphsElement;
                            if (num5 <= 0.0)
                            {
                                break;
                            }
                        }
                    }
                }
                int offset;
                this._GlyphRunHitTest(g, xoffset, out offset, out edge);
                fixedp = new FixedPosition(fixedNode, offset);
                result = true;
            }
            return(result);
        }