Skip to content

Commit af5e6ef

Browse files
committed
Add support up to version 40 (1852 to 4296 characters) + autodetect
1 parent 8d2f9c5 commit af5e6ef

2 files changed

Lines changed: 207 additions & 4 deletions

File tree

src/jquery.qrcode.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
}
77

88
// set default values
9+
// typeNumber < 1 for automatic calculation
910
options = $.extend( {}, {
1011
width : 256,
1112
height : 256,
12-
typeNumber : 4,
13+
typeNumber : -1,
1314
correctLevel : QRErrorCorrectLevel.H
1415
}, options);
1516

@@ -42,4 +43,4 @@
4243
jQuery(canvas).appendTo(this);
4344
});
4445
};
45-
})( jQuery );
46+
})( jQuery );

src/qrcode.js

Lines changed: 204 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ QRCode.prototype = {
7070
},
7171

7272
make : function() {
73+
// Calculate automatically typeNumber if provided is < 1
74+
if (this.typeNumber < 1 ){
75+
var typeNumber = 1;
76+
for (typeNumber = 1; typeNumber < 40; typeNumber++) {
77+
var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
78+
79+
var buffer = new QRBitBuffer();
80+
var totalDataCount = 0;
81+
for (var i = 0; i < rsBlocks.length; i++) {
82+
totalDataCount += rsBlocks[i].dataCount;
83+
}
84+
85+
for (var i = 0; i < this.dataList.length; i++) {
86+
var data = this.dataList[i];
87+
buffer.put(data.mode, 4);
88+
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber) );
89+
data.write(buffer);
90+
}
91+
if (buffer.getLengthInBits() <= totalDataCount * 8)
92+
break;
93+
}
94+
this.typeNumber = typeNumber;
95+
}
7396
this.makeImpl(false, this.getBestMaskPattern() );
7497
},
7598

@@ -947,8 +970,187 @@ QRRSBlock.RS_BLOCK_TABLE = [
947970
[2, 86, 68, 2, 87, 69],
948971
[4, 69, 43, 1, 70, 44],
949972
[6, 43, 19, 2, 44, 20],
950-
[6, 43, 15, 2, 44, 16]
951-
973+
[6, 43, 15, 2, 44, 16],
974+
975+
// 11
976+
[4, 101, 81],
977+
[1, 80, 50, 4, 81, 51],
978+
[4, 50, 22, 4, 51, 23],
979+
[3, 36, 12, 8, 37, 13],
980+
981+
// 12
982+
[2, 116, 92, 2, 117, 93],
983+
[6, 58, 36, 2, 59, 37],
984+
[4, 46, 20, 6, 47, 21],
985+
[7, 42, 14, 4, 43, 15],
986+
987+
// 13
988+
[4, 133, 107],
989+
[8, 59, 37, 1, 60, 38],
990+
[8, 44, 20, 4, 45, 21],
991+
[12, 33, 11, 4, 34, 12],
992+
993+
// 14
994+
[3, 145, 115, 1, 146, 116],
995+
[4, 64, 40, 5, 65, 41],
996+
[11, 36, 16, 5, 37, 17],
997+
[11, 36, 12, 5, 37, 13],
998+
999+
// 15
1000+
[5, 109, 87, 1, 110, 88],
1001+
[5, 65, 41, 5, 66, 42],
1002+
[5, 54, 24, 7, 55, 25],
1003+
[11, 36, 12],
1004+
1005+
// 16
1006+
[5, 122, 98, 1, 123, 99],
1007+
[7, 73, 45, 3, 74, 46],
1008+
[15, 43, 19, 2, 44, 20],
1009+
[3, 45, 15, 13, 46, 16],
1010+
1011+
// 17
1012+
[1, 135, 107, 5, 136, 108],
1013+
[10, 74, 46, 1, 75, 47],
1014+
[1, 50, 22, 15, 51, 23],
1015+
[2, 42, 14, 17, 43, 15],
1016+
1017+
// 18
1018+
[5, 150, 120, 1, 151, 121],
1019+
[9, 69, 43, 4, 70, 44],
1020+
[17, 50, 22, 1, 51, 23],
1021+
[2, 42, 14, 19, 43, 15],
1022+
1023+
// 19
1024+
[3, 141, 113, 4, 142, 114],
1025+
[3, 70, 44, 11, 71, 45],
1026+
[17, 47, 21, 4, 48, 22],
1027+
[9, 39, 13, 16, 40, 14],
1028+
1029+
// 20
1030+
[3, 135, 107, 5, 136, 108],
1031+
[3, 67, 41, 13, 68, 42],
1032+
[15, 54, 24, 5, 55, 25],
1033+
[15, 43, 15, 10, 44, 16],
1034+
1035+
// 21
1036+
[4, 144, 116, 4, 145, 117],
1037+
[17, 68, 42],
1038+
[17, 50, 22, 6, 51, 23],
1039+
[19, 46, 16, 6, 47, 17],
1040+
1041+
// 22
1042+
[2, 139, 111, 7, 140, 112],
1043+
[17, 74, 46],
1044+
[7, 54, 24, 16, 55, 25],
1045+
[34, 37, 13],
1046+
1047+
// 23
1048+
[4, 151, 121, 5, 152, 122],
1049+
[4, 75, 47, 14, 76, 48],
1050+
[11, 54, 24, 14, 55, 25],
1051+
[16, 45, 15, 14, 46, 16],
1052+
1053+
// 24
1054+
[6, 147, 117, 4, 148, 118],
1055+
[6, 73, 45, 14, 74, 46],
1056+
[11, 54, 24, 16, 55, 25],
1057+
[30, 46, 16, 2, 47, 17],
1058+
1059+
// 25
1060+
[8, 132, 106, 4, 133, 107],
1061+
[8, 75, 47, 13, 76, 48],
1062+
[7, 54, 24, 22, 55, 25],
1063+
[22, 45, 15, 13, 46, 16],
1064+
1065+
// 26
1066+
[10, 142, 114, 2, 143, 115],
1067+
[19, 74, 46, 4, 75, 47],
1068+
[28, 50, 22, 6, 51, 23],
1069+
[33, 46, 16, 4, 47, 17],
1070+
1071+
// 27
1072+
[8, 152, 122, 4, 153, 123],
1073+
[22, 73, 45, 3, 74, 46],
1074+
[8, 53, 23, 26, 54, 24],
1075+
[12, 45, 15, 28, 46, 16],
1076+
1077+
// 28
1078+
[3, 147, 117, 10, 148, 118],
1079+
[3, 73, 45, 23, 74, 46],
1080+
[4, 54, 24, 31, 55, 25],
1081+
[11, 45, 15, 31, 46, 16],
1082+
1083+
// 29
1084+
[7, 146, 116, 7, 147, 117],
1085+
[21, 73, 45, 7, 74, 46],
1086+
[1, 53, 23, 37, 54, 24],
1087+
[19, 45, 15, 26, 46, 16],
1088+
1089+
// 30
1090+
[5, 145, 115, 10, 146, 116],
1091+
[19, 75, 47, 10, 76, 48],
1092+
[15, 54, 24, 25, 55, 25],
1093+
[23, 45, 15, 25, 46, 16],
1094+
1095+
// 31
1096+
[13, 145, 115, 3, 146, 116],
1097+
[2, 74, 46, 29, 75, 47],
1098+
[42, 54, 24, 1, 55, 25],
1099+
[23, 45, 15, 28, 46, 16],
1100+
1101+
// 32
1102+
[17, 145, 115],
1103+
[10, 74, 46, 23, 75, 47],
1104+
[10, 54, 24, 35, 55, 25],
1105+
[19, 45, 15, 35, 46, 16],
1106+
1107+
// 33
1108+
[17, 145, 115, 1, 146, 116],
1109+
[14, 74, 46, 21, 75, 47],
1110+
[29, 54, 24, 19, 55, 25],
1111+
[11, 45, 15, 46, 46, 16],
1112+
1113+
// 34
1114+
[13, 145, 115, 6, 146, 116],
1115+
[14, 74, 46, 23, 75, 47],
1116+
[44, 54, 24, 7, 55, 25],
1117+
[59, 46, 16, 1, 47, 17],
1118+
1119+
// 35
1120+
[12, 151, 121, 7, 152, 122],
1121+
[12, 75, 47, 26, 76, 48],
1122+
[39, 54, 24, 14, 55, 25],
1123+
[22, 45, 15, 41, 46, 16],
1124+
1125+
// 36
1126+
[6, 151, 121, 14, 152, 122],
1127+
[6, 75, 47, 34, 76, 48],
1128+
[46, 54, 24, 10, 55, 25],
1129+
[2, 45, 15, 64, 46, 16],
1130+
1131+
// 37
1132+
[17, 152, 122, 4, 153, 123],
1133+
[29, 74, 46, 14, 75, 47],
1134+
[49, 54, 24, 10, 55, 25],
1135+
[24, 45, 15, 46, 46, 16],
1136+
1137+
// 38
1138+
[4, 152, 122, 18, 153, 123],
1139+
[13, 74, 46, 32, 75, 47],
1140+
[48, 54, 24, 14, 55, 25],
1141+
[42, 45, 15, 32, 46, 16],
1142+
1143+
// 39
1144+
[20, 147, 117, 4, 148, 118],
1145+
[40, 75, 47, 7, 76, 48],
1146+
[43, 54, 24, 22, 55, 25],
1147+
[10, 45, 15, 67, 46, 16],
1148+
1149+
// 40
1150+
[19, 148, 118, 6, 149, 119],
1151+
[18, 75, 47, 31, 76, 48],
1152+
[34, 54, 24, 34, 55, 25],
1153+
[20, 45, 15, 61, 46, 16]
9521154
];
9531155

9541156
QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {

0 commit comments

Comments
 (0)