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.

286 lines
7.6 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: CText.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 "CText.h"
  14. CText::CText(BOOL bRegression)
  15. {
  16. strcpy(m_szName,"Text");
  17. m_bRegression=bRegression;
  18. }
  19. CText::~CText()
  20. {
  21. }
  22. void CText::Draw(Graphics *g)
  23. {
  24. //Font font(L"Arial", 60);
  25. FontFamily ff(L"Arial");
  26. RectF rectf(20.0f/500.0f*TESTAREAWIDTH, 0.0f/500.0f*TESTAREAHEIGHT, 500.0f/500.0f*TESTAREAWIDTH, 300.0f/500.0f*TESTAREAHEIGHT);
  27. GraphicsPath path;
  28. // Solid color text.
  29. Color color(128, 100, 0, 200);
  30. SolidBrush brush(color);
  31. path.AddString(L"Color", 5, &ff, 0, 100.0f/500.0f*TESTAREAWIDTH, rectf, NULL);
  32. g->FillPath(&brush, &path);
  33. // Texture text.
  34. WCHAR filename[256];
  35. wcscpy(filename, L"../data/marble1.jpg");
  36. Bitmap *bitmap = new Bitmap(filename);
  37. TextureBrush textureBrush(bitmap, WrapModeTile);
  38. path.Reset();
  39. rectf.Y = 100.0f/500.0f*TESTAREAWIDTH;
  40. path.AddString(L"Texture", 7, &ff, 0, 100.0f/500.0f*TESTAREAWIDTH, rectf, NULL);
  41. g->FillPath(&textureBrush, &path);
  42. delete bitmap;
  43. // Gradient text.
  44. rectf.Y = 200.0f/500.0f*TESTAREAWIDTH;
  45. path.Reset();
  46. path.AddString(L"Gradient", 8, &ff, 0, 100.0f/500.0f*TESTAREAWIDTH, rectf, NULL);
  47. Color color1(255, 255, 0, 0);
  48. Color color2(255, 0, 255, 0);
  49. LinearGradientBrush lineGrad(rectf, color1, color2, 0.0f);
  50. g->FillPath(&lineGrad, &path);
  51. // Shadow test
  52. REAL charHeight = 100.0f/500.0f*TESTAREAWIDTH;
  53. REAL topMargin = - 5;
  54. rectf.Y = - charHeight - topMargin; // Make y-coord of the base line
  55. // of the characters to be 0.
  56. path.Reset();
  57. path.AddString(L"Shadow", 6, &ff, 0, charHeight, rectf, NULL);
  58. GraphicsPath* clonePath = path.Clone();
  59. Color redColor(255, 0, 0);
  60. Color grayColor(128, 0, 0, 0);
  61. SolidBrush redBrush(redColor);
  62. SolidBrush grayBrush(grayColor);
  63. // Shadow part.
  64. REAL tx = 0.0f/500.0f*TESTAREAWIDTH, ty = 400.0f/500.0f*TESTAREAHEIGHT;
  65. Matrix skew;
  66. skew.Scale(1.0, 0.5);
  67. skew.Shear(-2.0, 0, MatrixOrderAppend);
  68. skew.Translate(tx, ty, MatrixOrderAppend);
  69. clonePath->Transform(&skew);
  70. g->FillPath(&grayBrush, clonePath);
  71. delete clonePath;
  72. // Front part.
  73. Matrix trans1;
  74. trans1.Translate(tx, ty);
  75. path.Transform(&trans1);
  76. g->FillPath(&redBrush, &path);
  77. return;
  78. /*
  79. REAL x = 200, y = 150;
  80. RectF brushRect(x, y, 150, 32);
  81. Color colors[4] = {
  82. Color(180, 255, 0, 0),
  83. Color(180, 0, 255, 0),
  84. Color(180, 255, 0, 0),
  85. Color(180, 0, 255, 0)
  86. };
  87. // RectangleGradientBrush rectGrad(brushRect, (Color*)&colors, WrapModeTile);
  88. // g->DrawString(L"GDI+", &font, &rectGrad, x, y);
  89. // And now with DrawText
  90. RectF rect(400, 200, 400, 400);
  91. g->DrawText(
  92. DrawTextDisplay,
  93. L"A few words powered by GDI+: \
  94. \x3c3\x3bb\x3b1\x3b4 \
  95. \x627\x644\x633\x644\x627\x645 \
  96. \x5e9\x5dc\x5d5\x5dd \
  97. \xe2d\xe4d\xe01\xe29\xe23\xe44\xe17\xe22 \
  98. \x110\x068\x0ea\x300\x103",
  99. &font, // Initial font
  100. &rectGrad, // Initial brush (ignored for the time being)
  101. LANG_NEUTRAL, // Initial language
  102. &rect // Formatting rectangle
  103. );
  104. */
  105. }
  106. /*
  107. int CALLBACK TestSpecificFont(CONST LOGFONT *lplf,CONST TEXTMETRIC *lptm,DWORD dwType,LPARAM lpData)
  108. {
  109. static REAL x = 50, y = 50;
  110. HFONT hf = CreateFontIndirect(lplf);
  111. Graphics *g = (Graphics*) lpData;
  112. Color red(0x80FF0000);
  113. Brush *brush = new SolidBrush(red);
  114. // g->DrawString(L"This is a test.", (VOID*)hf, brush, x, y);
  115. delete brush;
  116. x = x + lplf->lfWidth * 2;
  117. y = y + lplf->lfHeight + 5;
  118. DeleteObject(hf);
  119. return 1;
  120. }
  121. VOID TestText(Graphics *g, HWND hwnd)
  122. {
  123. HDC hdc = GetDC(hwnd);
  124. // enumerate the fonts in the system
  125. EnumFonts(hdc, NULL, &TestSpecificFont, (LPARAM)g);
  126. ReleaseDC(hwnd, hdc);
  127. }
  128. void CText::Draw(Graphics *g)
  129. {
  130. Point points[4];
  131. REAL width = 4; // Pen width
  132. WCHAR filename[]=L"../data/4x5_trans_Q60_cropped_1k.jpg";
  133. // Open the image with the appropriate ICM mode.
  134. Bitmap *bitmap = new Bitmap(filename, TRUE);
  135. // Create a texture brush.
  136. Unit u;
  137. RectF copyRect;
  138. bitmap->GetBounds(&copyRect, &u);
  139. copyRect.X = copyRect.Width/2-1;
  140. copyRect.Width = copyRect.Width/4-1;
  141. copyRect.X += copyRect.Width;
  142. copyRect.Height = copyRect.Height/2-1;
  143. // Our ICM profile is hacked to flip the red and blue color channels
  144. // Apply a recolor matrix to flip them back so that if something breaks
  145. // ICM, the picture will look blue instead of the familiar colors.
  146. ImageAttributes *img = new ImageAttributes();
  147. img->SetWrapMode(WrapModeTile, Color(0xffff0000), FALSE);
  148. ColorMatrix flipRedBlue =
  149. {0, 0, 1, 0, 0,
  150. 0, 1, 0, 0, 0,
  151. 1, 0, 0, 0, 0,
  152. 0, 0, 0, 1, 0,
  153. 0, 0, 0, 0, 1};
  154. img->SetColorMatrix(&flipRedBlue);
  155. img->SetICMMode(TRUE);
  156. img->SetWrapMode(WrapModeTile, Color(0xffff0000), FALSE);
  157. // Create a texture brush.
  158. TextureBrush textureBrush(bitmap, copyRect, img);
  159. // Create a radial gradient pen.
  160. Color redColor(255, 0, 0);
  161. SolidBrush redBrush(redColor);
  162. Pen redPen(&redBrush, width);
  163. GraphicsPath *path;
  164. points[0].X = 100*3+300;
  165. points[0].Y = 60*3-100;
  166. points[1].X = -50*3+300;
  167. points[1].Y = 60*3-100;
  168. points[2].X = 150*3+300;
  169. points[2].Y = 250*3-100;
  170. points[3].X = 200*3+300;
  171. points[3].Y = 120*3-100;
  172. path = new GraphicsPath(FillModeAlternate);
  173. path->AddBeziers(points, 4);
  174. g->FillPath(&textureBrush, path);
  175. g->DrawPath(&redPen, path);
  176. delete img;
  177. delete path;
  178. delete bitmap;
  179. PointF destPoints[3];
  180. destPoints[0].X = 300;
  181. destPoints[0].Y = 50;
  182. destPoints[1].X = 450;
  183. destPoints[1].Y = 50;
  184. destPoints[2].X = 240;
  185. destPoints[2].Y = 200;
  186. Matrix mat;
  187. mat.Translate(0, 100);
  188. mat.TransformPoints(&destPoints[0], 3);
  189. wcscpy(filename, L"../data/apple1.png");
  190. bitmap = new Bitmap(filename);
  191. g->DrawImage(bitmap, &destPoints[0], 3);
  192. delete bitmap;
  193. destPoints[0].X = 30;
  194. destPoints[0].Y = 200;
  195. destPoints[1].X = 200;
  196. destPoints[1].Y = 200;
  197. destPoints[2].X = 200;
  198. destPoints[2].Y = 420;
  199. wcscpy(filename, L"../data/dog2.png");
  200. bitmap = new Bitmap(filename);
  201. g->DrawImage(bitmap, &destPoints[0], 3);
  202. delete bitmap;
  203. Color color(100, 128, 255, 0);
  204. SolidBrush brush(color);
  205. Point pts[10];
  206. INT count = 4;
  207. pts[0].X = 150;
  208. pts[0].Y = 60;
  209. pts[1].X = 100;
  210. pts[1].Y = 230;
  211. pts[2].X = 250;
  212. pts[2].Y = 260;
  213. pts[3].X = 350;
  214. pts[3].Y = 100;
  215. g->FillClosedCurve(&brush, pts, count);
  216. wcscpy(filename, L"../data/ballmer.jpg");
  217. bitmap = new Bitmap(filename);
  218. RectF destRect(220, 50, 180, 120);
  219. RectF srcRect;
  220. srcRect.X = 100;
  221. srcRect.Y = 40;
  222. srcRect.Width = 200;
  223. srcRect.Height = 200;
  224. g->DrawImage(bitmap, destRect, srcRect.X, srcRect.Y,
  225. srcRect.Width, srcRect.Height, UnitPixel);
  226. delete bitmap;
  227. }
  228. */