mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
优化AnsiColorWrapper
This commit is contained in:
parent
d9506196de
commit
146abd3e26
@ -60,21 +60,6 @@ public class AnsiColorWrapper {
|
||||
return Ansi8BitColor.background(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 区分前景还是背景
|
||||
*/
|
||||
public enum ForeOrBack{
|
||||
|
||||
/**
|
||||
* 前景
|
||||
*/
|
||||
FORE,
|
||||
/**
|
||||
* 背景
|
||||
*/
|
||||
BACK,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
@ -0,0 +1,16 @@
|
||||
package cn.hutool.core.lang.ansi;
|
||||
|
||||
/**
|
||||
* 区分前景还是背景
|
||||
*/
|
||||
public enum ForeOrBack{
|
||||
|
||||
/**
|
||||
* 前景
|
||||
*/
|
||||
FORE,
|
||||
/**
|
||||
* 背景
|
||||
*/
|
||||
BACK,
|
||||
}
|
@ -30,10 +30,11 @@ public class AnsiEncoderTest {
|
||||
Color.RED, Color.WHITE,
|
||||
Color.YELLOW
|
||||
};
|
||||
for (Color foreColor : colorArray) {
|
||||
AnsiElement foreElement = ansiColors.findClosest(foreColor).toAnsiElement(AnsiColorWrapper.ForeOrBack.FORE);
|
||||
for (int i = 0; i < colorArray.length; i++) {
|
||||
Color foreColor = colorArray[i];
|
||||
AnsiElement foreElement = ansiColors.findClosest(foreColor).toAnsiElement(ForeOrBack.FORE);
|
||||
Color backColor = new Color(255 - foreColor.getRed(), 255 - foreColor.getGreen(), 255 - foreColor.getBlue());
|
||||
AnsiElement backElement = ansiColors.findClosest(backColor).toAnsiElement(AnsiColorWrapper.ForeOrBack.BACK);
|
||||
AnsiElement backElement = ansiColors.findClosest(backColor).toAnsiElement(ForeOrBack.BACK);
|
||||
String encode = AnsiEncoder.encode(foreElement, backElement, text);
|
||||
//Console.print( i%2==1?encode+"\n":encode);
|
||||
}
|
||||
@ -56,8 +57,8 @@ public class AnsiEncoderTest {
|
||||
count++;
|
||||
if (count<from)continue;
|
||||
if (count>until)break;
|
||||
AnsiElement backElement4bit = ansiColors4Bit.findClosest(new Color(r,g,b)).toAnsiElement(AnsiColorWrapper.ForeOrBack.BACK);
|
||||
AnsiElement backElement8bit = ansiColors8Bit.findClosest(new Color(r,g,b)).toAnsiElement(AnsiColorWrapper.ForeOrBack.BACK);
|
||||
AnsiElement backElement4bit = ansiColors4Bit.findClosest(new Color(r,g,b)).toAnsiElement(ForeOrBack.BACK);
|
||||
AnsiElement backElement8bit = ansiColors8Bit.findClosest(new Color(r,g,b)).toAnsiElement(ForeOrBack.BACK);
|
||||
String encode4 = AnsiEncoder.encode( backElement4bit,text4);
|
||||
String encode8 = AnsiEncoder.encode( backElement8bit,text8);
|
||||
//Console.log(StrUtil.format(encode4,r,g,b)+StrUtil.format(encode8,r,g,b));
|
||||
|
@ -5,10 +5,7 @@ import cn.hutool.core.img.Img;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.ansi.AnsiColorWrapper;
|
||||
import cn.hutool.core.lang.ansi.AnsiColors;
|
||||
import cn.hutool.core.lang.ansi.AnsiElement;
|
||||
import cn.hutool.core.lang.ansi.AnsiEncoder;
|
||||
import cn.hutool.core.lang.ansi.*;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
@ -637,8 +634,8 @@ public class QrCodeUtil {
|
||||
final int height = bitMatrix.getHeight();
|
||||
|
||||
|
||||
final AnsiElement foreground = qrConfig.foreColor == null ? null : rgbToAnsi8BitElement(qrConfig.foreColor, AnsiColorWrapper.ForeOrBack.FORE);
|
||||
final AnsiElement background = qrConfig.backColor == null ? null : rgbToAnsi8BitElement(qrConfig.backColor, AnsiColorWrapper.ForeOrBack.BACK);
|
||||
final AnsiElement foreground = qrConfig.foreColor == null ? null : rgbToAnsi8BitElement(qrConfig.foreColor, ForeOrBack.FORE);
|
||||
final AnsiElement background = qrConfig.backColor == null ? null : rgbToAnsi8BitElement(qrConfig.backColor, ForeOrBack.BACK);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i <= height; i += 2) {
|
||||
@ -669,7 +666,7 @@ public class QrCodeUtil {
|
||||
* @return AnsiElement
|
||||
* @since 5.8.6
|
||||
*/
|
||||
private static AnsiElement rgbToAnsi8BitElement(int rgb,AnsiColorWrapper.ForeOrBack foreOrBack) {
|
||||
private static AnsiElement rgbToAnsi8BitElement(int rgb,ForeOrBack foreOrBack) {
|
||||
return ansiColors.findClosest(new Color(rgb)).toAnsiElement(foreOrBack);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user