fix(client): 打印字体改 TrueType,修复 Windows 打印卡死
打印字体实为 OpenType/CFF,dart_pdf 只支持 TrueType(glyf),渲染中文 抛 'does not support Unicode';标签打印时异常抛在原生 onLayout 回调内 导致打印插件死等->卡死。用 fonttools 将字体转为 TrueType/glyf 替换。 加回归测试防止退回 CFF 字体。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
|
||||
// 回归测试:打印用的中文字体必须是 TrueType(glyf) 轮廓。
|
||||
// 若误用 OpenType/CFF 字体(如 Noto 的 .otf),dart_pdf 渲染中文会抛
|
||||
// "This font does not support Unicode characters",标签打印会在原生 onLayout
|
||||
// 回调里抛异常导致 Windows 打印卡死。此测试确保打印 PDF 能正常生成中文。
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('打印字体能渲染中文(防止退回 CFF 字体导致打印卡死)', () async {
|
||||
final data = await rootBundle.load('assets/fonts/NotoSansSC-Regular.ttf');
|
||||
final font = pw.Font.ttf(data);
|
||||
|
||||
final doc = pw.Document();
|
||||
doc.addPage(pw.Page(
|
||||
build: (_) => pw.Text('入库单 茅台飞天 53度 500ml 扫码溯源',
|
||||
style: pw.TextStyle(font: font, fontSize: 12)),
|
||||
));
|
||||
|
||||
// 若字体是 CFF,会在此抛 Latin1/Unicode 异常。
|
||||
final bytes = await doc.save();
|
||||
expect(bytes.isNotEmpty, true);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user