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

com.pdfjet.QRCode Maven / Gradle / Ivy

/*     */ package com.pdfjet;
/*     */ 
/*     */ import java.io.UnsupportedEncodingException;
/*     */ 
/*     */ public class QRCode
/*     */   implements Drawable
/*     */ {
/*     */   private static final int PAD0 = 236;
/*     */   private static final int PAD1 = 17;
/*     */   private Boolean[][] modules;
/*  30 */   private int moduleCount = 33;
/*  31 */   private int errorCorrectLevel = 0;
/*     */   private float x;
/*     */   private float y;
/*     */   private byte[] qrData;
/*  37 */   private float m1 = 2.0F;
/*     */ 
/*     */   public QRCode(String paramString, int paramInt)
/*     */     throws UnsupportedEncodingException
/*     */   {
/*  48 */     this.qrData = paramString.getBytes("UTF-8");
/*  49 */     this.errorCorrectLevel = paramInt;
/*  50 */     make(false, getBestMaskPattern());
/*     */   }
/*     */ 
/*     */   public void setPosition(double paramDouble1, double paramDouble2)
/*     */   {
/*  60 */     setPosition((float)paramDouble1, (float)paramDouble2);
/*     */   }
/*     */ 
/*     */   public void setPosition(float paramFloat1, float paramFloat2)
/*     */   {
/*  70 */     setLocation(paramFloat1, paramFloat2);
/*     */   }
/*     */ 
/*     */   public void setLocation(float paramFloat1, float paramFloat2)
/*     */   {
/*  80 */     this.x = paramFloat1;
/*  81 */     this.y = paramFloat2;
/*     */   }
/*     */ 
/*     */   public void setModuleLength(double paramDouble)
/*     */   {
/*  91 */     this.m1 = ((float)paramDouble);
/*     */   }
/*     */ 
/*     */   public void setModuleLength(float paramFloat)
/*     */   {
/* 102 */     this.m1 = paramFloat;
/*     */   }
/*     */ 
/*     */   public float[] drawOn(Page paramPage)
/*     */     throws Exception
/*     */   {
/* 113 */     for (int i = 0; i < this.modules.length; i++) {
/* 114 */       for (int j = 0; j < this.modules.length; j++) {
/* 115 */         if (isDark(i, j)) {
/* 116 */           paramPage.fillRect(this.x + j * this.m1, this.y + i * this.m1, this.m1, this.m1);
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 121 */     float f1 = this.m1 * this.modules.length;
/* 122 */     float f2 = this.m1 * this.modules.length;
/* 123 */     return new float[] { this.x + f1, this.y + f2 };
/*     */   }
/*     */ 
/*     */   public Boolean[][] getData() {
/* 127 */     return this.modules;
/*     */   }
/*     */ 
/*     */   protected boolean isDark(int paramInt1, int paramInt2)
/*     */   {
/* 135 */     if (this.modules[paramInt1][paramInt2] != null) {
/* 136 */       return this.modules[paramInt1][paramInt2].booleanValue();
/*     */     }
/*     */ 
/* 139 */     return false;
/*     */   }
/*     */ 
/*     */   protected int getModuleCount()
/*     */   {
/* 144 */     return this.moduleCount;
/*     */   }
/*     */ 
/*     */   protected int getBestMaskPattern() {
/* 148 */     int i = 0;
/* 149 */     int j = 0;
/*     */ 
/* 151 */     for (int k = 0; k < 8; k++) {
/* 152 */       make(true, k);
/* 153 */       int m = QRUtil.getLostPoint(this);
/* 154 */       if ((k == 0) || (i > m)) {
/* 155 */         i = m;
/* 156 */         j = k;
/*     */       }
/*     */     }
/*     */ 
/* 160 */     return j;
/*     */   }
/*     */ 
/*     */   protected void make(boolean paramBoolean, int paramInt) {
/* 164 */     this.modules = new Boolean[this.moduleCount][this.moduleCount];
/*     */ 
/* 166 */     setupPositionProbePattern(0, 0);
/* 167 */     setupPositionProbePattern(this.moduleCount - 7, 0);
/* 168 */     setupPositionProbePattern(0, this.moduleCount - 7);
/*     */ 
/* 170 */     setupPositionAdjustPattern();
/* 171 */     setupTimingPattern();
/* 172 */     setupTypeInfo(paramBoolean, paramInt);
/*     */ 
/* 174 */     mapData(createData(this.errorCorrectLevel), paramInt);
/*     */   }
/*     */ 
/*     */   private void mapData(byte[] paramArrayOfByte, int paramInt) {
/* 178 */     int i = -1;
/* 179 */     int j = this.moduleCount - 1;
/* 180 */     int k = 7;
/* 181 */     int m = 0;
/*     */ 
/* 183 */     for (int n = this.moduleCount - 1; n > 0; n -= 2) {
/* 184 */       if (n == 6) n--; do
/*     */       {
/* 186 */         for (int i1 = 0; i1 < 2; i1++) {
/* 187 */           if (this.modules[j][(n - i1)] == null) {
/* 188 */             boolean bool1 = false;
/*     */ 
/* 190 */             if (m < paramArrayOfByte.length) {
/* 191 */               bool1 = (paramArrayOfByte[m] >>> k & 0x1) == 1;
/*     */             }
/*     */ 
/* 194 */             boolean bool2 = QRUtil.getMask(paramInt, j, n - i1);
/* 195 */             if (bool2) {
/* 196 */               bool1 = !bool1;
/*     */             }
/*     */ 
/* 199 */             this.modules[j][(n - i1)] = Boolean.valueOf(bool1);
/* 200 */             k--;
/* 201 */             if (k == -1) {
/* 202 */               m++;
/* 203 */               k = 7;
/*     */             }
/*     */           }
/*     */         }
/*     */ 
/* 208 */         j += i;
/* 209 */       }while ((j >= 0) && (this.moduleCount > j));
/* 210 */       j -= i;
/* 211 */       i = -i;
/*     */     }
/*     */   }
/*     */ 
/*     */   private void setupPositionAdjustPattern()
/*     */   {
/* 219 */     int[] arrayOfInt = { 6, 26 };
/* 220 */     for (int i = 0; i < arrayOfInt.length; i++)
/* 221 */       for (int j = 0; j < arrayOfInt.length; j++) {
/* 222 */         int k = arrayOfInt[i];
/* 223 */         int m = arrayOfInt[j];
/*     */ 
/* 225 */         if (this.modules[k][m] == null)
/*     */         {
/* 229 */           for (int n = -2; n <= 2; n++)
/* 230 */             for (int i1 = -2; i1 <= 2; i1++)
/* 231 */               this.modules[(k + n)][(m + i1)] = Boolean.valueOf((n == -2) || (n == 2) || (i1 == -2) || (i1 == 2) || ((n == 0) && (i1 == 0)) ? 1 : false);
/*     */         }
/*     */       }
/*     */   }
/*     */ 
/*     */   private void setupPositionProbePattern(int paramInt1, int paramInt2)
/*     */   {
/* 240 */     for (int i = -1; i <= 7; i++)
/* 241 */       for (int j = -1; j <= 7; j++)
/* 242 */         if ((paramInt1 + i > -1) && (this.moduleCount > paramInt1 + i) && (paramInt2 + j > -1) && (this.moduleCount > paramInt2 + j))
/*     */         {
/* 247 */           this.modules[(paramInt1 + i)][(paramInt2 + j)] = Boolean.valueOf(((0 <= i) && (i <= 6) && ((j == 0) || (j == 6))) || ((0 <= j) && (j <= 6) && ((i == 0) || (i == 6))) || ((2 <= i) && (i <= 4) && (2 <= j) && (j <= 4)) ? 1 : false);
/*     */         }
/*     */   }
/*     */ 
/*     */   private void setupTimingPattern()
/*     */   {
/* 256 */     for (int i = 8; i < this.moduleCount - 8; i++)
/* 257 */       if (this.modules[i][6] == null)
/*     */       {
/* 260 */         this.modules[i][6] = Boolean.valueOf(i % 2 == 0 ? 1 : false);
/*     */       }
/* 262 */     for (i = 8; i < this.moduleCount - 8; i++)
/* 263 */       if (this.modules[6][i] == null)
/*     */       {
/* 266 */         this.modules[6][i] = Boolean.valueOf(i % 2 == 0 ? 1 : false);
/*     */       }
/*     */   }
/*     */ 
/*     */   private void setupTypeInfo(boolean paramBoolean, int paramInt) {
/* 271 */     int i = this.errorCorrectLevel << 3 | paramInt;
/* 272 */     int j = QRUtil.getBCHTypeInfo(i);
/*     */     Boolean localBoolean;
/* 274 */     for (int k = 0; k < 15; k++) {
/* 275 */       localBoolean = Boolean.valueOf((!paramBoolean) && ((j >> k & 0x1) == 1));
/* 276 */       if (k < 6) {
/* 277 */         this.modules[k][8] = localBoolean;
/*     */       }
/* 279 */       else if (k < 8) {
/* 280 */         this.modules[(k + 1)][8] = localBoolean;
/*     */       }
/*     */       else {
/* 283 */         this.modules[(this.moduleCount - 15 + k)][8] = localBoolean;
/*     */       }
/*     */     }
/*     */ 
/* 287 */     for (k = 0; k < 15; k++) {
/* 288 */       localBoolean = Boolean.valueOf((!paramBoolean) && ((j >> k & 0x1) == 1));
/* 289 */       if (k < 8) {
/* 290 */         this.modules[8][(this.moduleCount - k - 1)] = localBoolean;
/*     */       }
/* 292 */       else if (k < 9) {
/* 293 */         this.modules[8][(15 - k - 1 + 1)] = localBoolean;
/*     */       }
/*     */       else {
/* 296 */         this.modules[8][(15 - k - 1)] = localBoolean;
/*     */       }
/*     */     }
/*     */ 
/* 300 */     this.modules[(this.moduleCount - 8)][8] = Boolean.valueOf(!paramBoolean ? 1 : false);
/*     */   }
/*     */ 
/*     */   private byte[] createData(int paramInt) {
/* 304 */     RSBlock[] arrayOfRSBlock = RSBlock.getRSBlocks(paramInt);
/*     */ 
/* 306 */     BitBuffer localBitBuffer = new BitBuffer();
/* 307 */     localBitBuffer.put(4, 4);
/* 308 */     localBitBuffer.put(this.qrData.length, 8);
/* 309 */     for (int i = 0; i < this.qrData.length; i++) {
/* 310 */       localBitBuffer.put(this.qrData[i], 8);
/*     */     }
/*     */ 
/* 313 */     i = 0;
/* 314 */     for (int j = 0; j < arrayOfRSBlock.length; j++) {
/* 315 */       i += arrayOfRSBlock[j].getDataCount();
/*     */     }
/*     */ 
/* 318 */     if (localBitBuffer.getLengthInBits() > i * 8) {
/* 319 */       throw new IllegalArgumentException("String length overflow. (" + localBitBuffer.getLengthInBits() + ">" + i * 8 + ")");
/*     */     }
/*     */ 
/* 326 */     if (localBitBuffer.getLengthInBits() + 4 <= i * 8) {
/* 327 */       localBitBuffer.put(0, 4);
/*     */     }
/*     */ 
/* 331 */     while (localBitBuffer.getLengthInBits() % 8 != 0) {
/* 332 */       localBitBuffer.put(false);
/*     */     }
/*     */ 
/* 337 */     while (localBitBuffer.getLengthInBits() < i * 8)
/*     */     {
/* 340 */       localBitBuffer.put(236, 8);
/*     */ 
/* 342 */       if (localBitBuffer.getLengthInBits() >= i * 8) {
/*     */         break;
/*     */       }
/* 345 */       localBitBuffer.put(17, 8);
/*     */     }
/*     */ 
/* 348 */     return createBytes(localBitBuffer, arrayOfRSBlock);
/*     */   }
/*     */ 
/*     */   private byte[] createBytes(BitBuffer paramBitBuffer, RSBlock[] paramArrayOfRSBlock) {
/* 352 */     int i = 0;
/* 353 */     int j = 0;
/* 354 */     int k = 0;
/*     */ 
/* 356 */     int[][] arrayOfInt1 = new int[paramArrayOfRSBlock.length][];
/* 357 */     int[][] arrayOfInt2 = new int[paramArrayOfRSBlock.length][];
/*     */ 
/* 359 */     for (int m = 0; m < paramArrayOfRSBlock.length; m++) {
/* 360 */       n = paramArrayOfRSBlock[m].getDataCount();
/* 361 */       i1 = paramArrayOfRSBlock[m].getTotalCount() - n;
/*     */ 
/* 363 */       j = Math.max(j, n);
/* 364 */       k = Math.max(k, i1);
/*     */ 
/* 366 */       arrayOfInt1[m] = new int[n];
/* 367 */       for (int i2 = 0; i2 < arrayOfInt1[m].length; i2++) {
/* 368 */         arrayOfInt1[m][i2] = (0xFF & paramBitBuffer.getBuffer()[(i2 + i)]);
/*     */       }
/* 370 */       i += n;
/*     */ 
/* 372 */       Polynomial localPolynomial1 = QRUtil.getErrorCorrectPolynomial(i1);
/* 373 */       Polynomial localPolynomial2 = new Polynomial(arrayOfInt1[m], localPolynomial1.getLength() - 1);
/*     */ 
/* 375 */       Polynomial localPolynomial3 = localPolynomial2.mod(localPolynomial1);
/* 376 */       arrayOfInt2[m] = new int[localPolynomial1.getLength() - 1];
/* 377 */       for (int i5 = 0; i5 < arrayOfInt2[m].length; i5++) {
/* 378 */         int i6 = i5 + localPolynomial3.getLength() - arrayOfInt2[m].length;
/* 379 */         arrayOfInt2[m][i5] = (i6 >= 0 ? localPolynomial3.get(i6) : 0);
/*     */       }
/*     */     }
/*     */ 
/* 383 */     m = 0;
/* 384 */     for (int n = 0; n < paramArrayOfRSBlock.length; n++) {
/* 385 */       m += paramArrayOfRSBlock[n].getTotalCount();
/*     */     }
/*     */ 
/* 388 */     byte[] arrayOfByte = new byte[m];
/* 389 */     int i1 = 0;
/*     */     int i4;
/* 390 */     for (int i3 = 0; i3 < j; i3++) {
/* 391 */       for (i4 = 0; i4 < paramArrayOfRSBlock.length; i4++) {
/* 392 */         if (i3 < arrayOfInt1[i4].length) {
/* 393 */           arrayOfByte[(i1++)] = ((byte)arrayOfInt1[i4][i3]);
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 398 */     for (i3 = 0; i3 < k; i3++) {
/* 399 */       for (i4 = 0; i4 < paramArrayOfRSBlock.length; i4++) {
/* 400 */         if (i3 < arrayOfInt2[i4].length) {
/* 401 */           arrayOfByte[(i1++)] = ((byte)arrayOfInt2[i4][i3]);
/*     */         }
/*     */       }
/*     */     }
/*     */ 
/* 406 */     return arrayOfByte;
/*     */   }
/*     */ }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy