66import com .google .zxing .client .j2se .MatrixToImageWriter ;
77import com .google .zxing .qrcode .QRCodeWriter ;
88import com .google .zxing .qrcode .decoder .ErrorCorrectionLevel ;
9-
109import net .glxn .qrgen .core .AbstractQRCode ;
1110import net .glxn .qrgen .core .exception .QRGenerationException ;
1211import net .glxn .qrgen .core .image .ImageType ;
@@ -28,6 +27,40 @@ protected QRCode(String text) {
2827 qrWriter = new QRCodeWriter ();
2928 }
3029
30+ /**
31+ * Create a QR code from the given text. <br><br>
32+ * <p>
33+ * There is a size limitation to how much you can put into a QR code. This has been tested to work with up to a length of
34+ * 2950
35+ * characters.<br><br>
36+ * </p>
37+ * <p>
38+ * The QRCode will have the following defaults: <br> {size: 100x100}<br>{imageType:PNG} <br><br>
39+ * </p>
40+ * Both size and imageType can be overridden: <br> Image type override is done by calling {@link
41+ * QRCode#to(ImageType)} e.g. QRCode.from("hello world").to(JPG) <br> Size override is done
42+ * by calling
43+ * {@link QRCode#withSize} e.g. QRCode.from("hello world").to(JPG).withSize(125, 125) <br>
44+ *
45+ * @param text the text to encode to a new QRCode, this may fail if the text is too large. <br>
46+ * @return the QRCode object <br>
47+ */
48+ public static QRCode from (String text ) {
49+ return new QRCode (text );
50+ }
51+
52+ /**
53+ * Creates a a QR Code from the given {@link VCard}.
54+ * <p>
55+ * The QRCode will have the following defaults: <br> {size: 100x100}<br>{imageType:PNG} <br><br>
56+ * </p>
57+ * @param vcard the vcard to encode as QRCode
58+ * @return the QRCode object
59+ */
60+ public static QRCode from (VCard vcard ) {
61+ return new QRCode (vcard .toString ());
62+ }
63+
3164 /**
3265 * Overrides the imageType from its default {@link net.glxn.qrgen.core.image.ImageType#PNG}
3366 *
@@ -56,6 +89,7 @@ public QRCode withSize(int width, int height) {
5689 * Overrides the default charset by supplying a {@link com.google.zxing.EncodeHintType#CHARACTER_SET} hint to {@link
5790 * com.google.zxing.qrcode.QRCodeWriter#encode}
5891 *
92+ * @param charset the charset as string, e.g. UTF-8
5993 * @return the current QRCode object
6094 */
6195 public QRCode withCharset (String charset ) {
@@ -66,6 +100,7 @@ public QRCode withCharset(String charset) {
66100 * Overrides the default error correction by supplying a {@link com.google.zxing.EncodeHintType#ERROR_CORRECTION} hint to
67101 * {@link com.google.zxing.qrcode.QRCodeWriter#encode}
68102 *
103+ * @param level the error correction level to use by {@link com.google.zxing.qrcode.QRCodeWriter#encode}
69104 * @return the current QRCode object
70105 */
71106 public QRCode withErrorCorrection (ErrorCorrectionLevel level ) {
@@ -75,70 +110,15 @@ public QRCode withErrorCorrection(ErrorCorrectionLevel level) {
75110 /**
76111 * Sets hint to {@link com.google.zxing.qrcode.QRCodeWriter#encode}
77112 *
113+ * @param hintType the hintType to set
114+ * @param value the concrete value to set
78115 * @return the current QRCode object
79116 */
80117 public QRCode withHint (EncodeHintType hintType , Object value ) {
81118 hints .put (hintType , value );
82119 return this ;
83120 }
84121
85- /**
86- * Create a QR code from the given text. <br/><br/>
87- * <p/>
88- * There is a size limitation to how much you can put into a QR code. This has been tested to work with up to a length of
89- * 2950
90- * characters.<br/><br/>
91- * <p/>
92- * The QRCode will have the following defaults: <br/> {size: 100x100}<br/>{imageType:PNG} <br/><br/>
93- * <p/>
94- * Both size and imageType can be overridden: <br/> Image type override is done by calling {@link
95- * AbstractQRCode#to(net.glxn.qrgen.core.image.ImageType)} e.g. QRCode.from("hello world").to(JPG) <br/> Size override is done
96- * by calling
97- * {@link AbstractQRCode#withSize} e.g. QRCode.from("hello world").to(JPG).withSize(125, 125) <br/>
98- *
99- * @param text the text to encode to a new QRCode, this may fail if the text is too large. <br/>
100- * @return the QRCode object <br/>
101- */
102- public static QRCode from (String text ) {
103- return new QRCode (text );
104- }
105-
106- /**
107- * Creates a a QR Code from the given {@link VCard}.
108- * <p/>
109- * The QRCode will have the following defaults: <br/> {size: 100x100}<br/>{imageType:PNG} <br/><br/>
110- *
111- * @param vcard the vcard to encode as QRCode
112- * @return the QRCode object
113- */
114- public static QRCode from (VCard vcard ) {
115- return new QRCode (vcard .toString ());
116- }
117-
118- public File svg () {
119- File file ;
120- try {
121- file = createTempSvgFile ();
122- MatrixToSvgWriter .writeToPath (createMatrix (text ), file .toPath (), matrixToImageConfig );
123- } catch (Exception e ) {
124- throw new QRGenerationException ("Failed to create QR svg from text due to underlying exception" , e );
125- }
126-
127- return file ;
128- }
129-
130- public File svg (String name ) {
131- File file ;
132- try {
133- file = createTempSvgFile (name );
134- MatrixToSvgWriter .writeToPath (createMatrix (text ), file .toPath (), matrixToImageConfig );
135- } catch (Exception e ) {
136- throw new QRGenerationException ("Failed to create QR svg from text due to underlying exception" , e );
137- }
138-
139- return file ;
140- }
141-
142122 @ Override
143123 public File file () {
144124 File file ;
0 commit comments