Skip to content

Commit

Permalink
Merge pull request #41 from vflyson/patch-2
Browse files Browse the repository at this point in the history
Autodetect the optimal typeNumber if < 1
  • Loading branch information
kazuhikoarase authored Jul 24, 2017
2 parents c986449 + c4f61f5 commit 55998be
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions js/qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,33 @@ var qrcode = function() {
};

_this.make = function() {
if (_typeNumber < 1) {
var typeNumber = 1;

for (; typeNumber < 40; typeNumber++) {
var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, _errorCorrectionLevel);
var buffer = qrBitBuffer();

for (var i = 0; i < _dataList.length; i++) {
var data = _dataList[i];
buffer.put(data.getMode(), 4);
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber) );
data.write(buffer);
}

var totalDataCount = 0;
for (var i = 0; i < rsBlocks.length; i++) {
totalDataCount += rsBlocks[i].dataCount;
}

if (buffer.getLengthInBits() <= totalDataCount * 8) {
break;
}
}

_typeNumber = typeNumber;
}

makeImpl(false, getBestMaskPattern() );
};

Expand Down

0 comments on commit 55998be

Please sign in to comment.