home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / datarec / Pdfdatarecognizer.cpp next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  2.6 KB  |  118 lines

  1. // PdfDataRecognizer.cpp
  2. //
  3. // Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
  4. //
  5. // Copyright (c) 1999 Sander van der Wal
  6. //
  7. // $Id: Pdfdatarecognizer.cpp 1.2 2000-09-21 14:06:37+02 svdwal Exp svdwal $
  8. //
  9. // $Log: Pdfdatarecognizer.cpp $
  10. // Revision 1.2  2000-09-21 14:06:37+02  svdwal
  11. // Some edits
  12. //
  13. // Revision 1.1  2000-09-17 15:08:15+02  svdwal
  14. // Initial checkin
  15. //
  16.  
  17.  
  18. /////////////////////////////////////////////////////////////////////////
  19. //
  20. // According to the Adobe Portable Document Format Reference Manual
  21. // version 1.3, March 1999, Chapter 5.12, page 55-56
  22. // A pdf file will contain in it's first line the string 
  23. //
  24. //  %PDF-
  25. //
  26. // and a version number afterwards. 
  27. // The line should be 255 chars or less long.
  28. // Here we use 1000 chars, the Adobe PDF readers do that too.
  29. //
  30. //
  31. ////////////////////////////////////////////////////////////////////////
  32.  
  33.  
  34. #include "PdfDataRecognizer.h"
  35.  
  36. // AppArc
  37. #ifndef __APMSTD_H__
  38. #include <apmstd.h>
  39. #endif
  40.  
  41. // Global const
  42.  
  43. #ifdef _UNICODE
  44. const TInt KUidRecPdfValue =   0x10005DE8;
  45. const TUid KUidRecPdf      = { 0x10005DE8 };
  46. #else
  47. const TInt KUidRecPdfValue =   0x10005DE7;
  48. const TUid KUidRecPdf      = { 0x10005DE7 };
  49. #endif
  50.  
  51. const TInt KMinBufferLength =    5; // minimum amount of file needed to determine a pdf file IF it's not called .pdf
  52. const TInt KMaxBufferLength = 1000; // maximum amount of buffer space we will ever use
  53.  
  54. _LIT8(KDataTypeApplicationPdf, "application/pdf");
  55.  
  56. CPdfDataRecognizer::CPdfDataRecognizer()
  57.     :CApaDataRecognizerType(KUidRecPdf, CApaDataRecognizerType::ELow)
  58. {
  59.   iCountDataTypes=1;
  60. }
  61.  
  62.  
  63. TUint CPdfDataRecognizer::PreferredBufSize()
  64. {
  65.   return KMaxBufferLength;
  66. }
  67.  
  68.  
  69. TDataType CPdfDataRecognizer::SupportedDataTypeL(TInt aIndex) const
  70. {
  71.   __ASSERT_DEBUG(aIndex==0,User::Invariant());
  72.   return TDataType(KDataTypeApplicationPdf);
  73. }
  74.  
  75.  
  76. void CPdfDataRecognizer::DoRecognizeL(const TDesC& /* aName */, const TDesC8& aBuffer)
  77. {
  78.   if (aBuffer.Length()<KMinBufferLength)
  79.     // not recognized, no room for '%PDF-'
  80.     return;
  81.   
  82.   // look for the '%PDF-'-string
  83.   if (aBuffer.FindF(_L("%PDF-")) >= 0) {
  84.     // found it. 
  85.     iConfidence=ECertain;
  86.     iDataType=TDataType(KDataTypeApplicationPdf);
  87.   }
  88.   return;
  89.  
  90. }
  91.  
  92.  
  93. //
  94. // The gate function - ordinal 1
  95. //
  96. EXPORT_C CApaDataRecognizerType* CreateRecognizer()
  97. {
  98.   return  new CPdfDataRecognizer(); // 0 if new failed
  99. }
  100.  
  101.  
  102. //
  103. // DLL entry point
  104. //
  105. GLDEF_C TInt E32Dll(TDllReason /*aReason*/)
  106. {
  107.   return KErrNone;
  108. }
  109.  
  110.  
  111. #ifdef __WINS__
  112. //
  113. // VC++ 6.0 Introductionary version wants this to be able to link
  114. //
  115. extern "C" void __pfnBkCheck() {}
  116.  
  117. #endif
  118.