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 ** <