Leaked source code of windows server 2003
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.

1539 lines
60 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: local.h *
  3. * *
  4. * Definitions needed for client side objects. *
  5. * *
  6. * Copyright (c) 1993-1999 Microsoft Corporation *
  7. \**************************************************************************/
  8. #include "gdispool.h"
  9. #include "umpd.h"
  10. #include "cliumpd.h"
  11. #define MIRRORED_HDC(hdc) (GetLayout(hdc) & LAYOUT_RTL)
  12. //
  13. // Semaphore utilities
  14. //
  15. #define INITIALIZECRITICALSECTION(psem) RtlInitializeCriticalSection(psem)
  16. #define ENTERCRITICALSECTION(hsem) RtlEnterCriticalSection(hsem)
  17. #define LEAVECRITICALSECTION(hsem) RtlLeaveCriticalSection(hsem)
  18. #define DELETECRITICALSECTION(psem) RtlDeleteCriticalSection(psem)
  19. //
  20. // Memory allocation
  21. //
  22. #define LOCALALLOC(size) RtlAllocateHeap(RtlProcessHeap(),0,size)
  23. #define LOCALFREE(pv) (void)RtlFreeHeap(RtlProcessHeap(),0,pv)
  24. //
  25. // check for multiplication overflow (#define's copied from gre/hmgr.h and
  26. // gre/engine.h, respectively; #include required fro PAGE_SIZE definition.)
  27. //
  28. #include "ntosp.h"
  29. #define MAXIMUM_POOL_ALLOC (PAGE_SIZE * 10000)
  30. #define BALLOC_OVERFLOW1(c,st) (c > (MAXIMUM_POOL_ALLOC/sizeof(st)))
  31. extern DWORD GdiBatchLimit;
  32. typedef LPWSTR PWSZ;
  33. extern HBRUSH ghbrDCBrush;
  34. extern HPEN ghbrDCPen;
  35. extern BOOL gbWOW64;
  36. #define WOW64PRINTING(pUMPD) ((gbWOW64) && (pUMPD) && ((pUMPD)->pp))
  37. void vUMPDWow64Shutdown();
  38. /**************************************************************************\
  39. *
  40. * Local handle macros
  41. *
  42. \**************************************************************************/
  43. // macros to validate the handles passed in and setup some local variables
  44. // for accessing the handle information.
  45. #define DC_PLDC(hdc,pldc,Ret) \
  46. pldc = GET_PLDC(hdc); \
  47. if (!pldc || (LO_TYPE(hdc) == LO_METADC16_TYPE)) \
  48. { \
  49. GdiSetLastError(ERROR_INVALID_HANDLE); \
  50. return(Ret); \
  51. } \
  52. ASSERTGDI((pldc->iType == LO_DC) || (pldc->iType == LO_METADC),"DC_PLDC error\n");
  53. #define GET_PLDC(hdc) pldcGet(hdc)
  54. #define GET_PMDC(hdc) pmdcGetFromHdc(hdc)
  55. #define GET_PMFRECORDER16(pmf,hdc) \
  56. { \
  57. pmf = (PMFRECORDER16)plinkGet(hdc); \
  58. if (pmf) \
  59. pmf = ((PLINK)pmf)->pv; \
  60. }
  61. #define hdcFromIhdc(i) GdiFixUpHandle((HANDLE)i)
  62. #define pmdcGetFromIhdc(i) pmdcGetFromHdc(GdiFixUpHandle((HANDLE)i))
  63. // ALTDC_TYPE is not LO_ALTDC_TYPE || LO_METADC16_TYPE
  64. #define IS_ALTDC_TYPE(h) (LO_TYPE(h) != LO_DC_TYPE)
  65. #define IS_METADC16_TYPE(h) (LO_TYPE(h) == LO_METADC16_TYPE)
  66. // these macros are defined to aid in determining color vs monochrome pages
  67. #define CLEAR_COLOR_PAGE(pldc) pldc->fl &= ~LDC_COLOR_PAGE
  68. #define IS_COLOR_GREY(color) ((BYTE)color == (BYTE)(color >> 8) && (BYTE)color == (BYTE)(color >> 16))
  69. #define IS_GREY_MONO(color) ((BYTE)color == (BYTE)0x0 || (BYTE)color == (BYTE)0xff)
  70. #define IS_COLOR_MONO(color) ((color & 0x00ffffff) == 0 || (color & 0x00ffffff) == 0x00ffffff)
  71. #if 1 // disable debug messages
  72. #define DESIGNATE_COLOR_PAGE(pldc) CLEAR_COLOR_PAGE(pldc);
  73. #define SET_COLOR_PAGE(pldc) pldc->fl |= LDC_COLOR_PAGE;
  74. #define CHECK_COLOR_PAGE(pldc,color) \
  75. { \
  76. if (!IS_COLOR_MONO(color)) \
  77. pldc->fl |= LDC_COLOR_PAGE; \
  78. }
  79. #else
  80. #define DESIGNATE_COLOR_PAGE(pldc) \
  81. { \
  82. if (pldc->fl & LDC_COLOR_PAGE) \
  83. { \
  84. DbgPrint ("gdi32:Color Page\n"); \
  85. } \
  86. else \
  87. { \
  88. DbgPrint ("gdi32:Monochrome Page\n"); \
  89. } \
  90. CLEAR_COLOR_PAGE(pldc); \
  91. }
  92. #define CHECK_COLOR_PAGE(pldc,color) \
  93. { \
  94. if (!IS_COLOR_MONO(color)) \
  95. { \
  96. pldc->fl |= LDC_COLOR_PAGE; \
  97. DbgPrint ("Set Color Page: %08x %s %d\n",color,__FILE__,__LINE__); \
  98. } \
  99. }
  100. #define SET_COLOR_PAGE(pldc) \
  101. { \
  102. pldc->fl |= LDC_COLOR_PAGE; \
  103. DbgPrint ("Set color page %s %d\n",__FILE__,__LINE__); \
  104. }
  105. #endif
  106. /**************************************************************************\
  107. *
  108. * LINK stuff
  109. *
  110. \**************************************************************************/
  111. #define INVALID_INDEX 0xffffffff
  112. #define LINK_HASH_SIZE 128
  113. #define H_INDEX(h) ((USHORT)(h))
  114. #define LINK_HASH_INDEX(h) (H_INDEX(h) & (LINK_HASH_SIZE-1))
  115. typedef struct tagLINK
  116. {
  117. DWORD metalink;
  118. struct tagLINK *plinkNext;
  119. HANDLE hobj;
  120. PVOID pv;
  121. } LINK, *PLINK;
  122. extern PLINK aplHash[LINK_HASH_SIZE];
  123. PLINK plinkGet(HANDLE h);
  124. PLINK plinkCreate(HANDLE h,ULONG ulSize);
  125. BOOL bDeleteLink(HANDLE h);
  126. HANDLE hCreateClientObjLink(PVOID pv,ULONG ulType);
  127. PVOID pvClientObjGet(HANDLE h, DWORD dwLoType);
  128. BOOL bDeleteClientObjLink(HANDLE h);
  129. int iGetServerType(HANDLE hobj);
  130. /****************************************************************************
  131. *
  132. * UFI Hash stuff
  133. *
  134. ***************************************************************************/
  135. typedef struct _MERGEDVIEW
  136. {
  137. BYTE *pjMem; // pointer to the merged font's memory image
  138. ULONG cjMem; // its size
  139. } MERGEDVIEW;
  140. // info needed for subsetting first and subsequent pages
  141. typedef struct _SSINFO
  142. {
  143. BYTE *pjBits; // glyph index bitfield, one bit set for every glyph
  144. // used on pages up to and including this one
  145. ULONG cjBits; // cj of the bitfield above
  146. ULONG cGlyphsSoFar; // number of bits set in the bitfield above
  147. ULONG cDeltaGlyphs; // number of glyphs in the delta for this page
  148. BYTE *pjDelta; // bitfield for glyphs in the delta for this page
  149. } SSINFO;
  150. typedef union _SSMERGE
  151. {
  152. MERGEDVIEW mvw; // only used on the server
  153. SSINFO ssi; // only used on the client
  154. } SSMERGE;
  155. #define UFI_HASH_SIZE 32 // this should be plenty
  156. typedef struct tagUFIHASH
  157. {
  158. UNIVERSAL_FONT_ID ufi;
  159. struct tagUFIHASH *pNext;
  160. FSHORT fs1;
  161. FSHORT fs2;
  162. // client of server side union
  163. SSMERGE u;
  164. } UFIHASH, *PUFIHASH;
  165. #if 0
  166. typedef struct tagUFIHASH
  167. {
  168. UNIVERSAL_FONT_ID ufi;
  169. struct tagUFIHASH *pNext;
  170. FSHORT fs1; // server or client, if client delta or not
  171. FSHORT fs2; // private or public, dv or not
  172. // this part of the structure is only optionally allocated, only needed
  173. // for subsetting code.
  174. PBYTE pjMemory;
  175. ULONG ulMemBytes;
  176. // these fields are only used on the client side to do book keeping about
  177. // which glyphs from this font are used in the document
  178. ULONG ulDistGlyph;
  179. ULONG ulDistDelta;
  180. PBYTE pjDelta;
  181. } UFIHASH, *PUFIHASH;
  182. #endif
  183. #define FLUFI_SERVER 1
  184. #define FLUFI_DELTA 2
  185. // Define the local DC object.
  186. #define PRINT_TIMER 0
  187. #if PRINT_TIMER
  188. extern BOOL bPrintTimer;
  189. #endif
  190. /****************************************************************************
  191. *
  192. * PostScript Data
  193. *
  194. ***************************************************************************/
  195. typedef struct _EMFITEMPSINJECTIONDATA
  196. {
  197. DWORD cjSize;
  198. int nEscape;
  199. int cjInput;
  200. BYTE EscapeData[1];
  201. } EMFITEMPSINJECTIONDATA, *PEMFITEMPSINJECTIONDATA;
  202. typedef struct _PS_INJECTION_DATA
  203. {
  204. LIST_ENTRY ListEntry;
  205. EMFITEMPSINJECTIONDATA EmfData;
  206. } PS_INJECTION_DATA, *PPS_INJECTION_DATA;
  207. /****************************************************************************
  208. *
  209. * Local DC
  210. *
  211. ***************************************************************************/
  212. typedef struct _LDC
  213. {
  214. HDC hdc;
  215. ULONG fl;
  216. ULONG iType;
  217. // Metafile information.
  218. PVOID pvPMDC; // can't have a PMDC here since it is a class
  219. // Printing information.
  220. // We need to cache the port name from createDC in case it is not specified at StartDoc
  221. LPWSTR pwszPort;
  222. ABORTPROC pfnAbort; // Address of application's abort proc.
  223. ULONG ulLastCallBack; // Last time we call back to abort proc.
  224. HANDLE hSpooler; // handle to the spooler.
  225. PUMPD pUMPD; // pointer to user-mode printer driver info
  226. KERNEL_PUMDHPDEV pUMdhpdev; // pointer to user-mode pdev info
  227. PUFIHASH *ppUFIHash; // used to keep track of fonts used in doc
  228. PUFIHASH *ppDVUFIHash; // used to keep track of mm instance fonts used in a doc
  229. PUFIHASH *ppSubUFIHash; // used to keep track of subsetted fonts in the doc
  230. DEVMODEW *pDevMode; // used to keep trak of ResetDC's
  231. UNIVERSAL_FONT_ID ufi; // current UFI used for forced mapping
  232. HANDLE hEMFSpool; // information used for recording EMF data
  233. #if PRINT_TIMER
  234. DWORD msStartDoc; // Time of StartDoc in miliseconds.
  235. DWORD msStartPage; // Time of StartPage in miliseconds.
  236. #endif
  237. DWORD dwSizeOfPSDataToRecord; // Total size of PostScript Injection data to record EMF
  238. LIST_ENTRY PSDataList; // List to PostScript Injection data
  239. DEVCAPS DevCaps;
  240. HBRUSH oldSetDCBrushColorBrush; // Holds latest temp DC brush
  241. HPEN oldSetDCPenColorPen; // Holds latest temp DC pen
  242. } LDC,*PLDC;
  243. // Flags for ldc.fl.
  244. #define LDC_SAP_CALLBACK 0x00000020L
  245. #define LDC_DOC_STARTED 0x00000040L
  246. #define LDC_PAGE_STARTED 0x00000080L
  247. #define LDC_CALL_STARTPAGE 0x00000100L
  248. #define LDC_NEXTBAND 0x00000200L
  249. #define LDC_EMPTYBAND 0x00000400L
  250. #define LDC_EMBED_FONTS 0x00001000L
  251. #define LDC_META_ARCDIR_CLOCKWISE 0x00002000L
  252. #define LDC_FONT_SUBSET 0x00004000L
  253. #define LDC_FONT_CHANGE 0x00008000L
  254. #define LDC_DOC_CANCELLED 0x00010000L
  255. #define LDC_META_PRINT 0x00020000L
  256. #define LDC_PRINT_DIRECT 0x00040000L
  257. #define LDC_BANDING 0x00080000L
  258. #define LDC_DOWNLOAD_FONTS 0x00100000L
  259. #define LDC_RESETDC_CALLED 0x00200000L
  260. #define LDC_FORCE_MAPPING 0x00400000L
  261. #define LDC_LINKED_FONTS 0x00800000L
  262. #define LDC_INFO 0x01000000L
  263. #define LDC_CACHED_DEVCAPS 0x02000000L
  264. #define LDC_ICM_INFO 0x04000000L
  265. #define LDC_DOWNLOAD_PROFILES 0x08000000L
  266. #define LDC_CALLED_ENDPAGE 0x10000000L
  267. #define LDC_COLOR_PAGE 0x20000000L
  268. // Values for lMsgSAP.
  269. #define MSG_FLUSH 1L // Created thread should flush its message queue.
  270. #define MSG_CALL_USER 2L // Created thread should call user.
  271. #define MSG_EXIT 3L // Created thread should exit.
  272. // TYPE of DC
  273. #define LO_DC 0x01
  274. #define LO_METADC 0x02
  275. extern RTL_CRITICAL_SECTION semLocal; // Semaphore for handle management
  276. extern RTL_CRITICAL_SECTION semBrush; // semphore for client brush
  277. // ahStockObjects will contain both the stock objects visible to an
  278. // application, and internal ones such as the private stock bitmap.
  279. extern ULONG_PTR ahStockObjects[];
  280. // Declare support functions.
  281. HANDLE GdiFixUpHandle(HANDLE h);
  282. PLDC pldcGet(HDC hdc);
  283. VOID vSetPldc(HDC hdc,PLDC pldc);
  284. VOID GdiSetLastError(ULONG iError);
  285. HBITMAP GdiConvertBitmap(HBITMAP hbm);
  286. HRGN GdiConvertRegion(HRGN hrgn);
  287. HDC GdiConvertDC(HDC hdc);
  288. HBRUSH GdiConvertBrush(HBRUSH hbrush);
  289. VOID vSAPCallback(PLDC);
  290. BOOL InternalDeleteDC(HDC hdc,ULONG iType);
  291. int GetBrushBits(HDC hdc,HBITMAP hbmRemote,UINT iUsage,DWORD cbBmi,
  292. LPVOID pBits,LPBITMAPINFO pBmi);
  293. VOID CopyCoreToInfoHeader(LPBITMAPINFOHEADER pbmih,LPBITMAPCOREHEADER pbmch);
  294. HBITMAP GetObjectBitmapHandle(HBRUSH hbr, UINT *piUsage);
  295. BOOL MonoBitmap(HBITMAP hSrvBitmap);
  296. int APIENTRY SetBkModeWOW(HDC hdc,int iMode);
  297. int APIENTRY SetPolyFillModeWOW(HDC hdc,int iMode);
  298. int APIENTRY SetROP2WOW(HDC hdc,int iMode);
  299. int APIENTRY SetStretchBltModeWOW(HDC hdc,int iMode);
  300. UINT APIENTRY SetTextAlignWOW(HDC hdc,UINT iMode);
  301. HMETAFILE WINAPI SetMetaFileBitsAlt(HLOCAL);
  302. HENHMETAFILE APIENTRY SetEnhMetaFileBitsAlt(HLOCAL, HANDLE, HANDLE, UINT64);
  303. BOOL InternalDeleteEnhMetaFile(HENHMETAFILE hemf, BOOL bAllocBuffer);
  304. BOOL SetFontXform(HDC hdc,FLOAT exScale,FLOAT eyScale);
  305. BOOL DeleteObjectInternal(HANDLE h);
  306. DWORD GetServerObjectType(HGDIOBJ h);
  307. BOOL MakeInfoDC(HDC hdc,BOOL bSet);
  308. BOOL GetDCPoint(HDC hdc,DWORD i,PPOINT pptOut);
  309. HANDLE CreateClientObj(ULONG ulType);
  310. BOOL DeleteClientObj(HANDLE h);
  311. PLDC pldcCreate(HDC hdc,ULONG ulType);
  312. BOOL bDeleteLDC(PLDC pldc);
  313. BOOL bGetANSISetMap();
  314. HANDLE CreateTempSpoolFile();
  315. // Some convenient defines.
  316. typedef BITMAPINFO BMI;
  317. typedef PBITMAPINFO PBMI;
  318. typedef LPBITMAPINFO LPBMI;
  319. typedef BITMAPINFOHEADER BMIH;
  320. typedef PBITMAPINFOHEADER PBMIH;
  321. typedef LPBITMAPINFOHEADER LPBMIH;
  322. typedef BITMAPCOREINFO BMC;
  323. typedef PBITMAPCOREINFO PBMC;
  324. typedef LPBITMAPCOREINFO LPBMC;
  325. typedef BITMAPCOREHEADER BMCH;
  326. typedef PBITMAPCOREHEADER PBMCH;
  327. typedef LPBITMAPCOREHEADER LPBMCH;
  328. #define NEG_INFINITY 0x80000000
  329. #define POS_INFINITY 0x7fffffff
  330. // Check if a source is needed in a 3-way bitblt operation.
  331. // This works on both rop and rop3. We assume that a rop contains zero
  332. // in the high byte.
  333. //
  334. // This is tested by comparing the rop result bits with source (column A
  335. // below) vs. those without source (column B). If the two cases are
  336. // identical, then the effect of the rop does not depend on the source
  337. // and we don't need a source device. Recall the rop construction from
  338. // input (pattern, source, target --> result):
  339. //
  340. // P S T | R A B mask for A = 0CCh
  341. // ------+-------- mask for B = 33h
  342. // 0 0 0 | x 0 x
  343. // 0 0 1 | x 0 x
  344. // 0 1 0 | x x 0
  345. // 0 1 1 | x x 0
  346. // 1 0 0 | x 0 x
  347. // 1 0 1 | x 0 x
  348. // 1 1 0 | x x 0
  349. // 1 1 1 | x x 0
  350. #define ISSOURCEINROP3(rop3) \
  351. (((rop3) & 0xCCCC0000) != (((rop3) << 2) & 0xCCCC0000))
  352. #define MIN(A,B) ((A) < (B) ? (A) : (B))
  353. #define MAX(A,B) ((A) > (B) ? (A) : (B))
  354. #define MAX4(a, b, c, d) max(max(max(a,b),c),d)
  355. #define MIN4(a, b, c, d) min(min(min(a,b),c),d)
  356. //
  357. // Win31 compatibility stuff.
  358. // see user\client
  359. //
  360. DWORD GetAppCompatFlags(KERNEL_PVOID);
  361. DWORD GetAppCompatFlags2(WORD); // defined in w32\w32inc\usergdi.h
  362. #define ABS(X) (((X) < 0 ) ? -(X) : (X))
  363. #define META
  364. int GetBreakExtra (HDC hdc);
  365. int GetcBreak (HDC hdc);
  366. HANDLE GetDCObject (HDC, int);
  367. DWORD GetDCDWord(HDC hdc,UINT index,INT error );
  368. #if DBG
  369. extern int gerritv;
  370. #define MFD1(X) { if(gerritv) DbgPrint(X); }
  371. #define MFD2(X,Y) { if(gerritv) DbgPrint(X,Y); }
  372. #define MFD3(X,Y,Z) { if(gerritv) DbgPrint(X,Y,Z); }
  373. #else
  374. #define MFD1(X)
  375. #define MFD2(X,Y)
  376. #define MFD3(X,Y,Z)
  377. #endif
  378. BOOL AssociateEnhMetaFile(HDC);
  379. HENHMETAFILE UnassociateEnhMetaFile(HDC, BOOL);
  380. ULONG ulToASCII_N(LPSTR psz, DWORD cbAnsi, LPWSTR pwsz, DWORD c);
  381. DWORD GetAndSetDCDWord( HDC, UINT, UINT, UINT, WORD, UINT );
  382. #ifdef DBCS
  383. #define gbDBCSCodeOn TRUE
  384. #endif
  385. /**************************************************************************\
  386. *
  387. * SPOOLER Linking routines. We don't want to staticly link to the spooler
  388. * so that it doesn't need to be brought in until necesary.
  389. *
  390. * 09-Aug-1994 -by- Eric Kutter [erick]
  391. *
  392. \**************************************************************************/
  393. BOOL bLoadSpooler();
  394. #define BLOADSPOOLER ((ghSpooler != NULL) || bLoadSpooler())
  395. typedef LPWSTR (FAR WINAPI * FPSTARTDOCDLGW)(HANDLE,CONST DOCINFOW *);
  396. typedef BOOL (FAR WINAPI * FPOPENPRINTERW)(LPWSTR,LPHANDLE,LPPRINTER_DEFAULTSW);
  397. typedef BOOL (FAR WINAPI * FPRESETPRINTERW)(HANDLE,LPPRINTER_DEFAULTSW);
  398. typedef BOOL (FAR WINAPI * FPCLOSEPRINTER)(HANDLE);
  399. typedef BOOL (FAR WINAPI * FPGETPRINTERW)(HANDLE,DWORD,LPBYTE,DWORD,LPDWORD);
  400. typedef BOOL (FAR WINAPI * FPGETPRINTERDRIVERW)(HANDLE,LPWSTR,DWORD,LPBYTE,DWORD,LPDWORD);
  401. typedef BOOL (FAR WINAPI * FPENDDOCPRINTER)(HANDLE);
  402. typedef BOOL (FAR WINAPI * FPENDPAGEPRINTER)(HANDLE);
  403. typedef BOOL (FAR WINAPI * FPREADPRINTER)(HANDLE,LPVOID,DWORD,LPDWORD);
  404. typedef BOOL (FAR WINAPI * FPSPLREADPRINTER)(HANDLE,LPBYTE *,DWORD);
  405. typedef DWORD (FAR WINAPI * FPSTARTDOCPRINTERW)(HANDLE,DWORD,LPBYTE);
  406. typedef BOOL (FAR WINAPI * FPSTARTPAGEPRINTER)(HANDLE);
  407. typedef BOOL (FAR WINAPI * FPWRITERPRINTER)(HANDLE,LPVOID,DWORD,LPDWORD);
  408. typedef BOOL (FAR WINAPI * FPABORTPRINTER)(HANDLE);
  409. typedef BOOL (FAR WINAPI * FPQUERYSPOOLMODE)(HANDLE,FLONG*,ULONG*);
  410. typedef INT (FAR WINAPI * FPQUERYREMOTEFONTS)(HANDLE,PUNIVERSAL_FONT_ID,ULONG);
  411. typedef BOOL (FAR WINAPI * FPSEEKPRINTER)(HANDLE,LARGE_INTEGER,PLARGE_INTEGER,DWORD,BOOL);
  412. typedef BOOL (FAR WINAPI * FPQUERYCOLORPROFILE)(HANDLE,PDEVMODEW,ULONG,PVOID,ULONG*,FLONG*);
  413. typedef VOID (FAR WINAPI * FPSPLDRIVERUNLOADCOMPLETE)(LPWSTR);
  414. typedef HANDLE (FAR WINAPI * FPGETSPOOLFILEHANDLE)(HANDLE);
  415. typedef HANDLE (FAR WINAPI * FPCOMMITSPOOLDATA)(HANDLE, HANDLE, DWORD);
  416. typedef BOOL (FAR WINAPI * FPCLOSESPOOLFILEHANDLE)(HANDLE, HANDLE);
  417. typedef LONG (FAR WINAPI * FPDOCUMENTPROPERTIESW)(HWND,HANDLE,LPWSTR,PDEVMODEW,PDEVMODEW,DWORD);
  418. typedef DWORD (FAR WINAPI * FPLOADSPLWOW64)(HANDLE *hProcess);
  419. typedef BOOL (FAR WINAPI * FPISVALIDDEVMODEW)(PDEVMODEW pDevmode, SIZE_T size);
  420. extern HINSTANCE ghSpooler;
  421. extern FPSTARTDOCDLGW fpStartDocDlgW;
  422. extern FPOPENPRINTERW fpOpenPrinterW;
  423. extern FPRESETPRINTERW fpResetPrinterW;
  424. extern FPCLOSEPRINTER fpClosePrinter;
  425. extern FPGETPRINTERW fpGetPrinterW;
  426. extern FPGETPRINTERDRIVERW fpGetPrinterDriverW;
  427. extern PFNDOCUMENTEVENT fpDocumentEvent;
  428. extern FPQUERYCOLORPROFILE fpQueryColorProfile;
  429. extern FPSPLDRIVERUNLOADCOMPLETE fpSplDriverUnloadComplete;
  430. extern FPENDDOCPRINTER fpEndDocPrinter;
  431. extern FPENDPAGEPRINTER fpEndPagePrinter;
  432. extern FPSPLREADPRINTER fpSplReadPrinter;
  433. extern FPREADPRINTER fpReadPrinter;
  434. extern FPSTARTDOCPRINTERW fpStartDocPrinterW;
  435. extern FPSTARTPAGEPRINTER fpStartPagePrinter;
  436. extern FPABORTPRINTER fpAbortPrinter;
  437. extern FPQUERYSPOOLMODE fpQuerySpoolMode;
  438. extern FPQUERYREMOTEFONTS fpQueryRemoteFonts;
  439. extern FPSEEKPRINTER fpSeekPrinter;
  440. extern FPGETSPOOLFILEHANDLE fpGetSpoolFileHandle;
  441. extern FPCOMMITSPOOLDATA fpCommitSpoolData;
  442. extern FPCLOSESPOOLFILEHANDLE fpCloseSpoolFileHandle;
  443. extern FPDOCUMENTPROPERTIESW fpDocumentPropertiesW;
  444. extern FPLOADSPLWOW64 fpLoadSplWow64;
  445. extern FPISVALIDDEVMODEW fpIsValidDevmodeW;
  446. int DocumentEventEx(PUMPD, HANDLE, HDC, INT, ULONG, PVOID, ULONG, PVOID);
  447. DWORD StartDocPrinterWEx(PUMPD, HANDLE, DWORD, LPBYTE);
  448. BOOL EndDocPrinterEx(PUMPD, HANDLE);
  449. BOOL StartPagePrinterEx(PUMPD, HANDLE);
  450. BOOL EndPagePrinterEx(PUMPD, HANDLE);
  451. BOOL AbortPrinterEx(PLDC, BOOL);
  452. BOOL ResetPrinterWEx(PLDC, PRINTER_DEFAULTSW *);
  453. BOOL QueryColorProfileEx(PLDC, PDEVMODEW, ULONG, PVOID, ULONG *, FLONG *);
  454. extern BOOL MFP_StartDocA(HDC hdc, CONST DOCINFOA * pDocInfo, BOOL bBanding );
  455. extern BOOL MFP_StartDocW(HDC hdc, CONST DOCINFOW * pDocInfo, BOOL bBanding );
  456. extern int MFP_StartPage(HDC hdc );
  457. extern int MFP_EndPage(HDC hdc );
  458. extern int MFP_EndFormPage(HDC hdc );
  459. extern int MFP_EndDoc(HDC hdc);
  460. extern BOOL MFP_ResetBanding( HDC hdc, BOOL bBanding );
  461. extern BOOL MFP_ResetDCW( HDC hdc, DEVMODEW *pdmw );
  462. extern int DetachPrintMetafile( HDC hdc );
  463. extern HDC ResetDCWInternal(HDC hdc, CONST DEVMODEW *pdm, BOOL *pbBanding);
  464. extern BOOL PutDCStateInMetafile( HDC hdcMeta );
  465. //font subsetting routines
  466. typedef void *(WINAPIV *CFP_ALLOCPROC) (size_t);
  467. typedef void *(WINAPIV *CFP_REALLOCPROC) (void *, size_t);
  468. typedef void (WINAPIV *CFP_FREEPROC) (void *);
  469. typedef SHORT (FAR WINAPIV * FPCREATEFONTPACKAGE)(const PUCHAR, const ULONG,
  470. PUCHAR*, ULONG*, ULONG*, const USHORT,
  471. const USHORT, const USHORT, const USHORT,
  472. const USHORT, const USHORT,
  473. const PUSHORT, const USHORT,
  474. CFP_ALLOCPROC, CFP_REALLOCPROC, CFP_FREEPROC,
  475. void*);
  476. typedef SHORT (FAR WINAPIV * FPMERGEFONTPACKAGE)(const PUCHAR, const ULONG, const PUCHAR, const ULONG, PUCHAR*,
  477. ULONG*, ULONG*, const USHORT,
  478. CFP_ALLOCPROC, CFP_REALLOCPROC, CFP_FREEPROC,
  479. void*);
  480. extern FPCREATEFONTPACKAGE gfpCreateFontPackage;
  481. extern FPMERGEFONTPACKAGE gfpMergeFontPackage;
  482. // gulMaxCig is used to decide whether font subset should be used for remote printing
  483. extern ULONG gulMaxCig;
  484. #if DBG
  485. #define DBGSUBSET 1
  486. #endif
  487. #ifdef DBGSUBSET
  488. extern FLONG gflSubset;
  489. #define FL_SS_KEEPLIST 1
  490. #define FL_SS_BUFFSIZE 2
  491. #define FL_SS_SPOOLTIME 4
  492. #define FL_SS_PAGETIME 8
  493. #define FL_SS_SUBSETTIME 16
  494. #endif // DBGSUBSET
  495. /**************************************************************************\
  496. *
  497. * EMF structures.
  498. *
  499. * EMFSPOOLHEADER - first thing in a spool file
  500. *
  501. * EMFITEMHEADER - defines items (blocks) of a metafile. This includes
  502. * fonts, pages, new devmode, list of things to do before
  503. * first start page.
  504. *
  505. * cjSize is the size of the data following the header
  506. *
  507. *
  508. \**************************************************************************/
  509. //
  510. // Round up n to the nearest multiple of sizeof(DWORD)
  511. // (also provide a boolean macro to which returns true of the roundup
  512. // calculation would overflow)
  513. #define ROUNDUP_DWORDALIGN(n) (((n) + sizeof(DWORD) - 1) & ~(sizeof(DWORD)-1))
  514. #define BROUNDUP_DWORDALIGN_OVERFLOW(n) (((unsigned)((n)+(sizeof(DWORD)-1)) < (n)) ? 1 : 0)
  515. typedef struct tagEMFSPOOLHEADER {
  516. DWORD dwVersion; // version of this EMF spoolfile
  517. DWORD cjSize; // size of this structure
  518. DWORD dpszDocName; // offset to lpszDocname value of DOCINFO struct
  519. DWORD dpszOutput; // offset to lpszOutput value of DOCINFO struct
  520. } EMFSPOOLHEADER;
  521. #define EMRI_METAFILE 0x00000001
  522. #define EMRI_ENGINE_FONT 0x00000002
  523. #define EMRI_DEVMODE 0x00000003
  524. #define EMRI_TYPE1_FONT 0x00000004
  525. #define EMRI_PRESTARTPAGE 0x00000005
  526. #define EMRI_DESIGNVECTOR 0x00000006
  527. #define EMRI_SUBSET_FONT 0x00000007
  528. #define EMRI_DELTA_FONT 0x00000008
  529. #define EMRI_FORM_METAFILE 0x00000009
  530. #define EMRI_BW_METAFILE 0x0000000A
  531. #define EMRI_BW_FORM_METAFILE 0x0000000B
  532. #define EMRI_METAFILE_DATA 0x0000000C
  533. #define EMRI_METAFILE_EXT 0x0000000D
  534. #define EMRI_BW_METAFILE_EXT 0x0000000E
  535. #define EMRI_ENGINE_FONT_EXT 0x0000000F
  536. #define EMRI_TYPE1_FONT_EXT 0x00000010
  537. #define EMRI_DESIGNVECTOR_EXT 0x00000011
  538. #define EMRI_SUBSET_FONT_EXT 0x00000012
  539. #define EMRI_DELTA_FONT_EXT 0x00000013
  540. #define EMRI_PS_JOB_DATA 0x00000014
  541. #define EMRI_EMBED_FONT_EXT 0x00000015
  542. #define EMF_PLAY_COLOR 0x00000001 // Current DC has DMCOLOR_COLOR
  543. #define EMF_PLAY_MONOCHROME 0x00000002 // Changed by Optimization code to MONOCHROME
  544. #define EMF_PLAY_FORCE_MONOCHROME 0x00000003 // Changed to MONOCHROME in the spool file
  545. #define NORMAL_PAGE 1
  546. #define FORM_PAGE 2
  547. typedef struct tagEMFITEMHEADER
  548. {
  549. DWORD ulID; // either EMRI_METAFILE or EMRI_FONT
  550. DWORD cjSize; // size of item in bytes
  551. } EMFITEMHEADER;
  552. //
  553. // EMF spool file record structure for the following record types:
  554. // EMRI_METAFILE_EXT
  555. // EMRI_BW_METAFILE_EXT
  556. // EMRI_ENGINE_FONT_EXT
  557. // EMRI_TYPE1_FONT_EXT
  558. // EMRI_DESIGNVECTOR_EXT
  559. // EMRI_SUBSET_FONT_EXT
  560. // EMRI_DELTA_FONT_EXT
  561. //
  562. typedef struct tagEMFITEMHEADER_EXT
  563. {
  564. EMFITEMHEADER emfi;
  565. INT64 offset;
  566. } EMFITEMHEADER_EXT;
  567. typedef struct tagEMFITEMPRESTARTPAGE
  568. {
  569. ULONG ulUnused; // originally ulCopyCount
  570. BOOL bEPS;
  571. }EMFITEMPRESTARTPAGE, *PEMFITEMPRESTARTPAGE;
  572. typedef struct tagRECORD_INFO_STRUCT
  573. {
  574. struct tagRECORD_INFO_STRUCT *pNext;
  575. LONGLONG RecordOffset;
  576. ULONG RecordSize;
  577. DWORD RecordID;
  578. } RECORD_INFO_STRUCT, *PRECORD_INFO_STRUCT;
  579. typedef struct tagPAGE_INFO_STRUCT
  580. {
  581. LONGLONG EMFOffset;
  582. LONGLONG SeekOffset;
  583. LPDEVMODEW pDevmode;
  584. ULONG EMFSize;
  585. ULONG ulID;
  586. PRECORD_INFO_STRUCT pRecordInfo;
  587. } PAGE_INFO_STRUCT;
  588. typedef struct tagPAGE_LAYOUT_STRUCT
  589. {
  590. HENHMETAFILE hemf;
  591. DWORD dwPageNumber;
  592. XFORM XFormDC;
  593. RECT rectClip;
  594. RECT rectDocument;
  595. RECT rectBorder;
  596. BOOL bAllocBuffer;
  597. } PAGE_LAYOUT_STRUCT;
  598. typedef struct tagEMF_HANDLE
  599. {
  600. DWORD tag;
  601. DWORD dwPageNumber;
  602. HENHMETAFILE hemf;
  603. BOOL bAllocBuffer;
  604. struct tagEMF_HANDLE *pNext;
  605. } EMF_HANDLE, *PEMF_HANDLE;
  606. typedef struct tagEMF_LIST
  607. {
  608. HENHMETAFILE hemf;
  609. BOOL bAllocBuffer;
  610. struct tagEMF_LIST *pNext;
  611. } EMF_LIST, *PEMF_LIST;
  612. typedef struct tagSPOOL_FILE_HANDLE
  613. {
  614. DWORD tag;
  615. HDC hdc;
  616. HANDLE hSpooler;
  617. LPDEVMODEW pOriginalDevmode;
  618. LPDEVMODEW pLastDevmode;
  619. ULONG MaxPageProcessed;
  620. PAGE_INFO_STRUCT *pPageInfo;
  621. ULONG PageInfoBufferSize;
  622. DWORD dwNumberOfPagesInCurrSide;
  623. BOOL bBanding;
  624. PAGE_LAYOUT_STRUCT *pPageLayout;
  625. DWORD dwNumberOfPagesAllocated;
  626. PEMF_HANDLE pEMFHandle;
  627. DWORD dwPlayBackStatus;
  628. BOOL bUseMemMap;
  629. } SPOOL_FILE_HANDLE;
  630. #define SPOOL_FILE_HANDLE_TAG 'SPHT'
  631. #define SPOOL_FILE_MAX_NUMBER_OF_PAGES_PER_SIDE 32
  632. #define EMF_HANDLE_TAG 'EFHT'
  633. /**************************************************************************\
  634. *
  635. * stuff from csgdi.h
  636. *
  637. \**************************************************************************/
  638. //
  639. // Win32ClientInfo[WIN32_CLIENT_INFO_SPIN_COUNT] corresponds to the
  640. // cSpins field of the CLIENTINFO structure. See ntuser\inc\user.h.
  641. //
  642. #define RESETUSERPOLLCOUNT() ((DWORD)NtCurrentTebShared()->Win32ClientInfo[WIN32_CLIENT_INFO_SPIN_COUNT] = 0)
  643. ULONG cjBitmapSize(CONST BITMAPINFO *pbmi,ULONG iUsage);
  644. ULONG cjBitmapBitsSize(CONST BITMAPINFO *pbmi);
  645. ULONG cjBitmapScanSize(CONST BITMAPINFO *pbmi, int nScans);
  646. BITMAPINFOHEADER * pbmihConvertHeader (BITMAPINFOHEADER *pbmih);
  647. LPBITMAPINFO pbmiConvertInfo(CONST BITMAPINFO *, ULONG, ULONG * ,BOOL);
  648. //
  649. // object.c
  650. //
  651. HANDLE hGetPEBHandle(HANDLECACHETYPE,ULONG);
  652. BOOL bDIBSectionSelected(PDC_ATTR);
  653. PDEVMODEW pdmwGetDefaultDevMode(
  654. HANDLE hSpooler,
  655. PUNICODE_STRING pustrDevice, // device name
  656. PVOID *ppvFree // *ppvFree must be freed by the caller
  657. );
  658. /**************************************************************************\
  659. * DIB flags. These flags are merged with the usage field when calling
  660. * cjBitmapSize to specify what the size should include. Any routine that
  661. * uses these flags should first use the macro, CHECKDIBFLAGS(iUsage) to
  662. * return an error if one of these bits is set. If the definition of
  663. * iUsage changes and one of these flags becomes a valid flag, the interface
  664. * will need to be changed slightly.
  665. *
  666. * 04-June-1991 -by- Eric Kutter [erick]
  667. \**************************************************************************/
  668. #define DIB_MAXCOLORS 0x80000000
  669. #define DIB_NOCOLORS 0x40000000
  670. #define DIB_LOCALFLAGS (DIB_MAXCOLORS | DIB_NOCOLORS)
  671. #define CHECKDIBFLAGS(i) {if (i & DIB_LOCALFLAGS) \
  672. {RIP("INVALID iUsage"); goto MSGERROR;}}
  673. #define HANDLE_TO_INDEX(h) (DWORD)((ULONG_PTR)h & 0x0000ffff)
  674. /******************************Public*Macro********************************\
  675. *
  676. * PSHARED_GET_VALIDATE
  677. *
  678. * Validate all handle information, return user pointer if the handle
  679. * is valid or NULL otherwise.
  680. *
  681. * Arguments:
  682. *
  683. * p - pointer to assign to pUser is successful
  684. * h - handle to object
  685. * iType - handle type
  686. *
  687. \**************************************************************************/
  688. #pragma warning(4:4821) // Disable all ptr64->ptr32 truncation warnings for now
  689. #define PSHARED_GET_VALIDATE(p,h,iType) \
  690. { \
  691. UINT uiIndex = HANDLE_TO_INDEX(h); \
  692. p = NULL; \
  693. \
  694. if (uiIndex < MAX_HANDLE_COUNT) \
  695. { \
  696. PENTRY pentry = &pGdiSharedHandleTable[uiIndex]; \
  697. \
  698. if ( \
  699. (pentry->Objt == iType) && \
  700. (pentry->FullUnique == (USHORT)((ULONG_PTR)h >> 16)) && \
  701. (OBJECTOWNER_PID(pentry->ObjectOwner) == gW32PID) \
  702. ) \
  703. { \
  704. p = (PVOID)(ULONG_PTR)pentry->pUser; \
  705. } \
  706. } \
  707. }
  708. #define VALIDATE_HANDLE(bRet, h,iType) \
  709. { \
  710. UINT uiIndex = HANDLE_TO_INDEX(h); \
  711. bRet = FALSE; \
  712. \
  713. if (uiIndex < MAX_HANDLE_COUNT) \
  714. { \
  715. PENTRY pentry = &pGdiSharedHandleTable[uiIndex]; \
  716. \
  717. if ( \
  718. (pentry->Objt == iType) && \
  719. ((pentry->FullUnique&~FULLUNIQUE_STOCK_MASK) == \
  720. (((USHORT)((ULONG_PTR)h >> 16))&~FULLUNIQUE_STOCK_MASK)) &&\
  721. ((OBJECTOWNER_PID(pentry->ObjectOwner) == gW32PID) || \
  722. (OBJECTOWNER_PID(pentry->ObjectOwner) == 0)) \
  723. ) \
  724. { \
  725. bRet = TRUE; \
  726. } \
  727. } \
  728. }
  729. #define VALIDATE_HANDLE_AND_STOCK(bRet, h, iType, bStock) \
  730. { \
  731. UINT uiIndex = HANDLE_TO_INDEX(h); \
  732. bRet = FALSE; \
  733. bStock = FALSE; \
  734. \
  735. if (uiIndex < MAX_HANDLE_COUNT) \
  736. { \
  737. PENTRY pentry = &pGdiSharedHandleTable[uiIndex]; \
  738. \
  739. if ( \
  740. (pentry->Objt == iType) && \
  741. ((pentry->FullUnique&~FULLUNIQUE_STOCK_MASK) == \
  742. (((USHORT)((ULONG_PTR)h >> 16))&~FULLUNIQUE_STOCK_MASK)) &&\
  743. ((OBJECTOWNER_PID(pentry->ObjectOwner) == gW32PID) || \
  744. (OBJECTOWNER_PID(pentry->ObjectOwner) == 0)) \
  745. ) \
  746. { \
  747. bRet = TRUE; \
  748. bStock = (pentry->FullUnique & FULLUNIQUE_STOCK_MASK); \
  749. } \
  750. } \
  751. }
  752. //
  753. //
  754. // DC_ATTR support
  755. //
  756. //
  757. //
  758. extern PGDI_SHARED_MEMORY pGdiSharedMemory;
  759. extern PDEVCAPS pGdiDevCaps;
  760. extern PENTRY pGdiSharedHandleTable;
  761. extern W32PID gW32PID;
  762. #define SHARECOUNT(hbrush) (pGdiSharedHandleTable[HANDLE_TO_INDEX(h)].ObjectOwner.Share.Count)
  763. /******************************Public*Routine******************************\
  764. *
  765. * FSHARED_DCVALID_RAO - check Valid RAO flag in the handle table entry for
  766. * the hdc
  767. *
  768. * Arguments:
  769. *
  770. * hdc
  771. *
  772. * Return Value:
  773. *
  774. * BOOL flag value
  775. *
  776. \**************************************************************************/
  777. #define FSHARED_DCVALID_RAO(hdc) \
  778. (pGdiSharedHandleTable[HDC_TO_INDEX(hdc)].Flags & \
  779. HMGR_ENTRY_VALID_RAO)
  780. BOOL
  781. DeleteRegion(HRGN);
  782. /******************************Public*Macro********************************\
  783. * ORDER_PRECT makes the rect well ordered
  784. *
  785. * Arguments:
  786. *
  787. * PRECTL prcl
  788. *
  789. \**************************************************************************/
  790. #define ORDER_PRECTL(prcl) \
  791. { \
  792. LONG lt; \
  793. \
  794. if (prcl->left > prcl->right) \
  795. { \
  796. lt = prcl->left; \
  797. prcl->left = prcl->right; \
  798. prcl->right = lt; \
  799. } \
  800. \
  801. if (prcl->top > prcl->bottom) \
  802. { \
  803. lt = prcl->top; \
  804. prcl->top = prcl->bottom; \
  805. prcl->bottom = lt; \
  806. } \
  807. }
  808. //
  809. // client region defines and structures
  810. //
  811. #define CONTAINED 1
  812. #define CONTAINS 2
  813. #define DISJOINT 3
  814. #define VALID_SCR(X) (!((X) & 0xF8000000) || (((X) & 0xF8000000) == 0xF8000000))
  815. #define VALID_SCRPT(P) ((VALID_SCR((P).x)) && (VALID_SCR((P).y)))
  816. #define VALID_SCRPPT(P) ((VALID_SCR((P)->x)) && (VALID_SCR((P)->y)))
  817. #define VALID_SCRRC(R) ((VALID_SCR((R).left)) && (VALID_SCR((R).bottom)) && \
  818. (VALID_SCR((R).right)) && (VALID_SCR((R).top)))
  819. #define VALID_SCRPRC(R) ((VALID_SCR((R)->left)) && (VALID_SCR((R)->bottom)) && \
  820. (VALID_SCR((R)->right)) && (VALID_SCR((R)->top)))
  821. int iRectRelation(PRECTL prcl1, PRECTL prcl2);
  822. int APIENTRY GetRandomRgn(HDC hdc,HRGN hrgn,int iNum);
  823. #define vReferenceCFONTCrit(pcf) {(pcf)->cRef++;}
  824. DWORD GetCodePage(HDC hdc);
  825. #define FLOATARG(f) (*(PULONG)(PFLOAT)&(f))
  826. #define FLOATPTRARG(pf) ((PULONG)(pf))
  827. /******************************Public*Macros******************************\
  828. * FIXUP_HANDLE(h) and FIXUP_HANDLEZ(h)
  829. *
  830. * check to see if the handle has been truncated.
  831. * FIXUP_HANDLEZ() adds an extra check to allow NULL.
  832. *
  833. * Arguments:
  834. * h - handle to be checked and fix
  835. *
  836. * Return Value:
  837. *
  838. * History:
  839. *
  840. * 25-Jan-1996 -by- Lingyun Wang [lingyunw]
  841. *
  842. \**************************************************************************/
  843. #define HANDLE_FIXUP 0
  844. #if DBG
  845. extern INT gbCheckHandleLevel;
  846. #endif
  847. #define NEEDS_FIXING(h) (!((ULONG_PTR)h & 0xffff0000))
  848. #if DBG
  849. #define HANDLE_WARNING() \
  850. { \
  851. if (gbCheckHandleLevel == 1) \
  852. { \
  853. WARNING ("truncated handle\n"); \
  854. } \
  855. ASSERTGDI (gbCheckHandleLevel != 2, "truncated handle\n"); \
  856. }
  857. #else
  858. #define HANDLE_WARNING()
  859. #endif
  860. #if DBG
  861. #define CHECK_HANDLE_WARNING(h, bZ) \
  862. { \
  863. BOOL bFIX = NEEDS_FIXING(h); \
  864. \
  865. if (bZ) bFIX = h && bFIX; \
  866. \
  867. if (bFIX) \
  868. { \
  869. if (gbCheckHandleLevel == 1) \
  870. { \
  871. WARNING ("truncated handle\n"); \
  872. } \
  873. ASSERTGDI (gbCheckHandleLevel != 2, "truncated handle\n"); \
  874. } \
  875. }
  876. #else
  877. #define CHECK_HANDLE_WARNING(h,bZ)
  878. #endif
  879. #if HANDLE_FIXUP
  880. #define FIXUP_HANDLE(h) \
  881. { \
  882. if (NEEDS_FIXING(h)) \
  883. { \
  884. HANDLE_WARNING(); \
  885. h = GdiFixUpHandle(h); \
  886. } \
  887. }
  888. #else
  889. #define FIXUP_HANDLE(h) \
  890. { \
  891. CHECK_HANDLE_WARNING(h,FALSE); \
  892. }
  893. #endif
  894. #if HANDLE_FIXUP
  895. #define FIXUP_HANDLEZ(h) \
  896. { \
  897. if (h && NEEDS_FIXING(h)) \
  898. { \
  899. HANDLE_WARNING(); \
  900. h = GdiFixUpHandle(h); \
  901. } \
  902. }
  903. #else
  904. #define FIXUP_HANDLEZ(h) \
  905. { \
  906. CHECK_HANDLE_WARNING(h,TRUE); \
  907. }
  908. #endif
  909. #define FIXUP_HANDLE_NOW(h) \
  910. { \
  911. if (NEEDS_FIXING(h)) \
  912. { \
  913. HANDLE_WARNING(); \
  914. h = GdiFixUpHandle(h); \
  915. } \
  916. }
  917. /******************************MACRO***************************************\
  918. * CHECK_AND_FLUSH
  919. *
  920. * Check if commands in the batch need to be flushed based on matching
  921. * hdc
  922. *
  923. * Arguments:
  924. *
  925. * hdc
  926. *
  927. * History:
  928. *
  929. * 14-Feb-1996 -by- Mark Enstrom [marke]
  930. *
  931. \**************************************************************************/
  932. #define CHECK_AND_FLUSH(hdc, pdca) \
  933. { \
  934. if ((NtCurrentTebShared()->GdiTebBatch.HDC == (ULONG_PTR)hdc) \
  935. && (pdca->ulDirty_ & BATCHED_DRAWING) \
  936. ) \
  937. { \
  938. NtGdiFlush(); \
  939. pdca->ulDirty_ &= ~BATCHED_DRAWING; \
  940. } \
  941. }
  942. #define CHECK_AND_FLUSH_TEXT(hdc, pdca) \
  943. { \
  944. if ((NtCurrentTebShared()->GdiTebBatch.HDC == (ULONG_PTR)hdc) \
  945. && (pdca->ulDirty_ & BATCHED_TEXT) \
  946. ) \
  947. { \
  948. NtGdiFlush(); \
  949. pdca->ulDirty_ &= ~BATCHED_TEXT; \
  950. pdca->ulDirty_ &= ~BATCHED_DRAWING; \
  951. } \
  952. }
  953. #if defined(_WIN64) || defined(BUILD_WOW6432)
  954. #define KHANDLE_ALIGN(size) ((size + sizeof(KHANDLE) - 1) & ~(sizeof(KHANDLE) - 1))
  955. #else
  956. // no alignment issues on regular 32-bit
  957. #define KHANDLE_ALIGN(size) (size)
  958. #endif
  959. /*********************************MACRO************************************\
  960. * BEGIN_BATCH_HDC
  961. *
  962. * Attemp to place the command in the TEB batch. This macro is for use
  963. * with commands requiring an HDC
  964. *
  965. * Arguments:
  966. *
  967. * hdc - hdc of command
  968. * pdca - PDC_ATTR from hdc
  969. * cType - enum bathc command type
  970. * StrType - specific BATCH structure
  971. *
  972. * Return Value:
  973. *
  974. * none: will jump to UNBATHCED_COMMAND if command can't be batched
  975. *
  976. * History:
  977. *
  978. * 22-Feb-1996 -by- Mark Enstrom [marke]
  979. *
  980. \**************************************************************************/
  981. #define BEGIN_BATCH_HDC(hdc,pdca,cType,StrType) \
  982. { \
  983. PTEBSHARED ptebShared = NtCurrentTebShared(); \
  984. StrType *pBatch; \
  985. HDC hdcBatch = hdc; \
  986. \
  987. if (!( \
  988. ( \
  989. (ptebShared->GdiTebBatch.HDC == 0) || \
  990. (ptebShared->GdiTebBatch.HDC == (ULONG_PTR)hdc) \
  991. ) && \
  992. ((ptebShared->GdiTebBatch.Offset + KHANDLE_ALIGN(sizeof(StrType))) <= GDI_BATCH_SIZE) && \
  993. (pdca != NULL) && \
  994. (!(pdca->ulDirty_ & DC_DIBSECTION)) \
  995. )) \
  996. { \
  997. goto UNBATCHED_COMMAND; \
  998. } \
  999. \
  1000. pBatch = (StrType *)( \
  1001. ((PBYTE)(&ptebShared->GdiTebBatch.Buffer[0])) + \
  1002. ptebShared->GdiTebBatch.Offset \
  1003. ); \
  1004. \
  1005. pBatch->Type = cType; \
  1006. pBatch->Length = KHANDLE_ALIGN(sizeof(StrType)); \
  1007. \
  1008. if (cType < BatchTypeSetBrushOrg) \
  1009. { \
  1010. pdca->ulDirty_ |= BATCHED_DRAWING; \
  1011. } \
  1012. \
  1013. if (cType == BatchTypeTextOut) \
  1014. { \
  1015. pdca->ulDirty_ |= BATCHED_TEXT; \
  1016. }
  1017. /*********************************MACRO************************************\
  1018. * BEGIN_BATCH_HDC
  1019. *
  1020. * Attemp to place the command in the TEB batch. This macro is for use
  1021. * with commands requiring an HDC
  1022. *
  1023. * Arguments:
  1024. *
  1025. * hdc - hdc of command
  1026. * pdca - PDC_ATTR from hdc
  1027. * cType - enum bathc command type
  1028. * StrType - specific BATCH structure
  1029. *
  1030. * Return Value:
  1031. *
  1032. * none: will jump to UNBATHCED_COMMAND if command can't be batched
  1033. *
  1034. * History:
  1035. *
  1036. * 22-Feb-1996 -by- Mark Enstrom [marke]
  1037. *
  1038. \**************************************************************************/
  1039. #define BEGIN_BATCH_HDC_SIZE(hdc,pdca,cType,StrType,Size) \
  1040. { \
  1041. PTEBSHARED ptebShared = NtCurrentTebShared(); \
  1042. StrType *pBatch; \
  1043. HDC hdcBatch = hdc; \
  1044. \
  1045. if (!( \
  1046. ( \
  1047. (ptebShared->GdiTebBatch.HDC == 0) || \
  1048. (ptebShared->GdiTebBatch.HDC == (ULONG_PTR)hdc) \
  1049. ) && \
  1050. ((ptebShared->GdiTebBatch.Offset + KHANDLE_ALIGN(Size)) <= GDI_BATCH_SIZE) && \
  1051. (pdca != NULL) && \
  1052. (!(pdca->ulDirty_ & DC_DIBSECTION)) \
  1053. )) \
  1054. { \
  1055. goto UNBATCHED_COMMAND; \
  1056. } \
  1057. \
  1058. pBatch = (StrType *)( \
  1059. ((PBYTE)(&ptebShared->GdiTebBatch.Buffer[0])) + \
  1060. ptebShared->GdiTebBatch.Offset \
  1061. ); \
  1062. \
  1063. pBatch->Type = cType; \
  1064. pBatch->Length = KHANDLE_ALIGN(Size); \
  1065. \
  1066. if (cType < BatchTypeSetBrushOrg) \
  1067. { \
  1068. pdca->ulDirty_ |= BATCHED_DRAWING; \
  1069. } \
  1070. \
  1071. if (cType == BatchTypeTextOut) \
  1072. { \
  1073. pdca->ulDirty_ |= BATCHED_TEXT; \
  1074. }
  1075. /*********************************MACRO************************************\
  1076. * BEGIN_BATCH
  1077. *
  1078. * Attemp to place the command in the TEB batch. This macro is for use
  1079. * with commands that don't require an HDC
  1080. *
  1081. * Arguments:
  1082. *
  1083. * cType - enum bathc command type
  1084. * StrType - specific BATCH structure
  1085. *
  1086. * Return Value:
  1087. *
  1088. * none: will jump to UNBATHCED_COMMAND if command can't be batched
  1089. *
  1090. * Notes:
  1091. *
  1092. * The "Win32ThreadInfo==NULL" check fixes "issue 2" of bug #338052.
  1093. *
  1094. * If the thread is not a GUI thread, we can't batch non-HDC operations,
  1095. * because we can't guarantee that the batch will be flushed before the
  1096. * thread exits. (GdiThreadCallout isn't called unless the thread is a GUI
  1097. * thread.)
  1098. *
  1099. * History:
  1100. *
  1101. * 22-Feb-1996 -by- Mark Enstrom [marke]
  1102. *
  1103. \**************************************************************************/
  1104. #define BEGIN_BATCH(cType,StrType) \
  1105. { \
  1106. PTEBSHARED ptebShared = NtCurrentTebShared(); \
  1107. StrType *pBatch; \
  1108. HDC hdcBatch = NULL; \
  1109. \
  1110. if (ptebShared->Win32ThreadInfo == NULL) \
  1111. { \
  1112. goto UNBATCHED_COMMAND; \
  1113. } \
  1114. \
  1115. if (! \
  1116. ((ptebShared->GdiTebBatch.Offset + KHANDLE_ALIGN(sizeof(StrType))) <= GDI_BATCH_SIZE) \
  1117. ) \
  1118. { \
  1119. goto UNBATCHED_COMMAND; \
  1120. } \
  1121. \
  1122. pBatch = (StrType *)( \
  1123. ((PBYTE)(&ptebShared->GdiTebBatch.Buffer[0])) + \
  1124. ptebShared->GdiTebBatch.Offset \
  1125. ); \
  1126. \
  1127. pBatch->Type = cType; \
  1128. pBatch->Length = KHANDLE_ALIGN(sizeof(StrType)); \
  1129. /*********************************MACRO************************************\
  1130. * COMPLETE_BATCH_COMMAND
  1131. *
  1132. * Complete batched command started with BEGIN_BATCH or BEGIN_BATCH_HDC.
  1133. * The command is not actually batched unless this macro is executed.
  1134. *
  1135. * Arguments:
  1136. *
  1137. * None
  1138. *
  1139. * Return Value:
  1140. *
  1141. * None
  1142. *
  1143. * History:
  1144. *
  1145. * 22-Feb-1996 -by- Mark Enstrom [marke]
  1146. *
  1147. \**************************************************************************/
  1148. #define COMPLETE_BATCH_COMMAND() \
  1149. if (hdcBatch) \
  1150. { \
  1151. ptebShared->GdiTebBatch.HDC = (ULONG_PTR)hdcBatch; \
  1152. } \
  1153. ptebShared->GdiTebBatch.Offset += \
  1154. (pBatch->Length + sizeof(KHANDLE) - 1) & ~(sizeof(KHANDLE)-1); \
  1155. \
  1156. ptebShared->GdiBatchCount++; \
  1157. if (ptebShared->GdiBatchCount >= GdiBatchLimit) \
  1158. { \
  1159. NtGdiFlush(); \
  1160. } \
  1161. }
  1162. /******************************Public*Routine******************************\
  1163. * HBRUSH CacheSelectBrush (HDC hdc, HBRUSH hbrush)
  1164. *
  1165. * Client side brush caching
  1166. *
  1167. * History:
  1168. * 04-June-1995 -by- Lingyun Wang [lingyunW]
  1169. * Wrote it.
  1170. \**************************************************************************/
  1171. #define CACHE_SELECT_BRUSH(pDcAttr,hbrushNew,hbrushOld) \
  1172. { \
  1173. hbrushOld = 0; \
  1174. \
  1175. if (pDcAttr) \
  1176. { \
  1177. pDcAttr->ulDirty_ |= DC_BRUSH_DIRTY; \
  1178. hbrushOld = pDcAttr->hbrush; \
  1179. pDcAttr->hbrush = hbrushNew; \
  1180. } \
  1181. }
  1182. /******************************Public*Routine******************************\
  1183. * CacheSelectPen
  1184. *
  1185. * Select a pen into DC_ATTR field of DC and set pen flag
  1186. *
  1187. * Arguments:
  1188. *
  1189. * hdc - user hdc
  1190. * hpenNew - New Pen to select
  1191. *
  1192. * Return Value:
  1193. *
  1194. * Old Pen or NULL
  1195. *
  1196. * History:
  1197. *
  1198. * 25-Jan-1996 -by- Mark Enstrom [marke]
  1199. *
  1200. \**************************************************************************/
  1201. #define CACHE_SELECT_PEN(pdcattr,hpenNew, hpenOld) \
  1202. { \
  1203. hpenOld = 0; \
  1204. \
  1205. if (pdcattr) \
  1206. { \
  1207. pdcattr->ulDirty_ |= DC_PEN_DIRTY; \
  1208. hpenOld = pdcattr->hpen; \
  1209. pdcattr->hpen = hpenNew; \
  1210. } \
  1211. }
  1212. /**************************************************************************\
  1213. *
  1214. * far east
  1215. *
  1216. \**************************************************************************/
  1217. extern UINT guintAcp;
  1218. extern UINT guintDBCScp;
  1219. extern UINT fFontAssocStatus;
  1220. extern WCHAR *gpwcANSICharSet;
  1221. extern WCHAR *gpwcDBCSCharSet;
  1222. extern BOOL gbDBCSCodePage;
  1223. UINT WINAPI QueryFontAssocStatus( VOID );
  1224. DWORD FontAssocHack(DWORD,CHAR*,UINT);
  1225. BOOL bComputeTextExtentDBCS(PDC_ATTR,CFONT*,LPCSTR,int,UINT,SIZE*);
  1226. BOOL bComputeCharWidthsDBCS(CFONT*, UINT, UINT, ULONG, PVOID);
  1227. extern BOOL IsValidDBCSRange( UINT iFirst , UINT iLast );
  1228. extern BYTE GetCurrentDefaultChar(HDC hdc);
  1229. extern BOOL bSetUpUnicodeStringDBCS(UINT iFirst,UINT iLast,PUCHAR puchTmp,
  1230. PWCHAR pwc, UINT uiCodePage,CHAR chDefaultChar);
  1231. extern WINAPI NamedEscape(HDC,LPWSTR,int,int,LPCSTR,int,LPSTR);
  1232. extern BOOL RemoteRasterizerCompatible(HANDLE hSpooler);
  1233. void ConvertDxArray(UINT CP,char *pszDBCS,INT *pDxDBCS,UINT c,INT *pDxU, BOOL bPdy);
  1234. #ifdef LANGPACK
  1235. /**************************************************************************\
  1236. *
  1237. * language packs
  1238. *
  1239. \**************************************************************************/
  1240. extern gbLpk;
  1241. extern void InitializeLanguagePack();
  1242. typedef BOOL (* FPLPKINITIALIZE)(DWORD);
  1243. typedef UINT (* FPLPKGETCHARACTERPLACEMENT)
  1244. (HDC,LPCWSTR,int,int,LPGCP_RESULTSW,DWORD,INT);
  1245. typedef BOOL (* FPLPKEXTEXTOUT)
  1246. (HDC,INT,INT,UINT,CONST RECT*,LPCWSTR,UINT,CONST INT*,INT);
  1247. typedef BOOL (* FPLPKGETTEXTEXTENTEXPOINT)
  1248. (HDC, LPCWSTR, INT, INT, LPINT, LPINT, LPSIZE, FLONG, INT);
  1249. typedef BOOL (* FPLPKUSEGDIWIDTHCACHE)(HDC,LPCSTR,int,LONG,BOOL);
  1250. extern FPLPKGETCHARACTERPLACEMENT fpLpkGetCharacterPlacement;
  1251. extern FPLPKEXTEXTOUT fpLpkExtTextOut;
  1252. extern FPLPKGETCHARACTERPLACEMENT fpLpkGetCharacterPlacement;
  1253. extern FPLPKGETTEXTEXTENTEXPOINT fpLpkGetTextExtentExPoint;
  1254. extern FPLPKUSEGDIWIDTHCACHE fpLpkUseGDIWidthCache;
  1255. #endif
  1256. typedef union _BLENDULONG
  1257. {
  1258. BLENDFUNCTION Blend;
  1259. ULONG ul;
  1260. }BLENDULONG,*PBLENDULONG;
  1261. BOOL bMergeSubsetFont(HDC, PVOID, ULONG, PVOID*, ULONG*, BOOL, UNIVERSAL_FONT_ID*);
  1262. PUFIHASH pufihAddUFIEntry(PUFIHASH*, PUNIVERSAL_FONT_ID, ULONG, FLONG, FLONG);
  1263. #define FL_UFI_SUBSET 1
  1264. BOOL bDoFontSubset(PUFIHASH, PUCHAR*, ULONG*, ULONG*);
  1265. BOOL WriteFontToSpoolFile(PLDC, PUNIVERSAL_FONT_ID, FLONG);
  1266. BOOL WriteSubFontToSpoolFile(PLDC, PUCHAR, ULONG, UNIVERSAL_FONT_ID*, BOOL);
  1267. BOOL bAddUFIandWriteSpool(HDC,PUNIVERSAL_FONT_ID,BOOL, FLONG);
  1268. VOID vFreeUFIHashTable( PUFIHASH *pUFIHashBase, FLONG fl);
  1269. BOOL WriteFontDataAsEMFComment(PLDC, DWORD, PVOID, DWORD, PVOID, DWORD);
  1270. //
  1271. // C helper functions for working with EMFSpoolData object
  1272. // (stored in the hEMFSpool field in LDC).
  1273. //
  1274. BOOL AllocEMFSpoolData(PLDC pldc, BOOL banding);
  1275. VOID DeleteEMFSpoolData(PLDC pldc);
  1276. BOOL WriteEMFSpoolData(PLDC pldc, PVOID buffer, ULONG size);
  1277. BOOL FlushEMFSpoolData(PLDC pldc, DWORD pageType);
  1278. #define MMAPCOPY_THRESHOLD 0x100000 // 1MB
  1279. VOID CopyMemoryToMemoryMappedFile(PVOID Destination, CONST VOID *Source, DWORD Length);
  1280. DWORD GetFileMappingAlignment();
  1281. DWORD GetSystemPageSize();
  1282. BOOL MirrorRgnDC(HDC hdc, HRGN hrgn, HRGN *phrgn);
  1283. #define HORZSIZEP 1
  1284. #define VERTSIZEP 2
  1285. #if DBG
  1286. #define EMFVALFAIL(x) DbgPrint x
  1287. #else
  1288. #define EMFVALFAIL(x)
  1289. #endif