// MSVC5OCRView.cpp : implementation of the CMSVC5OCRView class // #include "stdafx.h" #include "MSVC5OCR.h" #include "MSVC5OCRDoc.h" #include "MSVC5OCRView.h" #include "Language.h" #include "Insertpage.h" #include "Selectpage.h" #include "Exportpages.h" #include "SaveResult.h" #include "RecognizePage.h" #include "ZoneFile.h" #include "AutoZoneOptions.h" #include "ZoneRemove.h" #include "leadraster.h" #include "leadrasterview.h" #include "RecogWords.h" #include "EngineMsg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMSVC5OCRView IMPLEMENT_DYNCREATE(CMSVC5OCRView, CFormView) BEGIN_MESSAGE_MAP(CMSVC5OCRView, CFormView) //{{AFX_MSG_MAP(CMSVC5OCRView) ON_COMMAND(ID_LANGUAGE_SELECT, OnLanguageSelect) ON_COMMAND(ID_PAGE_INSERT, OnPageInsert) ON_UPDATE_COMMAND_UI(ID_PAGE_INSERT, OnUpdatePageInsert) ON_UPDATE_COMMAND_UI(ID_LANGUAGE_SELECT, OnUpdateLanguageSelect) ON_COMMAND(ID_PAGE_REMOVE, OnPageRemove) ON_UPDATE_COMMAND_UI(ID_PAGE_REMOVE, OnUpdatePageRemove) ON_COMMAND(ID_PAGE_EXPORT, OnPageExport) ON_UPDATE_COMMAND_UI(ID_PAGE_EXPORT, OnUpdatePageExport) ON_COMMAND(ID_PAGE_COUNT, OnPageCount) ON_UPDATE_COMMAND_UI(ID_PAGE_COUNT, OnUpdatePageCount) ON_COMMAND(ID_PAGE_SHOW, OnPageShow) ON_UPDATE_COMMAND_UI(ID_PAGE_SHOW, OnUpdatePageShow) ON_COMMAND(ID_OCR_RECOGNIZE, OnOcrRecognize) ON_UPDATE_COMMAND_UI(ID_OCR_RECOGNIZE, OnUpdateOcrRecognize) ON_COMMAND(ID_OCR_SAVEDOCUMENT, OnOcrSavedocument) ON_UPDATE_COMMAND_UI(ID_OCR_SAVEDOCUMENT, OnUpdateOcrSavedocument) ON_COMMAND(ID_EDIT_COPY, OnEditCopy) ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy) ON_COMMAND(ID_ZONE_SHOW, OnZoneShow) ON_UPDATE_COMMAND_UI(ID_ZONE_SHOW, OnUpdateZoneShow) ON_COMMAND(ID_ZONE_REMOVE, OnZoneRemove) ON_UPDATE_COMMAND_UI(ID_ZONE_REMOVE, OnUpdateZoneRemove) ON_COMMAND(ID_ZONE_OPTIONS, OnZoneOptions) ON_UPDATE_COMMAND_UI(ID_ZONE_OPTIONS, OnUpdateZoneOptions) ON_COMMAND(ID_ZONE_LOAD, OnZoneLoad) ON_UPDATE_COMMAND_UI(ID_ZONE_LOAD, OnUpdateZoneLoad) ON_COMMAND(ID_ZONE_FIND, OnZoneFind) ON_UPDATE_COMMAND_UI(ID_ZONE_FIND, OnUpdateZoneFind) ON_COMMAND(ID_ZONE_EXPORT, OnZoneExport) ON_UPDATE_COMMAND_UI(ID_ZONE_EXPORT, OnUpdateZoneExport) ON_COMMAND(ID_ZONE_COUNT, OnZoneCount) ON_UPDATE_COMMAND_UI(ID_ZONE_COUNT, OnUpdateZoneCount) ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs) ON_COMMAND(ID_FILE_CLOSE, OnFileClose) ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE, OnUpdateFileClose) ON_WM_ERASEBKGND() ON_WM_DESTROY() ON_COMMAND(ID_SCAN_ACQUIRETWAIN, OnScanAcquiretwain) ON_UPDATE_COMMAND_UI(ID_SCAN_ACQUIRETWAIN, OnUpdateScanAcquiretwain) ON_COMMAND(ID_SCAN_SELECTTWAIN, OnScanSelecttwain) ON_UPDATE_COMMAND_UI(ID_SCAN_SELECTTWAIN, OnUpdateScanSelecttwain) ON_COMMAND(ID_ENGINE_SHUTDOWN, OnEngineShutdown) ON_UPDATE_COMMAND_UI(ID_ENGINE_SHUTDOWN, OnUpdateEngineShutdown) ON_COMMAND(ID_ENGINE_STARTUP, OnEngineStartup) ON_UPDATE_COMMAND_UI(ID_ENGINE_STARTUP, OnUpdateEngineStartup) ON_COMMAND(ID_PAGE_INSERTCURRENTPAGE, OnPageInsertcurrentpage) ON_UPDATE_COMMAND_UI(ID_PAGE_INSERTCURRENTPAGE, OnUpdatePageInsertcurrentpage) ON_WM_SIZE() ON_COMMAND(ID_EDIT_PASTE, OnEditPaste) ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste) ON_COMMAND(ID_PAGE_AUTOORIENT, OnPageAutoorient) ON_UPDATE_COMMAND_UI(ID_PAGE_AUTOORIENT, OnUpdatePageAutoorient) ON_COMMAND(ID_OCR_GET_RECOGNIZED_WORDS, OnOcrGetRecognizedWords) ON_UPDATE_COMMAND_UI(ID_OCR_GET_RECOGNIZED_WORDS, OnUpdateOcrGetRecognizedWords) ON_COMMAND(ID_VIEW_NORMAL, OnViewNormal) ON_UPDATE_COMMAND_UI(ID_VIEW_NORMAL, OnUpdateViewNormal) ON_COMMAND(ID_VIEW_SCALETOGRAY, OnViewScaletogray) ON_UPDATE_COMMAND_UI(ID_VIEW_SCALETOGRAY, OnUpdateViewScaletogray) ON_COMMAND(ID_VIEW_FAVORTOBLACK, OnViewFavortoblack) ON_UPDATE_COMMAND_UI(ID_VIEW_FAVORTOBLACK, OnUpdateViewFavortoblack) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMSVC5OCRView construction/destruction CMSVC5OCRView::CMSVC5OCRView(): CFormView(CMSVC5OCRView::IDD) { m_pLRasterDoc = NULL; m_bClose = FALSE; m_nPageIndex = -1; m_bFindZone = FALSE; m_bShowZones = TRUE; m_pZoneData = NULL; m_pZoneSink = NULL; m_bAccpetAll = FALSE; m_bRecognized = FALSE; m_nSelZoneIndex = -1; m_bSelectZone = FALSE; m_bShowPage = TRUE; m_bScanStarted = FALSE; m_bEnginStarted = FALSE; m_csRecogDataFileName = _T(""); m_nStartRecogIndex = -1; m_nEndRecogIndex = -1; m_nViewScale = BITONALSCALING_NORMAL; if( IsWindow(m_RasterView.m_hWnd) ) { RECT Rect; GetClientRect(&Rect); m_RasterView.SetBackErase(FALSE); m_RasterView.MoveWindow(0, 0, Rect.right , Rect.bottom ); } } CMSVC5OCRView::~CMSVC5OCRView() { } BOOL CMSVC5OCRView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMSVC5OCRView drawing void CMSVC5OCRView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMSVC5OCRView) DDX_Control(pDX, IDC_LEADRASTERVIEW, m_RasterView); //}}AFX_DATA_MAP } void CMSVC5OCRView::OnInitialUpdate() { CFormView::OnInitialUpdate(); } ///////////////////////////////////////////////////////////////////////////// // CMSVC5OCRView printing BOOL CMSVC5OCRView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CMSVC5OCRView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CMSVC5OCRView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CMSVC5OCRView diagnostics #ifdef _DEBUG void CMSVC5OCRView::AssertValid() const { CFormView::AssertValid(); } void CMSVC5OCRView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CMSVC5OCRDoc* CMSVC5OCRView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMSVC5OCRDoc))); return (CMSVC5OCRDoc*)m_pDocument; } #endif //_DEBUG BOOL CMSVC5OCRView::AddPage() { int nRet; BeginWaitCursor(); CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); nRet = m_pLRasterDoc->AddPage(pTheApp->m_pRaster, -1); if (nRet != 0) { CString csErr; csErr.Format(_TEXT("Can't add page to engine\nError = %d\n"), nRet); AfxMessageBox(csErr); } else { int nPageCount = 0; nPageCount = m_pLRasterDoc->PageCount; if (m_nPageIndex == -1) { m_bShowPage = TRUE; m_nPageIndex = nPageCount - 1; m_bClose = TRUE; } UpdateView(); m_pLRasterDoc->ActivePageIndex = m_nPageIndex; m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); } m_bClose = (nRet == 0) ? TRUE : FALSE; EndWaitCursor(); return m_bClose; } void CMSVC5OCRView::UpdateView() { CMSVC5OCRDoc * pDoc = (CMSVC5OCRDoc *)GetDocument(); if (m_nPageIndex != -1 && m_bClose) { m_RasterView.SetEnableOCRDrawing(FALSE); if (m_RasterView.GetRaster().GetBitmap() != 0) m_RasterView.GetRaster().Free(); // Get Copy from Active image in LEADRasterView // For "Copy" and "Insert Current Image" m_pLRasterDoc->ExportPage(m_RasterView.GetRaster(), m_nPageIndex); m_pLRasterDoc->ActivePageIndex = m_nPageIndex; m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); m_bClose = TRUE; CString csTitle; if (m_nPageIndex >= 0) csTitle.Format(_TEXT("Page Number %d"), m_nPageIndex+1); else csTitle.Format(_TEXT("No attached Page")); pDoc->SetTitle(csTitle); } else { m_bClose = m_RasterView.GetEnableOCRDrawing(); pDoc->SetTitle(_TEXT("Untitled")); } if (IsWindow(m_RasterView.m_hWnd)) RedrawWindow(); } void CMSVC5OCRView::Free(BOOL bPaste) { m_bClose = FALSE; m_nPageIndex = -1; m_bFindZone = FALSE; m_bShowZones = TRUE; m_bAccpetAll = FALSE; m_bRecognized = FALSE; m_bScanStarted = FALSE; m_bShowPage = TRUE; m_nSelZoneIndex= -1; m_bSelectZone = FALSE; m_nViewScale = BITONALSCALING_NORMAL; CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); if (pTheApp && pTheApp->m_pRaster && !bPaste) pTheApp->m_pRaster->Free(); if(m_RasterView.GetRaster().GetBitmap()) { m_RasterView.GetRaster().Free(); pTheApp->m_pRaster->Free(); } m_RasterView.SetEnableOCRDrawing(FALSE); m_RasterView.ForceRepaint(); UpdateView(); } BOOL CMSVC5OCRView::OnEraseBkgnd(CDC* pDC) { CRect rcClient; GetClientRect(&rcClient); CBrush br(GetSysColor(DKGRAY_BRUSH)); FillOutsideRect(pDC, &br); return TRUE; } CString CMSVC5OCRView::GetMultiFileName(CString csFileName, int nFormat, int nPage, int nExpCount) { BOOL bMulti = FALSE; switch (nFormat) { case FILE_FAX_G4: case FILE_FAX_G3_2D: case FILE_FAX_G3_1D: case FILE_CCITT_GROUP4: case FILE_CCITT_GROUP3_2DIM: case FILE_CCITT_GROUP3_1DIM: case FILE_GIF: case FILE_ICA_G3_1D: case FILE_ICA_G3_2D: case FILE_ICA_G4: case FILE_PCX: case FILE_TGA: case FILE_TIFLZW: case FILE_TIFLZW_CMYK: case FILE_TIFLZW_YCC: case FILE_TIF: case FILE_TIF_CMYK: case FILE_TIF_YCC: case FILE_TIF_PACKBITS: case FILE_TIF_PACKBITS_CMYK: case FILE_TIF_PACKBITS_YCC: case FILE_TIF_CMP: case FILE_TIF_JBIG: case FILE_TIF_DXF: case FILE_TIF_J2K: case FILE_TIF_CMW: case FILE_TIF_JPEG_422: case FILE_TIF_JPEG_411: case FILE_WIN_ICO: case FILE_WIN_CUR: case FILE_IFF_CAT: case FILE_FLC: case FILE_ANI: case FILE_RAS_PDF: case FILE_RAS_PDF_G3_1D: case FILE_RAS_PDF_G3_2D: case FILE_RAS_PDF_G4: case FILE_RAS_PDF_JPEG: case FILE_RAS_PDF_JPEG_422: case FILE_RAS_PDF_JPEG_411: bMulti = TRUE; break; } CString csName; if (!bMulti && nExpCount > 1) { TCHAR szScanNo[10]; TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szFName[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; LPTSTR lptstrFName = csName.GetBuffer(MAX_PATH); memset(szDrive, 0, sizeof(szDrive)); memset(szDir, 0, sizeof(szDir)); memset(szFName, 0, sizeof(szFName)); memset(szExt, 0, sizeof(szExt)); _tsplitpath(csFileName, szDrive, szDir, szFName, szExt); memset(szScanNo, 0, sizeof(szScanNo)); wsprintf(szScanNo, _TEXT("%d"), nPage); lstrcat(szFName, szScanNo); _tmakepath(lptstrFName, szDrive, szDir, szFName, szExt); csName.ReleaseBuffer(); } else csName = csFileName; return csName; } ///////////////////////////////////////////////////////////////////////////// // CMSVC5OCRView message handlers BOOL CMSVC5OCRView::InitEngine() { int nRet; BeginWaitCursor(); if(m_pLRasterDoc) Free(); HRESULT hr = CoCreateInstance(CLSID_LEADRasterDocument, NULL, CLSCTX_ALL, IID_ILEADRasterDocument, (void**)&m_pLRasterDoc); if (FAILED(hr)) { m_pLRasterDoc = NULL; AfxMessageBox(_TEXT("Can't instantiate the OCR COM Object...")); return FALSE; } m_pLRasterDoc->EnableMethodErrors = FALSE; m_pLRasterDoc->EnableShowZones = m_bShowZones; hr = CoCreateInstance(CLSID_LTZoneData, NULL, CLSCTX_ALL, IID_ILTZoneData, (void**)&m_pZoneData); if (FAILED(hr)) { m_pZoneData = NULL; AfxMessageBox(_TEXT("Can't instantiate the Zone Data COM Object...")); return FALSE; } m_pZoneSink = new CSampleZoneSink; m_pZoneSink->m_pView = this; LPUNKNOWN pUnkSink = m_pZoneSink->GetIDispatch(FALSE); AfxConnectionAdvise(m_pZoneData, DIID__LTZoneDataEvents, pUnkSink, FALSE, &m_dwOCRCookie); if (m_pLRasterDoc) { if (m_RasterView.GetRaster().IsSupportLocked(L_SUPPORT_OCR)) { AfxMessageBox(TEXT("You need to unlock the OCR engine before you can use this demo!")); EndWaitCursor(); return FALSE; } nRet = m_pLRasterDoc->StartUp(); if (nRet == 0) { m_pLRasterDoc->ZonePenStyle = PS_SOLID; m_pLRasterDoc->ZonePenWidth = 2; m_pLRasterDoc->ZonePenColor = RGB(255, 255, 0); m_pLRasterDoc->SetZonePen(); m_pLRasterDoc->SelectedZonePenStyle = PS_SOLID; m_pLRasterDoc->SelectedZonePenWidth = 2; m_pLRasterDoc->SelectedZonePenColor = RGB(255, 0, 0); m_pLRasterDoc->SetSelectedZonePen(); m_RasterView.SetRasterDocument(m_pLRasterDoc); } else { if (nRet != 21218) AfxMessageBox(TEXT("Failed while initializing the OCR Engine")); else { CEngineMsg engineDlg; engineDlg.DoModal(); } EndWaitCursor(); return FALSE; } } m_bEnginStarted = TRUE; EndWaitCursor(); return (nRet == 0) ? TRUE : FALSE; } /************************* Edit Menu *************************/ void CMSVC5OCRView::OnEditCopy() { CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); if(m_pLRasterDoc && m_pLRasterDoc->PageCount) { int nRet = m_pLRasterDoc->ExportPage(pTheApp->m_pRaster, m_nPageIndex); if (nRet != 0) { AfxMessageBox(_TEXT("Can't copy the active page")); return; } BeginWaitCursor(); nRet = pTheApp->m_pRaster->Copy((RasterCopyConstants)(COPY_EMPTY|COPY_DIB|COPY_PALETTE)); if(nRet != 0) AfxMessageBox(_TEXT("Couldn't Copy to the Clipboard")); EndWaitCursor(); } else { BeginWaitCursor(); m_RasterView.GetRaster().Copy((RasterCopyConstants)(COPY_EMPTY|COPY_DIB|COPY_PALETTE)); EndWaitCursor(); } } void CMSVC5OCRView::OnUpdateEditCopy(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_bClose); } /************************* Language Menu *************************/ void CMSVC5OCRView::OnLanguageSelect() { if (!ShowOCRErrMsg(FALSE)) return; CLanguage dlgLang; if (dlgLang.DoModal() != IDOK) return; m_pLRasterDoc->ActiveLanguagesCount = dlgLang.m_nLangCount; m_pLRasterDoc->ActivLanguage[0] = *dlgLang.m_pLangIds; int nRet = m_pLRasterDoc->SelectLanguages(); if (nRet != 0) AfxMessageBox(_TEXT("Can't set selected languages successfully")); } void CMSVC5OCRView::OnUpdateLanguageSelect(CCmdUI* pCmdUI) { pCmdUI->Enable(m_pLRasterDoc ? TRUE : FALSE); } /************************* Page Menu *************************/ void CMSVC5OCRView::OnPageInsert() { if (!ShowOCRErrMsg(FALSE)) return; CInsertPage dlgInsert; if (dlgInsert.DoModal() != IDOK) return; CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); int nRet = pTheApp->m_pRasterIO->GetFileInfo(pTheApp->m_pRaster,(TCHAR *)(LPCTSTR)dlgInsert.m_csFileName, 0, FILEINFO_TOTALPAGES); if (nRet != 0) { CString csError; csError.Format(_TEXT("Can't insert selected file %s\n"), dlgInsert.m_csFileName); AfxMessageBox(csError); return; } if (dlgInsert.m_bInsertAll) { int nTotalPage = pTheApp->m_pRasterIO->InfoTotalPages; for (int i=0; im_pRasterIO->Load(pTheApp->m_pRaster,(TCHAR *)(LPCTSTR)dlgInsert.m_csFileName, 0,i+1,1); if (nRet != 0) continue; BeginWaitCursor(); nRet = m_pLRasterDoc->AddPage(pTheApp->m_pRaster, (dlgInsert.m_nIndex -1) + i); if (nRet != 0) { CString csError; csError.Format(_TEXT("Can't add page # %d from file %s\n"), i, dlgInsert.m_csFileName); AfxMessageBox(csError); break; } EndWaitCursor(); } int nPageCount = 0; nPageCount = m_pLRasterDoc->PageCount; if (m_nPageIndex == -1 && nPageCount > 0) { m_bClose = TRUE; m_bShowPage = TRUE; m_nPageIndex = nPageCount - 1; } else m_nPageIndex = dlgInsert.m_nIndex -1; m_pLRasterDoc->ActivePageIndex = m_nPageIndex; m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); UpdateView(); } else { nRet = pTheApp->m_pRasterIO->Load(pTheApp->m_pRaster,(TCHAR *)(LPCTSTR)dlgInsert.m_csFileName, 0, 0,1); if (nRet != 0) { CString csError; csError.Format(_TEXT("Can't load page # %d from file %s\n"), dlgInsert.m_nPageNumber, dlgInsert.m_csFileName); AfxMessageBox(csError); return; } BeginWaitCursor(); nRet = m_pLRasterDoc->AddPage(pTheApp->m_pRaster, dlgInsert.m_nIndex - 1); if (nRet != 0) { CString csError; csError.Format(_TEXT("Can't add page # %d from file %s\n"), dlgInsert.m_nPageNumber, dlgInsert.m_csFileName); AfxMessageBox(csError); return; } EndWaitCursor(); int nPageCount = 0; nPageCount = m_pLRasterDoc->PageCount; if (m_nPageIndex == -1 && nPageCount > 0) { m_bClose = TRUE; m_bShowPage = TRUE; m_nPageIndex = nPageCount - 1; } else m_nPageIndex = dlgInsert.m_nIndex -1; m_pLRasterDoc->ActivePageIndex = m_nPageIndex; m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); UpdateView(); } } void CMSVC5OCRView::OnUpdatePageInsert(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_bEnginStarted); } void CMSVC5OCRView::OnPageRemove() { if (!ShowOCRErrMsg()) return; int nPageCount=0; nPageCount = m_pLRasterDoc->PageCount; CSelectPage dlgSelPage(SELECT_PAGE_DEL, nPageCount); if (dlgSelPage.DoModal() == IDOK) { int nRet = m_pLRasterDoc->RemovePage(dlgSelPage.m_nPageNum - 1); if (nRet == 0) { nPageCount = m_pLRasterDoc->PageCount; if (nPageCount == 0) { m_nPageIndex = -1; } else m_nPageIndex = (m_nPageIndex >= nPageCount) ? --m_nPageIndex : m_nPageIndex; if (m_nPageIndex != -1) { m_pLRasterDoc->ActivePageIndex = m_nPageIndex; m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); } else { m_RasterView.SetEnableOCRDrawing(FALSE); m_RasterView.ForceRepaint(); } m_bShowPage = TRUE; UpdateView(); if (m_nPageIndex == -1) { Free(); m_bClose = FALSE; RedrawWindow(); } } else AfxMessageBox(_TEXT("Error, couldn't remove the specified page")); } } void CMSVC5OCRView::OnUpdatePageRemove(CCmdUI* pCmdUI) { pCmdUI->Enable((m_pLRasterDoc && m_pLRasterDoc->PageCount)? TRUE : FALSE); } void CMSVC5OCRView::OnPageExport() { int nPageCount=0; nPageCount = m_pLRasterDoc->PageCount; if (nPageCount == 0) { AfxMessageBox(_TEXT("There is no page to export")); return; } CExportPages dlgExprtPage(nPageCount); if (dlgExprtPage.DoModal() != IDOK) return; ExportPages(dlgExprtPage.m_csFileName, dlgExprtPage.m_nPageNumber - 1, dlgExprtPage.m_bExportAll ? nPageCount : 1, dlgExprtPage.m_nSaveFormat); } void CMSVC5OCRView::ExportPages(CString csFileName, int nPage, int nCount, int nSaveFormat)//FILESAVEPARM { int nStartPage = (nCount == 1) ? nPage : 0; int nEndPage = (nCount == 1) ? nPage+1 : nCount; int nRet; CString csError; TCHAR strDrv[MAX_PATH]; TCHAR strPath[MAX_PATH]; TCHAR strFName[MAX_PATH]; TCHAR strExt[MAX_PATH]; CString csPrfx; CString csFinalFileName; BOOL bMulti = FALSE; switch(nSaveFormat) { case FILE_GIF: case FILE_PCX: case FILE_TIFLZW: case FILE_TIFLZW_CMYK: case FILE_TIFLZW_YCC: case FILE_TIF: case FILE_TIF_CMYK: case FILE_TIF_YCC: case FILE_TIF_PACKBITS: case FILE_TIF_PACKBITS_YCC: case FILE_TIF_CMP: case FILE_TIF_JBIG: case FILE_TIF_DXF: case FILE_TIF_J2K: case FILE_TIF_CMW: case FILE_TIF_JPEG_422: case FILE_TIF_JPEG_411: bMulti = TRUE; break; } CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); for (int i=nStartPage; iExportPage(pTheApp->m_pRaster,i); if (nRet != 0) { csError.Format(_TEXT("Can't export page #\n"), i); AfxMessageBox(csError); continue; } pTheApp->m_pRasterDlgFile->PutBitmap(pTheApp->m_pRaster->GetBitmap()); pTheApp->m_pRasterIO->SavePage = pTheApp->m_pRasterDlgFile->PageNumber; if (!bMulti && nCount != 1) { csFinalFileName.Empty(); csPrfx.Empty(); _tsplitpath(csFileName, strDrv,strPath,strFName,strExt); csPrfx.Format(_TEXT("%d"),i); csFinalFileName+= strDrv; csFinalFileName+= strPath; csFinalFileName+= strFName; csFinalFileName+= csPrfx; csFinalFileName+= strExt; } else csFinalFileName = csFileName; nRet = pTheApp->m_pRasterIO->Save(pTheApp->m_pRaster,(TCHAR *)(LPCTSTR)csFinalFileName, (RasterFileConstants)pTheApp->m_pRasterDlgFile->GetSaveFormat(), pTheApp->m_pRasterDlgFile->GetSaveBitsPerPixel(), (QFactorConstants)pTheApp->m_pRasterDlgFile->GetSaveQFactor(), (bMulti == TRUE) ? 3 : 0); } if(nRet != 0) { CString csBuffer; csBuffer.Format(_TEXT("Can't export %s\n\nError: \t%d"),(LPCTSTR)csFileName,nRet); AfxMessageBox(csBuffer); } } void CMSVC5OCRView::OnUpdatePageExport(CCmdUI* pCmdUI) { pCmdUI->Enable((m_pLRasterDoc && m_pLRasterDoc->PageCount) ? TRUE : FALSE); } void CMSVC5OCRView::OnPageCount() { int nPageCount=0; nPageCount = m_pLRasterDoc->PageCount; CString csMsg; csMsg.Format(_TEXT("Page Count = %d\n"), nPageCount); AfxMessageBox(csMsg); } void CMSVC5OCRView::OnUpdatePageCount(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_pLRasterDoc); } void CMSVC5OCRView::OnPageShow() { if (!ShowOCRErrMsg()) return; int nPageCount=0; nPageCount = m_pLRasterDoc->PageCount; CSelectPage dlgSelPage(SELECT_PAGE_SHOW, nPageCount); if (dlgSelPage.DoModal() == IDOK) { m_nPageIndex = dlgSelPage.m_nPageNum - 1; m_bShowPage = TRUE; m_bClose = TRUE; m_pLRasterDoc->ActivePageIndex = m_nPageIndex; m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); UpdateView(); } } void CMSVC5OCRView::OnUpdatePageShow(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted); } /************************* OCR Menu *************************/ void CMSVC5OCRView::OnOcrRecognize() { if (!ShowOCRErrMsg()) return; int nPageCount=0; int nZoneCount = 0, i, j; int nRet; nPageCount = m_pLRasterDoc->PageCount; nZoneCount = m_pLRasterDoc->ZoneCount[m_nPageIndex]; CRecognizePage dlgRecog(m_csRecogDataFileName, nPageCount, nZoneCount); if (dlgRecog.DoModal() != IDOK) return; m_csRecogDataFileName = dlgRecog.m_csRDFileName; m_pLRasterDoc->RecognitionDataFileName = (TCHAR *)(LPCTSTR)dlgRecog.m_csRDFileName; m_pLRasterDoc->SpellLanguageID = LANGID_ENGLISH; m_pLRasterDoc->EnableSubSystem = dlgRecog.m_bShowVerificationDlg; m_pLRasterDoc->EnableCorrection = dlgRecog.m_bShowVerificationDlg; for(i = dlgRecog.m_nStartPage - 1; iZoneCount[i]; for (j=0; jGetZoneInfo(i, j, m_pZoneData); m_pZoneData->EnableVerificationEvent = true; m_pLRasterDoc->UpdateZone(i, j, m_pZoneData); } } BeginWaitCursor(); m_bAccpetAll = FALSE; m_bRecognized = FALSE; m_nStartRecogIndex = dlgRecog.m_nStartPage - 1; m_nEndRecogIndex = dlgRecog.m_nPageCount; nRet = m_pLRasterDoc->Recognize(dlgRecog.m_nStartPage - 1, dlgRecog.m_nPageCount); if (nRet != 0) AfxMessageBox(_TEXT("Can't recognize the specific pages")); m_bRecognized = TRUE; m_bShowZones = TRUE; m_bFindZone = TRUE; m_pLRasterDoc->EnableShowZones = m_bShowZones; m_RasterView.ForceRepaint(); RedrawWindow(); EndWaitCursor(); } void CMSVC5OCRView::OnUpdateOcrRecognize(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted); } void CMSVC5OCRView::OnOcrSavedocument() { CSaveResult saveResDlg(m_pLRasterDoc); if (saveResDlg.DoModal() != IDOK) return; BeginWaitCursor(); int nRet = m_pLRasterDoc->SaveDocument((TCHAR *)(LPCTSTR)saveResDlg.m_csFileName); if (nRet != 0) AfxMessageBox(_TEXT("Can't save recognition result to specific format")); EndWaitCursor(); } void CMSVC5OCRView::OnUpdateOcrSavedocument(CCmdUI* pCmdUI) { pCmdUI->Enable(m_pLRasterDoc && m_nPageIndex != -1 && m_bRecognized); } /************************* Zone Menu *************************/ void CMSVC5OCRView::OnZoneShow() { m_bShowZones = !m_bShowZones; m_pLRasterDoc->EnableShowZones = m_bShowZones; m_RasterView.ForceRepaint(); RedrawWindow(); } void CMSVC5OCRView::OnUpdateZoneShow(CCmdUI* pCmdUI) { pCmdUI->Enable(m_pLRasterDoc && m_nPageIndex != -1 && m_bFindZone); pCmdUI->SetCheck(m_bShowZones); } void CMSVC5OCRView::OnZoneRemove() { int nRet = 0; int nZoneCount = 0; nZoneCount = m_pLRasterDoc->ZoneCount[m_nPageIndex]; CZoneRemove dlgDelZone(nZoneCount); if (dlgDelZone.DoModal() != IDOK) return; nRet = m_pLRasterDoc->RemoveZone(m_nPageIndex, (dlgDelZone.m_bDelZones ) ? -1 : dlgDelZone.m_nZoneIndex - 1); if (nRet == 0) AfxMessageBox(_TEXT("The selected zones(s) are deleted successfully")); else { CString csError; if (dlgDelZone.m_bDelZones) csError.Format(_TEXT("Can't delete all zones")); else csError.Format(_TEXT("Can't delete zone # %d\n")); AfxMessageBox(csError); } nZoneCount = m_pLRasterDoc->ZoneCount[m_nPageIndex]; m_bFindZone = (nZoneCount != 0); m_RasterView.ForceRepaint(); RedrawWindow(); } void CMSVC5OCRView::OnUpdateZoneRemove(CCmdUI* pCmdUI) { pCmdUI->Enable(m_pLRasterDoc && m_nPageIndex != -1 && m_bFindZone); } void CMSVC5OCRView::OnZoneOptions() { if (!ShowOCRErrMsg()) return; int nRet = m_pLRasterDoc->GetAutoZoneOptions(); if (nRet != 0) return; CAutoZoneOptions dlgZoneOpts(m_pLRasterDoc); if (dlgZoneOpts.DoModal() == IDOK) m_pLRasterDoc->SetAutoZoneOptions(); } void CMSVC5OCRView::OnUpdateZoneOptions(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted); } void CMSVC5OCRView::OnZoneLoad() { if (!ShowOCRErrMsg()) return; CZoneFile dlgZoneFile(TRUE); if (dlgZoneFile.DoModal() != IDOK) return; CString csErr; int nRet = m_pLRasterDoc->ImportZones(m_nPageIndex, (TCHAR *)(LPCTSTR)dlgZoneFile.m_csZoneFileName); if (nRet == 0) { csErr.Format(_TEXT("The Zone file %s is loaded successfully"), dlgZoneFile.m_csZoneFileName); AfxMessageBox(csErr); m_bFindZone = TRUE; m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); } else { csErr.Format(_TEXT("Failed loading Zone file %s\n"), dlgZoneFile.m_csZoneFileName); AfxMessageBox(csErr); } } void CMSVC5OCRView::OnUpdateZoneLoad(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted); } void CMSVC5OCRView::OnZoneFind() { if (!ShowOCRErrMsg()) return; int nRet = m_pLRasterDoc->FindZones(m_nPageIndex, TRUE); if (nRet == 0) { AfxMessageBox(_TEXT("Find Zones process successful")); m_bFindZone = TRUE; m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); } else AfxMessageBox(_TEXT("Failed during Find Zones")); } void CMSVC5OCRView::OnUpdateZoneFind(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted); } void CMSVC5OCRView::OnZoneExport() { if (!ShowOCRErrMsg()) return; CZoneFile dlgZoneFile(FALSE); if (dlgZoneFile.DoModal() != IDOK) return; CString csErr; int nRet = m_pLRasterDoc->ExportZones(m_nPageIndex, (TCHAR *)(LPCTSTR)dlgZoneFile.m_csZoneFileName); if (nRet == 0) { csErr.Format(_TEXT("The Zone file %s is exported successfully"), dlgZoneFile.m_csZoneFileName); AfxMessageBox(csErr); } else { csErr.Format(_TEXT("Failed exporting Zone file %s\n"), dlgZoneFile.m_csZoneFileName); AfxMessageBox(csErr); } } void CMSVC5OCRView::OnUpdateZoneExport(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_nPageIndex != -1 && m_bFindZone); } void CMSVC5OCRView::OnZoneCount() { if (!ShowOCRErrMsg()) return; int nZoneCount = m_pLRasterDoc->ZoneCount[m_nPageIndex]; CString csBuffer; csBuffer.Format(_TEXT("Zone Count = %d\n"), nZoneCount); AfxMessageBox(csBuffer); } void CMSVC5OCRView::OnUpdateZoneCount(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted); } void CMSVC5OCRView::OnFileSaveAs() { CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); pTheApp->m_pRasterDlgFile->PutBitmap (pTheApp->m_pRaster->Bitmap); pTheApp->m_pRasterDlgFile->PutEnableMethodErrors(FALSE); pTheApp->m_pRasterDlgFile->PutFileDlgFlags(0); pTheApp->m_pRasterDlgFile->PutUIFlags(SAVE_AUTOPROCESS | SAVE_SHOW_FILEOPTIONS_MULTIPAGE | SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | SAVE_SHOW_FILEOPTIONS_QFACTOR| SAVE_SHOW_FILEOPTIONS_STAMP | SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| SAVE_SHOW_FILEOPTIONS_J2KOPTIONS); pTheApp->m_pRasterDlgFile->PutDialogTitle("Save File"); pTheApp->m_pRasterDlgFile->ShowSaveDlg((long)this->m_hWnd); } void CMSVC5OCRView::OnUpdateFileSaveAs(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_bClose); } void CMSVC5OCRView::OnFileClose() { if(m_pLRasterDoc) Free(); m_bClose = FALSE; RedrawWindow(); } void CMSVC5OCRView::OnUpdateFileClose(CCmdUI* pCmdUI) { pCmdUI->Enable(m_bClose && !m_bScanStarted); } void CMSVC5OCRView::OnDestroy() { OnEngineShutdown(); CFormView::OnDestroy(); } void CMSVC5OCRView::OnScanAcquiretwain() { if (!ShowOCRErrMsg(FALSE)) return; CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); m_bScanStarted = TRUE; try { pTheApp->m_pRasterTwain->Acquire(L_LTWAIN_SHOW_USER_INTERFACE | L_LTWAIN_MODAL_USER_INTERFACE); } catch (...) { AfxMessageBox(_TEXT("Scan Acquire cancelled!")); } m_bScanStarted = FALSE; } void CMSVC5OCRView::OnUpdateScanAcquiretwain(CCmdUI* pCmdUI) { CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); pCmdUI->Enable(!m_bScanStarted && pTheApp->m_bTwnAvailable); } void CMSVC5OCRView::OnScanSelecttwain() { if (!ShowOCRErrMsg(FALSE)) return; CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); try { pTheApp->m_pRasterTwain->SelectSource(); } catch (...) { AfxMessageBox(_TEXT("Select source cancelled!")); } } void CMSVC5OCRView::OnUpdateScanSelecttwain(CCmdUI* pCmdUI) { CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); pCmdUI->Enable(!m_bScanStarted && pTheApp->m_bTwnAvailable); } BOOL CMSVC5OCRView::ShowOCRErrMsg(BOOL bCheckPages /*= TRUE*/) { if (!m_pLRasterDoc) { AfxMessageBox(_TEXT("Engine Ended,\nUse Engine -> Start Up")); return FALSE; } if (bCheckPages) { int nPageCount = 0; nPageCount = m_pLRasterDoc->PageCount; if (nPageCount <= 0) { AfxMessageBox(_TEXT("No images have been inserted to the OCR Document, to insert an image:\nUse Page -> Insert Current Image or\nUse Page -> Insert")); return FALSE; } } return TRUE; } void CMSVC5OCRView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView); } void CMSVC5OCRView::ShowSelectedZoneInfo() { if (m_nSelZoneIndex == -1) return; ILTZoneData* pZoneData = NULL; HRESULT hr = CoCreateInstance(CLSID_LTZoneData, NULL, CLSCTX_ALL, IID_ILTZoneData, (void**)&pZoneData); if (FAILED(hr)) { m_pZoneData = NULL; AfxMessageBox(_TEXT("Can't instantiate the Zone Data COM Object...")); return; } int nRet = m_pLRasterDoc->GetZoneInfo(m_nPageIndex, m_nSelZoneIndex, pZoneData); if (nRet == 0) { CString csZoneData=""; CString csTemp; csTemp.Format(_TEXT("Area: {%d, %d, %d, %d}\n"), pZoneData->Left, pZoneData->Top, pZoneData->Right, pZoneData->Bottom); csZoneData += csTemp; csTemp.Format(_TEXT("Zone Number: %d\n"), m_nSelZoneIndex+1); csZoneData += csTemp; csTemp.Format(_TEXT("Id: %d\n"), pZoneData->ID); csZoneData += csTemp; CString csFill=""; switch (pZoneData->GetFillMethod()) { case FM_DEFAULT: csFill = "Default"; break; case FM_OMNIFONT: csFill = "Omnifont"; break; case FM_DRAFTDOT9: csFill = "Draft Dot9"; break; case FM_OMR: csFill = "OMR"; break; case FM_HANDPRINT: csFill = "HandPrint"; break; case FM_DRAFTDOT24: csFill = "Draft Dot24"; break; case FM_OCRA: csFill = "OCRA"; break; case FM_OCRB: csFill = "OCRB"; break; case FM_MICR: csFill = "MICR"; break; case FM_DOTDIGIT: csFill = "Dot Digit"; break; case FM_DASHDIGIT: csFill = "Dash Digit"; break; case FM_NO_OCR: csFill = "No OCR"; break; default: return; } csTemp.Format(_TEXT("Fill Method: %s\n"), csFill); csZoneData += csTemp; CString csRecog=""; switch (pZoneData->GetRecognizeModule()) { case RECOGNIZE_MODULE_AUTO: csRecog = "Auto"; break; case RECOGNIZE_MODULE_MTEXT_OMNIFONT: csRecog = "MTEXT Omnifont"; break; case RECOGNIZE_MODULE_MULTI_LINGUAL_OMNIFONT: csRecog = "Multi Lingual Omnifont"; break; case RECOGNIZE_MODULE_DOT_MATRIX: csRecog = "Dot Matrix"; break; case RECOGNIZE_MODULE_OMR: csRecog = "OMR"; break; case RECOGNIZE_MODULE_HAND_PRINTED_NUMERAL: csRecog = "HNR"; break; case RECOGNIZE_MODULE_RER_PRINTED: csRecog = "RER"; break; case RECOGNIZE_MODULE_MATRIX: csRecog = "Matrix"; break; case RECOGNIZE_MODULE_OMNIFONT_PLUS2W: csRecog = "Plus2w"; break; case RECOGNIZE_MODULE_OMNIFONT_FRX: csRecog = "FRX"; break; case RECOGNIZE_MODULE_OMNIFONT_PLUS3W: csRecog = "Plus3w"; break; default: return; } csTemp.Format(_TEXT("Recognize Module: %s\n"), csRecog); csZoneData += csTemp; CString csCharFilter=""; switch (pZoneData->GetCharacterFilter()) { case CHAR_FILTER_DEFAULT: csCharFilter = "Default"; break; case CHAR_FILTER_DIGIT: csCharFilter = "Digit"; break; case CHAR_FILTER_UPPERCASE: csCharFilter = "Uppercase"; break; case CHAR_FILTER_LOWERCASE: csCharFilter = "Lowercase"; break; case CHAR_FILTER_PUNCTUATION: csCharFilter = "Punctuation"; break; case CHAR_FILTER_MISCELLANEOUS: csCharFilter = "Misc"; break; case CHAR_FILTER_PLUS: csCharFilter = "Plus"; break; case CHAR_FILTER_ALL: csCharFilter = "All"; break; case CHAR_FILTER_ALPHA: csCharFilter = "Alpha"; break; case CHAR_FILTER_NUMBERS: csCharFilter = "Numbers"; break; default: return; } csTemp.Format(_TEXT("Character Filter: %s\n"), csCharFilter); csZoneData += csTemp; CString csType=""; switch (pZoneData->GetType()) { case ZONE_TYPE_FLOWTEXT: csType = "Flow Text"; break; case ZONE_TYPE_TABLE: csType = "Table"; break; case ZONE_TYPE_GRAPHIC: csType = "Graphic"; break; case ZONE_TYPE_COLUMN: csType = "Column"; break; case ZONE_TYPE_HEADER: csType = "Header"; break; case ZONE_TYPE_FOOTER: csType = "Footer"; break; case ZONE_TYPE_CAPTION: csType = "Caption"; break; case ZONE_TYPE_TITLE: csType = "Title"; break; case ZONE_TYPE_OTHER: csType = "Other"; break; case ZONE_TYPE_SGRAPHIC: csType = "S Graphic"; break; case ZONE_TYPE_HORZTEXT: csType = "Horz Text"; break; case ZONE_TYPE_VERTTEXT: csType = "Vert Text"; break; default: return; } csTemp.Format(_TEXT("Type: %s\n"), csType); csZoneData += csTemp; MessageBox(csZoneData, _TEXT("Zone Data"), MB_OK); } pZoneData->Release(); } void CMSVC5OCRView::OnEngineShutdown() { CMSVC5OCRDoc * pDoc = (CMSVC5OCRDoc *)GetDocument(); if (m_pLRasterDoc) { BeginWaitCursor(); m_bClose = FALSE; m_nPageIndex = -1; m_bFindZone = FALSE; m_bShowZones = TRUE; m_bRecognized = FALSE; m_bAccpetAll = FALSE; m_nSelZoneIndex= -1; m_bSelectZone = FALSE; m_bShowPage = TRUE; m_bScanStarted = FALSE; if (m_pZoneData) { if (m_pZoneSink) { LPUNKNOWN pUnkSink = m_pZoneSink->GetIDispatch(FALSE); if (m_pZoneData) AfxConnectionUnadvise(m_pZoneData, DIID__LTZoneDataEvents, pUnkSink, FALSE, m_dwOCRCookie); delete m_pZoneSink; m_pZoneSink = NULL; } m_pZoneData->Release(); m_pZoneData = NULL; } m_pLRasterDoc->ShutDown(); m_pLRasterDoc->Release(); m_pLRasterDoc = NULL; m_RasterView.GetRaster().SetBitmap(0); m_RasterView.SetEnableOCRDrawing(FALSE); m_RasterView.ForceRepaint(); m_bEnginStarted = FALSE; CString csTitle; csTitle.Format(_TEXT("Untitled")); pDoc->SetTitle(csTitle); EndWaitCursor(); } } void CMSVC5OCRView::OnUpdateEngineShutdown(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_pLRasterDoc && m_bEnginStarted); } void CMSVC5OCRView::OnEngineStartup() { if (!m_pLRasterDoc) { BOOL bRet = InitEngine(); if (!bRet) return; } } void CMSVC5OCRView::OnUpdateEngineStartup(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && !m_pLRasterDoc &&!m_bEnginStarted); } void CMSVC5OCRView::OnPageInsertcurrentpage() { m_nPageIndex = -1; AddPage(); } void CMSVC5OCRView::OnUpdatePageInsertcurrentpage(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_bClose && m_bEnginStarted); } void CMSVC5OCRView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); if( IsWindow(m_RasterView.m_hWnd) ) { m_RasterView.SetBackErase(FALSE); m_RasterView.MoveWindow(0, 0, cx, cy); } } void CMSVC5OCRView::DoFit() { if (IsWindow(m_RasterView.m_hWnd)) { if(::IsWindowVisible(m_RasterView.m_hWnd)) { RECT Rect; GetClientRect(&Rect); m_RasterView.SetBackErase(FALSE); m_RasterView.MoveWindow(0, 0, Rect.right, Rect.bottom); } } } void CMSVC5OCRView::OnEditPaste() { CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); m_RasterView.GetRaster().Paste((RasterPasteConstants)0); m_RasterView.SetEnableOCRDrawing(FALSE); m_RasterView.ForceRepaint(); m_bClose = TRUE; pTheApp->m_pRaster->Free(); pTheApp->m_pRaster->PutBitmap(m_RasterView.GetRaster().GetBitmap()); } void CMSVC5OCRView::OnUpdateEditPaste(CCmdUI* pCmdUI) { pCmdUI->Enable(m_RasterView.GetRaster().Paste(PASTE_ISREADY)); } BEGIN_EVENTSINK_MAP(CMSVC5OCRView, CFormView) //{{AFX_EVENTSINK_MAP(CMSVC5OCRView) ON_EVENT(CMSVC5OCRView, IDC_LEADRASTERVIEW, 4 /* MouseDown */, OnMouseDownLeadrasterview, VTS_I2 VTS_I2 VTS_R4 VTS_R4) ON_EVENT(CMSVC5OCRView, IDC_LEADRASTERVIEW, 7 /* DblClick */, OnDblClickLeadrasterview, VTS_NONE) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CMSVC5OCRView::OnMouseDownLeadrasterview(short Button, short Shift, float x, float y) { CMSVC5OCRApp * pTheApp = (CMSVC5OCRApp *)AfxGetApp(); POINT point; point.x = (LONG)x; point.y = (LONG)y; if(m_pLRasterDoc) { CClientDC dc(this); if (m_nSelZoneIndex != -1) { m_pLRasterDoc->SelectZone(NULL, (long)dc.m_hDC, m_nPageIndex, m_nSelZoneIndex, FALSE); m_bSelectZone = FALSE; m_RasterView.SetSelectedZoneIndex(-1); m_bSelectZone = FALSE; RedrawWindow(); } int nZoneIndex = -1; CPoint pt = point; pt.Offset(::GetScrollPos(m_RasterView.m_hWnd, SB_HORZ), ::GetScrollPos(m_RasterView.m_hWnd, SB_VERT)); m_pLRasterDoc->SelectZoneByPoint(NULL, (long)dc.m_hDC, m_nPageIndex, (float)pt.x, (float)pt.y); nZoneIndex = m_pLRasterDoc->SelectZoneIndex; if (nZoneIndex != -1) { m_bSelectZone = TRUE; m_nSelZoneIndex = nZoneIndex; int nRet = m_pLRasterDoc->SelectZone(NULL, (long)dc.m_hDC, m_nPageIndex, m_nSelZoneIndex, m_bSelectZone); m_RasterView.SetSelectedZoneIndex(m_nSelZoneIndex); } else { m_bSelectZone = FALSE; m_nSelZoneIndex = -1; } RedrawWindow(); } } void CMSVC5OCRView::OnDblClickLeadrasterview() { if (m_nSelZoneIndex != -1) ShowSelectedZoneInfo(); } void CMSVC5OCRView::OnPageAutoorient() { if (!ShowOCRErrMsg()) return; int nRet = m_pLRasterDoc->AutoOrientPage(m_nPageIndex); if (nRet != 0) AfxMessageBox(TEXT("Failure during auto orient the current page")); m_RasterView.SetEnableOCRDrawing(TRUE); m_RasterView.ForceRepaint(); UpdateView(); } void CMSVC5OCRView::OnUpdatePageAutoorient(CCmdUI* pCmdUI) { pCmdUI->Enable((m_pLRasterDoc && m_pLRasterDoc->PageCount)? TRUE : FALSE); } void CMSVC5OCRView::OnOcrGetRecognizedWords() { for (int i=m_nStartRecogIndex; iEnable(m_pLRasterDoc && !m_bScanStarted && m_nPageIndex != -1 && m_bRecognized); } void CMSVC5OCRView::OnViewNormal() { m_nViewScale = BITONALSCALING_NORMAL; m_RasterView.SetBitonalScaling(m_nViewScale); RedrawWindow(); } void CMSVC5OCRView::OnUpdateViewNormal(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_bClose && m_nPageIndex != -1); pCmdUI->SetRadio(m_nViewScale == BITONALSCALING_NORMAL); } void CMSVC5OCRView::OnViewScaletogray() { m_nViewScale = BITONALSCALING_SCALETOGRAY; m_RasterView.SetBitonalScaling(m_nViewScale); RedrawWindow(); } void CMSVC5OCRView::OnUpdateViewScaletogray(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_bClose && m_nPageIndex != -1); pCmdUI->SetRadio(m_nViewScale == BITONALSCALING_SCALETOGRAY); } void CMSVC5OCRView::OnViewFavortoblack() { m_nViewScale = BITONALSCALING_FAVORBLACK; m_RasterView.SetBitonalScaling(m_nViewScale); RedrawWindow(); } void CMSVC5OCRView::OnUpdateViewFavortoblack(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bScanStarted && m_bClose && m_nPageIndex != -1); pCmdUI->SetRadio(m_nViewScale == BITONALSCALING_FAVORBLACK); }