2026-10-06 21:04:38 +08:00
|
|
|
// 测试辅助:构造演示工程与加载中文字体(用于平板布局测试与截图生成)。
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:sequence_diagram/model/models.dart';
|
|
|
|
|
|
|
|
|
|
/// 构造一个动作较多、含依赖与相位分区的演示工程。
|
2026-10-09 13:59:05 +08:00
|
|
|
/// 演示工程:与内置默认工程完全一致(`Project.demo()`),
|
|
|
|
|
/// 保证「本地构建启动即所见」与演示截图的数据永远同步。
|
|
|
|
|
Project demoTiming() => Project.demo();
|
2026-10-06 21:04:38 +08:00
|
|
|
|
|
|
|
|
/// 从系统字体加载中文字体,使测试截图中的中文正常渲染。
|
|
|
|
|
Future<void> loadZhFonts() async {
|
|
|
|
|
const List<String> candidates = <String>[
|
|
|
|
|
r'C:\Windows\Fonts\simhei.ttf',
|
|
|
|
|
r'C:\Windows\Fonts\msyh.ttf',
|
|
|
|
|
r'C:\Windows\Fonts\msyh.ttc',
|
|
|
|
|
r'C:\Windows\Fonts\simsun.ttc',
|
|
|
|
|
];
|
|
|
|
|
for (final String path in candidates) {
|
|
|
|
|
final File f = File(path);
|
|
|
|
|
if (!f.existsSync()) continue;
|
|
|
|
|
final ByteData bytes = ByteData.sublistView(await f.readAsBytes());
|
|
|
|
|
final FontLoader loader = FontLoader('Microsoft YaHei UI')..addFont(Future<ByteData>.value(bytes));
|
|
|
|
|
await loader.load();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-09 13:59:05 +08:00
|
|
|
|
|
|
|
|
/// 从 Flutter SDK 加载 Material 图标字体,使测试截图中的图标正常渲染
|
|
|
|
|
/// (否则所有 Icon 会显示为空心方框)。
|
|
|
|
|
Future<void> loadMaterialIcons() async {
|
|
|
|
|
final String root = Platform.environment['FLUTTER_ROOT'] ?? '';
|
|
|
|
|
if (root.isEmpty) return;
|
|
|
|
|
final File f = File('$root/bin/cache/artifacts/material_fonts/MaterialIcons-Regular.otf');
|
|
|
|
|
if (!f.existsSync()) return;
|
|
|
|
|
final ByteData bytes = ByteData.sublistView(await f.readAsBytes());
|
|
|
|
|
final FontLoader loader = FontLoader('MaterialIcons')..addFont(Future<ByteData>.value(bytes));
|
|
|
|
|
await loader.load();
|
|
|
|
|
}
|