fontlist.cpp

Go to the documentation of this file.
00001 // $Id: fontlist.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // Implementation code for the font usage list
00100 
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 #include "fontlist.h"
00106 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "node.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 #include "nodetext.h"
00110 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 #include "fontman.h"
00112 
00113 DECLARE_SOURCE("$Revision: 1282 $");
00114 
00115 CC_IMPLEMENT_MEMDUMP(FontListItem, CC_CLASS_MEMDUMP);
00116 CC_IMPLEMENT_MEMDUMP(FontList, CC_CLASS_MEMDUMP);
00117 
00118 // Declare smart memory handling in Debug builds
00119 #define new CAM_DEBUG_NEW
00120 
00121 
00122 /***********************************************************************************************
00123 
00124 >   FontListItem::FontListItem()
00125 
00126     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00127     Created:    20/4/95
00128     Inputs:     -
00129     Returns:    -
00130     Purpose:    Default constructor.
00131 
00132 ***********************************************************************************************/
00133 
00134 FontListItem::FontListItem()
00135 {
00136     FontStyle=0;
00137     FontUsage=0;
00138     Class=FC_UNDEFINED;
00139 }
00140 
00141 /***********************************************************************************************
00142 
00143 >   void FontListItem::Initialise(String_64& String, INT32 Style, FontClass FClass = FC_UNDEFINED)
00144 
00145     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00146     Created:    20/4/95
00147     Inputs:     String  - Typeface name of item
00148                 Style   - &1 for Bold, &2 for Italic
00149                 FClass  - FontClass of item (TrueType, ATM, etc)
00150     Returns:    -
00151     Purpose:    Initalise a fontlist item
00152 
00153 ***********************************************************************************************/
00154 
00155 void FontListItem::Initialise(String_64& String, INT32 Style, FontClass FClass)
00156 {
00157     ENSURE(FontUsage==0, "None NULL FontListItem initialised!");
00158 
00159     FontName=String;
00160     FontStyle=Style;
00161     FontUsage=1;
00162     Class=FClass;
00163 }
00164 
00165 
00166 
00167 /***********************************************************************************************
00168 
00169 >   FontList::FontList()
00170 
00171     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00172     Created:    20/4/95
00173     Inputs:     -
00174     Returns:    -
00175     Purpose:    Default constructor.
00176 
00177 ***********************************************************************************************/
00178 
00179 FontList::FontList()
00180 {
00181 }
00182 
00183 /***********************************************************************************************
00184 
00185 >   FontList::~FontList()
00186 
00187     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00188     Created:    20/4/95
00189     Inputs:     -
00190     Returns:    -
00191     Purpose:    Default destructor, will remove all entries in the font list before it gets
00192                 deleted.
00193 
00194 ***********************************************************************************************/
00195 
00196 FontList::~FontList()
00197 {
00198     TheFontList.DeleteAll();
00199 }
00200 
00201 
00202 
00203 /***********************************************************************************************
00204 
00205 >   BOOL FontList::Build(Document* pDoc)
00206 
00207     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00208     Created:    20/4/95
00209     Inputs:     pDoc = a pointer to the document to build the fontlist for
00210     Returns:    TRUE if the font list was successfully built
00211                 FALSE if not
00212     Purpose:    Builds a list of font names, which are used in this document. Each item in the
00213                 list contains a usage count too.
00214 
00215 ***********************************************************************************************/
00216 
00217 BOOL FontList::Build(Document* pDoc)
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 }
00233 
00234 
00235 
00236 /***********************************************************************************************
00237 
00238 >   BOOL FontList::EnumerateItems(Node* pNode)
00239 
00240     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00241     Created:    20/5/95
00242     Inputs:     pNode = a pointer to a node to start searching from
00243     Outputs:    -
00244     Returns:    TRUE if the whole document tree was searched
00245                 FALSE if failed.
00246     Purpose:    Scans the entire tree from the node given on entry. All fonts used in this
00247                 (sub)tree are compiled into a list. Font attributes of bold and italic are
00248                 taken into account. Separate records are created if the same fontname has
00249                 different style attributes applied in different areas of the tree. A usage
00250                 count is also kept of every font found.
00251 
00252 ***********************************************************************************************/
00253 
00254 BOOL FontList::EnumerateItems(Node* pNode)
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 }
00324 
00325 
00326 
00327 /***********************************************************************************************
00328 
00329 >   FontListItem* FontList::FindFontMatch(const String_64& FName, INT32 style, FontClass Class = FC_UNDEFINED)
00330 
00331     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00332     Created:    5/12/94
00333     Inputs:     fname = a font name to search for
00334                 style = a style word
00335                         b0 = 1 then bold is current
00336                         b1 = 1 then italic is current
00337                 Class = Font class of item
00338     Outputs:    -
00339     Returns:    NULL if unable to find a match for this font name in the list
00340     Purpose:    Trys to find the font name in our list
00341 
00342 ***********************************************************************************************/
00343 
00344 FontListItem* FontList::FindFontMatch(const String_64& fname, INT32 style, FontClass Class)
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 }
00359 
00360 
00361 /***********************************************************************************************
00362 
00363 >   BOOL FontList::AddItem(FontListItem* pFListItem)
00364 
00365     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00366     Created:    5/12/94
00367     Inputs:     pFListItem = ptr to a font item to add to our list
00368     Outputs:    -
00369     Returns:    TRUE if successfully initialises, FALSE otherwise
00370     Purpose:    Adds a font list item to our list
00371 
00372 ***********************************************************************************************/
00373 
00374 BOOL FontList::AddItem(FontListItem* pFListItem)
00375 {
00376     TheFontList.AddTail(pFListItem);
00377     return TRUE;
00378 }
00379 
00380 
00381 /***********************************************************************************************
00382 
00383 >   FontListItem* FontList::GetFirstItem()
00384 
00385     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00386     Created:    20/4/95
00387     Inputs:     -
00388     Outputs:    -
00389     Returns:    First Font object in the list, or NULL if the list is empty
00390     Purpose:    Lets you get the first Font object in the list
00391 
00392 ***********************************************************************************************/
00393 
00394 FontListItem* FontList::GetFirstItem()
00395 {
00396     return ((FontListItem*)TheFontList.GetHead());
00397 }
00398 
00399 /***********************************************************************************************
00400 
00401 >   FontListItem* FontList::GetNextItem(FontListItem* pCurrFontItem)
00402 
00403     Author:     Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com>
00404     Created:    20/4/95
00405     Inputs:     pCurrFontItem = ptr the current font item in the list
00406     Outputs:    -
00407     Returns:    Returns the next font item after pCurrFontItem, 
00408                 or NULL if there isn't a next one
00409     Purpose:    Lets you get the next font item in the list
00410 
00411 ***********************************************************************************************/
00412 
00413 FontListItem* FontList::GetNextItem(FontListItem* pCurrFontItem)
00414 {
00415     return ((FontListItem*)TheFontList.GetNext(pCurrFontItem));
00416 }
00417 
00418 
00419 
00420 
00421 /*
00422 BOOL KernCode::ExportRender(RenderRegion* pRegion)
00423 {
00424 #if EXPORT_TEXT
00425     if (pRegion->IsKindOf(CC_RUNTIME_CLASS(EPSRenderRegion)))
00426     {
00427         EPSExportDC *pDC=(EPSExportDC*)pRegion->GetRenderDC();
00428 
00429         // Use illustrator 3.0 compatible token.
00430         // Any vertical movement is done by BaselineShift
00431         INT32 autokern = 0;
00432         pDC->OutputValue(autokern);
00433         pDC->OutputValue(Value.x);
00434         pDC->OutputToken("Tk");
00435         pDC->OutputNewLine();
00436         return TRUE;
00437     }
00438 #endif
00439     return FALSE;
00440 }
00441 */

Generated on Sat Nov 10 03:45:21 2007 for Camelot by  doxygen 1.4.4