00001 // $Id: ttfonts.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 // implementation file for TrueType Font manager winoil inclusion 00099 00100 /* 00101 */ 00102 00103 #include "camtypes.h" 00104 #include "ttfonts.h" 00105 #include "fontman.h" 00106 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 #include "textfuns.h" 00108 #include "oilpanse.h" 00109 00110 DECLARE_SOURCE( "$Revision: 1282 $" ); 00111 00112 CC_IMPLEMENT_DYNCREATE( TTFontMan, CCObject ) 00113 CC_IMPLEMENT_DYNCREATE( TTFont, FontBase ) 00114 00115 #define new CAM_DEBUG_NEW 00116 00117 /******************************************************************************************** 00118 00119 > TTFont::TTFont() 00120 00121 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00122 Created: 12/09/95 00123 Purpose: Default constructor 00124 00125 ********************************************************************************************/ 00126 00127 TTFont::TTFont() 00128 { 00129 } 00130 00131 /******************************************************************************************** 00132 00133 > TTFont::~TTFont() 00134 00135 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00136 Created: 12/09/95 00137 Purpose: destructor for the TTFont class 00138 00139 ********************************************************************************************/ 00140 00141 TTFont::~TTFont() 00142 { 00143 } 00144 00145 /******************************************************************************************** 00146 00147 > void TTFont::Dump() 00148 00149 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00150 Created: 12/09/95 00151 Purpose: Dump the contents of this cache entry out 00152 00153 ********************************************************************************************/ 00154 00155 void TTFont::Dump() 00156 { 00157 FontBase::Dump(); 00158 TRACE( _T(" FontClass = TrueType\n")); 00159 } 00160 00161 /******************************************************************************************** 00162 00163 > TTFontMan::TTFontMan() 00164 00165 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00166 Created: 12/09/95 00167 Purpose: Default constructor 00168 00169 ********************************************************************************************/ 00170 00171 TTFontMan::TTFontMan() 00172 { 00173 } 00174 00175 /******************************************************************************************** 00176 00177 static BOOL TTFontMan::IsOkToCall() 00178 00179 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00180 Created: 01/9/95 00181 Returns: TRUE if the TrueType mangler is actually running and can be used on this OpSys 00182 Purpose: Determine whether we can make further calls to the TrueType Manager 00183 00184 ********************************************************************************************/ 00185 00186 BOOL TTFontMan::IsOkToCall() 00187 { 00188 // Currently its always true as this is the winoil 00189 return TRUE; 00190 } 00191 00192 /******************************************************************************************** 00193 00194 > static BOOL TTFontMan::CacheNamedFont(String_64* pFontName) 00195 00196 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00197 Created: 12/9/95 00198 Inputs: pFontName = a pointer to a fontname to find and cache 00199 Outputs: - 00200 Returns: TRUE if the font has been cached 00201 FALSE if not. 00202 Purpose: This function attempts to cache a font of the true type variety. It caches 00203 the font in the kernels font list, and hence can be accessed via 00204 FONTMANAGER-> calls 00205 00206 ********************************************************************************************/ 00207 00208 BOOL TTFontMan::CacheNamedFont(String_64* pFontName) 00209 { 00210 CDC Screen; 00211 if (Screen.CreateIC(TEXT("DISPLAY"), 0, 0, 0)) 00212 { 00213 Application* pApp = GetApplication(); 00214 FontManager* pFontMan = pApp->GetFontManager(); 00215 ERROR2IF(pFontMan == NULL,FALSE,"NULL FontManager ptr"); 00216 pFontMan->ClearTempFont(); 00217 EnumFontFamilies(Screen.m_hDC, 00218 NULL, 00219 (FONTENUMPROC) TTFontMan_CallBackCacheNamedFont, 00220 (LPARAM)pFontName); 00221 Screen.DeleteDC(); 00222 return pFontMan->TempFontValid(); 00223 } 00224 return FALSE; 00225 } 00226 00227 /******************************************************************************************** 00228 00229 > static BOOL TTFontMan::CacheCompatibleFont(String_64* pFontName) 00230 00231 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00232 Created: 12/9/95 00233 Inputs: pFontName = a pointer to a fontname to find and cache 00234 Outputs: - 00235 Returns: - 00236 Purpose: This function attempts to cache a font of the ATM variety 00237 00238 ********************************************************************************************/ 00239 00240 BOOL TTFontMan::CacheCompatibleFont(String_64* pFontName) 00241 { 00242 return FALSE; 00243 } 00244 00245 /******************************************************************************************** 00246 00247 > static void TTFontMan::ValidateCache() 00248 00249 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00250 Created: 12/9/95 00251 Purpose: This function will attempt to recache all true type fonts within the kernels 00252 font manager cache. 00253 00254 ********************************************************************************************/ 00255 00256 void TTFontMan::ValidateCache() 00257 { 00258 CDC Screen; 00259 if (Screen.CreateIC(TEXT("DISPLAY"), 0, 0, 0)) 00260 { 00261 EnumFontFamilies(Screen.m_hDC, 00262 NULL, 00263 (FONTENUMPROC) TTFontMan_CallBackValidateFont, 00264 NULL); 00265 Screen.DeleteDC(); 00266 } 00267 } 00268 00269 /******************************************************************************************** 00270 00271 > static void TTFontMan::FindClosestFont() 00272 00273 Author: Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com> 00274 Created: 20/08/96 00275 Purpose: Enumerates all the fonts, looking for a match to a panose number 00276 00277 ********************************************************************************************/ 00278 00279 void TTFontMan::FindClosestFont() 00280 { 00281 CDC Screen; 00282 if (Screen.CreateIC(TEXT("DISPLAY"), 0, 0, 0)) 00283 { 00284 EnumFontFamilies(Screen.m_hDC, 00285 NULL, 00286 (FONTENUMPROC) TTFontMan_CallBackFindClosestFont, 00287 NULL); 00288 Screen.DeleteDC(); 00289 } 00290 } 00291 00292 /******************************************************************************************** 00293 00294 > TTFont* TTFontMan::CreateNewFont(String_64* pFontName) 00295 00296 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00297 Created: 12/9/95 00298 Inputs: pFontName = a pointer to a fontname 00299 Returns: NULL if no true type font structure has been created 00300 A pointer to a true type font structure if successfull. 00301 Purpose: This function attempts to create a font instance and will be called by 00302 the font manager when new fonts are added. 00303 00304 ********************************************************************************************/ 00305 00306 TTFont* TTFontMan::CreateNewFont(String_64* pFontName) 00307 { 00308 TTFont *pFont = new TTFont; 00309 if (pFont==NULL) 00310 return NULL; 00311 if (!pFont->Initialise(pFontName)) 00312 { 00313 delete pFont; 00314 return NULL; 00315 } 00316 return pFont; 00317 } 00318 00319 /******************************************************************************************** 00320 00321 > OUTLINETEXTMETRIC *TTFontMan::GetOutlineTextMetric(LOGFONT *pLogFont) 00322 00323 Author: Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com> 00324 Created: 15/08/96 00325 Inputs: pLogFont - pointer to the LOGFONT describing the font in question 00326 Returns: pointer to an OUTLINETEXTMETRIC structure, or NULL if none exists. 00327 Purpose: Retrieves the OUTLINETEXTMETRIC structure for a TrueType font 00328 00329 The caller is responsible for deleting this after use. 00330 00331 ********************************************************************************************/ 00332 00333 OUTLINETEXTMETRIC *TTFontMan::GetOutlineTextMetric(LOGFONT *pLogFont) 00334 { 00335 ERROR2IF(pLogFont==NULL, FALSE, "Parameter pLogFont==NULL."); 00336 00337 // watch closely now - it gets fairly involved down here 00338 00339 OUTLINETEXTMETRIC *pOutlineTextMetric = NULL; 00340 INT32 Value; 00341 00342 CDC DisplayDC; 00343 if (DisplayDC.CreateIC(TEXT("DISPLAY"), 0, 0, 0)) 00344 { 00345 CFont *pNewCFont = new CFont; 00346 00347 if (pNewCFont->CreateFontIndirect(pLogFont) != NULL) 00348 { 00349 // ** ** ** ** 00350 // ** ** must remember to select the old CFont ** ** 00351 // *** back in again when we've *** 00352 // ** ** finished using this new CFont! ** ** 00353 // ** ** ** ** 00354 00355 CFont *pOldCFont = DisplayDC.SelectObject(pNewCFont); 00356 00357 if (pOldCFont != NULL) 00358 { 00359 TEXTMETRIC MyTextMetric; 00360 00361 if (DisplayDC.GetTextMetrics(&MyTextMetric) != 0) 00362 { 00363 if (MyTextMetric.tmPitchAndFamily & TMPF_TRUETYPE == TMPF_TRUETYPE) 00364 { 00365 // its a TrueType font, so get the OUTLINETEXTMETRIC structure and run 00366 00367 Value = DisplayDC.GetOutlineTextMetrics(NULL, NULL); 00368 00369 // claim a block of memory for the OUTLINETEXTMETRIC class 00370 pOutlineTextMetric = (OUTLINETEXTMETRIC *) malloc(Value); 00371 00372 // now get the OUTLINETEXTMETRIC structure itself 00373 Value = DisplayDC.GetOutlineTextMetrics(Value, pOutlineTextMetric); 00374 00375 if (Value==FALSE) 00376 { 00377 // failed to get the outline text metrics, so free the memory we claimed 00378 free(pOutlineTextMetric); 00379 pOutlineTextMetric=NULL; 00380 } 00381 } 00382 else 00383 { 00384 // not a truetype font, so do nothing. 00385 } 00386 } 00387 else 00388 { 00389 DisplayDC.SelectObject(pOldCFont); 00390 DisplayDC.DeleteDC(); 00391 delete pNewCFont; 00392 ERROR2(NULL, "Unable to retrieve TEXTMETRIC structure from DisplayDC.") 00393 } 00394 00395 // ** ** ** ** 00396 // ** ** select the old CFont back into the ** ** 00397 // *** DC now we've finished using the *** 00398 // ** ** new CFont! ** ** 00399 // ** ** ** ** 00400 00401 DisplayDC.SelectObject(pOldCFont); 00402 } 00403 else 00404 { 00405 delete pNewCFont; 00406 DisplayDC.DeleteDC(); 00407 ERROR2(NULL, "Unable to select font into IC."); 00408 } 00409 } 00410 else 00411 { 00412 delete pNewCFont; 00413 DisplayDC.DeleteDC(); 00414 ERROR2(NULL, "Unable to create font."); 00415 } 00416 delete pNewCFont; 00417 DisplayDC.DeleteDC(); 00418 } 00419 else 00420 { 00421 ERROR2(NULL, "Unable to create an IC."); 00422 } 00423 00424 return pOutlineTextMetric; 00425 } 00426 00427 /******************************************************************************************** 00428 00429 > static void TTFontMan::EnumAllFonts(OILEnumFonts* pClass) 00430 00431 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00432 Created: 12/9/95 00433 Inputs: pClass = A pointer to an object to call back. 00434 Purpose: Gives the kernel a way of enumerating fonts itself 00435 00436 ********************************************************************************************/ 00437 00438 void TTFontMan::EnumAllFonts(OILEnumFonts* pClass) 00439 { 00440 CDC Screen; 00441 if (Screen.CreateIC(TEXT("DISPLAY"), 0, 0, 0)) 00442 { 00443 EnumFontFamilies(Screen.m_hDC, 00444 NULL, 00445 (FONTENUMPROC) TTFontMan_CallBackDispatchFont, 00446 (LPARAM)pClass); 00447 Screen.DeleteDC(); 00448 } 00449 } 00450 00451 /******************************************************************************************** 00452 00453 > INT32 APIENTRY TTFontMan_CallBackCacheNamedFont( 00454 ENUMLOGFONT FAR* lpelf, // address of logical-font data 00455 NEWTEXTMETRIC FAR* lpntm, // address of physical-font data 00456 INT32 FontType, // type of font 00457 LPARAM lParam // address of application-defined data 00458 00459 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00460 Created: 12/9/95 00461 Purpose: The call back function providing all font data 00462 00463 ********************************************************************************************/ 00464 00465 INT32 APIENTRY TTFontMan_CallBackCacheNamedFont( 00466 ENUMLOGFONT FAR* lpelf, // address of logical-font data 00467 NEWTEXTMETRIC FAR* lpntm, // address of physical-font data 00468 INT32 FontType, // type of font 00469 LPARAM lParam // address of application-defined data 00470 ) 00471 { 00472 if (FontType & TRUETYPE_FONTTYPE) 00473 { 00474 // find the font name 00475 String_64 FontName(lpelf->elfLogFont.lfFaceName); 00476 00477 if (lParam==NULL || (_tcsncicmp(FontName, *((String_64 * )lParam), 64) == 0)) 00478 { 00479 FontManager* pFontMan = GetApplication()->GetFontManager(); 00480 pFontMan->SetTempFont(FC_TRUETYPE, &FontName, lpelf); 00481 return FALSE; 00482 } 00483 } 00484 return TRUE; 00485 } 00486 00487 /******************************************************************************************** 00488 00489 > INT32 APIENTRY TTFontMan_CallBackValidateFont( 00490 ENUMLOGFONT FAR* lpelf, // address of logical-font data 00491 NEWTEXTMETRIC FAR* lpntm, // address of physical-font data 00492 INT32 FontType, // type of font 00493 LPARAM lParam // address of application-defined data 00494 00495 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00496 Created: 12/9/95 00497 Purpose: The call back function providing all font data 00498 00499 ********************************************************************************************/ 00500 00501 INT32 APIENTRY TTFontMan_CallBackValidateFont( 00502 ENUMLOGFONT FAR* lpelf, // address of logical-font data 00503 NEWTEXTMETRIC FAR* lpntm, // address of physical-font data 00504 INT32 FontType, // type of font 00505 LPARAM lParam // address of application-defined data 00506 ) 00507 { 00508 UNREFERENCED_PARAMETER (lpntm); 00509 00510 if (FontType & TRUETYPE_FONTTYPE) 00511 { 00512 // find the font name 00513 String_64 FontName(lpelf->elfLogFont.lfFaceName); 00514 00515 FontManager* pFontMan = GetApplication()->GetFontManager(); 00516 pFontMan->ValidateItem(FC_TRUETYPE, &FontName, lpelf); 00517 } 00518 return TRUE; 00519 } 00520 00521 /******************************************************************************************** 00522 00523 INT32 APIENTRY TTFontMan_CallBackDispatchFont( 00524 ENUMLOGFONT FAR* lpelf, // address of logical-font data 00525 NEWTEXTMETRIC FAR* lpntm, // address of physical-font data 00526 INT32 FontType, // type of font 00527 LPARAM lParam // address of application-defined data 00528 00529 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00530 Created: 12/9/95 00531 Purpose: The call back function providing all font data 00532 00533 ********************************************************************************************/ 00534 00535 INT32 APIENTRY TTFontMan_CallBackDispatchFont( 00536 ENUMLOGFONT FAR* lpelf, // address of logical-font data 00537 NEWTEXTMETRIC FAR* lpntm, // address of physical-font data 00538 INT32 FontType, // type of font 00539 LPARAM lParam // address of application-defined data 00540 ) 00541 { 00542 UNREFERENCED_PARAMETER (lpntm); 00543 00544 if ((FontType & TRUETYPE_FONTTYPE) && lpelf->elfLogFont.lfFaceName[0] != TEXT('@')) 00545 { 00546 return ((OILEnumFonts*) lParam)->NewFont(FC_TRUETYPE, lpelf); 00547 } 00548 00549 return TRUE; 00550 } 00551 00552 /******************************************************************************************** 00553 00554 INT32 APIENTRY TTFontMan_CallBackFindClosestFont( 00555 ENUMLOGFONT FAR* lpelf, // address of logical-font data 00556 NEWTEXTMETRIC FAR* lpntm, // address of physical-font data 00557 INT32 FontType, // type of font 00558 LPARAM lParam // address of application-defined data 00559 00560 Author: Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com> 00561 Created: 20/08/96 00562 Purpose: The call back function for finding the closest font 00563 00564 ********************************************************************************************/ 00565 00566 INT32 APIENTRY TTFontMan_CallBackFindClosestFont( 00567 ENUMLOGFONT FAR* lpelf, // address of logical-font data 00568 NEWTEXTMETRIC FAR* lpntm, // address of physical-font data 00569 INT32 FontType, // type of font 00570 LPARAM lParam // address of application-defined data 00571 ) 00572 { 00573 UNREFERENCED_PARAMETER (lpntm); 00574 00575 if (FontType & TRUETYPE_FONTTYPE) 00576 { 00577 // find the font name 00578 String_64 FontName(lpelf->elfLogFont.lfFaceName); 00579 00580 FontManager* pFontMan = GetApplication()->GetFontManager(); 00581 return pFontMan->FindClosestFontFullTry(FC_TRUETYPE, &FontName, lpelf); 00582 } 00583 00584 return TRUE; 00585 }