diff --git a/pc/code_twain/sln/hgjson/DlgOptJson.cpp b/pc/code_twain/sln/hgjson/DlgOptJson.cpp index 0af4ae8..fe59983 100644 --- a/pc/code_twain/sln/hgjson/DlgOptJson.cpp +++ b/pc/code_twain/sln/hgjson/DlgOptJson.cpp @@ -19,7 +19,7 @@ namespace known_name std::wstring name; std::wstring title; } - g_group[] = { {L"base", L"\u57FA\u672C\u8BBE\u7F6E"}, {L"imgp", L"\u56FE\u50CF\u5904\u7406"}, {L"feeder", L"\u9001\u7EB8\u65B9\u5F0F"}, {L"adv", L"\u9AD8\u7EA7\u8BBE\u7F6E"}}, + g_group[] = { {L"base", L"\u57FA\u672C\u8BBE\u7F6E"}, {L"imgp", L"\u56FE\u50CF\u5904\u7406"}, {L"feeder", L"\u9001\u7EB8\u65B9\u5F0F"}, {L"advance", L"\u9AD8\u7EA7\u8BBE\u7F6E"}}, g_cats[] = { {L"imgp", L"\u56FE\u50CF\u5904\u7406"}}; static std::wstring group_name(const wchar_t* grp_title) diff --git a/pc/code_twain/sln/usb_tools/Debug/hgjson.exe b/pc/code_twain/sln/usb_tools/Debug/hgjson.exe index d3d0731..b7d3753 100644 Binary files a/pc/code_twain/sln/usb_tools/Debug/hgjson.exe and b/pc/code_twain/sln/usb_tools/Debug/hgjson.exe differ diff --git a/pc/code_twain/sln/usb_tools/Debug/usb_tools.exe b/pc/code_twain/sln/usb_tools/Debug/usb_tools.exe index 466f705..81a11a6 100644 Binary files a/pc/code_twain/sln/usb_tools/Debug/usb_tools.exe and b/pc/code_twain/sln/usb_tools/Debug/usb_tools.exe differ diff --git a/pc/code_twain/sln/usb_tools/DlgScanner.cpp b/pc/code_twain/sln/usb_tools/DlgScanner.cpp index 63252d1..ee6fcb2 100644 --- a/pc/code_twain/sln/usb_tools/DlgScanner.cpp +++ b/pc/code_twain/sln/usb_tools/DlgScanner.cpp @@ -406,22 +406,31 @@ namespace sane else if (jsn->get_value("hwonly", bv) && bv) SET_CAP_DEVICE_SETTABLE(ret->cap, true) - val = ""; - jsn->get_value("category", val); - if (val == "advanced") + val = ""; + jsn->get_value("group", val); + if (val == "advance") { ret->cap |= SANE_CAP_ADVANCED; } - if (strcmp(ret->name, SANE_STD_OPT_NAME_RESOLUTION) == 0) + val = ""; + if (jsn->get_value("unit", val)) { - ret->unit = SANE_UNIT_DPI; + if (val == "DPI") + ret->unit = SANE_UNIT_DPI; + else if (val == "pixel") + ret->unit = SANE_UNIT_PIXEL; + else if (val == "mm") + ret->unit = SANE_UNIT_MM; + else if (val == "bit") + ret->unit = SANE_UNIT_BIT; + else if (val == "microsec") + ret->unit = SANE_UNIT_MICROSECOND; + else if (val == "%") + ret->unit = SANE_UNIT_PERCENT; + else + ret->unit = SANE_UNIT_NONE; } - else if (strcmp(ret->name, SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT) == 0 || - strcmp(ret->name, SANE_STD_OPT_NAME_CUSTOM_AREA_RIGHT) == 0 || - strcmp(ret->name, SANE_STD_OPT_NAME_CUSTOM_AREA_TOP) == 0 || - strcmp(ret->name, SANE_STD_OPT_NAME_CUSTOM_AREA_BOTTOM) == 0) - ret->unit = SANE_UNIT_MM; bool enabled = true; if (jsn->get_value("enabled", enabled) && !enabled) @@ -527,7 +536,7 @@ namespace sane val_size = strlen((char*)value); SANE_Int after = 0; - SANE_Status ret = (SANE_Status)dlg->set_option(g_opts[option - 1]->name, value, g_opts[option - 1]->type, val_size, g_opts[option - 1]->size, (int*)&after); + SANE_Status ret = (SANE_Status)dlg->set_option(g_opts[option - 1]->name, buf, g_opts[option - 1]->type, val_size, g_opts[option - 1]->size, (int*)&after); if (info) *info = after; @@ -652,7 +661,7 @@ IMPLEMENT_DYNAMIC(CDlgScanner, CDialogEx) CDlgScanner::CDlgScanner(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_SCANNER, pParent) , scanner_(NULL), auto_tx_file_(-1), auto_tx_(false) - , setting_ui_(NULL), img_cnt_(0), paper_cnt_(0) + , setting_ui_(NULL), img_cnt_(0), paper_cnt_(0), max_sent_(0), max_cmd_(0) { g_my_inst = GetModuleHandle(NULL); @@ -794,6 +803,7 @@ void CDlgScanner::set_device(usb::LPUSBPNP pnp) ::PostMessage(m_hWnd, WM_DEVICE_STATTUS, 0, (LPARAM)status); }; + max_cmd_ = max_sent_ = 0; if (pnp) { int err = 0; @@ -895,7 +905,6 @@ int CDlgScanner::refresh_bulk_status(void) EP0REPLYSTATUS s = { 0 }; wchar_t buf[128] = { 0 }; int err = scanner_->get_scanner_status(&s); - static uint32_t max_sent = 0, max_cmd = 0; if (err == 0) { @@ -912,15 +921,15 @@ int CDlgScanner::refresh_bulk_status(void) SetDlgItemTextW(IDC_EDIT_BULK_OUT, buf); } - if (max_sent < s.packets_to_sent) - max_sent = s.packets_to_sent; - if (max_cmd < s.task_cnt) - max_cmd = s.task_cnt; + if (max_sent_ < s.packets_to_sent) + max_sent_ = s.packets_to_sent; + if (max_cmd_ < s.task_cnt) + max_cmd_ = s.task_cnt; - swprintf_s(buf, _countof(buf) - 1, L"%u (max: %u)", s.packets_to_sent, max_sent); + swprintf_s(buf, _countof(buf) - 1, L"%u (max: %u)", s.packets_to_sent, max_sent_); SetDlgItemTextW(IDC_EDIT_SENT_QUE, buf); - swprintf_s(buf, _countof(buf) - 1, L"%u (max: %u)", s.task_cnt, max_cmd); + swprintf_s(buf, _countof(buf) - 1, L"%u (max: %u)", s.task_cnt, max_cmd_); SetDlgItemTextW(IDC_EDIT_CMD_QUE, buf); } diff --git a/pc/code_twain/sln/usb_tools/DlgScanner.h b/pc/code_twain/sln/usb_tools/DlgScanner.h index e3d0e43..0bacd1c 100644 --- a/pc/code_twain/sln/usb_tools/DlgScanner.h +++ b/pc/code_twain/sln/usb_tools/DlgScanner.h @@ -60,6 +60,8 @@ class CDlgScanner : public CDialogEx std::wstring img_root_; uint32_t img_cnt_; uint32_t paper_cnt_; + uint32_t max_sent_; + uint32_t max_cmd_; public: CDlgScanner(CWnd* pParent = nullptr); // 标准构造函数 diff --git a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgArea.cpp b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgArea.cpp index 55e841a..1025a6d 100644 --- a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgArea.cpp +++ b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgArea.cpp @@ -718,30 +718,30 @@ void dlg_area::on_lbutton_up(int x, int y) } -void dlg_area::set_paper(const wchar_t* name, float width_mm, float height_mm, float dpi) +void dlg_area::set_paper(const wchar_t* name, int width_px, int height_px, float dpi) { wchar_t paper[40] = { 0 }; dpi_ = dpi; paper_ = name; - paper_w_0_ = width_mm; - paper_h_0_ = height_mm; + paper_w_0_ = dlg_area::pixel_2_mm(width_px, dpi); + paper_h_0_ = dlg_area::pixel_2_mm(height_px, dpi); if (unit_ == PAPER_UNIT_INCH) { - paper_w_ = dlg_area::mm_2_inches(width_mm); - paper_h_ = dlg_area::mm_2_inches(height_mm); + paper_w_ = dlg_area::pixel_2_inches(width_px, dpi); + paper_h_ = dlg_area::pixel_2_inches(height_px, dpi); } - else if (unit_ == PAPER_UNIT_PIXEL) + else if (unit_ == PAPER_UNIT_MM) { - paper_w_ = dlg_area::mm_2_pixel(width_mm, dpi_); - paper_h_ = dlg_area::mm_2_pixel(height_mm, dpi_); + paper_w_ = paper_w_0_; + paper_h_ = paper_h_0_; } else { - paper_w_ = width_mm; - paper_h_ = height_mm; + paper_w_ = width_px; + paper_h_ = height_px; } RECT r = { 0 }; diff --git a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgArea.h b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgArea.h index 1067cad..17562c3 100644 --- a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgArea.h +++ b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgArea.h @@ -89,7 +89,7 @@ public: static float pixel_2_inches(float px, float dpi); public: - void set_paper(const wchar_t* name, float width_mm, float height_mm, float dpi); + void set_paper(const wchar_t* name, int width_px, int height_px, float dpi); void set_area(float x, float y, float w, float h); float x_in_mm(void); float y_in_mm(void); diff --git a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgPage.cpp b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgPage.cpp index 3ce41b3..2bf47e7 100644 --- a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgPage.cpp +++ b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgPage.cpp @@ -627,7 +627,7 @@ dlg_page::dlg_page(HWND parent, const wchar_t* name , sane_(*api), dev_(dev), done_(false) , id_custom_area_(-1), id_custom_left_(-1), id_custom_right_(-1), id_custom_top_(-1), id_custom_bottom_(-1) , id_custom_gamma_(-1), id_paper_(-1), paper_(L"A4"), id_dpi_(-1), dpi_(200), vsb_pos_(0), hsb_pos_(0) - , vsb_(false), hsb_(false) + , vsb_(false), hsb_(false), id_paper_w_(-1), id_paper_h_(-1), id_lateral_(-1) { size_.cx = size_.cy = 0; pos_.x = 12; @@ -1084,35 +1084,47 @@ void dlg_page::handle_command(WORD code, WORD id, HANDLE ctrl) unsigned int size = 0; std::string utf8(local_trans::u2a(paper_.c_str(), CP_UTF8)); dlg_area dlg(parent_); - float x = .0f, y = .0f, w = .0f, h = .0f; + double x = .0f, y = .0f; + int w = 0, h = 0, n = 0; SANE_Fixed sf; + bool lateral = false; - sane_.sane_io_control_api(dev_, IO_CTRL_CODE_GET_PAPER_SIZE, &utf8[0], &size); - dlg.set_paper(paper_.c_str(), (float)(size & 0x0ffff), float(size >> 16), dpi_); - sane_.sane_control_option_api(dev_, id_custom_left_, SANE_ACTION_GET_VALUE, &sf, NULL); - x = (float)SANE_UNFIX(sf); - sane_.sane_control_option_api(dev_, id_custom_top_, SANE_ACTION_GET_VALUE, &sf, NULL); - y = (float)SANE_UNFIX(sf); - sane_.sane_control_option_api(dev_, id_custom_right_, SANE_ACTION_GET_VALUE, &sf, NULL); - w = (float)SANE_UNFIX(sf) - x; - sane_.sane_control_option_api(dev_, id_custom_bottom_, SANE_ACTION_GET_VALUE, &sf, NULL); - h = (float)SANE_UNFIX(sf) - y; + // FIXED me here ... + // all the size options, has it's unit, we should convert them to pixel according their units here ... + // now we consinder them all be pixels ... + sane_.sane_control_option_api(dev_, id_paper_w_, SANE_ACTION_GET_VALUE, &w, NULL); + sane_.sane_control_option_api(dev_, id_paper_h_, SANE_ACTION_GET_VALUE, &h, NULL); + sane_.sane_control_option_api(dev_, id_lateral_, SANE_ACTION_GET_VALUE, &lateral, NULL); + if (lateral) + { + const SANE_Option_Descriptor* desc = sane_.sane_get_option_descriptor_api(dev_, id_lateral_); + lateral &= SANE_OPTION_IS_ACTIVE(desc->cap); + } + dlg.set_paper(lateral ? (paper_ + L"\u6A2A\u5411").c_str() : paper_.c_str(), w, h, dpi_); + sane_.sane_control_option_api(dev_, id_custom_left_, SANE_ACTION_GET_VALUE, &n, NULL); + x = dlg_area::pixel_2_mm(n, dpi_); + sane_.sane_control_option_api(dev_, id_custom_top_, SANE_ACTION_GET_VALUE, &n, NULL); + y = dlg_area::pixel_2_mm(n, dpi_); + sane_.sane_control_option_api(dev_, id_custom_right_, SANE_ACTION_GET_VALUE, &n, NULL); + w = dlg_area::pixel_2_mm(n, dpi_); + sane_.sane_control_option_api(dev_, id_custom_bottom_, SANE_ACTION_GET_VALUE, &n, NULL); + h = dlg_area::pixel_2_mm(n, dpi_); dlg.set_area(x, y, w, h); if (dlg.do_modal(parent_) == IDOK) { - SANE_Fixed val = SANE_FIX(dlg.x_in_mm()); + SANE_Int val = dlg_area::mm_2_pixel(dlg.x_in_mm(), dpi_); SANE_Int after = 0; bool created = true; sane_.sane_control_option_api(dev_, id_custom_left_, SANE_ACTION_SET_VALUE, &val, &after); - val = SANE_FIX(dlg.y_in_mm()); + val = dlg_area::mm_2_pixel(dlg.y_in_mm(), dpi_); sane_.sane_control_option_api(dev_, id_custom_top_, SANE_ACTION_SET_VALUE, &val, &after); - val = SANE_FIX(dlg.x_in_mm() + dlg.w_in_mm()); + val = dlg_area::mm_2_pixel(dlg.x_in_mm() + dlg.w_in_mm(), dpi_); sane_.sane_control_option_api(dev_, id_custom_right_, SANE_ACTION_SET_VALUE, &val, &after); - val = SANE_FIX(dlg.y_in_mm() + dlg.h_in_mm()); + val = dlg_area::mm_2_pixel(dlg.y_in_mm() + dlg.h_in_mm(), dpi_); sane_.sane_control_option_api(dev_, id_custom_bottom_, SANE_ACTION_SET_VALUE, &val, &after); } return; @@ -1541,6 +1553,13 @@ bool dlg_page::add_control(int sn, const SANE_Option_Descriptor* desc, void* cur id_custom_right_ = sn; else { + if (strcmp(desc->name, "paper-w") == 0) + id_paper_w_ = sn; + else if (strcmp(desc->name, "paper-h") == 0) + id_paper_h_ = sn; + else if (strcmp(desc->name, "lateral") == 0) + id_lateral_ = sn; + for (int i = 0; i < _countof(creat); ++i) { if (creat[i].sane_type == desc->type) @@ -1692,7 +1711,7 @@ const wchar_t* dlg_page::name(void) void dlg_page::set_view_size(SIZE size) { int h = size.cy; - vsb_ = h < desired_size().cy; + vsb_ = h < desired_size().cy + dlg_page::sb_adden; if (!vsb_) { show_scroll_bar(SB_VERT, false); @@ -1705,7 +1724,7 @@ void dlg_page::set_view_size(SIZE size) } int w = size.cx; - hsb_ = w < desired_size().cx; + hsb_ = w < desired_size().cx + dlg_page::sb_adden; if (!hsb_) { show_scroll_bar(SB_HORZ, false); diff --git a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgPage.h b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgPage.h index 074e002..b5ad231 100644 --- a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgPage.h +++ b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgPage.h @@ -173,6 +173,9 @@ class dlg_page : public dlg_base int id_custom_right_; int id_custom_top_; int id_custom_bottom_; + int id_paper_w_; + int id_paper_h_; + int id_lateral_; int id_custom_gamma_; static std::wstring property_type; diff --git a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgSetting.cpp b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgSetting.cpp index 688d0a2..62bc7a7 100644 --- a/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgSetting.cpp +++ b/pc/code_twain/sln/usb_tools/scanner/opt_ui/DlgSetting.cpp @@ -69,6 +69,64 @@ namespace local_trans return from_hz ? from_default_language(in, nullptr) : to_default_language(in, nullptr); } } +namespace known_name +{ + struct + { + std::wstring name; + std::wstring title; + } + g_group[] = { {L"base", L"\u57FA\u672C\u8BBE\u7F6E"}, {L"imgp", L"\u56FE\u50CF\u5904\u7406"}, {L"feeder", L"\u9001\u7EB8\u65B9\u5F0F"}, {L"advance", L"\u9AD8\u7EA7\u8BBE\u7F6E"} }, + g_cats[] = { {L"imgp", L"\u56FE\u50CF\u5904\u7406"} }; + + static std::wstring group_name(const wchar_t* grp_title) + { + for (auto& v : g_group) + { + if (v.title == grp_title) + return v.name; + } + + return grp_title; + } + static std::wstring group_title(const wchar_t* grp_name) + { + if (wcscmp(grp_name, L"imgproc") == 0) + grp_name = L"imgp"; + + for (auto& v : g_group) + { + if (v.name == grp_name) + return v.title; + } + + return grp_name; + } + + static std::wstring category_name(const wchar_t* cat_title) + { + for (auto& v : g_cats) + { + if (v.title == cat_title) + return v.name; + } + + return cat_title; + } + static std::wstring category_title(const wchar_t* cat_name) + { + if (wcscmp(cat_name, L"imgproc") == 0) + cat_name = L"imgp"; + + for (auto& v : g_cats) + { + if (v.name == cat_name) + return v.title; + } + + return cat_name; + } +}; dlg_setting::dlg_setting(HWND parent, LPSANEAPI api, SANE_Handle dev, LPRECT area) : dlg_base(parent, IDD_SETTING) , sane_api_(*api), sane_dev_(dev), area_(*area) @@ -299,7 +357,7 @@ int dlg_setting::get_tab_count(void) } dlg_page* dlg_setting::add_tab(const char* utf8_title) { - std::wstring title(local_trans::a2u(utf8_title, CP_UTF8)); + std::wstring title(known_name::group_title(local_trans::a2u(utf8_title, CP_UTF8).c_str())); dlg_page *page = new dlg_page(hwnd(), title.c_str(), &sane_api_, sane_dev_); HFONT font = (HFONT)SendMessage(get_item(IDOK), WM_GETFONT, 0, 0); LOGFONTW lf = { 0 }; diff --git a/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp b/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp index 95073f8..f3548e8 100644 --- a/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp +++ b/pc/code_twain/sln/usb_tools/scanner/scanner_handler.cpp @@ -327,7 +327,6 @@ bool scanner_handler::reorder_device_config_json(std::string& cont, const std::m continue; child = new gb_json(); - child->set_value("category", "base"); child->set_value("type", "group"); child->set_value("title", v.second.c_str()); jsn->set_value(("grp-" + std::to_string(cnt++)).c_str(), child); @@ -345,7 +344,6 @@ bool scanner_handler::reorder_device_config_json(std::string& cont, const std::m for (auto& v : items) { child = new gb_json(); - child->set_value("category", "base"); child->set_value("type", "group"); child->set_value("title", v.name.c_str()); jsn->set_value(("grp-" + std::to_string(cnt++)).c_str(), child);