78 lines
3.3 KiB
Dart
78 lines
3.3 KiB
Dart
// 方向校准卡(Windows Pavo 直打校准用):642×1014 纵向,四角 ▲■●◆ + 中央大写 F + 左右箭头。
|
||
// 打一张即可从 8 种变换(4 旋转 × 2 镜像)中唯一定出打印机的实际映射。
|
||
//
|
||
// 用法(在项目根目录):
|
||
// dart run tool/make_test_card.dart # 只生成 build/calibration_card.png
|
||
// dart run tool/make_test_card.dart --print # 生成并直接 POST 到本机助手打印一张
|
||
//
|
||
// 放卡方式与正式打印一致:打印面朝上、文字对着自己。
|
||
import 'dart:convert';
|
||
import 'dart:io';
|
||
|
||
import 'package:image/image.dart';
|
||
|
||
Future<void> main(List<String> args) async {
|
||
final doPrint = args.contains('--print');
|
||
final black = ColorRgb8(0, 0, 0);
|
||
final img = Image(width: 642, height: 1014);
|
||
fill(img, color: ColorRgb8(255, 255, 255));
|
||
|
||
// 边框(四边留 6px)
|
||
drawRect(img, x1: 6, y1: 6, x2: 635, y2: 1007, color: ColorRgb8(0, 120, 215));
|
||
|
||
// 四角标记(各不相同,一印即辨)
|
||
// 左上:实心三角 ▲
|
||
fillPolygon(img, vertices: [Point(40, 40), Point(150, 40), Point(40, 150)], color: black);
|
||
drawString(img, 'LT', font: arial14, x: 44, y: 158, color: black);
|
||
// 右上:实心方块 ■
|
||
fillRect(img, x1: 492, y1: 40, x2: 602, y2: 150, color: black);
|
||
drawString(img, 'RT', font: arial14, x: 500, y: 158, color: black);
|
||
// 左下:实心圆 ●
|
||
fillCircle(img, x: 95, y: 930, radius: 55, color: black);
|
||
drawString(img, 'LB', font: arial14, x: 44, y: 856, color: black);
|
||
// 右下:实心菱形 ◆
|
||
fillPolygon(img, vertices: [Point(547, 860), Point(602, 930), Point(547, 1000), Point(492, 930)], color: black);
|
||
drawString(img, 'RB', font: arial14, x: 560, y: 1004, color: black);
|
||
|
||
// 中部超大 F(旋转/镜像一票判别)
|
||
// arial 字体最大 48 号,642 宽卡面已足够醒目
|
||
drawString(img, 'F', font: arial48, x: 300, y: 520, color: black);
|
||
|
||
// 左右语义标注 + 箭头线
|
||
drawString(img, '<-LEFT', font: arial24, x: 60, y: 430, color: black);
|
||
drawString(img, 'RIGHT->', font: arial24, x: 440, y: 430, color: black);
|
||
drawLine(img, x1: 180, y1: 340, x2: 440, y2: 340, color: black, thickness: 8);
|
||
fillPolygon(img, vertices: [Point(440, 320), Point(490, 340), Point(440, 360)], color: black);
|
||
drawString(img, 'CALIB 0923', font: arial14, x: 180, y: 312, color: black);
|
||
|
||
final png = encodePng(img);
|
||
final out = 'build/calibration_card.png';
|
||
final file = File(out);
|
||
await file.parent.create(recursive: true);
|
||
await file.writeAsBytes(png);
|
||
// ignore: avoid_print
|
||
print('written $out (${png.length} bytes)');
|
||
|
||
if (doPrint) {
|
||
final b64 = base64Encode(png);
|
||
final body = jsonEncode({
|
||
'copies': 1,
|
||
'front': {'color': 'data:image/png;base64,$b64'},
|
||
});
|
||
final client = HttpClient();
|
||
try {
|
||
final req = await client.postUrl(Uri.parse('http://127.0.0.1:38200/api/card-printer/print'));
|
||
req.headers.contentType = ContentType.json;
|
||
req.write(body);
|
||
final res = await req.close();
|
||
final text = await res.transform(utf8.decoder).join();
|
||
// ignore: avoid_print
|
||
print('print -> ${res.statusCode} $text');
|
||
// ignore: avoid_print
|
||
print('任务已提交;等打印机出卡后查看方向(四角标记:LT三角 RT方块 LB圆 RB菱形,中央大F)');
|
||
} finally {
|
||
client.close();
|
||
}
|
||
}
|
||
}
|