001 /**
002 * This library is free software; you can redistribute it and/or modify it
003 * under the terms of the GNU Lesser General Public License (LGPL) as
004 * published by the Free Software Foundation; either version 3.0 of the
005 * License, or (at your option) any later version.
006 *
007 * This library is distributed in the hope that it will be useful, but
008 * WITHOUT ANY WARRANTY; without even the implied warranty of
009 * MERCHANTABILITY of FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010 * Lesser General Public License for more details.
011 */
012
013 /**
014 * Title: JBarcodeBean
015 * Description: Barcode JavaBeans Component
016 * Copyright: Copyright (C) 2004
017 * Company: Matthias Hanisch
018 */
019 package net.sourceforge.jbarcodebean.model;
020
021 import net.sourceforge.jbarcodebean.BarcodeException;
022
023
024 public class Code11 extends AbstractBarcodeStrategy {
025
026 static final CharacterCode[] codes={
027 new CharacterCode('0',new byte[]{1,1,1,1,2,1},0),
028 new CharacterCode('1',new byte[]{2,1,1,1,2,1},1),
029 new CharacterCode('2',new byte[]{1,2,1,1,2,1},2),
030 new CharacterCode('3',new byte[]{2,2,1,1,1,1},3),
031 new CharacterCode('4',new byte[]{1,1,2,1,2,1},4),
032 new CharacterCode('5',new byte[]{2,1,2,1,1,1},5),
033 new CharacterCode('6',new byte[]{1,2,2,1,1,1},6),
034 new CharacterCode('7',new byte[]{1,1,1,2,2,1},7),
035 new CharacterCode('8',new byte[]{2,1,1,2,1,1},8),
036 new CharacterCode('9',new byte[]{2,1,1,1,1,1},9),
037 new CharacterCode('-',new byte[]{1,1,2,1,1,1},10),
038 new CharacterCode('*',new byte[]{1,1,2,2,1,1},11),
039 new CharacterCode('$',new byte[]{0,1},12)};
040
041 protected String augmentWithChecksum(String text) throws BarcodeException {
042 int checksumC=0;
043 int checksumK=0;
044 int weightC=1;
045 int weightK=1;
046 for(int i=text.length()-1;i>=0;i--){
047 CharacterCode cc = getCharacterCode(text.charAt(i));
048 checksumC+=cc.check*weightC;
049 weightC++;
050 if(weightC>10){
051 weightC=1;
052 }
053 }
054 checksumC=checksumC%11;
055 CharacterCode codeC=getCharacterCode(checksumC);
056 text+=codeC.character;
057 for(int i=text.length()-1;i>=0;i--){
058 CharacterCode cc = getCharacterCode(text.charAt(i));
059 checksumK+=cc.check*weightK;
060 weightK++;
061 if(weightK>9){
062 weightK=1;
063 }
064 }
065 checksumK=checksumK%11;
066 CharacterCode codeK=getCharacterCode(checksumK);
067 if(text.length()>=10){
068 text+=codeK.character;
069 }
070 return text;
071 }
072
073 protected String getBarcodeLabelText(String text) {
074 return text;
075 }
076
077 protected CharacterCode[] getCodes() {
078 return codes;
079 }
080
081 protected byte getMarginWidth() {
082 return 0;
083 }
084
085 protected char getStartSentinel() {
086 return '*';
087 }
088
089 protected char getStopSentinel() {
090 return '*';
091 }
092
093 protected boolean isInterleaved() {
094 return false;
095 }
096
097 protected String postprocess(String text) {
098 return text;
099 }
100
101 protected String preprocess(String text) throws BarcodeException {
102 return text;
103 }
104
105 public int requiresChecksum() {
106 return OPTIONAL_CHECKSUM;
107 }
108
109 }