[PythonCAD] patch for exact printing

Russ Nelson nelson at crynwr.com
Tue Jun 27 17:08:44 CEST 2006


I plan to create some parts by printing to sticky paper, sticking the
paper directly to the raw material, and then cutting the part out.
Thus, I need "Exact" scale printing, so that something drawn 10cm x
10cm gets printed at 10cm x 10cm regardless of the size of the paper.
Units are taking into account, so that a 1" x 1" square is drawn at
that size also.

Note that most printers can't do edge-to-edge printing, so you
probably shouldn't draw your part at 0,0.  The exact printing area is
printer-dependent, so count on leaving a margin.

Index: PythonCAD/Generic/printing.py
===================================================================
--- PythonCAD/Generic/printing.py	(revision 2387)
+++ PythonCAD/Generic/printing.py	(working copy)
@@ -73,6 +73,7 @@
     # some sizes taken from 'gs_statd.ps' Ghostscript file
     #
     __papersizes = {
+        'exact' : (0, 0),
         'letter' : (612, 792),
         'legal' : (612, 1008),
         'tabloid' : (792, 1224),
@@ -205,10 +206,16 @@
             raise ValueError, "Unexpected unit: %s" % _units
         self.__factor = _fac
         # print "factor: %g" % _fac
-        _xs = _fac * ((_xmax - _xmin)/float(_w))
-        _ys = _fac * ((_ymax - _ymin)/float(_h))
-        # print "xs: %g; ys: %g" % (_xs, _ys)
-        _s = 1.0/max(_xs, _ys)
+
+        if _w == 0 and _h == 0:
+            _ymin = 0
+            _xmin = 0
+            _s = 1
+        else:
+            _xs = _fac * ((_xmax - _xmin)/float(_w))
+            _ys = _fac * ((_ymax - _ymin)/float(_h))
+            # print "xs: %g; ys: %g" % (_xs, _ys)
+            _s = 1.0/max(_xs, _ys)
         self.__scale = _s
         # print "scale: %g" % self.__scale
         self.__matrix = ((_s * _fac),

-- 
--my blog is at    http://blog.russnelson.com   | When immigration is
Crynwr sells support for free software  | PGPok | outlawed, only criminals
521 Pleasant Valley Rd. | +1 315-323-1241       | will immigrate.  Illegal
Potsdam, NY 13676-3213  |     Sheepdog          | immigration causes crime.


More information about the PythonCAD mailing list