FontList Class Reference

A class which can be used to create a font usage list. Create an instance of this class and pass its Build() function a particular document pointer. The function will create a list of used fonts in that particular document, each item of which will contain a font name and usage count. More...

#include <fontlist.h>

List of all members.

Public Member Functions

 FontList ()
 Default constructor.
 ~FontList ()
 Default destructor, will remove all entries in the font list before it gets deleted.
BOOL Build (Document *pDoc)
 Builds a list of font names, which are used in this document. Each item in the list contains a usage count too.
BOOL AddItem (FontListItem *pFontListObj)
 Adds a font list item to our list.
FontListItemGetFirstItem ()
 Lets you get the first Font object in the list.
FontListItemGetNextItem (FontListItem *pCurrItem)
 Lets you get the next font item in the list.
FontListItemFindFontMatch (const String_64 &FName, INT32 style, FontClass Class=FC_UNDEFINED)
 Trys to find the font name in our list.

Private Member Functions

 CC_DECLARE_MEMDUMP (FontList)
BOOL EnumerateItems (Node *pNode)
 Scans the entire tree from the node given on entry. All fonts used in this (sub)tree are compiled into a list. Font attributes of bold and italic are taken into account. Separate records are created if the same fontname has different style attributes applied in different areas of the tree. A usage count is also kept of every font found.

Private Attributes

List TheFontList
CCAttrMap AppliedAtts


Detailed Description

A class which can be used to create a font usage list. Create an instance of this class and pass its Build() function a particular document pointer. The function will create a list of used fonts in that particular document, each item of which will contain a font name and usage count.

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

Definition at line 162 of file fontlist.h.


Constructor & Destructor Documentation

FontList::FontList  ) 
 

Default constructor.

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

Definition at line 179 of file fontlist.cpp.

00180 {
00181 }

FontList::~FontList  ) 
 

Default destructor, will remove all entries in the font list before it gets deleted.

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

Definition at line 196 of file fontlist.cpp.

00197 {
00198     TheFontList.DeleteAll();
00199 }


Member Function Documentation

BOOL FontList::AddItem FontListItem pFListItem  ) 
 

Adds a font list item to our list.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/12/94
Parameters:
pFListItem = ptr to a font item to add to our list [INPUTS]
- [OUTPUTS]
Returns:
TRUE if successfully initialises, FALSE otherwise

Definition at line 374 of file fontlist.cpp.

00375 {
00376     TheFontList.AddTail(pFListItem);
00377     return TRUE;
00378 }

BOOL FontList::Build Document pDoc  ) 
 

Builds a list of font names, which are used in this document. Each item in the list contains a usage count too.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/4/95
Parameters:
pDoc = a pointer to the document to build the fontlist for [INPUTS]
Returns:
TRUE if the font list was successfully built FALSE if not

Definition at line 217 of file fontlist.cpp.

00218 {
00219     ERROR2IF(pDoc==NULL,FALSE,"FontList::Build passed a NULL document");
00220 
00221     // Delete all previous entries
00222     TheFontList.DeleteAll();
00223 
00224     Node* pNode = pDoc->GetFirstNode();
00225     ENSURE(pNode != NULL,"No first node!");
00226     if (!EnumerateItems(pNode))
00227     {
00228         TheFontList.DeleteAll();
00229         return FALSE;
00230     }
00231     return TRUE;
00232 }

FontList::CC_DECLARE_MEMDUMP FontList   )  [private]
 

BOOL FontList::EnumerateItems Node pNode  )  [private]
 

Scans the entire tree from the node given on entry. All fonts used in this (sub)tree are compiled into a list. Font attributes of bold and italic are taken into account. Separate records are created if the same fontname has different style attributes applied in different areas of the tree. A usage count is also kept of every font found.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/5/95
Parameters:
pNode = a pointer to a node to start searching from [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the whole document tree was searched FALSE if failed.

Definition at line 254 of file fontlist.cpp.

00255 {
00256     while (pNode!=NULL)
00257     {
00258         if (IS_A(pNode,TextChar))
00259         {
00260             TextChar* pChar = (TextChar*)pNode;
00261             AppliedAtts.RemoveAll();
00262 
00263             if (pChar->FindAppliedAttributes(&AppliedAtts))
00264             {
00265                 void* pFontName;
00266 
00267                 if( AppliedAtts.Lookup( CC_RUNTIME_CLASS(AttrTxtFontTypeface), pFontName ) )
00268                 {
00269                     void *pBold, *pItalic;
00270                     INT32 style=0;
00271 
00272                     if( AppliedAtts.Lookup( CC_RUNTIME_CLASS(AttrTxtBold), pBold ) )
00273                     {
00274                         AttrTxtBold* pBoldAttr = (AttrTxtBold*) pBold;
00275                         TxtBoldAttribute* pAttr = &(pBoldAttr->Value);
00276                         if ((pAttr) && (pAttr->BoldOn))
00277                             style+=1;
00278                     }
00279 
00280                     if( AppliedAtts.Lookup(  CC_RUNTIME_CLASS(AttrTxtItalic), pItalic ) )
00281                     {
00282                         AttrTxtItalic* pItalicAttr = (AttrTxtItalic*)pItalic;
00283                         TxtItalicAttribute* pAttr = &(pItalicAttr->Value);
00284                         if ((pAttr) && (pAttr->ItalicOn))
00285                             style+=2;
00286                     }
00287 
00288                     AttrTxtFontTypeface* pFontAttr = (AttrTxtFontTypeface*)pFontName;
00289 
00290                     FontClass Class = FONTMANAGER->GetFontClass(pFontAttr->Value.HTypeface);
00291 
00292                     String_64 FName;
00293                     if (FONTMANAGER->GetFontName(pFontAttr->Value.HTypeface, FName))
00294                     {
00295                         FontListItem* FListObj = FindFontMatch(FName,style);
00296                         if (FListObj)
00297                             FListObj->IncUsage();
00298                         else
00299                         {
00300                             FListObj = new FontListItem;
00301                             if (!FListObj)
00302                                 return FALSE;
00303 
00304                             FListObj->Initialise(FName,style, Class);
00305                             AddItem(FListObj);
00306                         }
00307                     }
00308                 }
00309             }
00310         }
00311 
00312         Node* qNode=pNode->FindFirstChild();
00313         if (qNode)
00314         {
00315             if (!EnumerateItems(qNode))
00316                 return FALSE;
00317         }
00318 
00319         pNode=pNode->FindNext();
00320     }
00321 
00322     return TRUE;
00323 }

FontListItem * FontList::FindFontMatch const String_64 fname,
INT32  style,
FontClass  Class = FC_UNDEFINED
 

Trys to find the font name in our list.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/12/94
Parameters:
fname = a font name to search for [INPUTS] style = a style word b0 = 1 then bold is current b1 = 1 then italic is current Class = Font class of item
- [OUTPUTS]
Returns:
NULL if unable to find a match for this font name in the list

Definition at line 344 of file fontlist.cpp.

00345 {
00346     FontListItem* pFont = GetFirstItem();
00347     while (pFont!=NULL)
00348     {
00349         if ( (pFont->GetFontName()==fname) && 
00350              (pFont->GetFontStyle()==style) &&
00351              ((pFont->GetFontClass()==Class) || Class == FC_UNDEFINED)
00352            )
00353             return pFont;
00354 
00355         pFont = GetNextItem(pFont);
00356     }
00357     return NULL;
00358 }

FontListItem * FontList::GetFirstItem  ) 
 

Lets you get the first Font object in the list.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/4/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
First Font object in the list, or NULL if the list is empty

Definition at line 394 of file fontlist.cpp.

00395 {
00396     return ((FontListItem*)TheFontList.GetHead());
00397 }

FontListItem * FontList::GetNextItem FontListItem pCurrFontItem  ) 
 

Lets you get the next font item in the list.

Author:
Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/4/95
Parameters:
pCurrFontItem = ptr the current font item in the list [INPUTS]
- [OUTPUTS]
Returns:
Returns the next font item after pCurrFontItem, or NULL if there isn't a next one

Definition at line 413 of file fontlist.cpp.

00414 {
00415     return ((FontListItem*)TheFontList.GetNext(pCurrFontItem));
00416 }


Member Data Documentation

CCAttrMap FontList::AppliedAtts [private]
 

Definition at line 181 of file fontlist.h.

List FontList::TheFontList [private]
 

Definition at line 180 of file fontlist.h.


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