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.

188 lines
4.6 KiB

  1. //// DspDriver.CPP - Display strings with DrawDriverString API
  2. //
  3. //
  4. #include "precomp.hxx"
  5. #include "global.h"
  6. void PaintDrawDriverString(
  7. HDC hdc,
  8. int *piY,
  9. RECT *prc,
  10. int iLineHeight) {
  11. int icpLineStart; // First character of line
  12. int icpLineEnd; // End of line (end of buffer or index of CR character)
  13. HFONT hFont;
  14. HFONT hOldFont;
  15. LOGFONT lf;
  16. BOOL testMetafile = FALSE;
  17. // Establish available width and height in device coordinates
  18. int plainTextWidth = prc->right - prc->left;
  19. int plainTextHeight = prc->bottom - *piY;
  20. Graphics *g = NULL;
  21. Metafile *metafile = NULL;
  22. if (testMetafile)
  23. {
  24. metafile = new Metafile(L"c:\\GdiPlusTest.emf", hdc);
  25. g = new Graphics(metafile);
  26. }
  27. else
  28. {
  29. g = new Graphics(hdc);
  30. g->ResetTransform();
  31. g->TranslateTransform(REAL(prc->left), REAL(*piY));
  32. g->SetSmoothingMode(g_SmoothingMode);
  33. }
  34. g->SetPageUnit(UnitPixel);
  35. g->SetTextContrast(g_GammaValue);
  36. g->SetTextRenderingHint(g_TextMode);
  37. // Clear the background
  38. RectF rEntire(0, 0, REAL(plainTextWidth), REAL(plainTextHeight));
  39. SolidBrush whiteBrush(Color(0xff, 0xff, 0xff));
  40. g->FillRectangle(g_textBackBrush, rEntire);
  41. // Apply selected world transform, adjusted to a little away from top
  42. // left edge.
  43. g->SetTransform(&g_WorldTransform);
  44. g->TranslateTransform(
  45. //REAL(prc->left + plainTextWidth/20),
  46. //REAL(*piY + plainTextHeight/10),
  47. REAL(prc->left + plainTextWidth/2),
  48. REAL(*piY + plainTextHeight/2),
  49. MatrixOrderAppend);
  50. Color grayColor(0xc0, 0xc0, 0xc0);
  51. SolidBrush grayBrush(grayColor);
  52. Pen grayPen(&grayBrush, 1.0);
  53. // Put some text in the middle
  54. Color blackColor(0, 0, 0);
  55. SolidBrush blackBrush(blackColor);
  56. Pen blackPen(&blackBrush, 1.0);
  57. Font font(&FontFamily(g_style[0].faceName), REAL(g_style[0].emSize), g_style[0].style, g_fontUnit);
  58. // Prepare array of glyph origins
  59. PointF *origins;
  60. if (g_DriverOptions & DriverStringOptionsRealizedAdvance)
  61. {
  62. origins = new PointF[1];
  63. if (!origins)
  64. {
  65. return;
  66. }
  67. origins[0].X = 0.0;
  68. origins[0].Y = 0.0;
  69. }
  70. else
  71. {
  72. origins = new PointF[g_iTextLen];
  73. if (!origins)
  74. {
  75. return;
  76. }
  77. origins[0].X = 0.0;
  78. origins[0].Y = 0.0;
  79. for (INT i=1; i<g_iTextLen; i++)
  80. {
  81. origins[i].X = origins[i-1].X + g_DriverDx;
  82. origins[i].Y = origins[i-1].Y + g_DriverDy;
  83. }
  84. }
  85. RectF measuredBoundingBox;
  86. // Change the font size to the pixel height requested in g_DriverPixels,
  87. // and map to the actual height showing here by adjusting the
  88. // world transform.
  89. REAL scale = REAL(font.GetSize() / g_DriverPixels);
  90. Font scaledFont(&FontFamily(g_style[0].faceName), g_DriverPixels, g_style[0].style, g_fontUnit);
  91. for(int iRender=0;iRender<g_iNumRenders;iRender++)
  92. {
  93. {
  94. g->DrawDriverString(
  95. g_wcBuf,
  96. g_iTextLen,
  97. &font,
  98. g_textBrush,
  99. origins,
  100. g_DriverOptions,
  101. &g_DriverTransform
  102. );
  103. }
  104. }
  105. {
  106. g->MeasureDriverString(
  107. g_wcBuf,
  108. g_iTextLen,
  109. &font,
  110. origins,
  111. g_DriverOptions,
  112. &g_DriverTransform,
  113. &measuredBoundingBox
  114. );
  115. }
  116. // Mark the first origin with a cross
  117. g->DrawLine(&blackPen, origins[0].X, origins[0].Y-4, origins[0].X, origins[0].Y+4);
  118. g->DrawLine(&blackPen, origins[0].X-4, origins[0].Y, origins[0].X+4, origins[0].Y);
  119. delete [] origins;
  120. g->DrawRectangle(
  121. &Pen(&SolidBrush(Color(0x80,0x80,0x80)), 1.0),
  122. measuredBoundingBox
  123. );
  124. delete g;
  125. if (metafile) delete metafile;
  126. if (testMetafile)
  127. {
  128. // Playback metafile to screen
  129. Metafile emfplus(L"c:\\GdiPlusTest.emf");
  130. Graphics graphPlayback(hdc);
  131. graphPlayback.ResetTransform();
  132. graphPlayback.TranslateTransform(REAL(prc->left), REAL(*piY));
  133. graphPlayback.DrawImage(
  134. &emfplus,
  135. REAL(0),
  136. REAL(0),
  137. REAL(plainTextWidth),
  138. REAL(plainTextHeight)
  139. );
  140. graphPlayback.Flush();
  141. }
  142. *piY += plainTextHeight;
  143. }