部分字体补充统一、日志更新
This commit is contained in:
@@ -21,13 +21,17 @@ class ChargeEntry extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
summary,
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: c.textPrimary,
|
||||
Flexible(
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
children: _buildSpans(summary),
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
@@ -57,4 +61,54 @@ class ChargeEntry extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 按 CJK / 非 CJK 拆分字符串,分别应用 HarmonyOS / Flyme
|
||||
List<TextSpan> _buildSpans(String text) {
|
||||
final spans = <TextSpan>[];
|
||||
if (text.isEmpty) return spans;
|
||||
|
||||
final buffer = StringBuffer();
|
||||
bool? isCJK;
|
||||
|
||||
void flush() {
|
||||
if (buffer.isEmpty) return;
|
||||
spans.add(
|
||||
TextSpan(
|
||||
text: buffer.toString(),
|
||||
style: TextStyle(
|
||||
fontFamily: (isCJK ?? false) ? 'HarmonyOS_Sans_SC' : 'Flyme',
|
||||
),
|
||||
),
|
||||
);
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
for (final rune in text.runes) {
|
||||
final cjk = _isCJKRune(rune);
|
||||
if (isCJK == null || cjk == isCJK) {
|
||||
buffer.writeCharCode(rune);
|
||||
isCJK = cjk;
|
||||
} else {
|
||||
flush();
|
||||
buffer.writeCharCode(rune);
|
||||
isCJK = cjk;
|
||||
}
|
||||
}
|
||||
flush();
|
||||
return spans;
|
||||
}
|
||||
|
||||
bool _isCJKRune(int rune) {
|
||||
// CJK 统一表意文字
|
||||
if (rune >= 0x4E00 && rune <= 0x9FFF) return true;
|
||||
// CJK 扩展 A
|
||||
if (rune >= 0x3400 && rune <= 0x4DBF) return true;
|
||||
// 中文标点(。、,:;等)
|
||||
if (rune >= 0x3000 && rune <= 0x303F) return true;
|
||||
// CJK 兼容符号
|
||||
if (rune >= 0xFE30 && rune <= 0xFE4F) return true;
|
||||
// 全角字符
|
||||
if (rune >= 0xFF00 && rune <= 0xFFEF) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user