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.

756 lines
20 KiB

  1. //////////////////////////////////////////////////////////////////
  2. // File : cfont.cpp
  3. // Purpose : Font handling class source code.
  4. // Shared by each Applet.
  5. // You can compile/test this file. see main() function below.
  6. //
  7. // Date : Thu Jul 01 12:20:34 1999
  8. // Author : toshiak
  9. //
  10. // Copyright(c) 1995-1999, Microsoft Corp. All rights reserved
  11. //////////////////////////////////////////////////////////////////
  12. #ifndef WIN32_LEAN_AND_MEAN
  13. #define WIN32_LEAN_AND_MEAN
  14. #endif
  15. #include <windows.h>
  16. #include <tchar.h>
  17. #include "cfont.h"
  18. #include "cutil.h"
  19. #ifdef _TEST_CFONT
  20. #include <stdio.h>
  21. #endif //_TEST_CFONT
  22. // Safe String
  23. #define STRSAFE_NO_DEPRECATE
  24. #include "strsafe.h"
  25. //----------------------------------------------------------------
  26. //structure define for internal
  27. //----------------------------------------------------------------
  28. #define EFI_STOPIFFOUND 0x00000001
  29. #define EFI_DONTENUMVERT 0x00010000
  30. typedef struct tagENUMFONTINFOA {
  31. DWORD dwFlag;
  32. BOOL fFound;
  33. LOGFONTA logFontIn;
  34. LOGFONTA logFontOut;
  35. }ENUMFONTINFOA, *LPENUMFONTINFOA;
  36. typedef struct tagENUMFONTINFOW {
  37. DWORD dwFlag;
  38. BOOL fFound;
  39. LOGFONTW logFontIn;
  40. LOGFONTW logFontOut;
  41. }ENUMFONTINFOW, *LPENUMFONTINFOW;
  42. #ifdef UNICODE
  43. #define ENUMFONTINFO ENUMFONTINFOW
  44. #define LPENUMFONTINFO LPENUMFONTINFOW
  45. #else
  46. #define ENUMFONTINFO ENUMFONTINFOA
  47. #define LPENUMFONTINFO LPENUMFONTINFOA
  48. #endif
  49. #ifdef UNDER_CE // Windows CE does not support EnumFontFamiliesEx
  50. inline int EnumFontFamiliesEx(HDC hdc, LPLOGFONT lpLogfont, FONTENUMPROC lpEnumFontFamProc,
  51. LPARAM lParam, DWORD)
  52. {
  53. return ::EnumFontFamilies(hdc, lpLogfont->lfFaceName, lpEnumFontFamProc, lParam);
  54. }
  55. #ifndef ZeroMemory // Defined on sdk\inc\objbase.h under new source tree
  56. #define ZeroMemory(dest, len) memset((dest),0,(len))
  57. #endif
  58. #define DEFAULT_GUI_FONT SYSTEM_FONT
  59. #endif // UNDER_CE
  60. //----------------------------------------------------------------
  61. //
  62. // Public Method.
  63. //
  64. //----------------------------------------------------------------
  65. //////////////////////////////////////////////////////////////////
  66. // Function : CFont::CreateDefGUIFont
  67. // Type : HFONT
  68. // Purpose : Create(Copy) DEFAULT_GUI_FONT font Handle.
  69. // Args : None
  70. // Return :
  71. // DATE : Wed Jun 30 18:33:15 1999
  72. // Histroy :
  73. //////////////////////////////////////////////////////////////////
  74. HFONT
  75. CFont::CreateDefGUIFont(VOID)
  76. {
  77. HFONT hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
  78. if(!hFont) {
  79. return NULL;
  80. }
  81. #ifdef AWBOTH
  82. if(CUtil::IsWinNT()) {
  83. LOGFONTW lf;
  84. if(!::GetObjectW(hFont, sizeof(lf), &lf)) {
  85. return NULL;
  86. }
  87. return ::CreateFontIndirectW(&lf);
  88. }
  89. #endif
  90. LOGFONT lf;
  91. if(!::GetObject(hFont, sizeof(lf), &lf)) {
  92. return NULL;
  93. }
  94. return ::CreateFontIndirect(&lf);
  95. }
  96. INT PointSize2LogPixel(INT pointSize)
  97. {
  98. HWND hwnd = NULL;
  99. HDC hDC = ::GetDC(hwnd);
  100. INT dpi = ::GetDeviceCaps(hDC, LOGPIXELSY);
  101. ::ReleaseDC(hwnd, hDC);
  102. return (pointSize * dpi)/72;
  103. }
  104. //////////////////////////////////////////////////////////////////
  105. // Function : CFont::CreateGUIFontByCharSet
  106. // Type : HFONT
  107. // Purpose : Create GUI Font handle with specified characterset.
  108. // Font size is same with DEFAULT_GUI_FONT.
  109. // Args :
  110. // : LPTSTR lpstrFontFace; fontface string to search,
  111. // if this NULL, return first found
  112. // charset HFONT.
  113. // : INT charSet
  114. // : INT poinstSize Inclues VerticalFont or NOT (default is FALSE)
  115. // Return :
  116. // DATE : Wed Jun 30 18:37:54 1999
  117. // Histroy :
  118. //////////////////////////////////////////////////////////////////
  119. HFONT
  120. CFont::CreateGUIFontByNameCharSet(LPTSTR lpstrFontFace,
  121. INT charSet,
  122. INT pointSize)
  123. {
  124. LOGFONT lf, lfDef;
  125. //Get DEFAULT_GUI_FONT's LOGFONT data.
  126. if(!CFont::GetDefGUILogFont(&lfDef)) {
  127. return NULL;
  128. }
  129. //Search Specified charset font's LOGFONT data.
  130. if(!CFont::SearchLogFontByNameCharSet(&lf, lpstrFontFace, charSet, FALSE)) {
  131. return NULL;
  132. }
  133. lfDef.lfCharSet = lf.lfCharSet;
  134. if(pointSize > 0) {
  135. lfDef.lfHeight = - PointSize2LogPixel(pointSize);
  136. }
  137. _tcscpy(lfDef.lfFaceName, lf.lfFaceName);
  138. return ::CreateFontIndirect(&lfDef);
  139. }
  140. #ifdef AWBOTH
  141. HFONT
  142. CFont::CreateGUIFontByNameCharSetW(LPWSTR lpstrFontFace,
  143. INT charSet,
  144. INT pointSize)
  145. {
  146. LOGFONTW lf, lfDef;
  147. //Get DEFAULT_GUI_FONT's LOGFONT data.
  148. if(!CFont::GetDefGUILogFontW(&lfDef)) {
  149. return NULL;
  150. }
  151. //Search Specified charset font's LOGFONT data.
  152. if(!CFont::SearchLogFontByNameCharSetW(&lf, lpstrFontFace, charSet, FALSE)) {
  153. return NULL;
  154. }
  155. lfDef.lfCharSet = lf.lfCharSet;
  156. if(pointSize > 0) {
  157. lfDef.lfHeight = - PointSize2LogPixel(pointSize);
  158. }
  159. lfDef.lfWidth = 0;
  160. wcscpy(lfDef.lfFaceName, lf.lfFaceName);
  161. return ::CreateFontIndirectW(&lfDef);
  162. }
  163. #endif //AWBOTH
  164. //////////////////////////////////////////////////////////////////
  165. // Function : CFont::IsFontExist
  166. // Type : BOOL
  167. // Purpose : Check specified FaceName & charSet font is Exit or NOT.
  168. // Args :
  169. // : LPTSTR lpstrFontFace
  170. // : INT charSet
  171. // Return :
  172. // DATE : Thu Jul 22 23:00:54 1999
  173. // Histroy :
  174. //////////////////////////////////////////////////////////////////
  175. BOOL
  176. CFont::IsFontExist(LPTSTR lpstrFontFace, INT charSet)
  177. {
  178. return CFont::SearchLogFontByNameCharSet(NULL,
  179. lpstrFontFace,
  180. charSet,
  181. FALSE);
  182. }
  183. #ifdef AWBOTH
  184. BOOL
  185. CFont::IsFontExist(LPWSTR lpstrFontFace, INT charSet)
  186. {
  187. return CFont::SearchLogFontByNameCharSetW(NULL,
  188. lpstrFontFace,
  189. charSet,
  190. FALSE);
  191. }
  192. #endif //AWBOTH
  193. //////////////////////////////////////////////////////////////////
  194. // Function : CFont::GetFontNameByCharSet
  195. // Type : BOOL
  196. // Purpose : Serach & Get FontFace with Specified charSet
  197. // Args :
  198. // : INT charSet
  199. // : LPTSTR lpstrFontFace
  200. // : INT cchMax
  201. // Return :
  202. // DATE : Thu Jul 22 23:13:01 1999
  203. // Histroy :
  204. //////////////////////////////////////////////////////////////////
  205. BOOL
  206. CFont::GetFontNameByCharSet(INT charSet,
  207. LPTSTR lpstrFontFace,
  208. INT cchMax)
  209. {
  210. if(!lpstrFontFace) {
  211. return FALSE;
  212. }
  213. if(cchMax < LF_FACESIZE) {
  214. return FALSE;
  215. }
  216. LOGFONT lf;
  217. BOOL fRet = CFont::SearchLogFontByNameCharSet(&lf,
  218. NULL,
  219. charSet,
  220. FALSE);
  221. if(fRet) {
  222. StringCchCopy(lpstrFontFace, cchMax, lf.lfFaceName);
  223. }
  224. return fRet;
  225. }
  226. #ifdef AWBOTH
  227. BOOL
  228. CFont::GetFontNameByCharSetW(INT charSet,
  229. LPWSTR lpstrFontFace,
  230. INT cchMax)
  231. {
  232. if(!lpstrFontFace) {
  233. return FALSE;
  234. }
  235. if(cchMax < LF_FACESIZE) {
  236. return FALSE;
  237. }
  238. LOGFONTW lf;
  239. BOOL fRet = CFont::SearchLogFontByNameCharSetW(&lf,
  240. NULL,
  241. charSet,
  242. FALSE);
  243. if(fRet) {
  244. wcscpy(lpstrFontFace, lf.lfFaceName);
  245. }
  246. return fRet;
  247. }
  248. #endif
  249. //////////////////////////////////////////////////////////////////
  250. // Function : CFont::GetFontInfoByName
  251. // Type : BOOL
  252. // Purpose :
  253. // Args :
  254. // : LPTSTR lpstrFontFace
  255. // : INT * pCharSet
  256. // : INT * pCodePage
  257. // Return :
  258. // DATE : Fri Jul 23 02:48:29 1999
  259. // Histroy :
  260. //////////////////////////////////////////////////////////////////
  261. BOOL
  262. CFont::GetFontInfoByName(LPTSTR lpstrFontFace,
  263. INT *pCharSet,
  264. INT *pCodePage)
  265. {
  266. LOGFONT lf;
  267. BOOL fRet = CFont::SearchLogFontByNameCharSet(&lf,
  268. lpstrFontFace,
  269. DEFAULT_CHARSET,
  270. FALSE);
  271. if(!fRet) {
  272. return FALSE;
  273. }
  274. *pCharSet = (INT)lf.lfCharSet;
  275. CHARSETINFO info;
  276. if(::TranslateCharsetInfo((DWORD *)(DWORD_PTR)*pCharSet,
  277. &info,
  278. TCI_SRCCHARSET)) {
  279. *pCodePage = (INT)info.ciACP;
  280. }
  281. else { //failed
  282. *pCodePage = CP_ACP;
  283. }
  284. return 0;
  285. }
  286. #ifdef AWBOTH
  287. BOOL
  288. CFont::GetFontInfoByNameW(LPWSTR lpstrFontFace,
  289. INT *pCharSet,
  290. INT *pCodePage)
  291. {
  292. LOGFONTW lf;
  293. BOOL fRet = CFont::SearchLogFontByNameCharSetW(&lf,
  294. lpstrFontFace,
  295. DEFAULT_CHARSET,
  296. FALSE);
  297. if(!fRet) {
  298. return FALSE;
  299. }
  300. *pCharSet = (INT)lf.lfCharSet;
  301. CHARSETINFO info;
  302. if(::TranslateCharsetInfo((DWORD *)(DWORD_PTR)*pCharSet,
  303. &info,
  304. TCI_SRCCHARSET)) {
  305. *pCodePage = (INT)info.ciACP;
  306. }
  307. else { //failed
  308. *pCodePage = CP_ACP;
  309. }
  310. return 0;
  311. }
  312. #endif //AWBOTH
  313. //----------------------------------------------------------------
  314. //
  315. // Private method.
  316. //
  317. //----------------------------------------------------------------
  318. //////////////////////////////////////////////////////////////////
  319. // Function : CFont::GetDefGUILogFont
  320. // Type : BOOL
  321. // Purpose :
  322. // Args : LOGFONT *lpLF
  323. // Return :
  324. // DATE : Wed Jul 15 19:36:57 1998
  325. // Histroy :
  326. //////////////////////////////////////////////////////////////////
  327. BOOL
  328. CFont::GetDefGUILogFont(LOGFONT *lpLF)
  329. {
  330. if(!lpLF) {
  331. return FALSE;
  332. }
  333. if(!::GetObject((HFONT)::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), lpLF)) {
  334. return FALSE;
  335. }
  336. return TRUE;
  337. }
  338. ////////////////////
  339. //Unicode version.
  340. ////////////////////
  341. #ifdef AWBOTH
  342. BOOL
  343. CFont::GetDefGUILogFontW(LOGFONTW *lpLF)
  344. {
  345. if(!lpLF) {
  346. return FALSE;
  347. }
  348. if(!::GetObjectW((HFONT)::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONTW), lpLF)) {
  349. return FALSE;
  350. }
  351. return TRUE;
  352. }
  353. #endif //AWBOTH
  354. //////////////////////////////////////////////////////////////////
  355. // Function : CFont::SearchLogFontByNameCharSet
  356. // Type : BOOL
  357. // Purpose : Search LOGFONT data with specified FaceName & charset.
  358. // If FaceName is not specified, return first find charset logfont.
  359. // Args :
  360. // : LOGFONT * lpLF
  361. // : LPTSTR lpstrFontFace
  362. // : INT charSet
  363. // : BOOL fIncVert
  364. // Inclues VerticalFont or NOT (default is FALSE)
  365. // Return :
  366. // DATE : Thu Jul 01 17:12:40 1999
  367. // Histroy :
  368. //////////////////////////////////////////////////////////////////
  369. BOOL
  370. CFont::SearchLogFontByNameCharSet(LOGFONT *lpLF,
  371. LPTSTR lpstrFontFace,
  372. INT charSet,
  373. BOOL fIncVert)
  374. {
  375. HWND hwndDC = NULL;
  376. HDC hDC = ::GetDC(hwndDC);
  377. if(!hDC) {
  378. return FALSE;
  379. }
  380. ENUMFONTINFO enumFontInfo;
  381. LPENUMFONTINFO lpEnumFontInfo = &enumFontInfo;
  382. ::ZeroMemory(&enumFontInfo, sizeof(enumFontInfo));
  383. lpEnumFontInfo->logFontIn.lfCharSet = (BYTE)charSet;
  384. if(lpstrFontFace) {
  385. if(lstrlen(lpstrFontFace) < LF_FACESIZE) {
  386. _tcscpy(lpEnumFontInfo->logFontIn.lfFaceName, lpstrFontFace);
  387. }
  388. }
  389. lpEnumFontInfo->dwFlag = EFI_STOPIFFOUND;
  390. lpEnumFontInfo->dwFlag |= fIncVert ? 0 : EFI_DONTENUMVERT;
  391. lpEnumFontInfo->fFound = FALSE;
  392. ::EnumFontFamiliesEx(hDC,
  393. &lpEnumFontInfo->logFontIn,
  394. (FONTENUMPROC)CFont::EnumFontFamiliesExProc,
  395. (LPARAM)lpEnumFontInfo,
  396. 0);
  397. ::ReleaseDC(hwndDC, hDC);
  398. if(lpEnumFontInfo->fFound) {
  399. if(lpLF) {
  400. *lpLF = lpEnumFontInfo->logFontOut;
  401. }
  402. }
  403. return lpEnumFontInfo->fFound;
  404. }
  405. #ifdef AWBOTH
  406. BOOL
  407. CFont::SearchLogFontByNameCharSetW(LOGFONTW *lpLF,
  408. LPWSTR lpstrFontFace,
  409. INT charSet,
  410. BOOL fIncVert)
  411. {
  412. HWND hwndDC = NULL;
  413. HDC hDC = ::GetDC(hwndDC);
  414. if(!hDC) {
  415. return FALSE;
  416. }
  417. ENUMFONTINFOW enumFontInfo;
  418. LPENUMFONTINFOW lpEnumFontInfo = &enumFontInfo;
  419. ::ZeroMemory(&enumFontInfo, sizeof(enumFontInfo));
  420. lpEnumFontInfo->logFontIn.lfCharSet = (BYTE)charSet;
  421. if(lpstrFontFace) {
  422. if(wcslen(lpstrFontFace) < LF_FACESIZE) {
  423. wcscpy(lpEnumFontInfo->logFontIn.lfFaceName, lpstrFontFace);
  424. }
  425. }
  426. lpEnumFontInfo->dwFlag = EFI_STOPIFFOUND;
  427. lpEnumFontInfo->dwFlag |= fIncVert ? 0 : EFI_DONTENUMVERT;
  428. lpEnumFontInfo->fFound = FALSE;
  429. ::EnumFontFamiliesExW(hDC,
  430. &lpEnumFontInfo->logFontIn,
  431. (FONTENUMPROCW)CFont::EnumFontFamiliesExProcW,
  432. (LPARAM)lpEnumFontInfo,
  433. 0);
  434. ::ReleaseDC(hwndDC, hDC);
  435. if(lpEnumFontInfo->fFound) {
  436. if(lpLF) {
  437. *lpLF = lpEnumFontInfo->logFontOut;
  438. }
  439. }
  440. return lpEnumFontInfo->fFound;
  441. }
  442. #endif
  443. //////////////////////////////////////////////////////////////////
  444. // Function : CFont::EnumFontFamiliesExProc
  445. // Type : INT CALLBACK
  446. // Purpose :
  447. // Args :
  448. // : ENUMLOGFONTEX * lpElf
  449. // : NEWTEXTMETRIC * lpNtm
  450. // : INT iFontType
  451. // : LPARAM lParam
  452. // Return :
  453. // DATE : Thu Jul 01 15:17:56 1999
  454. // Histroy :
  455. //////////////////////////////////////////////////////////////////
  456. INT CALLBACK
  457. CFont::EnumFontFamiliesExProc(ENUMLOGFONTEX *lpElf,
  458. NEWTEXTMETRIC *lpNtm,
  459. INT iFontType,
  460. LPARAM lParam)
  461. {
  462. LPENUMFONTINFO lpEnumFontInfo = (LPENUMFONTINFO)lParam;
  463. if(!lpEnumFontInfo) {
  464. return 0; //Do not continue;
  465. }
  466. if(lpEnumFontInfo->dwFlag & EFI_STOPIFFOUND) {
  467. if(lpEnumFontInfo->logFontIn.lfFaceName[0] == (TCHAR)0x00) {
  468. if(lpEnumFontInfo->logFontIn.lfCharSet == lpElf->elfLogFont.lfCharSet) {
  469. //----------------------------------------------------------------
  470. //if EFI_DONTENUMVERT is set,
  471. //Do skip vertical font enumulation.
  472. //----------------------------------------------------------------
  473. if( (lpEnumFontInfo->dwFlag & EFI_DONTENUMVERT) &&
  474. lpElf->elfLogFont.lfFaceName[0] == (TCHAR)'@') {
  475. return 1; //continue to enum.
  476. }
  477. //Found specified charSet's logfont
  478. lpEnumFontInfo->logFontOut = lpElf->elfLogFont;
  479. lpEnumFontInfo->fFound = TRUE;
  480. return 0; //Do not coninue;
  481. }
  482. }
  483. else {
  484. if(lpEnumFontInfo->logFontIn.lfCharSet == lpElf->elfLogFont.lfCharSet &&
  485. 0 == _tcscmp(lpEnumFontInfo->logFontIn.lfFaceName, lpElf->elfLogFont.lfFaceName)) {
  486. //Found specified charSet's logfont
  487. lpEnumFontInfo->logFontOut = lpElf->elfLogFont;
  488. lpEnumFontInfo->fFound = TRUE;
  489. return 0; //Do not coninue;
  490. }
  491. }
  492. }
  493. else {
  494. #ifdef _TEST_CFONT
  495. extern LPTSTR GetCharset(int );
  496. _tprintf(TEXT("[%-24s] [%-20s][%s][%s][%s]\n"),
  497. lpElf->elfLogFont.lfFaceName,
  498. GetCharset(lpElf->elfLogFont.lfCharSet),
  499. lpElf->elfFullName,
  500. lpElf->elfScript,
  501. lpElf->elfStyle);
  502. #endif
  503. }
  504. return 1;//continue to enum;
  505. UNREFERENCED_PARAMETER(lpNtm);
  506. UNREFERENCED_PARAMETER(iFontType);
  507. }
  508. #ifdef AWBOTH
  509. INT CALLBACK
  510. CFont::EnumFontFamiliesExProcW(ENUMLOGFONTEXW *lpElf,
  511. NEWTEXTMETRIC *lpNtm,
  512. INT iFontType,
  513. LPARAM lParam)
  514. {
  515. LPENUMFONTINFOW lpEnumFontInfo = (LPENUMFONTINFOW)lParam;
  516. if(!lpEnumFontInfo) {
  517. return 0; //Do not continue;
  518. }
  519. if(lpEnumFontInfo->dwFlag & EFI_STOPIFFOUND) {
  520. if(lpEnumFontInfo->logFontIn.lfFaceName[0] == (WCHAR)0x00) {
  521. if(lpEnumFontInfo->logFontIn.lfCharSet == lpElf->elfLogFont.lfCharSet) {
  522. //----------------------------------------------------------------
  523. //if EFI_DONTENUMVERT is set,
  524. //Do skip vertical font enumulation.
  525. //----------------------------------------------------------------
  526. if( (lpEnumFontInfo->dwFlag & EFI_DONTENUMVERT) &&
  527. lpElf->elfLogFont.lfFaceName[0] == (WCHAR)'@') {
  528. return 1; //continue to enum.
  529. }
  530. //Found specified charSet's logfont
  531. lpEnumFontInfo->logFontOut = lpElf->elfLogFont;
  532. lpEnumFontInfo->fFound = TRUE;
  533. return 0; //Do not coninue;
  534. }
  535. }
  536. else {
  537. if(lpEnumFontInfo->logFontIn.lfCharSet == lpElf->elfLogFont.lfCharSet &&
  538. 0 == wcscmp(lpEnumFontInfo->logFontIn.lfFaceName, lpElf->elfLogFont.lfFaceName)) {
  539. //Found specified charSet's logfont
  540. lpEnumFontInfo->logFontOut = lpElf->elfLogFont;
  541. lpEnumFontInfo->fFound = TRUE;
  542. return 0; //Do not coninue;
  543. }
  544. }
  545. }
  546. return 1;//continue to enum;
  547. UNREFERENCED_PARAMETER(lpNtm);
  548. UNREFERENCED_PARAMETER(iFontType);
  549. }
  550. #endif //AWBOTH
  551. //----------------------------------------------------------------
  552. //
  553. // test program for cfontex.cpp
  554. //
  555. // how to compile.
  556. // 1. for ANSI.
  557. // cl cfontex.cpp -I../common -D_TEST_CFONT -link user32.lib advapi32.lib gdi32.lib
  558. // 2. for Ansi&Wide both
  559. // cl cfontex.cpp -I../common -DAWBOTH -D_TEST_CFONT -link user32.lib advapi32.lib gdi32.lib
  560. // 2. for Unicode.
  561. // cl cfontex.cpp -I../common -DUNICODE -D_UNICODE -D_TEST_CFONT -link user32.lib advapi32.lib gdi32.lib
  562. //----------------------------------------------------------------
  563. #ifdef _TEST_CFONT
  564. #if defined(UNICODE) || defined(_UNICODE)
  565. #define DEFSTR(a) {a, L ## #a}
  566. #else
  567. #define DEFSTR(a) {a, #a}
  568. #endif
  569. typedef struct tagIDSTR {
  570. INT id;
  571. TCHAR *p;
  572. }IDSTR;
  573. IDSTR idstr[]= {
  574. DEFSTR(ANSI_CHARSET),
  575. DEFSTR(DEFAULT_CHARSET),
  576. DEFSTR(SYMBOL_CHARSET),
  577. DEFSTR(SHIFTJIS_CHARSET),
  578. DEFSTR(HANGEUL_CHARSET),
  579. DEFSTR(HANGUL_CHARSET),
  580. DEFSTR(GB2312_CHARSET),
  581. DEFSTR(CHINESEBIG5_CHARSET),
  582. DEFSTR(OEM_CHARSET),
  583. DEFSTR(JOHAB_CHARSET),
  584. DEFSTR(HEBREW_CHARSET),
  585. DEFSTR(ARABIC_CHARSET),
  586. DEFSTR(GREEK_CHARSET),
  587. DEFSTR(TURKISH_CHARSET),
  588. DEFSTR(VIETNAMESE_CHARSET),
  589. DEFSTR(THAI_CHARSET),
  590. DEFSTR(EASTEUROPE_CHARSET),
  591. DEFSTR(RUSSIAN_CHARSET),
  592. DEFSTR(MAC_CHARSET),
  593. DEFSTR(BALTIC_CHARSET),
  594. };
  595. #define ArrayCount(a) sizeof(a)/sizeof(a[0])
  596. LPTSTR GetCharset(INT charset)
  597. {
  598. static TCHAR szbuf[256];
  599. int i;
  600. for( i = 0; i < ArrayCount(idstr); i++) {
  601. if(charset == idstr[i].id) {
  602. return idstr[i].p;
  603. }
  604. }
  605. wsprintf(szbuf, TEXT("Unknown Charset[0x%08x]"), charset);
  606. return szbuf;
  607. }
  608. VOID PrintLogFont(LOGFONT *lplf)
  609. {
  610. _tprintf(TEXT("lfHeight [%d]\n"), lplf->lfHeight);
  611. _tprintf(TEXT("lfWidth [%d]\n"), lplf->lfWidth );
  612. _tprintf(TEXT("lfEscapement [%d]\n"), lplf->lfEscapement);
  613. _tprintf(TEXT("lfOrientation [%d]\n"), lplf->lfOrientation);
  614. _tprintf(TEXT("lfWeight [%d]\n"), lplf->lfWeight);
  615. _tprintf(TEXT("lfItalic [%d]\n"), lplf->lfItalic);
  616. _tprintf(TEXT("lfUnderline [%d]\n"), lplf->lfUnderline);
  617. _tprintf(TEXT("lfStrikeOut [%d]\n"), lplf->lfStrikeOut);
  618. _tprintf(TEXT("lfCharSet [%d]\n"), lplf->lfCharSet);
  619. _tprintf(TEXT("lfOutPrecision [%d]\n"), lplf->lfOutPrecision);
  620. _tprintf(TEXT("lfClipPrecision [%d]\n"), lplf->lfClipPrecision);
  621. _tprintf(TEXT("lfQuality [%d]\n"), lplf->lfQuality);
  622. _tprintf(TEXT("lfPitchAndFamily[%d]\n"), lplf->lfPitchAndFamily);
  623. _tprintf(TEXT("lfFaceName [%s]\n"), lplf->lfFaceName);
  624. }
  625. #include <windows.h>
  626. #include <stdio.h>
  627. #include <tchar.h>
  628. #include <mbstring.h>
  629. #include <mbctype.h>
  630. #include <locale.h>
  631. #include "cfont.h"
  632. #include "cutil.h"
  633. #include "cutil.cpp"
  634. extern LPTSTR GetCharset(INT charset);
  635. void main(void)
  636. {
  637. _tsetlocale(LC_ALL, TEXT(".ACP"));
  638. HWND hwndDC = NULL;
  639. HDC hDC = ::GetDC(hwndDC);
  640. ENUMFONTINFO enumFontInfo;
  641. LPENUMFONTINFO lpEnumFontInfo = &enumFontInfo;
  642. #if 0
  643. ::ZeroMemory(&enumFontInfo, sizeof(enumFontInfo));
  644. lpEnumFontInfo->logFontIn.lfCharSet = (BYTE)DEFAULT_CHARSET;
  645. lpEnumFontInfo->dwFlag = 0;
  646. _tprintf(TEXT("Enumlate All Font\n"));
  647. ::EnumFontFamiliesEx(hDC,
  648. &lpEnumFontInfo->logFontIn,
  649. (FONTENUMPROC)CFont::EnumFontFamiliesExProc,
  650. (LPARAM)lpEnumFontInfo,
  651. 0);
  652. ::ZeroMemory(&enumFontInfo, sizeof(enumFontInfo));
  653. lpEnumFontInfo->logFontIn.lfCharSet = ANSI_CHARSET;
  654. lpEnumFontInfo->dwFlag = 0;
  655. _tprintf(TEXT("Enumulate ANSI_CHARSET font\n"));
  656. ::EnumFontFamiliesEx(hDC,
  657. &lpEnumFontInfo->logFontIn,
  658. (FONTENUMPROC)CFont::EnumFontFamiliesExProc,
  659. (LPARAM)lpEnumFontInfo,
  660. 0);
  661. _tprintf(TEXT("Enumulate SHIFTJIS_CHARSET font\n"));
  662. ::ZeroMemory(&enumFontInfo, sizeof(enumFontInfo));
  663. lpEnumFontInfo->logFontIn.lfCharSet = SHIFTJIS_CHARSET;
  664. lpEnumFontInfo->dwFlag = 0;
  665. ::EnumFontFamiliesEx(hDC,
  666. &lpEnumFontInfo->logFontIn,
  667. (FONTENUMPROC)CFont::EnumFontFamiliesExProc,
  668. (LPARAM)lpEnumFontInfo,
  669. 0);
  670. ::ReleaseDC(hwndDC, hDC);
  671. #endif
  672. LOGFONT lf;
  673. BOOL fRet;
  674. static LPTSTR fontNameList[]= { TEXT("MS Mincho"),
  675. TEXT("MS Gothic"),
  676. TEXT("MS UI Gothic"),
  677. TEXT("�l�r ����"),
  678. TEXT("�l�r �o����"),
  679. TEXT("�l�r �S�V�b�N"),
  680. TEXT("�l�r �o�S�V�b�N")};
  681. CFont::GetDefGUILogFont(&lf);
  682. _tprintf(TEXT("DEFAULT_GUI_FONT LOGFONT\n"));
  683. PrintLogFont(&lf);
  684. int i;
  685. for(i = 0; i < sizeof(fontNameList)/sizeof(fontNameList[0]); i++) {
  686. fRet = CFont::SearchLogFontByNameCharSet(&lf,
  687. fontNameList[i],
  688. SHIFTJIS_CHARSET);
  689. _tprintf(TEXT("Search Font [%-20s] %s\n"),
  690. fontNameList[i],
  691. fRet ? TEXT("FOUND") : TEXT("NOT FOUND"));
  692. if(fRet) {
  693. PrintLogFont(&lf);
  694. HFONT hFont = CFont::CreateGUIFontByNameCharSet(fontNameList[i],
  695. SHIFTJIS_CHARSET, FALSE);
  696. LOGFONT lfNew;
  697. ::GetObject(hFont, sizeof(lfNew), &lfNew);
  698. PrintLogFont(&lfNew);
  699. }
  700. }
  701. }
  702. #endif //_TEST_CFONT