============================================================================= Style_SelectFont()
| 2590 | // Style_SelectFont() |
| 2591 | // |
| 2592 | BOOL Style_SelectFont ( HWND hwnd, LPWSTR lpszStyle, int cchStyle, BOOL bDefaultStyle ) |
| 2593 | { |
| 2594 | CHOOSEFONT cf; |
| 2595 | LOGFONT lf; |
| 2596 | WCHAR szNewStyle[512]; |
| 2597 | int iValue; |
| 2598 | WCHAR tch[32]; |
| 2599 | HDC hdc; |
| 2600 | ZeroMemory ( &cf, sizeof ( CHOOSEFONT ) ); |
| 2601 | ZeroMemory ( &lf, sizeof ( LOGFONT ) ); |
| 2602 | // Map lpszStyle to LOGFONT |
| 2603 | if ( Style_StrGetFont ( lpszStyle, tch, COUNTOF ( tch ) ) ) { |
| 2604 | lstrcpyn ( lf.lfFaceName, tch, COUNTOF ( lf.lfFaceName ) ); |
| 2605 | } |
| 2606 | if ( Style_StrGetCharSet ( lpszStyle, &iValue ) ) { |
| 2607 | lf.lfCharSet = iValue; |
| 2608 | } |
| 2609 | if ( Style_StrGetSize ( lpszStyle, &iValue ) ) { |
| 2610 | hdc = GetDC ( hwnd ); |
| 2611 | lf.lfHeight = -MulDiv ( iValue, GetDeviceCaps ( hdc, LOGPIXELSY ), 72 ); |
| 2612 | ReleaseDC ( hwnd, hdc ); |
| 2613 | } |
| 2614 | lf.lfWeight = ( StrStrI ( lpszStyle, L"bold" ) ) ? FW_BOLD : FW_NORMAL; |
| 2615 | lf.lfItalic = ( StrStrI ( lpszStyle, L"italic" ) ) ? 1 : 0; |
| 2616 | // Init cf |
| 2617 | cf.lStructSize = sizeof ( CHOOSEFONT ); |
| 2618 | cf.hwndOwner = hwnd; |
| 2619 | cf.lpLogFont = &lf; |
| 2620 | cf.Flags = CF_INITTOLOGFONTSTRUCT /*| CF_NOSCRIPTSEL*/ | CF_SCREENFONTS; |
| 2621 | if ( HIBYTE ( GetKeyState ( VK_SHIFT ) ) ) { |
| 2622 | cf.Flags |= CF_FIXEDPITCHONLY; |
| 2623 | } |
| 2624 | if ( !ChooseFont ( &cf ) || !lstrlen ( lf.lfFaceName ) ) { |
| 2625 | return FALSE; |
| 2626 | } |
| 2627 | // Map back to lpszStyle |
| 2628 | lstrcpy ( szNewStyle, L"font:" ); |
| 2629 | lstrcat ( szNewStyle, lf.lfFaceName ); |
| 2630 | if ( Style_StrGetFontQuality ( lpszStyle, tch, COUNTOF ( tch ) ) ) { |
| 2631 | lstrcat ( szNewStyle, L"; smoothing:" ); |
| 2632 | lstrcat ( szNewStyle, tch ); |
| 2633 | } |
| 2634 | if ( bDefaultStyle && |
| 2635 | lf.lfCharSet != DEFAULT_CHARSET && |
| 2636 | lf.lfCharSet != ANSI_CHARSET && |
| 2637 | lf.lfCharSet != iDefaultCharSet ) { |
| 2638 | lstrcat ( szNewStyle, L"; charset:" ); |
| 2639 | wsprintf ( tch, L"%i", lf.lfCharSet ); |
| 2640 | lstrcat ( szNewStyle, tch ); |
| 2641 | } |
| 2642 | lstrcat ( szNewStyle, L"; size:" ); |
| 2643 | wsprintf ( tch, L"%i", cf.iPointSize / 10 ); |
| 2644 | lstrcat ( szNewStyle, tch ); |
| 2645 | if ( cf.nFontType & BOLD_FONTTYPE ) { |
| 2646 | lstrcat ( szNewStyle, L"; bold" ); |
| 2647 | } |
| 2648 | if ( cf.nFontType & ITALIC_FONTTYPE ) { |
| 2649 | lstrcat ( szNewStyle, L"; italic" ); |
no test coverage detected