home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Inkscape / Inkscape-0.48.2-1-win32.exe / share / extensions / Barcode / RM4CC.py < prev    next >
Text File  |  2011-07-08  |  3KB  |  131 lines

  1. '''
  2. Copyright (C) 2007 Martin Owens
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. '''
  18.  
  19. from Base import Barcode
  20.  
  21. map = {
  22.     '(' : '25',
  23.     ')' : '3',
  24.     '0' : '05053535',
  25.     '1' : '05152535',
  26.     '2' : '05153525',
  27.     '3' : '15052535',
  28.     '4' : '15053525',
  29.     '5' : '15152525',
  30.     '6' : '05251535',
  31.     '7' : '05350535',
  32.     '8' : '05351525',
  33.     '9' : '15250535',
  34.     'A' : '15251525',
  35.     'B' : '15350525',
  36.     'C' : '05253515',
  37.     'D' : '05352515',
  38.     'E' : '05353505',
  39.     'F' : '15252515',
  40.     'G' : '15253505',
  41.     'H' : '15352505',
  42.     'I' : '25051535',
  43.     'J' : '25150535',
  44.     'K' : '25151525',
  45.     'L' : '35050535',
  46.     'M' : '35051525',
  47.     'N' : '35150525',
  48.     'O' : '25053525',
  49.     'P' : '25152515',
  50.     'Q' : '25153505',
  51.     'R' : '35052515',
  52.     'S' : '35053505',
  53.     'T' : '35152505',
  54.     'U' : '25251515',
  55.     'V' : '25350515',
  56.     'W' : '25351505',
  57.     'X' : '35250515',
  58.     'Y' : '35251505',
  59.     'Z' : '35350505',
  60. }
  61.  
  62. check = ['ZUVWXY','501234','B6789A','HCDEFG','NIJKLM','TOPQRS']
  63.  
  64. class Object(Barcode):
  65.     def encode(self, text):
  66.         result = ''
  67.  
  68.         self.height = 18
  69.         text = text.upper()
  70.         text.replace('(', '')
  71.         text.replace(')', '')
  72.  
  73.         text = '(' + text + self.checksum(text) + ')'
  74.  
  75.         i = 0
  76.         for char in text:
  77.             if map.has_key(char):
  78.                 result = result + map[char]
  79.             
  80.                 i = i + 1
  81.  
  82.         self.inclabel = text
  83.         return result;
  84.  
  85.     # given a string of data, return the check character
  86.     def checksum(self, text):
  87.         total_lower = 0
  88.         total_upper = 0
  89.         for char in text:
  90.             if map.has_key(char):
  91.                 bars = map[char][0:8:2]
  92.                 lower = 0
  93.                 upper = 0
  94.  
  95.                 if int(bars[0]) & 1:
  96.                     lower = lower + 4 
  97.                 if int(bars[1]) & 1:
  98.                     lower = lower + 2
  99.                 if int(bars[2]) & 1:
  100.                     lower = lower + 1
  101.                 if int(bars[0]) & 2:
  102.                     upper = upper + 4
  103.                 if int(bars[1]) & 2:
  104.                     upper = upper + 2
  105.                 if int(bars[2]) & 2:
  106.                     upper = upper + 1
  107.             total_lower = total_lower + (lower % 6)
  108.             total_upper = total_upper + (upper % 6)
  109.  
  110.         total_lower = total_upper % 6
  111.         total_upper = total_upper % 6
  112.     
  113.         checkchar = check[total_upper][total_lower]
  114.         return checkchar
  115.  
  116.     def getStyle(self, index):
  117.         result = { 'width' : 2, 'write' : True, 'top' : int(self.y) }
  118.         if index==0: # Track Bar
  119.             result['top']    = result['top'] + 6
  120.             result['height'] = 5
  121.         elif index==1: # Decender Bar
  122.             result['top']    = result['top'] + 6
  123.             result['height'] = 11
  124.         elif index==2: # Accender Bar
  125.             result['height'] = 11
  126.         elif index==3: # Full Bar
  127.             result['height'] = 17
  128.         elif index==5: # White Space
  129.             result['write']  = False
  130.         return result
  131.