diff --git a/CHANGELOG.md b/CHANGELOG.md index edef9d0..137bc83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.53] - 2026-06-15 + +### 修复 +- 修复 Windows 上点击打印无反应的问题(GBK 编码改为直接调用系统 API,不再依赖第三方插件) + ## [1.0.52] - 2026-06-15 ### 改进 diff --git a/client/lib/core/utils/print_util_stub.dart b/client/lib/core/utils/print_util_stub.dart index 6611c15..391b9fd 100644 --- a/client/lib/core/utils/print_util_stub.dart +++ b/client/lib/core/utils/print_util_stub.dart @@ -14,7 +14,8 @@ import 'package:win32/win32.dart' EndPagePrinter, EndDocPrinter, ClosePrinter, - DOC_INFO_1; + DOC_INFO_1, + WideCharToMultiByte; import 'package:flutter/foundation.dart' show kIsWeb, debugPrint; import 'package:flutter/services.dart'; import '../errors/error_reporter.dart'; @@ -266,12 +267,44 @@ Future _renderLabelBitmap({ return recorder.endRecording().toImage(sw, sh); // 返回 2× 图(640×320) } +/// UTF-8 → GBK 字节: +/// Windows 直接调 WideCharToMultiByte(936) FFI,无需插件; +/// macOS 走 charset_converter(CoreFoundation 原生支持 GBK)。 +Uint8List _encodeGbk(String text) { + if (text.isEmpty) return Uint8List(0); + if (Platform.isWindows) { + final wideStr = text.toNativeUtf16(); + try { + final needed = WideCharToMultiByte(936, 0, wideStr, -1, nullptr, 0, nullptr, nullptr); + if (needed <= 1) return Uint8List(0); + final buf = calloc(needed); + try { + WideCharToMultiByte(936, 0, wideStr, -1, buf.cast(), needed, nullptr, nullptr); + return Uint8List.fromList(buf.asTypedList(needed - 1)); // 不含 null 终止符 + } finally { + calloc.free(buf); + } + } finally { + calloc.free(wideStr); + } + } + // macOS: charset_converter(同步 CoreFoundation) + // encode() 在 macOS 上是同步 channel 调用,此处以 Future.value 包装保持接口一致 + throw UnsupportedError('call _encodeGbkAsync on macOS'); +} + +Future _encodeGbkAsync(String text) async { + if (text.isEmpty) return Uint8List(0); + if (Platform.isWindows) return _encodeGbk(text); + return CharsetConverter.encode('GBK', text); +} + /// TSPL TEXT 命令辅助:将文本以 GBK 编码写入 BytesBuilder。 /// TSS24.BF2/TSS16.BF2 是 TSC 固件内置简体中文点阵字体,需 GBK 编码。 Future _addTextCmd( BytesBuilder buf, int x, int y, String font, String text) async { if (text.isEmpty) return; - final gbk = await CharsetConverter.encode('GBK', text); + final gbk = await _encodeGbkAsync(text); buf.add(ascii.encode('TEXT $x,$y,"$font",0,1,1,"')); buf.add(gbk); buf.add(ascii.encode('"\r\n')); diff --git a/client/pubspec.lock b/client/pubspec.lock index 6131e19..0265447 100644 --- a/client/pubspec.lock +++ b/client/pubspec.lock @@ -521,10 +521,10 @@ packages: dependency: "direct main" description: name: path_provider - sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd" + sha256: a7f4874f987173da295a61c181b8ee71dab59b332a486b391babf26a1b884825 url: "https://pub.dev" source: hosted - version: "2.1.5" + version: "2.1.6" path_provider_android: dependency: transitive description: @@ -553,10 +553,10 @@ packages: dependency: transitive description: name: path_provider_platform_interface - sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" + sha256: "484838772624c3a4b94f1e44a3e19897fee738f2d5c4ce448443b0417f7c9dda" url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" path_provider_windows: dependency: transitive description: diff --git a/client/pubspec.yaml b/client/pubspec.yaml index 71c01cc..4f66528 100644 --- a/client/pubspec.yaml +++ b/client/pubspec.yaml @@ -1,7 +1,7 @@ name: jiu_client description: 酒库管理系统 - 酒店仓库管理 publish_to: 'none' -version: 1.0.3+1 +version: 1.0.52+1 environment: sdk: '>=3.0.0 <4.0.0'