调整属性,增加不可见属性纸张宽度和高度

This commit is contained in:
gb 2023-11-04 17:41:26 +08:00
parent 7bb5390417
commit 9007ae0c28
7 changed files with 139 additions and 12 deletions

View File

@ -139,6 +139,15 @@ g_fold_type[] =
{MAKE_ID_AND_STR(ID_OPTION_VALUE_ZDDZ),FOLD_TYPE_AUTO}
};
int g_paper_hx[] = { PAPER_A4, PAPER_A4_LATERAL
, PAPER_A5, PAPER_A5_LATERAL
, PAPER_A6, PAPER_A6_LATERAL
, PAPER_B5, PAPER_B5_LATERAL
, PAPER_B6, PAPER_B6_LATERAL
, PAPER_16K,PAPER_16K_LATERAL
, PAPER_LETTER, PAPER_LETTER_LATERAL
};
static struct paper_size
{
int paper;
@ -451,13 +460,27 @@ std::string paper_string(int paper)
}
bool is_lateral(int paper)
{
return paper == PAPER_A4_LATERAL
|| paper == PAPER_A5_LATERAL
|| paper == PAPER_A6_LATERAL
|| paper == PAPER_B5_LATERAL
|| paper == PAPER_B6_LATERAL
|| paper == PAPER_16K_LATERAL
|| paper == PAPER_LETTER_LATERAL;
for (int i = 1; i < _countof(g_paper_hx); i += 2)
{
if (paper == g_paper_hx[i])
return true;
}
return false;
}
int switch_lateral(int paper, bool lateral)
{
for (int i = !lateral; i < _countof(g_paper_hx); i += 2)
{
if (g_paper_hx[i] == paper)
{
i += lateral ? 1 : -1;
paper = g_paper_hx[i];
break;
}
}
return paper;
}
std::string page_string(int page)
{

View File

@ -166,6 +166,7 @@ SIZE paper_size(int paper); // unit: mm
int match_best_paper(std::string& val, bool* exact);
std::string paper_string(int paper);
bool is_lateral(int paper);
int switch_lateral(int paper, bool lateral);
// 页面扫描模式 选项
//#define HUAGAO_SETTING_STR_PAGE_SINGLE "单面"

View File

@ -1197,9 +1197,10 @@ int hg_scanner::setting_paper(void* data, long* len)
val = 0,
old = image_prc_param_.bits.paper;
val = image_prc_param_.bits.paper = match_best_paper(paper, NULL);
val = image_prc_param_.bits.paper = switch_lateral(match_best_paper(paper, NULL), lateral_);
// check 600 dpi ...
paper_size_mm_ = paper_size(val);
sub = on_paper_changed(val);
image_prc_param_.bits.paper = val;
@ -4274,6 +4275,16 @@ std::string hg_scanner::get_value(const char* name, void* value, int* err)
{
val = get_ip();
}
else if (strcmp(name, SANE_STD_OPT_NAME_PAPER_W) == 0)
{
double w = paper_size_mm_.cx;
val = std::string((char*)&w, sizeof(w));
}
else if (strcmp(name, SANE_STD_OPT_NAME_PAPER_H) == 0)
{
double h = paper_size_mm_.cy;
val = std::string((char*)&h, sizeof(h));
}
else
{
result = SCANNER_ERR_DEVICE_NOT_SUPPORT;
@ -4293,6 +4304,12 @@ int hg_scanner::set_value(const char* name, void* val)
long len = 0;
err = (this->*setting_map_[name])(val, &len);
}
else if (strcmp(name, SANE_STD_OPT_NAME_LATERAL) == 0)
{
lateral_ = *(bool*)val;
image_prc_param_.bits.paper = switch_lateral(image_prc_param_.bits.paper, lateral_);
err = SCANNER_ERR_OK;
}
return err;
}

View File

@ -333,6 +333,7 @@ protected:
int is_auto_paper_scan_exit_time; //待纸扫描退出时间
bool is_auto_feedmode_; //是否启用自动分纸强度
bool is_discardblank; //是否启动跳过空白页
bool lateral_ = false;
SANE_DISTORTION_VAL distortion_val; //畸变修正结构体保存

File diff suppressed because one or more lines are too long

View File

@ -943,6 +943,13 @@ scanner_err hg_scanner_mgr::hg_scanner_set_parameter(scanner_handle h, const cha
}
else
{
// 1 - paper option removes 'lateral' choices and add new option with name 'lateral'
// 2 - page option replaces 'single side' with 'front side' and 'back side'
//
// here to transfer them ...
std::string prev("");
bool lateral = false, restore_data = false;
if (to_default)
{
int size = 0;
@ -958,11 +965,47 @@ scanner_err hg_scanner_mgr::hg_scanner_set_parameter(scanner_handle h, const cha
}
else
{
if (strcmp(name, SANE_STD_OPT_NAME_PAPER) == 0)
{
std::string hx(from_default_language("\346\250\252\345\220\221"));
char *lat = strstr((char*)data, hx.c_str()) ;
if (lat)
{
prev = (char*)data;
lateral = true;
restore_data = true;
*lat = 0;
}
}
else if (strcmp(name, SANE_STD_OPT_NAME_PAGE) == 0)
{
if (strcmp((char*)data, from_default_language("\345\215\225\351\235\242")) == 0) // single side
{
prev = (char*)data;
restore_data = true;
strcpy((char*)data, from_default_language("\346\255\243\351\235\242")); // front side
utils::to_log(LOG_LEVEL_DEBUG, "compatible for old page option '%s' to '%s'.\n", prev.c_str(), (char*)data);
}
}
err = dev_opts_->refine_data(name, data) ? SCANNER_ERR_NOT_EXACT : SCANNER_ERR_OK;
}
se = (scanner_err)dev_opts_->update_data(name, data);
if (se != SCANNER_ERR_OK)
err = se;
else if (restore_data)
{
// here handle options paper and page are both string ...
strcpy((char*)data, prev.c_str());
if (lateral)
{
utils::to_log(LOG_LEVEL_DEBUG, "compatible for old paper option '%s', set lateral to '%s' additional.\n", prev.c_str(), lateral ? "true" : "false");
dev_opts_->refine_data(SANE_STD_OPT_NAME_LATERAL, &lateral);
dev_opts_->update_data(SANE_STD_OPT_NAME_LATERAL, &lateral);
}
}
}
return err;

View File

@ -1670,7 +1670,9 @@ int device_option::update_data(const char* name, void* value, bool reorder_if_ne
// pass to sane_opt_provider ...
err = SCANNER_ERR_OK;
if (src_.count(name))
{
err = src_[name]->set_value(name, value);
}
if (err == SCANNER_ERR_OK || err == SCANNER_ERR_NOT_EXACT
|| err == SCANNER_ERR_RELOAD_IMAGE_PARAM || err == SCANNER_ERR_RELOAD_OPT_PARAM)
@ -1698,6 +1700,46 @@ int device_option::update_data(const char* name, void* value, bool reorder_if_ne
}
child->release();
// set paper-w and paper-h
if (strcmp(name, SANE_STD_OPT_NAME_PAPER) == 0 ||
strcmp(name, SANE_STD_OPT_NAME_LATERAL) == 0)
{
if (src_.count(SANE_STD_OPT_NAME_PAPER_W))
{
std::string w(src_[SANE_STD_OPT_NAME_PAPER_W]->get_value(SANE_STD_OPT_NAME_PAPER_W, nullptr)),
h(src_[SANE_STD_OPT_NAME_PAPER_H]->get_value(SANE_STD_OPT_NAME_PAPER_H, nullptr)),
lateral(get_option_value(SANE_STD_OPT_NAME_LATERAL, SANE_ACTION_GET_VALUE));
now_->get_value(SANE_STD_OPT_NAME_LATERAL, child);
if (child)
{
if (device_option::is_opt_enabled(child, nullptr, nullptr, nullptr))
{
refine_data(SANE_STD_OPT_NAME_LATERAL, &lateral[0]);
if (*(bool*)&lateral[0])
w.swap(h);
}
child->release();
}
gb_json* pw = nullptr,
* ph = nullptr;
now_->get_value(SANE_STD_OPT_NAME_PAPER_W, pw);
now_->get_value(SANE_STD_OPT_NAME_PAPER_H, ph);
if (pw)
{
pw->set_value("cur", *(double*)&w[0]);
pw->release();
}
if (ph)
{
ph->set_value("cur", *(double*)&h[0]);
ph->release();
}
name = SANE_STD_OPT_NAME_PAPER; // ensure invoked refresh ...
}
}
if (reorder_if_need && changed && // value has changed
std::find(master_opts_.begin(), master_opts_.end(), name) != master_opts_.end()) // can affect others
{