All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pdfjet.BarCode2D Maven / Gradle / Ivy

/*     */ package com.pdfjet;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ 
/*     */ public class BarCode2D
/*     */   implements Drawable
/*     */ {
/*     */   private static final int ALPHA = 8;
/*     */   private static final int LOWER = 4;
/*     */   private static final int MIXED = 2;
/*     */   private static final int PUNCT = 1;
/*     */   private static final int LATCH_TO_LOWER = 27;
/*     */   private static final int SHIFT_TO_ALPHA = 27;
/*     */   private static final int LATCH_TO_MIXED = 28;
/*     */   private static final int LATCH_TO_ALPHA = 28;
/*     */   private static final int SHIFT_TO_PUNCT = 29;
/*  53 */   private float x1 = 0.0F;
/*  54 */   private float y1 = 0.0F;
/*     */ 
/*  57 */   private float w1 = 0.75F;
/*  58 */   private float h1 = 0.0F;
/*     */ 
/*  60 */   private int rows = 50;
/*  61 */   private int cols = 18;
/*     */   private int[] codewords;
/*     */   private String str;
/*     */ 
/*     */   public BarCode2D(String paramString)
/*     */   {
/*  74 */     this.str = paramString;
/*  75 */     this.h1 = (3.0F * this.w1);
/*  76 */     this.codewords = new int[this.rows * (this.cols + 2)];
/*     */ 
/*  78 */     int[] arrayOfInt1 = new int[this.rows];
/*  79 */     int[] arrayOfInt2 = new int[this.rows];
/*  80 */     int[] arrayOfInt3 = new int[this.rows * this.cols];
/*     */ 
/*  83 */     int i = 5;
/*  84 */     int j = 1;
/*     */     int n;
/*     */     int i1;
/*  85 */     for (int k = 0; k < this.rows; k++) {
/*  86 */       m = 0;
/*  87 */       n = 0;
/*  88 */       i1 = 30 * (k / 3);
/*  89 */       if (j == 1) {
/*  90 */         m = i1 + (this.rows - 1) / 3;
/*  91 */         n = i1 + (this.cols - 1);
/*     */       }
/*  93 */       else if (j == 2) {
/*  94 */         m = i1 + 3 * i + (this.rows - 1) % 3;
/*  95 */         n = i1 + (this.rows - 1) / 3;
/*     */       }
/*  97 */       else if (j == 3) {
/*  98 */         m = i1 + (this.cols - 1);
/*  99 */         n = i1 + 3 * i + (this.rows - 1) % 3;
/*     */       }
/* 101 */       arrayOfInt1[k] = m;
/* 102 */       arrayOfInt2[k] = n;
/* 103 */       j++;
/* 104 */       if (j == 4) j = 1;
/*     */     }
/*     */ 
/* 107 */     k = this.rows * this.cols - ECC_L5.table.length;
/* 108 */     for (int m = 0; m < k; m++) {
/* 109 */       arrayOfInt3[m] = 900;
/*     */     }
/* 111 */     arrayOfInt3[0] = k;
/*     */ 
/* 113 */     addData(arrayOfInt3, k);
/* 114 */     addECC(arrayOfInt3);
/*     */ 
/* 116 */     for (m = 0; m < this.rows; m++) {
/* 117 */       n = (this.cols + 2) * m;
/* 118 */       this.codewords[n] = arrayOfInt1[m];
/* 119 */       for (i1 = 0; i1 < this.cols; i1++) {
/* 120 */         this.codewords[(n + i1 + 1)] = arrayOfInt3[(this.cols * m + i1)];
/*     */       }
/* 122 */       this.codewords[(n + this.cols + 1)] = arrayOfInt2[m];
/*     */     }
/*     */   }
/*     */ 
/*     */   public void setPosition(double paramDouble1, double paramDouble2)
/*     */   {
/* 134 */     setPosition((float)paramDouble1, (float)paramDouble2);
/*     */   }
/*     */ 
/*     */   public void setPosition(float paramFloat1, float paramFloat2)
/*     */   {
/* 145 */     setLocation(paramFloat1, paramFloat2);
/*     */   }
/*     */ 
/*     */   public void setLocation(float paramFloat1, float paramFloat2)
/*     */   {
/* 156 */     this.x1 = paramFloat1;
/* 157 */     this.y1 = paramFloat2;
/*     */   }
/*     */ 
/*     */   public float[] drawOn(Page paramPage)
/*     */     throws Exception
/*     */   {
/* 169 */     return drawPdf417(paramPage);
/*     */   }
/*     */ 
/*     */   private List convertTheStringToListOfValues()
/*     */   {
/* 174 */     ArrayList localArrayList = new ArrayList();
/*     */ 
/* 176 */     int i = 0;
/* 177 */     int j = 8;
/* 178 */     int k = 0;
/* 179 */     int m = 0;
/* 180 */     for (int n = 0; n < this.str.length(); n++) {
/* 181 */       m = this.str.charAt(n);
/* 182 */       if (m == 32) {
/* 183 */         localArrayList.add(Integer.valueOf(26));
/*     */       }
/*     */       else
/*     */       {
/* 187 */         i = TextCompact.TABLE[m][1];
/* 188 */         k = TextCompact.TABLE[m][2];
/* 189 */         if (k == j) {
/* 190 */           localArrayList.add(Integer.valueOf(i));
/*     */         }
/* 193 */         else if ((k == 8) && (j == 4)) {
/* 194 */           localArrayList.add(Integer.valueOf(27));
/* 195 */           localArrayList.add(Integer.valueOf(i));
/*     */         }
/* 197 */         else if ((k == 8) && (j == 2)) {
/* 198 */           localArrayList.add(Integer.valueOf(28));
/* 199 */           localArrayList.add(Integer.valueOf(i));
/* 200 */           j = k;
/*     */         }
/* 202 */         else if ((k == 4) && (j == 8)) {
/* 203 */           localArrayList.add(Integer.valueOf(27));
/* 204 */           localArrayList.add(Integer.valueOf(i));
/* 205 */           j = k;
/*     */         }
/* 207 */         else if ((k == 4) && (j == 2)) {
/* 208 */           localArrayList.add(Integer.valueOf(27));
/* 209 */           localArrayList.add(Integer.valueOf(i));
/* 210 */           j = k;
/*     */         }
/* 212 */         else if ((k == 2) && (j == 8)) {
/* 213 */           localArrayList.add(Integer.valueOf(28));
/* 214 */           localArrayList.add(Integer.valueOf(i));
/* 215 */           j = k;
/*     */         }
/* 217 */         else if ((k == 2) && (j == 4)) {
/* 218 */           localArrayList.add(Integer.valueOf(28));
/* 219 */           localArrayList.add(Integer.valueOf(i));
/* 220 */           j = k;
/*     */         }
/* 222 */         else if ((k == 1) && (j == 8)) {
/* 223 */           localArrayList.add(Integer.valueOf(29));
/* 224 */           localArrayList.add(Integer.valueOf(i));
/*     */         }
/* 226 */         else if ((k == 1) && (j == 4)) {
/* 227 */           localArrayList.add(Integer.valueOf(29));
/* 228 */           localArrayList.add(Integer.valueOf(i));
/*     */         }
/* 230 */         else if ((k == 1) && (j == 2)) {
/* 231 */           localArrayList.add(Integer.valueOf(29));
/* 232 */           localArrayList.add(Integer.valueOf(i));
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 237 */     return localArrayList;
/*     */   }
/*     */ 
/*     */   private void addData(int[] paramArrayOfInt, int paramInt)
/*     */   {
/* 242 */     List localList = convertTheStringToListOfValues();
/* 243 */     int i = 1;
/* 244 */     int j = 0;
/* 245 */     int k = 0;
/* 246 */     for (int m = 0; m < localList.size(); m += 2) {
/* 247 */       j = ((Integer)localList.get(m)).intValue();
/* 248 */       if (m + 1 == localList.size())
/* 249 */         k = 29;
/*     */       else {
/* 251 */         k = ((Integer)localList.get(m + 1)).intValue();
/*     */       }
/*     */ 
/* 254 */       i++;
/* 255 */       if (i == paramInt) break;
/* 256 */       paramArrayOfInt[i] = (30 * j + k);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void addECC(int[] paramArrayOfInt)
/*     */   {
/* 262 */     int[] arrayOfInt = new int[ECC_L5.table.length];
/* 263 */     int i = 0;
/* 264 */     int j = 0;
/* 265 */     int k = 0;
/*     */ 
/* 267 */     int m = paramArrayOfInt.length - arrayOfInt.length;
/* 268 */     for (int n = 0; n < m; n++) {
/* 269 */       i = (paramArrayOfInt[n] + arrayOfInt[(arrayOfInt.length - 1)]) % 929;
/* 270 */       for (int i1 = arrayOfInt.length - 1; i1 > 0; i1--) {
/* 271 */         j = i * ECC_L5.table[i1] % 929;
/* 272 */         k = 929 - j;
/* 273 */         arrayOfInt[i1] = ((arrayOfInt[(i1 - 1)] + k) % 929);
/*     */       }
/* 275 */       j = i * ECC_L5.table[0] % 929;
/* 276 */       k = 929 - j;
/* 277 */       arrayOfInt[0] = (k % 929);
/*     */     }
/*     */ 
/* 280 */     for (n = 0; n < arrayOfInt.length; n++)
/* 281 */       if (arrayOfInt[n] != 0)
/* 282 */         paramArrayOfInt[(paramArrayOfInt.length - 1 - n)] = (929 - arrayOfInt[n]);
/*     */   }
/*     */ 
/*     */   private float[] drawPdf417(Page paramPage)
/*     */     throws Exception
/*     */   {
/* 289 */     float f1 = this.x1;
/* 290 */     float f2 = this.y1;
/*     */ 
/* 292 */     int[] arrayOfInt1 = { 8, 1, 1, 1, 1, 1, 1, 3 };
/* 293 */     for (int i = 0; i < arrayOfInt1.length; i++) {
/* 294 */       j = arrayOfInt1[i];
/* 295 */       if (i % 2 == 0) {
/* 296 */         drawBar(paramPage, f1, f2, j * this.w1, this.rows * this.h1);
/*     */       }
/* 298 */       f1 += j * this.w1;
/*     */     }
/* 300 */     this.x1 = f1;
/*     */ 
/* 302 */     i = 1;
/* 303 */     for (int j = 0; j < this.codewords.length; j++) {
/* 304 */       k = this.codewords[j];
/* 305 */       String str1 = Integer.toString(PDF417.TABLE[k][i]);
/* 306 */       for (int n = 0; n < 8; n++) {
/* 307 */         int i1 = str1.charAt(n) - '0';
/* 308 */         if (n % 2 == 0) {
/* 309 */           drawBar(paramPage, f1, f2, i1 * this.w1, this.h1);
/*     */         }
/* 311 */         f1 += i1 * this.w1;
/*     */       }
/* 313 */       if (j == this.codewords.length - 1) break;
/* 314 */       if ((j + 1) % (this.cols + 2) == 0) {
/* 315 */         f1 = this.x1;
/* 316 */         f2 += this.h1;
/* 317 */         i++;
/* 318 */         if (i == 4) i = 1;
/*     */       }
/*     */     }
/*     */ 
/* 322 */     f2 = this.y1;
/* 323 */     int[] arrayOfInt2 = { 7, 1, 1, 3, 1, 1, 1, 2, 1 };
/* 324 */     for (int k = 0; k < arrayOfInt2.length; k++) {
/* 325 */       int m = arrayOfInt2[k];
/* 326 */       if (k % 2 == 0) {
/* 327 */         drawBar(paramPage, f1, f2, m * this.w1, this.rows * this.h1);
/*     */       }
/* 329 */       f1 += m * this.w1;
/*     */     }
/*     */ 
/* 332 */     return new float[] { f1, f2 + this.h1 * this.rows };
/*     */   }
/*     */ 
/*     */   private void drawBar(Page paramPage, float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4)
/*     */     throws Exception
/*     */   {
/* 342 */     paramPage.setPenWidth(paramFloat3);
/* 343 */     paramPage.moveTo(paramFloat1 + paramFloat3 / 2.0F, paramFloat2);
/* 344 */     paramPage.lineTo(paramFloat1 + paramFloat3 / 2.0F, paramFloat2 + paramFloat4);
/* 345 */     paramPage.strokePath();
/*     */   }
/*     */ }

/* Location:           E:\EGGWIFI\Customer\trunk\src\Workspace\Customer\Customer Maven Webapp\src\main\webapp\WEB-INF\lib\PDFjet.jar
 * Qualified Name:     com.pdfjet.BarCode2D
 * JD-Core Version:    0.6.2
 */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy