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.DataTooLongException;
|
||||||
import io.nayuki.qrcodegen.QrCode;
|
import io.nayuki.qrcodegen.QrCode;
|
||||||
import io.nayuki.qrcodegen.QrCode.Ecc;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -31,7 +30,7 @@ public class App
|
||||||
jqrcode (-h | --help)
|
jqrcode (-h | --help)
|
||||||
jqrcode (-V | --version)
|
jqrcode (-V | --version)
|
||||||
jqrcode (-l | --licence)
|
jqrcode (-l | --licence)
|
||||||
jqrcode (-s | --say)
|
jqrcode [-m | --minified] (-s | --say)
|
||||||
""";
|
""";
|
||||||
private static String readInput() throws IOException {
|
private static String readInput() throws IOException {
|
||||||
BufferedReader input =
|
BufferedReader input =
|
||||||
|
@ -45,15 +44,38 @@ public class App
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String encode(String input) {
|
private static String encode(String input, QRStyle qrstyle) {
|
||||||
String output = "";
|
String output = "";
|
||||||
QrCode qr = QrCode.encodeText(input, QrCode.Ecc.MEDIUM);
|
QrCode qr = QrCode.encodeText(input, QrCode.Ecc.MEDIUM);
|
||||||
for(int x = 0; x < qr.size; x++) {
|
if (qrstyle.equals(QRStyle.NORMAL)) {
|
||||||
for(int y = 0; y < qr.size; y++) {
|
for(int x = 0; x < qr.size; x++) {
|
||||||
/* █ ▀ ▄ */
|
for(int y = 0; y < qr.size; y++) {
|
||||||
output += qr.getModule(x, 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;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -62,13 +84,18 @@ public class App
|
||||||
if (args.length > 0 ) {
|
if (args.length > 0 ) {
|
||||||
final Iterator<String> argsIterator =
|
final Iterator<String> argsIterator =
|
||||||
Arrays.stream(args).iterator();
|
Arrays.stream(args).iterator();
|
||||||
|
QRStyle qrStyle = QRStyle.NORMAL;
|
||||||
while (argsIterator.hasNext()){
|
while (argsIterator.hasNext()){
|
||||||
String arg = argsIterator.next();
|
String arg = argsIterator.next();
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case "-h":
|
case "-h":
|
||||||
case "--help":
|
case "--help":
|
||||||
System.out.println(HELP);
|
System.out.println(HELP);
|
||||||
System.exit(0);
|
break;
|
||||||
|
case "-m":
|
||||||
|
case "--minified":
|
||||||
|
qrStyle = QRStyle.MINIFIED;
|
||||||
|
continue;
|
||||||
case "-s":
|
case "-s":
|
||||||
case "--say":
|
case "--say":
|
||||||
if(argsIterator.hasNext()) {
|
if(argsIterator.hasNext()) {
|
||||||
|
@ -76,28 +103,35 @@ public class App
|
||||||
String output;
|
String output;
|
||||||
try {
|
try {
|
||||||
if (TEXT.equals("-")) {
|
if (TEXT.equals("-")) {
|
||||||
output = encode(readInput());
|
output = encode(
|
||||||
|
readInput(),
|
||||||
|
qrStyle
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
output = encode(TEXT);
|
output = encode(
|
||||||
|
TEXT,
|
||||||
|
qrStyle
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
output = "ERROR: Input too long!\n";
|
output = "ERROR: Input too long!\n";
|
||||||
}
|
}
|
||||||
System.out.print(output);
|
System.out.print(output);
|
||||||
System.exit(0);
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println("'--say' hasn't entry!");
|
System.out.println("'--say' hasn't entry!");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case "-V":
|
case "-V":
|
||||||
case "--version":
|
case "--version":
|
||||||
System.out.print(VERSION);
|
System.out.print(VERSION);
|
||||||
System.exit(0);
|
break;
|
||||||
case "-l":
|
case "-l":
|
||||||
case "--licence":
|
case "--licence":
|
||||||
System.out.print(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