Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

502 lines
16 KiB

  1. /****************************************************************************
  2. QuickDraw Import Filter; Implementation
  3. *****************************************************************************
  4. This file contains the source for a dynamically loaded graphics
  5. import filters that read QuickDraw PICT images. The entry points
  6. support both Aldus version 1 style interface, embedded extensions,
  7. and a parameterized input control.
  8. ****************************************************************************/
  9. #include <headers.c>
  10. #pragma hdrstop
  11. #include "api.h" /* Own interface */
  12. /*********************** Exported Data **************************************/
  13. /*********************** Private Data ***************************************/
  14. #define GraphicsImport 2
  15. #define PICTHeaderOffset 512
  16. #define USEDIALOG TRUE
  17. #define NODIALOG FALSE
  18. private USERPREFS upgradePrefs;
  19. private USERPREFS defaultPrefs =
  20. {
  21. { 'Q','D','2','G','D','I' }, // signature
  22. 2, // version = 2
  23. sizeof( USERPREFS ), // size of structure
  24. NULL, // no sourceFilename, yet
  25. NULL, // no sourceHandle, yet
  26. NULL, // no destinationFilename, yet
  27. 3, // penPatternAction = blend fore and background
  28. 5, // nonSquarePenAction = use max dimension
  29. 1, // penModeAction = use srcCopy
  30. 1, // textModeAction = use srcCopy
  31. 1, // nonRectRegionAction = create masks
  32. 0, // optimize PowerPoint = false
  33. 0, // noRLE = false
  34. 0, // reservedByte
  35. { 0, 0, 0, 0, 0 } // reserved initialized
  36. };
  37. private Handle instanceHandle;
  38. /*********************** Private Function Definitions ***********************/
  39. LPUSERPREFS VerifyPrefBlock( LPUSERPREFS lpPrefs );
  40. /* Perform cursory verification of the parameter block header */
  41. private void ConvertPICT( LPUSERPREFS lpPrefs, PICTINFO far * lpPict,
  42. Boolean doDialog );
  43. /* perform conversion and return results once environment is set up */
  44. /*********************** Function Implementation ****************************/
  45. #ifdef WIN32
  46. int WINAPI GetFilterInfo( short PM_Version, LPSTR lpIni,
  47. HANDLE FAR * lphPrefMem,
  48. HANDLE FAR * lphFileTypes )
  49. /*=====================*/
  50. #else
  51. int FAR PASCAL GetFilterInfo( short PM_Version, LPSTR lpIni,
  52. HANDLE FAR * lphPrefMem,
  53. HANDLE FAR * lphFileTypes )
  54. /*=========================*/
  55. #endif
  56. /* Returns information about this filter.
  57. Input parameters are PM_Version which is the filter interface version#
  58. and lpIni which is a copy of the win.ini entry
  59. Output parameters are lphPrefMem which is a handle to moveable global
  60. memory which will be allocated and initialized.
  61. lphFileTypes is a structure that contains the file types
  62. that this filter can import. (For MAC only)
  63. This routine should be called once, just before the filter is to be used
  64. the first time. */
  65. {
  66. LPUSERPREFS lpPrefs;
  67. /* allocate the global memory block */
  68. *lphPrefMem = GlobalAlloc( GHND, Sizeof( USERPREFS ) );
  69. /* if allocation is unsuccessful, set global error */
  70. if (*lphPrefMem == NULL)
  71. {
  72. ErSetGlobalError( ErMemoryFull );
  73. }
  74. else
  75. {
  76. /* lock down the memory and assign the default values */
  77. lpPrefs = (LPUSERPREFS)GlobalLock( *lphPrefMem );
  78. *lpPrefs = defaultPrefs;
  79. /* unlock the memory */
  80. GlobalUnlock( *lphPrefMem );
  81. }
  82. /* Indicate handles graphics import */
  83. return( GraphicsImport );
  84. UnReferenced( PM_Version );
  85. UnReferenced( lpIni );
  86. UnReferenced( lphFileTypes );
  87. } /* GetFilterInfo */
  88. #ifdef WIN32
  89. void WINAPI GetFilterPref( HANDLE hInst, HANDLE hWnd,
  90. HANDLE hPrefMem, WORD wFlags )
  91. /*======================*/
  92. #else
  93. void FAR PASCAL GetFilterPref( HANDLE hInst, HANDLE hWnd,
  94. HANDLE hPrefMem, WORD wFlags )
  95. /*==========================*/
  96. #endif
  97. /* Input parameters are hInst (in order to access resources), hWnd (to
  98. allow the DLL to display a dialog box), and hPrefMem (memory allocated
  99. in the GetFilterInfo() entry point). WFlags is currently unused, but
  100. should be set to 1 for Aldus' compatability */
  101. {
  102. return;
  103. UnReferenced( hInst );
  104. UnReferenced( hWnd );
  105. UnReferenced( hPrefMem );
  106. UnReferenced( wFlags );
  107. } /* GetFilterPref */
  108. #ifndef _OLECNV32_
  109. #ifdef WIN32
  110. short WINAPI ImportGr( HDC hdcPrint, LPFILESPEC lpFileSpec,
  111. PICTINFO FAR * lpPict, HANDLE hPrefMem )
  112. /*==================*/
  113. #else
  114. short FAR PASCAL ImportGr( HDC hdcPrint, LPFILESPEC lpFileSpec,
  115. PICTINFO FAR * lpPict, HANDLE hPrefMem )
  116. /*======================*/
  117. #endif
  118. /* Import the metafile in the file indicated by the lpFileSpec. The
  119. metafile generated will be returned in lpPict. */
  120. {
  121. LPUSERPREFS lpPrefs;
  122. /* Check for any errors from GetFilterInfo() or GetFilterPref() */
  123. if (ErGetGlobalError() != NOERR)
  124. {
  125. return ErInternalErrorToAldus();
  126. }
  127. /* Lock the preference memory and verify correct header */
  128. lpPrefs = (LPUSERPREFS)GlobalLock( hPrefMem );
  129. lpPrefs = VerifyPrefBlock( lpPrefs );
  130. /* if there is no error from the header verification, proceed */
  131. if (ErGetGlobalError() == NOERR)
  132. {
  133. /* provide IO module with source file name and read begin offset */
  134. IOSetFileName( (StringLPtr) lpFileSpec->fullName );
  135. IOSetReadOffset( PICTHeaderOffset );
  136. /* save the source filename for the status dialog box */
  137. lpPrefs->sourceFilename = lpFileSpec->fullName;
  138. /* Tell Gdi module to create a memory-based metafile */
  139. lpPrefs->destinationFilename = NULL;
  140. /* convert the image, provide status update */
  141. ConvertPICT( lpPrefs, lpPict, USEDIALOG );
  142. }
  143. /* Unlock preference memory */
  144. GlobalUnlock( hPrefMem );
  145. /* return the translated error code (if any problems encoutered) */
  146. return ErInternalErrorToAldus();
  147. UnReferenced( hdcPrint );
  148. UnReferenced( hPrefMem );
  149. } /* ImportGR */
  150. #ifdef WIN32
  151. short WINAPI ImportEmbeddedGr( HDC hdcPrint, LPFILESPEC lpFileSpec,
  152. PICTINFO FAR * lpPict, HANDLE hPrefMem,
  153. DWORD dwSize, LPSTR lpMetafileName )
  154. /*==========================*/
  155. #else
  156. short FAR PASCAL ImportEmbeddedGr( HDC hdcPrint, LPFILESPEC lpFileSpec,
  157. PICTINFO FAR * lpPict, HANDLE hPrefMem,
  158. DWORD dwSize, LPSTR lpMetafileName )
  159. /*==============================*/
  160. #endif
  161. /* Import the metafile in using the previously opened file handle in
  162. the structure field lpFileSpec->handle. Reading begins at offset
  163. lpFileSpect->filePos, and the convertor will NOT expect to find the
  164. 512 byte PICT header. The metafile generated will be returned in
  165. lpPict and can be specified via lpMetafileName (NIL = memory metafile,
  166. otherwise, fully qualified filename. */
  167. {
  168. LPUSERPREFS lpPrefs;
  169. /* Check for any errors from GetFilterInfo() or GetFilterPref() */
  170. if (ErGetGlobalError() != NOERR)
  171. {
  172. return ErInternalErrorToAldus();
  173. }
  174. /* Lock the preference memory and verify correct header */
  175. lpPrefs = (LPUSERPREFS)GlobalLock( hPrefMem );
  176. lpPrefs = VerifyPrefBlock( lpPrefs );
  177. /* if there is no error from the header verification, proceed */
  178. if (ErGetGlobalError() == NOERR)
  179. {
  180. /* provide IO module with source file handle and read begin offset */
  181. IOSetFileHandleAndSize( lpFileSpec->handle, dwSize );
  182. IOSetReadOffset( lpFileSpec->filePos );
  183. /* save the source filename for the status dialog box */
  184. lpPrefs->sourceFilename = lpFileSpec->fullName;
  185. /* Tell Gdi module to create metafile passed as parameter */
  186. lpPrefs->destinationFilename = lpMetafileName;
  187. /* convert the image, provide status update */
  188. ConvertPICT( lpPrefs, lpPict, USEDIALOG );
  189. }
  190. /* Unlock preference memory */
  191. GlobalUnlock( hPrefMem );
  192. /* return the translated error code (if any problems encoutered) */
  193. return ErInternalErrorToAldus();
  194. UnReferenced( hdcPrint );
  195. UnReferenced( hPrefMem );
  196. } /* ImportEmbeddedGr */
  197. #endif // !_OLECNV32_
  198. #ifdef WIN32
  199. short WINAPI QD2GDI( LPUSERPREFS lpPrefMem, PICTINFO FAR * lpPict )
  200. /*================*/
  201. #else
  202. short FAR PASCAL QD2GDI( LPUSERPREFS lpPrefMem, PICTINFO FAR * lpPict )
  203. /*====================*/
  204. #endif
  205. /* Import the metafile as specified using the parameters supplied in the
  206. lpPrefMem. The metafile will be returned in lpPict. */
  207. {
  208. /* verify correct header, and return if something is wrong */
  209. lpPrefMem = VerifyPrefBlock( lpPrefMem );
  210. /* if there is no error from the header verification, proceed */
  211. if (ErGetGlobalError() == NOERR)
  212. {
  213. #ifndef _OLECNV32_
  214. /* Determine if there is a fully-qualified source file name */
  215. if (lpPrefMem->sourceFilename != NIL)
  216. {
  217. /* Set the filename and read offset */
  218. IOSetFileName( (StringLPtr) lpPrefMem->sourceFilename );
  219. IOSetReadOffset( 0 );
  220. }
  221. /* otherwise, we are performing memory read from a global memory block */
  222. else
  223. #endif // !_OLECNV32_
  224. if (lpPrefMem->sourceHandle != NIL)
  225. {
  226. /* Set the memory handle and read offset */
  227. IOSetMemoryHandle( (HANDLE) lpPrefMem->sourceHandle );
  228. IOSetReadOffset( 0 );
  229. }
  230. else
  231. {
  232. /* Problem with input parameter block */
  233. ErSetGlobalError( ErNoSourceFormat );
  234. #ifdef _OLECNV32_
  235. return((short) ErGetGlobalError());
  236. #else
  237. return ErInternalErrorToAldus();
  238. #endif
  239. }
  240. /* convert the image - no status updates */
  241. ConvertPICT( lpPrefMem, lpPict, NODIALOG );
  242. }
  243. /* return the translated error code (if any problems encoutered) */
  244. #ifdef _OLECNV32_
  245. return((short) ErGetGlobalError());
  246. #else
  247. return ErInternalErrorToAldus();
  248. #endif
  249. } /* QD2GDI */
  250. #ifdef WIN32
  251. BOOL LibMain( HINSTANCE hInst, DWORD fdwReason, LPVOID lpReserved)
  252. /*=========*/
  253. #else
  254. int FAR PASCAL LibMain( HANDLE hInst, WORD wDataSeg, WORD cbHeap,
  255. LPSTR lpszCmdline )
  256. /*===================*/
  257. #endif
  258. /* Needed to get an instance handle */
  259. {
  260. instanceHandle = hInst;
  261. /* default return value */
  262. return( 1 );
  263. #ifndef WIN32
  264. UnReferenced( wDataSeg );
  265. UnReferenced( cbHeap );
  266. UnReferenced( lpszCmdline );
  267. #endif
  268. } /* LibMain */
  269. #ifdef WIN32
  270. int WINAPI WEP( int nParameter )
  271. /*===========*/
  272. #else
  273. int FAR PASCAL WEP( int nParameter )
  274. /*===============*/
  275. #endif
  276. {
  277. /* default return value */
  278. return( 1 );
  279. UnReferenced( nParameter );
  280. } /* WEP */
  281. /******************************* Private Routines ***************************/
  282. LPUSERPREFS VerifyPrefBlock( LPUSERPREFS lpPrefs )
  283. /*-------------------------*/
  284. /* Perform cursory verification of the parameter block header */
  285. {
  286. Byte i;
  287. Byte far * prefs = (Byte far *)lpPrefs;
  288. Byte far * check = (Byte far *)&defaultPrefs;
  289. /* loop through chars of signature verifying it */
  290. for (i = 0; i < sizeof( lpPrefs->signature); i++)
  291. {
  292. /* if any of the byte miscompare ... */
  293. if (*prefs++ != *check++)
  294. {
  295. /* ... set a global flag and return */
  296. ErSetGlobalError( ErInvalidPrefsHeader );
  297. return lpPrefs; // Sundown - According to callers, ErGetGlobalError() is used to check any error.
  298. }
  299. }
  300. /* check if this is a version 1 structure */
  301. if (lpPrefs->version == 1)
  302. {
  303. USERPREFS_V1 v1Prefs = *((LPUSERPREFS_V1)lpPrefs);
  304. /* convert the version 1 fields to version 2 fields */
  305. upgradePrefs = defaultPrefs;
  306. upgradePrefs.sourceFilename = v1Prefs.sourceFilename;
  307. upgradePrefs.sourceHandle = v1Prefs.sourceHandle;
  308. upgradePrefs.destinationFilename = v1Prefs.destinationFilename;
  309. upgradePrefs.nonSquarePenAction = v1Prefs.nonSquarePenAction;
  310. upgradePrefs.penModeAction = v1Prefs.penModeAction;
  311. upgradePrefs.textModeAction = v1Prefs.textModeAction;
  312. upgradePrefs.optimizePP = v1Prefs.optimizePP;
  313. /* since new functionality was added to the patterned pens and region
  314. records, upgrade to highest image fidelity setting if they didn't
  315. request omit or import abort actions. */
  316. upgradePrefs.penPatternAction = (v1Prefs.penPatternAction == 1) ?
  317. (Byte)3 :
  318. v1Prefs.penPatternAction;
  319. upgradePrefs.nonRectRegionAction = (v1Prefs.nonRectRegionAction == 0) ?
  320. (Byte)1 :
  321. v1Prefs.nonRectRegionAction;
  322. /* return address of the converted fields data structure */
  323. return &upgradePrefs;
  324. }
  325. else if( lpPrefs->version <= 3 )
  326. {
  327. if( lpPrefs->version==2 )
  328. { /* noRLE wasn't supported in version 2, so zero it */
  329. lpPrefs->noRLE = 0;
  330. }
  331. /* return address that was passed in */
  332. return lpPrefs;
  333. }
  334. else /* version > 3 is an error */ {
  335. ErSetGlobalError( ErInvalidPrefsHeader );
  336. return lpPrefs; // Sundown - According to callers, ErGetGlobalError() is used to check any error.
  337. }
  338. }
  339. private void ConvertPICT( LPUSERPREFS lpPrefs, PICTINFO far * lpPict,
  340. Boolean doDialog )
  341. /*----------------------*/
  342. /* perform conversion and return results once environment is set up */
  343. {
  344. #ifndef _OLECNV32_
  345. FARPROC dialogBoxProcedure;
  346. StatusParam statusParams;
  347. #endif
  348. /* Set conversion preferences */
  349. /* This is somewhat bogus in that it passes ptr to middle of USERPREFS
  350. to a function that wants a ptr to ConvPrefs (a trailing subset) */
  351. GdiSetConversionPrefs( (ConvPrefsLPtr)&lpPrefs->destinationFilename );
  352. #ifndef _OLECNV32_
  353. if (doDialog)
  354. {
  355. /* save data in structure to be passed to dialog window */
  356. statusParams.sourceFilename = lpPrefs->sourceFilename;
  357. statusParams.instance = instanceHandle;
  358. /* make a callable address for status dialog */
  359. dialogBoxProcedure = MakeProcInstance( StatusProc, instanceHandle );
  360. /* make sure that the procedure address was obtained */
  361. if (dialogBoxProcedure == NULL)
  362. {
  363. /* set error if unable to proceed */
  364. ErSetGlobalError( ErNoDialogBox );
  365. return;
  366. }
  367. else
  368. {
  369. /* AR: GetActiveWindow() may be bad, since the ability to update
  370. !!! links may be performed in the background, shutting out
  371. any process which then becomes the active window */
  372. /* dialog module calls quickdraw entry point to convert image */
  373. DialogBoxParam( instanceHandle, MAKEINTRESOURCE( RS_STATUS ),
  374. GetActiveWindow(), dialogBoxProcedure,
  375. (DWORD)((StatusParamLPtr)&statusParams) );
  376. /* release the procedure instance */
  377. FreeProcInstance( dialogBoxProcedure );
  378. }
  379. }
  380. else
  381. #endif // !_OLECNV32_
  382. {
  383. /* convert image, NULL parameter means no status updates */
  384. QDConvertPicture( NULL );
  385. }
  386. /* Get conversion results in parameter block */
  387. GdiGetConversionResults( lpPict );
  388. #ifdef DEBUG
  389. if (ErGetGlobalError() == ErNoError)
  390. {
  391. HANDLE hPICT;
  392. LPMETAFILEPICT lpPICT;
  393. OpenClipboard( GetActiveWindow() );
  394. hPICT = GlobalAlloc( GHND, sizeof( METAFILEPICT ) );
  395. if (hPICT)
  396. {
  397. lpPICT = (LPMETAFILEPICT)GlobalLock( hPICT );
  398. lpPICT->mm = MM_ANISOTROPIC;
  399. lpPICT->xExt = Width( lpPict->bbox );
  400. lpPICT->yExt = Height( lpPict->bbox );
  401. lpPICT->hMF = CopyMetaFile( lpPict->hmf, NULL );
  402. GlobalUnlock( hPICT );
  403. SetClipboardData( CF_METAFILEPICT, hPICT );
  404. CloseClipboard();
  405. }
  406. }
  407. #endif
  408. } /* ConvertPICT */