1 module ithox.qrcode.common.mode;
2 import ithox.qrcode.common.qrcodeversion;
3 
4 ///Enum representing various modes in which data can be encoded to bits.
5 class Mode
6 {
7     /**#@+
8 	* Mode enumants.
9 	*/
10     enum int TERMINATOR = 0x0;
11     enum int NUMERIC = 0x1;
12     enum int ALPHANUMERIC = 0x2;
13     enum int STRUCTURED_APPEND = 0x3;
14     enum int BYTE = 0x4;
15     enum int ECI = 0x7;
16     enum int KANJI = 0x8;
17     enum int FNC1_FIRST_POSITION = 0x5;
18     enum int FNC1_SECOND_POSITION = 0x9;
19     enum int HANZI = 0xd;
20     /**#@-*/
21 
22     private
23     {
24         int _mode;
25     }
26 
27     this(int m)
28     {
29 
30         this._mode = m;
31     }
32 
33     public @property int mode()
34     {
35         return this._mode;
36     }
37 
38     public @property void mode(int _m)
39     {
40         this._mode = _m;
41     }
42     /**
43 	* Character count bits for each version.
44 	*
45 	* @var array
46 	*/
47     protected static int[][] characterCountBitsForVersions = [
48 TERMINATOR : [0, 0, 0
49     ], NUMERIC : [10, 12, 14], ALPHANUMERIC : [
50         9, 11, 13
51     ], STRUCTURED_APPEND : [0, 0, 0], BYTE : [
52         8, 16, 16
53     ], ECI : [0, 0, 0], KANJI : [
54         8, 10, 12
55     ], FNC1_FIRST_POSITION : [0, 0, 0], FNC1_SECOND_POSITION : [0, 0, 0], HANZI : [8, 10, 12],];
56 
57     /**
58 	* Gets the number of bits used in a specific QR code version.
59 	*
60 	* @param  Version $version
61 	* @return integer
62 	*/
63     public int getCharacterCountBits(QrCodeVersion _version)
64     {
65         int number = _version.VersionNumber;
66         int offset = 0;
67         if (number <= 9)
68         {
69             offset = 0;
70         }
71         else if (number <= 26)
72         {
73             offset = 1;
74         }
75         else
76         {
77             offset = 2;
78         }
79         return characterCountBitsForVersions[this._mode][offset];
80     }
81 }