fix(export): 纯白背景 + 2x 像素比渲染(3840×2160),导出更清晰

- 导出专用令牌 exportTokens:无论屏幕主题深浅,SVG/PNG 背景均为纯白、文字深色(印刷/工艺卡导向)

- PNG 按 2 倍像素比渲染:1920×1080 逻辑画布 → 3840×2160 像素,矢量内容在高分屏上锐利

- SVG 背景 rect 同步纯白;export_test 校验尺寸 3840×2160 与左上角纯白像素

- 重建 dist 与签名 APK
This commit is contained in:
admin
2026-10-07 09:44:33 +08:00
parent c1d9f27952
commit 2b04705ba8
4 changed files with 91 additions and 17 deletions
+18 -9
View File
@@ -21,28 +21,35 @@ import 'export_fit.dart';
///
/// 参数:
/// - [project]:数据源;
/// - [tokens]:配色令牌;
/// - [tokens]:配色令牌(内部转为导出专用纯白主题);
/// - [criticalActions]/[criticalDeps]:关键路径高亮(与屏幕一致)。
///
/// 输出:3840×2160 像素(1920×1080 逻辑画布 × 2 倍像素比),
/// 保证平板 / 2K / 4K 屏幕上查看清晰锐利。
Future<Uint8List> renderExportPng({
required Project project,
required Tokens tokens,
required Set<String> criticalActions,
required Set<String> criticalDeps,
}) async {
// 导出专用令牌:纯白背景、浅色文字。
final Tokens et = exportTokens(tokens);
final ui.PictureRecorder recorder = ui.PictureRecorder();
final Canvas canvas = Canvas(recorder);
final double w = kExportSize.width;
final double h = kExportSize.height;
// 2 倍像素比:整体放大绘制,矢量内容保持锐利。
canvas.scale(kExportPixelRatio);
// 背景铺满。
canvas.drawRect(Rect.fromLTWH(0, 0, w, h), Paint()..color = tokens.bg);
// 背景铺满(纯白)。
canvas.drawRect(Rect.fromLTWH(0, 0, w, h), Paint()..color = et.bg);
// 标题:固定左上角。
final ViewMode mode = project.viewState.mode;
_text(canvas, exportTitle(mode), const Offset(48, 36),
color: tokens.text, size: 34, weight: FontWeight.w700);
color: et.text, size: 34, weight: FontWeight.w700);
_text(canvas, exportSubtitle(project, mode), const Offset(48, 88),
color: tokens.sub, size: 16, weight: FontWeight.w400);
color: et.sub, size: 16, weight: FontWeight.w400);
// 内容:适配缩放并居中到内容区。
final ExportFit fit = computeExportFit(project, mode, kExportContentArea);
@@ -52,7 +59,7 @@ Future<Uint8List> renderExportPng({
if (mode == ViewMode.bar) {
BarPainter(
project: project,
tokens: tokens,
tokens: et,
criticalActions: criticalActions,
criticalDeps: criticalDeps,
selectedIds: const <String>{},
@@ -60,7 +67,7 @@ Future<Uint8List> renderExportPng({
} else {
CircularPainter(
project: project,
tokens: tokens,
tokens: et,
criticalActions: criticalActions,
criticalDeps: criticalDeps,
selectedIds: const <String>{},
@@ -70,9 +77,11 @@ Future<Uint8List> renderExportPng({
// 图例:固定左下角。
_text(canvas, exportLegend(project), Offset(48, h - 38),
color: tokens.sub, size: 15, weight: FontWeight.w400);
color: et.sub, size: 15, weight: FontWeight.w400);
final ui.Image image = await recorder.endRecording().toImage(w.toInt(), h.toInt());
final ui.Image image = await recorder
.endRecording()
.toImage((w * kExportPixelRatio).toInt(), (h * kExportPixelRatio).toInt());
final ByteData? data = await image.toByteData(format: ui.ImageByteFormat.png);
return data!.buffer.asUint8List();
}