Esempio n. 1
0
        internal void RenderLines(DrawingContext dc)
        {
            for (int i = 0; i < _lineResults.Length; i++)
            {
                FixedLineResult lineResult = _lineResults[i];

                Pen  pen       = new Pen(Brushes.Red, 1);
                Rect layoutBox = lineResult.LayoutBox;
                dc.DrawRectangle(null, pen, layoutBox);

                CultureInfo   EnglishCulture = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;
                FixedPage     fp             = _fixedTextBuilder.FixedTextContainer.FixedDocument.GetFixedPage(PageIndex);
                FormattedText ft             = new FormattedText(i.ToString(),
                                                                 EnglishCulture,
                                                                 FlowDirection.LeftToRight,
                                                                 new Typeface("Arial"),
                                                                 10,
                                                                 Brushes.White,
                                                                 fp.GetDpi().PixelsPerDip);
                Point    labelLocation = new Point(layoutBox.Left - 25, (layoutBox.Bottom + layoutBox.Top) / 2 - 10);
                Geometry geom          = ft.BuildHighlightGeometry(labelLocation);
                Pen      backgroundPen = new Pen(Brushes.Black, 1);
                dc.DrawGeometry(Brushes.Black, backgroundPen, geom);
                dc.DrawText(ft, labelLocation);
            }
        }
Esempio n. 2
0
        internal void RenderFlowNode(DrawingContext dc)
        {
            FormattedText ft;
            FixedNode     fixedNode;

            FixedSOMElement[] somElements;
            String            ouptputString;
            FixedElement      fixedElement;
            Random            random = new Random();

            CultureInfo EnglishCulture = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;

            FixedPage fp = _fixedTextBuilder.FixedTextContainer.FixedDocument.GetFixedPage(PageIndex);
            //
            //Iterate through flow node to draw Transparent Rect and draw its index
            //
            Point    prevTextPoint = new Point(0, 0);
            DpiScale dpi           = fp.GetDpi();

            for (int i = FlowStart.Fp; i <= FlowEnd.Fp; i++)
            {
                FlowNode fn = _fixedTextBuilder.FixedFlowMap[i];
                switch (fn.Type)
                {
                case FlowNodeType.Boundary:
                case FlowNodeType.Virtual:
                    // this two cases won't happen.
                    Debug.Assert(false);
                    break;

                case FlowNodeType.Start:
                case FlowNodeType.End:
                {
                    fixedElement = fn.Cookie as FixedElement;
                    String typeString = fixedElement.Type.ToString();
                    int    indexofDot = typeString.LastIndexOf('.');
                    ouptputString = String.Format("{0}-{1}",
                                                  fn.ToString(),
                                                  typeString.Substring(indexofDot + 1));

                    ft = new FormattedText(ouptputString,
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkGreen,
                                           dpi.PixelsPerDip);
                    // Ideally, for FlowNodeType.Start, this should find next FlowNode with physical location,
                    // and draw it around the physical location.
                    prevTextPoint = CreateFromLastTextPoint(prevTextPoint);

                    dc.DrawText(ft, prevTextPoint);
                    break;
                }

                case FlowNodeType.Noop:
                    ft = new FormattedText(fn.ToString(),
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkGreen,
                                           dpi.PixelsPerDip);
                    prevTextPoint = CreateFromLastTextPoint(prevTextPoint);
                    dc.DrawText(ft, prevTextPoint);
                    break;

                case FlowNodeType.Run:
                    //
                    // Paint the region. The rect is the union of child glyphs.
                    //

                    Glyphs glyphs;
                    Rect   flowRunBox = Rect.Empty;
                    Rect   glyphBox;
                    somElements = _fixedTextBuilder.FixedFlowMap.FlowNodes[fn.Fp].FixedSOMElements;

                    foreach (FixedSOMElement currentSomeElement in somElements)
                    {
                        FixedNode currentFixedNode = currentSomeElement.FixedNode;
                        int       startIndex       = currentSomeElement.StartIndex;
                        int       endIndex         = currentSomeElement.EndIndex;

                        // same as (_IsBoundaryFixedNode(currentFixedNode))
                        if (currentFixedNode.Page == FixedFlowMap.FixedOrderStartPage ||
                            currentFixedNode.Page == FixedFlowMap.FixedOrderEndPage ||
                            currentFixedNode[1] == FixedFlowMap.FixedOrderStartVisual ||
                            currentFixedNode[1] == FixedFlowMap.FixedOrderEndVisual)
                        {
                            continue;
                        }

                        glyphs = fp.GetGlyphsElement(currentFixedNode);
                        Debug.Assert(glyphs != null);

                        glyphBox = FixedTextView._GetGlyphRunDesignRect(glyphs, startIndex, endIndex);
                        if (!glyphBox.IsEmpty)
                        {
                            GeneralTransform g = glyphs.TransformToAncestor(fp);

                            glyphBox = g.TransformBounds(glyphBox);
                        }

                        flowRunBox.Union(glyphBox);
                    }

                    if (flowRunBox.IsEmpty)
                    {
                        Debug.Assert(false);
                    }
                    prevTextPoint.X = flowRunBox.Right;
                    prevTextPoint.Y = flowRunBox.Bottom - random.Next(15);

                    // Draw something the upper left corner of region.
                    ft = new FormattedText(fn.ToString() + "-" + Convert.ToString((int)(fn.Cookie)) +
                                           "-" + Convert.ToString(somElements.Length),
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkBlue,
                                           dpi.PixelsPerDip);
                    dc.DrawText(ft, prevTextPoint);

                    Pen pen = new Pen(Brushes.Blue, 2);
                    flowRunBox.Inflate(random.Next(3), random.Next(3));
                    DrawRectOutline(dc, pen, flowRunBox);
                    break;

                case FlowNodeType.Object:
                    //
                    // Find the mapping fixed node
                    //
                    somElements = _fixedTextBuilder.FixedFlowMap.FlowNodes[fn.Fp].FixedSOMElements;

                    foreach (FixedSOMElement currentSomeElement in somElements)
                    {
                        fixedNode = currentSomeElement.FixedNode;

                        DependencyObject dependencyObject = fp.GetElement(fixedNode);

                        Image image = dependencyObject as Image;
                        Path  path  = dependencyObject as Path;

                        if (image != null || path != null)
                        {
                            Rect imageRect, boundingRect = Rect.Empty;
                            //
                            // Get Image bounding box.
                            //
                            GeneralTransform transform = ((Visual)dependencyObject).TransformToAncestor(fp);
                            // You can't use GetContentBounds inside OnRender
                            if (image != null)
                            {
                                boundingRect = new Rect(0, 0, image.Width, image.Height);
                            }
                            else
                            {
                                boundingRect = path.Data.Bounds;
                            }

                            if (!boundingRect.IsEmpty)
                            {
                                imageRect = transform.TransformBounds(boundingRect);

                                // Image might overlap, inflate the box.
                                imageRect.Inflate(3, 3);
                                dc.DrawRectangle(Brushes.CadetBlue, null, imageRect);

                                prevTextPoint.X = imageRect.Right;
                                prevTextPoint.Y = imageRect.Top;
                            }
                        }
                        else
                        {
                            //
                            // If the object is the Image type(that is not likey).
                            // Use the last Point to infer a comment area!
                            //
                            Debug.Assert(false);
                        }

                        fixedElement = fn.Cookie as FixedElement;
                        ft           = new FormattedText(fn.ToString(),
                                                         EnglishCulture,
                                                         FlowDirection.LeftToRight,
                                                         new Typeface("Courier New"),
                                                         8,
                                                         Brushes.DarkGreen,
                                                         dpi.PixelsPerDip);
                        dc.DrawText(ft, prevTextPoint);
                    }

                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
            }
        }
Esempio n. 3
0
        internal void RenderFixedNode(DrawingContext dc)
        {
            //
            //Iterate through fix node to draw red dotted line
            //
            CultureInfo EnglishCulture = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;

            int lineCount = _lineResults.Length;

            if (lineCount == 0)
            {
                return;
            }

            FixedNode fixedStartPage = _lineResults[0].Start;
            FixedNode fixedEndPage   = _lineResults[lineCount - 1].End;

            FixedNode[]   fixedNodes = _fixedTextBuilder.FixedFlowMap.FixedOrderGetRangeNodes(fixedStartPage, fixedEndPage);
            FixedPage     fp         = _fixedTextBuilder.FixedTextContainer.FixedDocument.GetFixedPage(PageIndex);
            FormattedText ft;
            Point         prevTextPoint = new Point(0, 0);
            DpiScale      dpi           = fp.GetDpi();

            foreach (FixedNode currentFixedNode in fixedNodes)
            {
                if (currentFixedNode.Page == FixedFlowMap.FixedOrderStartPage)
                {
                    prevTextPoint.X = prevTextPoint.Y = 0;
                    ft = new FormattedText("FixedOrderStartPage",
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkViolet,
                                           dpi.PixelsPerDip);
                    dc.DrawText(ft, prevTextPoint);
                    continue;
                }
                if (currentFixedNode.Page == FixedFlowMap.FixedOrderEndPage)
                {
                    prevTextPoint.X = fp.Width - 100;
                    prevTextPoint.Y = fp.Height - 10;
                    ft = new FormattedText("FixedOrderEndPage",
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkViolet,
                                           dpi.PixelsPerDip);
                    dc.DrawText(ft, prevTextPoint);
                    continue;
                }
                if (currentFixedNode[1] == FixedFlowMap.FixedOrderStartVisual ||
                    currentFixedNode[1] == FixedFlowMap.FixedOrderEndVisual)
                {
                    prevTextPoint.X = 2;
                    prevTextPoint.Y = prevTextPoint.Y + 10;
                    String outputString = currentFixedNode[1] == FixedFlowMap.FixedOrderStartVisual ?
                                          "FixedOrderStartVisual" : "FixedOrderEndVisual";
                    ft = new FormattedText(outputString,
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkViolet,
                                           dpi.PixelsPerDip);
                    dc.DrawText(ft, prevTextPoint);
                    continue;
                }

                DependencyObject dependencyObject = fp.GetElement(currentFixedNode);

                Image image = dependencyObject as Image;
                if (image != null)
                {
                    GeneralTransform transform = image.TransformToAncestor(fp);
                    // You can't use GetContentBounds inside OnRender
                    Rect boundingRect = new Rect(0, 0, image.Width, image.Height);
                    Rect imageRect    = transform.TransformBounds(boundingRect);

                    if (!imageRect.IsEmpty)
                    {
                        // Image might overlap, inflate the box.
                        imageRect.Inflate(1, 1);

                        Pen pen = new Pen(Brushes.DarkMagenta, 1.5);
                        DrawRectOutline(dc, pen, imageRect);

                        prevTextPoint.X = imageRect.Right;
                        prevTextPoint.Y = imageRect.Bottom - 10;
                    }
                    else
                    {
                        prevTextPoint.X = 2;
                        prevTextPoint.Y = prevTextPoint.Y + 10;
                    }
                    ft = new FormattedText(currentFixedNode.ToString(),
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkViolet,
                                           dpi.PixelsPerDip);
                    dc.DrawText(ft, prevTextPoint);
                    continue;
                }
                Path path = dependencyObject as Path;
                if (path != null)
                {
                    GeneralTransform transform = path.TransformToAncestor(fp);
                    // You can't use GetContentBounds inside OnRender
                    Rect boundingRect = path.Data.Bounds;
                    Rect imageRect    = transform.TransformBounds(boundingRect);

                    if (!imageRect.IsEmpty)
                    {
                        // Image might overlap, inflate the box.
                        imageRect.Inflate(1, 1);

                        Pen pen = new Pen(Brushes.DarkMagenta, 1.5);
                        DrawRectOutline(dc, pen, imageRect);

                        prevTextPoint.X = imageRect.Right;
                        prevTextPoint.Y = imageRect.Bottom - 10;
                    }
                    else
                    {
                        prevTextPoint.X = 2;
                        prevTextPoint.Y = prevTextPoint.Y + 10;
                    }
                    ft = new FormattedText(currentFixedNode.ToString(),
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkViolet,
                                           dpi.PixelsPerDip);
                    dc.DrawText(ft, prevTextPoint);
                    continue;
                }
                Glyphs glyphs = dependencyObject as Glyphs;
                if (glyphs != null)
                {
                    GlyphRun run = glyphs.ToGlyphRun();
                    if (run != null)
                    {
                        Rect glyphBox = run.ComputeAlignmentBox();
                        glyphBox.Offset(glyphs.OriginX, glyphs.OriginY);
                        GeneralTransform transform = glyphs.TransformToAncestor(fp);
                        //
                        // Draw it using the dotted red line
                        //
                        Pen       pen = new Pen(Brushes.Red, 0.5);
                        Transform t   = transform.AffineTransform;
                        if (t != null)
                        {
                            dc.PushTransform(t);
                        }
                        else
                        {
                            dc.PushTransform(Transform.Identity);
                        }
                        DrawRectOutline(dc, pen, glyphBox);

                        prevTextPoint.X = glyphBox.Right;
                        prevTextPoint.Y = glyphBox.Bottom;
                        transform.TryTransform(prevTextPoint, out prevTextPoint);
                        dc.Pop(); // transform
                    }
                    else
                    {
                        prevTextPoint.X = 2;
                        prevTextPoint.Y = prevTextPoint.Y + 10;
                    }

                    ft = new FormattedText(currentFixedNode.ToString(),
                                           EnglishCulture,
                                           FlowDirection.LeftToRight,
                                           new Typeface("Courier New"),
                                           8,
                                           Brushes.DarkViolet,
                                           dpi.PixelsPerDip);
                    dc.DrawText(ft, prevTextPoint);
                    continue;
                }

                //
                // For anything else, there is this code to draw ...
                //
                prevTextPoint.X = 2;
                prevTextPoint.Y = prevTextPoint.Y + 10;
                ft = new FormattedText(currentFixedNode.ToString(),
                                       EnglishCulture,
                                       FlowDirection.LeftToRight,
                                       new Typeface("Courier New"),
                                       8,
                                       Brushes.DarkViolet,
                                       dpi.PixelsPerDip);
                dc.DrawText(ft, prevTextPoint);
            }
        }