diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 3b028ad..cd6690a 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -3717,6 +3717,20 @@ int hg_scanner::get_setting(const char* name, char* json_txt_buf, int* len, int* } else { + // language can be set outer: + if (real_n == SANE_STD_OPT_NAME_LANGUAGE && setting_jsn_.contains(SANE_STD_OPT_NAME_LANGUAGE)) + { + LANATTR** lang = lang_get_supported_languages(); + for (int i = 0; lang[i]; ++i) + { + if (lang[i]->cp == lang_get_cur_code_page()) + { + setting_jsn_.at(SANE_STD_OPT_NAME_LANGUAGE).at("cur") = lang[i]->id; + break; + } + } + } + //json_name.find(real_n) //auto it = json_name.find(real_n); //if (it != json_name.end()) diff --git a/hgdriver/wrapper/huagaoxxx_warraper_ex.cpp b/hgdriver/wrapper/huagaoxxx_warraper_ex.cpp index a1dd839..b52bbb0 100644 --- a/hgdriver/wrapper/huagaoxxx_warraper_ex.cpp +++ b/hgdriver/wrapper/huagaoxxx_warraper_ex.cpp @@ -99,17 +99,24 @@ extern "C" VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "Module sane : [%s] - %s\n", g_sane_ver.c_str(), sane.c_str()); VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Module exe : %s\n", (pe + path + name).c_str()); - if (lang_initialize() == -1) - { - VLOG_MINI_1(LOG_LEVEL_FATAL, "No language package found(%d)!\n", -1); - return SCANNER_ERR_LANG_PAK_LOST; - } - register_language_changed_notify(language_changed, true); hg_scanner_mgr::set_version(VERSION_MAJOR, VERSION_MINOR, VERSION_YEAR, GET_BUILD_VER); hg_scanner_mgr::set_exe_name(pe.c_str(), name.c_str()); hg_scanner_mgr::instance(callback); + register_language_changed_notify(language_changed, true); + std::string lang(hg_log::ini_get("language", "code-page")); + if (lang.empty() && STRICMP(name.c_str(), "qtsane") == 0) + { + lang = "20127"; // qtsane can not support chinese !!! we change language to English :( + hg_log::log(LOG_LEVEL_DEBUG_INFO, "Change the default language to English while qtsane does not support Chinese!\n"); + } + if (!lang.empty()) + { + lang_set_code_page(atoi(lang.c_str())); + VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "Found the language specified by user: %s, code-page after set = %d\n", lang.c_str(), lang_get_cur_code_page()); + } + return SCANNER_ERR_OK; } void hg_scanner_uninitialize(void) diff --git a/hgsane/sane_hg_mdw.cpp b/hgsane/sane_hg_mdw.cpp index 4037353..5852da9 100644 --- a/hgsane/sane_hg_mdw.cpp +++ b/hgsane/sane_hg_mdw.cpp @@ -518,11 +518,6 @@ const SANE_Device** hg_sane_middleware::dev_list_ = NULL; hg_sane_middleware::hg_sane_middleware(void) : opt_0_(nullptr), init_ok_(false) { - if (lang_initialize() == -1) - { - return; - } - char sane_ver[40] = { 0 }; init_ok_ = true; @@ -530,11 +525,8 @@ hg_sane_middleware::hg_sane_middleware(void) : opt_0_(nullptr), init_ok_(false) sprintf(sane_ver, "%u.%u.%u", SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, VERSION_BUILD); signal(SIGUSR1, &hg_sane_middleware::device_pnp); hg_scanner_set_sane_info(g_sane_name.c_str(), sane_ver); - hg_scanner_initialize(local_utility::ui_cb, NULL); - - if (lang_get_cur_code_page() != DEFAULT_CODE_PAGE) - lang_refresh_language(); - register_language_changed_notify(&hg_sane_middleware::language_changed, true); + hg_scanner_initialize(local_utility::ui_cb, NULL); + register_language_changed_notify(&hg_sane_middleware::language_changed, true); #if !defined(WIN32) && !defined(_WIN64) char path[512] = { 0 }; @@ -1016,6 +1008,7 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st std::vector constraints; double lower = .0f, upper = .0f, step = .0f; bool db_val = false; + int opt_val_size = 0; if (!jsn->get_value("type", val)) return NULL; @@ -1031,27 +1024,15 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st { if (range->first_child(val)) { - size_t pos = val.find("."); - if (pos != std::string::npos) - { - for (size_t i = val.length() - 1; i > pos; --i) - { - if (val[i] != '0') - { - pos = i + 1; - break; - } - } - val.erase(pos); - } - if (std::to_string(atoi(val.c_str())) == val) - constraints.push_back(lang_load_string(atoi(val.c_str()), (int*)&lower)); - else - constraints.push_back(val); + local_utility::trans_language_if_was_word_id(val); + constraints.push_back(val); + opt_val_size = val.length(); while (range->next_child(val)) { local_utility::trans_language_if_was_word_id(val); constraints.push_back(val); + if (opt_val_size < val.length()) + opt_val_size = val.length(); } } delete range; @@ -1157,6 +1138,12 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st bool bv = false; jsn->get_value("size", bytes); + if (bytes < opt_val_size) + { + opt_val_size = ALIGN_INT(opt_val_size + 4); + VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "Resize size of '%s' from %d to %d\n", name.c_str(), bytes, opt_val_size); + bytes = opt_val_size; + } ret->size = bytes; if (jsn->get_value("readonly", bv) && bv)