PurplePen.MapDisplay.SetMapFile C# (CSharp) Method

SetMapFile() public method

public SetMapFile ( MapType newMapType, string newFilename ) : void
newMapType MapType
newFilename string
return void
        public void SetMapFile(MapType newMapType, string newFilename)
        {
            this.mapType = newMapType;
            this.filename = newFilename;
            this.bitmap = null;
            this.map = null;

            if (newMapType == MapType.None) {
                map = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                bitmap = null;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.OCAD) {
                map = new Map(MapUtil.TextMetricsProvider, new GDIPlus_FileLoader(Path.GetDirectoryName(newFilename)));
                mapVersion = InputOutput.ReadFile(newFilename, map);
                bitmap = null;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.Bitmap) {
                map = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                Bitmap bm = (Bitmap)Image.FromFile(newFilename);
                bitmap = new GDIPlus_Bitmap(bm);
                bitmapDpi = bm.HorizontalResolution;
                pdfMapFile = null;
            }
            else if (newMapType == MapType.PDF) {
                string errorText;
                map = null;
                mapVersion = new MapFileFormat(MapFileFormatKind.None, 0);
                Size bitmapSize;
                pdfMapFile = MapUtil.ValidatePdf(newFilename, out bitmapDpi, out bitmapSize, out errorText);
                if (pdfMapFile == null) {
                    this.mapType = MapType.None;
                    bitmap = null;
                }
                else {
                    Bitmap bm = (Bitmap)Image.FromFile(pdfMapFile.PngFileName);
                    bitmap = new GDIPlus_Bitmap(bm);
                }
            }
            else {
                Debug.Fail("bad maptype");
            }

            UpdateDimmedBitmap();
            RaiseChanged(null);        // redraw everything.
        }

Usage Example

Example #1
0
        // Create a single PDF file
        void CreateOnePdfFile(string fileName, IEnumerable <CourseDesignator> courseDesignators)
        {
            List <CoursePage> pages     = LayoutPages(courseDesignators);
            PdfWriter         pdfWriter = new PdfWriter(Path.GetFileNameWithoutExtension(fileName), coursePdfSettings.ColorModel == ColorModel.CMYK);

            foreach (CoursePage page in pages)
            {
                CoursePage pageToDraw = page;

                SizeF paperSize = new SizeF(pageToDraw.paperSize.Width / 100F, pageToDraw.paperSize.Height / 100F);
                if (pageToDraw.landscape)
                {
                    paperSize = new SizeF(paperSize.Height, paperSize.Width);
                }

                if (controller.UpdateProgressDialog(string.Format(MiscText.CreatingFile, Path.GetFileName(fileName)), (double)currentPage / (double)totalPages))
                {
                    throw new Exception(MiscText.CancelledByUser);
                }

                IGraphicsTarget grTarget;
                PdfImporter     pdfImporter = null;

                if (IsPdfMap)
                {
                    // We need to re-obtain a PdfImporter every time, or else very strange bugs start to crop up.

                    pdfImporter = new PdfImporter(sourcePdfMapFileName);

                    float scaleRatio = CourseView.CreatePrintingCourseView(eventDB, page.courseDesignator).ScaleRatio;
                    if (scaleRatio == 1.0)
                    {
                        // If we're doing a PDF at scale 1, we just copy the page directly.
                        grTarget   = pdfWriter.BeginCopiedPage(pdfImporter, 0);
                        pageToDraw = PdfNonScaledPage(page.courseDesignator);
                    }
                    else
                    {
                        Matrix     transform = Geometry.CreateInvertedRectangleTransform(page.printRectangle, page.mapRectangle);
                        RectangleF printedPortionInMapCoords = Geometry.TransformRectangle(transform, new RectangleF(0, 0, paperSize.Width * 100F, paperSize.Height * 100F));
                        RectangleF printedPortionInInches    = new RectangleF(
                            Geometry.InchesFromMm(printedPortionInMapCoords.Left),
                            Geometry.InchesFromMm(mapBounds.Height - printedPortionInMapCoords.Bottom),
                            Geometry.InchesFromMm(printedPortionInMapCoords.Width),
                            Geometry.InchesFromMm(printedPortionInMapCoords.Height));

                        grTarget = pdfWriter.BeginCopiedPartialPage(pdfImporter, 0, paperSize, printedPortionInInches);
                    }

                    // Don't draw the map normally.
                    mapDisplay.SetMapFile(MapType.None, null);
                }
                else
                {
                    grTarget = pdfWriter.BeginPage(paperSize);
                }

                DrawPage(grTarget, pageToDraw);
                pdfWriter.EndPage(grTarget);
                grTarget.Dispose();

                if (pdfImporter != null)
                {
                    pdfImporter.Dispose();
                    pdfImporter = null;
                }

                currentPage += 1;
            }

            pdfWriter.Save(fileName);
        }
All Usage Examples Of PurplePen.MapDisplay::SetMapFile