public static bool ValidateMapFile(string mapFileName, out float scale, out float dpi, out Size bitmapSize, out RectangleF mapBounds, out MapType mapType, out string errorMessageText)
{
scale = 0; dpi = 0;
mapType = MapType.None;
bitmapSize = new Size();
string fileExtension = Path.GetExtension(mapFileName);
if (string.Compare(fileExtension, ".pdf", StringComparison.InvariantCultureIgnoreCase) == 0) {
if (ValidatePdf(mapFileName, out dpi, out bitmapSize, out errorMessageText) != null) {
mapType = MapType.PDF;
mapBounds = new RectangleF(0, 0, (float)bitmapSize.Width / dpi * 25.4F, (float) bitmapSize.Height / dpi * 25.4F);
return true;
}
else {
mapBounds = new RectangleF();
return false;
}
}
Map map = new Map(TextMetricsProvider, new GDIPlus_FileLoader(Path.GetDirectoryName(mapFileName)));
try {
InputOutput.ReadFile(mapFileName, map);
}
catch (Exception e) {
// Didn't load as an OCAD file. If it has a non-OCD/OpenMapper extension, try loading as an image.
if ((string.Compare(fileExtension, ".ocd", StringComparison.InvariantCultureIgnoreCase) != 0) &&
(string.Compare(fileExtension, ".omap", StringComparison.InvariantCultureIgnoreCase) != 0) &&
(string.Compare(fileExtension, ".xmap", StringComparison.InvariantCultureIgnoreCase) != 0))
{
try {
Bitmap bitmap = (Bitmap) Image.FromFile(mapFileName);
bitmapSize = bitmap.Size;
dpi = bitmap.HorizontalResolution;
bitmap.Dispose();
mapType = MapType.Bitmap;
mapBounds = new RectangleF(0, 0, (float)bitmapSize.Width / dpi * 25.4F, (float)bitmapSize.Height / dpi * 25.4F);
errorMessageText = "";
return true;
}
catch {
// Wasn't an bitmap file either.
errorMessageText = string.Format(MiscText.CannotReadImageFile, mapFileName);
mapBounds = new RectangleF();
return false;
}
}
errorMessageText = string.Format(MiscText.CannotReadMap, e.Message);
mapBounds = new RectangleF();
return false;
}
using (map.Read())
{
scale = map.MapScale;
mapBounds = map.Bounds;
}
errorMessageText = "";
mapType = MapType.OCAD;
return true;
}