Code 128 barcode does not work properly
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Inkscape |
Fix Released
|
Medium
|
Unassigned |
Bug Description
The changing Codes #99 - #100 - #101 are not correct calculated .
Barcodes with more than one code section (e.g. an odd count >5 of digits or letter and digits mixed) causes an error in inkscape and would otherwise not recognized by a scanner.
The code near the line 100 should be changed from
num = num + (math.abs(num - 102) * 2)
to
num = 204 - num
Furthermore a two digit Barcde is not optimized in Code 128C but its printed in Code 128A.
A simple change in the regex near line 55 could fix it:
Cange
for datum in re.findall(
to
for datum in re.findall(
here is the complete working Version:
'''
Copyright (C) 2007 Martin Owens
Debugged by Ralf Heinecke & Martin Siepmann 09/07/2007
Debugged by Horst Schottky Feb. 27. 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
from Base import Barcode
import math
import re
map = [ '11011001100'
def mapExtra(sd, chars):
result = list(sd)
for char in chars:
result.
result.
result.
result.
return result
# The mapExtra method is used to slim down the amount
# of pre code and instead we generate the lists
charAB = list(' !"#$%&\
charA = mapExtra(charAB, range(0, 31)) # Offset 64
charB = mapExtra(charAB, range(96, 125)) # Offset -32
class Object(Barcode):
def encode(self, text):
result = ''
blocks = []
block = ''
# Split up into sections of numbers, or charicters
# This makes sure that all the charicters are encoded
# In the best way posible for Code128
for datum in re.findall(
if len(datum) == 1:
block = block + datum
else:
if block:
blocks.
block = ''
blocks.append( [ 'C', datum ] )
if block:
blocks.
block = '';
self.inclabel = text
return self.encodeBloc
def bestBlock(self, block):
# If this has lower case then select B over A
if block.upper() == block:
return [ 'A', block ]
return [ 'B', block ]
def encodeBlocks(self, blocks):
total = 0
pos = 0
encode = '';
for block in blocks:
set = block[0]
datum = block[1]
# POS : 0, 1
# A : 101, 103
# B : 100, 104
# C : 99, 105
num = 0;
if set == 'A':
num = 103
elif set == 'B':
num = 104
elif set == 'C':
num = 105
i = pos
if pos:
num = 204 - num
else:
i = 1
total = total + num * i
encode = encode + map[num]
pos = pos + 1
if set == 'A' or set == 'B':
chars = charB
if set == 'A':
chars = charA
for char in datum:
total = total + (chars.index(char) * pos)
encode = encode + map[chars.
pos = pos + 1
else:
for char in (datum[i:i+2] for i in range(0, len(datum), 2)):
total = total + (int(char) * pos)
encode = encode + map[int(char)]
pos = pos + 1
checksum = total % 103
encode = encode + map[checksum]
encode = encode + map[106]
encode = encode + map[107]
return encode
Related branches
tags: | added: extensions-plugins |
summary: |
- Code 128 does not work properly + Code 128 barcode does not work properly |
Changed in inkscape: | |
milestone: | none → 0.48 |
Changed in inkscape: | |
importance: | Undecided → Medium |
Changed in inkscape: | |
status: | Fix Committed → Fix Released |
for testing purposes, could you provide a few examples of codes that work with the new version and previously did not work?