mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
优化生成SVG的代码
This commit is contained in:
parent
1ebdea3e0e
commit
cb5c5ba74f
@ -568,7 +568,7 @@ public class QrCodeUtil {
|
||||
* @return SVG矢量图(字符串)
|
||||
* @since 5.8.6
|
||||
*/
|
||||
public static String toSVG(BitMatrix matrix, int foreColor, Integer backColor, Image logoImg, int ratio) {
|
||||
public static String toSVG(BitMatrix matrix, Integer foreColor, Integer backColor, Image logoImg, int ratio) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int qrWidth = matrix.getWidth();
|
||||
int qrHeight = matrix.getHeight();
|
||||
@ -601,8 +601,6 @@ public class QrCodeUtil {
|
||||
|
||||
}
|
||||
|
||||
Color fore = new Color(foreColor, true);
|
||||
|
||||
StringBuilder result = StrUtil.builder();
|
||||
result.append("<svg width=\"").append(qrWidth).append("\" height=\"").append(qrHeight).append("\" \n");
|
||||
if (backColor != null) {
|
||||
@ -612,7 +610,12 @@ public class QrCodeUtil {
|
||||
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("\" stroke=\"rgba(").append(fore.getRed()).append(",").append(fore.getGreen()).append(",").append(fore.getBlue()).append(",").append(fore.getAlpha()).append(")\" /> \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(")\"");
|
||||
}
|
||||
result.append(" /> \n");
|
||||
if (StrUtil.isNotBlank(logoBase64)) {
|
||||
result.append("<image xlink:href=\"").append(logoBase64).append("\" height=\"").append(logoHeight).append("\" width=\"").append(logoWidth).append("\" y=\"").append(logoY).append("\" x=\"").append(logoX).append("\" />\n");
|
||||
}
|
||||
|
@ -207,12 +207,13 @@ public class QrCodeUtilTest {
|
||||
public void comparePngAndSvgAndAsciiArtTest() {
|
||||
final QrConfig qrConfig = QrConfig.create()
|
||||
.setForeColor(null)
|
||||
.setBackColor(null)
|
||||
.setWidth(0)
|
||||
.setHeight(0).setMargin(1);
|
||||
.setBackColor(Color.WHITE)
|
||||
.setWidth(200)
|
||||
.setHeight(200).setMargin(1);
|
||||
QrCodeUtil.generate("https://hutool.cn", qrConfig, FileUtil.touch("d:/test/compare/config_null_color.jpg"));
|
||||
QrCodeUtil.generate("https://hutool.cn", qrConfig, FileUtil.touch("d:/test/compare/config_null_color.txt"));
|
||||
QrCodeUtil.generate("https://hutool.cn", qrConfig, FileUtil.touch("d:/test/compare/config_null_color.png"));
|
||||
QrCodeUtil.generate("https://hutool.cn", qrConfig, FileUtil.touch("d:/test/compare/config_null_color.svg"));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user