home *** CD-ROM | disk | FTP | other *** search
- // OCRDoc.cpp : implementation of the COCRDEMODoc class
- //
-
- #include "stdafx.h"
- #include "OCRDEMO.h"
-
- #include "OCRDoc.h"
- #include "CntrItem.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- extern COCRApp theApp;
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMODoc
-
- IMPLEMENT_DYNCREATE(COCRDEMODoc, COleDocument)
-
- BEGIN_MESSAGE_MAP(COCRDEMODoc, COleDocument)
- //{{AFX_MSG_MAP(COCRDEMODoc)
- ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
- ON_COMMAND(ID_OCR_RECOGNIZE, OnOcrRecognize)
- ON_COMMAND(ID_OCR_EDITDOCUMENT, OnOcrEditdocument)
- ON_COMMAND(ID_OCR_CLEARDOCUMENT, OnOcrCleardocument)
- //}}AFX_MSG_MAP
- // Enable default OLE container implementation
- ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, COleDocument::OnUpdatePasteMenu)
- ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, COleDocument::OnUpdatePasteLinkMenu)
- ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, COleDocument::OnUpdateObjectVerbMenu)
- ON_COMMAND(ID_OLE_EDIT_CONVERT, COleDocument::OnEditConvert)
- ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, COleDocument::OnUpdateEditLinksMenu)
- ON_COMMAND(ID_OLE_EDIT_LINKS, COleDocument::OnEditLinks)
- ON_UPDATE_COMMAND_UI(ID_OLE_VERB_FIRST, COleDocument::OnUpdateObjectVerbMenu)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMODoc construction/destruction
- static const WCHAR BASED_CODE _szLicString[] =
- L"LEADTOOLS OCX Copyright (c) 1998 LEAD Technologies, Inc.";
-
- COCRDEMODoc::COCRDEMODoc()
- {
- m_pOcr = NULL;
- }
-
- void COCRDEMODoc::InitLEADDoc(void)
- {
- CRect rcClient(0,0,1,1);
- BSTR lpLic = SysAllocString(_szLicString);
- m_Lead1.Create("", 0, rcClient, theApp.m_pMainWnd, 0,NULL,FALSE,lpLic);
- m_Lead1.ShowWindow(SW_HIDE);
- UNLOCKSUPPORT(m_Lead1);
- SysFreeString(lpLic);
- }
-
- COCRDEMODoc::~COCRDEMODoc()
- {
- if(m_pOcr)
- {
- m_pOcr->DestroyWindow();
- delete m_pOcr;
- }
- m_Lead1.DestroyWindow();
- }
-
- BOOL COCRDEMODoc::OnNewDocument()
- {
- if (!COleDocument::OnNewDocument())
- return FALSE;
-
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMODoc serialization
-
- void COCRDEMODoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMODoc diagnostics
-
- #ifdef _DEBUG
- void COCRDEMODoc::AssertValid() const
- {
- COleDocument::AssertValid();
- }
-
- void COCRDEMODoc::Dump(CDumpContext& dc) const
- {
- COleDocument::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // COCRDEMODoc commands
-
- BOOL COCRDEMODoc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- int nRet;
-
- if(lpszPathName)
- {
- nRet = m_Lead1.Load(lpszPathName, 0, theApp.m_nPage, 1);
- if( nRet )
- {
- theApp.DisplayLEADError(nRet);
- return FALSE;
- }
- else
- theApp.m_fImage = TRUE;
-
- if ((m_pOcr == NULL) && (!nRet))
- {
- m_pOcr = new CLeadOcr;
- m_pOcr->Create("", 0, CRect(0, 0, 50, 50), theApp.m_pMainWnd, 0, NULL, FALSE, NULL);
- m_pOcr->UnlockSupport(L_SUPPORT_OCR, L_KEY_OCR);
- }
- }
- return TRUE;
- }
-
- #define FILETYPES "Ami Pro 2.0|*.ami|\
- Ami Pro 3.0|*.ami|\
- ASCII Smart|*.txt|\
- ASCII Standard|*.txt|\
- ASCII Standard (DOS)|*.txt|\
- ASCII Stripped|*.txt|\
- dBase IV v1.0|*.dbf|\
- DCA/RFT|*.dca|\
- DisplayWrite 5|*.dw5|\
- Excel for the Macintosh|*.xls|\
- Excel 3.0|*.xls|\
- Excel 4.0|*.xls|\
- Excel 5.0|*.xls|\
- Excel Office 97|*.xls|\
- FrameMaker|*.doc|\
- HTML (2.0 specification)|*.htm|\
- HTML (SoftQuad Editor)|*.htm|\
- HTML (Netscape additions)|*.htm|\
- Interleaf|*.doc|\
- Lotus 1-2-3|*.123|\
- Lotus Word Pro|*.lwp|\
- MultiMate Advantage II|*.mma|\
- Postscript|*.eps|\
- Professional Write 2.0|*.doc|\
- Professional Write 2.2|*.doc|\
- Quattro Pro|*.pro|\
- Rich Text Format|*.rtf|\
- Rich Text Format (Macintosh)|*.rtf|\
- Rich Text Format (Word 6.0)|*.rtf|\
- Windows Write|*.wri|\
- Word for Windows 2.X|*.doc|\
- Word for Windows 6.0|*.doc|\
- Word Office 97|*.doc|\
- WordPerfect 4.2 (DOS)|*.doc|\
- WordPerfect (Windows)|*.doc|\
- WordPerfect 6.0 (Windows)|*.doc|\
- WordPerfect 6.1 (Windows)|*.doc|\
- WordPerfect 7X (Windows)|*.doc|\
- WordStar 1.X (Windows)|*.doc|\
- Works|*.doc|\
- Xerox XDOC|*.xdc||"
-
- void COCRDEMODoc::OnFileSaveAs()
- {
- CFileDialog dlg(FALSE, NULL, NULL, OFN_LONGNAMES | OFN_HIDEREADONLY, NULL, NULL);
-
- char szFilter[] = FILETYPES;
- LPTSTR pch;
-
- pch = szFilter;
- while ((pch = _tcschr(pch, '|')) != NULL)
- {
- *pch++ = '\0';
- }
-
- dlg.m_ofn.hInstance = AfxGetInstanceHandle();
- dlg.m_ofn.lpstrFilter = szFilter;
- dlg.m_ofn.nFilterIndex = 0;
-
- if (dlg.DoModal() != IDOK)
- {
- return;
- }
-
- CString strPathName;
- POSITION pos = dlg.GetStartPosition();
- if (pos == NULL)
- {
- return;
- }
-
- strPathName = dlg.GetNextPathName(pos);
-
- m_nFormat = dlg.m_ofn.nFilterIndex + FILE_AMI_PRO_20 - 1;
-
- // DoSave(strPathName, TRUE);
- OnSaveDocument(strPathName);
- }
-
- BOOL COCRDEMODoc::OnSaveDocument(LPCTSTR lpszPathName)
- {
- // if (!CDocument::OnSaveDocument(lpszPathName))
- // return FALSE;
-
- if (m_pOcr == NULL)
- return FALSE;
-
- short nResult;
-
- BeginWaitCursor();
- nResult = m_pOcr->SaveDoc((char FAR *)lpszPathName, m_nFormat);
- EndWaitCursor();
-
- if (nResult)
- theApp.DisplayLEADError(nResult);
-
- return TRUE;
- }
-
- void COCRDEMODoc::OnOcrRecognize()
- {
- short nResult;
-
- if (m_pOcr == NULL)
- return;
-
- BeginWaitCursor();
-
- m_pOcr->SetBitmap((long)m_Lead1.GetBitmap());
-
- m_pOcr->SetPreprocessingMode(theApp.m_nPreprocessingMode);
- m_pOcr->SetRecognitionMode(theApp.m_nRecognitionMode);
- m_pOcr->SetVerifierMode(theApp.m_nVerifierMode);
- m_pOcr->SetVerifierThreshold(theApp.m_nVerifierThreshold);
- m_pOcr->SetMinPointSize(theApp.m_nMinPointSize);
- m_pOcr->SetMaxPointSize(theApp.m_nMaxPointSize);
- m_pOcr->SetLanguage(theApp.m_nLanguage);
- m_pOcr->SetHeaderFooterProcess(theApp.m_bHeaderFooterProcess);
- m_pOcr->SetSloppyManual(theApp.m_bSloppyManual);
- m_pOcr->SetTextOrientLimit(theApp.m_nTextOrientLimit);
- m_pOcr->SetDocumentName(theApp.m_szDocumentName);
- m_pOcr->SetUnrecognized(theApp.m_szUnrecognized);
- m_pOcr->SetQuestionable(theApp.m_szQuestionable);
- m_pOcr->SetLeftSingleQuote(theApp.m_szLeftSingleQuote);
- m_pOcr->SetRightSingleQuote(theApp.m_szRightSingleQuote);
- m_pOcr->SetLeftDoubleQuote(theApp.m_szLeftDoubleQuote);
- m_pOcr->SetRightDoubleQuote(theApp.m_szRightDoubleQuote);
- m_pOcr->SetDecimal(theApp.m_szDecimal);
- m_pOcr->SetThousands(theApp.m_szThousands);
- m_pOcr->SetLexicon(theApp.m_szLexicon);
- m_pOcr->SetTraining(theApp.m_szTraining);
-
- nResult = m_pOcr->RecognizeOCR(OCRFLAG_CALLBACK_AUTO);
- EndWaitCursor();
-
- if (nResult)
- {
- theApp.m_fRecognize = FALSE;
- theApp.DisplayLEADError(nResult);
- }
- else
- theApp.m_fRecognize = TRUE;
- }
-
- void COCRDEMODoc::OnOcrEditdocument()
- {
- short nResult;
-
- if (m_pOcr == NULL)
- return;
-
- nResult = m_pOcr->EditDoc();
- if (nResult)
- theApp.DisplayLEADError(nResult);
- }
-
- void COCRDEMODoc::OnOcrCleardocument()
- {
- if (m_pOcr == NULL)
- return;
-
- m_pOcr->ClearDoc();
- theApp.m_fRecognize = FALSE;
- }
-
-