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:
@@ -16,10 +16,14 @@ import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
import '../theme/tokens.dart';
|
||||
|
||||
/// 导出画布尺寸(固定)。
|
||||
/// 导出画布尺寸(固定,逻辑单位)。
|
||||
const Size kExportSize = Size(1920, 1080);
|
||||
|
||||
/// 导出渲染像素比:按 2 倍像素渲染(3840×2160),保证高分辨率屏幕下清晰锐利。
|
||||
const double kExportPixelRatio = 2.0;
|
||||
|
||||
/// 内容区(标题下方、图例上方)。
|
||||
const Rect kExportContentArea = Rect.fromLTRB(48, 128, 1872, 1016);
|
||||
|
||||
@@ -79,3 +83,52 @@ String exportSubtitle(Project project, ViewMode mode) {
|
||||
/// 导出图例(左下角固定)。
|
||||
String exportLegend(Project project) =>
|
||||
'时序图设计器 · ${project.name} · 循环 ${tfmt(project.cycle.durationMs, project.units)} = 360°';
|
||||
|
||||
/// 导出专用令牌:始终使用浅色、**纯白背景**(印刷 / 工艺卡导向),
|
||||
/// 文字、语义色与屏幕浅色主题保持一致。
|
||||
///
|
||||
/// 无论当前屏幕主题是深是浅,导出的 PNG / SVG 背景都是纯白、文字深色,
|
||||
/// 避免「导出背景不是纯白」的问题。
|
||||
Tokens exportTokens(Tokens base) {
|
||||
return Tokens(
|
||||
brightness: Brightness.light,
|
||||
bg: Colors.white,
|
||||
canvas1: Colors.white,
|
||||
canvas2: Colors.white,
|
||||
chrome: base.chrome,
|
||||
panel: Colors.white,
|
||||
panel2: Colors.white,
|
||||
dialog: Colors.white,
|
||||
line: base.line,
|
||||
line2: base.line2,
|
||||
text: base.text,
|
||||
text2: base.text2,
|
||||
sub: base.sub,
|
||||
dim: base.dim,
|
||||
accent: base.accent,
|
||||
accent2: base.accent2,
|
||||
ok: base.ok,
|
||||
warn: base.warn,
|
||||
danger: base.danger,
|
||||
fs: base.fs,
|
||||
ss: base.ss,
|
||||
crit: base.crit,
|
||||
chip: Colors.white,
|
||||
dial: Colors.white,
|
||||
arcText: base.arcText,
|
||||
onAccent: base.onAccent,
|
||||
ringA: base.ringA,
|
||||
ringB: base.ringB,
|
||||
ringEdge: base.ringEdge,
|
||||
ringLabel: base.ringLabel,
|
||||
info: Colors.white,
|
||||
track: base.track,
|
||||
sel: base.sel,
|
||||
grid: base.grid,
|
||||
shadow: base.shadow,
|
||||
shadowOp: 0.10,
|
||||
selOutline: base.selOutline,
|
||||
overlay: base.overlay,
|
||||
tailOp: base.tailOp,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,10 @@ class SvgWriter {
|
||||
/// - [mode]:视图模式,决定生成条形还是圆形布局。
|
||||
///
|
||||
/// 构造时不生成任何内容;调用 [build] 才写出 SVG。
|
||||
SvgWriter({required this.project, required this.tokens, required this.mode});
|
||||
///
|
||||
/// [tokens] 会经 [exportTokens] 转为导出专用令牌(纯白背景、浅色文字)。
|
||||
SvgWriter({required this.project, required Tokens tokens, required this.mode})
|
||||
: tokens = exportTokens(tokens);
|
||||
|
||||
/// 数据源工程。
|
||||
final Project project;
|
||||
|
||||
Reference in New Issue
Block a user