Can minimize QRCode.
Ça peut être plus carré via `-m`.
This commit is contained in:
parent
c305d24713
commit
7f6bbaaabd
2 changed files with 53 additions and 14 deletions
src/main/java/fr/alnotz/jqrcode
|
@ -2,7 +2,6 @@ package fr.alnotz.jqrcode;
|
|||
|
||||
import io.nayuki.qrcodegen.DataTooLongException;
|
||||
import io.nayuki.qrcodegen.QrCode;
|
||||
import io.nayuki.qrcodegen.QrCode.Ecc;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
@ -31,7 +30,7 @@ public class App
|
|||
jqrcode (-h | --help)
|
||||
jqrcode (-V | --version)
|
||||
jqrcode (-l | --licence)
|
||||
jqrcode (-s | --say)
|
||||
jqrcode [-m | --minified] (-s | --say)
|
||||
""";
|
||||
private static String readInput() throws IOException {
|
||||
BufferedReader input =
|
||||
|
@ -45,15 +44,38 @@ public class App
|
|||
return text;
|
||||
}
|
||||
|
||||
private static String encode(String input) {
|
||||
private static String encode(String input, QRStyle qrstyle) {
|
||||
String output = "";
|
||||
QrCode qr = QrCode.encodeText(input, QrCode.Ecc.MEDIUM);
|
||||
for(int x = 0; x < qr.size; x++) {
|
||||
for(int y = 0; y < qr.size; y++) {
|
||||
/* █ ▀ ▄ */
|
||||
output += qr.getModule(x, y) ? "█" : " ";
|
||||
if (qrstyle.equals(QRStyle.NORMAL)) {
|
||||
for(int x = 0; x < qr.size; x++) {
|
||||
for(int y = 0; y < qr.size; y++) {
|
||||
/* █ ▀ ▄ */
|
||||
output += qr.getModule(x, y) ? "█" : " ";
|
||||
}
|
||||
output += "\n";
|
||||
}
|
||||
} else {
|
||||
for(int x = 0; x < qr.size-1; x += 2) {
|
||||
for (int y = 0; y < qr.size; y++) {
|
||||
if (qr.getModule(x, y) && qr.getModule(x+1, y)) {
|
||||
output += "█";
|
||||
} else if (qr.getModule(x, y) && !qr.getModule(x+1, y)) {
|
||||
output += "▀";
|
||||
} else if (!qr.getModule(x, y) && qr.getModule(x+1, y)) {
|
||||
output += "▄";
|
||||
} else {
|
||||
output += " ";
|
||||
}
|
||||
}
|
||||
output += "\n";
|
||||
}
|
||||
if (qr.size %2 == 1) {
|
||||
for (int y = 0; y < qr.size; y++) {
|
||||
output += qr.getModule(qr.size-1, y) ? "▀" : " ";
|
||||
}
|
||||
output += "\n";
|
||||
}
|
||||
output += "\n";
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@ -62,13 +84,18 @@ public class App
|
|||
if (args.length > 0 ) {
|
||||
final Iterator<String> argsIterator =
|
||||
Arrays.stream(args).iterator();
|
||||
QRStyle qrStyle = QRStyle.NORMAL;
|
||||
while (argsIterator.hasNext()){
|
||||
String arg = argsIterator.next();
|
||||
switch (arg) {
|
||||
case "-h":
|
||||
case "--help":
|
||||
System.out.println(HELP);
|
||||
System.exit(0);
|
||||
break;
|
||||
case "-m":
|
||||
case "--minified":
|
||||
qrStyle = QRStyle.MINIFIED;
|
||||
continue;
|
||||
case "-s":
|
||||
case "--say":
|
||||
if(argsIterator.hasNext()) {
|
||||
|
@ -76,28 +103,35 @@ public class App
|
|||
String output;
|
||||
try {
|
||||
if (TEXT.equals("-")) {
|
||||
output = encode(readInput());
|
||||
output = encode(
|
||||
readInput(),
|
||||
qrStyle
|
||||
);
|
||||
} else {
|
||||
output = encode(TEXT);
|
||||
output = encode(
|
||||
TEXT,
|
||||
qrStyle
|
||||
);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
output = "ERROR: Input too long!\n";
|
||||
}
|
||||
System.out.print(output);
|
||||
System.exit(0);
|
||||
} else {
|
||||
System.out.println("'--say' hasn't entry!");
|
||||
System.exit(1);
|
||||
}
|
||||
break;
|
||||
case "-V":
|
||||
case "--version":
|
||||
System.out.print(VERSION);
|
||||
System.exit(0);
|
||||
break;
|
||||
case "-l":
|
||||
case "--licence":
|
||||
System.out.print(LICENCE);
|
||||
System.exit(0);
|
||||
break;
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
5
src/main/java/fr/alnotz/jqrcode/QRStyle.java
Normal file
5
src/main/java/fr/alnotz/jqrcode/QRStyle.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package fr.alnotz.jqrcode;
|
||||
|
||||
public enum QRStyle {
|
||||
NORMAL, MINIFIED
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue