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 #ifndef INC_FONTMAN
00104 #define INC_FONTMAN
00105
00106
00107
00108 #include "fontbase.h"
00109
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
00123
00124
00125
00126
00127
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;
00167 WORD Handle;
00168 ENUMLOGFONT* pEnumLogFont;
00169 OUTLINETEXTMETRIC* pOutlineTextMetric;
00170 BOOL FlagIsCorrupt;
00171 BOOL FlagIsReplaced;
00172 };
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 class FontManager : public CCObject
00188 {
00189 CC_DECLARE_DYNCREATE( FontManager )
00190
00191 public:
00192 FontManager();
00193 ~FontManager();
00194
00195
00196
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
00246 public:
00247 WORD FindTypeface(String_64 &TypeFaceName, FontClass Class);
00248 WORD FindClosestFont(const CCPanose &PanoseNumber);
00249
00250
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
00265 public:
00266 void InvalidateCharMetrics();
00267 BOOL GetCharMetrics(CNativeDC* pDC, WCHAR ch, CharDescription& FontDesc,
00268 CharMetrics* pCharMetrics);
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
00309
00310
00311
00312
00313
00314
00315
00316
00317
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