Esempio n. 1
0
        // Set the map file used to draw.
        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.
        }
Esempio n. 2
0
        public static PdfMapFile ValidatePdf(string pdfFileName, out float dpi, out Size bitmapSize, out string errorMessageText)
        {
            IPdfLoadingStatus loadingStatus = new PdfLoadingUI();  // UNDONE: Should this be passed in instead?

            PdfMapFile mapFile = new PdfMapFile(pdfFileName);

            bool ok = true;
            PdfMapFile.ConversionStatus status = mapFile.BeginConversion();
            if (status == PdfMapFile.ConversionStatus.Working) {
                // Put up a modal dialog until loading is complete.
                mapFile.ConversionCompleted += delegate { 
                    loadingStatus.LoadingComplete(mapFile.Status == PdfMapFile.ConversionStatus.Success, mapFile.ConversionOutput);
                };
                if (status == PdfMapFile.ConversionStatus.Working) {
                    ok = loadingStatus.ShowLoadingStatus(pdfFileName);
                }
            }

            status = mapFile.Status;
            if (!ok || status == PdfMapFile.ConversionStatus.Failure) {
                errorMessageText = MiscText.PdfConversionFailed;
                if (!string.IsNullOrWhiteSpace(mapFile.ConversionOutput))
                    errorMessageText += ": " + mapFile.ConversionOutput;
                dpi = 0;
                bitmapSize = default(Size);
                return null;
            }

            // Make sure resulting image file can be read.
            try {
                Bitmap bitmap = (Bitmap)Image.FromFile(mapFile.PngFileName);
                dpi = bitmap.HorizontalResolution;
                bitmapSize = bitmap.Size;
                bitmap.Dispose();
                errorMessageText = "";
                return mapFile;
            }
            catch {
                // Couldn't read the resulting PNG
                errorMessageText = string.Format(MiscText.PdfResultNotReadable, mapFile.PngFileName);
                dpi = 0;
                bitmapSize = default(Size);
                return null;
            }
        }
Esempio n. 3
0
        // Set the map file used to draw.
        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.
        }
Esempio n. 4
0
        public static PdfMapFile ValidatePdf(string pdfFileName, out float dpi, out Size bitmapSize, out string errorMessageText)
        {
            IPdfLoadingStatus loadingStatus = new PdfLoadingUI();  // UNDONE: Should this be passed in instead?

            PdfMapFile mapFile = new PdfMapFile(pdfFileName);

            bool ok = true;
            PdfMapFile.ConversionStatus status = mapFile.BeginConversion();
            if (status == PdfMapFile.ConversionStatus.Working) {
                // Put up a modal dialog until loading is complete.
                mapFile.ConversionCompleted += delegate {
                    loadingStatus.LoadingComplete(mapFile.Status == PdfMapFile.ConversionStatus.Success, mapFile.ConversionOutput);
                };
                if (status == PdfMapFile.ConversionStatus.Working) {
                    ok = loadingStatus.ShowLoadingStatus(pdfFileName);
                }
            }

            status = mapFile.Status;
            if (!ok || status == PdfMapFile.ConversionStatus.Failure) {
                errorMessageText = MiscText.PdfConversionFailed;
                if (!string.IsNullOrWhiteSpace(mapFile.ConversionOutput))
                    errorMessageText += ": " + mapFile.ConversionOutput;
                dpi = 0;
                bitmapSize = default(Size);
                return null;
            }

            // Make sure resulting image file can be read.
            try {
                Bitmap bitmap = (Bitmap)Image.FromFile(mapFile.PngFileName);
                dpi = bitmap.HorizontalResolution;
                bitmapSize = bitmap.Size;
                bitmap.Dispose();
                errorMessageText = "";
                return mapFile;
            }
            catch {
                // Couldn't read the resulting PNG
                errorMessageText = string.Format(MiscText.PdfResultNotReadable, mapFile.PngFileName);
                dpi = 0;
                bitmapSize = default(Size);
                return null;
            }
        }