fntcache.h

Go to the documentation of this file.
00001 // $Id: fntcache.h 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  * */
00100 // Definition of the Text tools FontCache
00101 // See FNTCACHE.DOC for an explanation
00102 
00103 
00104 
00105 
00106 #ifndef INC_FNTCACHE
00107 #define INC_FNTCACHE
00108 
00109 //#include "ccobject.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "listitem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 #include "gcache.h"
00112 //#include "txtattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include <limits.h>
00114 
00115 
00116 /********************************************************************************************
00117 
00118 >   class FontCache
00119 
00120     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00121 
00122     Created:    16/1/95
00123     
00124     Purpose:    The FontCache maps a character description to a  path for that character. 
00125                 There only ever needs to be a single instance of the FontCache so all
00126                 data and methods are static.
00127     
00128     Documentation:  specs\fntcache.doc
00129     
00130     SeeAlso:    CharDescription
00131     SeeAlso:    PathHandleItem
00132 
00133 ********************************************************************************************/
00134 
00135 
00136 // The simpler FontCache defined below is simply a wrapper around a CamCache
00137 
00138 class FontCache
00139 {
00140     // All data/methods must be static
00141 
00142 public:
00143     // This method must be called before we can use the CamCache
00144     static BOOL Init();
00145 
00146     static BOOL InitCalled; // = FALSE, set to TRUE only if Init function has been called
00147 
00148     // This function must be called to destroy the font cache
00149     static void DeInit(); 
00150 
00151     // Returns path for character specified by ChDesc 
00152     static BOOL GetPath(CharDescription& ChDesc, INT32** Points, BYTE** Types, UINT32 *Length);
00153     
00154     // The path cache is used to map a Path Handle to path data
00155     static CamCache* pPathCache;
00156 
00157     static BOOL  GetBounds(DocRect* pBounds, CharDescription& CharDesc);
00158     static BOOL  CalcDefaultCharBounds(DocRect* pRect, CharDescription& CharDesc);
00159     static Path* CreateDefaultCharPath(CharDescription& CharDesc);
00160 private:
00161     static INT32 BoundsEntries;     // number of entries in the char bounds cache
00162 
00163 
00164 };
00165 
00166 
00167 #endif
00168 
00169 #if 0
00170 
00171 //
00172 // WE ARE NOT USING THE HI-TECH FONT CACHE AT THE MOMENT
00173 //
00174 //
00175 
00176 // ------------------------------------------------------------------------------------------
00177 // Constants
00178 
00179 // The cache size is the maximum number of characters to cache
00180 #define CACHE_SIZE 255
00181 
00182 // We will allocate two arrays CacheA, CacheB each of length CACHE_LIST_SIZE. Each of these arrays
00183 // will never be more than 1/3 full
00184 //#define CACHE_LIST_SIZE (1.5 * CACHE_SIZE); // This MUST be prime or performance is naff
00185 #define CACHE_LIST_SIZE 383
00186 
00187 //#define MAX_ITEMS_IN_CACHE_LIST = (CACHE_LIST_SIZE/3)
00188 #define MAX_ITEMS_IN_CACHE_LIST 255
00189 
00190 // We can never allocate a path handle larger than MAX_FONT_HANDLE 
00191 #define MAX_PATH_HANDLE (UINT32_MAX - 1)
00192 
00193 
00194 /********************************************************************************************
00195 
00196 >   class ClassName : public CCObject
00197 
00198     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00199     Created:    16/1/95
00200     Purpose:    Each character we need to render can be uniquely identified by a 16 bit 
00201                 unicode character + various attributes which define the appearance of the 
00202                 characters font. The CharDescription structure defined below is used to 
00203                 identify a character. This structure is similar to the windows LOGFONT 
00204                 structure.
00205 
00206     SeeAlso:    FontCache
00207 
00208 ********************************************************************************************/
00209 
00210 
00211 class CharDescription : public CCObject
00212 {
00213     // Important !!!
00214     // Whenever this structure is changed, you must remember to update the operator= and
00215     // operator== methods !!!
00216     CC_DECLARE_DYNAMIC(CharDescription)
00217 
00218     public:
00219 
00220     INT32 operator==(const CharDescription& ChDesc); 
00221     CharDescription& operator=(CharDescription& ChDesc);
00222 
00223     INT32 Height;
00224     INT32 Width;
00225     //INT32 lfEscapement;
00226     //INT32 lfOrientation;
00227     //INT32 lfWeight;
00228     BYTE Italic;
00229     //BYTE lfUnderline;
00230     //BYTE lfStrikeOut;
00231     //BYTE lfCharSet;
00232     //BYTE lfOutPrecision;
00233     //BYTE lfClipPrecision;
00234     //BYTE lfQuality;
00235     //BYTE lfPitchAndFamily;    
00236     WCHAR CharCode;             // A 16 bit unicode value
00237 }; 
00238 
00239 
00240 /********************************************************************************************
00241 
00242 >   class PathHandleItem: public CCObject
00243 
00244     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00245     Created:    16/1/95
00246     Purpose:    We store PathHandle Items in lists pointed to by the CacheA and CacheB arrays
00247                 within the FontCache.They associate a CharDescription with a unique path handle.
00248 
00249     SeeAlso:    FontCache
00250     SeeAlso:    CharDescription
00251 
00252 ********************************************************************************************/
00253 /*
00254     Technical notes: We want to minimise the size of the PathHandleItem. This is why they are
00255     not derived from ListItem. Instead they store a single Next pointer so that they can be 
00256     linked together.
00257 
00258 */                                                                                                     
00259 
00260 
00261 class PathHandleItem: public CCObject
00262 {  
00263     CC_DECLARE_DYNAMIC(PathHandleItem)
00264 
00265     public:
00266     PathHandleItem(CharDescription& ChDesc, UINT32 PathHandle);
00267 
00268     CharDescription CharDesc;   // Identifies a character
00269     UINT32 PathHandle;
00270     // Removes this item from the specified list
00271     void RemoveItemFromList(PathHandleItem** pHead); 
00272     PathHandleItem* Next;       // pointer to the Next PathHandleItem
00273 };
00274 
00275 
00276 
00277 
00278 class FontCache
00279 {
00280     // All data/methods must be static
00281 
00282     public:
00283     
00284     // This method must be called before we can use the CamCache
00285     static BOOL Init();
00286 
00287     static BOOL InitCalled; // = FALSE, set to TRUE only if Init function has been called
00288 
00289     // This function must be called to destroy the font cache
00290     static void DeInit(); 
00291 
00292     // Returns path for character specified by ChDesc 
00293     static BOOL GetPath(CharDescription& ChDesc, INT32** Points, BYTE** Types, UINT32 *Length);
00294     
00295     #ifdef _DEBUG
00296     static void Test1();
00297     #endif
00298 
00299 
00300     private:
00301     
00302     static UINT32 GetPathHandle(CharDescription& ChDesc); 
00303 
00304     // Given a CharDescription returns an integer hash key in the range 0..CACHE_LIST_SIZE
00305     static UINT32 GetHashKey(CharDescription& ChDesc);
00306 
00307     // The two caches used to map a CharacterDescription to a Path Handle 
00308     static PathHandleItem* CacheA   [CACHE_LIST_SIZE]; 
00309     static PathHandleItem* CacheB   [CACHE_LIST_SIZE]; 
00310     
00311     // Searches a PathHandleItem list for ChDesc item
00312     static PathHandleItem* GetPathHandleItem(PathHandleItem* ListHead, CharDescription&  ChDesc); 
00313     
00314     // Deletes all items in specified cache
00315     static void DeleteCacheLists(PathHandleItem** pCacheArray);
00316     
00317     static void TidyCache();
00318 
00319     static PathHandleItem** PrimaryC;   // Points to the current primary cache (CacheA or CacheB)
00320     static PathHandleItem** SecondaryC; // Points to the current secondary cache (CacheA or CacheB)
00321 
00322 
00323     static BOOL GetPathFromPathCache(UINT32 PathHandle, CharDescription& ChDesc, 
00324                                     INT32** Points, BYTE** Types, UINT32* Length);
00325     
00326     // The path cache is used to map a Path Handle to path data
00327     static CamCache* pPathCache;
00328     
00329     static PathHandleItem* AllocatePathHandle(UINT32 Key, CharDescription& ChDesc);
00330 
00331     // The next PathHandle to assign to a new CharDescPathHandleItem we add to the cache
00332     static UINT32 NextUniquePathHandle; 
00333 
00334     // The number of items stored in the primary cache
00335     static UINT32 NumItemsInPrimaryCache; 
00336 
00337     // Can be deleted
00338     #ifdef _DEBUG
00339     static UINT32 PHits;
00340     static UINT32 SHits;
00341     static UINT32 Misses;
00342     #endif
00343 
00344         
00345 };
00346 
00347 #endif

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