src/reportlab/graphics/barcode/code128.py
author rptlab
Tue, 30 Apr 2013 14:20:22 +0100
branchpy33
changeset 3721 0c93dd8ff567
parent 3326 ce725978d11c
child 3723 99aa837b6703
permissions -rw-r--r--
initial changes from 2to3-3.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     1
#
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     2
# Copyright (c) 2000 Tyler C. Sarna <tsarna@sarna.org>
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     3
# All rights reserved.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     4
#
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     5
# Redistribution and use in source and binary forms, with or without
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     6
# modification, are permitted provided that the following conditions
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     7
# are met:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     8
# 1. Redistributions of source code must retain the above copyright
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
     9
#    notice, this list of conditions and the following disclaimer.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    10
# 2. Redistributions in binary form must reproduce the above copyright
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    11
#    notice, this list of conditions and the following disclaimer in the
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    12
#    documentation and/or other materials provided with the distribution.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    13
# 3. All advertising materials mentioning features or use of this software
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    14
#    must display the following acknowledgement:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    15
#      This product includes software developed by Tyler C. Sarna.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    16
# 4. Neither the name of the author nor the names of contributors
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    17
#    may be used to endorse or promote products derived from this software
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    18
#    without specific prior written permission.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    19
#
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    20
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    21
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    22
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    23
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    24
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    25
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    26
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    27
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    28
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    29
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    30
# POSSIBILITY OF SUCH DAMAGE.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    31
#
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    32
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    33
from reportlab.lib.units import inch
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3326
diff changeset
    34
from .common import MultiWidthBarcode
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    35
from string import digits
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    36
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    37
_patterns = {
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    38
    0   :   'BaBbBb',    1   :   'BbBaBb',    2   :   'BbBbBa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    39
    3   :   'AbAbBc',    4   :   'AbAcBb',    5   :   'AcAbBb',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    40
    6   :   'AbBbAc',    7   :   'AbBcAb',    8   :   'AcBbAb',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    41
    9   :   'BbAbAc',    10  :   'BbAcAb',    11  :   'BcAbAb',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    42
    12  :   'AaBbCb',    13  :   'AbBaCb',    14  :   'AbBbCa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    43
    15  :   'AaCbBb',    16  :   'AbCaBb',    17  :   'AbCbBa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    44
    18  :   'BbCbAa',    19  :   'BbAaCb',    20  :   'BbAbCa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    45
    21  :   'BaCbAb',    22  :   'BbCaAb',    23  :   'CaBaCa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    46
    24  :   'CaAbBb',    25  :   'CbAaBb',    26  :   'CbAbBa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    47
    27  :   'CaBbAb',    28  :   'CbBaAb',    29  :   'CbBbAa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    48
    30  :   'BaBaBc',    31  :   'BaBcBa',    32  :   'BcBaBa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    49
    33  :   'AaAcBc',    34  :   'AcAaBc',    35  :   'AcAcBa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    50
    36  :   'AaBcAc',    37  :   'AcBaAc',    38  :   'AcBcAa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    51
    39  :   'BaAcAc',    40  :   'BcAaAc',    41  :   'BcAcAa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    52
    42  :   'AaBaCc',    43  :   'AaBcCa',    44  :   'AcBaCa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    53
    45  :   'AaCaBc',    46  :   'AaCcBa',    47  :   'AcCaBa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    54
    48  :   'CaCaBa',    49  :   'BaAcCa',    50  :   'BcAaCa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    55
    51  :   'BaCaAc',    52  :   'BaCcAa',    53  :   'BaCaCa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    56
    54  :   'CaAaBc',    55  :   'CaAcBa',    56  :   'CcAaBa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    57
    57  :   'CaBaAc',    58  :   'CaBcAa',    59  :   'CcBaAa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    58
    60  :   'CaDaAa',    61  :   'BbAdAa',    62  :   'DcAaAa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    59
    63  :   'AaAbBd',    64  :   'AaAdBb',    65  :   'AbAaBd',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    60
    66  :   'AbAdBa',    67  :   'AdAaBb',    68  :   'AdAbBa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    61
    69  :   'AaBbAd',    70  :   'AaBdAb',    71  :   'AbBaAd',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    62
    72  :   'AbBdAa',    73  :   'AdBaAb',    74  :   'AdBbAa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    63
    75  :   'BdAbAa',    76  :   'BbAaAd',    77  :   'DaCaAa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    64
    78  :   'BdAaAb',    79  :   'AcDaAa',    80  :   'AaAbDb',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    65
    81  :   'AbAaDb',    82  :   'AbAbDa',    83  :   'AaDbAb',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    66
    84  :   'AbDaAb',    85  :   'AbDbAa',    86  :   'DaAbAb',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    67
    87  :   'DbAaAb',    88  :   'DbAbAa',    89  :   'BaBaDa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    68
    90  :   'BaDaBa',    91  :   'DaBaBa',    92  :   'AaAaDc',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    69
    93  :   'AaAcDa',    94  :   'AcAaDa',    95  :   'AaDaAc',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    70
    96  :   'AaDcAa',    97  :   'DaAaAc',    98  :   'DaAcAa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    71
    99  :   'AaCaDa',    100 :   'AaDaCa',    101 :   'CaAaDa',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    72
    102 :   'DaAaCa',    103 :   'BaAdAb',    104 :   'BaAbAd',
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    73
    105 :   'BaAbCb',    106 :   'BcCaAaB'
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    74
}
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    75
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    76
starta, startb, startc, stop = 103, 104, 105, 106
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    77
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    78
seta = {
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    79
        ' ' :   0,        '!' :   1,        '"' :   2,        '#' :   3,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    80
        '$' :   4,        '%' :   5,        '&' :   6,       '\'' :   7,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    81
        '(' :   8,        ')' :   9,        '*' :  10,        '+' :  11,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    82
        ',' :  12,        '-' :  13,        '.' :  14,        '/' :  15,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    83
        '0' :  16,        '1' :  17,        '2' :  18,        '3' :  19,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    84
        '4' :  20,        '5' :  21,        '6' :  22,        '7' :  23,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    85
        '8' :  24,        '9' :  25,        ':' :  26,        ';' :  27,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    86
        '<' :  28,        '=' :  29,        '>' :  30,        '?' :  31,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    87
        '@' :  32,        'A' :  33,        'B' :  34,        'C' :  35,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    88
        'D' :  36,        'E' :  37,        'F' :  38,        'G' :  39,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    89
        'H' :  40,        'I' :  41,        'J' :  42,        'K' :  43,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    90
        'L' :  44,        'M' :  45,        'N' :  46,        'O' :  47,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    91
        'P' :  48,        'Q' :  49,        'R' :  50,        'S' :  51,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    92
        'T' :  52,        'U' :  53,        'V' :  54,        'W' :  55,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    93
        'X' :  56,        'Y' :  57,        'Z' :  58,        '[' :  59,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    94
       '\\' :  60,        ']' :  61,        '^' :  62,        '_' :  63,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    95
     '\x00' :  64,     '\x01' :  65,     '\x02' :  66,     '\x03' :  67,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    96
     '\x04' :  68,     '\x05' :  69,     '\x06' :  70,     '\x07' :  71,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    97
     '\x08' :  72,     '\x09' :  73,     '\x0a' :  74,     '\x0b' :  75,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    98
     '\x0c' :  76,     '\x0d' :  77,     '\x0e' :  78,     '\x0f' :  79,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
    99
     '\x10' :  80,     '\x11' :  81,     '\x12' :  82,     '\x13' :  83,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   100
     '\x14' :  84,     '\x15' :  85,     '\x16' :  86,     '\x17' :  87,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   101
     '\x18' :  88,     '\x19' :  89,     '\x1a' :  90,     '\x1b' :  91,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   102
     '\x1c' :  92,     '\x1d' :  93,     '\x1e' :  94,     '\x1f' :  95,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   103
     '\xf3' :  96,     '\xf2' :  97,    'SHIFT' :  98,     'TO_C' :  99,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   104
     'TO_B' : 100,     '\xf4' : 101,     '\xf1' : 102
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   105
}
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   106
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   107
setb = {
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   108
        ' ' :   0,        '!' :   1,        '"' :   2,        '#' :   3,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   109
        '$' :   4,        '%' :   5,        '&' :   6,       '\'' :   7,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   110
        '(' :   8,        ')' :   9,        '*' :  10,        '+' :  11,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   111
        ',' :  12,        '-' :  13,        '.' :  14,        '/' :  15,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   112
        '0' :  16,        '1' :  17,        '2' :  18,        '3' :  19,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   113
        '4' :  20,        '5' :  21,        '6' :  22,        '7' :  23,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   114
        '8' :  24,        '9' :  25,        ':' :  26,        ';' :  27,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   115
        '<' :  28,        '=' :  29,        '>' :  30,        '?' :  31,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   116
        '@' :  32,        'A' :  33,        'B' :  34,        'C' :  35,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   117
        'D' :  36,        'E' :  37,        'F' :  38,        'G' :  39,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   118
        'H' :  40,        'I' :  41,        'J' :  42,        'K' :  43,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   119
        'L' :  44,        'M' :  45,        'N' :  46,        'O' :  47,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   120
        'P' :  48,        'Q' :  49,        'R' :  50,        'S' :  51,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   121
        'T' :  52,        'U' :  53,        'V' :  54,        'W' :  55,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   122
        'X' :  56,        'Y' :  57,        'Z' :  58,        '[' :  59,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   123
       '\\' :  60,        ']' :  61,        '^' :  62,        '_' :  63,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   124
        '`' :  64,        'a' :  65,        'b' :  66,        'c' :  67,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   125
        'd' :  68,        'e' :  69,        'f' :  70,        'g' :  71,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   126
        'h' :  72,        'i' :  73,        'j' :  74,        'k' :  75,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   127
        'l' :  76,        'm' :  77,        'n' :  78,        'o' :  79,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   128
        'p' :  80,        'q' :  81,        'r' :  82,        's' :  83,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   129
        't' :  84,        'u' :  85,        'v' :  86,        'w' :  87,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   130
        'x' :  88,        'y' :  89,        'z' :  90,        '{' :  91,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   131
        '|' :  92,        '}' :  93,        '~' :  94,     '\x7f' :  95,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   132
     '\xf3' :  96,     '\xf2' :  97,    'SHIFT' :  98,     'TO_C' :  99,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   133
     '\xf4' : 100,     'TO_A' : 101,     '\xf1' : 102
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   134
}
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   135
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   136
setc = {
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   137
    '00': 0, '01': 1, '02': 2, '03': 3, '04': 4,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   138
    '05': 5, '06': 6, '07': 7, '08': 8, '09': 9,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   139
    '10':10, '11':11, '12':12, '13':13, '14':14,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   140
    '15':15, '16':16, '17':17, '18':18, '19':19,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   141
    '20':20, '21':21, '22':22, '23':23, '24':24,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   142
    '25':25, '26':26, '27':27, '28':28, '29':29,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   143
    '30':30, '31':31, '32':32, '33':33, '34':34,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   144
    '35':35, '36':36, '37':37, '38':38, '39':39,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   145
    '40':40, '41':41, '42':42, '43':43, '44':44,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   146
    '45':45, '46':46, '47':47, '48':48, '49':49,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   147
    '50':50, '51':51, '52':52, '53':53, '54':54,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   148
    '55':55, '56':56, '57':57, '58':58, '59':59,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   149
    '60':60, '61':61, '62':62, '63':63, '64':64,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   150
    '65':65, '66':66, '67':67, '68':68, '69':69,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   151
    '70':70, '71':71, '72':72, '73':73, '74':74,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   152
    '75':75, '76':76, '77':77, '78':78, '79':79,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   153
    '80':80, '81':81, '82':82, '83':83, '84':84,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   154
    '85':85, '86':86, '87':87, '88':88, '89':89,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   155
    '90':90, '91':91, '92':92, '93':93, '94':94,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   156
    '95':95, '96':96, '97':97, '98':98, '99':99,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   157
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   158
    'TO_B' : 100,    'TO_A' : 101,    '\xf1' : 102
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   159
}
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   160
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   161
setmap = {
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   162
    'TO_A' : (seta, setb),
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   163
    'TO_B' : (setb, seta),
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   164
    'TO_C' : (setc, None),
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   165
    'START_A' : (starta, seta, setb),
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   166
    'START_B' : (startb, setb, seta),
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   167
    'START_C' : (startc, setc, None),
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   168
}
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3326
diff changeset
   169
tos = list(setmap.keys())
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   170
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   171
class Code128(MultiWidthBarcode):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   172
    """
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   173
    Code 128 is a very compact symbology that can encode the entire
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   174
    128 character ASCII set, plus 4 special control codes,
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   175
    (FNC1-FNC4, expressed in the input string as \xf1 to \xf4).
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   176
    Code 128 can also encode digits at double density (2 per byte)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   177
    and has a mandatory checksum.  Code 128 is well supported and
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   178
    commonly used -- for example, by UPS for tracking labels.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   179
    
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   180
    Because of these qualities, Code 128 is probably the best choice
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   181
    for a linear symbology today (assuming you have a choice).
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   182
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   183
    Options that may be passed to constructor:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   184
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   185
        value (int, or numeric string. required.):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   186
            The value to encode.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   187
   
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   188
        barWidth (float, default .0075):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   189
            X-Dimension, or width of the smallest element
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   190
            Minumum is .0075 inch (7.5 mils).
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   191
            
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   192
        barHeight (float, see default below):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   193
            Height of the symbol.  Default is the height of the two
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   194
            bearer bars (if they exist) plus the greater of .25 inch
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   195
            or .15 times the symbol's length.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   196
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   197
        quiet (bool, default 1):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   198
            Wether to include quiet zones in the symbol.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   199
            
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   200
        lquiet (float, see default below):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   201
            Quiet zone size to left of code, if quiet is true.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   202
            Default is the greater of .25 inch, or 10 barWidth
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   203
            
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   204
        rquiet (float, defaults as above):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   205
            Quiet zone size to right left of code, if quiet is true.
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   206
            
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   207
    Sources of Information on Code 128:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   208
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   209
    http://www.semiconductor.agilent.com/barcode/sg/Misc/code_128.html
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   210
    http://www.adams1.com/pub/russadam/128code.html
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   211
    http://www.barcodeman.com/c128.html
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   212
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   213
    Official Spec, "ANSI/AIM BC4-1999, ISS" is available for US$45 from
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   214
    http://www.aimglobal.org/aimstore/
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   215
    """
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   216
    barWidth = inch * 0.0075
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   217
    lquiet = None
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   218
    rquiet = None
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   219
    quiet = 1
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   220
    barHeight = None
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   221
    def __init__(self, value='', **args):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   222
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   223
        if type(value) is type(1):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   224
            value = str(value)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   225
            
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3326
diff changeset
   226
        for (k, v) in list(args.items()):
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   227
            setattr(self, k, v)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   228
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   229
        if self.quiet:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   230
            if self.lquiet is None:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   231
                self.lquiet = max(inch * 0.25, self.barWidth * 10.0)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   232
            if self.rquiet is None:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   233
                self.rquiet = max(inch * 0.25, self.barWidth * 10.0)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   234
        else:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   235
            self.lquiet = self.rquiet = 0.0
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   236
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   237
        MultiWidthBarcode.__init__(self, value)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   238
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   239
    def validate(self):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   240
        vval = ""
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   241
        self.valid = 1
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   242
        for c in self.value:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   243
            if ord(c) > 127 and c not in '\xf1\xf2\xf3\xf4':
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   244
                self.valid = 0
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   245
                continue
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   246
            vval = vval + c
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   247
        self.validated = vval
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   248
        return vval
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   249
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   250
    def _trailingDigitsToC(self, l):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   251
        # Optimization: trailing digits -> set C double-digits
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   252
        c = 1
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   253
        savings = -1 # the TO_C costs one character
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   254
        rl = ['STOP']
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   255
        while c < len(l):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   256
            i = (-c - 1)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   257
            if l[i] == '\xf1':
2660
c147aff8edae reportlab: minor fixes and add strokeDashArray
rgbecker
parents: 2587
diff changeset
   258
                c += 1
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   259
                rl.insert(0, '\xf1')
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   260
                continue
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   261
            elif len(l[i]) == 1 and l[i] in digits \
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   262
             and len(l[i-1]) == 1 and l[i-1] in digits:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   263
                c += 2
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   264
                savings += 1
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   265
                rl.insert(0, l[i-1] + l[i])
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   266
                continue
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   267
            else:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   268
                break
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   269
        if savings > 0:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   270
            return l[:-c] + ['TO_C'] + rl
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   271
        else:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   272
            return l
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   273
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   274
    def encode(self):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   275
        # First, encode using only B
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   276
        s = self.validated
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   277
        l = ['START_B']
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   278
        for c in s:
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 2964
diff changeset
   279
            if c not in setb:
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   280
                l = l + ['TO_A', c, 'TO_B']
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   281
            else:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   282
                l.append(c)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   283
        l.append('STOP')
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   284
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   285
        l = self._trailingDigitsToC(l)
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   286
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   287
        # Finally, replace START_X,TO_Y with START_Y
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   288
        if l[1] in tos:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   289
            l[:2] = ['START_' + l[1][-1]]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   290
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 2964
diff changeset
   291
#        print repr(l)
2587
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   292
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   293
        # encode into numbers
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   294
        start, set, shset = setmap[l[0]]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   295
        e = [start]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   296
        
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   297
        l = l[1:-1]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   298
        while l:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   299
            c = l[0]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   300
            if c == 'SHIFT':
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   301
                e = e + [set[c], shset[l[1]]]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   302
                l = l[2:]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   303
            elif c in tos:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   304
                e.append(set[c])
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   305
                set, shset = setmap[c]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   306
                l = l[1:]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   307
            else:
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   308
                e.append(set[c])
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   309
                l = l[1:]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   310
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   311
        c = e[0]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   312
        for i in range(1, len(e)):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   313
            c = c + i * e[i]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   314
        self.encoded = e + [c % 103, stop]
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   315
        return self.encoded
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   316
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   317
    def decompose(self):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   318
        self.decomposed = ''.join([_patterns[c] for c in self.encoded])
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   319
        return self.decomposed
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   320
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   321
    def _humanText(self):
8984967879af reportlab: barcode moved to reportlab/graphics
rgbecker
parents:
diff changeset
   322
        return self.value