X-Git-Url: https://git.hedgecode.org/?p=chesshog.git;a=blobdiff_plain;f=chesshog-qrcode%2Fsrc%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fchess%2Fqrcode%2FChessQRCodeWriter.java;h=cb2d53250e122b9b5d8040139bdf27e55182d7f4;hp=bc1175087ef43e17ca9cda13e106c3894f692256;hb=6f233e90e111f983e0ef401697859bb677bc0929;hpb=0b24d5b71c19ba38060297084ad39685f76a8539 diff --git a/chesshog-qrcode/src/main/java/org/hedgecode/chess/qrcode/ChessQRCodeWriter.java b/chesshog-qrcode/src/main/java/org/hedgecode/chess/qrcode/ChessQRCodeWriter.java index bc11750..cb2d532 100644 --- a/chesshog-qrcode/src/main/java/org/hedgecode/chess/qrcode/ChessQRCodeWriter.java +++ b/chesshog-qrcode/src/main/java/org/hedgecode/chess/qrcode/ChessQRCodeWriter.java @@ -35,7 +35,6 @@ import com.google.zxing.qrcode.encoder.ByteMatrix; import com.google.zxing.qrcode.encoder.Encoder; import com.google.zxing.qrcode.encoder.QRCode; -import org.hedgecode.chess.ChessQRCodeConstants; import org.hedgecode.chess.img.ImageFormat; /** @@ -47,12 +46,13 @@ public class ChessQRCodeWriter { private static final int DEF_QUIET_ZONE_SIZE = 4; private static final int DEF_QRCODE_BIT_SIZE = 250; + private static final int MIN_QRCODE_BIT_SIZE = 50; private static final ErrorCorrectionLevel DEF_ERR_CORR_LEVEL = ErrorCorrectionLevel.H; // todo: Q private static ChessQRCodeWriter _instance = new ChessQRCodeWriter(); - private ChessQRCodeWriter() { + protected ChessQRCodeWriter() { } public void write(ChessQRCodeMode mode, String contents, ImageFormat format, String qrCodeFilePath) @@ -139,7 +139,7 @@ public class ChessQRCodeWriter { ); } - private BitMatrix encode( + protected BitMatrix encode( ChessQRCodeMode mode, String contents, int width, int height, @@ -158,12 +158,14 @@ public class ChessQRCodeWriter { ); } - if (width < 0 || height < 0) { // todo + if (Math.min(width, height) < MIN_QRCODE_BIT_SIZE) { // todo: check for Version throw new ChessQRCodeException( ChessQRCodeException.Type.WRITE, "write.qrcode.size.incorrect" ); } + String qrCodeContents = mode.name().concat(contents); + int quietZone = DEF_QUIET_ZONE_SIZE; ErrorCorrectionLevel errorCorrectionLevel = DEF_ERR_CORR_LEVEL; @@ -188,12 +190,10 @@ public class ChessQRCodeWriter { } hints = newHints; - String qrCodeText = mode.name().concat(contents); - QRCode qrCode; try { qrCode = Encoder.encode( - qrCodeText, errorCorrectionLevel, hints + qrCodeContents, errorCorrectionLevel, hints ); } catch (WriterException e) { throw new ChessQRCodeException( @@ -239,7 +239,7 @@ public class ChessQRCodeWriter { ChessQRCodeMode.FEN, "rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2", ImageFormat.PNG, - "./MyQRCode.png" + "./qrcode.png" ); /* ChessQRCodeWriter.getInstance().write( @@ -249,7 +249,7 @@ public class ChessQRCodeWriter { "11.Bf4 b5 12.a4 Bb7 13.Re1 Nd5 14.Bg3 Kc8 15.axb5 cxb5 16.Qd3 Bc6 \n" + "17.Bf5 exf5 18.Rxe7 Bxe7 19.c4 1-0", ImageFormat.PNG, - "./MyQRCode.png" + "./qrcode.png" ); */ } catch (ChessQRCodeException e) {