#include <fonts.h>
Static Public Member Functions | |
static BOOL | Init () |
Initialise the font factory - set up the font handle array and find out information about the screen. | |
static void | Deinit () |
Frees/deletes all logical fonts so far created by the font factory. | |
static HFONT | GetFont (StockFont) |
Gets a handle to a stock font used in Camelot. This allows you to get a handle to a particular font quickly and easily. This font will be automatically cleaned up when Camelot exits, and you should NOT delete this font yourself. | |
static CFont * | GetCFont (StockFont) |
Gets a CFont object for a stock font used in Camelot. This allows you to get to a particular font quickly and easily. This font will be automatically cleaned up when Camelot exits, and you should NOT delete this font object yourself. | |
static BOOL | ApplyFontToWindow (HWND, StockFont) |
brute force setting of all gadgets in window to use a stock font This should be called after window creation but before the window is shown - It does not force a window redraw. | |
static BOOL | GetSystemDialogFont (LOGFONT *pLogFont) |
Call to read the sustem default font for dialogs (set by the user) NOTE: this code was stolen from MFC (see CDialogTemplate::SetSystemFont). | |
static BOOL | InvalidateFont (StockFont) |
Invalidate a font - it will be recreated next time GetCFont is called. | |
static BOOL | CheckSystemBarFontsChanged () |
Determine whether the system dialog title font has changed. | |
static BOOL | CheckSystemStatusLineFontChanged () |
Determine whether the system dialog title font has changed. | |
Static Private Attributes | |
static CFont * | Fonts = NULL |
static SIZE | PixelsPerInch = { 1, 1 } |
static String_32 | FontDBSmall |
static String_32 | FontEFSmall |
static INT32 | FontDBSmallSize = 7 |
static INT32 | FontEFSmallSize = 7 |
static BOOL | bNoBitmapFonts = TRUE |
Definition at line 143 of file fonts.h.
|
brute force setting of all gadgets in window to use a stock font This should be called after window creation but before the window is shown - It does not force a window redraw.
Definition at line 683 of file fonts.cpp. 00684 { 00685 if(!(IsWindow(ThisWindow))) 00686 ERROR2(FALSE,"Apply Font to a non existent Window"); 00687 00688 CFont *pFont = GetCFont(Font); // Get the font 00689 if (pFont == NULL) // If this failed, return quietly 00690 return(FALSE); 00691 00692 // get the first gadget in the window 00693 HWND DlgItem; 00694 DlgItem = ::GetWindow(ThisWindow,GW_CHILD); 00695 00696 while(DlgItem !=NULL) 00697 { 00698 // set it's font 00699 ::SendMessage( DlgItem, WM_SETFONT, (WPARAM)pFont->m_hObject, 0); 00700 00701 // and get the next 00702 DlgItem = ::GetWindow(DlgItem,GW_HWNDNEXT); 00703 } 00704 return TRUE; 00705 }
|
|
Determine whether the system dialog title font has changed.
Definition at line 322 of file fonts.cpp. 00323 { 00324 BOOL returnVal = FALSE; 00325 #if _MFC_VER >= 0x400 00326 if(IS_CHICAGO) 00327 { 00328 // test the font used in gallery title bars 00329 NONCLIENTMETRICS NCMetrics; 00330 NCMetrics.cbSize = sizeof(NONCLIENTMETRICS); 00331 if(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&NCMetrics,NULL)==TRUE) 00332 { 00333 CFont TBFont; 00334 // Create a temporary font. 00335 TBFont.CreateFontIndirect(&NCMetrics.lfSmCaptionFont); 00336 00337 if(TBFont!= Fonts[STOCKFONT_DIALOGBARTITLE]) 00338 { 00339 InvalidateFont(STOCKFONT_DIALOGBARTITLE); 00340 returnVal= TRUE; 00341 } 00342 00343 } 00344 00345 // test the font used in bubble help 00346 00347 } 00348 #endif 00349 00350 00351 return returnVal ; 00352 }
|
|
Determine whether the system dialog title font has changed.
Definition at line 277 of file fonts.cpp. 00278 { 00279 BOOL returnVal = FALSE; 00280 #if _MFC_VER >= 0x400 00281 if(IS_CHICAGO) 00282 { 00283 // test the font used in gallery title bars 00284 NONCLIENTMETRICS NCMetrics; 00285 NCMetrics.cbSize = sizeof(NONCLIENTMETRICS); 00286 if(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&NCMetrics,NULL)==TRUE) 00287 { 00288 00289 CFont BBFont; 00290 // Create a temporary font. 00291 BBFont.CreateFontIndirect(&NCMetrics.lfStatusFont); 00292 00293 if(BBFont!= Fonts[STOCKFONT_BUBBLEHELP]) 00294 { 00295 InvalidateFont(STOCKFONT_BUBBLEHELP); 00296 InvalidateFont(STOCKFONT_STATUSBARBOLD); 00297 InvalidateFont(STOCKFONT_STATUSBAR); 00298 returnVal= TRUE; 00299 } 00300 00301 } 00302 00303 // test the font used in bubble help 00304 00305 } 00306 #endif 00307 00308 00309 return returnVal ; 00310 }
|
|
Frees/deletes all logical fonts so far created by the font factory.
Definition at line 233 of file fonts.cpp. 00234 { 00235 // Delete any fonts we've created so far. 00236 delete [] Fonts; 00237 Fonts = NULL; 00238 }
|
|
Gets a CFont object for a stock font used in Camelot. This allows you to get to a particular font quickly and easily. This font will be automatically cleaned up when Camelot exits, and you should NOT delete this font object yourself.
Definition at line 373 of file fonts.cpp. 00374 { 00375 #ifndef EXCLUDE_FROM_RALPH 00376 // Check for bad font arrays 00377 ERROR3IF(Fonts == NULL, "No font array in FontFactory::GetCFont()"); 00378 if (Fonts == NULL) 00379 return NULL; 00380 00381 if ((INT32)Font < 0 || (INT32)Font >= NUMSTOCKFONTS) 00382 { 00383 ERROR2RAW("Illegal stock font index in FontFactory::GetCFont\n"); 00384 return(NULL); 00385 } 00386 00387 // Check to see if this font has already been allocated 00388 if (Fonts[Font].m_hObject != NULL) 00389 // Yes - just return the handle 00390 return &Fonts[Font]; 00391 00392 // Otherwise, create a LOGFONT structure and get the font. 00393 LOGFONT LogFont; 00394 memset(&LogFont, 0, sizeof(LogFont)); 00395 LogFont.lfCharSet = UnicodeManager::GetFontCharSet(); 00396 LPTCHAR FontName = NULL; 00397 INT32 FontSize = 0; 00398 00399 switch (Font) 00400 { 00401 // WEBSTER - markn 15/1/97 00402 // No rulers in Webster 00403 #ifndef WEBSTER 00404 case STOCKFONT_RULERS: 00405 if (OILRuler::FontName == NULL) 00406 OILRuler::FontName = new String_256(_R(IDS_OILRULER_SMALL_FONTS)); 00407 00408 if (OILRuler::FontName != NULL) 00409 { 00410 FontSize = OILRuler::FontSize; 00411 LogFont.lfWeight = FW_NORMAL; 00412 LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; 00413 FontName = (TCHAR*)(*OILRuler::FontName); 00414 } 00415 break; 00416 #endif 00417 00418 // UIC replaces case STOCKFONT_STATUSBAR: 00419 case STOCKFONT_STATUSBAR: 00420 { 00421 BOOL DoneSysFont =FALSE; 00422 #if _MFC_VER >= 0x400 00423 if(IS_CHICAGO) 00424 { 00425 NONCLIENTMETRICS NCMetrics; 00426 NCMetrics.cbSize = sizeof(NONCLIENTMETRICS); 00427 if(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&NCMetrics,NULL)==TRUE) 00428 { 00429 LogFont = NCMetrics.lfStatusFont; 00430 DoneSysFont= TRUE; 00431 } 00432 00433 } 00434 #endif 00435 if(!DoneSysFont) 00436 { 00437 LogFont.lfHeight = 9; 00438 LogFont.lfWeight = FW_NORMAL; 00439 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00440 FontName = String_64(_R(IDS_FONTS_STATUSBAR)); // "MS Sans Serif"; 00441 } 00442 break; 00443 } 00444 00445 /* case STOCKFONT_STATUSBAR: 00446 LogFont.lfHeight = 9; 00447 LogFont.lfWeight = FW_NORMAL; 00448 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00449 FontName = String_64(_R(IDS_FONTS_STATUSBAR)); // "MS Sans Serif"; 00450 break; 00451 00452 case STOCKFONT_STATUSBARBOLD: 00453 LogFont.lfHeight = 9; 00454 LogFont.lfWeight = FW_BOLD; 00455 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00456 FontName = String_64(_R(IDS_FONTS_STATUSBARBOLD)); // "MS Sans Serif"; 00457 break; 00458 */ 00459 00460 // UIC 00461 case STOCKFONT_STATUSBARBOLD: 00462 { 00463 BOOL DoneSysFont =FALSE; 00464 #if _MFC_VER >= 0x400 00465 if(IS_CHICAGO) 00466 { 00467 NONCLIENTMETRICS NCMetrics; 00468 NCMetrics.cbSize = sizeof(NONCLIENTMETRICS); 00469 if(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&NCMetrics,NULL)==TRUE) 00470 { 00471 LogFont = NCMetrics.lfStatusFont; 00472 LogFont.lfWeight = FW_BOLD; 00473 DoneSysFont= TRUE; 00474 } 00475 00476 } 00477 #endif 00478 if(!DoneSysFont) 00479 { 00480 LogFont.lfHeight = 9; 00481 LogFont.lfWeight = FW_BOLD; 00482 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00483 FontName = String_64(_R(IDS_FONTS_STATUSBARBOLD)); // "MS Sans Serif"; 00484 } 00485 break; 00486 } 00487 00488 case STOCKFONT_SPLASHBOXINFO: 00489 FontSize = 14; 00490 LogFont.lfWeight = FW_NORMAL; 00491 LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS; 00492 FontName = String_64(_R(IDS_FONTS_SPLASHBOXINFO)); // "SmallFonts" 00493 break; 00494 00495 case STOCKFONT_DIALOGBARCLIENT: 00496 case STOCKFONT_RNDRGNFIXEDTEXT: // Used in kernel-rendered dlgs (SuperGalleries) 00497 FontSize = 9; 00498 LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; 00499 FontName = String_64(_R(IDS_FONTS_GALLERIES_AND_BAR)); // "MS Sans Serif"; 00500 break; 00501 00502 case STOCKFONT_DIALOGBARSMALL: 00503 if (bNoBitmapFonts || UnicodeManager::IsDBCSOS()) 00504 { 00505 FontSize = FontDBSmallSize; 00506 LogFont.lfWeight = FW_NORMAL; 00507 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; 00508 FontName = FontDBSmall; 00509 FontName = "MS Sans Serif"; 00510 } 00511 else 00512 { 00513 FontSize = 7; 00514 LogFont.lfCharSet = ANSI_CHARSET; 00515 LogFont.lfWeight = FW_NORMAL; 00516 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00517 FontName = String_64(_R(IDS_FONTS_DIALOGBARSMALL)); // "CCSMALL"; 00518 } 00519 break; 00520 00521 case STOCKFONT_DIALOGBARLARGE: 00522 FontSize = 9; 00523 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; 00524 FontName = String_64(_R(IDS_FONTS_DIALOGBARLARGE)); // "MS Sans Serif"; 00525 break; 00526 00527 case STOCKFONT_EDITFIELDSMALL: 00528 if (bNoBitmapFonts || UnicodeManager::IsDBCSOS()) 00529 { 00530 FontSize = FontEFSmallSize; 00531 LogFont.lfWeight = FW_NORMAL; 00532 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; 00533 FontName = FontEFSmall; 00534 } 00535 else 00536 { 00537 FontSize = 7; 00538 LogFont.lfCharSet = ANSI_CHARSET; 00539 LogFont.lfWeight = FW_NORMAL; 00540 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00541 FontName = String_64(_R(IDS_FONTS_EDITFIELDSMALL)); // "CCSMALL"; 00542 } 00543 break; 00544 00545 case STOCKFONT_EDITFIELDLARGE: 00546 FontSize = 9; 00547 if (bNoBitmapFonts || UnicodeManager::IsDBCSOS()) 00548 { 00549 LogFont.lfWeight = FW_NORMAL; 00550 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; 00551 FontName = "MS Sans Serif"; 00552 } 00553 else 00554 { 00555 LogFont.lfCharSet = ANSI_CHARSET; 00556 LogFont.lfWeight = FW_NORMAL; 00557 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00558 FontName = String_64(_R(IDS_FONTS_EDITFIELDLARGE)); // "CCLARGE"; 00559 } 00560 break; 00561 00562 case STOCKFONT_GALLERYLIST: 00563 FontSize = 9; 00564 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; 00565 FontName = String_64(_R(IDS_FONTS_GALLERYLIST)); // "MS Sans Serif"; 00566 break; 00567 00568 case STOCKFONT_DIALOGBARTITLE: 00569 FontSize = 7; 00570 LogFont.lfWeight = FW_NORMAL; 00571 LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS; 00572 FontName = String_64(_R(IDS_FONTS_DIALOGBARTITLE)); // "SmallFonts"; 00573 break; 00574 00575 // UIC 00576 case STOCKFONT_BUBBLEHELP: 00577 { 00578 BOOL DoneSysFont = FALSE; 00579 00580 #if _MFC_VER >= 0x400 00581 if(IS_CHICAGO) 00582 { 00583 NONCLIENTMETRICS NCMetrics; 00584 NCMetrics.cbSize = sizeof(NONCLIENTMETRICS); 00585 if(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&NCMetrics,NULL)==TRUE) 00586 { 00587 LogFont = NCMetrics.lfStatusFont; 00588 DoneSysFont= TRUE; 00589 } 00590 00591 } 00592 #endif 00593 if(!DoneSysFont) 00594 { 00595 LogFont.lfHeight = 14; 00596 LogFont.lfWeight = FW_NORMAL; 00597 LogFont.lfOutPrecision = OUT_RASTER_PRECIS; 00598 LogFont.lfClipPrecision = CLIP_CHARACTER_PRECIS; 00599 LogFont.lfQuality = DRAFT_QUALITY; 00600 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00601 FontName = String_64(_R(IDS_FONTS_BUBBLEHELP)); // "Helvetica"; 00602 } 00603 break; 00604 } 00605 00606 case STOCKFONT_DIALOG: 00607 if (!GetSystemDialogFont(&LogFont)) 00608 return NULL; 00609 break; 00610 00611 default: 00612 ENSURE(FALSE, "Bad font requested in FontFactory::GetStockFont()"); 00613 return NULL; 00614 } 00615 00616 if (FontName) 00617 camStrcpy(LogFont.lfFaceName, FontName); 00618 if (FontSize) 00619 LogFont.lfHeight = -MulDiv(FontSize, PixelsPerInch.cx, 72); 00620 00621 // Create the font and store it in our array. 00622 Fonts[Font].CreateFontIndirect(&LogFont); 00623 00624 // If the font could not be created, use a stock font. 00625 if (Fonts[Font].m_hObject == NULL) 00626 Fonts[Font].CreateStockObject(SYSTEM_FONT); 00627 00628 // Return the handle to the caller. 00629 return &Fonts[Font]; 00630 #else 00631 return NULL; 00632 #endif 00633 }
|
|
Gets a handle to a stock font used in Camelot. This allows you to get a handle to a particular font quickly and easily. This font will be automatically cleaned up when Camelot exits, and you should NOT delete this font yourself.
Definition at line 654 of file fonts.cpp. 00655 { 00656 // Just defer the main work to GetCFont(). 00657 CFont *pFont = GetCFont(Font); 00658 00659 // Did it work? 00660 if (pFont == NULL) 00661 // No - return null font handle 00662 return NULL; 00663 00664 // Worked ok, so extract font handle and return it. 00665 return (HFONT) pFont->m_hObject; 00666 }
|
|
Call to read the sustem default font for dialogs (set by the user) NOTE: this code was stolen from MFC (see CDialogTemplate::SetSystemFont).
Definition at line 720 of file fonts.cpp. 00721 { 00722 // Salary check 00723 ERROR2IF(pLogFont == NULL, FALSE, "NULL output parameter"); 00724 00725 // Get a font handle to the default font 00726 HFONT hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); 00727 if (hFont == NULL) 00728 hFont = (HFONT)::GetStockObject(SYSTEM_FONT); 00729 ERROR2IF(hFont == NULL, FALSE, "Failed to get default font handle"); 00730 00731 // Get the font description 00732 INT32 Result = ::GetObject(hFont, sizeof(LOGFONT), pLogFont); 00733 ERROR2IF(Result == 0, FALSE, "Failed to get default font information"); 00734 00735 // { 00736 // pszFace = lf.lfFaceName; 00737 // HDC hDC = ::GetDC(NULL); 00738 // if (lf.lfHeight < 0) 00739 // lf.lfHeight = -lf.lfHeight; 00740 // wDefSize = (WORD)MulDiv(lf.lfHeight, 72, GetDeviceCaps(hDC, LOGPIXELSY)); 00741 // ::ReleaseDC(NULL, hDC); 00742 // } 00743 00744 return TRUE; 00745 }
|
|
Initialise the font factory - set up the font handle array and find out information about the screen.
Definition at line 150 of file fonts.cpp. 00151 { 00152 // Sanity check - Make sure nobody has completely screwed up the header! 00153 ERROR3IF(NUMSTOCKFONTS < 2, 00154 "I suspect something strange has happened to the StockFont system!"); 00155 00156 // Allocate the font handle array 00157 TRY 00158 { 00159 Fonts = new CFont[NUMSTOCKFONTS]; 00160 } 00161 CATCH (CMemoryException, e) 00162 { 00163 ERROR(_R(IDS_OUT_OF_MEMORY), FALSE); 00164 } 00165 END_CATCH 00166 00167 // Initialise the font handle array 00168 for (INT32 i = 0; i < NUMSTOCKFONTS; i++) 00169 Fonts[i].m_hObject = NULL; 00170 00171 // Find out about the screen display capabilities. 00172 CDC Screen; 00173 Screen.CreateIC(TEXT("DISPLAY"), 0, 0, 0); 00174 PixelsPerInch.cx = Screen.GetDeviceCaps(LOGPIXELSX); 00175 PixelsPerInch.cy = Screen.GetDeviceCaps(LOGPIXELSY); 00176 Screen.DeleteDC(); 00177 00178 // Try to create our dodgy bitmap font 00179 LOGFONT LogFont; 00180 memset(&LogFont, 0, sizeof(LogFont)); 00181 LogFont.lfCharSet = UnicodeManager::GetFontCharSet(); 00182 LPTCHAR FontName = NULL; 00183 LogFont.lfCharSet = ANSI_CHARSET; 00184 LogFont.lfWeight = FW_NORMAL; 00185 LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; 00186 camStrcpy(LogFont.lfFaceName, _T("CCSmall")); 00187 LogFont.lfHeight = -MulDiv(7, PixelsPerInch.cx, 72); 00188 00189 // Create the font 00190 CFont TestFont; 00191 TestFont.CreateFontIndirect(&LogFont); 00192 00193 // Get hold of any old DC 00194 CDC *pDesktopDC = CWnd::GetDesktopWindow()->GetDC(); 00195 00196 // If we got a DC and a font 00197 if (pDesktopDC && TestFont.m_hObject != NULL) 00198 { 00199 CFont * pOldFont = pDesktopDC->SelectObject(&TestFont); // Select the font into the DC 00200 char buff[64]; 00201 pDesktopDC->GetTextFace(64, buff); // Get the typeface name 00202 pDesktopDC->SelectObject(pOldFont); // Select the original font back in 00203 CWnd::GetDesktopWindow()->ReleaseDC(pDesktopDC); // Release the DC 00204 if (_tcsncicmp(buff, _T("CCSmall"), 64) == 0) 00205 bNoBitmapFonts = FALSE; 00206 } 00207 00208 if (Camelot.DeclareSection("Fonts", 20)) 00209 { 00210 Camelot.DeclarePref(NULL, "DialogBarSmall", &FontDBSmall); 00211 Camelot.DeclarePref(NULL, "EditFieldSmall", &FontEFSmall); 00212 00213 Camelot.DeclarePref(NULL, "DialogBarSmallSize", &FontDBSmallSize, 1, 50); 00214 Camelot.DeclarePref(NULL, "EditFieldSmallSize", &FontEFSmallSize, 1, 50); 00215 } 00216 00217 return TRUE; 00218 }
|
|
Invalidate a font - it will be recreated next time GetCFont is called.
Definition at line 251 of file fonts.cpp. 00252 { 00253 if ((INT32)Font < 0 || (INT32)Font >= NUMSTOCKFONTS) 00254 { 00255 ERROR2RAW("Illegal stock font index in FontFactory::GetCFont"); 00256 return FALSE; 00257 } 00258 00259 // Check to see if this font has already been allocated 00260 Fonts[Font].m_hObject = NULL; 00261 00262 return TRUE; 00263 00264 00265 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|