reingart / pyfpdf_googlecode

Automatically exported from code.google.com/p/pyfpdf
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Dashed Line #35

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would appreceate it if a dashed line function would be included in the 
official release. A possible implementation would be:

    def dashed_line(self, x1,y1,x2,y2, on_length=1, off_length=1):
        self.setDash(on_length, off_length)
        self.line(x1, y1, x2, y2)
        self.setDash()

    def setDash(self, black=False, white=False):
        if(black and white):
            s = self.sprintf('[%.3f %.3f] 0 d', black*self.k, white*self.k)
        else:
            s = '[] 0 d'
        self._out(s)

    def sprintf(self, fmt, *args): return fmt % args

Adopted from FPDF Addon "Dashes": http://www.fpdf.de/downloads/addons/33/

Original issue reported on code.google.com by dieterle...@gmail.com on 18 Dec 2012 at 9:09

GoogleCodeExporter commented 9 years ago
It could be included, but please if you can make a diff and adjust method name 
PEP8 python style guide: 

def set_dash(self, black=False, white=False):

Please also add documentation (at least docstring) and a test case.

sprintf is not already a method or function available?

Original comment by reingart@gmail.com on 18 Dec 2012 at 6:14

GoogleCodeExporter commented 9 years ago
Hi reingart,

see attached a diff file with adjusted method name to PEP8.

Documentation is added as docstring.

Yes, your right, sprintf is already an available function.

A test case would be:
# With default dash length of 1mm and space length of 1mm:
dashed_line(10, 10, 20, 10)

# Or with dash lenght of 5mm and space length of 2mm:
dashed_line(10, 10, 20, 10, 5, 2)

Original comment by dieterle...@gmail.com on 14 Feb 2013 at 6:51

Attachments:

GoogleCodeExporter commented 9 years ago
The unit is not in mm but as for the other functions depending on the unit 
given in the fpdf constructor.

Sorry.

Original comment by dieterle...@gmail.com on 14 Feb 2013 at 6:55

GoogleCodeExporter commented 9 years ago
Great.
I've added you as commiter, please fell free to commit the changes directly and 
close the issue.
If so, dont forget to make a sample test file and/or documentation wiki page
Thank you for you contribution!

Original comment by reingart@gmail.com on 14 Feb 2013 at 7:46

GoogleCodeExporter commented 9 years ago
Hi,

- The new function is committed
- A test case is added in tests/dashed_line_issue35.py
- The wiki documentation page is created.
- The issue status is changed to Fixed.

Original comment by dieterle...@gmail.com on 8 Mar 2013 at 8:02