feat(core):优化中文字体支持和证书生成功能

- 在BszxBmServiceImpl和BszxPayServiceImpl中增强字体检测逻辑,确保正确显示中文
- 调整macOS字体优先级,优先使用PingFang SC等系统字体- 添加多层字体回退机制,包括预定义字体、逻辑字体和错误提示
- 更新Dockerfile,安装文泉驿微米黑字体以支持中文显示- 添加中文乱码修复指南文档,提供三种修复方案和故障排查方法
- 创建fix-chinese-font.sh脚本,用于在运行中的容器内安装中文字体
- 删除不再使用的SQL脚本和证书检查脚本- 改进日志输出,提供更详细的字体加载信息和错误提示
This commit is contained in:
2025-10-30 14:46:53 +08:00
parent 3bb1e8f6ce
commit 6036869645
14 changed files with 415 additions and 1109 deletions

View File

@@ -184,32 +184,51 @@ public class BszxBmServiceImpl extends ServiceImpl<BszxBmMapper, BszxBm> impleme
try {
// 尝试使用系统中文字体
String[] chineseFonts = {
"Alibaba PuHuiTi 2.0",
"PingFang SC", // 苹方 (macOS) - 优先使用
"STHeiti", // 华文黑体 (macOS)
"Hiragino Sans GB", // 冬青黑体 (macOS)
"Microsoft YaHei", // 微软雅黑 (Windows)
"SimHei", // 黑体 (Windows)
"SimSun", // 宋体 (Windows)
"PingFang SC", // 苹方 (macOS)
"Hiragino Sans GB", // 冬青黑体 (macOS)
"WenQuanYi Micro Hei", // 文泉驿微米黑 (Linux)
"Noto Sans CJK SC", // 思源黑体 (Linux)
"Arial Unicode MS", // 支持Unicode的Arial
"DejaVu Sans" // 备用字体
};
for (String fontName : chineseFonts) {
Font font = new Font(fontName, Font.PLAIN, fontSize);
// 检查字体是否能正确显示中文
if (font.canDisplay('中')) {
System.out.println("使用字体: " + fontName);
if (font.canDisplay('中') && font.canDisplay('文')) {
System.out.println("✓ 成功使用字体: " + fontName + " (字号: " + fontSize + ")");
return font;
} else {
System.out.println("✗ 字体不支持中文: " + fontName);
}
}
// 如果没有找到合适的字体,尝试加载系统默认中文字体
System.out.println("⚠ 警告:未找到预定义的中文字体,尝试使用系统默认字体");
// 尝试使用逻辑字体名称这些在Java中通常会映射到系统字体
String[] logicalFonts = {"SansSerif", "Serif", "Monospaced", "Dialog", "DialogInput"};
for (String logicalFont : logicalFonts) {
Font font = new Font(logicalFont, Font.PLAIN, fontSize);
if (font.canDisplay('中') && font.canDisplay('文')) {
System.out.println("✓ 使用逻辑字体: " + logicalFont);
return font;
}
}
// 如果没有找到合适的字体,使用默认字体
System.out.println("警告:未找到支持中文的字体,使用默认字体");
return new Font(Font.SANS_SERIF, Font.PLAIN, fontSize);
// 最后的备选方案
System.err.println("❌ 严重警告:系统中没有找到任何支持中文的字体!请安装中文字体包。");
return new Font("SansSerif", Font.PLAIN, fontSize);
} catch (Exception e) {
System.err.println("创建中文字体失败: " + e.getMessage());
return new Font(Font.SANS_SERIF, Font.PLAIN, fontSize);
System.err.println("创建中文字体失败: " + e.getMessage());
e.printStackTrace();
return new Font("SansSerif", Font.PLAIN, fontSize);
}
}

View File

@@ -238,32 +238,51 @@ public class BszxPayServiceImpl extends ServiceImpl<BszxPayMapper, BszxPay> impl
try {
// 尝试使用系统中文字体
String[] chineseFonts = {
"Alibaba PuHuiTi 2.0",
"PingFang SC", // 苹方 (macOS) - 优先使用
"STHeiti", // 华文黑体 (macOS)
"Hiragino Sans GB", // 冬青黑体 (macOS)
"Microsoft YaHei", // 微软雅黑 (Windows)
"SimHei", // 黑体 (Windows)
"SimSun", // 宋体 (Windows)
"PingFang SC", // 苹方 (macOS)
"Hiragino Sans GB", // 冬青黑体 (macOS)
"WenQuanYi Micro Hei", // 文泉驿微米黑 (Linux)
"Noto Sans CJK SC", // 思源黑体 (Linux)
"Arial Unicode MS", // 支持Unicode的Arial
"DejaVu Sans" // 备用字体
};
for (String fontName : chineseFonts) {
Font font = new Font(fontName, Font.PLAIN, fontSize);
// 检查字体是否能正确显示中文
if (font.canDisplay('中')) {
System.out.println("使用字体: " + fontName);
if (font.canDisplay('中') && font.canDisplay('文')) {
System.out.println("✓ 成功使用字体: " + fontName + " (字号: " + fontSize + ")");
return font;
} else {
System.out.println("✗ 字体不支持中文: " + fontName);
}
}
// 如果没有找到合适的字体,尝试加载系统默认中文字体
System.out.println("⚠ 警告:未找到预定义的中文字体,尝试使用系统默认字体");
// 尝试使用逻辑字体名称这些在Java中通常会映射到系统字体
String[] logicalFonts = {"SansSerif", "Serif", "Monospaced", "Dialog", "DialogInput"};
for (String logicalFont : logicalFonts) {
Font font = new Font(logicalFont, Font.PLAIN, fontSize);
if (font.canDisplay('中') && font.canDisplay('文')) {
System.out.println("✓ 使用逻辑字体: " + logicalFont);
return font;
}
}
// 如果没有找到合适的字体,使用默认字体
System.out.println("警告:未找到支持中文的字体,使用默认字体");
return new Font(Font.SANS_SERIF, Font.PLAIN, fontSize);
// 最后的备选方案
System.err.println("❌ 严重警告:系统中没有找到任何支持中文的字体!请安装中文字体包。");
return new Font("SansSerif", Font.PLAIN, fontSize);
} catch (Exception e) {
System.err.println("创建中文字体失败: " + e.getMessage());
return new Font(Font.SANS_SERIF, Font.PLAIN, fontSize);
System.err.println("创建中文字体失败: " + e.getMessage());
e.printStackTrace();
return new Font("SansSerif", Font.PLAIN, fontSize);
}
}
}