Browse Source

fixed Chinese support for ios

pull/9/head
Khoren Markosyan 2 years ago
parent
commit
58ebd29725
  1. 10
      ios/Classes/src/common.cpp
  2. 3
      ios/Classes/src/common.h
  3. 47
      ios/Classes/src/native_zxing.cpp
  4. 2
      ios/Classes/src/native_zxing.h

10
ios/Classes/src/common.cpp

@ -5,6 +5,13 @@
using namespace std;
bool isLogEnabled;
void setLoggingEnabled(bool enabled)
{
isLogEnabled = enabled;
}
long long int get_now()
{
return chrono::duration_cast<std::chrono::milliseconds>(
@ -14,6 +21,8 @@ long long int get_now()
void platform_log(const char *fmt, ...)
{
if (isLogEnabled)
{
va_list args;
va_start(args, fmt);
#ifdef __ANDROID__
@ -28,4 +37,5 @@ void platform_log(const char *fmt, ...)
vprintf(fmt, args);
#endif
va_end(args);
}
}

3
ios/Classes/src/common.h

@ -19,7 +19,8 @@
#define FUNCTION_ATTRIBUTE __declspec(dllexport)
#endif
long long int get_now();
void platform_log(const char *fmt, ...);
void setLoggingEnabled(bool enabled);

47
ios/Classes/src/native_zxing.cpp

@ -5,16 +5,18 @@
#include "BitMatrix.h"
#include "native_zxing.h"
#include <locale>
#include <codecvt>
#include <stdarg.h>
using namespace ZXing;
extern "C"
{
bool logEnabled = false;
FUNCTION_ATTRIBUTE
void setLogEnabled(int enabled)
{
logEnabled = enabled;
setLoggingEnabled(enabled);
}
FUNCTION_ATTRIBUTE
@ -48,18 +50,16 @@ extern "C"
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);
platform_log("zxingRead: %ls\n", resultText);
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::string text = converter.to_bytes(result.text());
code.text = new char[text.length() + 1];
strcpy(code.text, text.c_str());
platform_log("Result: %s\n", code.text);
}
int evalInMillis = static_cast<int>(get_now() - start);
if (logEnabled)
{
platform_log("zxingRead: %d ms\n", evalInMillis);
}
platform_log("Read Barcode in: %d ms\n", evalInMillis);
return code;
}
@ -92,22 +92,19 @@ extern "C"
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);
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::string text = converter.to_bytes(result.text());
code.text = new char[text.length() + 1];
strcpy(code.text, text.c_str());
codes[i] = code;
i++;
platform_log("zxingRead: %s\n", code.text);
platform_log("Result: %s\n", code.text);
}
}
int evalInMillis = static_cast<int>(get_now() - start);
if (logEnabled)
{
platform_log("zxingRead: %d ms\n", evalInMillis);
}
platform_log("Read Barcode in: %d ms\n", evalInMillis);
return {i, codes};
}
@ -126,20 +123,14 @@ extern "C"
result.isValid = true;
}
catch (const std::exception &e)
{
if (logEnabled)
{
platform_log("Can't encode text: %s\nError: %s\n", contents, e.what());
}
result.error = new char[strlen(e.what()) + 1];
strcpy(result.error, e.what());
}
int evalInMillis = static_cast<int>(get_now() - start);
if (logEnabled)
{
platform_log("zxingEncode: %d ms\n", evalInMillis);
}
platform_log("Encode Barcode in: %d ms\n", evalInMillis);
return result;
}
}

2
ios/Classes/src/native_zxing.h

@ -38,7 +38,7 @@ extern "C"
struct CodeResults
{
int count;
struct CodeResult* results;
struct CodeResult *results;
};
struct EncodeResult

Loading…
Cancel
Save