Add minimal support for FNC1 mode in QR Code
[zxing.git] / core / src / com / google / zxing / qrcode / decoder / Mode.java
index f1d369d..9e9947b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2007 Google Inc.
+ * Copyright 2007 ZXing authors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,9 +32,12 @@ final class Mode {
   static final Mode NUMERIC = new Mode(new int[]{10, 12, 14});
   static final Mode ALPHANUMERIC = new Mode(new int[]{9, 11, 13});
   static final Mode BYTE = new Mode(new int[]{8, 16, 16});
+  static final Mode ECI = new Mode(null); // character counts don't apply
   static final Mode KANJI = new Mode(new int[]{8, 10, 12});
+  static final Mode FNC1_FIRST_POSITION = new Mode(null);
+  static final Mode FNC1_SECOND_POSITION = new Mode(null);
 
-  private int[] characterCountBitsForVersions;
+  private final int[] characterCountBitsForVersions;
 
   private Mode(int[] characterCountBitsForVersions) {
     this.characterCountBitsForVersions = characterCountBitsForVersions;
@@ -55,10 +58,16 @@ final class Mode {
         return ALPHANUMERIC;
       case 0x4:
         return BYTE;
+      case 0x5:
+        return FNC1_FIRST_POSITION;
+      case 0x7:
+        return ECI;
       case 0x8:
         return KANJI;
+      case 0x9:
+        return FNC1_SECOND_POSITION;
       default:
-        throw new ReaderException("Illegal mode bits: " + bits);
+        throw new ReaderException("Unsupported mode bits: " + bits);
     }
   }
 
@@ -68,6 +77,9 @@ final class Mode {
    *         count of characters that will follow encoded in this {@link Mode}
    */
   int getCharacterCountBits(Version version) {
+    if (characterCountBitsForVersions == null) {
+      throw new IllegalArgumentException("Character count doesn't apply to this mode");
+    }
     int number = version.getVersionNumber();
     int offset;
     if (number <= 9) {