Skip to content

Commit 8e55c57

Browse files
committed
modify HousingSaleScheduler update font setting
1 parent 930cfcc commit 8e55c57

2 files changed

Lines changed: 52 additions & 16 deletions

File tree

.idea/workspace.xml

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/phantoms/phantomsbackend/service/scheduler/HousingSaleScheduler.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,10 @@ private String generateHousingTableImage(String server, List<HousingSale> houses
722722
int cols = headers.length;
723723
int rows = houses.size() + 2; // 表头 + 数据 + 标题
724724

725-
// 设置字体
726-
Font headerFont = new Font("黑体", Font.BOLD, 14);
727-
Font dataFont = new Font("黑体", Font.PLAIN, 12);
728-
Font titleFont = new Font("黑体", Font.BOLD, 24);
725+
// 设置字体,添加降级机制
726+
Font headerFont = getFontWithFallback("Noto Sans CJK SC", Font.BOLD, 14);
727+
Font dataFont = getFontWithFallback("Noto Sans CJK SC", Font.PLAIN, 12);
728+
Font titleFont = getFontWithFallback("Noto Sans CJK SC", Font.BOLD, 24);
729729

730730
// 计算动态列宽
731731
int[] columnWidths = calculateColumnWidths(houses, headers, headerFont, dataFont);
@@ -980,4 +980,40 @@ public void manualTriggerHousingDataFetch() {
980980
logger.info("手动触发房屋数据获取");
981981
fetchAndProcessHousingSales();
982982
}
983+
984+
/**
985+
* 获取字体,添加降级机制
986+
* @param fontName 字体名称
987+
* @param style 字体样式
988+
* @param size 字体大小
989+
* @return 字体对象
990+
*/
991+
private Font getFontWithFallback(String fontName, int style, int size) {
992+
// 字体优先级列表,适用于 Alpine Linux 环境
993+
String[] fontPriorities = {
994+
fontName, // 用户指定的字体
995+
"Noto Sans CJK SC", // 思源黑体(Google开源字体,现代无衬线字体)
996+
"WenQuanYi Micro Hei", // 文泉驿微米黑(轻量中文字体)
997+
"Droid Sans Fallback", // Android 回退字体
998+
Font.SANS_SERIF // 系统默认无衬线字体
999+
};
1000+
1001+
for (String currentFontName : fontPriorities) {
1002+
try {
1003+
// 尝试加载当前字体
1004+
Font font = new Font(currentFontName, style, size);
1005+
// 检查字体是否成功加载
1006+
if (font != null && !font.getFontName().equals("Dialog")) {
1007+
return font;
1008+
}
1009+
} catch (Exception e) {
1010+
// 捕获字体加载异常,继续尝试下一个字体
1011+
logger.debug("加载字体 {} 失败: {}", currentFontName, e.getMessage());
1012+
}
1013+
}
1014+
1015+
// 如果所有字体都加载失败,使用系统默认字体
1016+
logger.warn("所有字体加载失败,使用系统默认字体");
1017+
return new Font(Font.SANS_SERIF, style, size);
1018+
}
9831019
}

0 commit comments

Comments
 (0)