diff --git a/src/main/java/fr/alnotz/jqrcode/App.java b/src/main/java/fr/alnotz/jqrcode/App.java index 21fbf15..3b188ac 100644 --- a/src/main/java/fr/alnotz/jqrcode/App.java +++ b/src/main/java/fr/alnotz/jqrcode/App.java @@ -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); } } } diff --git a/src/main/java/fr/alnotz/jqrcode/QRStyle.java b/src/main/java/fr/alnotz/jqrcode/QRStyle.java new file mode 100644 index 0000000..dae8f50 --- /dev/null +++ b/src/main/java/fr/alnotz/jqrcode/QRStyle.java @@ -0,0 +1,5 @@ +package fr.alnotz.jqrcode; + +public enum QRStyle { + NORMAL, MINIFIED +}