FontManager Class Reference

The font manager controlling class. More...

#include <fontman.h>

Inheritance diagram for FontManager:

CCObject SimpleCCObject List of all members.

Public Member Functions

 FontManager ()
 Constructor for the font manager class.
 ~FontManager ()
BOOL Init ()
 Get Camelots Font manager going. We simply cache the default font so unknown fonts can be sensibly replaced.
BOOL LegalFontClass (INT32 Class, FontClass &RealClass)
 Check whether a numeric value actually indicates a valid class of font ie lies in the range of supported font types. This is used generally for loading purpose where the font class is loaded as a numeric value.
WORD CacheNamedFont (String_64 *FontName, FontClass Class=FC_UNDEFINED)
 Given a font name try to cache all the data for that font so that we can actually us it. The cache will be checked first to make sure the font is not already installed.
CachedFontItemAddFont (String_64 *Name, FontClass Class, WORD &Handle)
 Creates a new font item for this named font. The font will not be fully cached. To cache all the data for the font, call CacheFontData(Handle).
CachedFontItemGetFont ()
 Return the precached default font data to use for rendering.
CachedFontItemGetFont (WORD Handle)
 Return the font data to use for rendering. This function performs a specific job in avoiding caching the font data. If the font is already cached then fine, it is returned for use. If not, the default font is returned.
CachedFontItemGetFont (String_64 *pFontName, FontClass Class=FC_UNDEFINED)
 Return the font data to use for rendering. This function performs a specific job in avoiding caching the font data. If the font is already cached then fine, it is returned for use. If not, the default font is returned.
WORD GetFontHandle (String_64 *pFontName, FontClass Class=FC_UNDEFINED)
 Get the handle on a cached font (if cached) otherwise return the default font handle.
String_64GetFontName (WORD Handle)
 Return a pointer to the font name given its font handle.
BOOL GetFontName (WORD Handle, String_64 &OutputString)
FontClass GetFontClass (WORD Handle)
 Return what class of font this handle is.
ENUMLOGFONTGetEnumLogFont (WORD Handle)
 Return the ENUMLOGFONT structure for this font handle. Note the function will automatically substitute the default font if the handle provided is invalid or the font it describes is not fully cached.
OUTLINETEXTMETRICGetOutlineTextMetric (WORD Handle)
 Return the ENUMLOGFONT structure for this font handle Note the function will automatically substitute the default font if the handle provided is invalid or the font it describes is not fully cached.
CachedFontItemGetFirstFont ()
CachedFontItemGetNextFont (CachedFontItem *pItem)
CachedFontItemGetCachedFont (WORD Handle)
 This function returns the font associated with the handle passed. If the font is not in the cache it will return NULL. It differs from GetFont in that it will not attempt to return the DefaultFontItem if it cannot find the item specified.
INT32 DoesFontExist (String_64 *pFontName, BOOL SearchCache, BOOL SearchInstalled)
 First check in the cache if necessary, then through the installed set of fonts to find whether the named font actually exists.
BOOL IsFontValid (WORD Handle)
 Check to see if the font described is actually valid, ie all the metrics for the font have been cached correctly.
BOOL IsFontInstalled (String_64 *pFontName, FontClass Class=FC_UNDEFINED)
 Search through all the installed sets of fonts for the named font.
BOOL IsFontDefault (WORD Handle)
 Check to see if the font handle described is the handle of the default font ie the font which is used to replace unknown fonts (fonts not resident on the host machine).
BOOL IsFontDefault (CachedFontItem *pItem)
BOOL IsFontReplaced (WORD Handle)
 Check to see if the font described has been replaced.
BOOL IsFontReplaced (String_64 *pFontName, FontClass Class=FC_UNDEFINED)
BOOL IsFontUsedInDoc (WORD Handle, Document *pDocument)
 Find out whether a given font is used in a document.
void OnDocumentLoaded (Document *pDocument)
 Called after a document has been loaded - allows us to fix the current and default fonts if they are not installed. They are only changed if they are not used in the document.
void GetCompatibleFont (const String_64 &EncodedName, String_64 &CompatibleFont, INT32 &Style)
 Find a compatible font to that specified in the encoded font name. An encoded name looks something like....
void EncodeFontName (String_64 &FontName, String_64 &Encoded, INT32 Styles)
 Output a font name with bold and italic flags attached. All spaces are converted to dashes. The font is first checked for the existance of style words bold and italic before new styles are added.
void EncodeAndMapFontName (String_64 &FontName, String_64 &Encoded, INT32 Styles)
 This function first calls EncodeFontName, to generate an approximated PostScript font name, before calling a second function to get the PostScript font mapping.
INT32 DecodeFontName (const String_64 &IStringRef, String_64 &OStringRef)
 Given a fontname encoded for EPS files, return the actual font name suitable for font matching and its style definintions (if applicable).
void ClearTempFont ()
 Throws away any font data stored in the temp font.
void SetTempFont (FontClass Class, String_64 *pFontName, ENUMLOGFONT *lpelf)
BOOL TempFontValid ()
void RefreshCache ()
 Scans all the cached fonts and checks to see if any are invalid. If a font is invalid it is attempted to be made valid. This function is generally called when the external worlds fonts have changed via install/deinstall.
void ValidateItem (FontClass Class, String_64 *pFontName, ENUMLOGFONT *lpelf)
 Used as a way of revalidating a cached font. This function is called from the various oil level font managers when we've asked them to refresh our cache. They simply need to scan their font lists and call this function with the new data.
void DumpFontCache ()
 Dubugging facitity - dumps out the contents of our cache.
void DumpFont (WORD Handle)
 Dubugging facitity - dumps out the contents of a font from our cache.
WORD FindTypeface (String_64 &TypeFaceName, FontClass Class)
 Used by the new file format, to check if a particular typeface (and font class) is installed and available. See Also: class FontComponent.
WORD FindClosestFont (const CCPanose &PanoseNumber)
 Performs panose matching on the installed fonts.
BOOL FindClosestFontFullTry (FontClass Class, String_64 *pTypeFaceName, ENUMLOGFONT *pEnumLogFont)
void InvalidateCharMetrics ()
 Invalidate char metrics cache.
BOOL GetCharMetrics (CNativeDC *pDC, WCHAR ch, CharDescription &FontDesc, CharMetrics *pCharMetrics)
 Get the char metrics for the given char and font Just dispenses the call to the FontMetricsCache.
MILLIPOINT GetCharsKerning (CNativeDC *pDC, WCHAR chLeft, WCHAR chRight, CharDescription &FontDesc)
 Finds the kerning distance between two chars.
BOOL GetCharPath (CharDescription &ChDesc, DocCoord **ppCoords, PathVerb **ppVerbs, UINT32 *pNumCoords, CNativeDC *pDC=NULL)
 Get the path associated with a given char.

Private Member Functions

WORD FindClosestFontFull (const CCPanose &PanoseNumber)
WORD FindClosestFontQuick (const CCPanose &PanoseNumber)
BOOL FindClosestFontQuickTry (WORD FontHandle)
CachedFontItemFindFont (WORD Handle)
 Find the entry in the font managers font cache which corresponds to this handle.
CachedFontItemFindFont (String_64 *pFontName, FontClass Class=FC_UNDEFINED)
 Find the entry in the font managers font list which corresponds to this fontname and font class Note: One might be tempted to include the default font item in the comparison and return the default font handle when the default font name is passed, but this does not happen and this is by design. See OnDocumentLoaded for further information.
WORD GetNextHandle ()
 Return a unique handle for the font cache handler Handles range from 1..n, 0 is explicitly reserved for the default handle, 0x7FFF is defined as an illegal handle.
CachedFontItemGetFirstFontType (FontClass fclass)
 Find the entry in the font managers font list which corresponds to the first 'FontClass' font cached.
BOOL IsFullyCached (WORD Handle)
 Find out if the font is fully cached and ready to use. This will generally be true of all fonts added by CacheNamedFont. If the font is not fully cached then call CacheFontData(). It will not be if AddFont has been used to add the font to the font list.
BOOL TempCacheNamedFont (String_64 *pFontName, FontClass=FC_UNDEFINED, INT32 Pass=1)
 Search through all the installed sets of fonts for the named font and place the result in a temp font.
BOOL CacheDefaultFont ()
 Cache the default font so we can use this as a replacement when unable to find strange fonts.
CachedFontItemAddTempFont (String_64 *pFontName, FontClass Class, WORD &hndle)
 Given the temp font data, this function goes and caches that data under the provided name and returns the font handle.
void InvalidateCache ()
 Scans all the cached fonts deletes all cached data. If the entries are not recached all visible fonts will be replaced by the default font.
void ResetDefaultFont ()
 Cache the default font so we can use this as a replacement when unable to find strange fonts. The cache is checked first to see if the default font is already there.
BOOL IsFontUsedInSiblings (Node *pNode, WORD Handle, WORD CurrentHandle, UINT32 Level)
 Find out whether a given font is used in a document.

Private Attributes

WORD FindClosestFontHandle
CCPanose FindClosestPanoseNumber
UINT32 FindClosestDistance
String_64 FindClosestTypeFaceName
FontClass FindClosestFontClass
ENUMLOGFONT FindClosestEnumLogFont
WORD UniqueHandle
WORD DefaultHandle
List TheFontList
CachedFontItem DefaultFontItem
FontClass TempFontClass
String_64 TempFontName
ENUMLOGFONT TempEnumLogFont

Detailed Description

The font manager controlling class.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/9/95
See also:
This font manager class acts as both a cache of used fonts in the various documents loaded into Camelot and an interface to the various font managers available to us.

Definition at line 187 of file fontman.h.


Constructor & Destructor Documentation

FontManager::FontManager  ) 
 

Constructor for the font manager class.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/09/95

Definition at line 461 of file fontman.cpp.

FontManager::~FontManager  ) 
 

Definition at line 468 of file fontman.cpp.

00469 {
00470     TheFontList.DeleteAll();
00471 }


Member Function Documentation

CachedFontItem * FontManager::AddFont String_64 Name,
FontClass  fclass,
WORD retHandle
 

Creates a new font item for this named font. The font will not be fully cached. To cache all the data for the font, call CacheFontData(Handle).

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Name = a pointer to the font name [INPUTS] fclass = a reference to the class of font to add
Handle = ILLEGALFHANDLE if the font could not be added [OUTPUTS] Handle = The font handle if ok
Returns:
NULL if the font could not be added A pointer to the font record

Definition at line 596 of file fontman.cpp.

00597 {
00598     TRACEUSER("wuerthne", _T("FontManager::AddFont %s"), (TCHAR*)*Name);
00599     CachedFontItem* pItem = new CachedFontItem;
00600     if (pItem==NULL)
00601         return NULL;
00602 
00603     FontBase* pClass = OILFontMan::CreateNewFont(fclass,Name);
00604     if (pClass==NULL)
00605     {
00606         delete pItem;
00607         pItem=NULL;
00608         return NULL;
00609     }
00610 
00611     pItem->pFontClass = pClass;
00612     pItem->Handle = GetNextHandle();
00613     TheFontList.AddTail(pItem);
00614 
00615     retHandle = pItem->Handle;
00616     TRACEUSER("wuerthne", _T("AddFont, returning %d"), retHandle);
00617 
00618     return pItem;
00619 }

CachedFontItem * FontManager::AddTempFont String_64 pFontName,
FontClass  Class,
WORD hndle
[private]
 

Given the temp font data, this function goes and caches that data under the provided name and returns the font handle.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
pFontName = a pointer to the font name [INPUTS] Class = describes the type of class (see typedef for details) FC_UNDEFINED then ignore the class match and match the first item with the same name whatever font class it is
Handle = ILLEGALFHANDLE if the font could not be added [OUTPUTS] Handle = The font handle if ok
Returns:
NULL if the font could not be added A pointer to the font record

Definition at line 1925 of file fontman.cpp.

01926 {
01927     CachedFontItem* pItem = NULL;
01928     if (TempFontClass==FC_UNDEFINED)
01929     {
01930         if (Class!=FC_UNDEFINED)
01931             pItem = AddFont(pFontName, Class, hndle);
01932         else
01933         {
01934 //          ERROR3("Trying to add a font of an unknown class");
01935             pItem = AddFont(pFontName, FC_TRUETYPE, hndle);
01936         }
01937     }
01938     else
01939     {   
01940         pItem = AddFont(pFontName, TempFontClass, hndle);
01941         if (pItem)
01942             pItem->SetCacheData(&TempEnumLogFont);
01943     }   
01944     return pItem;
01945 }

BOOL FontManager::CacheDefaultFont  )  [private]
 

Cache the default font so we can use this as a replacement when unable to find strange fonts.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the default font has been cached FALSE if not

Definition at line 1591 of file fontman.cpp.

01592 {
01593     PORTNOTE("text","FontManager::CacheDefaultFont - do nothing");
01594 #ifndef DISABLE_TEXT_RENDERING
01595     if (DefaultFontItem.pFontClass!=NULL)
01596     {
01597         ERROR3("CacheDefaultFont called but a default font is already resident");
01598         return TRUE;
01599     }
01600 
01601     // now scan all installed lists an set out local temp font data
01602     String_64 DefFont(DEFAULTFONTNAME);
01603 
01604     if (!TempCacheNamedFont(&DefFont))
01605         if (!TempCacheNamedFont(NULL))
01606             return FALSE;
01607 
01608     FontBase* pClass = OILFontMan::CreateNewFont(TempFontClass,&TempFontName);
01609     if (pClass==NULL)
01610         return FALSE;
01611 
01612     DefaultFontItem.pFontClass = pClass;
01613     DefaultFontItem.Handle = DEFAULTHANDLE;
01614 
01615     if (!DefaultFontItem.SetCacheData(&TempEnumLogFont))
01616     {
01617         DefaultFontItem.Delete();
01618         return FALSE;
01619     }
01620 
01621     return TRUE;
01622 #else
01623     return TRUE;
01624 #endif
01625 }

WORD FontManager::CacheNamedFont String_64 pFontName,
FontClass  Class = FC_UNDEFINED
 

Given a font name try to cache all the data for that font so that we can actually us it. The cache will be checked first to make sure the font is not already installed.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
pFontName = a pointer to a font name [INPUTS] Class : the class of font to cache FC_UNDEFINED - then try to cache any font by asking each font manager in turn.
- [OUTPUTS]
Returns:
ILLEGALFHANDLE - if unable to cache the named font A unique font handle if cached

Definition at line 1668 of file fontman.cpp.

01669 {
01670     ERROR2IF(pFontName==NULL, ILLEGALFHANDLE, "Bad fontname passed to CacheNamedFont");
01671 
01672     // try to find the font in the cache first
01673     CachedFontItem *pItem = FindFont(pFontName, Class);
01674     if (pItem!=NULL)
01675         return pItem->Handle;
01676     
01677     // now scan all installed lists and set our local temp font data
01678     if (!TempCacheNamedFont(pFontName, Class, 1))
01679     {
01680         // ok we couldn't find the exact font. It may be possible
01681         // to create the font we are after. ATM for instance allows
01682         // named font instances to be created from their base multiple
01683         // master outlines.
01684         TempCacheNamedFont(pFontName, Class, 2);
01685     }
01686     
01687     // add the font that has been returned to us, even if none has.
01688     // if no font has been installed then we will end up having a font cache
01689     // object which describes a font as invalid. This is fine as we now know
01690     // we've done a search for it and it does not exist so we'll use the default
01691     WORD hndle=ILLEGALFHANDLE;
01692     AddTempFont(pFontName, Class, hndle);
01693 
01694     TRACEUSER("wuerthne", _T("FontManager::CacheNamedFont = %d"), hndle);
01695     return (hndle);
01696 }

void FontManager::ClearTempFont  ) 
 

Throws away any font data stored in the temp font.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95

Definition at line 1879 of file fontman.cpp.

01880 {
01881     TempFontClass=FC_UNDEFINED;
01882     TempFontName.Empty();
01883 }

INT32 FontManager::DecodeFontName const String_64 IStringRef,
String_64 OStringRef
 

Given a fontname encoded for EPS files, return the actual font name suitable for font matching and its style definintions (if applicable).

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/4/95
Parameters:
IStringRef the string to decode. [INPUTS]
OStringRef contains the decoded fontname suitable for font matching [OUTPUTS]
Returns:
Flags b0 = 1 then Bold style is enabled b1 = 1 then Italic style is enabled

Definition at line 2253 of file fontman.cpp.

02254 {
02255     String_32 Match;
02256     String_64 Temp;
02257     INT32 pos,Flags;
02258 
02259     OStringRef.Empty();
02260     Flags=0;
02261     Temp=IStringRef;
02262 
02263     Match = _R(IDS_FONTMAN_MINUS_BOLDITALIC); // "-BoldItalic";
02264     pos = Temp.Sub(Match,0,0);
02265     if (pos>-1)
02266     {
02267         Flags |= 3;
02268         Temp.Left(&OStringRef,pos); 
02269         Temp=OStringRef;        
02270     }
02271     
02272     Match = _R(IDS_FONTMAN_MINUS_BOLD); // "-Bold";
02273     pos = Temp.Sub(Match,0,0);
02274     if (pos>-1)
02275     {
02276         Flags |= 1;
02277         Temp.Left(&OStringRef,pos); 
02278         Temp=OStringRef;        
02279     }
02280 
02281     Match = _R(IDS_FONTMAN_MINUS_ITALIC); // "-Italic";
02282     pos = Temp.Sub(Match,0,0);
02283     if (pos>-1)
02284     {
02285         Flags |= 2;
02286         Temp.Left(&OStringRef,pos); 
02287         Temp=OStringRef;        
02288     }
02289 
02290     // Remove the front _ char
02291     Match = _T("_");
02292     if (Temp.Sub(Match,0,0)==0)
02293         Temp.Remove(0,1);
02294 
02295     Temp.SwapChar('-',' ');
02296     OStringRef = Temp;
02297     return Flags;
02298 }

INT32 FontManager::DoesFontExist String_64 pFontName,
BOOL  SearchCache,
BOOL  SearchInstalled
 

First check in the cache if necessary, then through the installed set of fonts to find whether the named font actually exists.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/05/95
Parameters:
FontName : Name of font to find [INPUTS] SearchCache : TRUE then search our internal cached fonts SearchInstalled: TRUE then search through the installed set of fonts too
- [OUTPUTS]
Returns:
0 if the font cannot be found in the specified search areas 1 if the font has been installed 2 if the font has been cached

Definition at line 834 of file fontman.cpp.

00835 {
00836     if (SearchCache)
00837         if (FindFont(pFontName) != NULL)
00838             return 2;
00839 
00840     if (SearchInstalled)
00841         if (IsFontInstalled(pFontName))
00842             return 1;
00843 
00844     return 0;
00845 }

void FontManager::DumpFont WORD  Handle  ) 
 

Dubugging facitity - dumps out the contents of a font from our cache.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95

Definition at line 1862 of file fontman.cpp.

01863 {
01864     CachedFontItem *pItem = FindFont(Handle);
01865     if (pItem)
01866         pItem->Dump();
01867 }   

void FontManager::DumpFontCache  ) 
 

Dubugging facitity - dumps out the contents of our cache.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95

Definition at line 1842 of file fontman.cpp.

01843 {
01844     CachedFontItem *pItem = GetFirstFont();
01845     while (pItem)
01846     {
01847         pItem->Dump();
01848         pItem = GetNextFont(pItem);
01849     }
01850 }   

void FontManager::EncodeAndMapFontName String_64 FontName,
String_64 Encoded,
INT32  Styles
 

This function first calls EncodeFontName, to generate an approximated PostScript font name, before calling a second function to get the PostScript font mapping.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/3/00
Parameters:
FontName - The TrueType font name. [INPUTS] Encoded - A string into which the PostScript font name will be written. Styles - Whether the font is bold, italic, or a combination.
Encoded - Populated with the encoded font name. [OUTPUTS]
Returns:
-

Definition at line 2099 of file fontman.cpp.

02102 {
02103     String_64   Mapped;
02104 
02105     // First encode the font name.
02106     EncodeFontName ( FontName, Encoded, Styles );
02107 
02108     // And then make the mapping.
02109     if ( Camelot.GetPrefDirect ( _T("EPSFontMapping"), ( TCHAR * ) Encoded, &Mapped ) )
02110     {
02111         // There is a PostScript equivalent stored for this font, so use the mapped
02112         // version as the encoded name.
02113         Encoded = Mapped;
02114     }
02115 }

void FontManager::EncodeFontName String_64 FontName,
String_64 Encoded,
INT32  Styles
 

Output a font name with bold and italic flags attached. All spaces are converted to dashes. The font is first checked for the existance of style words bold and italic before new styles are added.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/4/95
Parameters:
FontName A reference to a font name to encode [INPUTS] Encoded 'none constant' string reference to a output string buffer Styles = 1 then try to append 'Bold' = 2 then try to append 'Italic' = 3 then try to append 'BoldItalic'
Encoded contains the string built by this function suitable for output [OUTPUTS] to an Illustrator 3.0, 5.0 format file.
Returns:
-
Notes:

FontNames --------- Encodings: FaceName (Bold) (BoldItalic) GaramondE GaramondE-Bold GaramondE-BoldItalic EuropeExtraBold EuropeExtraBold-Bold EuropeExtraBold-BoldItalic European Bold Oblique European-Bold-Oblique European-Bold-Oblique deGaulleBlack Italic deGualleBlack-BoldItalic deGualleBlack-BoldItalic

Definition at line 1995 of file fontman.cpp.

01996 {
01997     String_64 Copy(FontName);
01998     String_32 Match;
01999     
02000     // Replace all spaces with a hyphen.
02001     Copy.SwapChar(_T(' '),_T('-'));
02002 
02003     INT32 Length = Copy.Length();
02004 
02005     // Find the last hyphen in the font's name.
02006     INT32 LastHyphen = Copy.ReverseFind ( '-' );
02007 
02008     // If there is a -XX extension to the name, remove the hyphen.
02009     if ( LastHyphen == Length - 3 )
02010     {
02011         Copy.Remove ( LastHyphen, 1 );
02012     }
02013 
02014     // Check for bold/italic.
02015     Match = _R(IDS_FONTMAN_MINUS_BOLD); //"-Bold";
02016     INT32 Bld = (Copy.Sub(Match,0,0));
02017 
02018     Match = _R(IDS_FONTMAN_MINUS_ITALIC); //"-Italic";
02019     INT32 Ital = (Copy.Sub(Match,0,0));
02020 
02021     switch (Styles)
02022     {
02023         case 1:
02024         {
02025             if (Bld<0 && Ital<0)
02026             {
02027                 Copy += String_16(_R(IDS_FONTMAN_MINUS_BOLD)); // "-Bold";
02028                 break;
02029             }
02030 
02031             if( ( Bld < 0 ) && ( Ital > -1 ) && ( Length - 7 == Ital ) )
02032             {
02033                 Copy.Insert( String_32(_R(IDS_FONTMAN_BOLD)), Ital );
02034             }
02035             break;
02036         }
02037 
02038         case 2: 
02039         {   
02040             if (Bld<0 && Ital<0)
02041             {
02042                 Copy += String_16(_R(IDS_FONTMAN_MINUS_ITALIC)); // "-Italic";
02043                 break;
02044             }
02045             
02046             if ((Ital<0) && (Bld>-1) && (Length-5==Bld))
02047                 Copy += String_16(_R(IDS_FONTMAN_ITALIC)); //"Italic";
02048             break;
02049         }
02050 
02051         case 3:
02052         {   
02053             if (Bld<0 && Ital<0)
02054             {
02055                 Copy += String_16(_R(IDS_FONTMAN_MINUS_BOLDITALIC)); // "-BoldItalic";
02056                 break;
02057             }
02058 
02059             // If the font contains the word bold at the end, append italic
02060             if( ( Ital < 0 ) && ( Bld > -1 ) && ( Length - 5 == Bld ) )
02061             {
02062                 Copy += String_16(_R(IDS_FONTMAN_ITALIC)); //"Italic";
02063                 break;
02064             }
02065                                     
02066             // If the font already has italic, insert Bold
02067             if( ( Bld < 0 ) && ( Ital > -1 ) && ( Length - 7 == Ital ) )
02068             {
02069                 Copy.Insert( String_32(_R(IDS_FONTMAN_BOLD)), Ital );
02070             }
02071             break;
02072 
02073         }
02074     }
02075 
02076     // Set the encoded output string
02077     Encoded=Copy;
02078 }

WORD FontManager::FindClosestFont const CCPanose PanoseNumber  ) 
 

Performs panose matching on the installed fonts.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/08/96
Parameters:
PanoseNumber - panose number to search against [INPUTS]
Returns:
Font handle of the closest font

Definition at line 1309 of file fontman.cpp.

01310 {
01311     // check, is this a 'simple' panose number with just Weight and Letterform components?
01312     if (PanoseNumber.GetFamilyType()==PAN_ANY &&
01313         PanoseNumber.GetSerifStyle()==PAN_ANY &&
01314         PanoseNumber.GetProportion()==PAN_ANY &&
01315         PanoseNumber.GetContrast()==PAN_ANY &&
01316         PanoseNumber.GetStrokeVariation()==PAN_ANY &&
01317         PanoseNumber.GetArmStyle()==PAN_ANY &&
01318         PanoseNumber.GetMidline()==PAN_ANY &&
01319         PanoseNumber.GetXHeight()==PAN_ANY)
01320     {
01321         // These 'simple' panose numbers get saved out for old files and ATM fonts. Obviously
01322         // we can't do any sensible font matching, so just return the default font handle.
01323         return DEFAULTHANDLE;
01324     }
01325     else
01326     {
01327         // shove the data we need into class members.
01328         FindClosestFontHandle = ILLEGALFHANDLE;
01329         FindClosestPanoseNumber = PanoseNumber;
01330         FindClosestDistance = 0xffffffff;
01331         FindClosestTypeFaceName = _T("");
01332         FindClosestFontClass = FC_UNDEFINED;
01333 
01334         // normalise the panose number.
01335         FindClosestPanoseNumber.BodgeToNormal();
01336 
01337         // choose whichever panose font matching algorithm you require:
01338 PORTNOTE("text","TrueType/Win specific code removed")
01339 #ifndef EXCLUDE_FROM_XARALX
01340         // quick - just checks the seven fonts from the Microsoft(tm) Web Font Pack(tm)
01341         return FindClosestFontQuick(PanoseNumber);
01342 #endif
01343 
01344         // full - checks all the fonts installed on the machine.
01345         return FindClosestFontFull(PanoseNumber);
01346     }
01347 } 

WORD FontManager::FindClosestFontFull const CCPanose PanoseNumber  )  [private]
 

Definition at line 1418 of file fontman.cpp.

01419 {
01420     WORD MyFontHandle;
01421     CachedFontItem *pCachedFontItem;
01422 
01423     // this is particularly rubbish code, since we ask the OS for information about each font
01424     // (the OUTLINETEXTMETRIC structure) and then throw it away if its not needed, rather than
01425     // caching it for the next time. Of course, if this font manager actually held information
01426     // about all the fonts on the system, rather than those in use, it would all be much easier.
01427 
01428     // call the OILFontMan to find the closest font.
01429     OILFontMan::FindClosestFont();
01430 
01431     // We've got the typeface name and font class of the best match, so get the font handle
01432     pCachedFontItem = FindFont(&FindClosestTypeFaceName, FindClosestFontClass);
01433 
01434     if (pCachedFontItem!=NULL)
01435     {
01436         // the font is already cached, so grab the font handle from the CachedFontItem
01437         MyFontHandle=pCachedFontItem->Handle;
01438     }
01439     else
01440     {
01441         // the font hasn't been cached yet, so cache it now.
01442         pCachedFontItem = AddFont(&FindClosestTypeFaceName, FindClosestFontClass, MyFontHandle);
01443         pCachedFontItem->SetCacheData(&FindClosestEnumLogFont);
01444     }
01445 
01446     // return with this font handle
01447     return MyFontHandle;
01448 }

BOOL FontManager::FindClosestFontFullTry FontClass  Class,
String_64 pTypeFaceName,
ENUMLOGFONT pEnumLogFont
 

Definition at line 1450 of file fontman.cpp.

01451 {
01452     ERROR2IF(pEnumLogFont==NULL, FALSE, "FindClosestTry called with pEnumLogFont==NULL.");
01453 
01454     OUTLINETEXTMETRIC *pOutlineTextMetric;
01455     CCPanose MyPanoseNumber;
01456     UINT32 MyDistance;
01457 
01458     pOutlineTextMetric = OILFontMan::GetOutlineTextMetric(Class, &(pEnumLogFont->elfLogFont));
01459 
01460     if (pOutlineTextMetric!=NULL)
01461     {
01462         MyPanoseNumber = (pOutlineTextMetric->otmPanoseNumber);
01463         MyPanoseNumber.BodgeToNormal();
01464 
01465         MyDistance = CCPanose::Distance(FindClosestPanoseNumber, MyPanoseNumber);
01466 
01467         if (MyDistance<FindClosestDistance)
01468         {
01469             FindClosestDistance = MyDistance;
01470             FindClosestFontClass = Class;
01471             FindClosestTypeFaceName = *(pTypeFaceName);
01472             FindClosestEnumLogFont = *(pEnumLogFont);
01473         }
01474 
01475         free(pOutlineTextMetric);
01476     }
01477     
01478     return TRUE;
01479 }

WORD FontManager::FindClosestFontQuick const CCPanose PanoseNumber  )  [private]
 

Definition at line 1351 of file fontman.cpp.

01352 {
01353     WORD MyFontHandle;
01354     String_64 MyFontName;
01355 
01356     // try "Arial"
01357     MyFontName = _T("Arial");
01358     MyFontHandle = CacheNamedFont(&MyFontName, FC_TRUETYPE);
01359     FindClosestFontQuickTry(MyFontHandle);
01360 
01361     // try "Arial Black"
01362     MyFontName = _T("Arial Black");
01363     MyFontHandle = CacheNamedFont(&MyFontName, FC_TRUETYPE);
01364     FindClosestFontQuickTry(MyFontHandle);
01365 
01366     // try "Comic Sans"
01367     MyFontName = _T("Comic Sans");
01368     MyFontHandle = CacheNamedFont(&MyFontName, FC_TRUETYPE);
01369     FindClosestFontQuickTry(MyFontHandle);
01370 
01371     // try "Courier New"
01372     MyFontName = _T("Courier New");
01373     MyFontHandle = CacheNamedFont(&MyFontName, FC_TRUETYPE);
01374     FindClosestFontQuickTry(MyFontHandle);
01375 
01376     // try "Impact"
01377     MyFontName = _T("Impact");
01378     MyFontHandle = CacheNamedFont(&MyFontName, FC_TRUETYPE);
01379     FindClosestFontQuickTry(MyFontHandle);
01380 
01381     // try "Times New Roman"
01382     MyFontName = _T("Times New Roman");
01383     MyFontHandle = CacheNamedFont(&MyFontName, FC_TRUETYPE);
01384     FindClosestFontQuickTry(MyFontHandle);
01385 
01386     // try "Verdana"
01387     MyFontName = _T("Verdana");
01388     MyFontHandle = CacheNamedFont(&MyFontName, FC_TRUETYPE);
01389     FindClosestFontQuickTry(MyFontHandle);
01390 
01391     return FindClosestFontHandle;
01392 } 

BOOL FontManager::FindClosestFontQuickTry WORD  FontHandle  )  [private]
 

Definition at line 1395 of file fontman.cpp.

01396 {
01397     OUTLINETEXTMETRIC *pOutlineTextMetric = GetOutlineTextMetric(MyFontHandle);
01398 
01399     if (pOutlineTextMetric!=NULL)
01400     {
01401         CCPanose MyPanoseNumber = pOutlineTextMetric->otmPanoseNumber;
01402 
01403         MyPanoseNumber.BodgeToNormal();
01404 
01405         UINT32 MyDistance = CCPanose::Distance(FindClosestPanoseNumber, MyPanoseNumber);
01406 
01407         if (MyDistance<FindClosestDistance)
01408         {
01409             FindClosestFontHandle = MyFontHandle;
01410             FindClosestDistance = MyDistance;
01411         }
01412     }
01413 
01414     return TRUE;
01415 }

CachedFontItem * FontManager::FindFont String_64 pFontName,
FontClass  Class = FC_UNDEFINED
[private]
 

Find the entry in the font managers font list which corresponds to this fontname and font class Note: One might be tempted to include the default font item in the comparison and return the default font handle when the default font name is passed, but this does not happen and this is by design. See OnDocumentLoaded for further information.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
pFontName = a pointer to a font name [INPUTS] Class = describes the type of class (see typedef for details) FC_UNDEFINED then ignore the class match and match the first item with the same name whatever font class it is
- [OUTPUTS]
Returns:
A pointer to the font managers cached font record for this font NULL if unable to find the font

Definition at line 670 of file fontman.cpp.

00671 {
00672     CachedFontItem* pItem = GetFirstFont();
00673 
00674     if (Class==FC_UNDEFINED)
00675     {
00676         while (pItem!=NULL)
00677         {
00678             if (pItem->Compare(pFontName))
00679                 return pItem;
00680             pItem = GetNextFont(pItem); 
00681         }
00682     }
00683     else
00684     {
00685         while (pItem!=NULL)
00686         {
00687             if (pItem->Compare(pFontName))
00688             {
00689                 if (pItem->GetFontClass() == Class)
00690                     return pItem;
00691             }
00692             pItem = GetNextFont(pItem); 
00693         }
00694     }
00695     return NULL;
00696 }

CachedFontItem * FontManager::FindFont WORD  Handle  )  [private]
 

Find the entry in the font managers font cache which corresponds to this handle.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
A pointer to the font managers cached font record for this handle

Definition at line 635 of file fontman.cpp.

00636 {
00637     // Check the cache first
00638     CachedFontItem* pItem = GetFirstFont();
00639     while (pItem!=NULL)
00640     {
00641         if (pItem->Handle == Handle)
00642             return pItem;
00643         pItem = GetNextFont(pItem);
00644     }
00645     return NULL;
00646 }

WORD FontManager::FindTypeface String_64 TypeFaceName,
FontClass  Class
 

Used by the new file format, to check if a particular typeface (and font class) is installed and available. See Also: class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/08/96
Parameters:
TypeFaceName - Typeface name of font to search for [INPUTS] Class - font class to search for
Returns:
Font handle of typeface, or ILLEGALFHANDLE if not found

Definition at line 1265 of file fontman.cpp.

01266 {
01267     WORD FontHandle = ILLEGALFHANDLE;
01268 
01269     CachedFontItem *pItem=FindFont(&TypeFaceName, Class);
01270 
01271     if (pItem!=NULL)
01272     {
01273         // font is in the cached font list.
01274         FontHandle=pItem->Handle;
01275     }
01276     // now scan the installed lists for this font, and set the local temp font data
01277     else if (TempCacheNamedFont(&TypeFaceName, Class, 1))
01278     {
01279         AddTempFont(&TypeFaceName, Class, FontHandle);
01280     }
01281     // Okay, so we couldn't find the exact font. It may be possible to create the
01282     // font we are after. ATM for instance allows named font instances to be created
01283     // from the base multiple master outlines.
01284     else if (TempCacheNamedFont(&TypeFaceName, Class, 2))
01285     {
01286         AddTempFont(&TypeFaceName, Class, FontHandle);
01287     }
01288     else
01289     // completly unsuccessful. :(
01290     {
01291         FontHandle=ILLEGALFHANDLE;
01292     }
01293 
01294     return FontHandle;
01295 }

CachedFontItem * FontManager::GetCachedFont WORD  Handle  ) 
 

This function returns the font associated with the handle passed. If the font is not in the cache it will return NULL. It differs from GetFont in that it will not attempt to return the DefaultFontItem if it cannot find the item specified.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
A pointer to a cached font record or NULL

Definition at line 714 of file fontman.cpp.

00715 {
00716     if (Handle==DefaultHandle) return (&DefaultFontItem);
00717     return FindFont(Handle);
00718 }

BOOL FontManager::GetCharMetrics CNativeDC pDC,
WCHAR  ch,
CharDescription FontDesc,
CharMetrics pCharMetrics
 

Get the char metrics for the given char and font Just dispenses the call to the FontMetricsCache.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/1/96
Parameters:
pDC - pointer to DC (rather than creating one each time) [INPUTS] ch - the char whose metrics are required FontDesc - the font
pCharMetrics - the metrics [OUTPUTS]
Returns:
FALSE if fails

Definition at line 1508 of file fontman.cpp.

01509 {
01510     return OILFontMan::GetCharMetrics(pDC, ch, FontDesc, pCharMetrics);
01511 }

BOOL FontManager::GetCharPath CharDescription ChDesc,
DocCoord **  ppCoords,
PathVerb **  ppVerbs,
UINT32 pNumCoords,
CNativeDC pDC = NULL
 

Get the path associated with a given char.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/9/95
Parameters:
ChDesc = description of char [INPUTS] pDC = (possible) pointer to a DC (for optimisation) defaults to NULL
ppCoords = pointer to path coords buffer [OUTPUTS] ppVerbs = pointer to path verbs buffer pNumCoords = number of elements in path
Returns:
FALSE if unable to return the outline

Definition at line 1552 of file fontman.cpp.

01557 {
01558     ERROR2IF(ppCoords==NULL,FALSE,"FontManager::GetCharPath pCoords==NULL");
01559     ERROR2IF(ppVerbs==NULL,FALSE,"FontManager::GetCharPath ppVerbs==NULL");
01560     ERROR2IF(pNumCoords==NULL,FALSE,"FontManager::GetCharPath pNumCoords==NULL");
01561 
01562     CachedFontItem* pItem = GetFont(ChDesc.GetTypefaceHandle());
01563     if (pItem==NULL)
01564         return FALSE;
01565 
01566     if (pItem->IsCorrupt())
01567         return FALSE;
01568 
01569     BOOL Success = OILFontMan::GetCharPath(pItem->GetFontClass(), ChDesc, ppCoords, ppVerbs, pNumCoords, pDC);
01570     if (!Success)
01571         pItem->SetIsCorrupt(TRUE);
01572 
01573     return Success;
01574 }

MILLIPOINT FontManager::GetCharsKerning CNativeDC pDC,
WCHAR  chLeft,
WCHAR  chRight,
CharDescription FontDesc
 

Finds the kerning distance between two chars.

Author:
Jonathan_Payne (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/10/2000
Parameters:
pDC - pointer to DC (rather than creating one each time) [INPUTS] chLeft - the left char of a kerning pair chRight - the right char of a kerning pair FontDesc - the font
Returns:
Kern distance between chars or 0 on error or no kern

Definition at line 1526 of file fontman.cpp.

01527 {
01528     // TRACEUSER("wuerthne", _T("FontManager::GetCharsKerning called\n") );
01529     return OILFontMan::GetCharsKerning(pDC, chLeft, chRight, FontDesc);
01530 }

void FontManager::GetCompatibleFont const String_64 EncodedName,
String_64 CompatibleFont,
INT32 &  Style
 

Find a compatible font to that specified in the encoded font name. An encoded name looks something like....

void FontManager::GetCompatibleFont(const String_64& EncodedName, String_64& CompatibleFont, INT32& Style)

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/4/95
Parameters:
EncodedName the encoded font name to find a compatible font for. [INPUTS] encoded names are those read direct from the native file.
CompatibleFont contains the decoded fontname suitable for font matching [OUTPUTS] Style b0 = 1 then Bold style should be enabled b1 = 1 then Italic style should be enabled
Returns:
Times-New-Roman Times-New-Roman-Bold Times-New-Roman-Italic Times-New-Roman-BoldItalic ChiversCond-Bold-Oblique

The algorithm used is based on diminishing returns, ie try to find the exact font first, then break the fontname up in various increasingly complex ways until a valid substitution is found. This substitution can then be used for font caching. Note if the fontmanager fails to find any match it will return the encodedname as a last resort. When this is cached, its metrics will be NULL and hence be replaced by the default font automatically be the font manager.

extras: This function tries to use the font name as specified. If it does not exist the function will attempt to use the fontname without styles and create styles to fit but only if this new fontname exists. ie it will do the following

FontName Styles NameExists StylesOutput (1) Times New Roman BoldItalic Yes BoldOff / ItalicOff (2) Times New Roman Bold/Italic Yes BoldOn / ItalicOn (3) Times New Roman BoldItalic No BoldOn / ItalicOn

Returns:
Errors:

Definition at line 2163 of file fontman.cpp.

02164 {
02165     // first make a copy of the encoded name
02166     String_64 TryFont(EncodedName);
02167     
02168     // now set the return style
02169     Style=0;
02170 
02171     // Usually the fontnames in the file are saved as /_FontName.Attr-BoldItalic format
02172     if( TryFont.Sub( String_32( _T("_") ),0 ,0 ) == 0 )
02173         TryFont.Remove(0,1);
02174 
02175     // remove our inserted - symbols which are encoded as separators on saving
02176     TryFont.SwapChar('-',' ');
02177 
02178     // Try to find the specified font name, search internal and external caches
02179     INT32 found = DoesFontExist(&TryFont,TRUE,TRUE);
02180     if (found>0)
02181     {
02182         CompatibleFont=TryFont;
02183         return;
02184     }
02185 
02186     // Ok, if we can't find the whole thing, try decoding
02187     String_64 DecodedName;
02188     Style = DecodeFontName(EncodedName, DecodedName);
02189 
02190     // find out what styles this font has
02191     BOOL Bold,Italic;
02192     Bold=((Style & 1) != 0);
02193     Italic=((Style & 2) != 0);
02194 
02195     // if both bold and italic found
02196     if (Bold && Italic)
02197     {
02198         String_64 HoldName(TryFont);
02199         // try to find bold first
02200         INT32 pos = HoldName.Sub( String_32( _T("Italic") ), 0, 0 );
02201         HoldName.Remove(pos,6);
02202         found = DoesFontExist(&HoldName,TRUE,TRUE);
02203         if (found>0)
02204         {
02205             CompatibleFont=HoldName;
02206             return;
02207         }       
02208 
02209         // Then try Italic
02210         HoldName=TryFont;
02211         pos = HoldName.Sub( String_32( _T("Bold") ), 0, 0 );
02212         HoldName.Remove(pos,4);
02213         found = DoesFontExist(&HoldName,TRUE,TRUE);
02214         if (found>0)
02215         {
02216             CompatibleFont=HoldName;
02217             return;
02218         }       
02219     }
02220 
02221     // Does the decoded name exist?, so we can make the rest up in styles?
02222     found = DoesFontExist(&DecodedName,TRUE,TRUE);
02223     if (found>0)
02224     {
02225         CompatibleFont=DecodedName;
02226         return;
02227     }
02228         
02229     // otherwise, we have a font with an extension, eg Trinity.Bold
02230     // (1) Trinity.Bold   - does not exist
02231     // (2) Trinity        - does not exist
02232     // now we set the font to (1), which will be replaced by Times-Roman.
02233     // Now we should also set the font styles too to give us TimesRoman bold
02234 
02235     CompatibleFont=TryFont;
02236 }

ENUMLOGFONT * FontManager::GetEnumLogFont WORD  Handle  ) 
 

Return the ENUMLOGFONT structure for this font handle. Note the function will automatically substitute the default font if the handle provided is invalid or the font it describes is not fully cached.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
A pointer to the ENUMLOGFONT structure for this font NULL if none

Definition at line 1144 of file fontman.cpp.

01145 {
01146     // ok, we need to get the font data for this particular font item   
01147     CachedFontItem *pItem = GetFont(Handle);
01148     if (pItem!=NULL)
01149     {
01150         return (pItem->GetEnumLogFont());
01151     }
01152     else
01153     {
01154         return NULL;
01155     }
01156 }

CachedFontItem * FontManager::GetFirstFont  ) 
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Returns:
A pointer to the first cached font item (NULL if none)

Definition at line 555 of file fontman.cpp.

00556 {
00557     return (CachedFontItem*)TheFontList.GetHead();
00558 }

CachedFontItem * FontManager::GetFirstFontType FontClass  Class  )  [private]
 

Find the entry in the font managers font list which corresponds to the first 'FontClass' font cached.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Class = the class of font to retrieve [INPUTS]
- [OUTPUTS]
Returns:
A pointer to a cached font record or NULL

Definition at line 1116 of file fontman.cpp.

01117 {
01118     CachedFontItem* pItem = GetFirstFont();
01119     while (pItem!=NULL)
01120     {
01121         if (pItem->GetFontClass() == Class)
01122             return pItem;
01123         pItem = GetNextFont(pItem);
01124     }
01125     return NULL;
01126 }

CachedFontItem * FontManager::GetFont String_64 pFontName,
FontClass  Class = FC_UNDEFINED
 

Return the font data to use for rendering. This function performs a specific job in avoiding caching the font data. If the font is already cached then fine, it is returned for use. If not, the default font is returned.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
pFontName = a pointer to a font name [INPUTS] Class = describes the type of class (see typedef for details) FC_UNDEFINED then ignore the class match and match the first item with the same name whatever font class it is
- [OUTPUTS]
Returns:
A pointer to a cached font record or NULL

Definition at line 806 of file fontman.cpp.

00807 {
00808     CachedFontItem* pItem = FindFont(pFontName, Class);
00809     if ((pItem!=NULL) && (pItem->IsFullyCached()))
00810         return pItem;
00811     return &DefaultFontItem;
00812 }

CachedFontItem * FontManager::GetFont WORD  Handle  ) 
 

Return the font data to use for rendering. This function performs a specific job in avoiding caching the font data. If the font is already cached then fine, it is returned for use. If not, the default font is returned.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
A pointer to a cached font record or NULL

Definition at line 780 of file fontman.cpp.

00781 {
00782     CachedFontItem* pItem = FindFont(Handle);
00783     if ((pItem!=NULL) && (pItem->IsFullyCached()))
00784         return pItem;
00785     return &DefaultFontItem;
00786 }

CachedFontItem * FontManager::GetFont  ) 
 

Return the precached default font data to use for rendering.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
A pointer to a cached font record or NULL

Definition at line 760 of file fontman.cpp.

00761 {
00762     return &DefaultFontItem;
00763 }

FontClass FontManager::GetFontClass WORD  Handle  ) 
 

Return what class of font this handle is.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
A font class FC_UNDEFINED if the handle is unknown

Definition at line 1238 of file fontman.cpp.

01239 {
01240     CachedFontItem* pItem = GetCachedFont(Handle);
01241     if (pItem==NULL)
01242     {
01243         ERROR3("FontManager::GetFontClass() - given an illegal handle");
01244         return FC_UNDEFINED;
01245     }
01246     return pItem->GetFontClass();
01247 }

WORD FontManager::GetFontHandle String_64 pFontName,
FontClass  Class = FC_UNDEFINED
 

Get the handle on a cached font (if cached) otherwise return the default font handle.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
pFontName = a pointer to a font name [INPUTS] Class = describes the class of font to get the handle of
- [OUTPUTS]
Returns:
The handle of the font if the font exists The default handle if the font does not exist and Replace is true ILLEGALFHANDLE if not

Definition at line 737 of file fontman.cpp.

00738 {
00739     ERROR2IF(pFontName==NULL, 0, "FontManager::GetFontHandle() called with an illegal font name pointer");
00740     CachedFontItem* pItem=FindFont(pFontName,Class);
00741     if (pItem!=NULL)
00742         return pItem->GetFontHandle();
00743     
00744     return DefaultHandle;
00745 }

BOOL FontManager::GetFontName WORD  Handle,
String_64 OutputString
 

Definition at line 1212 of file fontman.cpp.

01213 {
01214     CachedFontItem* pItem = GetCachedFont(Handle);
01215     if (pItem==NULL)
01216     {
01217         ERROR3("FontManager::GetFontName() - given an illegal handle");
01218         return FALSE;
01219     }
01220     OutputString = *(pItem->GetFontName());
01221     return TRUE;
01222 }

String_64 * FontManager::GetFontName WORD  Handle  ) 
 

Return a pointer to the font name given its font handle.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
A pointer to the font name associated with this handle NULL if the handle is illegal

Definition at line 1200 of file fontman.cpp.

01201 {
01202     CachedFontItem* pItem = GetCachedFont(Handle);
01203     if (pItem==NULL)
01204     {
01205         ERROR3("FontManager::GetFontName() - given an illegal handle");
01206         return NULL;
01207     }
01208     return pItem->GetFontName();
01209 }

CachedFontItem * FontManager::GetNextFont CachedFontItem pItem  ) 
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
A pointer to a font item to find the next from. [INPUTS]
Returns:
A pointer to the next cached font item from pItem (NULL if none)

Definition at line 572 of file fontman.cpp.

00573 {
00574     return (CachedFontItem*)TheFontList.GetNext(pItem);
00575 }

WORD FontManager::GetNextHandle  )  [private]
 

Return a unique handle for the font cache handler Handles range from 1..n, 0 is explicitly reserved for the default handle, 0x7FFF is defined as an illegal handle.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
The next font handle. [OUTPUTS]
Returns:
-

Definition at line 509 of file fontman.cpp.

00510 {
00511     WORD CurrHandle=UniqueHandle;
00512     UniqueHandle++;
00513     return (CurrHandle);
00514 }

OUTLINETEXTMETRIC * FontManager::GetOutlineTextMetric WORD  Handle  ) 
 

Return the ENUMLOGFONT structure for this font handle Note the function will automatically substitute the default font if the handle provided is invalid or the font it describes is not fully cached.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/08/96
Parameters:
Handle = the font manager handle [INPUTS]
Returns:
Pointer to the OUTLINETEXTMETRIC structure for this font, NULL if none

Definition at line 1172 of file fontman.cpp.

01173 {
01174     // ok, we need to get the font data for this particular font item
01175     CachedFontItem *pItem = GetFont(Handle);
01176     if (pItem!=NULL)
01177     {
01178         return pItem->GetOutlineTextMetric();
01179     }
01180     else
01181     {
01182         return NULL;
01183     }
01184 }

BOOL FontManager::Init void   ) 
 

Get Camelots Font manager going. We simply cache the default font so unknown fonts can be sensibly replaced.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/09/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the fontmanager was able to initialise correctly FALSE if not

Reimplemented from SimpleCCObject.

Definition at line 531 of file fontman.cpp.

00532 {
00533     // initialise the OIL cache of enumerated fonts by simply enumerating them
00534     // and ignoring the result - since we do not want to see the names, we do
00535     // not even have to create a subclass
00536     OILEnumFonts enumerator;
00537     enumerator.Execute();
00538     if (!CacheDefaultFont())    
00539     {
00540         ERROR3("FontManager::Init() - Unable to cache the default font");
00541     }
00542     return TRUE;
00543 }

void FontManager::InvalidateCache void   )  [private]
 

Scans all the cached fonts deletes all cached data. If the entries are not recached all visible fonts will be replaced by the default font.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/9/95

Definition at line 1820 of file fontman.cpp.

01821 {
01822     CachedFontItem *pItem = GetFirstFont();
01823     while (pItem)
01824     {
01825         pItem->DeleteMetrics();
01826         pItem->SetIsCorrupt(FALSE);
01827         pItem->SetIsReplaced(TRUE);
01828         pItem = GetNextFont(pItem);
01829     }
01830 }

void FontManager::InvalidateCharMetrics  ) 
 

Invalidate char metrics cache.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/1/96

Definition at line 1489 of file fontman.cpp.

01490 {
01491     OILFontMan::InvalidateCharMetrics();
01492 }

BOOL FontManager::IsFontDefault CachedFontItem pItem  ) 
 

Definition at line 967 of file fontman.cpp.

00968 {
00969     return (pItem == (&DefaultFontItem));
00970 }

BOOL FontManager::IsFontDefault WORD  Handle  ) 
 

Check to see if the font handle described is the handle of the default font ie the font which is used to replace unknown fonts (fonts not resident on the host machine).

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the font handle is the handle describing the default font FALSE if not.

Definition at line 962 of file fontman.cpp.

00963 {
00964     return (Handle==DefaultHandle);
00965 }

BOOL FontManager::IsFontInstalled String_64 pFontName,
FontClass  Class = FC_UNDEFINED
 

Search through all the installed sets of fonts for the named font.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/05/95
Parameters:
pFontName : Name of font to search for [INPUTS] Class : The class of font to cache FC_UNDEFINED - then try to cache any font
- [OUTPUTS]
Returns:
TRUE if the font has been installed

Definition at line 1736 of file fontman.cpp.

01737 {
01738     return TempCacheNamedFont(pFontName, Class);
01739 }

BOOL FontManager::IsFontReplaced String_64 pFontName,
FontClass  Class = FC_UNDEFINED
 

Definition at line 916 of file fontman.cpp.

00917 {
00918     BOOL Result = FALSE;
00919 
00920     // Check whether its the default font, if it is then obviously it's not been replaced.
00921     if (DefaultFontItem.Compare(pFontName))
00922     {
00923         Result = FALSE;
00924     }
00925     else
00926     {
00927         CachedFontItem *pItem = FindFont(pFontName, Class);
00928 
00929         if (pItem==NULL)
00930         {
00931             Result = TRUE;      // font doesn't exist
00932         }
00933         else if (pItem->IsReplaced())
00934         {
00935             Result = TRUE;      // IsReplaced flag is set
00936         }
00937         else if (!pItem->IsValid())
00938         {
00939             Result = TRUE;      // The font isn't valid
00940         }
00941     }
00942 
00943     return Result;
00944 }

BOOL FontManager::IsFontReplaced WORD  FontHandle  ) 
 

Check to see if the font described has been replaced.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
pFontName = a pointer to a font name [INPUTS] Class = describes the type of class (see typedef for details) FC_UNDEFINED then ignore the class match and match the first item with the same name whatever font class it is
- [OUTPUTS]
Returns:
TRUE if the font has been replaced by the default FALSE if not.

Definition at line 886 of file fontman.cpp.

00887 {
00888     BOOL Result = FALSE;
00889 
00890     // check whether its the default font, if it is then obviously it's not been replaced.
00891     if (IsFontDefault(FontHandle))
00892     {
00893         Result = FALSE;
00894     }
00895     else
00896     {
00897         CachedFontItem *pItem = FindFont(FontHandle);
00898 
00899         if (pItem==NULL)
00900         {
00901             Result = TRUE;      // font doesn't exist
00902         }
00903         else if (pItem->IsReplaced())
00904         {
00905             Result = TRUE;      // IsReplaced flag is set
00906         }
00907         else if (!pItem->IsValid())
00908         {
00909             Result = TRUE;      // The font isn't valid
00910         }
00911     }
00912 
00913     return Result;
00914 }

BOOL FontManager::IsFontUsedInDoc WORD  Handle,
Document pDocument
 

Find out whether a given font is used in a document.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
01/08/06
Parameters:
Handle - a font handle [INPUTS] pDocument - pointer to a document
Returns:
When called with Handle == DEFAULTHANDLE it returns TRUE if the default attribute applies to a text object. Otherwise, it returns TRUE if the supplied font handle is used in the document

Definition at line 1023 of file fontman.cpp.

01024 {
01025     Node* pNode = pDocument->GetFirstNode();
01026     return IsFontUsedInSiblings(pNode, Handle, ILLEGALFHANDLE, 0);
01027 }

BOOL FontManager::IsFontUsedInSiblings Node pNode,
WORD  Handle,
WORD  CurrentHandle,
UINT32  Level
[private]
 

Find out whether a given font is used in a document.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
01/08/06
Parameters:
pNode - the root node of the subtree to check [INPUTS] Handle - a font handle CurrentHandle - the font handle applying to the current subtree Level - level in the tree (level 0 is NodeDocument, level 1 are default attributes)
Returns:
Returns TRUE if a font attribute with the given handle applies to a text object.

Definition at line 988 of file fontman.cpp.

00989 {
00990     // perform a standard child-first recursion keeping track of the current font
00991     while(pNode)
00992     {
00993         Node* pFirstChild = pNode->FindFirstChild();
00994         if (pFirstChild && IsFontUsedInSiblings(pFirstChild, Handle, CurrentHandle, Level + 1)) return TRUE;
00995         if (IS_A(pNode, AttrTxtFontTypeface))
00996         {
00997             AttrTxtFontTypeface* pAttr = (AttrTxtFontTypeface*)pNode;
00998             CurrentHandle = pAttr->Value.HTypeface;
00999             ENSURE(!(CurrentHandle == DEFAULTHANDLE && Level > 1), "FontManager::IsFontUsedInSiblings is based on the assumption that we do not have non-default attribute nodes referencing the default font");
01000         }
01001         if (CurrentHandle == Handle && (IS_A(pNode, TextStory) || IS_A(pNode, TextLine) || IS_A(pNode, TextChar)))
01002             return TRUE;
01003         pNode = pNode->FindNext();
01004     }
01005     return FALSE;
01006 }

BOOL FontManager::IsFontValid WORD  Handle  ) 
 

Check to see if the font described is actually valid, ie all the metrics for the font have been cached correctly.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the font is valid and ready to use FALSE if not.

Definition at line 862 of file fontman.cpp.

00863 {
00864     CachedFontItem* pItem = GetCachedFont(Handle);
00865     return ( (pItem!=NULL) && (pItem->IsFullyCached()) );
00866 }

BOOL FontManager::IsFullyCached WORD  Handle  )  [private]
 

Find out if the font is fully cached and ready to use. This will generally be true of all fonts added by CacheNamedFont. If the font is not fully cached then call CacheFontData(). It will not be if AddFont has been used to add the font to the font list.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
Handle = The font manager font handle [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the font exists and is cached FALSE if not

Definition at line 1758 of file fontman.cpp.

01759 {
01760     CachedFontItem* pItem = GetCachedFont(Handle);
01761     if (pItem!=NULL)
01762         return pItem->IsFullyCached();
01763     return FALSE;
01764 }

BOOL FontManager::LegalFontClass INT32  Class,
FontClass RealClass
 

Check whether a numeric value actually indicates a valid class of font ie lies in the range of supported font types. This is used generally for loading purpose where the font class is loaded as a numeric value.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/09/95
Parameters:
A INT32 describing the font class [INPUTS]
The real font class to use for this numeric value [OUTPUTS]
Returns:
TRUE if the font class is supported, FALSE if not

Definition at line 488 of file fontman.cpp.

00489 {
00490     return OILFontMan::LegalFontClass(Class, RealClass);
00491 }

void FontManager::OnDocumentLoaded Document pDocument  ) 
 

Called after a document has been loaded - allows us to fix the current and default fonts if they are not installed. They are only changed if they are not used in the document.

Author:
Martin Wuerthner <xara@mw-software.com>
Date:
01/08/06
Parameters:
pDocument - pointer to the newly created/loaded document [INPUTS]
Fixing the current font is useful because it stops "Arial (missing)" from being displayed after start-up if Arial is not installed. The same happens when loading a document with the current font set to Arial (or any other font that is not installed). We do not touch the current font if it is actually used in the document because then, it is possible that it was set deliberately (maybe even in a template).

One might consider a similar approach for the default font, but by definition, the default font is always installed (though it may or may not be Times New Roman), so there is no need to change anything. The default attributes are not saved with the document, so, in contrast to the current font, there cannot be any surprises with fonts that are not installed. The font name referenced by the default font does not matter because the default font attribute is never inherited by any text object in the document.

This is down to the behaviour of FindFont(String_64*,FontClass), which never returns the default font handle, so any font attribute created by the text tool based on a font name (which involves calling FindFont at some stage) is always different from the default attribute (even if it happens to be the same font as the default font) and hence this attribute is not optimised away. Therefore, each and every text object has a non-default font attribute applied to it.

Definition at line 1064 of file fontman.cpp.

01065 {
01066     // check if the current font is installed and change it in case it is not (only if the font is not used)
01067     NodeAttribute* pAttr = pDocument->GetAttributeMgr().GetCurrentAttribute(CC_RUNTIME_CLASS(BaseTextClass),
01068                                                                             CC_RUNTIME_CLASS(AttrTxtFontTypeface));
01069     if (pAttr)
01070     {
01071         AttrTxtFontTypeface* pTypeface = (AttrTxtFontTypeface*)pAttr;
01072         WORD Handle = pTypeface->Value.HTypeface;
01073         TRACEUSER("wuerthne", _T("found current font attribute, handle = %d"), Handle);
01074         CachedFontItem *pItem = FindFont(Handle);
01075         if (pItem)
01076         {
01077             String_64* SurfaceFontName = pItem->GetFontName();
01078             TRACEUSER("wuerthne", _T("current font name is %s"), (TCHAR*)*SurfaceFontName);
01079             ENUMLOGFONT *pEnumLogFont = pItem->GetEnumLogFont();
01080             if (pEnumLogFont)
01081             {
01082                 if (!IsFontInstalled(SurfaceFontName) && !IsFontUsedInDoc(Handle, pDocument))
01083                 {
01084                     // the current font is not installed and not used in the document,
01085                     // so find out what the replacement font is and use that instead
01086                     TRACEUSER("wuerthne", _T("font replaced and not used"));
01087                     String_64* NativeFontName = OILFontMan::GetNativeFontName(pItem->GetFontClass(),
01088                                                                               &pEnumLogFont->elfLogFont);
01089                     WORD NewHandle = CacheNamedFont(NativeFontName, pItem->GetFontClass());
01090                     if (NewHandle != ILLEGALFHANDLE)
01091                     {
01092                         TRACEUSER("wuerthne", _T("change current font to handle %d"), NewHandle);
01093                         // modify the current attribute directly
01094                         pTypeface->Value.HTypeface = NewHandle;
01095                     }
01096                 }
01097             }
01098         }
01099     }
01100 }

void FontManager::RefreshCache  ) 
 

Scans all the cached fonts and checks to see if any are invalid. If a font is invalid it is attempted to be made valid. This function is generally called when the external worlds fonts have changed via install/deinstall.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/9/95

Definition at line 1779 of file fontman.cpp.

01780 {
01781     InvalidateCache();
01782     OILFontMan::ValidateCache();
01783     ResetDefaultFont();
01784 }

void FontManager::ResetDefaultFont  )  [private]
 

Cache the default font so we can use this as a replacement when unable to find strange fonts. The cache is checked first to see if the default font is already there.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 1642 of file fontman.cpp.

01643 {
01644     DefaultFontItem.Delete();
01645     CacheDefaultFont();
01646 }

void FontManager::SetTempFont FontClass  Class,
String_64 pFontName,
ENUMLOGFONT lpelf
 

Definition at line 1896 of file fontman.cpp.

01897 {
01898     ERROR3IF(lpelf==NULL,"FontManager::SetTempFont() given a null ENUMLOGFONT structure");
01899     ERROR3IF(Class==FC_UNDEFINED, "FontManager::SetTempFont() given an illegal font class");
01900     
01901     TempFontClass=Class;
01902     TempFontName=(*pFontName);
01903     TempEnumLogFont=(*lpelf);
01904 }

BOOL FontManager::TempCacheNamedFont String_64 pFontName,
FontClass  Class = FC_UNDEFINED,
INT32  Pass = 1
[private]
 

Search through all the installed sets of fonts for the named font and place the result in a temp font.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/05/95
Parameters:
pFontName : Name of font to search for [INPUTS] Class : The class of font to cache FC_UNDEFINED - then try to cache any font Pass : 1 - first pass, try to match the font exactly : 2 - second pass, try to find a compatible font
- [OUTPUTS]
Returns:
TRUE if the font has been temporarily installed

Definition at line 1716 of file fontman.cpp.

01717 {
01718     return (OILFontMan::CacheNamedFont(pFontName, Class, Pass));
01719 }

BOOL FontManager::TempFontValid  ) 
 

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Returns:
TRUE if the temp font has been set to a valid font FALSE if not

Definition at line 1958 of file fontman.cpp.

01959 {
01960     return (TempFontClass!=FC_UNDEFINED);
01961 }

void FontManager::ValidateItem FontClass  Class,
String_64 pFontName,
ENUMLOGFONT lpelf
 

Used as a way of revalidating a cached font. This function is called from the various oil level font managers when we've asked them to refresh our cache. They simply need to scan their font lists and call this function with the new data.

void FontManager::ValidateItem(FontClass Class, String_64 * pFontName, ENUMLOGFONT * lpelf)

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/9/95

Definition at line 1799 of file fontman.cpp.

01800 {
01801     CachedFontItem *pItem = FindFont(pFontName,Class);
01802     if (pItem)
01803     {
01804         pItem->SetCacheData(lpelf);
01805         pItem->SetIsReplaced(FALSE);
01806     }
01807 }


Member Data Documentation

CachedFontItem FontManager::DefaultFontItem [private]
 

Definition at line 298 of file fontman.h.

WORD FontManager::DefaultHandle [private]
 

Definition at line 296 of file fontman.h.

UINT32 FontManager::FindClosestDistance [private]
 

Definition at line 258 of file fontman.h.

ENUMLOGFONT FontManager::FindClosestEnumLogFont [private]
 

Definition at line 261 of file fontman.h.

FontClass FontManager::FindClosestFontClass [private]
 

Definition at line 260 of file fontman.h.

WORD FontManager::FindClosestFontHandle [private]
 

Definition at line 256 of file fontman.h.

CCPanose FontManager::FindClosestPanoseNumber [private]
 

Definition at line 257 of file fontman.h.

String_64 FontManager::FindClosestTypeFaceName [private]
 

Definition at line 259 of file fontman.h.

ENUMLOGFONT FontManager::TempEnumLogFont [private]
 

Definition at line 303 of file fontman.h.

FontClass FontManager::TempFontClass [private]
 

Definition at line 301 of file fontman.h.

String_64 FontManager::TempFontName [private]
 

Definition at line 302 of file fontman.h.

List FontManager::TheFontList [private]
 

Definition at line 297 of file fontman.h.

WORD FontManager::UniqueHandle [private]
 

Definition at line 295 of file fontman.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:54:31 2007 for Camelot by  doxygen 1.4.4