fonts.cpp

Go to the documentation of this file.
00001 // $Id: fonts.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // Module to deal with font allocation within Camelot.
00100 
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 
00106 #include <stdlib.h>
00107 #include "fonts.h"
00108 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "resource.h"
00111 #include "camelot.h"
00112 #include "unicdman.h"
00113 #ifndef EXCLUDE_FROM_RALPH
00114 #include "oilruler.h"
00115 #endif
00116 
00117 //#include "richard2.h"
00118 
00119 // The number of pixels per inch in the x and y direction for the screen display.
00120 SIZE FontFactory::PixelsPerInch = { 1, 1 };
00121 
00122 // The font array
00123 CFont *FontFactory::Fonts = NULL;
00124 
00125 // Statics to hold registry values for bar fonts
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 >   BOOL FontFactory::Init()
00139 
00140     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00141     Created:    31/05/94
00142     Returns:    TRUE if the factory initialised ok;
00143                 FALSE if not.
00144     Purpose:    Initialise the font factory - set up the font handle array and find out
00145                 information about the screen.
00146     SeeAlso:    FontFactory::Deinit; FontFactory::GetFont; FontFactory::GetCFont
00147 
00148 ********************************************************************************************/
00149 
00150 BOOL FontFactory::Init()
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 }
00219 
00220 
00221 
00222 /********************************************************************************************
00223 
00224 >   void FontFactory::Deinit()
00225 
00226     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00227     Created:    31/05/94
00228     Purpose:    Frees/deletes all logical fonts so far created by the font factory.
00229     SeeAlso:    FontFactory::Init
00230 
00231 ********************************************************************************************/
00232 
00233 void FontFactory::Deinit()
00234 {
00235     // Delete any fonts we've created so far.
00236     delete [] Fonts;
00237     Fonts = NULL;
00238 }
00239 
00240 // UIC 
00241 /********************************************************************************************
00242 
00243 >   BOOL FontFactory::InvalidateFont()
00244 
00245     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00246     Created:    29/2/96
00247     Purpose:    Invalidate a font - it will be recreated next time GetCFont is called.
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     // Check to see if this font has already been allocated
00260     Fonts[Font].m_hObject = NULL;
00261 
00262     return TRUE;
00263 
00264 
00265 }
00266 
00267 /********************************************************************************************
00268 
00269 >   BOOL FontFactory::CheckStatusLineFontChanged()
00270 
00271     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00272     Created:    29/2/96
00273     Purpose:    Determine whether the system dialog title font has changed.
00274 
00275 ********************************************************************************************/
00276 
00277 BOOL FontFactory::CheckSystemStatusLineFontChanged()
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 }
00311 
00312 /********************************************************************************************
00313 
00314 >   BOOL FontFactory::CheckSystemBarFontsChanged()
00315 
00316     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00317     Created:    29/2/96
00318     Purpose:    Determine whether the system dialog title font has changed.
00319 
00320 ********************************************************************************************/
00321 
00322 BOOL FontFactory::CheckSystemBarFontsChanged()
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 }
00353 
00354 /********************************************************************************************
00355 
00356 >   CFont *FontFactory::GetCFont(StockFont Font)
00357 
00358     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00359     Created:    31/05/94
00360     Inputs:     Font - the font desired (see StockFont).
00361     Returns:    Pointer to the CFont object for the required font.  If the required font
00362                 cannot be created, then a pointer to a CFont object for a stock font is 
00363                 returned instead.
00364     Purpose:    Gets a CFont object for a stock font used in Camelot.  This allows you to 
00365                 get to a particular font quickly and easily.  This font will be 
00366                 automatically cleaned up when Camelot exits, and you should NOT delete this
00367                 font object yourself.
00368     Errors:     Out of memory; The CreateFont() call fails for some reason.
00369     SeeAlso:    FontFactory::GetFont; StockFont
00370 
00371 ********************************************************************************************/
00372 
00373 CFont *FontFactory::GetCFont(StockFont Font)
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 }
00634 
00635 
00636 /********************************************************************************************
00637 
00638 >   HFONT FontFactory::GetFont(StockFont Font)
00639 
00640     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00641     Created:    31/05/94
00642     Inputs:     Font - the font desired (see StockFont).
00643     Returns:    Handle to the required font.  If the required font cannot be created, then a 
00644                 handle to a stock font is returned instead.
00645     Purpose:    Gets a handle to a stock font used in Camelot.  This allows you to get a
00646                 handle to a particular font quickly and easily.  This font will be 
00647                 automatically cleaned up when Camelot exits, and you should NOT delete this
00648                 font yourself.
00649     Errors:     Out of memory; The CreateFont() call fails for some reason.
00650     SeeAlso:    FontFactory::GetCFont; StockFont
00651 
00652 ********************************************************************************************/
00653 
00654 HFONT FontFactory::GetFont(StockFont Font)
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 }
00667 
00668 
00669 
00670 /********************************************************************************************
00671 
00672 >   BOOL FontFactory::SetWindowFont(StockFont Font)
00673 
00674     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00675     Created:    12/01/95
00676     Inputs:     Font - the font desired (see StockFont).
00677     Returns:    TRUE if no errors
00678     Purpose:    brute force setting of all gadgets in window to use a stock font
00679                 This should be called after window creation but before the window is shown -
00680                 It does not force a window redraw. 
00681     Errors:     If window doesn't exist
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);      // 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 }
00706 
00707 
00708 
00709 /********************************************************************************************
00710 >   static BOOL FontFactory::GetSystemDialogFont(LOGFONT* pLogFont)
00711 
00712     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
00713     Created:    19/7/96
00714     Inputs:     see outputs
00715     Outputs:    pLogFont - descibes the system default font
00716     Returns:    TRUE/FALSE for success/failure
00717     Purpose:    Call to read the sustem default font for dialogs (set by the user)
00718                 NOTE: this code was stolen from MFC (see CDialogTemplate::SetSystemFont)
00719 ********************************************************************************************/
00720 BOOL FontFactory::GetSystemDialogFont(LOGFONT* pLogFont)
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 }

Generated on Sat Nov 10 03:48:29 2007 for Camelot by  doxygen 1.4.4