Fix print scaling code, should resolve issue #12 and may help with issue #10 and issue #11

master
Nathan Crawford 2016-04-12 16:16:08 -04:00
rodzic 34eb10023c
commit 1b33c47dda
4 zmienionych plików z 18 dodań i 16 usunięć

Wyświetl plik

@ -44,6 +44,8 @@ namespace PesFile
private Int64 startStitches = 0; private Int64 startStitches = 0;
private Point translateStart; private Point translateStart;
private UInt16 pesVersion; private UInt16 pesVersion;
// Native format appears to use 0.1mm steps, for 254 steps per inch
public int NativeDPI = 254;
// If set to true, this variable means we couldn't figure out some or // If set to true, this variable means we couldn't figure out some or
@ -577,6 +579,7 @@ namespace PesFile
return retval; return retval;
} }
// When scale is 1.0, each pixel appears to be 0.1mm, or about 254 ppi
public Bitmap designToBitmap(Single threadThickness, bool filterUglyStitches, double filterUglyStitchesThreshold, float scale) public Bitmap designToBitmap(Single threadThickness, bool filterUglyStitches, double filterUglyStitchesThreshold, float scale)
{ {
// Do some basic input checks // Do some basic input checks

Wyświetl plik

@ -55,5 +55,5 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.5.1.0")] [assembly: AssemblyVersion("1.5.2.0")]
[assembly: AssemblyFileVersion("1.5.1.0")] [assembly: AssemblyFileVersion("1.5.2.0")]

Wyświetl plik

@ -54,5 +54,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("2.2.1.0")] [assembly: AssemblyVersion("2.2.2.0")]
[assembly: AssemblyFileVersion("2.2.1.0")] [assembly: AssemblyFileVersion("2.2.2.0")]

Wyświetl plik

@ -531,24 +531,23 @@ namespace embroideryReader
{ {
if (design != null) if (design != null)
{ {
int xDpi = e.PageSettings.PrinterResolution.X; // Calculate scale values for print graphics object (100 dpi seems to be the default for the printer graphics object)
int yDpi = e.PageSettings.PrinterResolution.Y; double graphicsXScaleFactor = (100.0 / design.NativeDPI);
// Basic checks on printer resolution double graphicsYScaleFactor = (100.0 / design.NativeDPI);
if(xDpi < 20 || xDpi > 10000)
// Check for scale out of range
if(graphicsXScaleFactor < 0.001 || graphicsXScaleFactor > 100.0)
{ {
throw new ArgumentOutOfRangeException("Printer X DPI claims to be '" + xDpi + "', expected range 20 - 10000"); throw new ArgumentOutOfRangeException("Print X graphics scale is '" + graphicsXScaleFactor + "', expected range is 0.001 - 100.0");
} }
if (yDpi < 20 || yDpi > 10000) if (graphicsYScaleFactor < 0.001 || graphicsYScaleFactor > 100.0)
{ {
throw new ArgumentOutOfRangeException("Printer Y DPI claims to be '" + yDpi + "', expected range 20 - 10000"); throw new ArgumentOutOfRangeException("Print Y graphics scale is '" + graphicsYScaleFactor + "', expected range is 0.001 - 100.0");
} }
const double inchesPerMM = 0.03937007874015748031496062992126f; // Set print graphics object scale and draw the image
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); e.Graphics.ScaleTransform((float)graphicsXScaleFactor, (float)graphicsYScaleFactor);
using (Bitmap tempDrawArea = design.designToBitmap((float)settings.threadThickness, settings.filterStiches, settings.filterStitchesThreshold, (float)designScaleFactor)) using (Bitmap tempDrawArea = design.designToBitmap((float)settings.threadThickness, settings.filterStiches, settings.filterStitchesThreshold, 1.0f))
{ {
e.Graphics.DrawImage(tempDrawArea, 30, 30); e.Graphics.DrawImage(tempDrawArea, 30, 30);
} }