Browse Source

fixed Chinese support

pull/3/head
Khoren Markosyan 2 years ago
parent
commit
dbacf19363
  1. 2
      example/pubspec.lock
  2. 23
      ios/Classes/src/native_zxing.cpp
  3. 8
      lib/flutter_zxing.dart
  4. 50
      lib/generated_bindings.dart
  5. 2
      lib/reader_widget.dart
  6. 4
      zxscanner/pubspec.lock
  7. 2
      zxscanner/pubspec.yaml

2
example/pubspec.lock

@ -141,7 +141,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.0"
version: "0.3.0"
font_awesome_flutter:
dependency: "direct main"
description:

23
ios/Classes/src/native_zxing.cpp

@ -24,7 +24,7 @@ extern "C"
auto *data = new uint8_t[length];
memcpy(data, bytes, length);
BarcodeFormats formats = BarcodeFormat(format); // BarcodeFormat::Any;
BarcodeFormats formats = BarcodeFormat(format);
DecodeHints hints = DecodeHints().setTryHarder(false).setTryRotate(true).setFormats(formats);
ImageView image{data, width, height, ImageFormat::Lum};
if (cropWidth > 0 && cropHeight > 0 && cropWidth < width && cropHeight < height)
@ -37,10 +37,13 @@ extern "C"
if (result.isValid())
{
code.isValid = result.isValid();
code.text = new char[result.text().length() + 1];
std::string text = std::string(result.text().begin(), result.text().end());
strcpy(code.text, text.c_str());
code.format = Format(static_cast<int>(result.format()));
const wchar_t *resultText = result.text().c_str();
size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t);
code.text = new char[size];
std::wcstombs(code.text, resultText, size);
}
int evalInMillis = static_cast<int>(get_now() - start);
@ -60,7 +63,7 @@ extern "C"
auto *data = new uint8_t[length];
memcpy(data, bytes, length);
BarcodeFormats formats = BarcodeFormat(format); // BarcodeFormat::Any;
BarcodeFormats formats = BarcodeFormat(format);
DecodeHints hints = DecodeHints().setTryHarder(false).setTryRotate(true).setFormats(formats);
ImageView image{data, width, height, ImageFormat::Lum};
if (cropWidth > 0 && cropHeight > 0 && cropWidth < width && cropHeight < height)
@ -77,10 +80,14 @@ extern "C"
if (result.isValid())
{
code.isValid = result.isValid();
code.text = new char[result.text().length() + 1];
std::string text = std::string(result.text().begin(), result.text().end());
strcpy(code.text, text.c_str());
code.format = Format(static_cast<int>(result.format()));
const wchar_t *resultText = result.text().c_str();
size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t);
code.text = new char[size];
std::wcstombs(code.text, resultText, size);
codes[i] = code;
i++;
}

8
lib/flutter_zxing.dart

@ -124,7 +124,7 @@ class FlutterZxing {
static EncodeResult encodeBarcode(String contents, int width, int height,
int format, int margin, int eccLevel) {
var result = bindings.encodeBarcode(contents.toNativeUtf8().cast<Int8>(),
var result = bindings.encodeBarcode(contents.toNativeUtf8().cast<Char>(),
width, height, format, margin, eccLevel, _logEnabled);
return result;
}
@ -166,11 +166,11 @@ DynamicLibrary dylib = _openDynamicLibrary();
extension Uint8ListBlobConversion on Uint8List {
/// Allocates a pointer filled with the Uint8List data.
Pointer<Int8> allocatePointer() {
Pointer<Char> allocatePointer() {
final blob = calloc<Int8>(length);
final blobBytes = blob.asTypedList(length);
blobBytes.setAll(0, this);
return blob;
return blob.cast<Char>();
}
}
@ -186,7 +186,7 @@ extension EncodeExt on EncodeResult {
String? get textString =>
text == nullptr ? null : text.cast<Utf8>().toDartString();
String get formatString => FlutterZxing.formatName(format);
Uint32List get bytes => data.asTypedList(length);
Uint32List get bytes => data.cast<Uint32>().asTypedList(length);
String get errorMessage => error.cast<Utf8>().toDartString();
}

50
lib/generated_bindings.dart

@ -22,14 +22,14 @@ class GeneratedBindings {
/// Returns the version of the zxing-cpp library.
///
/// @return The version of the zxing-cpp library.
ffi.Pointer<ffi.Int8> version() {
ffi.Pointer<ffi.Char> version() {
return _version();
}
late final _versionPtr =
_lookup<ffi.NativeFunction<ffi.Pointer<ffi.Int8> Function()>>('version');
_lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function()>>('version');
late final _version =
_versionPtr.asFunction<ffi.Pointer<ffi.Int8> Function()>();
_versionPtr.asFunction<ffi.Pointer<ffi.Char> Function()>();
/// @brief Reads barcode from image.
/// @param bytes Image bytes.
@ -41,7 +41,7 @@ class GeneratedBindings {
/// @param logEnabled Log enabled.
/// @return Barcode result.
CodeResult readBarcode(
ffi.Pointer<ffi.Int8> bytes,
ffi.Pointer<ffi.Char> bytes,
int format,
int width,
int height,
@ -62,11 +62,11 @@ class GeneratedBindings {
late final _readBarcodePtr = _lookup<
ffi.NativeFunction<
CodeResult Function(ffi.Pointer<ffi.Int8>, ffi.Int32, ffi.Int32,
ffi.Int32, ffi.Int32, ffi.Int32, ffi.Int32)>>('readBarcode');
CodeResult Function(ffi.Pointer<ffi.Char>, ffi.Int, ffi.Int, ffi.Int,
ffi.Int, ffi.Int, ffi.Int)>>('readBarcode');
late final _readBarcode = _readBarcodePtr.asFunction<
CodeResult Function(
ffi.Pointer<ffi.Int8>, int, int, int, int, int, int)>();
ffi.Pointer<ffi.Char>, int, int, int, int, int, int)>();
/// @brief Reads barcodes from image.
/// @param bytes Image bytes.
@ -78,7 +78,7 @@ class GeneratedBindings {
/// @param logEnabled Log enabled.
/// @return Barcode results.
ffi.Pointer<CodeResult> readBarcodes(
ffi.Pointer<ffi.Int8> bytes,
ffi.Pointer<ffi.Char> bytes,
int format,
int width,
int height,
@ -99,17 +99,11 @@ class GeneratedBindings {
late final _readBarcodesPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CodeResult> Function(
ffi.Pointer<ffi.Int8>,
ffi.Int32,
ffi.Int32,
ffi.Int32,
ffi.Int32,
ffi.Int32,
ffi.Int32)>>('readBarcodes');
ffi.Pointer<CodeResult> Function(ffi.Pointer<ffi.Char>, ffi.Int,
ffi.Int, ffi.Int, ffi.Int, ffi.Int, ffi.Int)>>('readBarcodes');
late final _readBarcodes = _readBarcodesPtr.asFunction<
ffi.Pointer<CodeResult> Function(
ffi.Pointer<ffi.Int8>, int, int, int, int, int, int)>();
ffi.Pointer<ffi.Char>, int, int, int, int, int, int)>();
/// @brief Encode a string into a barcode
/// @param contents The string to encode
@ -121,7 +115,7 @@ class GeneratedBindings {
/// @param eccLevel The error correction level of the barcode. Used for Aztec, PDF417, and QRCode only, [0-8].
/// @return The barcode data
EncodeResult encodeBarcode(
ffi.Pointer<ffi.Int8> contents,
ffi.Pointer<ffi.Char> contents,
int width,
int height,
int format,
@ -142,11 +136,11 @@ class GeneratedBindings {
late final _encodeBarcodePtr = _lookup<
ffi.NativeFunction<
EncodeResult Function(ffi.Pointer<ffi.Int8>, ffi.Int32, ffi.Int32,
ffi.Int32, ffi.Int32, ffi.Int32, ffi.Int32)>>('encodeBarcode');
EncodeResult Function(ffi.Pointer<ffi.Char>, ffi.Int, ffi.Int,
ffi.Int, ffi.Int, ffi.Int, ffi.Int)>>('encodeBarcode');
late final _encodeBarcode = _encodeBarcodePtr.asFunction<
EncodeResult Function(
ffi.Pointer<ffi.Int8>, int, int, int, int, int, int)>();
ffi.Pointer<ffi.Char>, int, int, int, int, int, int)>();
}
abstract class Format {
@ -206,28 +200,28 @@ abstract class Format {
}
class CodeResult extends ffi.Struct {
@ffi.Int32()
@ffi.Int()
external int isValid;
external ffi.Pointer<ffi.Int8> text;
external ffi.Pointer<ffi.Char> text;
@ffi.Int32()
external int format;
}
class EncodeResult extends ffi.Struct {
@ffi.Int32()
@ffi.Int()
external int isValid;
external ffi.Pointer<ffi.Int8> text;
external ffi.Pointer<ffi.Char> text;
@ffi.Int32()
external int format;
external ffi.Pointer<ffi.Uint32> data;
external ffi.Pointer<ffi.UnsignedInt> data;
@ffi.Int32()
@ffi.Int()
external int length;
external ffi.Pointer<ffi.Int8> error;
external ffi.Pointer<ffi.Char> error;
}

2
lib/reader_widget.dart

@ -89,6 +89,8 @@ class _ReaderWidgetState extends State<ReaderWidget>
}
if (mounted) {
if (message == AppLifecycleState.paused.toString()) {
await cameraController.stopImageStream();
await cameraController.dispose();
_cameraOn = false;
setState(() {});
}

4
zxscanner/pubspec.lock

@ -300,7 +300,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.0"
version: "0.3.0"
font_awesome_flutter:
dependency: "direct main"
description:
@ -524,7 +524,7 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.10"
version: "2.0.11"
path_provider_android:
dependency: transitive
description:

2
zxscanner/pubspec.yaml

@ -26,7 +26,7 @@ dependencies:
image_picker: ^0.8.5
intl: ^0.17.0
mobx: ^2.0.7
path_provider: ^2.0.10
path_provider: ^2.0.11
share_plus: ^4.0.7
shared_preferences: ^2.0.15
url_launcher: ^6.1.2

Loading…
Cancel
Save