中晶增加ocrpdf

This commit is contained in:
yangjiaxuan 2023-02-17 09:20:12 +08:00
parent 05d2c6e9b1
commit 54473bbf0a
9 changed files with 255 additions and 67 deletions

View File

@ -45,10 +45,6 @@ Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) :
ui->lineEdit_fileName->setText(getCfgValue("aquire", "namePrefix", QString("HGScan"))); ui->lineEdit_fileName->setText(getCfgValue("aquire", "namePrefix", QString("HGScan")));
#endif #endif
#if defined(OEM_LISICHENG) || defined(OEM_ZHONGJING) || defined(x86_64)
ui->cbox_format->removeItem(11);
ui->cbox_format->removeItem(10);
#endif
ui->spin_index->setValue(getCfgValue("aquire", "startIndex", 1)); ui->spin_index->setValue(getCfgValue("aquire", "startIndex", 1));
ui->cbox_digit->setCurrentIndex(getCfgValue("aquire", "digit", 2)); ui->cbox_digit->setCurrentIndex(getCfgValue("aquire", "digit", 2));
ui->cbox_evenOdd->setCurrentIndex(getCfgValue("aquire", "evenOdd", 0)); ui->cbox_evenOdd->setCurrentIndex(getCfgValue("aquire", "evenOdd", 0));

View File

@ -6,8 +6,10 @@
#include <algorithm> #include <algorithm>
#include <QRegExpValidator> #include <QRegExpValidator>
#include "dialog_writesettings.h" #include "dialog_writesettings.h"
#include "base/HGBase.h"
#include "HGUIGlobal.h" #include "HGUIGlobal.h"
#include "app_cfg.h" #include "app_cfg.h"
#include "ocrPdf.h"
#include <assert.h> #include <assert.h>
#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0]) #define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
@ -19,6 +21,7 @@ enum file_type_attr
FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES = 0x01 << 1, // this type supports multi-images to be saved into one file FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES = 0x01 << 1, // this type supports multi-images to be saved into one file
FILE_TYPE_ATTR_THIRD_HANDLER = 0x01 << 2, // this type supports third-handling methods FILE_TYPE_ATTR_THIRD_HANDLER = 0x01 << 2, // this type supports third-handling methods
}; };
/*
static struct static struct
{ {
QString ext; QString ext;
@ -26,8 +29,7 @@ static struct
int attr; int attr;
}g_support_type[] = }g_support_type[] =
{ {
#if defined(OEM_LISICHENG) || defined(OEM_ZHONGJING) || defined(x86_64) {".jpg", "JPG - JPEG / JFIF", FILE_TYPE_ATTR_MORE_OPTIONS}
{".jpg", "JPG - JPEG / JFIF", FILE_TYPE_ATTR_MORE_OPTIONS}
, {".bmp", "BMP - Windows Bitmap", FILE_TYPE_ATTR_NO_MORE_OPTION} , {".bmp", "BMP - Windows Bitmap", FILE_TYPE_ATTR_NO_MORE_OPTION}
, {".png", "PNG - Portable Network Graphics", FILE_TYPE_ATTR_NO_MORE_OPTION} , {".png", "PNG - Portable Network Graphics", FILE_TYPE_ATTR_NO_MORE_OPTION}
, {".ppm", "PPM - Portable PixMap", FILE_TYPE_ATTR_NO_MORE_OPTION} , {".ppm", "PPM - Portable PixMap", FILE_TYPE_ATTR_NO_MORE_OPTION}
@ -37,23 +39,15 @@ static struct
, {".pdf", "PDF - Portable Document Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES} , {".pdf", "PDF - Portable Document Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".ofd", "OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES} , {".ofd", "OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".gif", "GIF - Graphics Interchange Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES} , {".gif", "GIF - Graphics Interchange Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
#else #if defined(OEM_ZHONGJING) && defined(HG_CMP_MSC)
{".jpg", "JPG - JPEG / JFIF", FILE_TYPE_ATTR_MORE_OPTIONS} , {".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".bmp", "BMP - Windows Bitmap", FILE_TYPE_ATTR_NO_MORE_OPTION} #elif (defined (OEM_HUAGAO) || defined (OEM_HANWANG) || defined (OEM_CANGTIAN)) && !defined(x86_64)
, {".png", "PNG - Portable Network Graphics", FILE_TYPE_ATTR_NO_MORE_OPTION} , {".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".ppm", "PPM - Portable PixMap", FILE_TYPE_ATTR_NO_MORE_OPTION} , {".ofd", "OCR->OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".pgm", "PGM - Portable GreyMap", FILE_TYPE_ATTR_NO_MORE_OPTION} , {".rtf", "OCR->RTF - Rich Text Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".pbm", "PBM - Portable BitMap", FILE_TYPE_ATTR_NO_MORE_OPTION}
, {".tif", "TIF - TIFF Revision 6", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES | FILE_TYPE_ATTR_MORE_OPTIONS}
, {".pdf", "PDF - Portable Document Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".ofd", "OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".gif", "GIF - Graphics Interchange Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".ofd", "OCR->OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
, {".rtf", "OCR->RTF - Rich Text Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES}
#endif #endif
}; };
*/
Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs, QWidget *parent) : Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs, QWidget *parent) :
QDialog(parent) QDialog(parent)
, ui(new Ui::Dialog_Export) , ui(new Ui::Dialog_Export)
@ -62,6 +56,25 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
{ {
ui->setupUi(this); ui->setupUi(this);
m_supportType.push_back(SupportType(".jpg", "JPG - JPEG / JFIF", FILE_TYPE_ATTR_MORE_OPTIONS));
m_supportType.push_back(SupportType(".bmp", "BMP - Windows Bitmap", FILE_TYPE_ATTR_NO_MORE_OPTION));
m_supportType.push_back(SupportType(".png", "PNG - Portable Network Graphics", FILE_TYPE_ATTR_NO_MORE_OPTION));
m_supportType.push_back(SupportType(".ppm", "PPM - Portable PixMap", FILE_TYPE_ATTR_NO_MORE_OPTION));
m_supportType.push_back(SupportType(".pgm", "PGM - Portable GreyMap", FILE_TYPE_ATTR_NO_MORE_OPTION));
m_supportType.push_back(SupportType(".pbm", "PBM - Portable BitMap", FILE_TYPE_ATTR_NO_MORE_OPTION));
m_supportType.push_back(SupportType(".tif", "TIF - TIFF Revision 6", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES | FILE_TYPE_ATTR_MORE_OPTIONS));
m_supportType.push_back(SupportType(".pdf", "PDF - Portable Document Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
m_supportType.push_back(SupportType(".ofd", "OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
m_supportType.push_back(SupportType(".gif", "GIF - Graphics Interchange Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
#if defined(OEM_ZHONGJING) && defined(HG_CMP_MSC)
if (!getOcrPath().empty())
m_supportType.push_back(SupportType(".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
#elif (defined (OEM_HUAGAO) || defined (OEM_HANWANG) || defined (OEM_CANGTIAN)) && !defined(x86_64)
m_supportType.push_back(SupportType(".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
m_supportType.push_back(SupportType(".ofd", "OCR->OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
m_supportType.push_back(SupportType(".rtf", "OCR->RTF - Rich Text Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
#endif
ui->fileDialog->setAcceptMode(QFileDialog::AcceptSave); ui->fileDialog->setAcceptMode(QFileDialog::AcceptSave);
ui->fileDialog->setWindowFlags(ui->fileDialog->windowFlags() & ~Qt::Dialog); ui->fileDialog->setWindowFlags(ui->fileDialog->windowFlags() & ~Qt::Dialog);
ui->fileDialog->setOption(QFileDialog::DontUseNativeDialog, true); ui->fileDialog->setOption(QFileDialog::DontUseNativeDialog, true);
@ -77,8 +90,8 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
// "OCR->PDF - Portable Document Format(*.pdf);;" // "OCR->PDF - Portable Document Format(*.pdf);;"
// "OCR->OFD - Open Fixed-layout Document(*.ofd)"); // "OCR->OFD - Open Fixed-layout Document(*.ofd)");
QStringList filters; QStringList filters;
for(int i = 0; i < ARRAY_SIZE(g_support_type); ++i) for(int i = 0; i < m_supportType.size(); ++i)
filters.push_back(g_support_type[i].title + "(*" + g_support_type[i].ext + ")"); filters.push_back(m_supportType[i].title + "(*" + m_supportType[i].ext + ")");
ui->fileDialog->setNameFilters(filters); ui->fileDialog->setNameFilters(filters);
connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted())); connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted()));
@ -88,13 +101,6 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
#ifdef USE_FILE_DLG_WITHOUT_PROMPT #ifdef USE_FILE_DLG_WITHOUT_PROMPT
init_custom_file_dlg(ui->fileDialog); init_custom_file_dlg(ui->fileDialog);
#endif #endif
QDialogButtonBox *buttonBox = ui->fileDialog->findChild<QDialogButtonBox *>("buttonBox");
QPushButton *okBtn = buttonBox->button(QDialogButtonBox::Ok);
if (okBtn)
okBtn->setText(tr("ok"));
QPushButton *cancelBtn = buttonBox->button(QDialogButtonBox::Cancel);
if (cancelBtn)
cancelBtn->setText(tr("cancel"));
QButtonGroup* btn_group = new QButtonGroup(this); QButtonGroup* btn_group = new QButtonGroup(this);
btn_group->addButton(ui->radio_chosenPages, 0); btn_group->addButton(ui->radio_chosenPages, 0);
@ -105,15 +111,15 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
ui->lineEdit_nominatePages->setValidator(new QRegExpValidator(rx, this)); ui->lineEdit_nominatePages->setValidator(new QRegExpValidator(rx, this));
m_suffix = getCfgValue("export", "suffix", 0); m_suffix = getCfgValue("export", "suffix", 0);
if(m_suffix < 0 || m_suffix >= ARRAY_SIZE(g_support_type)) if(m_suffix < 0 || m_suffix >= m_supportType.size())
m_suffix = 0; m_suffix = 0;
ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix)); ui->fileDialog->selectNameFilter(ui->fileDialog->nameFilters().at(m_suffix));
m_saveExt = g_support_type[m_suffix].ext; m_saveExt = m_supportType[m_suffix].ext;
// ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6); // ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6);
ui->check_saveAsMulti->setEnabled((g_support_type[m_suffix].attr & FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES) == FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES); ui->check_saveAsMulti->setEnabled((m_supportType[m_suffix].attr & FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES) == FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES);
ui->check_saveAsMulti->setChecked(getCfgValue("export", "saveAsMulti", false)); ui->check_saveAsMulti->setChecked(getCfgValue("export", "saveAsMulti", false));
// ui->btn_option->setEnabled(m_suffix == 0 || m_suffix == 3); // ui->btn_option->setEnabled(m_suffix == 0 || m_suffix == 3);
ui->btn_option->setEnabled((g_support_type[m_suffix].attr & FILE_TYPE_ATTR_MORE_OPTIONS) == FILE_TYPE_ATTR_MORE_OPTIONS); ui->btn_option->setEnabled((m_supportType[m_suffix].attr & FILE_TYPE_ATTR_MORE_OPTIONS) == FILE_TYPE_ATTR_MORE_OPTIONS);
int exportType = getCfgValue("export", "exportType", 0); int exportType = getCfgValue("export", "exportType", 0);
if (0 == exportType) if (0 == exportType)
@ -183,7 +189,7 @@ int Dialog_Export::getTiffQuality()
bool Dialog_Export::isOcr() bool Dialog_Export::isOcr()
{ {
// return (m_suffix >= 6); // return (m_suffix >= 6);
return (g_support_type[m_suffix].attr & FILE_TYPE_ATTR_THIRD_HANDLER) == FILE_TYPE_ATTR_THIRD_HANDLER; return (m_supportType[m_suffix].attr & FILE_TYPE_ATTR_THIRD_HANDLER) == FILE_TYPE_ATTR_THIRD_HANDLER;
} }
bool Dialog_Export::isSaveAsMultiPage() bool Dialog_Export::isSaveAsMultiPage()
@ -198,7 +204,7 @@ void Dialog_Export::getSaveIndexs(std::vector<int> &indexs)
void Dialog_Export::on_dialog_accepted() void Dialog_Export::on_dialog_accepted()
{ {
QString extName(g_support_type[m_suffix].ext); QString extName(m_supportType[m_suffix].ext);
// switch (m_suffix) // switch (m_suffix)
// { // {
// case 0: // case 0:
@ -275,17 +281,17 @@ void Dialog_Export::on_filterSelected(const QString& filterName)
bool enabled = false; bool enabled = false;
m_suffix = ui->fileDialog->nameFilters().indexOf(filterName); m_suffix = ui->fileDialog->nameFilters().indexOf(filterName);
enabled = (g_support_type[m_suffix].attr & FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES) == FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES; enabled = (m_supportType[m_suffix].attr & FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES) == FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES;
ui->check_saveAsMulti->setEnabled(enabled); ui->check_saveAsMulti->setEnabled(enabled);
// ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6); // ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6);
// if (m_suffix <= 2 || m_suffix >= 6) // if (m_suffix <= 2 || m_suffix >= 6)
if(!enabled) if(!enabled)
ui->check_saveAsMulti->setChecked(false); ui->check_saveAsMulti->setChecked(false);
enabled = (g_support_type[m_suffix].attr & FILE_TYPE_ATTR_MORE_OPTIONS) == FILE_TYPE_ATTR_MORE_OPTIONS; enabled = (m_supportType[m_suffix].attr & FILE_TYPE_ATTR_MORE_OPTIONS) == FILE_TYPE_ATTR_MORE_OPTIONS;
// ui->btn_option->setEnabled(0 == m_suffix || 3 == m_suffix); // ui->btn_option->setEnabled(0 == m_suffix || 3 == m_suffix);
ui->btn_option->setEnabled(enabled); ui->btn_option->setEnabled(enabled);
m_saveExt = g_support_type[m_suffix].ext; m_saveExt = m_supportType[m_suffix].ext;
} }
void Dialog_Export::on_btn_option_clicked() void Dialog_Export::on_btn_option_clicked()
@ -602,11 +608,11 @@ void Dialog_Export::makeSaveIndexs()
bool Dialog_Export::is_support_file_type(const QString& ext) bool Dialog_Export::is_support_file_type(const QString& ext)
{ {
return ext.compare(g_support_type[m_suffix].ext, Qt::CaseInsensitive) == 0; return ext.compare(m_supportType[m_suffix].ext, Qt::CaseInsensitive) == 0;
for(int i = 0; i < ARRAY_SIZE(g_support_type); ++i) for(int i = 0; i < m_supportType.size(); ++i)
{ {
if(ext.compare(g_support_type[i].ext, Qt::CaseInsensitive) == 0) if(ext.compare(m_supportType[i].ext, Qt::CaseInsensitive) == 0)
return true; return true;
} }

View File

@ -2,10 +2,26 @@
#define DIALOG_EXPORT_H #define DIALOG_EXPORT_H
#include <QDialog> #include <QDialog>
#include <vector>
// u can ONLY comment following line if u want to use filedialog as system present ! // u can ONLY comment following line if u want to use filedialog as system present !
#include "custom_file_dialog.h" #include "custom_file_dialog.h"
struct SupportType
{
public:
SupportType(const QString &e, const QString &t, int a)
{
ext = e;
title = t;
attr = a;
}
QString ext;
QString title;
int attr;
};
namespace Ui { namespace Ui {
class Dialog_Export; class Dialog_Export;
} }
@ -54,6 +70,7 @@ private:
private: private:
Ui::Dialog_Export *ui; Ui::Dialog_Export *ui;
std::vector<SupportType> m_supportType;
int m_total; int m_total;
std::vector<int> m_selectedIndexs; std::vector<int> m_selectedIndexs;

View File

@ -2,12 +2,14 @@
#include "ui_dialog_exportimagefile.h" #include "ui_dialog_exportimagefile.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "base/HGInfo.h" #include "base/HGInfo.h"
#include "base/HGUtility.h"
#include "imgfmt/HGImgFmt.h" #include "imgfmt/HGImgFmt.h"
#include "imgproc/HGOCR.h" #include "imgproc/HGOCR.h"
#include "HGUIGlobal.h" #include "HGUIGlobal.h"
#include "HGString.h" #include "HGString.h"
#include <QMessageBox> #include <QMessageBox>
#include <QFile> #include <QFile>
#include "ocrPdf.h"
Dialog_ExportImageFile::Dialog_ExportImageFile(const QString &destPath, const QString &destName, const QString &destExt, Dialog_ExportImageFile::Dialog_ExportImageFile(const QString &destPath, const QString &destName, const QString &destExt,
bool isSaveAsMulti, int jpegQuality, int tiffCompressionBW, int tiffCompression, int tiffQuality, bool isOcr, bool isSaveAsMulti, int jpegQuality, int tiffCompressionBW, int tiffCompression, int tiffQuality, bool isOcr,
@ -61,6 +63,62 @@ void HGAPI Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param)
if (p->m_isOcr) if (p->m_isOcr)
{ {
#if defined(OEM_ZHONGJING)
HGChar tmpFileName[256];
HGBase_GetTmpFileName("tif", tmpFileName, 256);
HGImgFmtWriter writer = NULL;
HGImgFmt_OpenImageWriter(tmpFileName, 0, &writer);
for (int i = 0; i < p->m_srcFiles.size(); ++i)
{
if (p->m_stopThread)
{
break;
}
emit p->updateProgress(i);
HGImgFmtReader imgFmtReader = nullptr;
ret = HGImgFmt_OpenImageReader(getStdString(p->m_srcFiles[i]).c_str(), 0, &imgFmtReader);
if (HGBASE_ERR_OK == ret)
{
HGUInt count = 0;
HGImgFmt_GetImagePageCount(imgFmtReader, &count);
for (HGUInt j = 0; j < count; ++j)
{
if (p->m_stopThread)
{
break;
}
HGImage img = nullptr;
ret = HGImgFmt_LoadImageFromReader(imgFmtReader, j, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img);
if (HGBASE_ERR_OK == ret)
{
ret = HGImgFmt_SaveImageToWriter(writer, img, NULL);
HGBase_DestroyImage(img);
}
if (ret != HGBASE_ERR_OK)
{
break;
}
}
HGImgFmt_CloseImageReader(imgFmtReader);
}
if (ret != HGBASE_ERR_OK)
break;
}
HGImgFmt_CloseImageWriter(writer);
createOcrPdf(tmpFileName, getStdString(fileName).c_str());
QFile::remove(tmpFileName);
#else
HGOCRMgr ocrMgr = nullptr; HGOCRMgr ocrMgr = nullptr;
ret = HGImgProc_CreateOCRMgr(0, &ocrMgr); ret = HGImgProc_CreateOCRMgr(0, &ocrMgr);
if (HGBASE_ERR_OK == ret) if (HGBASE_ERR_OK == ret)
@ -115,6 +173,7 @@ void HGAPI Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param)
HGImgProc_DestroyOCRMgr(ocrMgr); HGImgProc_DestroyOCRMgr(ocrMgr);
} }
#endif
} }
else else
{ {

View File

@ -1,8 +1,10 @@
#include "dialog_saveas.h" #include "dialog_saveas.h"
#include "ui_dialog_saveas.h" #include "ui_dialog_saveas.h"
#include "dialog_writesettings.h" #include "dialog_writesettings.h"
#include "base/HGBase.h"
#include "HGUIGlobal.h" #include "HGUIGlobal.h"
#include "app_cfg.h" #include "app_cfg.h"
#include "ocrPdf.h"
#include <assert.h> #include <assert.h>
#include <qabstractproxymodel.h> #include <qabstractproxymodel.h>
#include <QDateTime> #include <QDateTime>
@ -69,33 +71,28 @@ Dialog_SaveAs::Dialog_SaveAs(QWidget *parent) :
ui->fileDialog->setOption(QFileDialog::DontUseNativeDialog, true); ui->fileDialog->setOption(QFileDialog::DontUseNativeDialog, true);
ui->fileDialog->setOption(QFileDialog::ReadOnly, true); // disable 'Delete' menu item ui->fileDialog->setOption(QFileDialog::ReadOnly, true); // disable 'Delete' menu item
ui->fileDialog->setSizeGripEnabled(false); ui->fileDialog->setSizeGripEnabled(false);
#if defined(OEM_LISICHENG) || defined(OEM_ZHONGJING) || defined(x86_64)
ui->fileDialog->setNameFilter("JPG - JPEG / JFIF(*.jpg);;" QString filter = "JPG - JPEG / JFIF(*.jpg)"
"BMP - Windows Bitmap(*.bmp);;" ";;BMP - Windows Bitmap(*.bmp)"
"PNG - Portable Network Graphics(*.png);;" ";;PNG - Portable Network Graphics(*.png)"
"PPM - Portable PixMap(*.ppm);;" ";;PPM - Portable PixMap(*.ppm)"
"PGM - Portable GreyMap(*.pgm);;" ";;PGM - Portable GreyMap(*.pgm)"
"PBM - Portable BitMap(*.pbm);;" ";;PBM - Portable BitMap(*.pbm)"
"TIF - TIFF Revision 6(*.tif);;" ";;TIF - TIFF Revision 6(*.tif)"
"PDF - Portable Document Format(*.pdf);;" ";;PDF - Portable Document Format(*.pdf)"
"OFD - Open Fixed-layout Document(*.ofd);;" ";;OFD - Open Fixed-layout Document(*.ofd)"
"GIF - Graphics Interchange Format(*.gif)"); ";;GIF - Graphics Interchange Format(*.gif)";
#else #if defined(OEM_ZHONGJING) && defined(HG_CMP_MSC)
ui->fileDialog->setNameFilter("JPG - JPEG / JFIF(*.jpg);;" if (!getOcrPath().empty())
"BMP - Windows Bitmap(*.bmp);;" filter += ";;OCR->PDF - Portable Document Format(*.pdf)";
"PNG - Portable Network Graphics(*.png);;" #elif (defined (OEM_HUAGAO) || defined (OEM_HANWANG) || defined (OEM_CANGTIAN)) && !defined(x86_64)
"PPM - Portable PixMap(*.ppm);;" filter += ";;OCR->PDF - Portable Document Format(*.pdf)";
"PGM - Portable GreyMap(*.pgm);;" filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)";
"PBM - Portable BitMap(*.pbm);;" filter += ";;OCR->RTF - Rich Text Format(*.rtf)";
"TIF - TIFF Revision 6(*.tif);;"
"PDF - Portable Document Format(*.pdf);;"
"OFD - Open Fixed-layout Document(*.ofd);;"
"GIF - Graphics Interchange Format(*.gif);;"
"OCR->PDF - Portable Document Format(*.pdf);;"
"OCR->OFD - Open Fixed-layout Document(*.ofd);;"
"OCR->RTF - Rich Text Format(*.rtf)");
#endif #endif
ui->fileDialog->setNameFilter(filter);
connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted())); connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted()));
connect(ui->fileDialog, SIGNAL(rejected()), this, SLOT(close())); connect(ui->fileDialog, SIGNAL(rejected()), this, SLOT(close()));
connect(ui->fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(on_filterSelected(const QString&))); connect(ui->fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(on_filterSelected(const QString&)));

View File

@ -50,6 +50,7 @@
#include "dialog_wrong_img.h" #include "dialog_wrong_img.h"
#include "../../code_device/hgdriver/hgdev/char_const.h" #include "../../code_device/hgdriver/hgdev/char_const.h"
#include "lang/app_language.h" #include "lang/app_language.h"
#include "ocrPdf.h"
#define PASSWORD_KEY 4 #define PASSWORD_KEY 4
#define MY_URL_SCHEME "inscanner" #define MY_URL_SCHEME "inscanner"
@ -427,6 +428,15 @@ HGResult MainWindow::saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool
} }
HGResult ret = HGBASE_ERR_FAIL; HGResult ret = HGBASE_ERR_FAIL;
#if defined(OEM_ZHONGJING)
HGChar tmpFileName[256];
HGBase_GetTmpFileName("bmp", tmpFileName, 256);
ret = HGImgFmt_SaveImage(image, 0, info, tmpFileName);
createOcrPdf(tmpFileName, fileName);
QFile::remove(tmpFileName);
return ret;
#else
// 韫囩晫鏆恑nfo // 韫囩晫鏆恑nfo
HGOCRMgr ocrMgr = nullptr; HGOCRMgr ocrMgr = nullptr;
ret = HGImgProc_CreateOCRMgr(0, &ocrMgr); ret = HGImgProc_CreateOCRMgr(0, &ocrMgr);
@ -437,6 +447,7 @@ HGResult MainWindow::saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool
} }
return ret; return ret;
#endif
} }
void MainWindow::on_act_90Left_triggered() void MainWindow::on_act_90Left_triggered()

91
app/scanner/ocrPdf.cpp Normal file
View File

@ -0,0 +1,91 @@
#include <iostream>
#include <Windows.h>
#include <atlstr.h>
#include <string>
#include "base/HGUtility.h"
std::string getOcrPath()
{
std::string ocrPath;
HKEY hKey = NULL;
#ifdef _WIN64
RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Microtek\\Microtek OCR Engine V1", 0, KEY_QUERY_VALUE, &hKey);
#else
RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microtek\\Microtek OCR Engine V1", 0, KEY_QUERY_VALUE, &hKey);
#endif
if (NULL != hKey)
{
CHAR szData[MAX_PATH] = { 0 };
DWORD cbData = MAX_PATH;
if (ERROR_SUCCESS == RegQueryValueExA(hKey, "InstallPath_Fast", NULL, NULL, (LPBYTE)szData, &cbData))
{
ocrPath = szData;
}
RegCloseKey(hKey);
}
return ocrPath;
}
bool createOcrPdf(const std::string &imgPath, const std::string &dstFile)
{
std::string ocrPath = getOcrPath();
if (ocrPath.empty())
return false;
DWORD len1 = GetEnvironmentVariableA("Path", NULL, 0);
char* env1 = (char *)malloc((size_t)len1 + 256);
if (NULL != env1)
{
memset(env1, 0, (size_t)len1 + 256);
GetEnvironmentVariableA("Path", env1, len1 + 256);
strcat(env1, ";");
strcat(env1, ocrPath.c_str());
SetEnvironmentVariableA("Path", env1);
free(env1);
}
DWORD len2 = GetEnvironmentVariableA("TESSDATA_PREFIX", NULL, 0);
char* env2 = (char*)malloc((size_t)len2 + 256);
if (NULL != env2)
{
memset(env2, 0, (size_t)len2 + 256);
GetEnvironmentVariableA("TESSDATA_PREFIX", env2, len2 + 256);
strcat(env2, ocrPath.c_str());
strcat(env2, "\\");
strcat(env2, "tessdata_f");
SetEnvironmentVariableA("TESSDATA_PREFIX", env2);
free(env2);
}
// std::string imgPath("D:\\1.jpg");
// std::string dstFile("D:\\1");
DeleteFileA(dstFile.c_str());
PROCESS_INFORMATION ProcessInfo;
STARTUPINFOA StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
HGChar prefix[256];
HGBase_GetFilePrefix(dstFile.c_str(), prefix, 256);
bool ret = false;
char cmd[1024] = {0};
sprintf(cmd, "tesseract.exe \"%s\" \"%s\" -l %s --psm %d --oem %d %s", imgPath.c_str(), prefix, "eng", 3, 3, "pdf");
BOOL b = CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &StartupInfo, &ProcessInfo);
if (b)
{
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
DWORD exitCode;
GetExitCodeProcess(ProcessInfo.hProcess, &exitCode);
if (0 == exitCode)
ret = true;
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
}
return ret;
}

9
app/scanner/ocrPdf.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef __OCRPDF_H__
#define __OCRPDF_H__
#include <string>
std::string getOcrPath();
bool createOcrPdf(const std::string &imgPath, const std::string &dstFile);
#endif /* __OCRPDF_H__ */

View File

@ -263,6 +263,7 @@ SOURCES += \
../../../app/scanner/hg_settingdialog.cpp \ ../../../app/scanner/hg_settingdialog.cpp \
../../../app/scanner/main.cpp \ ../../../app/scanner/main.cpp \
../../../app/scanner/mainwindow.cpp \ ../../../app/scanner/mainwindow.cpp \
../../../app/scanner/ocrPdf.cpp \
../../../app/scanner/sane_device.cpp \ ../../../app/scanner/sane_device.cpp \
../../../app/scanner/setpicclrtool.cpp \ ../../../app/scanner/setpicclrtool.cpp \
../../../app/scanner/widget.cpp \ ../../../app/scanner/widget.cpp \
@ -312,6 +313,7 @@ HEADERS += \
../../../app/scanner/graphicsscene.h \ ../../../app/scanner/graphicsscene.h \
../../../app/scanner/hg_settingdialog.h \ ../../../app/scanner/hg_settingdialog.h \
../../../app/scanner/mainwindow.h \ ../../../app/scanner/mainwindow.h \
../../../app/scanner/ocrPdf.h \
../../../app/scanner/sane_device.h \ ../../../app/scanner/sane_device.h \
../../../app/scanner/setpicclrtool.h \ ../../../app/scanner/setpicclrtool.h \
../../../app/scanner/widget.h \ ../../../app/scanner/widget.h \