From a4e5af59be881cc1f695c095f7b2e5dceffb79fc Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Wed, 29 Nov 2023 11:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4AutoMaticBorderDetection?= =?UTF-8?q?=E4=B8=8ESupportedSizes=E5=8D=8F=E8=AE=AE=EF=BC=9A=E5=B0=86?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=8E=9F=E5=A7=8B=E5=B0=BA=E5=AF=B8=E7=9C=8B?= =?UTF-8?q?=E4=BD=9C=E7=8B=AC=E7=AB=8B=E5=8D=8F=E8=AE=AE=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?TWAIN=E5=8D=8F=E8=AE=AE=E5=B1=82=E5=AE=9E=E7=8E=B0=E4=B8=8E?= =?UTF-8?q?=E7=BA=B8=E5=BC=A0=E5=B0=BA=E5=AF=B8=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twain/twain/huagaods.cpp | 68 ++++++++++++++++++++++++++++++++++------ twain/twain/huagaods.hpp | 4 +++ 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/twain/twain/huagaods.cpp b/twain/twain/huagaods.cpp index 6c2ed67..579b502 100644 --- a/twain/twain/huagaods.cpp +++ b/twain/twain/huagaods.cpp @@ -2132,14 +2132,27 @@ void huagao_ds::init_support_caps(void) init = 0; std::vector all; GET_SANE_OPT_EX(int, scanner_, ex_paper, NULL, &all); - now = all[sane_opts::RANGE_POS_CURRENT]; + now = user_auto_paper_size_ ? user_paper_size_ : all[sane_opts::RANGE_POS_CURRENT]; init = all[sane_opts::RANGE_POS_DEFAULT]; + if (user_paper_size_ == -1) + user_paper_size_ = init; + if (msg == Msg::Set || msg == Msg::Reset) { if(msg == Msg::Set) init = (int)data.currentItem(); else data = Capability::createOneValue((Twpp::PaperSize)init); + user_paper_size_ = init; + + if (user_auto_paper_size_) + { + wchar_t info[128] = { 0 }; + swprintf_s(info, _countof(info) - 1, L"user set paper size to %d, but auto-paper-size is on and ignore this oper.\r\n", user_paper_size_); + load_sane_util::log_info(info, 1); + + return success(); + } SET_SANE_OPT_EX(now, scanner_, ex_paper, &init); return now == SCANNER_ERR_OK ? success() : badValue(); @@ -2583,12 +2596,29 @@ void huagao_ds::init_support_caps(void) auto autosize = data.currentItem(); bool match = autosize == AutoSize::Auto; int ret = SCANNER_ERR_OK; - SET_SANE_OPT_EX(ret, scanner_, ex_auto_paper_size, &match); + user_auto_paper_size_ = match; + if (user_auto_paper_size_) + { + SET_SANE_OPT_EX(ret, scanner_, ex_auto_paper_size, &match); + } + else + { + // restore to user_paper_size_ ... + { + wchar_t info[128] = { 0 }; + swprintf_s(info, _countof(info) - 1, L"disable auto paper size and restore paper to %d\r\n", user_paper_size_); + load_sane_util::log_info(info, 1); + } + int err = 0, + val = user_paper_size_; + SET_SANE_OPT_EX(err, scanner_, ex_paper, &val); + } + return ret == SCANNER_ERR_OK ? success() : badValue(); } - std::vector all; - GET_SANE_OPT_EX(bool, scanner_, ex_auto_paper_size, NULL, &all); - UInt16 size = all[sane_opts::RANGE_POS_CURRENT] ? (UInt16)AutoSize::Auto : (UInt16)AutoSize::None; + //std::vector all; + //GET_SANE_OPT_EX(bool, scanner_, ex_auto_paper_size, NULL, &all); + UInt16 size = /*all[sane_opts::RANGE_POS_CURRENT]*/user_auto_paper_size_ ? (UInt16)AutoSize::Auto : (UInt16)AutoSize::None; return CapSupGetAllReset(msg, data, { AutoSize::None, AutoSize::Auto }, size, AutoSize::None, (size == (UInt16)AutoSize::Auto) ? 1 : 0, 0); }; @@ -2598,15 +2628,33 @@ void huagao_ds::init_support_caps(void) if (Msg::Set == msg) { auto autodetectborder = data.currentItem(); int ret = SCANNER_ERR_OK; - SET_SANE_OPT_EX(ret, scanner_, ex_auto_paper_size, (bool*)&autodetectborder); + + user_auto_paper_size_ = (bool)autodetectborder; + if (user_auto_paper_size_) + { + SET_SANE_OPT_EX(ret, scanner_, ex_auto_paper_size, (bool*)&autodetectborder); + } + else + { + // restore to user_paper_size_ ... + { + wchar_t info[128] = { 0 }; + swprintf_s(info, _countof(info) - 1, L"disable auto paper size and restore paper to %d\r\n", user_paper_size_); + load_sane_util::log_info(info, 1); + } + int err = 0, + val = user_paper_size_; + SET_SANE_OPT_EX(err, scanner_, ex_paper, &val); + } + return ret == SCANNER_ERR_OK ? success() : badValue(); } Bool init = false, erase = false; - std::vector all; - GET_SANE_OPT_EX(bool, scanner_, ex_auto_paper_size, NULL, &all); - init = (bool)all[sane_opts::RANGE_POS_DEFAULT]; - erase = (bool)all[sane_opts::RANGE_POS_CURRENT]; + //std::vector all; + //GET_SANE_OPT_EX(bool, scanner_, ex_auto_paper_size, NULL, &all); + init = true; // (bool)all[sane_opts::RANGE_POS_DEFAULT]; + erase = user_auto_paper_size_; // (bool)all[sane_opts::RANGE_POS_CURRENT]; return CapSupGetAllReset(msg, data, { false,true }, erase, init, erase ? 1 : 0, 0); }; diff --git a/twain/twain/huagaods.hpp b/twain/twain/huagaods.hpp index 3bae343..2c5f732 100644 --- a/twain/twain/huagaods.hpp +++ b/twain/twain/huagaods.hpp @@ -59,6 +59,10 @@ class huagao_ds : public Twpp::SourceFromThis { bool no_bitdepth_ = false; // 军队扫描2.0.exe set this but sychronize to APP int count_; + // 匹配原始尺寸(IAutomaticBorderDetection) & 纸张尺寸(ISupportedSizes) + int user_paper_size_ = -1; + bool user_auto_paper_size_ = false; + volatile bool notfify_close_ = false; enum {NOTIFY_AUTO = 0, NOTIFY_ALWAYS, NOTIFY_NONE}; volatile unsigned notify_close_ = 0; // 0 - auto; 1 - notify always; 2 - no notify