diff --git a/app/scanner/dialog_aquireinto.cpp b/app/scanner/dialog_aquireinto.cpp index 70937470..3b67ed85 100644 --- a/app/scanner/dialog_aquireinto.cpp +++ b/app/scanner/dialog_aquireinto.cpp @@ -45,10 +45,6 @@ Dialog_AquireInto::Dialog_AquireInto(QWidget* parent) : ui->lineEdit_fileName->setText(getCfgValue("aquire", "namePrefix", QString("HGScan"))); #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->cbox_digit->setCurrentIndex(getCfgValue("aquire", "digit", 2)); ui->cbox_evenOdd->setCurrentIndex(getCfgValue("aquire", "evenOdd", 0)); diff --git a/app/scanner/dialog_export.cpp b/app/scanner/dialog_export.cpp index 655513e4..62cc68c2 100644 --- a/app/scanner/dialog_export.cpp +++ b/app/scanner/dialog_export.cpp @@ -6,8 +6,10 @@ #include #include #include "dialog_writesettings.h" +#include "base/HGBase.h" #include "HGUIGlobal.h" #include "app_cfg.h" +#include "ocrPdf.h" #include #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_THIRD_HANDLER = 0x01 << 2, // this type supports third-handling methods }; +/* static struct { QString ext; @@ -26,8 +29,7 @@ static struct int attr; }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} , {".png", "PNG - Portable Network Graphics", 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} , {".ofd", "OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES} , {".gif", "GIF - Graphics Interchange Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES} -#else - {".jpg", "JPG - JPEG / JFIF", FILE_TYPE_ATTR_MORE_OPTIONS} - , {".bmp", "BMP - Windows Bitmap", 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} - , {".pgm", "PGM - Portable GreyMap", FILE_TYPE_ATTR_NO_MORE_OPTION} - , {".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} +#if defined(OEM_ZHONGJING) && defined(HG_CMP_MSC) + , {".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) + , {".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 }; - +*/ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, QWidget *parent) : QDialog(parent) , ui(new Ui::Dialog_Export) @@ -62,6 +56,25 @@ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, { 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->setWindowFlags(ui->fileDialog->windowFlags() & ~Qt::Dialog); ui->fileDialog->setOption(QFileDialog::DontUseNativeDialog, true); @@ -77,8 +90,8 @@ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, // "OCR->PDF - Portable Document Format(*.pdf);;" // "OCR->OFD - Open Fixed-layout Document(*.ofd)"); QStringList filters; - for(int i = 0; i < ARRAY_SIZE(g_support_type); ++i) - filters.push_back(g_support_type[i].title + "(*" + g_support_type[i].ext + ")"); + for(int i = 0; i < m_supportType.size(); ++i) + filters.push_back(m_supportType[i].title + "(*" + m_supportType[i].ext + ")"); ui->fileDialog->setNameFilters(filters); connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted())); @@ -88,13 +101,6 @@ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, #ifdef USE_FILE_DLG_WITHOUT_PROMPT init_custom_file_dlg(ui->fileDialog); #endif - QDialogButtonBox *buttonBox = ui->fileDialog->findChild("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); btn_group->addButton(ui->radio_chosenPages, 0); @@ -105,15 +111,15 @@ Dialog_Export::Dialog_Export(int total, const std::vector &selectedIndexs, ui->lineEdit_nominatePages->setValidator(new QRegExpValidator(rx, this)); 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; 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((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->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); if (0 == exportType) @@ -183,7 +189,7 @@ int Dialog_Export::getTiffQuality() bool Dialog_Export::isOcr() { // 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() @@ -198,7 +204,7 @@ void Dialog_Export::getSaveIndexs(std::vector &indexs) void Dialog_Export::on_dialog_accepted() { - QString extName(g_support_type[m_suffix].ext); + QString extName(m_supportType[m_suffix].ext); // switch (m_suffix) // { // case 0: @@ -275,17 +281,17 @@ void Dialog_Export::on_filterSelected(const QString& filterName) bool enabled = false; 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(m_suffix > 2 && m_suffix < 6); // if (m_suffix <= 2 || m_suffix >= 6) if(!enabled) 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(enabled); - m_saveExt = g_support_type[m_suffix].ext; + m_saveExt = m_supportType[m_suffix].ext; } 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) { - 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; } diff --git a/app/scanner/dialog_export.h b/app/scanner/dialog_export.h index 06c482c3..239bb7ba 100644 --- a/app/scanner/dialog_export.h +++ b/app/scanner/dialog_export.h @@ -2,10 +2,26 @@ #define DIALOG_EXPORT_H #include +#include // u can ONLY comment following line if u want to use filedialog as system present ! #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 { class Dialog_Export; } @@ -54,6 +70,7 @@ private: private: Ui::Dialog_Export *ui; + std::vector m_supportType; int m_total; std::vector m_selectedIndexs; diff --git a/app/scanner/dialog_exportimagefile.cpp b/app/scanner/dialog_exportimagefile.cpp index 342aba9f..950393d7 100644 --- a/app/scanner/dialog_exportimagefile.cpp +++ b/app/scanner/dialog_exportimagefile.cpp @@ -2,12 +2,14 @@ #include "ui_dialog_exportimagefile.h" #include "mainwindow.h" #include "base/HGInfo.h" +#include "base/HGUtility.h" #include "imgfmt/HGImgFmt.h" #include "imgproc/HGOCR.h" #include "HGUIGlobal.h" #include "HGString.h" #include #include +#include "ocrPdf.h" 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, @@ -61,6 +63,62 @@ void HGAPI Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param) 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; ret = HGImgProc_CreateOCRMgr(0, &ocrMgr); if (HGBASE_ERR_OK == ret) @@ -115,6 +173,7 @@ void HGAPI Dialog_ExportImageFile::ThreadFunc(HGThread thread, HGPointer param) HGImgProc_DestroyOCRMgr(ocrMgr); } +#endif } else { diff --git a/app/scanner/dialog_saveas.cpp b/app/scanner/dialog_saveas.cpp index 83b81e5d..1b2639d9 100644 --- a/app/scanner/dialog_saveas.cpp +++ b/app/scanner/dialog_saveas.cpp @@ -1,8 +1,10 @@ #include "dialog_saveas.h" #include "ui_dialog_saveas.h" #include "dialog_writesettings.h" +#include "base/HGBase.h" #include "HGUIGlobal.h" #include "app_cfg.h" +#include "ocrPdf.h" #include #include #include @@ -69,33 +71,28 @@ Dialog_SaveAs::Dialog_SaveAs(QWidget *parent) : ui->fileDialog->setOption(QFileDialog::DontUseNativeDialog, true); ui->fileDialog->setOption(QFileDialog::ReadOnly, true); // disable 'Delete' menu item ui->fileDialog->setSizeGripEnabled(false); -#if defined(OEM_LISICHENG) || defined(OEM_ZHONGJING) || defined(x86_64) - ui->fileDialog->setNameFilter("JPG - JPEG / JFIF(*.jpg);;" - "BMP - Windows Bitmap(*.bmp);;" - "PNG - Portable Network Graphics(*.png);;" - "PPM - Portable PixMap(*.ppm);;" - "PGM - Portable GreyMap(*.pgm);;" - "PBM - Portable BitMap(*.pbm);;" - "TIF - TIFF Revision 6(*.tif);;" - "PDF - Portable Document Format(*.pdf);;" - "OFD - Open Fixed-layout Document(*.ofd);;" - "GIF - Graphics Interchange Format(*.gif)"); -#else - ui->fileDialog->setNameFilter("JPG - JPEG / JFIF(*.jpg);;" - "BMP - Windows Bitmap(*.bmp);;" - "PNG - Portable Network Graphics(*.png);;" - "PPM - Portable PixMap(*.ppm);;" - "PGM - Portable GreyMap(*.pgm);;" - "PBM - Portable BitMap(*.pbm);;" - "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)"); + + QString filter = "JPG - JPEG / JFIF(*.jpg)" + ";;BMP - Windows Bitmap(*.bmp)" + ";;PNG - Portable Network Graphics(*.png)" + ";;PPM - Portable PixMap(*.ppm)" + ";;PGM - Portable GreyMap(*.pgm)" + ";;PBM - Portable BitMap(*.pbm)" + ";;TIF - TIFF Revision 6(*.tif)" + ";;PDF - Portable Document Format(*.pdf)" + ";;OFD - Open Fixed-layout Document(*.ofd)" + ";;GIF - Graphics Interchange Format(*.gif)"; +#if defined(OEM_ZHONGJING) && defined(HG_CMP_MSC) + if (!getOcrPath().empty()) + filter += ";;OCR->PDF - Portable Document Format(*.pdf)"; +#elif (defined (OEM_HUAGAO) || defined (OEM_HANWANG) || defined (OEM_CANGTIAN)) && !defined(x86_64) + filter += ";;OCR->PDF - Portable Document Format(*.pdf)"; + filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)"; + filter += ";;OCR->RTF - Rich Text Format(*.rtf)"; #endif + ui->fileDialog->setNameFilter(filter); + connect(ui->fileDialog, SIGNAL(accepted()), this, SLOT(on_dialog_accepted())); connect(ui->fileDialog, SIGNAL(rejected()), this, SLOT(close())); connect(ui->fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(on_filterSelected(const QString&))); diff --git a/app/scanner/mainwindow.cpp b/app/scanner/mainwindow.cpp index e0941cd9..a605b573 100644 --- a/app/scanner/mainwindow.cpp +++ b/app/scanner/mainwindow.cpp @@ -50,6 +50,7 @@ #include "dialog_wrong_img.h" #include "../../code_device/hgdriver/hgdev/char_const.h" #include "lang/app_language.h" +#include "ocrPdf.h" #define PASSWORD_KEY 4 #define MY_URL_SCHEME "inscanner" @@ -427,6 +428,15 @@ HGResult MainWindow::saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool } 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 HGOCRMgr ocrMgr = nullptr; ret = HGImgProc_CreateOCRMgr(0, &ocrMgr); @@ -437,6 +447,7 @@ HGResult MainWindow::saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool } return ret; +#endif } void MainWindow::on_act_90Left_triggered() diff --git a/app/scanner/ocrPdf.cpp b/app/scanner/ocrPdf.cpp new file mode 100644 index 00000000..4c560d1b --- /dev/null +++ b/app/scanner/ocrPdf.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#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; +} diff --git a/app/scanner/ocrPdf.h b/app/scanner/ocrPdf.h new file mode 100644 index 00000000..f2dbcffb --- /dev/null +++ b/app/scanner/ocrPdf.h @@ -0,0 +1,9 @@ +#ifndef __OCRPDF_H__ +#define __OCRPDF_H__ + +#include + +std::string getOcrPath(); +bool createOcrPdf(const std::string &imgPath, const std::string &dstFile); + +#endif /* __OCRPDF_H__ */ diff --git a/build-qt/HGSolution/HGScanner/HGScanner.pro b/build-qt/HGSolution/HGScanner/HGScanner.pro index afe66fde..d7880114 100644 --- a/build-qt/HGSolution/HGScanner/HGScanner.pro +++ b/build-qt/HGSolution/HGScanner/HGScanner.pro @@ -263,6 +263,7 @@ SOURCES += \ ../../../app/scanner/hg_settingdialog.cpp \ ../../../app/scanner/main.cpp \ ../../../app/scanner/mainwindow.cpp \ + ../../../app/scanner/ocrPdf.cpp \ ../../../app/scanner/sane_device.cpp \ ../../../app/scanner/setpicclrtool.cpp \ ../../../app/scanner/widget.cpp \ @@ -312,6 +313,7 @@ HEADERS += \ ../../../app/scanner/graphicsscene.h \ ../../../app/scanner/hg_settingdialog.h \ ../../../app/scanner/mainwindow.h \ + ../../../app/scanner/ocrPdf.h \ ../../../app/scanner/sane_device.h \ ../../../app/scanner/setpicclrtool.h \ ../../../app/scanner/widget.h \