FontComponent Class Reference

Provides a compoent to the document that handles the saving and loading of font definitions to and from the new file format. More...

#include <fontcomp.h>

Inheritance diagram for FontComponent:

DocComponent ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 FontComponent ()
 Constructor See Also: class FontComponent.
 ~FontComponent ()
 Destructor See Also: class FontComponent.
BOOL StartExport (BaseCamelotFilter *pFilter)
 Allows the font component a chance to prepare for an export operation See Also: class FontComponent.
BOOL EndExport (BaseCamelotFilter *pFilter, BOOL Success)
 Allows the font component a chance to recover from an export operation See Also: class FontComponent.
INT32 WriteFontDefinition (BaseCamelotFilter *pFilter, WORD FontHandle, BOOL IsBold, BOOL IsItalic)
 Writes a font definition record to the filter, and returns with the record number of this font definition record. See Also: class FontComponent, class FontComponentList, class FontComponentListItem.
BOOL StartImport (BaseCamelotFilter *pFilter)
 Gives objects of type class FontComponent a chance to prepare themselves for an import operation See Also: class FontComponent.
BOOL EndImport (BaseCamelotFilter *pFilter, BOOL Success)
 Gives this class a chance to recover from an import operation See Also: class FontComponent.
BOOL ReadFontDefinition (CXaraFileRecord *pRec)
 Reads a font component record from the filter See Also: class FontComponent, class TextObjRecordHandler.
BOOL GetFontInformation (INT32 RecordNumber, WORD *pFontHandle, BOOL *pIsBold, BOOL *pIsItalic)
 Retrives information from the font definition record with the corresponding record number See Also: class FontComponent, class TextAttrRecordHandler.

Public Attributes

FontComponentListpFontList
FontManagerpFontManager

Private Member Functions

 CC_DECLARE_DYNAMIC (FontComponent)
INT32 WriteFontRecord (BaseCamelotFilter *pFilter, FontComponentListItem *pItem)
 Writes a font definition record to the filter, and returns with the record number See Also: class FontComponent, class FontComponentListItem.
INT32 WriteTrueTypeRecord (BaseCamelotFilter *pFilter, FontComponentListItem *pItem)
INT32 WriteATMRecord (BaseCamelotFilter *pFilter, FontComponentListItem *pItem)
INT32 WriteUnknownRecord (BaseCamelotFilter *pFilter, FontComponentListItem *pItem)
BOOL ReadFontTrueType (CXaraFileRecord *pRec)
BOOL ReadFontATM (CXaraFileRecord *pRec)
BOOL ReadFontUnknown (CXaraFileRecord *pRec)
BOOL ExportCacheFont (FontComponentListItem *pItem)
 Caches information about a font in a FontComponentListItem object for export. See Also: class FontComponentListItem, class FontComponent.
BOOL ExportCacheFullFontName (FontComponentListItem *pItem)
BOOL ExportCacheTypeFaceName (FontComponentListItem *pItem)
BOOL ExportCacheFontClass (FontComponentListItem *pItem)
BOOL ExportCacheCCPanose (FontComponentListItem *pItem)
OUTLINETEXTMETRICExportGetOutlineTextMetricStage1 (FontComponentListItem *pItem)
 Tries to retrieve the OUTLINETEXTMETRIC structure for a font.
OUTLINETEXTMETRICExportGetOutlineTextMetricStage2 (FontComponentListItem *pItem)
BOOL ImportCacheFont (FontComponentListItem *pItem)
 Caches information about a font in a FontComponentListItem for import See Also: class FontComponentListItem, class FontComponent.

Private Attributes

BOOL ExportInitialised
BOOL ImportInitialised
BaseCamelotFilterpCamFilter
BOOL WarnedBefore

Detailed Description

Provides a compoent to the document that handles the saving and loading of font definitions to and from the new file format.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
06/08/96 Base Class: public DocComponent
See also:
class FontComponentList, class DocComponent

Definition at line 232 of file fontcomp.h.


Constructor & Destructor Documentation

FontComponent::FontComponent  ) 
 

Constructor See Also: class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/08/96
Parameters:
- [INPUTS]
Returns:
-

Definition at line 689 of file fontcomp.cpp.

00690 {
00691     // constructor for this class, ho hum,
00692     ExportInitialised = FALSE;
00693     ImportInitialised = FALSE;
00694 
00695     pFontList = new FontComponentList;
00696     pFontManager = GetApplication()->GetFontManager();
00697 
00698     // Our link to the BaseCamelotFilter
00699     pCamFilter = NULL;
00700     // Set our variable so that we warn about a possible replacement only once
00701     WarnedBefore = FALSE;
00702 }

FontComponent::~FontComponent  ) 
 

Destructor See Also: class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/08/96
Parameters:
- [INPUTS]
Returns:
-

Definition at line 717 of file fontcomp.cpp.

00718 {
00719     ERROR3IF(ImportInitialised!=FALSE, "Deconstructor called when ImportInitialised!=FALSE");
00720     ERROR3IF(ExportInitialised!=FALSE, "Deconstructor called when ExportInitialised!=FALSE");
00721 
00722     if (pFontList)
00723     {
00724         delete pFontList;
00725         pFontList = NULL;
00726     }
00727 }


Member Function Documentation

FontComponent::CC_DECLARE_DYNAMIC FontComponent   )  [private]
 

BOOL FontComponent::EndExport BaseCamelotFilter pFilter,
BOOL  Success
[virtual]
 

Allows the font component a chance to recover from an export operation See Also: class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/08/96
Parameters:
- [INPUTS]
Returns:
TRUE if successful, FALSE otherwise

Reimplemented from DocComponent.

Definition at line 768 of file fontcomp.cpp.

00769 {
00770     //ERROR2IF(ExportInitialised==FALSE, FALSE, "EndExport called when ExportInitialised==FALSE.");
00771     //ERROR2IF(pFontList==NULL, FALSE, "EndExport called when pFontList==NULL.");
00772     // If we error about the pFontList and ExportInitialised then we assume that the StartExport has been called.
00773     // This may not be the case if we are in clean up mode. So just handle it!
00774 
00775     BOOL ok = TRUE;
00776 
00777     if (ok && pFontList) ok = pFontList->ExportEnd(Success);
00778     if (ok) ExportInitialised=FALSE;
00779 
00780     return ok;
00781 }

BOOL FontComponent::EndImport BaseCamelotFilter pFilter,
BOOL  Success
[virtual]
 

Gives this class a chance to recover from an import operation See Also: class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/08/96
Parameters:
pFilter - filter to use [INPUTS] Success - TRUE if import operation was successful, FALSE otherwise
Returns:
TRUE if successful, FALSE otherwise

Reimplemented from DocComponent.

Definition at line 991 of file fontcomp.cpp.

00992 {
00993     //ERROR2IF(ImportInitialised==FALSE, FALSE, "EndImport called when ImportInitialised==FALSE.");
00994     //ERROR2IF(pFontList==NULL, FALSE, "EndImport called when pFontList==NULL.");
00995     // If we error about the pFontList and ImportInitialised then we assume that the EndExport has been called.
00996     // This may not be the case if we are in clean up mode. So just handle it!
00997 
00998     BOOL ok = TRUE;
00999 
01000     if (ok && pFontList) ok = pFontList->ImportEnd(Success);
01001     if (ok) ImportInitialised=FALSE;
01002 
01003     // Null our link to the BaseCamelotFilter
01004     pCamFilter = NULL;
01005     // Set our variable so that we warn about a possible replacement only once
01006     WarnedBefore = FALSE;
01007 
01008     return ok;
01009 }

BOOL FontComponent::ExportCacheCCPanose FontComponentListItem pItem  )  [private]
 

Definition at line 1284 of file fontcomp.cpp.

01285 {
01286     ERROR2IF(pItem==NULL, FALSE, "ExportCacheFullFontName called with pItem==NULL.");
01287 
01288     OUTLINETEXTMETRIC *pOutlineTextMetric;
01289 
01290     if (NULL!=(pOutlineTextMetric=ExportGetOutlineTextMetricStage1(pItem)))
01291     {
01292         // successful!
01293         pItem->mPanoseNumber = pOutlineTextMetric->otmPanoseNumber;
01294     }
01295     else
01296     {
01297         if (NULL!=(pOutlineTextMetric=ExportGetOutlineTextMetricStage2(pItem)))
01298         {
01299             // successful!
01300             pItem->mPanoseNumber = pOutlineTextMetric->otmPanoseNumber;
01301             free(pOutlineTextMetric);   // remember to free this result
01302         }
01303         else
01304         {
01305             // unsuccessful. :(
01306             pItem->mPanoseNumber.SetAllToAny();
01307         }
01308     }
01309 
01310     pItem->mPanoseNumber.BodgePanoseNumber(pItem->mIsBold, pItem->mIsItalic);
01311 
01312     return TRUE;
01313 }

BOOL FontComponent::ExportCacheFont FontComponentListItem pItem  )  [private]
 

Caches information about a font in a FontComponentListItem object for export. See Also: class FontComponentListItem, class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/08/96
Parameters:
pItem : FontComponentListItem to complete [INPUTS]
Returns:
TRUE if successful, FALSE otherwise

Definition at line 1198 of file fontcomp.cpp.

01199 {
01200     ERROR2IF(pItem==NULL, FALSE, "Parameter pItem==NULL.");
01201     ERROR2IF(ExportInitialised==FALSE, FALSE, "ExportCacheFont called when ExportInitialised==FALSE.");
01202     ERROR2IF(pFontManager==NULL, FALSE, "ExportCacheFont called when pFontManager==NULL.");
01203 
01204     BOOL ok = TRUE;
01205     
01206     // members of class FontComponentListItem are:
01207     //      BOOL mIsBold                    : should be already filled in   
01208     //      BOOL mIsItalic                  : should be already filled in
01209     //      BOOL mRecentlyCreated           : leave alone
01210     //      WORD mFontHandle                : should be already filled in
01211     //      INT32 mRecordNumber             : leave alone
01212     //      String_64 mFullFontName         : set to a null string
01213     //      String_64 mTypeFaceName         : get from the font manager
01214     //      FontClass mFontClass            : get from the font manager
01215     //      CCPanose mPanoseNumber          : get from the font manager
01216 
01217     // the following order is important - don't change unless you need to.      ach - 16/08/96
01218     if (ok) ok = ExportCacheFontClass(pItem);
01219     if (ok) ok = ExportCacheTypeFaceName(pItem);
01220     if (ok) ok = ExportCacheFullFontName(pItem);
01221     if (ok) ok = ExportCacheCCPanose(pItem);
01222 
01223     return ok;
01224 }

BOOL FontComponent::ExportCacheFontClass FontComponentListItem pItem  )  [private]
 

Definition at line 1271 of file fontcomp.cpp.

01272 {
01273     ERROR2IF(pItem==NULL, FALSE, "ExportCacheFaceName called with pItem==NULL.");
01274     ERROR2IF(pFontManager==NULL, FALSE, "pFontManager==NULL");
01275     ERROR2IF(pItem->mFontHandle==ILLEGALFHANDLE, FALSE, "pItem->mFontHandle==ILLEGALFHANDLE.");
01276 
01277     BOOL ok = TRUE;
01278 
01279     pItem->mFontClass = pFontManager->GetFontClass(pItem->mFontHandle);
01280 
01281     return ok;
01282 }

BOOL FontComponent::ExportCacheFullFontName FontComponentListItem pItem  )  [private]
 

Definition at line 1226 of file fontcomp.cpp.

01227 {
01228     PORTNOTETRACE("text","FontComponent::ExportCacheFullFontName - do nothing");
01229 #ifndef EXCLUDE_FROM_XARALX
01230     ERROR2IF(pItem==NULL, FALSE, "ExportCacheFullFontName called with pItem==NULL.");
01231 
01232     OUTLINETEXTMETRIC *pOutlineTextMetric;
01233 
01234     if (NULL!=(pOutlineTextMetric=ExportGetOutlineTextMetricStage1(pItem)))
01235     {
01236         // successful!
01237         pItem->mFullFontName = (char *)(((INT32) pOutlineTextMetric) + ((INT32) pOutlineTextMetric->otmpFaceName));
01238     }
01239     else
01240     {
01241         if (NULL!=(pOutlineTextMetric=ExportGetOutlineTextMetricStage2(pItem)))
01242         {
01243             // successful!
01244             pItem->mFullFontName = (char *)(((INT32) pOutlineTextMetric) + ((INT32) pOutlineTextMetric->otmpFaceName));
01245             free(pOutlineTextMetric);   // remember to free this result
01246         }
01247         else
01248         {
01249             // unsuccessful. :(
01250             pItem->mFullFontName="";
01251         }
01252     }
01253 #endif
01254     return TRUE;
01255 }

BOOL FontComponent::ExportCacheTypeFaceName FontComponentListItem pItem  )  [private]
 

Definition at line 1258 of file fontcomp.cpp.

01259 {
01260     ERROR2IF(pItem==NULL, FALSE, "ExportCacheFaceName called with pItem==NULL.");
01261     ERROR2IF(pFontManager==NULL, FALSE, "pFontManager==NULL");
01262     ERROR2IF(pItem->mFontHandle==ILLEGALFHANDLE, FALSE, "pItem->mFontHandle==ILLEGALFHANDLE.");
01263 
01264     BOOL ok = TRUE;
01265 
01266     if (ok) ok = pFontManager->GetFontName(pItem->mFontHandle, pItem->mTypeFaceName);
01267 
01268     return ok;
01269 }

OUTLINETEXTMETRIC * FontComponent::ExportGetOutlineTextMetricStage1 FontComponentListItem pItem  )  [private]
 

Tries to retrieve the OUTLINETEXTMETRIC structure for a font.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/08/96
Parameters:
pItem - pointer to a FontComponentListItem to get the OUTLINETEXTMETRIC for [INPUTS]
Returns:
Pointer to an OUTLINETEXTMETRIC, or NULL if not found
Be careful, since the pointer returned by these functions is (and should be) deleted by the caller.

Definition at line 1331 of file fontcomp.cpp.

01332 {
01333     PORTNOTETRACE("text","FontComponent::ExportGetOutlineTextMetricStage1 - do nothing");
01334 #ifndef EXCLUDE_FROM_XARALX
01335     ERROR2IF(pItem==NULL, NULL, "ExportGetOutlineTextMetricStage1 with pItem==NULL.");
01336 
01337     // stage 1 - does the font manager have the OUTLINETEXTMETRIC structure for this font?
01338     //
01339     // We'll ask it nicely and see what result it comes backwith. Because the font manager can
01340     // oly cope with one font per typeface (Doh!) we'll ask it for the OUTLINETEXTMETRIC for
01341     // the typeface of the font we're trying to cache, and see if it bears any resemblance to the
01342     // font we originally asked for.
01343 
01344     OUTLINETEXTMETRIC *pOutlineTextMetric = pFontManager->GetOutlineTextMetric(pItem->mFontHandle);
01345 
01346     if (pOutlineTextMetric!=NULL)
01347     {
01348         // see if it bears any resemblance to the one we want
01349         //
01350         // Here we notice Microsoft's documentation and code don't quite agree. The OUTLINETEXTMETRIC
01351         // structure has 4 strings at the end, the 'family name', 'type name', 'style name'
01352         // and 'full name'. However for, say, Arial Bold:
01353         //
01354         // family name = "Arial"            : what we call the typeface name
01355         // face name = "Arial Bold"         : what we call the full name
01356         // style name = "Bold"              : style name
01357         // full name = "blah blah blah" (not important).
01358         
01359         const String_64 TypeFaceName = (char *) (((INT32)pOutlineTextMetric) + ((INT32)pOutlineTextMetric->otmpFamilyName));
01360         const BOOL IsBold = pOutlineTextMetric->otmTextMetrics.tmWeight > FW_NORMAL;
01361         const BOOL IsItalic = pOutlineTextMetric->otmTextMetrics.tmItalic != 0;
01362 
01363         if (TypeFaceName==pItem->mTypeFaceName && IsBold==pItem->mIsBold && IsItalic==pItem->mIsItalic)
01364         {
01365             // hurray, success - so return this result.
01366         }
01367         else
01368         {
01369             // doesn't match, so return NULL;
01370             pOutlineTextMetric = NULL;
01371         }
01372     }
01373 
01374     return pOutlineTextMetric;
01375 #endif
01376     return NULL;
01377 }

OUTLINETEXTMETRIC * FontComponent::ExportGetOutlineTextMetricStage2 FontComponentListItem pItem  )  [private]
 

Definition at line 1379 of file fontcomp.cpp.

01380 {
01381     PORTNOTETRACE("text","FontComponent::ExportGetOutlineTextMetricStage2 - do nothing");
01382 #ifndef EXCLUDE_FROM_XARALX
01383     ERROR2IF(pItem==NULL, NULL, "ExportGetOutlineTextMetricStage2 called with pItem==NULL.");
01384     ERROR2IF(pFontManager==NULL, NULL, "pFontManager==NULL.");
01385     ERROR2IF(pItem->mFontHandle==ILLEGALFHANDLE, NULL, "pItem->mFontHandle==ILLEGALFHANDLE.");
01386 
01387     OUTLINETEXTMETRIC *pOutlineTextMetric = NULL;
01388 
01389     // stage 2 - can we get the OUTLINETEXTMETRIC from one of the oil font managers
01390     //
01391     // Again, we'll ask nicely and see what result we get back. We'll get the LOGFONT from the font
01392     // manager, fill in the weight and italic entries like OSRenderRegion does and see what it comes back
01393     // with. And again we'll check to see if its anything like what we asked for.
01394 
01395     ENUMLOGFONT *pEnumLogFont;
01396     LOGFONT MyLogFont;
01397 
01398     pEnumLogFont = pFontManager->GetEnumLogFont(pItem->mFontHandle);
01399 
01400     if (pEnumLogFont!=NULL)
01401     {
01402         MyLogFont = pEnumLogFont->elfLogFont;
01403 
01404         // straight from OSRenderRegion.
01405         MyLogFont.lfWeight = (pItem->mIsBold) ? FW_BOLD : FW_NORMAL;
01406         MyLogFont.lfItalic = (pItem->mIsItalic) ? 1 : 0;
01407 
01408         pOutlineTextMetric=OILFontMan::GetOutlineTextMetric(pItem->mFontClass, &MyLogFont);
01409 
01410         if (pOutlineTextMetric!=NULL)
01411         {
01412             // we've got an OUTLINETEXTMETRIC, now check to see if its the right one
01413             //
01414             // Here we notice Microsoft's documentation and code don't quite agree. The OUTLINETEXTMETRIC
01415             // structure has 4 strings at the end, the 'family name', 'type name', 'style name'
01416             // and 'full name'. However for, say, Arial Bold:
01417             //
01418             // family name = "Arial"
01419             // face name = "Arial Bold"
01420             // style name = "Bold"
01421             // full name = "blah blah blah" (not important).
01422 
01423             const String_64 TypeFaceName = (char *) (((INT32)pOutlineTextMetric) + ((INT32)pOutlineTextMetric->otmpFamilyName));
01424             const BOOL IsBold = pOutlineTextMetric->otmTextMetrics.tmWeight > FW_NORMAL;
01425             const BOOL IsItalic = pOutlineTextMetric->otmTextMetrics.tmItalic != 0;
01426             
01427             if (TypeFaceName==pItem->mTypeFaceName && IsBold==pItem->mIsBold && IsItalic==pItem->mIsItalic)
01428             {
01429                 // hurray it is, so do nothing
01430             }
01431             else
01432             {
01433                 // No, its not. Free the memory and return NULL.
01434                 free(pOutlineTextMetric);
01435                 pOutlineTextMetric=NULL;
01436             }
01437         }
01438         else
01439         {
01440             // pOutlineTextMetric==NULL, so we have to return NULL
01441         }
01442     }
01443     else
01444     {
01445         // unable to get the LOGFONT structure, so we'll return NULL
01446         pOutlineTextMetric=NULL;
01447     }
01448 
01449     return pOutlineTextMetric;
01450 #endif
01451     return NULL;
01452 }

BOOL FontComponent::GetFontInformation INT32  RecordNumber,
WORD pFontHandle,
BOOL *  pIsBold,
BOOL *  pIsItalic
 

Retrives information from the font definition record with the corresponding record number See Also: class FontComponent, class TextAttrRecordHandler.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/08/96
Parameters:
RecordNumber - Record number of font definition record [INPUTS]
pFontHandle - pointer to a WORD to return the font maangers font handle in [OUTPUTS] pIsBold - pointer to a BOOL to return the bold flag in pIsItalic - pointer to a BOOL to return the italic flag in
Returns:
TRUE if successful, FALSE otherwise

Definition at line 1136 of file fontcomp.cpp.

01137 {
01138     ERROR2IF(ImportInitialised==FALSE, FALSE, "GetFontInformation called when ImportInitialised==FALSE.");
01139     ERROR2IF(pFontList==NULL, FALSE, "GetFontInformation called when pFontList==NULL.");
01140     ERROR2IF(pFontHandle==NULL, FALSE, "GetFontInformation called when pFontHandle==NULL.");
01141     ERROR2IF(pIsBold==NULL, FALSE, "GetFontInformation called when pIsBold==NULL.");
01142     ERROR2IF(pIsItalic==NULL, FALSE, "GetFontInformation called when pIsItalic==NULL.");
01143 
01144     BOOL ok;
01145 
01146     FontComponentListItem *pItem = pFontList->ImportFind(RecordNumber);
01147 
01148     if (pItem==NULL)
01149     {
01150         // oh dear, we can't find the font definition record - possibly an error in the file
01151         ok = TRUE;
01152 
01153         // We will warn the user and use a replacement font instead
01154         // If we have a pFilter then ask the default warning handle to append our message
01155         if (pCamFilter)
01156         {
01157             if (!WarnedBefore)
01158             {
01159                 pCamFilter->AppendWarning(_R(IDS_NATIVE_FONTWARNING));
01160                 WarnedBefore = TRUE;
01161             }
01162         }
01163         else
01164             ERROR3("FontComponent::GetFontInformation unkown font reference - using default");
01165 
01166         *pFontHandle = DEFAULTHANDLE;
01167         *pIsBold = FALSE;
01168         *pIsItalic = FALSE;
01169     }
01170     else
01171     {
01172         ok = TRUE;
01173         *pFontHandle = pItem->mFontHandle;
01174         *pIsBold = pItem->mIsBold;
01175         *pIsItalic = pItem->mIsItalic;
01176     }
01177 
01178     return ok;  
01179 }

BOOL FontComponent::ImportCacheFont FontComponentListItem pItem  )  [private]
 

Caches information about a font in a FontComponentListItem for import See Also: class FontComponentListItem, class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/08/96
Parameters:
pItem : FontComponentListItem to complete [INPUTS]
Returns:
TRUE if successful, FALSE otherwise
Finally, the guts of the clever font matching system for the new file format. From the font definition record we get the font name (null string), face name and panose number for a font. We need to find the closest matching font out of all those installed on this system.

Definition at line 1472 of file fontcomp.cpp.

01473 {
01474     ERROR2IF(pItem==NULL, FALSE, "Parameter pItem==NULL.");
01475     ERROR2IF(ImportInitialised==FALSE, FALSE, "ImportCacheFont called when ImportInitialised==FALSE.");
01476     ERROR2IF(pFontManager==NULL, FALSE, "ImportCacheFont called when pFontManager==NULL.");
01477     
01478     // members of class FontComponentListItem are:
01479     //      BOOL mIsBold                    : bodge from the panose number
01480     //      BOOL mIsItalic                  : bodge from the panose number
01481     //      BOOL mRecentlyCreated           : leave alone
01482     //      WORD mFontHandle                : from the font manager
01483     //      INT32 mRecordNumber             : leave alone
01484     //      String_64 mFullFontName         : should already be filled in
01485     //      String_64 mTypeFaceName         : should already be filled in
01486     //      FontClass mFontClass            : should already be filled in
01487     //      CCPanose mPanoseNumber          : should already be filled in
01488 
01489     WORD FontHandle;
01490 
01491     // Ask the kernel font manager to find this typeface name and class
01492     FontHandle = pFontManager->FindTypeface(pItem->mTypeFaceName, pItem->mFontClass);
01493 
01494     if (FontHandle==ILLEGALFHANDLE)
01495     {
01496         // Failed, we ask the kernel font manager just to find this typeface name, ignoring the class
01497         FontHandle = pFontManager->FindTypeface(pItem->mTypeFaceName, FC_UNDEFINED);
01498     }
01499     else if (FALSE==(pFontManager->IsFontValid(FontHandle)))
01500     {
01501         // although the font is in the font cache it's not fully cached. i.e.
01502         // the font has been deinstalled during this session of Camelot. So
01503         // we find a replacement font now...
01504 
01505         PORTNOTE("text","FontComponent::ImportCacheFont - Removed FindClosestFont usage");
01506 #ifndef DISABLE_TEXT_RENDERING
01507         CachedFontItem *pCachedFontItem = pFontManager->GetFont(FontHandle);
01508 
01509         WORD BestFontHandle = pFontManager->FindClosestFont(pItem->mPanoseNumber);
01510         ENUMLOGFONT MyEnumLogFont = *(pFontManager->GetEnumLogFont(BestFontHandle));
01511 
01512         // if necessary, get rid of the old ENUMLOGFONT structure
01513         pCachedFontItem->DeleteMetrics();
01514 
01515         pCachedFontItem->SetCacheData(&MyEnumLogFont);
01516         pCachedFontItem->SetIsReplaced(TRUE);
01517 #endif
01518     }
01519 
01520     if (FontHandle==ILLEGALFHANDLE)
01521     {
01522         PORTNOTE("text","FontComponent::ImportCacheFont - Removed FindClosestFont usage");
01523 #ifndef DISABLE_TEXT_RENDERING
01524 
01525             // Failed again, so we try to find the closest font using PANOSE font matching.
01526         WORD BestFontHandle = pFontManager->FindClosestFont(pItem->mPanoseNumber);
01527 
01528         // Get the correct fontclass for the subsituted font
01529         FontClass BestFontClass = pFontManager->GetFontClass(BestFontHandle);
01530 
01531         // add our font to the font manager's list
01532         CachedFontItem *pCachedFontItem = pFontManager->AddFont(&(pItem->mTypeFaceName), BestFontClass, FontHandle);
01533 
01534         // fix in the ENUMLOGFONT from the font found above.
01535         ENUMLOGFONT MyEnumLogFont = *(pFontManager->GetEnumLogFont(BestFontHandle));
01536         pCachedFontItem->SetCacheData(&MyEnumLogFont);
01537         pCachedFontItem->SetIsReplaced(TRUE);
01538 #endif
01539     }
01540     
01541     if (FontHandle==ILLEGALFHANDLE)
01542     {
01543         // something has gone wrong. complain, and fix the error
01544         ERROR2(FALSE, "Unable to find a font!.");
01545         FontHandle = DEFAULTHANDLE;
01546     }
01547 
01548     pItem->mFontHandle = FontHandle;
01549 
01550     // fill in the mIsBold and mIsItalic entries for the FontComponentListItem from the panose number.
01551     pItem->mIsBold   = pItem->mPanoseNumber.GetWeight() > PAN_WEIGHT_MEDIUM;                // !!HACK!!
01552     pItem->mIsItalic = pItem->mPanoseNumber.GetLetterform() > PAN_LETT_NORMAL_SQUARE;       // !!HACK!!
01553 
01554     return TRUE;        // we succeed - we always succeed!
01555 }

BOOL FontComponent::ReadFontATM CXaraFileRecord pRec  )  [private]
 

Definition at line 1077 of file fontcomp.cpp.

01078 {
01079     ERROR2IF(ImportInitialised==FALSE, FALSE, "ReadFontATM called when ImportInitialised==FALSE.");
01080     ERROR2IF(pRec==NULL, FALSE, "Parameter pRec==NULL.");
01081     ERROR2IF(pFontList==NULL, FALSE, "ReadFontATM called when pFontList==NULL.");
01082 
01083     BOOL ok = TRUE;
01084 
01085     TCHAR Buffer[256];
01086     FontComponentListItem *pItem = new FontComponentListItem;
01087 
01088     pItem->mRecordNumber = pRec->GetRecordNumber();
01089 
01090     pItem->mFontClass = FC_ATM;
01091 
01092     if (ok) ok = pRec->ReadUnicode(Buffer, 256);
01093     pItem->mFullFontName = Buffer;
01094 
01095     if (ok) ok = pRec->ReadUnicode(Buffer, 256);
01096     pItem->mTypeFaceName = Buffer;
01097 
01098     if (ok) ok = pRec->ReadCCPanose( &(pItem->mPanoseNumber) );
01099 
01100     PORTNOTE("text","FontComponent::ReadFontATM - removed ImportCacheFont call");
01101 #ifndef DISABLE_TEXT_RENDERING
01102     if (ok) ok = ImportCacheFont(pItem);    // do all our clever matching
01103 
01104     if (ok) pFontList->AddTail(pItem);
01105 #endif
01106     return ok;
01107 }

BOOL FontComponent::ReadFontDefinition CXaraFileRecord pRec  ) 
 

Reads a font component record from the filter See Also: class FontComponent, class TextObjRecordHandler.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/08/96
Parameters:
pRec : pointer to a CXaraFileRecord to read [INPUTS]
Returns:
TRUE if successful, FALSE otherwise

Definition at line 1027 of file fontcomp.cpp.

01028 {
01029     ERROR2IF(pRec==NULL, FALSE, "Parameter pRec==NULL.");
01030     ERROR2IF(ImportInitialised==FALSE, FALSE, "ReadFontDefinition called when ImportInitialised==FALSE.");
01031 
01032     BOOL ok;
01033 
01034     switch (pRec->GetTag())
01035     {
01036         case TAG_FONT_DEF_TRUETYPE  : ok = ReadFontTrueType(pRec); break;
01037         case TAG_FONT_DEF_ATM       : ok = ReadFontATM(pRec); break;
01038         default                     : ok = ReadFontUnknown(pRec); break;
01039     }
01040 
01041     return ok;
01042 }

BOOL FontComponent::ReadFontTrueType CXaraFileRecord pRec  )  [private]
 

Definition at line 1044 of file fontcomp.cpp.

01045 {
01046     ERROR2IF(ImportInitialised==FALSE, FALSE, "ReadFontTrueType called when ImportInitialised==FALSE.");
01047     ERROR2IF(pRec==NULL, FALSE, "Parameter pRec==NULL.");
01048     ERROR2IF(pFontList==NULL, FALSE, "ReadFontTrueType called when pFontList==NULL.");
01049 
01050     BOOL ok = TRUE;
01051 
01052     TCHAR Buffer[256];
01053     FontComponentListItem *pItem = new FontComponentListItem;
01054 
01055     pItem->mRecordNumber = pRec->GetRecordNumber();
01056 
01057     pItem->mFontClass = FC_TRUETYPE;
01058 
01059     if (ok) ok = pRec->ReadUnicode(Buffer, 256);
01060     pItem->mFullFontName = Buffer;
01061 
01062     if (ok) ok = pRec->ReadUnicode(Buffer, 256);
01063     pItem->mTypeFaceName = Buffer;
01064 
01065     if (ok) ok = pRec->ReadCCPanose( &(pItem->mPanoseNumber) );
01066 
01067     PORTNOTE("text","FontComponent::ReadFontTrueType - removed ImportCacheFont call");
01068 #ifndef DISABLE_TEXT_RENDERING
01069     if (ok) ok = ImportCacheFont(pItem);    // do all our clever matching
01070 
01071     if (ok) pFontList->AddTail(pItem);
01072 #endif
01073 
01074     return ok;
01075 }

BOOL FontComponent::ReadFontUnknown CXaraFileRecord pRec  )  [private]
 

Definition at line 1109 of file fontcomp.cpp.

01110 {
01111     ERROR2IF(ImportInitialised==FALSE, FALSE, "ReadFontTrueType called when ImportInitialised==FALSE.");
01112     ERROR2IF(pRec==NULL, FALSE, "Parameter pRec==NULL.");
01113     ERROR2IF(pFontList==NULL, FALSE, "ReadFontTrueType called when pFontList==NULL.");
01114 
01115     ERROR3("Attempt to read an unrecognised font definition record.");
01116 
01117     return FALSE;
01118 }

BOOL FontComponent::StartExport BaseCamelotFilter pFilter  )  [virtual]
 

Allows the font component a chance to prepare for an export operation See Also: class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/08/96
Parameters:
- [INPUTS]
Returns:
TRUE if successful, FALSE otherwise

Reimplemented from DocComponent.

Definition at line 742 of file fontcomp.cpp.

00743 {
00744     ERROR2IF(ExportInitialised!=FALSE, FALSE, "StartExport called when ExportInitialised!=FALSE");
00745     ERROR2IF(pFontList==NULL, FALSE, "StartExport called when pFontList==NULL.");
00746 
00747     BOOL ok = TRUE;
00748 
00749     if (ok) ok = pFontList->ExportStart();
00750     if (ok) ExportInitialised=TRUE;
00751 
00752     return ok;
00753 }

BOOL FontComponent::StartImport BaseCamelotFilter pFilter  )  [virtual]
 

Gives objects of type class FontComponent a chance to prepare themselves for an import operation See Also: class FontComponent.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/08/96
Parameters:
pFilter - filter to use [INPUTS]
Returns:
TRUE if successful, FALSE otherwise

Reimplemented from DocComponent.

Definition at line 959 of file fontcomp.cpp.

00960 {
00961     ERROR2IF(ImportInitialised!=FALSE, FALSE, "StartImport called when ImportInitialised!=FALSE.");
00962     ERROR2IF(pFontList==NULL, FALSE, "StartImport called when pFontList==NULL.");
00963 
00964     // Save this in our link to the BaseCamelotFilter
00965     pCamFilter = pFilter;
00966     // Set our variable so that we warn about a possible replacement only once
00967     WarnedBefore = FALSE;
00968 
00969     BOOL ok = TRUE;
00970 
00971     if (ok) ok = pFontList->ImportStart();
00972     if (ok) ImportInitialised=TRUE;
00973 
00974     return ok;
00975 }

INT32 FontComponent::WriteATMRecord BaseCamelotFilter pFilter,
FontComponentListItem pItem
[private]
 

Definition at line 910 of file fontcomp.cpp.

00911 {
00912     ERROR2IF(ExportInitialised==FALSE, FALSE, "EndExport called when ExportInitialised==FALSE.");
00913     ERROR2IF(pFilter==NULL, 0, "Parameter pFilter==NULL.");
00914     ERROR2IF(pItem==NULL, 0, "Parameter pItem==NULL.");
00915 
00916     BOOL ok = TRUE;
00917     INT32 RecordNumber = 0;
00918 
00919     CamelotFileRecord Rec(pFilter, TAG_FONT_DEF_ATM, TAG_FONT_DEF_ATM_SIZE);
00920 
00921     ok = Rec.Init();
00922 
00923     if (ok) ok = Rec.WriteUnicode((TCHAR*)pItem->mFullFontName);
00924     if (ok) ok = Rec.WriteUnicode((TCHAR*)pItem->mTypeFaceName);
00925     if (ok) ok = Rec.WriteCCPanose(pItem->mPanoseNumber);
00926 
00927     if (ok) ok = (0 != (RecordNumber = pFilter->WriteDefinitionRecord(&Rec)));
00928 
00929     // if ok==TRUE, then by the above line RecordNumber!=NULL. if ok==FALSE then
00930     // RecordNumber==NULL. so we don't need to check ok at this point.
00931     return RecordNumber;
00932 }

INT32 FontComponent::WriteFontDefinition BaseCamelotFilter pFilter,
WORD  FontHandle,
BOOL  IsBold,
BOOL  IsItalic
 

Writes a font definition record to the filter, and returns with the record number of this font definition record. See Also: class FontComponent, class FontComponentList, class FontComponentListItem.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/08/96
Parameters:
pFilter - filter to write font defintion record to [INPUTS] FontHandle - font handle of font definition to write IsBold - bold flag of font definition IsItalic - italic flag of font definition
Returns:
RecordNumber of font definition, or NULL if unsuccessful

Definition at line 800 of file fontcomp.cpp.

00801 {
00802     ERROR2IF(ExportInitialised==FALSE, FALSE, "EndExport called when ExportInitialised==FALSE.");
00803     ERROR2IF(pFilter==NULL, FALSE, "Parameter pFilter==NULL.");
00804     ERROR2IF(FontHandle==ILLEGALFHANDLE, FALSE, "Parameter FontHandle==ILLEGALFHANDLE.");
00805     ERROR2IF(pFontList==NULL, FALSE, "member variable pFontList==NULL.");
00806 
00807     INT32 RecordNumber = 0;
00808     FontComponentListItem *pItem;
00809     
00810     // is this item already cached?
00811     pItem = pFontList->ExportFind(FontHandle, IsBold, IsItalic);
00812 
00813     if (pItem==NULL)
00814     {
00815         // first time we've come across this font, so cache some information about it.
00816         pItem = new FontComponentListItem;
00817         pItem->mFontHandle = FontHandle;
00818         pItem->mIsBold = IsBold;
00819         pItem->mIsItalic = IsItalic;
00820 
00821         (void) ExportCacheFont(pItem);      // cache the rest of the information about this font
00822 
00823         pFontList->AddTail(pItem);
00824     }
00825 
00826     // by now, pItem!=NULL, otherwise we've got serious problems
00827 
00828     if (pItem!=NULL)
00829     {
00830         // have we already written a font defintion record for this font? i.e. is
00831         // mRecordNumber!=NULL?
00832         if (pItem->mRecordNumber != 0)
00833         {
00834             RecordNumber = pItem->mRecordNumber;
00835         }
00836         else
00837         {
00838             RecordNumber = WriteFontRecord(pFilter, pItem);
00839             pItem->mRecordNumber=RecordNumber;
00840         }
00841     }
00842     else
00843     {
00844         ERROR3("pItem==NULL, and it shouldn't!");
00845         RecordNumber=0;
00846     }
00847 
00848     return RecordNumber;
00849 }

INT32 FontComponent::WriteFontRecord BaseCamelotFilter pFilter,
FontComponentListItem pItem
[private]
 

Writes a font definition record to the filter, and returns with the record number See Also: class FontComponent, class FontComponentListItem.

Author:
Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/08/96
Parameters:
pFilter - filter to write [INPUTS] pItem - fontto write a definition for
Returns:
Record number of font definition record, or 0 if unsuccessful

Definition at line 868 of file fontcomp.cpp.

00869 {
00870     ERROR2IF(ExportInitialised==FALSE, FALSE, "EndExport called when ExportInitialised==FALSE.");
00871     ERROR2IF(pFilter==NULL, 0, "Parameter pFilter==NULL.");
00872     ERROR2IF(pItem==NULL, 0, "Parameter pItem==NULL.");
00873 
00874     INT32 RecordNumber;
00875     
00876     switch (pItem->mFontClass)
00877     {
00878         case FC_TRUETYPE        : RecordNumber = WriteTrueTypeRecord(pFilter, pItem); break;
00879         case FC_ATM             : RecordNumber = WriteATMRecord(pFilter, pItem); break;
00880         default                 : RecordNumber = WriteUnknownRecord(pFilter, pItem); break;
00881     }
00882 
00883     return RecordNumber;
00884 }

INT32 FontComponent::WriteTrueTypeRecord BaseCamelotFilter pFilter,
FontComponentListItem pItem
[private]
 

Definition at line 886 of file fontcomp.cpp.

00887 {
00888     ERROR2IF(ExportInitialised==FALSE, FALSE, "EndExport called when ExportInitialised==FALSE.");
00889     ERROR2IF(pFilter==NULL, 0, "Parameter pFilter==NULL.");
00890     ERROR2IF(pItem==NULL, 0, "Parameter pItem==NULL.");
00891 
00892     BOOL ok = TRUE;
00893     INT32 RecordNumber = 0;
00894 
00895     CamelotFileRecord Rec(pFilter, TAG_FONT_DEF_TRUETYPE, TAG_FONT_DEF_TRUETYPE_SIZE);
00896 
00897     ok = Rec.Init();
00898 
00899     if (ok) ok = Rec.WriteUnicode((TCHAR*)pItem->mFullFontName);
00900     if (ok) ok = Rec.WriteUnicode((TCHAR*)pItem->mTypeFaceName);
00901     if (ok) ok = Rec.WriteCCPanose(pItem->mPanoseNumber);
00902 
00903     if (ok) ok = (0 != (RecordNumber = pFilter->WriteDefinitionRecord(&Rec)));
00904     
00905     // if ok==TRUE, then by the above line RecordNumber!=NULL. if ok==FALSE then
00906     // RecordNumber==NULL. so we don't need to check ok at this point.
00907     return RecordNumber;
00908 }

INT32 FontComponent::WriteUnknownRecord BaseCamelotFilter pFilter,
FontComponentListItem pItem
[private]
 

Definition at line 934 of file fontcomp.cpp.

00935 {
00936     ERROR2IF(ExportInitialised==FALSE, FALSE, "EndExport called when ExportInitialised==FALSE.");
00937     ERROR2IF(pFilter==NULL, 0, "Parameter pFilter==NULL.");
00938     ERROR2IF(pItem==NULL, 0, "Parameter pItem==NULL.");
00939 
00940     ERROR3("Attempt to write an font definition for an unknown file type.");
00941     
00942     return 0;
00943 }


Member Data Documentation

BOOL FontComponent::ExportInitialised [private]
 

Definition at line 251 of file fontcomp.h.

BOOL FontComponent::ImportInitialised [private]
 

Definition at line 263 of file fontcomp.h.

BaseCamelotFilter* FontComponent::pCamFilter [private]
 

Definition at line 283 of file fontcomp.h.

FontComponentList* FontComponent::pFontList
 

Definition at line 267 of file fontcomp.h.

FontManager* FontComponent::pFontManager
 

Definition at line 268 of file fontcomp.h.

BOOL FontComponent::WarnedBefore [private]
 

Definition at line 286 of file fontcomp.h.


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