mugmuggy / pyfpdf

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

Code39 does not work #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The method code39 does not generate a correct barcode.

It should be replaced by the following code:

def code39(self, txt, x, y, w=1.5, h=5.0):
    """Barcode 3of9"""
    dim = {'w': w, 'n': w/3.}
    chars = {
        '0': 'nnnwwnwnn', '1': 'wnnwnnnnw', '2': 'nnwwnnnnw',
        '3': 'wnwwnnnnn', '4': 'nnnwwnnnw', '5': 'wnnwwnnnn',
        '6': 'nnwwwnnnn', '7': 'nnnwnnwnw', '8': 'wnnwnnwnn',
        '9': 'nnwwnnwnn', 'A': 'wnnnnwnnw', 'B': 'nnwnnwnnw',
        'C': 'wnwnnwnnn', 'D': 'nnnnwwnnw', 'E': 'wnnnwwnnn',
        'F': 'nnwnwwnnn', 'G': 'nnnnnwwnw', 'H': 'wnnnnwwnn',
        'I': 'nnwnnwwnn', 'J': 'nnnnwwwnn', 'K': 'wnnnnnnww',
        'L': 'nnwnnnnww', 'M': 'wnwnnnnwn', 'N': 'nnnnwnnww',
        'O': 'wnnnwnnwn', 'P': 'nnwnwnnwn', 'Q': 'nnnnnnwww',
        'R': 'wnnnnnwwn', 'S': 'nnwnnnwwn', 'T': 'nnnnwnwwn',
        'U': 'wwnnnnnnw', 'V': 'nwwnnnnnw', 'W': 'wwwnnnnnn',
        'X': 'nwnnwnnnw', 'Y': 'wwnnwnnnn', 'Z': 'nwwnwnnnn',
        '-': 'nwnnnnwnw', '.': 'wwnnnnwnn', ' ': 'nwwnnnwnn',
        '*': 'nwnnwnwnn', '$': 'nwnwnwnnn', '/': 'nwnwnnnwn',
        '+': 'nwnnnwnwn', '%': 'nnnwnwnwn',
    }
    self.set_fill_color(0)
    for c in txt.upper():
        if c not in chars:
            raise RuntimeError('Invalid char "%s" for Code39' % c)
        for i, d in enumerate(chars[c]):
            if i % 2 == 0:
                self.rect(x, y, dim[d], h, 'F')
            x += dim[d]
        x += dim['n']

Original issue reported on code.google.com by thimo.kr...@joonis.de on 21 Jan 2014 at 10:01

GoogleCodeExporter commented 9 years ago
This issue was closed by revision bd97feba36b3.

Original comment by reingart@gmail.com on 5 Feb 2014 at 4:22