Add some basic checks on printer resolution to try to debug issue #11

master
Nathan Crawford 2016-04-04 22:20:51 -04:00
rodzic 8798fcb80c
commit fe2e9a7446
1 zmienionych plików z 18 dodań i 3 usunięć

Wyświetl plik

@ -527,9 +527,24 @@ namespace embroideryReader
{
if (design != null)
{
float inchesPerMM = 0.03937007874015748031496062992126f;
e.Graphics.ScaleTransform((float)(e.PageSettings.PrinterResolution.X * inchesPerMM * 0.01f), (float)(e.PageSettings.PrinterResolution.Y * inchesPerMM * 0.01f));
using (Bitmap tempDrawArea = design.designToBitmap((float)settings.threadThickness, settings.filterStiches, settings.filterStitchesThreshold, e.PageSettings.PrinterResolution.X * inchesPerMM * 0.2f))
int xDpi = e.PageSettings.PrinterResolution.X;
int yDpi = e.PageSettings.PrinterResolution.Y;
// Basic checks on printer resolution
if(xDpi < 20 || xDpi > 10000)
{
throw new ArgumentOutOfRangeException("Printer X DPI claims to be '" + xDpi + "', expected range 20 - 10000");
}
if (yDpi < 20 || yDpi > 10000)
{
throw new ArgumentOutOfRangeException("Printer Y DPI claims to be '" + yDpi + "', expected range 20 - 10000");
}
const double inchesPerMM = 0.03937007874015748031496062992126f;
double graphicsXScaleFactor = xDpi * inchesPerMM * 0.01;
double graphicsYScaleFactor = yDpi * inchesPerMM * 0.01;
double designScaleFactor = xDpi * inchesPerMM * 0.2f;
e.Graphics.ScaleTransform((float)graphicsXScaleFactor, (float)graphicsYScaleFactor);
using (Bitmap tempDrawArea = design.designToBitmap((float)settings.threadThickness, settings.filterStiches, settings.filterStitchesThreshold, (float)designScaleFactor))
{
e.Graphics.DrawImage(tempDrawArea, 30, 30);
}