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.

131 lines
4.0 KiB

  1. //// DspFamly.CPP - Display available font families
  2. //
  3. //
  4. #include "precomp.hxx"
  5. #include "global.h"
  6. void PaintFamilies(
  7. HDC hdc,
  8. int *piY,
  9. RECT *prc,
  10. int iLineHeight) {
  11. // Establish available width and height in device coordinates
  12. int DrawingWidth = prc->right - prc->left;
  13. int DrawingHeight = DrawingWidth/2;
  14. // Establish a Graphics with 0,0 at the top left of the drawing area
  15. Graphics g(hdc);
  16. Matrix matrix;
  17. g.ResetTransform();
  18. g.TranslateTransform(REAL(prc->left), REAL(*piY));
  19. // Clear the background
  20. RectF rEntire(0, 0, REAL(DrawingWidth), REAL(DrawingHeight));
  21. SolidBrush whiteBrush(Color(0xff, 0xff, 0xff));
  22. g.FillRectangle(&whiteBrush, rEntire);
  23. // Leave a little space for right and bottom margins
  24. DrawingWidth -= DrawingWidth/40;
  25. DrawingHeight -= DrawingHeight/40;
  26. // Display face names sized to fit: allow 1.5 ems vertical x 20 ems horizontal per char.
  27. // Thus failyCount fonts will take familyCount*30 square ems.
  28. INT emSize = (INT)sqrt(DrawingWidth*DrawingHeight/(g_familyCount*30));
  29. if (emSize < 6)
  30. emSize = 6; // we need a reasonable lower limit otherwise we may div by zero
  31. INT columnCount = DrawingWidth / (emSize*15);
  32. // HFONT hfont = CreateFont(-emSize, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "Tahoma");
  33. // HFONT hOldFont = (HFONT) SelectObject(hdc, hfont);
  34. Color blackColor(0, 0, 0);
  35. SolidBrush blackBrush(blackColor);
  36. Pen blackPen(&blackBrush, 1);
  37. StringFormat format(g_formatFlags);
  38. for (INT i=0; i<g_familyCount; i++) {
  39. WCHAR facename[LF_FACESIZE];
  40. g_families[i].GetFamilyName(facename);
  41. RectF textRect(
  42. REAL(emSize*15*(i%columnCount)),
  43. REAL(emSize*3*(i/columnCount)/2),
  44. REAL(emSize*15),
  45. REAL(emSize*3/2));
  46. g.DrawString(
  47. facename, -1,
  48. &Font(&FontFamily(L"Tahoma"),REAL(emSize), 0, UnitWorld),
  49. textRect,
  50. &format,
  51. &blackBrush);
  52. /*
  53. TextOutW(
  54. hdc,
  55. prc->left + emSize*15*(i%columnCount),
  56. *piY + emSize*3*(i/columnCount)/2,
  57. facename,
  58. lstrlenW(facename)
  59. );
  60. */
  61. // Do some metric analysis
  62. #ifdef TEXTV2
  63. char str[200];
  64. for (INT style = 0; style < 3; style++)
  65. {
  66. if (g_families[i].IsStyleAvailable(style))
  67. {
  68. if (g_families[i].GetTypographicDescent(style) >= 0)
  69. {
  70. wsprintf(str, "%S: typo descent(%d) >= 0\n", facename, g_families[i].GetTypographicDescent(style));
  71. OutputDebugString(str);
  72. }
  73. if (g_families[i].GetTypographicAscent(style) <= 0)
  74. {
  75. wsprintf(str, "%S: typo ascent(%d) <= 0\n", facename, g_families[i].GetTypographicAscent(style));
  76. OutputDebugString(str);
  77. }
  78. if (g_families[i].GetTypographicAscent(style) > g_families[i].GetCellAscent(style))
  79. {
  80. wsprintf(str, "%S: typo ascent(%d) > cell ascent (%d)\n", facename, g_families[i].GetTypographicAscent(style), g_families[i].GetCellAscent(style));
  81. OutputDebugString(str);
  82. }
  83. if (-g_families[i].GetTypographicDescent(style) > g_families[i].GetCellDescent(style))
  84. {
  85. wsprintf(str, "%S: -typo descent(%d) > cell descent (%d)\n", facename, -g_families[i].GetTypographicDescent(style), g_families[i].GetCellDescent(style));
  86. OutputDebugString(str);
  87. }
  88. }
  89. }
  90. #endif
  91. }
  92. // DeleteObject(SelectObject(hdc, hOldFont));
  93. *piY += emSize*3*(1+((g_familyCount-1)/columnCount))/2;
  94. }