/** * @file XTPFontManager.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "stdafx.h" #include "Common/XTPTypeId.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPResourceManager.h" #include "Common/XTPGdiObjects.h" #include "Common/XTPFontManager.h" #include "Common/XTPVC80Helpers.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # undef THIS_FILE static char THIS_FILE[] = __FILE__; # define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CXTPFontManager::CXTPFontManager() { CXTPNonClientMetrics ncm; ncm.lfMenuFont.lfCharSet = XTPResourceManager()->GetFontCharset(); if (XTPSystemVersion()->IsClearTypeTextQualitySupported()) { ncm.lfMenuFont.lfQuality = CLEARTYPE_QUALITY; } CreateFonts(ncm.lfMenuFont); } AFX_STATIC int CALLBACK XTPEnumFontFamExProc(const LOGFONT* lpelfe, const TEXTMETRIC* lpntme, DWORD FontType, LPARAM lParam) { UNREFERENCED_PARAMETER(lpntme); UNREFERENCED_PARAMETER(FontType); const ENUMLOGFONTEX* pelf = reinterpret_cast(lpelfe); _ASSERTE(NULL != pelf); LPCTSTR strFontName = reinterpret_cast(lParam); _ASSERTE(NULL != strFontName); CString strFaceName = pelf->elfLogFont.lfFaceName; return (strFaceName.CompareNoCase(strFontName) == 0 ? 0 : 1); } BOOL CXTPFontManager::FontExists(LPCTSTR strFaceName) { // Enumerate all styles and charsets of all fonts: LOGFONT lfEnum; ::ZeroMemory(&lfEnum, sizeof(LOGFONT)); lfEnum.lfFaceName[0] = 0; lfEnum.lfCharSet = DEFAULT_CHARSET; CWindowDC dc(NULL); return ::EnumFontFamiliesEx(dc.m_hDC, &lfEnum, (FONTENUMPROC)XTPEnumFontFamExProc, (LPARAM)strFaceName, 0) == 0; } #define DELETE_FONT(font) \ if ((font).GetSafeHandle()) \ { \ (font).DeleteObject(); \ } void CXTPFontManager::CreateFonts(LOGFONT lf) { // normal font. DELETE_FONT(m_xtpFont); m_xtpFont.CreateFontIndirect(&lf); // bold font. DELETE_FONT(m_xtpFontBold); lf.lfWeight = FW_BOLD; m_xtpFontBold.CreateFontIndirect(&lf); // italic font. DELETE_FONT(m_xtpFontItalic); lf.lfItalic = TRUE; lf.lfWeight = FW_NORMAL; m_xtpFontItalic.CreateFontIndirect(&lf); // italic bold font. DELETE_FONT(m_xtpFontItalicBold); lf.lfWeight = FW_BOLD; m_xtpFontItalicBold.CreateFontIndirect(&lf); // older OS needs Arial to display vertical fonts. if (!XTPSystemVersion()->IsWin2KOrGreater()) { if (FontExists(_T("Arial"))) STRCPY_S(lf.lfFaceName, LF_FACESIZE, _T("Arial")); } // vertical font. DELETE_FONT(m_xtpFontVertical); lf.lfEscapement = 900; // 90 degreees rotated text lf.lfItalic = FALSE; m_xtpFontVertical.CreateFontIndirect(&lf); // vertical bold font. DELETE_FONT(m_xtpFontVerticalBold); lf.lfWeight = FW_BOLD; m_xtpFontVerticalBold.CreateFontIndirect(&lf); } ////////////////////////////////////////////////////////////////////// // Function: XTPFontManager() CXTPFontManager* AFX_CDECL XTPFontManager() { return &CXTPSingleton::Instance(); }