00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #include "camtypes.h"
00105
00106 #include <stdlib.h>
00107 #include "fonts.h"
00108
00109
00110
00111 #include "camelot.h"
00112 #include "unicdman.h"
00113 #ifndef EXCLUDE_FROM_RALPH
00114 #include "oilruler.h"
00115 #endif
00116
00117
00118
00119
00120 SIZE FontFactory::PixelsPerInch = { 1, 1 };
00121
00122
00123 CFont *FontFactory::Fonts = NULL;
00124
00125
00126 String_32 FontFactory::FontDBSmall("MS Sans Serif");
00127 String_32 FontFactory::FontEFSmall("MS Sans Serif");
00128 INT32 FontFactory::FontDBSmallSize = 7;
00129 INT32 FontFactory::FontEFSmallSize = 7;
00130
00131 BOOL FontFactory::bNoBitmapFonts = TRUE;
00132
00133 #define IS_CHICAGO ((LOBYTE(LOWORD(GetVersion()))) > 3)
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 BOOL FontFactory::Init()
00151 {
00152
00153 ERROR3IF(NUMSTOCKFONTS < 2,
00154 "I suspect something strange has happened to the StockFont system!");
00155
00156
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
00168 for (INT32 i = 0; i < NUMSTOCKFONTS; i++)
00169 Fonts[i].m_hObject = NULL;
00170
00171
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
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
00190 CFont TestFont;
00191 TestFont.CreateFontIndirect(&LogFont);
00192
00193
00194 CDC *pDesktopDC = CWnd::GetDesktopWindow()->GetDC();
00195
00196
00197 if (pDesktopDC && TestFont.m_hObject != NULL)
00198 {
00199 CFont * pOldFont = pDesktopDC->SelectObject(&TestFont);
00200 char buff[64];
00201 pDesktopDC->GetTextFace(64, buff);
00202 pDesktopDC->SelectObject(pOldFont);
00203 CWnd::GetDesktopWindow()->ReleaseDC(pDesktopDC);
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 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 void FontFactory::Deinit()
00234 {
00235
00236 delete [] Fonts;
00237 Fonts = NULL;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 BOOL FontFactory::InvalidateFont(StockFont Font)
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
00260 Fonts[Font].m_hObject = NULL;
00261
00262 return TRUE;
00263
00264
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 BOOL FontFactory::CheckSystemStatusLineFontChanged()
00278 {
00279 BOOL returnVal = FALSE;
00280 #if _MFC_VER >= 0x400
00281 if(IS_CHICAGO)
00282 {
00283
00284 NONCLIENTMETRICS NCMetrics;
00285 NCMetrics.cbSize = sizeof(NONCLIENTMETRICS);
00286 if(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&NCMetrics,NULL)==TRUE)
00287 {
00288
00289 CFont BBFont;
00290
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
00304
00305 }
00306 #endif
00307
00308
00309 return returnVal ;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 BOOL FontFactory::CheckSystemBarFontsChanged()
00323 {
00324 BOOL returnVal = FALSE;
00325 #if _MFC_VER >= 0x400
00326 if(IS_CHICAGO)
00327 {
00328
00329 NONCLIENTMETRICS NCMetrics;
00330 NCMetrics.cbSize = sizeof(NONCLIENTMETRICS);
00331 if(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&NCMetrics,NULL)==TRUE)
00332 {
00333 CFont TBFont;
00334
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
00346
00347 }
00348 #endif
00349
00350
00351 return returnVal ;
00352 }
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 CFont *FontFactory::GetCFont(StockFont Font)
00374 {
00375 #ifndef EXCLUDE_FROM_RALPH
00376
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
00388 if (Fonts[Font].m_hObject != NULL)
00389
00390 return &Fonts[Font];
00391
00392
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
00402
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
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));
00441 }
00442 break;
00443 }
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
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));
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));
00493 break;
00494
00495 case STOCKFONT_DIALOGBARCLIENT:
00496 case STOCKFONT_RNDRGNFIXEDTEXT:
00497 FontSize = 9;
00498 LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
00499 FontName = String_64(_R(IDS_FONTS_GALLERIES_AND_BAR));
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));
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));
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));
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));
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));
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));
00573 break;
00574
00575
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));
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
00622 Fonts[Font].CreateFontIndirect(&LogFont);
00623
00624
00625 if (Fonts[Font].m_hObject == NULL)
00626 Fonts[Font].CreateStockObject(SYSTEM_FONT);
00627
00628
00629 return &Fonts[Font];
00630 #else
00631 return NULL;
00632 #endif
00633 }
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654 HFONT FontFactory::GetFont(StockFont Font)
00655 {
00656
00657 CFont *pFont = GetCFont(Font);
00658
00659
00660 if (pFont == NULL)
00661
00662 return NULL;
00663
00664
00665 return (HFONT) pFont->m_hObject;
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683 BOOL FontFactory::ApplyFontToWindow(HWND ThisWindow , StockFont Font)
00684 {
00685 if(!(IsWindow(ThisWindow)))
00686 ERROR2(FALSE,"Apply Font to a non existent Window");
00687
00688 CFont *pFont = GetCFont(Font);
00689 if (pFont == NULL)
00690 return(FALSE);
00691
00692
00693 HWND DlgItem;
00694 DlgItem = ::GetWindow(ThisWindow,GW_CHILD);
00695
00696 while(DlgItem !=NULL)
00697 {
00698
00699 ::SendMessage( DlgItem, WM_SETFONT, (WPARAM)pFont->m_hObject, 0);
00700
00701
00702 DlgItem = ::GetWindow(DlgItem,GW_HWNDNEXT);
00703 }
00704 return TRUE;
00705 }
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720 BOOL FontFactory::GetSystemDialogFont(LOGFONT* pLogFont)
00721 {
00722
00723 ERROR2IF(pLogFont == NULL, FALSE, "NULL output parameter");
00724
00725
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
00732 INT32 Result = ::GetObject(hFont, sizeof(LOGFONT), pLogFont);
00733 ERROR2IF(Result == 0, FALSE, "Failed to get default font information");
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744 return TRUE;
00745 }