Exemple #1
0
        private void _rasterImageViewer_PostImagePaint(object sender, PaintEventArgs e)
        {
            if (_selectedText != null && _selectedText[_currentPageNumber] != null)
            {
                HighlightSelectedWords(e.Graphics);
            }

            if (HighlightObjects && _document != null)
            {
                PDFDocumentPage page = _document.Pages[_currentPageNumber - 1];

                HighlightObjectsData data = new HighlightObjectsData();
                data.TextBrush         = new SolidBrush(Color.FromArgb(128, Color.Yellow));
                data.RetangleBrush     = new SolidBrush(Color.FromArgb(128, Color.Black));
                data.ImageBrush        = new SolidBrush(Color.FromArgb(128, Color.Red));
                data.HyperlinkBrush    = new SolidBrush(Color.FromArgb(128, Color.Blue));
                data.InternalLinkBrush = new SolidBrush(Color.FromArgb(128, Color.Green));

                DrawHighlightObjects(e.Graphics, data, page);
                DrawLegends(e.Graphics, data);

                data.TextBrush.Dispose();
                data.RetangleBrush.Dispose();
                data.ImageBrush.Dispose();
                data.HyperlinkBrush.Dispose();
                data.InternalLinkBrush.Dispose();
            }
        }
Exemple #2
0
        private void DrawHighlightObjects(Graphics g, HighlightObjectsData data, PDFDocumentPage page)
        {
            LeadMatrix  mm    = _rasterImageViewer.GetImageTransformWithDpi(true);
            Matrix      m     = new Matrix((float)mm.M11, (float)mm.M12, (float)mm.M21, (float)mm.M22, (float)mm.OffsetX, (float)mm.OffsetY);
            Transformer trans = new Transformer(m);

            // Clip to the current image bounds
            RectangleF clipRect = new RectangleF(0, 0, _rasterImageViewer.Image.ImageWidth, _rasterImageViewer.Image.ImageHeight);

            clipRect = trans.RectangleToPhysical(clipRect);
            g.SetClip(clipRect);

            // Draw objects
            if (page.Objects != null)
            {
                foreach (PDFObject obj in page.Objects)
                {
                    RectangleF rc = ToRectangleF(page.ConvertRect(PDFCoordinateType.Pdf, PDFCoordinateType.Pixel, obj.Bounds));
                    rc = trans.RectangleToPhysical(rc);

                    // Highlight it
                    Brush brush;

                    if (obj.ObjectType == PDFObjectType.Image)
                    {
                        brush = data.ImageBrush;
                    }
                    else if (obj.ObjectType == PDFObjectType.Rectangle)
                    {
                        brush = data.RetangleBrush;
                    }
                    else
                    {
                        brush = data.TextBrush;
                    }

                    DrawRectangle(g, brush, rc);
                }
            }

            // Draw internal and hyper links
            foreach (PageLink link in _pageLinks)
            {
                RectangleF rc = trans.RectangleToPhysical(new RectangleF(link.ImageBounds.X, link.ImageBounds.Y, link.ImageBounds.Width, link.ImageBounds.Height));

                Brush brush;
                if (link.InternalLinkIndex != -1)
                {
                    brush = data.InternalLinkBrush;
                }
                else
                {
                    brush = data.HyperlinkBrush;
                }

                DrawRectangle(g, brush, rc);
            }
        }
Exemple #3
0
        private void DrawLegends(Graphics g, HighlightObjectsData data)
        {
            GraphicsState state = g.Save();

            g.ResetClip();

            SizeF      textSize = g.MeasureString("WWW", Font);
            RectangleF rc       = new RectangleF(0, 0, _rasterImageViewer.ClientRectangle.Width, textSize.Height);

            g.FillRectangle(Brushes.White, rc);
            g.DrawString("Legends: ", Font, Brushes.Black, 0, 0);

            float x = g.MeasureString("Legends: ", Font).Width + 1;

            string[] texts =
            {
                "Text",
                "Rectangle",
                "Image",
                "Hyperlink",
                "InternalLink",
            };

            Brush[] brushes =
            {
                data.TextBrush,
                data.RetangleBrush,
                data.ImageBrush,
                data.HyperlinkBrush,
                data.InternalLinkBrush,
            };

            rc.Inflate(-1, -2);
            rc.Width = rc.Height;

            for (int i = 0; i < texts.Length; i++)
            {
                rc.X = x;

                DrawRectangle(g, brushes[i], rc);
                x += rc.Width + 1;

                g.DrawString(texts[i], Font, Brushes.Black, x, 1);
                x += g.MeasureString(texts[i], Font).Width + 8;
            }

            g.Restore(state);
        }
Exemple #4
0
        void _rasterImageViewer_PostRender(object sender, Leadtools.Controls.ImageViewerRenderEventArgs e)
        {
            PDFDocumentPage page = _document.Pages[_currentPageNumber - 1];

            if (_selectedText != null && _selectedText[_currentPageNumber] != null)
            {
                HighlightSelectedWords(e.PaintEventArgs.Graphics);
            }

            if (HighlightObjects && _document != null)
            {
                HighlightObjectsData data = new HighlightObjectsData();
                data.TextBrush         = new SolidBrush(Color.FromArgb(128, Color.Yellow));
                data.RetangleBrush     = new SolidBrush(Color.FromArgb(128, Color.Black));
                data.ImageBrush        = new SolidBrush(Color.FromArgb(128, Color.Red));
                data.HyperlinkBrush    = new SolidBrush(Color.FromArgb(128, Color.Blue));
                data.InternalLinkBrush = new SolidBrush(Color.FromArgb(128, Color.Green));

                DrawHighlightObjects(e.PaintEventArgs.Graphics, data, page);
                DrawLegends(e.PaintEventArgs.Graphics, data);

                data.TextBrush.Dispose();
                data.RetangleBrush.Dispose();
                data.ImageBrush.Dispose();
                data.HyperlinkBrush.Dispose();
                data.InternalLinkBrush.Dispose();
            }

            if (_highlightSelectedImageObject && !HighlightObjects)
            {
                using (Brush imageBrush = new SolidBrush(Color.FromArgb(128, Color.Red)))
                {
                    DrawHighlightImageObject(e.PaintEventArgs.Graphics, imageBrush, page);
                }
            }
        }