mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add methods
This commit is contained in:
@@ -20,7 +20,7 @@ public class QrAsciiArt {
|
||||
* @param matrix {@link BitMatrix}
|
||||
* @param qrConfig {@link QrConfig}
|
||||
*/
|
||||
public QrAsciiArt(BitMatrix matrix, QrConfig qrConfig) {
|
||||
public QrAsciiArt(final BitMatrix matrix, final QrConfig qrConfig) {
|
||||
this.matrix = matrix;
|
||||
this.qrConfig = qrConfig;
|
||||
}
|
||||
@@ -34,12 +34,12 @@ public class QrAsciiArt {
|
||||
final AnsiElement foreground = qrConfig.foreColor == null ? null : ColorUtil.toAnsiColor(qrConfig.foreColor, true, false);
|
||||
final AnsiElement background = qrConfig.backColor == null ? null : ColorUtil.toAnsiColor(qrConfig.backColor, true, true);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i <= height; i += 2) {
|
||||
StringBuilder rowBuilder = new StringBuilder();
|
||||
final StringBuilder rowBuilder = new StringBuilder();
|
||||
for (int j = 0; j < width; j++) {
|
||||
boolean tp = matrix.get(i, j);
|
||||
boolean bt = i + 1 >= height || matrix.get(i + 1, j);
|
||||
final boolean tp = matrix.get(i, j);
|
||||
final boolean bt = i + 1 >= height || matrix.get(i + 1, j);
|
||||
if (tp && bt) {
|
||||
rowBuilder.append(' ');//'\u0020'
|
||||
} else if (tp) {
|
||||
|
@@ -41,7 +41,7 @@ public class QrCodeUtil {
|
||||
* @param logoBase64 logo 图片的 base64 编码
|
||||
* @return 图片 Base64 编码字符串
|
||||
*/
|
||||
public static String generateAsBase64(String content, QrConfig qrConfig, String targetType, String logoBase64) {
|
||||
public static String generateAsBase64(final String content, final QrConfig qrConfig, final String targetType, final String logoBase64) {
|
||||
return generateAsBase64DataUri(content, qrConfig, targetType, Base64.decode(logoBase64));
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class QrCodeUtil {
|
||||
* @param logo logo 图片的byte[]
|
||||
* @return 图片 Base64 编码字符串
|
||||
*/
|
||||
public static String generateAsBase64DataUri(String content, QrConfig qrConfig, String targetType, byte[] logo) {
|
||||
public static String generateAsBase64DataUri(final String content, final QrConfig qrConfig, final String targetType, final byte[] logo) {
|
||||
return generateAsBase64DataUri(content, qrConfig.setImg(ImgUtil.toImage(logo)), targetType);
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public class QrCodeUtil {
|
||||
* @return SVG矢量图(字符串)
|
||||
* @since 5.8.6
|
||||
*/
|
||||
public static String generateAsSvg(String content, QrConfig qrConfig) {
|
||||
public static String generateAsSvg(final String content, final QrConfig qrConfig) {
|
||||
return toSVG(encode(content, qrConfig), qrConfig);
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ public class QrCodeUtil {
|
||||
* @param config {@link QrConfig}
|
||||
* @return SVG矢量图(字符串)
|
||||
*/
|
||||
public static String toSVG(BitMatrix matrix, QrConfig config) {
|
||||
public static String toSVG(final BitMatrix matrix, final QrConfig config) {
|
||||
return new QrSVG(matrix, config).toString();
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ public class QrCodeUtil {
|
||||
* @return ASCII Art字符画形式的二维码
|
||||
* @since 5.8.6
|
||||
*/
|
||||
public static String generateAsAsciiArt(String content, QrConfig qrConfig) {
|
||||
public static String generateAsAsciiArt(final String content, final QrConfig qrConfig) {
|
||||
return toAsciiArt(encode(content, qrConfig), qrConfig);
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ public class QrCodeUtil {
|
||||
* @return ASCII Art字符画形式的二维码
|
||||
* @since 5.8.6
|
||||
*/
|
||||
public static String toAsciiArt(BitMatrix bitMatrix, QrConfig qrConfig) {
|
||||
public static String toAsciiArt(final BitMatrix bitMatrix, final QrConfig qrConfig) {
|
||||
return new QrAsciiArt(bitMatrix, qrConfig).toString();
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ public class QrEncoder implements Encoder<CharSequence, BitMatrix> {
|
||||
* @param config {@link QrConfig}
|
||||
* @return QrEncoder
|
||||
*/
|
||||
public static QrEncoder of(QrConfig config) {
|
||||
public static QrEncoder of(final QrConfig config) {
|
||||
return new QrEncoder(config);
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ public class QrEncoder implements Encoder<CharSequence, BitMatrix> {
|
||||
*
|
||||
* @param config {@link QrConfig}
|
||||
*/
|
||||
public QrEncoder(QrConfig config) {
|
||||
public QrEncoder(final QrConfig config) {
|
||||
this.config = ObjUtil.defaultIfNull(config, QrConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitMatrix encode(CharSequence content) {
|
||||
public BitMatrix encode(final CharSequence content) {
|
||||
final MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
||||
|
||||
final BitMatrix bitMatrix;
|
||||
|
@@ -2,6 +2,7 @@ package cn.hutool.extra.qrcode;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.swing.img.ImgUtil;
|
||||
import cn.hutool.swing.img.color.ColorUtil;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import java.awt.Color;
|
||||
@@ -22,7 +23,7 @@ public class QrSVG {
|
||||
* @param matrix {@link BitMatrix}
|
||||
* @param qrConfig {@link QrConfig}
|
||||
*/
|
||||
public QrSVG(BitMatrix matrix, QrConfig qrConfig) {
|
||||
public QrSVG(final BitMatrix matrix, final QrConfig qrConfig) {
|
||||
this.matrix = matrix;
|
||||
this.qrConfig = qrConfig;
|
||||
}
|
||||
@@ -35,9 +36,9 @@ public class QrSVG {
|
||||
final int ratio = qrConfig.ratio;
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
int qrWidth = matrix.getWidth();
|
||||
final int qrWidth = matrix.getWidth();
|
||||
int qrHeight = matrix.getHeight();
|
||||
int moduleHeight = (qrHeight == 1) ? qrWidth / 2 : 1;
|
||||
final int moduleHeight = (qrHeight == 1) ? qrWidth / 2 : 1;
|
||||
for (int y = 0; y < qrHeight; y++) {
|
||||
for (int x = 0; x < qrWidth; x++) {
|
||||
if (matrix.get(x, y)) {
|
||||
@@ -69,16 +70,16 @@ public class QrSVG {
|
||||
final StringBuilder result = StrUtil.builder();
|
||||
result.append("<svg width=\"").append(qrWidth).append("\" height=\"").append(qrHeight).append("\" \n");
|
||||
if (backColor != null) {
|
||||
Color back = new Color(backColor, true);
|
||||
result.append("style=\"background-color:rgba(").append(back.getRed()).append(",").append(back.getGreen()).append(",").append(back.getBlue()).append(",").append(back.getAlpha()).append(")\"\n");
|
||||
final Color back = new Color(backColor, true);
|
||||
result.append("style=\"background-color:").append(ColorUtil.toCssRgba(back)).append("\"\n");
|
||||
}
|
||||
result.append("viewBox=\"0 0 ").append(qrWidth).append(" ").append(qrHeight).append("\" \n");
|
||||
result.append("xmlns=\"http://www.w3.org/2000/svg\" \n");
|
||||
result.append("xmlns:xlink=\"http://www.w3.org/1999/xlink\" >\n");
|
||||
result.append("<path d=\"").append(sb).append("\" ");
|
||||
if (foreColor != null) {
|
||||
Color fore = new Color(foreColor, true);
|
||||
result.append("stroke=\"rgba(").append(fore.getRed()).append(",").append(fore.getGreen()).append(",").append(fore.getBlue()).append(",").append(fore.getAlpha()).append(")\"");
|
||||
final Color fore = new Color(foreColor, true);
|
||||
result.append("stroke=\"").append(ColorUtil.toCssRgba(fore)).append("\"");
|
||||
}
|
||||
result.append(" /> \n");
|
||||
if (StrUtil.isNotBlank(logoBase64)) {
|
||||
|
Reference in New Issue
Block a user