fontman.h

Go to the documentation of this file.
00001 // $Id: fontman.h 1642 2006-08-02 10:15:44Z 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 Camelots Font Managler, supposidly
00099 
00100 /*
00101 */
00102 
00103 #ifndef INC_FONTMAN
00104 #define INC_FONTMAN
00105 
00106 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "listitem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 #include "fontbase.h"
00109 // #include "ccpanose.h" - included in fontbase.h
00110 
00111 #define DEFAULTFONTNAME _T("Times New Roman")
00112 #define DEFAULTHANDLE   0
00113 #define ILLEGALFHANDLE  0x7FFF
00114 #define FIRSTFONTHANDLE 1
00115 
00116 #define HNDLINVALID(handle) ((handle)==(ILLEGALFHANDLE))
00117 #define HNDLVALID(handle) ((handle)!=(ILLEGALFHANDLE))
00118 
00119 
00120 /********************************************************************************************
00121 
00122 >   class CachedFontItem : public ListItem
00123             
00124     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00125     Created:    13/9/95
00126     Purpose:    A font item cached by the font manager
00127     SeeAlso:    
00128 
00129 ********************************************************************************************/
00130 
00131 class CachedFontItem : public ListItem
00132 {
00133     friend class FontManager;
00134     friend class FontComponent;
00135 
00136     CC_DECLARE_DYNCREATE( CachedFontItem )
00137 
00138     public:
00139          CachedFontItem();
00140         ~CachedFontItem();
00141 
00142         String_64*              GetFontName();
00143         WORD                    GetFontHandle() { return Handle; }
00144         FontClass               GetFontClass();
00145         BOOL                    Compare(String_64* pFontName);
00146         ENUMLOGFONT*            GetEnumLogFont();
00147         OUTLINETEXTMETRIC*      GetOutlineTextMetric();
00148 
00149         void                    SetIsCorrupt(BOOL flag) { FlagIsCorrupt = flag; };
00150         void                    SetIsReplaced(BOOL flag) { FlagIsReplaced = flag; };
00151 
00152         BOOL                    IsFullyCached();
00153         BOOL                    IsCorrupt() { return FlagIsCorrupt; }
00154         BOOL                    IsValid() { return IsFullyCached(); };
00155         BOOL                    IsReplaced() { return FlagIsReplaced; };
00156         
00157 
00158     private:
00159         BOOL                    SetCacheData(ENUMLOGFONT* lpelf);
00160         void                    DeleteMetrics();
00161         void                    DeleteFontClass();
00162         void                    Delete();
00163         void                    Dump();
00164 
00165     private:
00166         FontBase*               pFontClass;                     // The class of font (TRUETYPE, ATM etc)
00167         WORD                    Handle;                         // The allocated font handle
00168         ENUMLOGFONT*            pEnumLogFont;                   // A description of the font
00169         OUTLINETEXTMETRIC*      pOutlineTextMetric;
00170         BOOL                    FlagIsCorrupt;
00171         BOOL                    FlagIsReplaced;
00172 };
00173 
00174 /********************************************************************************************
00175 
00176 >   class FontManager : public CCObject
00177             
00178     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00179     Created:    13/9/95
00180     Purpose:    The font manager controlling class
00181     SeeAlso:    This font manager class acts as both a cache of used fonts in the various
00182                 documents loaded into Camelot and an interface to the various font managers
00183                 available to us.
00184 
00185 ********************************************************************************************/
00186 
00187 class FontManager : public CCObject
00188 {
00189     CC_DECLARE_DYNCREATE( FontManager )
00190     
00191     public:
00192          FontManager();
00193         ~FontManager();
00194 
00195 //**************************************************************************************
00196 // The Font Manager interface. Font based calls
00197         
00198         BOOL            Init();
00199         BOOL            LegalFontClass(INT32 Class, FontClass& RealClass);
00200 
00201         WORD            CacheNamedFont(String_64 *FontName, FontClass Class=FC_UNDEFINED);
00202         CachedFontItem* AddFont(String_64* Name, FontClass Class, WORD& Handle);
00203 
00204         CachedFontItem*     GetFont();
00205         CachedFontItem*     GetFont(WORD Handle);
00206         CachedFontItem*     GetFont(String_64 *pFontName, FontClass Class=FC_UNDEFINED);
00207         WORD                GetFontHandle(String_64* pFontName, FontClass Class=FC_UNDEFINED);
00208         String_64*          GetFontName(WORD Handle);
00209         BOOL                GetFontName(WORD Handle, String_64& OutputString);
00210         FontClass           GetFontClass(WORD Handle);
00211         ENUMLOGFONT*        GetEnumLogFont(WORD Handle);
00212         OUTLINETEXTMETRIC*  GetOutlineTextMetric(WORD Handle);
00213 
00214         CachedFontItem* GetFirstFont();
00215         CachedFontItem* GetNextFont(CachedFontItem* pItem);
00216         CachedFontItem* GetCachedFont(WORD Handle);
00217 
00218         INT32           DoesFontExist(String_64 *pFontName, BOOL SearchCache, BOOL SearchInstalled);
00219         BOOL            IsFontValid(WORD Handle);
00220         BOOL            IsFontInstalled(String_64* pFontName, FontClass Class=FC_UNDEFINED);
00221         BOOL            IsFontDefault(WORD Handle);
00222         BOOL            IsFontDefault(CachedFontItem* pItem);
00223         BOOL            IsFontReplaced(WORD Handle);
00224         BOOL            IsFontReplaced(String_64* pFontName, FontClass Class=FC_UNDEFINED);
00225 
00226         BOOL            IsFontUsedInDoc(WORD Handle, Document* pDocument);
00227         void            OnDocumentLoaded(Document* pDocument);
00228 
00229         void            GetCompatibleFont(const String_64& EncodedName, String_64& CompatibleFont, INT32& Style);
00230         void            EncodeFontName(String_64& FontName, String_64& Encoded, INT32 Styles);
00231         void            EncodeAndMapFontName(String_64& FontName, String_64& Encoded, INT32 Styles);
00232         INT32           DecodeFontName(const String_64& IStringRef, String_64& OStringRef);
00233 
00234         void            ClearTempFont();
00235         void            SetTempFont(FontClass Class, String_64* pFontName, ENUMLOGFONT* lpelf);
00236         BOOL            TempFontValid();
00237 
00238         void            RefreshCache();
00239         void            ValidateItem(FontClass Class, String_64* pFontName, ENUMLOGFONT *lpelf);
00240 
00241         void            DumpFontCache();
00242         void            DumpFont(WORD Handle);
00243         
00244 //**************************************************************************************
00245 // Font manager - font based calls used by the new file format
00246 public:
00247         WORD FindTypeface(String_64 &TypeFaceName, FontClass Class);
00248         WORD FindClosestFont(const CCPanose &PanoseNumber);
00249         // the next function needs to be called from a callback function, hence it's public.
00250         // however, it shouldn't be used by anyone else.
00251         BOOL FindClosestFontFullTry(FontClass Class, String_64 *pTypeFaceName, ENUMLOGFONT *pEnumLogFont);
00252 private:
00253         WORD FindClosestFontFull(const CCPanose &PanoseNumber);
00254         WORD FindClosestFontQuick(const CCPanose &PanoseNumber);
00255         BOOL FindClosestFontQuickTry(WORD FontHandle);
00256         WORD FindClosestFontHandle;
00257         CCPanose FindClosestPanoseNumber;
00258         UINT32 FindClosestDistance;
00259         String_64 FindClosestTypeFaceName;
00260         FontClass FindClosestFontClass;
00261         ENUMLOGFONT FindClosestEnumLogFont;
00262 
00263 //**************************************************************************************
00264 // Character based calls
00265 public:
00266         void            InvalidateCharMetrics();
00267         BOOL            GetCharMetrics(CNativeDC* pDC, WCHAR ch, CharDescription& FontDesc,
00268                                             CharMetrics* pCharMetrics); // jwp 15/10/2000
00269         MILLIPOINT      GetCharsKerning(CNativeDC* pDC, WCHAR chLeft, WCHAR chRight,
00270                                             CharDescription& FontDesc);
00271         BOOL            GetCharPath(CharDescription& ChDesc,
00272                                     DocCoord** ppCoords,
00273                                     PathVerb** ppVerbs,
00274                                     UINT32* pNumCoords,
00275                                     CNativeDC* pDC=NULL);
00276 
00277 //**************************************************************************************
00278 
00279 
00280     private:
00281         CachedFontItem* FindFont(WORD Handle);
00282         CachedFontItem* FindFont(String_64* pFontName, FontClass Class=FC_UNDEFINED);
00283 
00284         WORD            GetNextHandle();
00285         CachedFontItem* GetFirstFontType(FontClass fclass);
00286         BOOL            IsFullyCached(WORD Handle);
00287         BOOL            TempCacheNamedFont(String_64* pFontName, FontClass=FC_UNDEFINED, INT32 Pass=1);
00288         BOOL            CacheDefaultFont();
00289         CachedFontItem* AddTempFont(String_64* pFontName, FontClass Class, WORD& hndle);
00290         void            InvalidateCache();
00291         void            ResetDefaultFont();
00292         BOOL            IsFontUsedInSiblings(Node* pNode, WORD Handle, WORD CurrentHandle, UINT32 Level);
00293 
00294     private:
00295         WORD            UniqueHandle;
00296         WORD            DefaultHandle;
00297         List            TheFontList;
00298         CachedFontItem  DefaultFontItem;
00299 
00300     private:
00301         FontClass       TempFontClass;
00302         String_64       TempFontName;
00303         ENUMLOGFONT     TempEnumLogFont;
00304 };
00305 
00306 /********************************************************************************************
00307 
00308 >   class EnumFonts : public OILEnumFonts
00309             
00310     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00311     Created:    13/9/95
00312     Purpose:    This class allows kernel level items to enumerate fonts. 
00313                 To use the class simply derive another from it and implement your own
00314                 NewFont function. If you then call pMyEnumObj->Execute() your
00315                 NewFont function will be called for every font the font manager and oil
00316                 layer support.
00317     SeeAlso:    
00318 
00319 ********************************************************************************************/
00320 
00321 class EnumAllFonts : public OILEnumFonts
00322 {
00323     CC_DECLARE_DYNCREATE( EnumAllFonts )
00324     
00325     public:
00326         EnumAllFonts() {};
00327         virtual BOOL NewFont(FontClass Class, ENUMLOGFONT FAR* lpelf);
00328 };
00329 
00330 #endif

Generated on Sat Nov 10 03:45:21 2007 for Camelot by  doxygen 1.4.4