Пример #1
0
        public static Bitmap RenderHighlights(int width, int height, PDFDocument pdf_document, int page)
        {
            WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread();

            // Render onto a scratch image in solid
            Bitmap bitmap = new Bitmap(width, height);     // <--- must b Dispose()d by caller

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                double   last_right        = Double.NegativeInfinity;
                double   last_top          = Double.NegativeInfinity;
                double   last_bottom       = Double.NegativeInfinity;
                PointF[] adjoinment_points = new PointF[4];

                // TODO: next call can be very costly; MUST run in background!
                var highlights = pdf_document.Highlights.GetHighlightsForPage(page);

                foreach (PDFHighlight highlight in highlights)
                {
                    using (Brush highlight_pen = new SolidBrush(StandardHighlightColours.GetColor_Drawing(highlight.Color)))
                    {
                        graphics.FillRectangle(highlight_pen, (float)(highlight.Left * width), (float)(highlight.Top * height), (float)(highlight.Width * width), (float)(highlight.Height * height));

                        // Do some adjoining
                        if (Math.Abs(last_right - highlight.Left) < highlight.Height * 0.75 && Math.Abs(last_top - highlight.Top) < highlight.Height * 0.75 && Math.Abs(last_bottom - highlight.Bottom) < highlight.Height * 0.75)
                        {
                            // 0 -- 1
                            // |    |
                            // 3 -- 2

                            adjoinment_points[0].X = (float)(last_right * width);
                            adjoinment_points[0].Y = (float)(last_top * height);

                            adjoinment_points[1].X = (float)(highlight.Left * width);
                            adjoinment_points[1].Y = (float)(highlight.Top * height);

                            adjoinment_points[2].X = (float)(highlight.Left * width);
                            adjoinment_points[2].Y = (float)(highlight.Bottom * height);

                            adjoinment_points[3].X = (float)(last_right * width);
                            adjoinment_points[3].Y = (float)(last_bottom * height);

                            graphics.FillPolygon(highlight_pen, adjoinment_points);
                        }

                        // Remember the last position for future potential adjoining
                        last_right  = highlight.Right;
                        last_top    = highlight.Top;
                        last_bottom = highlight.Bottom;
                    }
                }
            }

            return(bitmap);
        }
        public static Bitmap RenderHighlights(int width, int height, PDFDocument pdf_document, int page)
        {
            // Render onto a scratch image in solid
            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                double   last_right        = Double.NegativeInfinity;
                double   last_top          = Double.NegativeInfinity;
                double   last_bottom       = Double.NegativeInfinity;
                PointF[] adjoinment_points = new PointF[4];

                foreach (PDFHighlight highlight in pdf_document.Highlights.GetHighlightsForPage(page))
                {
                    Brush highlight_pen = new SolidBrush(StandardHighlightColours.GetColor_Drawing(highlight.Color));
                    graphics.FillRectangle(highlight_pen, (float)(highlight.Left * width), (float)(highlight.Top * height), (float)(highlight.Width * width), (float)(highlight.Height * height));

                    // Do some adjoining
                    if (Math.Abs(last_right - highlight.Left) < highlight.Height * 0.75 && Math.Abs(last_top - highlight.Top) < highlight.Height * 0.75 && Math.Abs(last_bottom - highlight.Bottom) < highlight.Height * 0.75)
                    {
                        // 0 -- 1
                        // |    |
                        // 3 -- 2

                        adjoinment_points[0].X = (float)(last_right * width);
                        adjoinment_points[0].Y = (float)(last_top * height);

                        adjoinment_points[1].X = (float)(highlight.Left * width);
                        adjoinment_points[1].Y = (float)(highlight.Top * height);

                        adjoinment_points[2].X = (float)(highlight.Left * width);
                        adjoinment_points[2].Y = (float)(highlight.Bottom * height);

                        adjoinment_points[3].X = (float)(last_right * width);
                        adjoinment_points[3].Y = (float)(last_bottom * height);

                        graphics.FillPolygon(highlight_pen, adjoinment_points);
                    }

                    // Remember the last position for future potential adjoining
                    last_right  = highlight.Right;
                    last_top    = highlight.Top;
                    last_bottom = highlight.Bottom;
                }
            }

            return(bitmap);
        }