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.

234 lines
4.7 KiB

  1. //// family.cpp - String format tests
  2. //
  3. //
  4. #include "precomp.hpp"
  5. #include "global.h"
  6. #include "gdiplus.h"
  7. ///// Family tests
  8. //
  9. // Test combinations of style with each family
  10. //
  11. // 2 rows for each family using all style combinations
  12. //
  13. // 6 families per page
  14. void GetInstalledFamilies()
  15. {
  16. InstalledFontCollection installedFonts;
  17. G.InstalledFamilyCount = installedFonts.GetFamilyCount();
  18. G.InstalledFamilies = new FontFamily[G.InstalledFamilyCount];
  19. installedFonts.GetFamilies(
  20. G.InstalledFamilyCount,
  21. G.InstalledFamilies,
  22. &G.InstalledFamilyCount
  23. );
  24. }
  25. void ReleaseInstalledFamilies()
  26. {
  27. G.InstalledFamilyCount = 0;
  28. delete [] G.InstalledFamilies;
  29. }
  30. INT FamilyTest::GetPageCount()
  31. {
  32. return (G.InstalledFamilyCount + 5) / 6;
  33. }
  34. void FamilyTest::GetPageTitle(INT pageNumber, WCHAR *title)
  35. {
  36. title[0] = 0;
  37. wcscat(title, L"AutoText family test.");
  38. }
  39. Font *GetItemFont(INT page, INT row, INT column)
  40. {
  41. INT familyIndex = page*6 + row/2;
  42. if (familyIndex < G.InstalledFamilyCount)
  43. {
  44. return new Font(
  45. G.InstalledFamilies + familyIndex,
  46. 9,
  47. FontStyle(((row & 1) << 4) + column),
  48. UnitPoint
  49. );
  50. }
  51. else
  52. {
  53. return NULL;
  54. }
  55. }
  56. /// DrawPage - draw one page of the test
  57. //
  58. //
  59. void FamilyTest::DrawPage(
  60. IN Graphics *graphics,
  61. IN INT page,
  62. IN REAL pageWidth,
  63. IN REAL pageHeight
  64. )
  65. {
  66. PageLayout pageLayout(pageWidth, pageHeight, 8, 12);
  67. SolidBrush blackBrush(Color(0, 0, 0));
  68. Pen blackPen(&blackBrush, 1.0);
  69. // Display title at bottom of page
  70. StringFormat titleFormat(StringFormat::GenericDefault());
  71. titleFormat.SetAlignment(StringAlignmentCenter);
  72. titleFormat.SetLineAlignment(StringAlignmentCenter);
  73. RectF titleRect;
  74. pageLayout.GetFooterRect(&titleRect);
  75. Font pageTitleFont(L"Microsoft Sans Serif", 12, FontStyleBold);
  76. WCHAR title[200];
  77. GetPageTitle(page, title);
  78. graphics->DrawString(
  79. title,
  80. -1,
  81. &pageTitleFont,
  82. titleRect,
  83. &titleFormat,
  84. &blackBrush
  85. );
  86. // Display row titles
  87. Font titleFont(
  88. &FontFamily(L"Microsoft Sans Serif"),
  89. 9,
  90. 0,
  91. UnitPoint
  92. );
  93. for (INT i=0; i<12; i++)
  94. {
  95. pageLayout.GetRowTitleRect(i, &titleRect);
  96. Font *rowFont = GetItemFont(page, i, 3); // bold/italic available if any are!
  97. if (rowFont)
  98. {
  99. FontFamily rowFamily;
  100. rowFont->GetFamily(&rowFamily);
  101. delete rowFont;
  102. rowFamily.GetFamilyName(title);
  103. graphics->DrawString(
  104. title,
  105. -1,
  106. &titleFont,
  107. titleRect,
  108. &titleFormat,
  109. &blackBrush
  110. );
  111. }
  112. }
  113. // Display column titles
  114. for (INT i=0; i<8; i++)
  115. {
  116. pageLayout.GetColumnTitleRect(i, &titleRect);
  117. title[0] = 0;
  118. if (i==0)
  119. {
  120. wcscat(title, L"regular");
  121. }
  122. else
  123. {
  124. if (i & 1)
  125. {
  126. wcscat(title, L"bold ");
  127. }
  128. if (i & 2)
  129. {
  130. wcscat(title, L"italic ");
  131. }
  132. if (i & 4)
  133. {
  134. wcscat(title, L"underline ");
  135. }
  136. }
  137. graphics->DrawString(
  138. title,
  139. -1,
  140. &titleFont,
  141. titleRect,
  142. &titleFormat,
  143. &blackBrush
  144. );
  145. }
  146. // Prepare common string format for this page
  147. StringFormat stringFormat(StringFormat::GenericDefault());
  148. // The tests themselves
  149. for (INT row=0; row<12; row++)
  150. {
  151. for (INT column=0; column<8; column++)
  152. {
  153. Font *itemFont = GetItemFont(page, row, column);
  154. if (itemFont)
  155. {
  156. RectF itemRect;
  157. pageLayout.GetItemRect(column, row, &itemRect);
  158. graphics->DrawRectangle(&blackPen, itemRect);
  159. graphics->DrawString(
  160. L"There was an Old Man of the Coast\n\
  161. Who placidly sat on a post;\n\
  162. But when it was cold,\n\
  163. He relinquished his hold,\n\
  164. And called for some hot buttered toast.\n",
  165. -1,
  166. itemFont,
  167. itemRect,
  168. &stringFormat,
  169. &blackBrush
  170. );
  171. delete itemFont;
  172. }
  173. }
  174. }
  175. }