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.

539 lines
15 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: CPrinting.cpp
  3. *
  4. * This file contains the code to support the functionality test harness
  5. * for GDI+. This includes menu options and calling the appropriate
  6. * functions for execution.
  7. *
  8. * Created: 05-May-2000 - Jeff Vezina [t-jfvez]
  9. *
  10. * Copyright (c) 2000 Microsoft Corporation
  11. *
  12. \**************************************************************************/
  13. #include "CPrinting.h"
  14. CPrinting::CPrinting(BOOL bRegression)
  15. {
  16. strcpy(m_szName,"Printing");
  17. m_bRegression=bRegression;
  18. }
  19. CPrinting::~CPrinting()
  20. {
  21. }
  22. VOID CPrinting::TestTextPrinting(Graphics *g)
  23. {
  24. Font f(L"Arial", 60);
  25. FontFamily ff(L"Arial");
  26. RectF rectf1( 20, 0, 300, 200);
  27. RectF rectf2( 20, 300, 300, 200);
  28. RectF rectf3(220, 0, 300, 200);
  29. RectF rectf4(220, 300, 300, 200);
  30. Color color1(0xff, 100, 0, 200);
  31. Color color2(128, 100, 0, 200);
  32. Color color3(0xff, 0, 100, 200);
  33. Color color4(128, 0, 100, 0);
  34. SolidBrush brush1(color1);
  35. SolidBrush brush2(color2);
  36. LinearGradientBrush brush3(rectf3, color3, color4, LinearGradientModeForwardDiagonal);
  37. g->DrawString(L"Color1", 6, &f, rectf1, NULL, &brush1);
  38. g->DrawString(L"Color2", 6, &f, rectf2, NULL, &brush2);
  39. g->DrawString(L"Color3", 6, &f, rectf3, NULL, &brush3);
  40. }
  41. VOID CPrinting::TestPerfPrinting(Graphics *g)
  42. {
  43. /*
  44. Analyze file size based on output of StretchDIBits. The claim by DonC is that when we StretchDIBits a
  45. subrectangle of a large DIB, it sends the large DIB to the printer and then clips to the subrectangle.
  46. How stupid, but it apparently does on Win98 postscript.
  47. So this is the results of my test: 1000x1000 DIB (32bpp). I blitted two chunks:
  48. This is 200x200 source rectangle (part of a band):
  49. 04/27/2000 03:00p 22,198 nt5pcl
  50. 04/27/2000 03:02p 268,860 nt5ps // Level 1 ps
  51. 04/27/2000 02:47p 17,488 w98pcl
  52. 04/27/2000 02:47p 6,207,459 w98ps // Level 1 ps
  53. This is 1000x200 source rectangle (an entire band):
  54. 04/27/2000 03:06p 80,291 nt5pcl
  55. 04/27/2000 03:06p 1,266,123 nt5ps // Level 1 ps
  56. 04/27/2000 02:51p 60,210 w98pcl
  57. 04/27/2000 02:52p 6,207,457 w98ps // Level 1 ps
  58. Also compared 32bpp vs. 24bpp DIB. The results were contradictary:
  59. 04/27/2000 03:59p <DIR> ..
  60. 04/27/2000 03:06p 80,291 nt5pcl
  61. 04/27/2000 03:51p 122,881 nt5pcl24
  62. 04/27/2000 03:06p 1,266,123 nt5ps
  63. 04/27/2000 03:51p 1,262,332 nt5ps24
  64. 04/27/2000 02:51p 60,210 w98pcl
  65. 04/27/2000 03:39p 101,216 w98pcl24
  66. 04/27/2000 02:52p 6,207,457 w98ps
  67. 04/27/2000 03:39p 6,207,457 w98ps24
  68. */
  69. if (1)
  70. {
  71. BITMAPINFO bi;
  72. ZeroMemory(&bi, sizeof(BITMAPINFO));
  73. bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  74. bi.bmiHeader.biPlanes = 1;
  75. bi.bmiHeader.biCompression = BI_RGB;
  76. bi.bmiHeader.biSizeImage = 0;
  77. bi.bmiHeader.biWidth = 1000;
  78. bi.bmiHeader.biHeight = 1000;
  79. bi.bmiHeader.biBitCount = 32;
  80. ARGB* Bits = (ARGB*)malloc(bi.bmiHeader.biWidth *
  81. bi.bmiHeader.biHeight *
  82. sizeof(ARGB));
  83. ARGB* Ptr = Bits;
  84. // To eliminate RLE/ASCII85 encoding, set to random bits
  85. for (INT i=0; i<bi.bmiHeader.biHeight; i++)
  86. for (INT j=0; j<bi.bmiHeader.biWidth; j++)
  87. {
  88. *Ptr++ = (ARGB)(i | (j<<16));
  89. }
  90. HDC hdc = g->GetHDC();
  91. StretchDIBits(hdc, 0, 0, 1000, 200,
  92. 0, 700, 1000, 200, Bits, &bi,
  93. DIB_RGB_COLORS, SRCCOPY);
  94. g->ReleaseHDC(hdc);
  95. free(Bits);
  96. }
  97. }
  98. void CPrinting::Draw(Graphics *g)
  99. {
  100. // TestPerfPrinting(g);
  101. // TestTextPrinting(g);
  102. TestBug104604(g);
  103. if (0)
  104. {
  105. #if 1
  106. HDC hdc = g->GetHDC();
  107. HDC bufHdc = CreateCompatibleDC(hdc);
  108. HBITMAP BufDIB = NULL;
  109. ARGB* argb;
  110. struct {
  111. BITMAPINFO bitmapInfo;
  112. RGBQUAD rgbQuad[4];
  113. } bmi;
  114. INT width=100;
  115. INT height=100;
  116. ZeroMemory(&bmi.bitmapInfo, sizeof(bmi.bitmapInfo));
  117. bmi.bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  118. bmi.bitmapInfo.bmiHeader.biWidth = width;
  119. bmi.bitmapInfo.bmiHeader.biHeight = -height;
  120. bmi.bitmapInfo.bmiHeader.biPlanes = 1;
  121. bmi.bitmapInfo.bmiHeader.biBitCount = 24;
  122. bmi.bitmapInfo.bmiHeader.biCompression = BI_RGB;
  123. RGBQUAD red = { 0, 0, 0xFF, 0}; // red
  124. RGBQUAD green = { 0, 0xFF, 0, 0}; // green
  125. RGBQUAD blue = { 0xFF, 0, 0, 0}; // blue
  126. bmi.bitmapInfo.bmiColors[0] = red;
  127. bmi.bitmapInfo.bmiColors[1] = green;
  128. bmi.bitmapInfo.bmiColors[2] = blue;
  129. // if assert fails, then we didn't clean up properly by calling End()
  130. // ASSERT(BufDIB == NULL);
  131. BufDIB = CreateDIBSection(bufHdc,
  132. &bmi.bitmapInfo,
  133. DIB_RGB_COLORS,
  134. (VOID**) &argb,
  135. NULL,
  136. 0);
  137. // ASSERT(BufDIB != NULL);
  138. memset(argb, 0, 3*width*height);
  139. INT i,j;
  140. BYTE* tempptr = (BYTE*)argb;
  141. for (i=0; i<height; i++)
  142. {
  143. for (j=0; j<width; j++)
  144. {
  145. if (i==j)
  146. {
  147. *tempptr++ = 0xFF;
  148. *tempptr++ = 0x80;
  149. *tempptr++ = 0x40;
  150. }
  151. else
  152. tempptr += 3;
  153. }
  154. if ((((ULONG_PTR)tempptr) % 4) != 0) tempptr += 4-(((ULONG_PTR)tempptr) % 4);
  155. }
  156. INT mode = GetMapMode(bufHdc);
  157. // WARNING(("MapMode printing = %08x\n", mode));
  158. SelectObject(bufHdc, BufDIB);
  159. /*
  160. for (i=0; i<100; i++)
  161. {
  162. int result = StretchBlt(hdc, 0, i*2, 2*width, 2, bufHdc, 0, i, width, 0, SRCCOPY);
  163. INT joke = GetLastError();
  164. joke++;
  165. }
  166. */
  167. // int result = StretchBlt(hdc, 0, 0, 50, 50, bufHdc, 0, 0, 50, 50, SRCCOPY);
  168. for (i=0; i<50; i++)
  169. {
  170. int result = StretchBlt(hdc, 0, 100+i*2, 100, 1, bufHdc, 0, i*2, 100, 1, SRCCOPY);
  171. }
  172. // int result = StretchBlt(hdc, 0, 0, 200, 200, bufHdc, 0, 0, 100, 100, SRCCOPY);
  173. // ASSERT(result != 0);
  174. g->ReleaseHDC(hdc);
  175. DeleteDC(bufHdc);
  176. DeleteObject(BufDIB);
  177. #endif
  178. #if 1
  179. REAL widthF = 4; // Pen width
  180. Color redColor(255, 0, 0);
  181. SolidBrush brush1(Color(0xFF,0xFF,0,0));
  182. SolidBrush brush2(Color(0x80,0x80,0,0));
  183. SolidBrush brush3(Color(0xFF,0xFF,0,0));
  184. SolidBrush brush4(Color(0x80,0x80,0,0));
  185. Color colors1[] = { Color(0xFF,0xFF,0,0),
  186. Color(0xFF,0,0xFF,0),
  187. Color(0xFF,0,0,0xFF),
  188. Color(0xFF,0x80,0x80,0x80) };
  189. Color colors2[] = { Color(0x80,0xFF,0,0),
  190. Color(0x80,0,0xFF,0),
  191. Color(0x80,0,0,0xFF),
  192. Color(0x80,0x80,0x80,0x80) };
  193. //SolidBrush brush3(colors1[2]);
  194. //SolidBrush brush4(colors2[2]);
  195. // Default Wrap: Clamp to small rectangle
  196. // RectangleGradientBrush brush3(Rect(125,275,50,50),
  197. // &colors1[0]);//,
  198. //WrapModeClamp);
  199. // Default Wrap: Clamp to
  200. // RectangleGradientBrush brush4(Rect(250,250,100,100),
  201. // &colors2[0]);//,
  202. //WrapModeClamp);
  203. g->SetPageScale(1.2f);
  204. // no path clip
  205. g->FillRectangle(&brush1, Rect(0,25,500,50));
  206. // tests solid + opaque combinations + path clip only
  207. g->FillEllipse(&brush1, Rect(100,100,100,100));
  208. g->FillEllipse(&brush2, Rect(300,100,100,100));
  209. g->FillEllipse(&brush3, Rect(100,250,100,100));
  210. g->FillEllipse(&brush4, Rect(300,250,100,100));
  211. // tests visible clip + path clip
  212. Region origRegion;
  213. g->GetClip(&origRegion);
  214. Region *newRegion = new Region();
  215. newRegion->MakeInfinite();
  216. //Rect horzRect(150, 600, 500, 25);
  217. //Rect vertRect(150, 600, 25, 500);
  218. Rect horzRect(100, 400, 500, 25);
  219. Rect vertRect(100, 400, 25, 500);
  220. Region *horzRegion = new Region(horzRect);
  221. Region *vertRegion = new Region(vertRect);
  222. for (i = 0; i < 10; i++)
  223. {
  224. newRegion->Xor(horzRegion);
  225. newRegion->Xor(vertRegion);
  226. horzRegion->Translate(0, 50);
  227. vertRegion->Translate(50, 0);
  228. }
  229. delete horzRegion;
  230. delete vertRegion;
  231. // Set grid clipping
  232. g->SetClip(newRegion);
  233. // set wrap mode from Clamp to Tile
  234. // brush3.SetWrapMode(WrapModeTile);
  235. // brush4.SetWrapMode(WrapModeTile);
  236. // tests solid + opaque combinations + visible clip + path clip only
  237. g->FillEllipse(&brush1, Rect(100,400,100,100));
  238. g->FillEllipse(&brush2, Rect(300,400,100,100));
  239. g->FillEllipse(&brush3, Rect(100,550,100,100));
  240. g->FillEllipse(&brush4, Rect(300,550,100,100));
  241. // restore original clip region
  242. g->SetClip(&origRegion);
  243. delete newRegion;
  244. // Test case which stretches beyond GetTightBounds() DrawBounds API
  245. PointF pts[8];
  246. pts[0].X = 2150.0f; pts[0].Y = 2928.03f;
  247. pts[1].X = 1950.0f; pts[1].Y = 3205.47f;
  248. pts[2].X = 1750.0f; pts[2].Y = 2650.58f;
  249. pts[3].X = 1550.0f; pts[3].Y = 2928.03f;
  250. pts[4].X = 1550.0f; pts[4].Y = 3371.97f;
  251. pts[5].X = 1750.0f; pts[5].Y = 3094.53f;
  252. pts[6].X = 1950.0f; pts[6].Y = 3649.42f;
  253. pts[7].X = 2150.0f; pts[7].Y = 3371.97f;
  254. BYTE types[8] = { 1, 3, 3, 3, 1, 3, 3, 0x83 };
  255. Bitmap *bitmap = new Bitmap(L"winnt256.bmp");
  256. // Test g->DrawImage
  257. if (bitmap && bitmap->GetLastStatus() == Ok)
  258. {
  259. int i;
  260. for (i=0; i<8; i++)
  261. {
  262. pts[i].X = pts[i].X / 8.0f;
  263. pts[i].Y = pts[i].Y / 8.0f;
  264. }
  265. TextureBrush textureBrush(bitmap, WrapModeTile);
  266. GraphicsPath path(&pts[0], &types[0], 8);
  267. g->FillPath(&textureBrush, &path);
  268. // Text using WrapModeClamp
  269. for (i=0; i<8; i++)
  270. pts[i].X += 200.0f;
  271. TextureBrush textureBrush2(bitmap, WrapModeClamp);
  272. GraphicsPath path2(&pts[0], &types[0], 8);
  273. g->FillPath(&textureBrush2, &path2);
  274. delete bitmap;
  275. }
  276. /*
  277. Font font(50.0f * g->GetDpiY() / 72.0f, // emSize
  278. FontFamily(L"Arial"), // faceName,
  279. 0,
  280. (Unit)g->GetPageUnit()
  281. );
  282. // will fail on Win9x
  283. LPWSTR str = L"Printing Support is COOL";
  284. GpRectF layoutRect1(200, 200, 300, 100);
  285. GpRectF layoutRect2(200, 400, 300, 100);
  286. GpRectF layoutRect3(200, 600, 300, 100);
  287. GpRectF layoutRect4(200, 800, 300, 100);
  288. INT len = 0;
  289. LPWSTR strPtr = str;
  290. while (*str != '\0') { len++; str++; }
  291. StringFormat format1 = StringFormatDirectionRightToLeft;
  292. StringFormat format2 = StringFormatDirectionVertical;
  293. StringFormat format3 = StringFormatDirectionRightToLeft;
  294. StringFormat format4 = StringFormatDirectionVertical;
  295. // Test DDI: SolidText (Brush 1 or 2)
  296. g->DrawString(strPtr, len, &font, &layoutRect1, &format1, &brush1);
  297. g->DrawString(strPtr, len, &font, &layoutRect2, &format2, &brush2);
  298. // Test DDI: BrushText (Brush 3 or 4)
  299. g->DrawString(strPtr, len, &font, &layoutRect3, &format3, &brush3);
  300. g->DrawString(strPtr, len, &font, &layoutRect4, &format4, &brush4);
  301. // Test DDI: StrokePath
  302. // Test DDI: FillRegion
  303. */
  304. #endif
  305. }
  306. }
  307. // Try this from Nolan Lettelier
  308. VOID CPrinting::TestNolan1(Graphics *g)
  309. {
  310. /* TestInit(hdc);
  311. Graphics *pg = Graphics::FromHDC(hdc);
  312. if (pg == NULL)
  313. {
  314. assert(0);
  315. return false;
  316. }
  317. int sts;
  318. int alpha = 255, red = 255, green = 0, blue = 255;
  319. Color c1(alpha,red,green,blue);
  320. Point p1(150,150), p2(300,300);
  321. Color c2(255, 255-red, 255-green, 255-blue);
  322. LineGradientBrush gb(p1, p2, c1, c2);
  323. Pen p(&gb, 50.0);
  324. sts = pg->DrawLine(&p,0, 0, 500, 500);
  325. assert(sts == Ok);
  326. sts = pg->DrawLine(&p,0,100, 500, 100);
  327. assert(sts == Ok);
  328. sts = pg->DrawLine(&p,0,350, 500, 350);
  329. assert(sts == Ok);
  330. sts = pg->DrawLine(&p,0,500, 500, 0);
  331. assert(sts == Ok);
  332. delete pg;
  333. return true;
  334. */
  335. }
  336. VOID CPrinting::TestNolan2(Graphics *g)
  337. {
  338. /*
  339. CString lineText("NolanRules");
  340. Graphics *pg = g;
  341. if (pg == NULL)
  342. {
  343. assert(0);
  344. return false;
  345. }
  346. Unit origUnit = pg->GetPageUnit();
  347. Matrix origXform;
  348. pg->GetTransform(&origXform);
  349. pg->SetPageUnit(UnitInch);
  350. pg->ScaleTransform(8.0f/1000.0f, 8.0f/1000.0f);
  351. Status sts;
  352. int alpha = 255, red = 255, green = 0, blue = 255;
  353. RectF rg(150,150,300,175);
  354. Color c1(alpha,red,green,blue);
  355. Color c2(255, 255-red, 255-green, 255-blue);
  356. LineGradientBrush gb(rg, c1, c2, LineGradientModeVertical);
  357. WCHAR *famName[] = {
  358. L"Comic Sans MS"
  359. , L"Courier New"
  360. , L"Times New Roman"
  361. , L"Tahoma"
  362. , L"Arial"
  363. , L"Lucida Console"
  364. , L"Garamond"
  365. , L"Palatino"
  366. , L"Univers"
  367. , L"Marigold"
  368. , L"Albertus"
  369. , L"Antique Olive"
  370. };
  371. int famCount = sizeof(famName) / sizeof(WCHAR *);
  372. WCHAR *s = L"GDI+ GradientFill";
  373. RectF r(30,30,0,0);
  374. StringFormat sf(0);
  375. FontFamily *pFontFamily;
  376. float lineHeight = 60;
  377. int i;
  378. for (i = 0, r.Y = 30 ; r.Y < 800 ; r.Y += lineHeight, ++i)
  379. {
  380. pFontFamily = new FontFamily(famName[i % famCount]);
  381. while (pFontFamily == NULL || pFontFamily->GetLastStatus()
  382. != Ok)
  383. {
  384. delete pFontFamily;
  385. ++i;
  386. pFontFamily = new FontFamily(famName[i % famCount]);
  387. }
  388. Font f(*pFontFamily, lineHeight * 5 / 6, 0, UnitPoint);
  389. sts = pg->DrawString(s, wcslen(s), &f, &r, &sf, &gb);
  390. // CHECK_RESULT(sts, "TestGradientLinearVertical2 DrawString");
  391. delete pFontFamily;
  392. }
  393. delete pg;
  394. pg->SetPageUnit(origUnit);
  395. pg->SetTransform(&origXform);
  396. return true;
  397. */
  398. } // TestGradientLinearVertical2
  399. VOID CPrinting::TestBug104604(Graphics *g)
  400. {
  401. BYTE* memory = new BYTE[8*8*3];
  402. // checkerboard pattern
  403. for (INT i=0; i<8*8; i += 3)
  404. {
  405. if (i%2)
  406. {
  407. memory[i] = 0xff;
  408. memory[i+1] = 0;
  409. memory[i+2] = 0;
  410. }
  411. else
  412. {
  413. memory[i] = 0;
  414. memory[i+1] = 0;
  415. memory[i+2] = 0xff;
  416. }
  417. }
  418. Bitmap bitmap(8,8, 8*3, PixelFormat24bppRGB, memory);
  419. TextureBrush brush(&bitmap);
  420. g->SetCompositingMode(CompositingModeSourceCopy);
  421. g->FillRectangle(&brush, 0, 0, 100, 100);
  422. }