Advertisement
Guest User

AlanW

a guest
Sep 1st, 2008
3,418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.78 KB | None | 0 0
  1. #define PDF_MEMORY_FILESYS              16
  2.  
  3. BYTE lpBuffer[] = data buffer containing pdf binary
  4. DWORD dwDataSize = sizeof( lpBuffer );
  5. DWORD dwDataIndex = 0; // acts as an index pointer into buffer
  6.  
  7. void* PDFUtilAlloc( void* pClientData, ASSize_t sizeData )
  8. {
  9.     // return allocator of your choice (or malloc)
  10. }
  11.  
  12. void* PDFUtilRealloc( void* pClientData, void* pAllocData, ASSize_t sizeData )
  13. {
  14.     // return re-allocator of your choice (or realloc)
  15. }
  16.  
  17. void PDFUtilFree( void* pClientData, void* pAllocData )
  18. {
  19.     // free memory of your choice (or free)
  20. }
  21.  
  22. ASSize_t PDFUtilAvail( void* pClientData )
  23. {
  24.     return INT_MAX;
  25. }
  26.  
  27. ASErrorCode PDFOpen( ASPathName pathName, ASFileMode mode, ASMDFile *fP )
  28. {
  29.     dwDataIndex = 0;
  30.     return 0;
  31. }
  32.  
  33. ASErrorCode PDFClose( ASMDFile f )
  34. {
  35.     dwDataIndex = 0;
  36.     return 0;
  37. }
  38.  
  39. ASErrorCode PDFFlush( ASMDFile f )
  40. {
  41.     return 0;
  42. }
  43.  
  44. ASErrorCode PDFSetPos( ASMDFile f, ASFilePos pos )
  45. {
  46.     dwDataIndex = (DWORD)pos;
  47.     return 0;
  48. }
  49.  
  50. ASErrorCode PDFGetPos( ASMDFile f, ASFilePos *pos )
  51. {
  52.     *pos = (ASFilePos)dwDataIndex;
  53.     return 0;
  54. }
  55.  
  56. ASErrorCode PDFSetEof( ASMDFile f, ASFilePos pos )
  57. {
  58.     return 0;
  59. }
  60.  
  61. ASErrorCode PDFGetEof( ASMDFile f, ASFilePos *pos )
  62. {
  63.     *pos = (ASFilePos)dwDataSize;
  64.     return 0;
  65. }
  66.  
  67. ASSize_t PDFRead( void *ptr, ASSize_t size, ASSize_t count, ASMDFile f, ASErrorCode *pError )
  68. {
  69.     *pError = 0;
  70.     if ( ptr == NULL )
  71.         return 0;
  72.    
  73.     DWORD dwRemaining = dwDataSize - dwDataIndex;
  74.     DWORD dwReadSize = min( dwRemaining, (DWORD)( size * count ) );
  75.    
  76.     CopyMemory( ptr, &lpBuffer[ dwDataIndex ], dwReadSize );
  77.     dwDataIndex += dwReadSize;
  78.    
  79.     return (ASSize_t)dwReadSize;
  80. }
  81.  
  82. ASSize_t PDFWrite( void *ptr, ASSize_t size, ASSize_t count, ASMDFile f, ASErrorCode *pError )
  83. {
  84.     *pError = 0;
  85.     return 0;
  86. }
  87.  
  88. ASErrorCode PDFRemove( ASPathName pathName )
  89. {
  90.     return 0;
  91. }
  92.  
  93. ASErrorCode PDFRename( ASMDFile* f, ASPathName oldPath, ASPathName newPath )
  94. {
  95.     return 0;
  96. }
  97.  
  98. ASBool PDFIsSameFile( ASMDFile f, ASPathName pathName, ASPathName newPathName )
  99. {
  100.     return 0;
  101. }
  102.  
  103. ASErrorCode PDFGetName( ASPathName pathName, char *name, ASTArraySize maxLength )
  104. {
  105.     return 0;
  106. }
  107.  
  108. ASPathName PDFGetTempPath( ASPathName pathName )
  109. {
  110.     return (ASPathName)PDF_MEMORY_FILESYS;
  111. }
  112.  
  113. ASPathName PDFCopyPathName( ASPathName pathName )
  114. {
  115.     return (ASPathName)PDF_MEMORY_FILESYS;
  116. }
  117.  
  118. char *PDFGetDiPathFromPath( ASPathName path, ASPathName relativeToThisPath )
  119. {
  120.     return (char *)"";
  121. }
  122.  
  123. ASPathName PDFGetPathFromDIPath( const char* diPath, ASPathName relativeToThisPath )
  124. {
  125.     return (ASPathName)PDF_MEMORY_FILESYS;
  126. }
  127.  
  128. void PDFDisposePathName( ASPathName pathName )
  129. {
  130. }
  131.  
  132. ASAtom PDFGetFileSysName()
  133. {
  134.     return NULL;
  135. }
  136.  
  137. ASDiskSpace PDFGetStorageFreeSpace( ASPathName pathName )
  138. {
  139.     return INT_MAX;
  140. }
  141.  
  142. ASErrorCode PDFFlushVolume( ASPathName pathName )
  143. {
  144.     return 0;
  145. }
  146.  
  147. ASFlagBits PDFGetFileFlags( ASMDFile f )
  148. {
  149.     return NULL;
  150. }
  151.  
  152. ASErrorCode PDFReadAsync( ASIORequest req )
  153. {
  154.     return 0;
  155. }
  156.  
  157. ASErrorCode PDFWriteAsync( ASIORequest req )
  158. {
  159.     return 0;
  160. }
  161.  
  162. void PDFAbortAsync( ASMDFile f )
  163. {
  164. }
  165.  
  166. ASErrorCode PDFMReadRequest( ASMDFile f, ASFile aFile, ASTFilePos *blockPairs, ASTArraySize nBlockPairs )
  167. {
  168.     return 0;
  169. }
  170.  
  171. ASFlagBits PDFGetStatus( ASMDFile f )
  172. {
  173.     return 0;
  174. }
  175.  
  176. ASErrorCode PDFYield( ASMDFile f )
  177. {
  178.     return 0;
  179. }
  180.  
  181. ASPathName PDFCreatePathName( ASAtom pathSpecType, const void *pathSpec, const void *mustBeZero )
  182. {
  183.     return (ASPathName)PDF_MEMORY_FILESYS;
  184. }
  185.  
  186. ASPathName PDFAcquireFileSysPath( ASPathName pathName, ASFileSys newFileSys )
  187. {
  188.     return (ASPathName)PDF_MEMORY_FILESYS;
  189. }
  190.  
  191. void PDFClearOutstandingMReads( ASMDFile f )
  192. {
  193. }
  194.  
  195. ASErrorCode PDFGetItemProps( ASPathName pathName, ASFileSysItemProps props )
  196. {
  197.     return 0;
  198. }
  199.  
  200. ASFolderIterator PDFFirstFolderItem( ASPathName folderPath, ASFileSysItemProps props, ASPathName *itemPath )
  201. {
  202.     return NULL;
  203. }
  204.  
  205. ASBool PDFNextFolderItem( ASFolderIterator folderIter, ASFileSysItemProps props, ASPathName *itemPath )
  206. {
  207.     return 0;
  208. }
  209.  
  210. void PDFDestroyFolderIterator( ASFolderIterator folderIter )
  211. {
  212. }
  213.  
  214. ASlFileMode PDFSetFileMode( ASMDFile f, ASlFileMode modeValue, ASMaskBits modeMask )
  215. {
  216.     return NULL;
  217. }
  218.  
  219. char* PDFGetUrlFromPath( ASPathName path )
  220. {
  221.     return (char *)"";
  222. }
  223.  
  224. ASPathName PDFGetParent( ASPathName path )
  225. {
  226.     return NULL;
  227. }
  228.  
  229. ASErrorCode PDFCreateFolder( ASPathName path )
  230. {
  231.     return 0;
  232. }
  233.  
  234. ASErrorCode PDFRemoveFolder( ASPathName path )
  235. {
  236.     return 0;
  237. }
  238.  
  239. char* PDFDisplayStringFromPath( ASPathName path )
  240. {
  241.     return (char *)"";
  242. }
  243.  
  244. void PDFSetTypeAndCreator( ASPathName path, ASlFileMode type, ASlFileMode creator )
  245. {
  246. }
  247.  
  248. void PDFGetTypeAndCreator( ASPathName path, ASlFileMode *type, ASlFileMode *creator )
  249. {
  250. }
  251.  
  252. ASMDFile PDFReopen( ASMDFile f, ASFileMode newMode, ASErrorCode *pError )
  253. {
  254.     *pError = 0;
  255.     dwDataIndex = 0;
  256.     return NULL;
  257. }
  258.  
  259. ASErrorCode PDFHardFlush( ASMDFile f )
  260. {
  261.     return 0;
  262. }
  263.  
  264. void* PDFGetPlatformThing( ASPathName path, ASAtom thing )
  265. {
  266.     return NULL;
  267. }
  268.  
  269. ASInt32 PDFGetItemPropsAsCab( ASPathName pathName, ASCab theCab )
  270. {
  271.     return 0;
  272. }
  273.  
  274. ASInt32 PDFCanPerformOpOnItem( ASPathName pathName, const char *op )
  275. {
  276.     return 0;
  277. }
  278.  
  279. ASInt32 PDFPerformOpOnItem( ASPathName pathName, const char *op, ASCab params )
  280. {
  281.     return 0;
  282. }
  283.  
  284. ASInt32 PDFAcquirePlatformPath( ASPathName path, ASAtom platformPathType, ASPlatformPath *platformPath )
  285. {
  286.     return 0;
  287. }
  288.  
  289. void PDFReleasePlatformPath( ASPlatformPath platformPath )
  290. {
  291. }
  292.  
  293. ASErrorCode PDFGetNameAsText( ASPathName pathName, ASText name )
  294. {
  295.     return 0;
  296. }
  297.  
  298. ASErrorCode PDFDisplayASTextFromPath( ASPathName path, ASText displayText )
  299. {
  300.     return 0;
  301. }
  302.  
  303. void PDFRangeArrived( ASInt32 start, ASInt32 length, void* clientData )
  304. {
  305. }
  306.  
  307. ASBool PDFCanSetEof( ASMDFile f, ASFilePos pos )
  308. {
  309.     return 0;
  310. }
  311.  
  312. ASErrorCode PDFDIPathFromPathEx( ASPathName path,ASPathName relativeToThisPath,ASText diPathText)
  313. {
  314.     return 0;
  315. }
  316.  
  317. ASPathName PDFPathFromDIPathEx( ASConstText diPathText,ASPathName relativeToThisPath )
  318. {
  319.     return (ASPathName)PDF_MEMORY_FILESYS;
  320. }
  321.  
  322. ASErrorCode PDFGetFilePosLimit( ASFilePos64 *pos )
  323. {
  324.     return 0;
  325. }
  326.  
  327. ASErrorCode PDFOpen64( ASPathName pathName, ASFileMode mode, ASMDFile *fP )
  328. {
  329.     return PDFOpen( pathName, mode, fP );
  330. }
  331.  
  332. ASErrorCode PDFSetPos64( ASMDFile f, ASFilePos64 pos )
  333. {
  334.     return PDFSetPos( f, (ASFilePos)pos );
  335. }
  336.  
  337. ASErrorCode PDFGetPos64( ASMDFile f, ASFilePos64 *pos )
  338. {
  339.     return PDFGetPos( f, (ASFilePos*)pos );
  340. }
  341.  
  342. ASErrorCode PDFSetEof64( ASMDFile f, ASFilePos64 pos )
  343. {
  344.     return 0;
  345. }
  346.  
  347. ASErrorCode PDFGetEof64( ASMDFile f, ASFilePos64 *pos )
  348. {
  349.     return PDFGetEof( f, (ASFilePos*)pos );
  350. }
  351.  
  352. ASErrorCode PDFGetNameForDisplay( ASPathName pathName, ASText nameForDisplay )
  353. {
  354.     return 0;
  355. }
  356.  
  357. ASDiskSpace64 PDFGetStorage64( ASPathName pathName )
  358. {
  359.     return 0;
  360. }
  361.  
  362.  
  363. ...
  364.  
  365.  
  366.     PDFLDataRec pdflData;
  367.     ZeroMemory( &pdflData, sizeof( PDFLDataRec ) );
  368.     pdflData.size = sizeof( PDFLDataRec );
  369.    
  370.     TKAllocatorProcs PDFUtilAllocProcs =
  371.     {
  372.         PDFUtilAlloc,
  373.         PDFUtilRealloc,
  374.         PDFUtilFree,
  375.         PDFUtilAvail,
  376.         NULL
  377.     };
  378.  
  379.         // use custom allocators
  380.         pdflData.allocator = &PDFUtilAllocProcs;
  381.    
  382.     if ( PDFLInit( &pdflData ) != 0 )
  383.         return FALSE;
  384.    
  385.     ASFileSysRec pdfMemoryFileSys;
  386.     ZeroMemory( &pdfMemoryFileSys, sizeof( ASFileSysRec ) );
  387.     pdfMemoryFileSys.size = sizeof( ASFileSysRec );
  388.    
  389.     // provide callback procedures for memory file system
  390.     pdfMemoryFileSys.open = PDFOpen;
  391.     pdfMemoryFileSys.close = PDFClose;
  392.     pdfMemoryFileSys.flush = PDFFlush;
  393.     pdfMemoryFileSys.setpos = PDFSetPos;
  394.     pdfMemoryFileSys.getpos = PDFGetPos;
  395.     pdfMemoryFileSys.seteof = PDFSetEof;
  396.     pdfMemoryFileSys.geteof = PDFGetEof;
  397.     pdfMemoryFileSys.read = PDFRead;
  398.     pdfMemoryFileSys.write = PDFWrite;
  399.     pdfMemoryFileSys.remove = PDFRemove;
  400.     pdfMemoryFileSys.rename = PDFRename;
  401.     pdfMemoryFileSys.isSameFile = PDFIsSameFile;
  402.     pdfMemoryFileSys.getName = PDFGetName;
  403.     pdfMemoryFileSys.getTempPathName = PDFGetTempPath;
  404.     pdfMemoryFileSys.copyPathName = PDFCopyPathName;
  405.     pdfMemoryFileSys.diPathFromPath = PDFGetDiPathFromPath;
  406.     pdfMemoryFileSys.pathFromDIPath = PDFGetPathFromDIPath;
  407.     pdfMemoryFileSys.disposePathName = PDFDisposePathName;
  408.     pdfMemoryFileSys.getFileSysName = PDFGetFileSysName;
  409.     pdfMemoryFileSys.getStorageFreeSpace = PDFGetStorageFreeSpace;
  410.     pdfMemoryFileSys.flushVolume = PDFFlushVolume;
  411.     pdfMemoryFileSys.getFileFlags = PDFGetFileFlags;
  412.     pdfMemoryFileSys.readAsync = PDFReadAsync;
  413.     pdfMemoryFileSys.writeAsync = PDFWriteAsync;
  414.     pdfMemoryFileSys.abortAsync = PDFAbortAsync;
  415.     pdfMemoryFileSys.yield = PDFYield;
  416.     pdfMemoryFileSys.mreadRequest = PDFMReadRequest;
  417.     pdfMemoryFileSys.getStatus = PDFGetStatus;
  418.     pdfMemoryFileSys.createPathName = PDFCreatePathName;
  419.     pdfMemoryFileSys.acquireFileSysPath = PDFAcquireFileSysPath;
  420.     pdfMemoryFileSys.clearOutstandingMReads = PDFClearOutstandingMReads;
  421.     pdfMemoryFileSys.getItemProps = PDFGetItemProps;
  422.     pdfMemoryFileSys.firstFolderItem = PDFFirstFolderItem;
  423.     pdfMemoryFileSys.nextFolderItem = PDFNextFolderItem;
  424.     pdfMemoryFileSys.destroyFolderIterator = PDFDestroyFolderIterator;
  425.     pdfMemoryFileSys.setFileMode = PDFSetFileMode;
  426.     pdfMemoryFileSys.urlFromPath = PDFGetUrlFromPath;
  427.     pdfMemoryFileSys.getParent = PDFGetParent;
  428.     pdfMemoryFileSys.createFolder = PDFCreateFolder;
  429.     pdfMemoryFileSys.removeFolder = PDFRemoveFolder;
  430.     pdfMemoryFileSys.displayStringFromPath = PDFDisplayStringFromPath;
  431.     pdfMemoryFileSys.setTypeAndCreator = PDFSetTypeAndCreator;
  432.     pdfMemoryFileSys.getTypeAndCreator = PDFGetTypeAndCreator;
  433.     pdfMemoryFileSys.reopen = PDFReopen;
  434.     pdfMemoryFileSys.hardFlush = PDFHardFlush;
  435.     pdfMemoryFileSys.getPlatformThing = PDFGetPlatformThing;
  436.     pdfMemoryFileSys.getItemPropsAsCab = PDFGetItemPropsAsCab;
  437.     pdfMemoryFileSys.canPerformOpOnItem = PDFCanPerformOpOnItem;
  438.     pdfMemoryFileSys.performOpOnItem = PDFPerformOpOnItem;
  439.     pdfMemoryFileSys.acquirePlatformPath = PDFAcquirePlatformPath;
  440.     pdfMemoryFileSys.releasePlatformPath = PDFReleasePlatformPath;
  441.     pdfMemoryFileSys.getNameAsASText = PDFGetNameAsText;
  442.     pdfMemoryFileSys.displayASTextFromPath = PDFDisplayASTextFromPath;
  443.     pdfMemoryFileSys.rangeArrived = PDFRangeArrived;
  444.     pdfMemoryFileSys.canSetEof = PDFCanSetEof;
  445.     pdfMemoryFileSys.diPathFromPathEx = PDFDIPathFromPathEx;
  446.     pdfMemoryFileSys.pathFromDIPathEx = PDFPathFromDIPathEx;
  447.     pdfMemoryFileSys.getfileposlimit = PDFGetFilePosLimit;
  448.     pdfMemoryFileSys.open64 = PDFOpen64;
  449.     pdfMemoryFileSys.setpos64 = PDFSetPos64;
  450.     pdfMemoryFileSys.getpos64 = PDFGetPos64;
  451.     pdfMemoryFileSys.seteof64 = PDFSetEof64;
  452.     pdfMemoryFileSys.geteof64 = PDFGetEof64;
  453.     pdfMemoryFileSys.getNameForDisplay = PDFGetNameForDisplay;
  454.     pdfMemoryFileSys.getStorageFreeSpace64 = PDFGetStorage64;
  455.    
  456.     DURING
  457.         PDDoc pdDoc = PDDocOpen( (ASPathName)PDF_MEMORY_FILESYS, &pdfMemoryFileSys, NULL, true );
  458.        
  459.         if ( pdDoc != NULL )
  460.         {
  461.             // do stuff with pdf here
  462.            
  463.             PDDocClose( pdDoc );
  464.         }
  465.     HANDLER
  466.         int nErrorCode = ERRORCODE;
  467.     END_HANDLER
  468.    
  469.     PDFLTerm();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement