Upce.py revision 12a239f8730c2bb6e3738d5e75b3237877594d07
#
# Copyright (C) 2010 Martin Owens
#
# 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
#
"""
Python barcode renderer for UPCE barcodes. Designed for use with Inkscape.
"""
from BaseEan import EanBarcode
import sys
# This is almost exactly the same as the standard FAMILIES
# But flipped around and with the first 111000 instead of 000000.
'100110', '100011', '101010', '101001', '100101' ]
class Upce(EanBarcode):
name = 'upce'
"""Generate a UPC-E Barcode"""
# 202(guard) + code + 020(center) + 202(guard)
"""Generate a UPCE Checksum"""
"""We need a font size of 10"""
return 10
"""Converting UPC-A to UPC-E, may cause errors."""
# All UPC-E Numbers use number system 0
# If not then the code is invalid
raise ValueError("Invalid UPC Number")
# Most of the conversions deal
# with the specific code parts
# There are 4 cases to convert:
# Maxium number product code digits can be encoded
# Now only 2 product code digits can be used
# With even more manufacturer code we have less room for product code
# The last recorse is to try and squeeze it in the last 5 numbers
# so long as the product is 00005-00009 so as not to conflict with
# the 0-4 used above.
else:
# Invalid UPC-A Numbe
raise ValueError("Invalid UPC Number")
"""Convert UPC-E to UPC-A by padding with zeros"""
# It's more likly to convert this without fault
# But we still must be mindful of the 4 conversions
return None
else: