2. AlphanumericMode, ByteMode, EciMode, NumericMode, QrMode 3. Add java class for using Strategy Patternpull/90/head
parent
b63fa83f32
commit
b65dad6f41
@ -0,0 +1,25 @@
|
||||
package io.nayuki.qrcodegen;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class AlphanumericMode extends QrMode {
|
||||
protected AlphanumericMode(int mode, int... ccbits) {
|
||||
modeBits = mode;
|
||||
numBitsCharCount = ccbits;
|
||||
}
|
||||
|
||||
protected AlphanumericMode() {
|
||||
modeBits = 0x2;
|
||||
numBitsCharCount[0] = 9;
|
||||
numBitsCharCount[1] = 11;
|
||||
numBitsCharCount[2] = 13;
|
||||
}
|
||||
|
||||
public int getcost(int pre, int codePoint) {
|
||||
return pre + 33;
|
||||
}
|
||||
|
||||
public QrSegment making(String str) {
|
||||
return QrSegment.makeAlphanumeric(str);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package io.nayuki.qrcodegen;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ByteMode extends QrMode {
|
||||
protected ByteMode(int mode, int... ccbits) {
|
||||
modeBits = mode;
|
||||
numBitsCharCount = ccbits;
|
||||
}
|
||||
|
||||
protected ByteMode() {
|
||||
modeBits = 0x4;
|
||||
numBitsCharCount[0] = 8;
|
||||
numBitsCharCount[1] = 16;
|
||||
numBitsCharCount[2] = 16;
|
||||
}
|
||||
|
||||
public int getcost(int pre, int codePoint) {
|
||||
return pre + QrSegmentAdvanced.countUtf8Bytes(codePoint) * 8 * 6;
|
||||
}
|
||||
|
||||
public QrSegment making(String str) {
|
||||
return QrSegment.makeBytes(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package io.nayuki.qrcodegen;
|
||||
|
||||
public class EciMode extends QrMode {
|
||||
protected EciMode(int mode, int... ccbits) {
|
||||
modeBits = mode;
|
||||
numBitsCharCount = ccbits;
|
||||
}
|
||||
|
||||
protected EciMode() {
|
||||
modeBits = 0x7;
|
||||
numBitsCharCount[0] = 0;
|
||||
numBitsCharCount[1] = 0;
|
||||
numBitsCharCount[2] = 0;
|
||||
}
|
||||
|
||||
public QrSegment making(int prmt) {
|
||||
return QrSegment.makeEci(prmt);
|
||||
}
|
||||
|
||||
public int getcost(int pre, int codePoint) {
|
||||
return pre;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package io.nayuki.qrcodegen;
|
||||
|
||||
public class NumericMode extends QrMode {
|
||||
protected NumericMode(int mode, int... ccbits) {
|
||||
modeBits = mode;
|
||||
numBitsCharCount = ccbits;
|
||||
}
|
||||
|
||||
protected NumericMode() {
|
||||
modeBits = 0x1;
|
||||
numBitsCharCount[0] = 10;
|
||||
numBitsCharCount[1] = 12;
|
||||
numBitsCharCount[2] = 1;
|
||||
}
|
||||
|
||||
public int getcost(int pre, int codePoint) {
|
||||
return pre + 20;
|
||||
}
|
||||
|
||||
public QrSegment making(String str) {
|
||||
return QrSegment.makeNumeric(str);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package io.nayuki.qrcodegen;
|
||||
|
||||
public abstract class QrMode {
|
||||
/*-- Fields --*/
|
||||
|
||||
// The mode indicator bits, which is a uint4 value (range 0 to 15).
|
||||
int modeBits;
|
||||
|
||||
// Number of character count bits for three different version ranges.
|
||||
protected int[] numBitsCharCount;
|
||||
|
||||
int headCost;
|
||||
/*-- Method --*/
|
||||
|
||||
// Returns the bit width of the character count field for a segment in this mode
|
||||
// in a QR Code at the given version number. The result is in the range [0, 16].
|
||||
int numCharCountBits(int ver) {
|
||||
assert QrCode.MIN_VERSION <= ver && ver <= QrCode.MAX_VERSION;
|
||||
return numBitsCharCount[(ver + 7) / 17];
|
||||
}
|
||||
|
||||
protected QrMode() {
|
||||
this.modeBits = 0;
|
||||
this.numBitsCharCount = null;
|
||||
}
|
||||
|
||||
public void get(QrMode md) {
|
||||
this.modeBits = md.modeBits;
|
||||
this.numBitsCharCount = md.numBitsCharCount;
|
||||
}
|
||||
|
||||
public int whichMode() {
|
||||
return modeBits;
|
||||
}
|
||||
|
||||
protected QrSegment making(String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getcost(int pre, int codePoint) {
|
||||
return pre;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue