feat: 导出固定 1920×1080(标题恒定左上、内容自适应缩放)+ 安卓保存位置可配置
- 导出重设计(exe 与安卓一致):SVG/PNG 固定 1920×1080;标题恒定左上、图例恒定左下;内容按包围盒等比缩放居中(export_fit.dart 统一计算,不裁切不溢出);PNG 改为离屏 1920×1080 渲染 - 安卓保存位置可改:保存/打开对话框新增「更改位置」,基础目录可选文档/下载/图片 + 自定义子文件夹,设置持久化(save_location.json) - 原生通道 seqstudio/docs 支持 base/folder 参数;新增 export_test.dart 回归(尺寸/标题/transform) - 重建 dist(Windows)与签名 APK
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/// PNG 导出渲染器:把时序图渲染为固定 1920×1080 的位图。
|
||||
///
|
||||
/// 与 SVG 导出共用同一套适配计算([computeExportFit]),保证两种格式几何一致:
|
||||
/// - 背景铺满 1920×1080;
|
||||
/// - 标题固定在左上角、图例固定在左下角;
|
||||
/// - 内容(条形 / 圆周)按自身包围盒等比缩放并居中到内容区。
|
||||
library;
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../model/models.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
import '../render/circular_painter.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'export_fit.dart';
|
||||
|
||||
/// 渲染导出 PNG 并返回字节。
|
||||
///
|
||||
/// 参数:
|
||||
/// - [project]:数据源;
|
||||
/// - [tokens]:配色令牌;
|
||||
/// - [criticalActions]/[criticalDeps]:关键路径高亮(与屏幕一致)。
|
||||
Future<Uint8List> renderExportPng({
|
||||
required Project project,
|
||||
required Tokens tokens,
|
||||
required Set<String> criticalActions,
|
||||
required Set<String> criticalDeps,
|
||||
}) async {
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
final Canvas canvas = Canvas(recorder);
|
||||
final double w = kExportSize.width;
|
||||
final double h = kExportSize.height;
|
||||
|
||||
// 背景铺满。
|
||||
canvas.drawRect(Rect.fromLTWH(0, 0, w, h), Paint()..color = tokens.bg);
|
||||
|
||||
// 标题:固定左上角。
|
||||
final ViewMode mode = project.viewState.mode;
|
||||
_text(canvas, exportTitle(mode), const Offset(48, 36),
|
||||
color: tokens.text, size: 34, weight: FontWeight.w700);
|
||||
_text(canvas, exportSubtitle(project, mode), const Offset(48, 88),
|
||||
color: tokens.sub, size: 16, weight: FontWeight.w400);
|
||||
|
||||
// 内容:适配缩放并居中到内容区。
|
||||
final ExportFit fit = computeExportFit(project, mode, kExportContentArea);
|
||||
canvas.save();
|
||||
canvas.translate(fit.tx, fit.ty);
|
||||
canvas.scale(fit.scale);
|
||||
if (mode == ViewMode.bar) {
|
||||
BarPainter(
|
||||
project: project,
|
||||
tokens: tokens,
|
||||
criticalActions: criticalActions,
|
||||
criticalDeps: criticalDeps,
|
||||
selectedIds: const <String>{},
|
||||
).paint(canvas, kExportSize);
|
||||
} else {
|
||||
CircularPainter(
|
||||
project: project,
|
||||
tokens: tokens,
|
||||
criticalActions: criticalActions,
|
||||
criticalDeps: criticalDeps,
|
||||
selectedIds: const <String>{},
|
||||
).paint(canvas, kExportSize);
|
||||
}
|
||||
canvas.restore();
|
||||
|
||||
// 图例:固定左下角。
|
||||
_text(canvas, exportLegend(project), Offset(48, h - 38),
|
||||
color: tokens.sub, size: 15, weight: FontWeight.w400);
|
||||
|
||||
final ui.Image image = await recorder.endRecording().toImage(w.toInt(), h.toInt());
|
||||
final ByteData? data = await image.toByteData(format: ui.ImageByteFormat.png);
|
||||
return data!.buffer.asUint8List();
|
||||
}
|
||||
|
||||
/// 用统一字体绘制单行文本。
|
||||
void _text(Canvas canvas, String s, Offset at,
|
||||
{required Color color, required double size, required FontWeight weight}) {
|
||||
final TextPainter tp = TextPainter(
|
||||
text: TextSpan(
|
||||
text: s,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: size,
|
||||
fontWeight: weight,
|
||||
fontFamily: 'Microsoft YaHei UI',
|
||||
fontFamilyFallback: const <String>['Microsoft YaHei', 'Noto Sans SC', 'sans-serif'],
|
||||
),
|
||||
),
|
||||
textDirection: ui.TextDirection.ltr,
|
||||
)..layout();
|
||||
tp.paint(canvas, Offset(at.dx, at.dy - tp.height / 2));
|
||||
}
|
||||
Reference in New Issue
Block a user