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.

491 lines
12 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright 1994-1998 Microsoft Corporation. All Rights Reserved.
  7. //
  8. // PROGRAM: CSSAMP
  9. //
  10. // PURPOSE: Demonstrate and test Uniscribe APIs
  11. //
  12. // PLATFORMS: Windows 95, 98, NT 4, NT 5.
  13. //
  14. #include "precomp.hxx"
  15. #define GLOBALS_HERE 1
  16. #include "global.h"
  17. #include "..\gpinit.inc"
  18. //#define ICECAP 1 // Since this isn't defined for some reason automatically
  19. #ifdef ICECAP
  20. #include "icecap.h"
  21. #endif // ICECAP
  22. /* Testing
  23. Font* ConstructFontWithCellHeight(
  24. const WCHAR *familyName,
  25. INT style,
  26. REAL cellHeight, // From positive LOGFONT.lfHeight
  27. Unit unit
  28. )
  29. {
  30. // Get the family details so we can do height arithmetic
  31. const FontFamily family(familyName);
  32. if (!family.IsStyleAvailable(style))
  33. {
  34. return NULL;
  35. }
  36. // Convert cell height to em height
  37. REAL emSize = cellHeight * family.GetEmHeight(style)
  38. / ( family.GetCellAscent(style)
  39. + family.GetCellDescent(style));
  40. return new Font(&family, emSize, style, unit);
  41. }
  42. */
  43. // Check to see if a given pathname contains a path or not...
  44. BOOL HasPath(char *szPathName)
  45. {
  46. BOOL fResult = false;
  47. ASSERT(szPathName);
  48. if (!szPathName)
  49. return fResult;
  50. char *p = szPathName;
  51. while(*p)
  52. {
  53. if (*p == '\\')
  54. {
  55. // We found a backslash - we have a path
  56. fResult = true;
  57. break;
  58. }
  59. p++;
  60. }
  61. return fResult;
  62. }
  63. // Strip any filename (and final backslash) from a pathname
  64. void StripFilename(char *szPathName)
  65. {
  66. ASSERT(szPathName);
  67. if (szPathName)
  68. {
  69. char *p = szPathName + (strlen(szPathName)-1);
  70. while(p > szPathName)
  71. {
  72. if (*p == '\\')
  73. {
  74. // Terminate the string at the first backslash.
  75. *p = 0;
  76. break;
  77. }
  78. p--;
  79. }
  80. }
  81. }
  82. //// Initialise
  83. //
  84. void Initialise()
  85. {
  86. INITCOMMONCONTROLSEX icce;
  87. icce.dwSize = sizeof(icce);
  88. icce.dwICC = ICC_BAR_CLASSES;
  89. InitCommonControlsEx(&icce);
  90. InitStyles();
  91. InitText(ID_INITIAL_TEXT);
  92. g_familyCount = g_InstalledFontCollection.GetFamilyCount();
  93. g_families = new FontFamily[g_familyCount];
  94. g_InstalledFontCollection.GetFamilies(g_familyCount, g_families, &g_familyCount);
  95. // Default values...
  96. g_szSourceTextFile[0] = 0;
  97. g_szProfileName[0] = 0;
  98. // Generate the application base directory...
  99. GetModuleFileNameA(g_hInstance, g_szAppDir, sizeof(g_szAppDir));
  100. StripFilename(g_szAppDir);
  101. }
  102. // Parse the command line...
  103. void ParseCommandLine(char *szCmdLine)
  104. {
  105. char *p = szCmdLine;
  106. // Look for a -p...
  107. while(*p)
  108. {
  109. switch (*p)
  110. {
  111. case '-' :
  112. case '/' :
  113. {
  114. // we have a command, so figure out what it is...
  115. p++; // next char indicate which command...
  116. switch(*p)
  117. {
  118. case 'p' :
  119. case 'P' :
  120. {
  121. char szProfileName[MAX_PATH];
  122. int i = 0;
  123. // Profile filename follows immediately (no spaces)
  124. p++; // skip the 'p'
  125. while(*p && *p != '\b')
  126. {
  127. szProfileName[i] = *p;
  128. i++;
  129. p++;
  130. }
  131. // Terminate the string...
  132. szProfileName[i] = 0;
  133. if (strlen(szProfileName) > 0)
  134. {
  135. if (!HasPath(szProfileName))
  136. {
  137. // Look for the profile file in the application directory
  138. wsprintfA(g_szProfileName, "%s\\%s", g_szAppDir, szProfileName);
  139. }
  140. else
  141. {
  142. // Otherwise it already contains a path
  143. strcpy(g_szProfileName, szProfileName);
  144. }
  145. }
  146. }
  147. break;
  148. }
  149. }
  150. break;
  151. default :
  152. break;
  153. }
  154. p++;
  155. }
  156. }
  157. //// WinMain - Application entry point and dispatch loop
  158. //
  159. //
  160. int APIENTRY WinMain(
  161. HINSTANCE hInst,
  162. HINSTANCE hPrevInstance,
  163. char *pCmdLine,
  164. int nCmdShow) {
  165. MSG msg;
  166. HACCEL hAccelTable;
  167. RECT rc;
  168. RECT rcMain;
  169. int iNumRenders = 1;
  170. if (!gGdiplusInitHelper.IsValid())
  171. {
  172. return 0;
  173. }
  174. g_hInstance = hInst; // Global hInstance
  175. #ifdef ICECAP
  176. // Mark the profile...
  177. StopProfile(PROFILE_GLOBALLEVEL, PROFILE_CURRENTID);
  178. #endif // ICECAP
  179. Initialise();
  180. // Parse the command line...
  181. ParseCommandLine(pCmdLine);
  182. // Read the global settings from the profile...
  183. ReadProfileInfo(g_szProfileName);
  184. // Over-ride number of renders on initial display...
  185. iNumRenders = g_iNumRenders;
  186. g_iNumRenders = 1;
  187. // It is possible that we want to use a file for the default text, so try to load it
  188. if (lstrlenA(g_szSourceTextFile) > 0)
  189. {
  190. char szFullPathText[MAX_PATH];
  191. if (!HasPath(g_szSourceTextFile))
  192. {
  193. // Look for the source text file in the application directory
  194. wsprintfA(szFullPathText, "%s\\%s", g_szAppDir, g_szSourceTextFile);
  195. }
  196. else
  197. {
  198. // Otherwise it contains a path already
  199. strcpy(szFullPathText, g_szSourceTextFile);
  200. }
  201. // This will replace the initial text with the text from the file
  202. InsertText(NULL, szFullPathText);
  203. }
  204. // Create main text window
  205. g_hTextWnd = CreateTextWindow();
  206. // Add dialog boxes on leading side
  207. g_hSettingsDlg = CreateDialogA(
  208. g_hInstance,
  209. "Settings",
  210. g_hTextWnd,
  211. SettingsDlgProc);
  212. g_hGlyphSettingsDlg = CreateDialogA(
  213. g_hInstance,
  214. "GlyphSettings",
  215. g_hTextWnd,
  216. GlyphSettingsDlgProc);
  217. g_hDriverSettingsDlg = CreateDialogA(
  218. g_hInstance,
  219. "DriverSettings",
  220. g_hTextWnd,
  221. DriverSettingsDlgProc);
  222. // Establish positon of text surface relative to the dialog
  223. GetWindowRect(g_hSettingsDlg, &rc);
  224. g_iSettingsWidth = rc.right - rc.left;
  225. g_iSettingsHeight = rc.bottom - rc.top;
  226. // Establish offset from main window to settings dialog
  227. GetWindowRect(g_hTextWnd, &rcMain);
  228. g_iMinWidth = rc.right - rcMain.left;
  229. g_iMinHeight = rc.bottom - rcMain.top;
  230. // Size main window to include dialog and text surface
  231. SetWindowPos(
  232. g_hTextWnd,
  233. NULL,
  234. 0,0,
  235. g_iMinWidth * 29 / 10, g_iMinHeight,
  236. SWP_NOZORDER | SWP_NOMOVE);
  237. // Position the sub dialogs below the main dialog
  238. SetWindowPos(
  239. g_hGlyphSettingsDlg,
  240. NULL,
  241. 0, rc.bottom-rc.top,
  242. 0,0,
  243. SWP_NOZORDER | SWP_NOSIZE);
  244. SetWindowPos(
  245. g_hDriverSettingsDlg,
  246. NULL,
  247. 0, rc.bottom-rc.top,
  248. 0,0,
  249. SWP_NOZORDER | SWP_NOSIZE);
  250. if (g_FontOverride)
  251. {
  252. // Update the styles with the values read from the profile...
  253. for(int iStyle=0;iStyle<5;iStyle++)
  254. {
  255. SetStyle(
  256. iStyle,
  257. g_iFontHeight,
  258. g_Bold ? 700 : 300,
  259. g_Italic ? 1 : 0,
  260. g_Underline ? 1 : 0,
  261. g_Strikeout ? 1 : 0,
  262. g_szFaceName);
  263. }
  264. }
  265. if (g_AutoDrive)
  266. {
  267. int iFont = 0;
  268. int iHeight = 0;
  269. int cFonts = 1;
  270. int cHeights = 1;
  271. int iIteration = 0;
  272. int iRepeatPaint = 0;
  273. int iStyle = 0;
  274. g_fPresentation = true;
  275. // Move the settings window out of the way...
  276. ShowWindow(g_hTextWnd, SW_SHOWNORMAL);
  277. SetWindowPos(g_hSettingsDlg, HWND_BOTTOM, -g_iSettingsWidth, 0, g_iSettingsWidth, g_iSettingsHeight, SWP_NOREDRAW);
  278. UpdateWindow(g_hSettingsDlg);
  279. // Initial Paint to setup font cache...
  280. InvalidateText();
  281. UpdateWindow(g_hTextWnd);
  282. // Reset the render multiplier...
  283. g_iNumRenders = iNumRenders;
  284. #ifdef ICECAP
  285. // Start the profiling...
  286. StartProfile(PROFILE_GLOBALLEVEL, PROFILE_CURRENTID);
  287. #endif // ICECAP
  288. if (g_AutoFont)
  289. cFonts = g_iAutoFonts;
  290. if (g_AutoHeight)
  291. cHeights = g_iAutoHeights;
  292. for(iIteration = 0;iIteration < g_iNumIterations; iIteration++)
  293. {
  294. for(iFont=0;iFont<cFonts;iFont++)
  295. {
  296. for(iHeight=0;iHeight<cHeights;iHeight++)
  297. {
  298. TCHAR szFaceName[MAX_PATH];
  299. int iFontHeight = g_iFontHeight;
  300. if (g_AutoFont)
  301. {
  302. lstrcpy(szFaceName, g_rgszAutoFontFacenames[iFont]);
  303. }
  304. else
  305. {
  306. lstrcpy(szFaceName, g_szFaceName);
  307. }
  308. if (g_AutoHeight)
  309. iFontHeight = g_rgiAutoHeights[iHeight];
  310. // Update the styles with the values read from the profile...
  311. for(int iStyle=0;iStyle<5;iStyle++)
  312. {
  313. SetStyle(
  314. iStyle,
  315. iFontHeight,
  316. g_Bold ? 700 : 300,
  317. g_Italic ? 1 : 0,
  318. g_Underline ? 1 : 0,
  319. g_Strikeout ? 1 : 0,
  320. szFaceName);
  321. }
  322. for(int iPaint=0;iPaint<g_iNumRepaints;iPaint++)
  323. {
  324. // Force a re-display of the entire text window...
  325. InvalidateText();
  326. UpdateWindow(g_hTextWnd);
  327. }
  328. }
  329. }
  330. }
  331. #ifdef ICECAP
  332. // Stop the profiling...
  333. StopProfile(PROFILE_GLOBALLEVEL, PROFILE_CURRENTID);
  334. #endif // ICECAP
  335. // Trigger application exit
  336. PostMessage(g_hTextWnd, WM_DESTROY, (WPARAM)0, (LPARAM)0);
  337. }
  338. else
  339. {
  340. ShowWindow(g_hTextWnd, SW_SHOWNORMAL);
  341. InvalidateText();
  342. UpdateWindow(g_hTextWnd);
  343. }
  344. // Main message loop
  345. if (g_bUnicodeWnd) {
  346. hAccelTable = LoadAcceleratorsW(g_hInstance, APPNAMEW);
  347. while (GetMessageW(&msg, (HWND) NULL, 0, 0) > 0) {
  348. if ( !IsDialogMessageW(g_hSettingsDlg, &msg)
  349. && !IsDialogMessageW(g_hGlyphSettingsDlg, &msg)
  350. && !TranslateAcceleratorW(g_hTextWnd, hAccelTable, &msg))
  351. {
  352. TranslateMessage(&msg);
  353. DispatchMessageW(&msg);
  354. }
  355. }
  356. } else {
  357. hAccelTable = LoadAcceleratorsA(g_hInstance, APPNAMEA);
  358. while (GetMessageA(&msg, (HWND) NULL, 0, 0) > 0) {
  359. if ( !IsDialogMessageA(g_hSettingsDlg, &msg)
  360. && !IsDialogMessageA(g_hGlyphSettingsDlg, &msg)
  361. && !TranslateAcceleratorA(g_hTextWnd, hAccelTable, &msg)
  362. )
  363. {
  364. TranslateMessage(&msg);
  365. DispatchMessageA(&msg);
  366. }
  367. }
  368. }
  369. FreeStyles();
  370. delete [] g_families;
  371. return (int)msg.wParam;
  372. UNREFERENCED_PARAMETER(hPrevInstance);
  373. UNREFERENCED_PARAMETER(pCmdLine);
  374. UNREFERENCED_PARAMETER(nCmdShow);
  375. }