Example #1
0
        private void PrintPage(object sender, PrintPageEventArgs e)
        {
            if (currentPage < totalPages)
            {
                // Get the graphics and origin relative to the page edge.
                Graphics g = e.Graphics;
                PointF   origin;
                if (!printPreviewInProgress && !printingToBitmaps)
                {
                    origin = new PointF(e.PageSettings.HardMarginX, e.PageSettings.HardMarginY);
                }
                else
                {
                    origin = new PointF();
                }

                // Get the dpi of the printer.
                float dpi = Math.Max((int)g.DpiX, (int)g.DpiY);

                // Move the origin of the graphics to the margin boundaries.
                g.TranslateTransform(e.MarginBounds.Left - origin.X, e.MarginBounds.Top - origin.Y);
                SizeF size = new SizeF(e.MarginBounds.Width, e.MarginBounds.Height);

                // Draw the page.
                IGraphicsTarget graphicsTarget;
                if (colorModel == ColorModel.RGB)
                {
                    graphicsTarget = new GDIPlus_GraphicsTarget(g);
                }
                else if (colorModel == ColorModel.CMYK)
                {
                    graphicsTarget = new GDIPlus_GraphicsTarget(g, new SwopColorConverter());
                }
                else
                {
                    throw new NotImplementedException();
                }

                using (graphicsTarget) {
                    DrawPage(graphicsTarget, currentPage, size, dpi);
                }
                graphicsTarget = null;

                // Update page count.
                ++currentPage;
            }

            e.HasMorePages = (currentPage < totalPages) && !StopDocumentAfterPage(currentPage - 1);
        }
Example #2
0
        public override void Highlight(Graphics g, Matrix xformWorldToPixel, Brush brush, bool erasing)
        {
            SymPath path1, path2;
            float thickness;

            GDIPlus_GraphicsTarget grTarget = new GDIPlus_GraphicsTarget(g);

            object brushKey = new object();
            grTarget.CreateGdiPlusBrush(brushKey, brush, false);

            // Get line thickness.
            thickness = TransformDistance(NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, xformWorldToPixel);

            // Get the paths.
            GetPaths(out path1, out path2);

            // Move and rotate the paths to the correct position.
            Matrix moveAndRotate = new Matrix();
            moveAndRotate.Rotate(orientation);
            moveAndRotate.Translate(location.X, location.Y, MatrixOrder.Append);
            path1 = path1.Transform(moveAndRotate);
            path2 = path2.Transform(moveAndRotate);

            object penKey = new object();
            grTarget.CreatePen(penKey, brushKey, thickness, LineCap.Flat, LineJoin.Miter, 5);

            // Draw it.
            path1.DrawTransformed(grTarget, penKey, xformWorldToPixel);
            path2.DrawTransformed(grTarget, penKey, xformWorldToPixel);

            grTarget.Dispose();
        }
Example #3
0
        // The core printing routine. The origin of the graphics is the upper-left of the margins,
        // and the printArea in the size to draw into (in hundreths of an inch).
        protected override void DrawPage(IGraphicsTarget graphicsTarget, int pageNumber, SizeF printArea, float dpi)
        {
            CoursePage page = pages[pageNumber];

            // Get the course view for the course we are printing.
            CourseView courseView = CourseView.CreatePrintingCourseView(eventDB, page.courseDesignator);

            // Get the correct purple color to print the course in.
            short ocadId;
            float purpleC, purpleM, purpleY, purpleK;
            bool  purpleOverprint;

            FindPurple.GetPurpleColor(mapDisplay, appearance, out ocadId, out purpleC, out purpleM, out purpleY, out purpleK, out purpleOverprint);

            // Create a course layout from the view.
            CourseLayout layout = new CourseLayout();

            layout.SetLayerColor(CourseLayer.Descriptions, NormalCourseAppearance.blackColorOcadId, NormalCourseAppearance.blackColorName, NormalCourseAppearance.blackColorC, NormalCourseAppearance.blackColorM, NormalCourseAppearance.blackColorY, NormalCourseAppearance.blackColorK, false);
            layout.SetLayerColor(CourseLayer.MainCourse, ocadId, NormalCourseAppearance.courseColorName, purpleC, purpleM, purpleY, purpleK, purpleOverprint);
            CourseFormatter.FormatCourseToLayout(symbolDB, courseView, appearance, layout, CourseLayer.MainCourse);

            // Set the course layout into the map display
            mapDisplay.SetCourse(layout);
            this.mapDisplay.SetPrintArea(null);

            // Collecting garbage should make out of memory less common.
            GC.Collect();

            if (graphicsTarget is GDIPlus_GraphicsTarget)
            {
                // We print to intermediate bands of bitmaps. This is the only way to get purple blending correct.
                // Other code ensure that if purple blending is on, we always take this code path.

                GDIPlus_GraphicsTarget gdiGraphicsTarget = ((GDIPlus_GraphicsTarget)graphicsTarget);
                Graphics g = gdiGraphicsTarget.Graphics;
                // Save and restore state so we can mess with stuff.
                GraphicsState graphicsState = g.Save();

                // Printing via a bitmap. Works best with some print drivers.
                dpi = AdjustDpi(dpi);

                const long        MAX_PIXELS_PER_BAND = 20000000; // 20M pixels = 60M bytes (3 bytes per pixel).
                List <CoursePage> bands = BandPageToLimitBitmapSize(page, dpi, MAX_PIXELS_PER_BAND);

                // Create the bitmap. Can do this once because each band is the same size.
                int    bitmapWidth  = (int)Math.Round(bands[0].printRectangle.Width * dpi / 100F);
                int    bitmapHeight = (int)Math.Round(bands[0].printRectangle.Height * dpi / 100F);
                Bitmap bitmap       = new Bitmap(bitmapWidth, bitmapHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                foreach (CoursePage band in bands)
                {
                    // Set the transform
                    Matrix transform = Geometry.CreateInvertedRectangleTransform(band.mapRectangle, new RectangleF(0, 0, bitmapWidth, bitmapHeight));
                    mapDisplay.Draw(bitmap, transform);

                    try {
                        // Draw the bitmap on the printer.
                        g.DrawImage(bitmap, band.printRectangle);
                    }
                    catch (Exception) { }
                }

                // restore state.
                g.Restore(graphicsState);
                bitmap.Dispose();
            }
            else
            {
                // Print directly. Used only when prerasterization is off.
                // Set the transform, and the clip.
                Matrix transform = Geometry.CreateInvertedRectangleTransform(page.mapRectangle, page.printRectangle);
                PushRectangleClip(graphicsTarget, page.printRectangle);
                graphicsTarget.PushTransform(transform);
                // Determine the resolution in map coordinates.
                Matrix inverseTransform = transform.Clone();
                inverseTransform.Invert();
                float minResolutionPage = 100F / dpi;
                float minResolutionMap  = Geometry.TransformDistance(minResolutionPage, inverseTransform);

                // And draw.
                mapDisplay.Draw(graphicsTarget, page.mapRectangle, minResolutionMap);

                graphicsTarget.PopTransform();
                graphicsTarget.PopClip();
            }
        }
Example #4
0
        public override void Highlight(Graphics g, Matrix xformWorldToPixel, Brush brush, bool erasing)
        {
            SymPath path1, path2, path3, path4;
            float thickness;

            GDIPlus_GraphicsTarget grTarget = new GDIPlus_GraphicsTarget(g);

            object brushKey = new object();
            grTarget.CreateGdiPlusBrush(brushKey, brush, false);

            // Get line thickness.
            thickness = TransformDistance(NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, xformWorldToPixel);

            // Get the paths.
            path1 = new SymPath(OffsetCoords(ScaleCoords((PointF[]) coords1.Clone()), location.X, location.Y), kinds1);
            path2 = new SymPath(OffsetCoords(ScaleCoords((PointF[]) coords2.Clone()), location.X, location.Y), kinds2);
            path3 = new SymPath(OffsetCoords(ScaleCoords((PointF[]) coords3.Clone()), location.X, location.Y), kinds3);
            path4 = new SymPath(OffsetCoords(ScaleCoords((PointF[]) coords4.Clone()), location.X, location.Y), kinds4);

            object penKey = new object();
            grTarget.CreatePen(penKey, brushKey, thickness, LineCap.Round, LineJoin.Miter, 5);

            // Draw the paths
            path1.DrawTransformed(grTarget, penKey, xformWorldToPixel);
            path2.DrawTransformed(grTarget, penKey, xformWorldToPixel);
            path3.DrawTransformed(grTarget, penKey, xformWorldToPixel);
            path4.DrawTransformed(grTarget, penKey, xformWorldToPixel);

            grTarget.Dispose();
        }
Example #5
0
        public override void Highlight(Graphics g, Matrix xformWorldToPixel, Brush brush, bool erasing)
        {
            object brushKey = new object();
            object penKey = new object();

            using (GDIPlus_GraphicsTarget graphicsTarget = new GDIPlus_GraphicsTarget(g)) {
                graphicsTarget.CreateGdiPlusBrush(brushKey, brush, false);
                graphicsTarget.CreatePen(penKey, brushKey, Geometry.TransformDistance(FullWidth, xformWorldToPixel), LineCap.Flat, LineJoin.Miter, 10);
                SymPath path = CreateSymPath();
                path = path.Transform(xformWorldToPixel);
                path.Draw(graphicsTarget, penKey);
            }
        }
Example #6
0
        // Draw the highlight. Everything must be drawn in pixel coords so fast erase works correctly.
        public override void Highlight(Graphics g, Matrix xformWorldToPixel, Brush brush, bool erasing)
        {
            GDIPlus_GraphicsTarget grTarget = new GDIPlus_GraphicsTarget(g);

               object brushKey = new object();
               grTarget.CreateGdiPlusBrush(brushKey, brush, false);

               // Get thickness of line.
               float pixelThickness = TransformDistance(thickness * scaleRatio, xformWorldToPixel);

               SymPath[] gappedPaths = LegGap.SplitPathWithGaps(path, gaps);

               // Draw it.
               object penKey = new object();
               grTarget.CreatePen(penKey, brushKey, pixelThickness, LineCap.Flat, LineJoin.Miter, 5);

               try {
               foreach (SymPath p in gappedPaths) {
                   p.DrawTransformed(grTarget, penKey, xformWorldToPixel);
               }
               }
               catch (ExternalException) {
               // Ignore this exeption. Not sure what causes it.
               }

               grTarget.Dispose();
        }
Example #7
0
        // Draw the highlight. Everything must be draw in pixel coords so fast erase works correctly.
        public override void Highlight(Graphics g, Matrix xformWorldToPixel, Brush brush, bool erasing)
        {
            GDIPlus_GraphicsTarget grTarget = new GDIPlus_GraphicsTarget(g);

            object brushKey = new object();
            grTarget.CreateGdiPlusBrush(brushKey, brush, false);

            // Draw the boundary.
            object penKey = new object();
            grTarget.CreatePen(penKey, brushKey, 2, LineCap.Round, LineJoin.Round, 5);
            path.DrawTransformed(grTarget, penKey, xformWorldToPixel);

            // Get a brush to fill the interior with.
            object fillBrushKey;

            if (erasing)
                fillBrushKey = brushKey;
            else {
                fillBrushKey = new object();
                grTarget.CreateGdiPlusBrush(fillBrushKey, NormalCourseAppearance.areaHighlight, false);
            }

            // Draw the interior
            path.FillTransformed(grTarget, fillBrushKey, xformWorldToPixel);

            grTarget.Dispose();
        }
Example #8
0
        private void PrintPage(object sender, PrintPageEventArgs e)
        {
            if (currentPage < totalPages) {
                // Get the graphics and origin relative to the page edge.
                Graphics g = e.Graphics;
                PointF origin;
                if (!printPreviewInProgress && !printingToBitmaps)
                    origin = new PointF(e.PageSettings.HardMarginX, e.PageSettings.HardMarginY);
                else
                    origin = new PointF();

                // Get the dpi of the printer.
                float dpi = Math.Max((int) g.DpiX, (int) g.DpiY);

                // Move the origin of the graphics to the margin boundaries.
                g.TranslateTransform(e.MarginBounds.Left - origin.X, e.MarginBounds.Top - origin.Y);
                SizeF size = new SizeF(e.MarginBounds.Width, e.MarginBounds.Height);

                // Draw the page.
                IGraphicsTarget graphicsTarget;
                if (colorModel == ColorModel.RGB)
                    graphicsTarget = new GDIPlus_GraphicsTarget(g);
                else if (colorModel == ColorModel.CMYK)
                    graphicsTarget = new GDIPlus_GraphicsTarget(g, new SwopColorConverter());
                else
                    throw new NotImplementedException();

                using (graphicsTarget) {
                    DrawPage(graphicsTarget, currentPage, size, dpi);
                }
                graphicsTarget = null;

                // Update page count.
                ++currentPage;
            }

            e.HasMorePages = (currentPage < totalPages) && !StopDocumentAfterPage(currentPage - 1);
        }