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.

305 lines
8.3 KiB

  1. //// brush.cpp - brush type tests
  2. //
  3. //
  4. #include "precomp.hpp"
  5. #include "global.h"
  6. #include "gdiplus.h"
  7. ///// Brush tests
  8. //
  9. // Test combinations of foreground background and rotation that
  10. // affect rendering codepaths.
  11. INT BrushTest::GetPageCount()
  12. {
  13. return 5;
  14. }
  15. void BrushTest::GetPageTitle(INT pageNumber, WCHAR *title)
  16. {
  17. title[0] = 0;
  18. wcscat(title, L"AutoText brush test, page settings: ");
  19. switch (pageNumber)
  20. {
  21. case 0: wcscat(title, L"1bpp Grid fit."); break;
  22. case 1: wcscat(title, L"1bpp."); break;
  23. case 2: wcscat(title, L"Anti alias grid fit."); break;
  24. case 3: wcscat(title, L"Anti alias."); break;
  25. case 4: wcscat(title, L"ClearType compatible grid fit."); break;
  26. }
  27. }
  28. /// DrawPage - draw one page of the test
  29. //
  30. //
  31. void BrushTest::DrawPage(
  32. IN Graphics *graphics,
  33. IN INT pageNumber,
  34. IN REAL pageWidth,
  35. IN REAL pageHeight
  36. )
  37. {
  38. PageLayout pageLayout(pageWidth, pageHeight, 10, 10);
  39. SolidBrush solidBlack (Color(0x00, 0x00, 0x00));
  40. SolidBrush solidDark (Color(0x80, 0x80, 0x80));
  41. SolidBrush solidLight (Color(0xc0, 0xc0, 0xc0));
  42. SolidBrush solidWhite (Color(0xf0, 0xf0, 0xf0));
  43. SolidBrush lucentBlack(Color(0x80, 0x00, 0x00, 0x00));
  44. SolidBrush lucentDark (Color(0x80, 0x80, 0x80, 0x80));
  45. SolidBrush lucentLight(Color(0x80, 0xc0, 0xc0, 0xc0));
  46. SolidBrush lucentWhite(Color(0x80, 0xf0, 0xf0, 0xf0));
  47. Pen blackPen(&solidBlack, 1.0);
  48. Font titleFont(
  49. &FontFamily(L"Microsoft Sans Serif"),
  50. 9,
  51. 0,
  52. UnitPoint
  53. );
  54. // Set page rendering hint
  55. switch (pageNumber)
  56. {
  57. case 0: graphics->SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit); break;
  58. case 1: graphics->SetTextRenderingHint(TextRenderingHintSingleBitPerPixel); break;
  59. case 2: graphics->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit); break;
  60. case 3: graphics->SetTextRenderingHint(TextRenderingHintAntiAlias); break;
  61. case 4: graphics->SetTextRenderingHint(TextRenderingHintClearTypeGridFit); break;
  62. }
  63. // Page title
  64. WCHAR title[200];
  65. RectF titleRect;
  66. StringFormat titleFormat(StringFormat::GenericDefault());
  67. titleFormat.SetAlignment(StringAlignmentCenter);
  68. titleFormat.SetLineAlignment(StringAlignmentCenter);
  69. pageLayout.GetFooterRect(&titleRect);
  70. Font pageTitleFont(L"Microsoft Sans Serif", 12, FontStyleBold);
  71. GetPageTitle(pageNumber, title);
  72. graphics->DrawString(
  73. title,
  74. -1,
  75. &pageTitleFont,
  76. titleRect,
  77. &titleFormat,
  78. &solidBlack
  79. );
  80. // Column titles
  81. for (INT column=0; column<10; column++)
  82. {
  83. // Row title
  84. title[0] = 0;
  85. switch (column)
  86. {
  87. case 0: wcscat(title, L"solid black foregrnd"); break;
  88. case 1: wcscat(title, L"solid dark foregrnd"); break;
  89. case 2: wcscat(title, L"solid light foregrnd"); break;
  90. case 3: wcscat(title, L"solid white foregrnd"); break;
  91. case 4: wcscat(title, L"solid grdnt foregrnd"); break;
  92. case 5: wcscat(title, L"lucent black foregrnd"); break;
  93. case 6: wcscat(title, L"lucent dark foregrnd"); break;
  94. case 7: wcscat(title, L"lucent light foregrnd"); break;
  95. case 8: wcscat(title, L"lucent white foregrnd"); break;
  96. case 9: wcscat(title, L"lucent grdnt foregrnd"); break;
  97. }
  98. pageLayout.GetColumnTitleRect(column, &titleRect);
  99. graphics->DrawString(
  100. title,
  101. -1,
  102. &titleFont,
  103. titleRect,
  104. &titleFormat,
  105. &solidBlack
  106. );
  107. }
  108. Font font(
  109. &FontFamily(L"Times New Roman"),
  110. 9,
  111. 0,
  112. UnitPoint
  113. );
  114. // The test rows
  115. for (INT row=0; row<10; row++)
  116. {
  117. Brush *background;
  118. switch (row)
  119. {
  120. // Solid brushes
  121. case 0: background = &solidBlack; break;
  122. case 1: background = &solidDark; break;
  123. case 2: background = &solidLight; break;
  124. case 3: background = &solidWhite; break;
  125. // 50% alpha brushes
  126. case 5: background = &lucentBlack; break;
  127. case 6: background = &lucentDark; break;
  128. case 7: background = &lucentLight; break;
  129. case 8: background = &lucentWhite; break;
  130. // Linear gradient brushes created separately for each item
  131. }
  132. // Row title
  133. title[0] = 0;
  134. switch (row)
  135. {
  136. case 0: wcscat(title, L"solid black backgrnd"); break;
  137. case 1: wcscat(title, L"solid dark backgrnd"); break;
  138. case 2: wcscat(title, L"solid light backgrnd"); break;
  139. case 3: wcscat(title, L"solid white backgrnd"); break;
  140. case 4: wcscat(title, L"solid grdnt backgrnd"); break;
  141. case 5: wcscat(title, L"lucent black backgrnd"); break;
  142. case 6: wcscat(title, L"lucent dark backgrnd"); break;
  143. case 7: wcscat(title, L"lucent light backgrnd"); break;
  144. case 8: wcscat(title, L"lucent white backgrnd"); break;
  145. case 9: wcscat(title, L"lucent grdnt backgrnd"); break;
  146. }
  147. pageLayout.GetRowTitleRect(row, &titleRect);
  148. graphics->DrawString(
  149. title,
  150. -1,
  151. &titleFont,
  152. titleRect,
  153. &titleFormat,
  154. &solidBlack
  155. );
  156. for (INT column=0; column<10; column++)
  157. {
  158. RectF itemRect;
  159. pageLayout.GetItemRect(column, row, &itemRect);
  160. switch (row)
  161. {
  162. // Linear gradient brushes
  163. case 4:
  164. background = new LinearGradientBrush(
  165. itemRect,
  166. Color(0x00, 0x00, 0x00),
  167. Color(0xff, 0xff, 0xff),
  168. LinearGradientModeVertical
  169. );
  170. break;
  171. case 9:
  172. background = new LinearGradientBrush(
  173. itemRect,
  174. Color(0x80, 0x00, 0x00, 0x00),
  175. Color(0x80, 0xff, 0xff, 0xff),
  176. LinearGradientModeVertical
  177. );
  178. break;
  179. }
  180. Brush *foreground;
  181. switch (column)
  182. {
  183. // Solid brushes
  184. case 0: foreground = &solidBlack; break;
  185. case 1: foreground = &solidDark; break;
  186. case 2: foreground = &solidLight; break;
  187. case 3: foreground = &solidWhite; break;
  188. // 50% alpha brushes
  189. case 5: foreground = &lucentBlack; break;
  190. case 6: foreground = &lucentDark; break;
  191. case 7: foreground = &lucentLight; break;
  192. case 8: foreground = &lucentWhite; break;
  193. // Linear gradient brushes
  194. case 4:
  195. foreground = new LinearGradientBrush(
  196. itemRect,
  197. Color(0x00, 0x00, 0x00),
  198. Color(0xff, 0xff, 0xff),
  199. LinearGradientModeHorizontal
  200. );
  201. break;
  202. case 9:
  203. foreground = new LinearGradientBrush(
  204. itemRect,
  205. Color(0x80, 0x00, 0x00, 0x00),
  206. Color(0x80, 0xff, 0xff, 0xff),
  207. LinearGradientModeHorizontal
  208. );
  209. break;
  210. }
  211. graphics->FillRectangle(background, itemRect);
  212. graphics->DrawRectangle(&blackPen, itemRect);
  213. graphics->DrawString(
  214. L"There was an Old Man of the Coast\n\
  215. Who placidly sat on a post;\n\
  216. But when it was cold,\n\
  217. He relinquished his hold,\n\
  218. And called for some hot buttered toast.\n",
  219. -1,
  220. &font,
  221. itemRect,
  222. NULL,
  223. foreground
  224. );
  225. switch (row)
  226. {
  227. case 4: case 9: delete background;
  228. }
  229. switch (column)
  230. {
  231. case 4: case 9: delete foreground;
  232. }
  233. }
  234. }
  235. }