crthumb.cpp

Go to the documentation of this file.
00001 // $Id: crthumb.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 // The "Create Font Thumbnails..." debug menu item
00099 
00100 #include "camtypes.h"
00101 
00102 //#include "pathname.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00103 //#include "barsdlgs.h"     //For _R(IDD_BARCONTROLSTORE)
00104 
00105 #include "crthumb.h"
00106 #include "sgfonts.h"        //For FontGallery
00107 
00108 #include "urlimp.h"
00109 #include "fileutil.h"
00110 
00111 //#include "resimmap.h"     //For _R(IDS_HTMLIMPORT_FILEDOWNLOAD)
00112 #include "urldlg.h"         //For URLImportDlg
00113 
00114 #include "gendwnd.h"        //For the download operation
00115 //#include "webster.h"
00116 
00117 #include "filedlgs.h"
00118 
00119 #include "pngfiltr.h"
00120 
00121 #include "sgindgen.h"
00122 
00123 #include "sgfonts.h"    //class SGTTFItem
00124 #include "camelot.h"
00125 #include "menucmds.h"
00126 
00127 extern CCamApp NEAR theApp;
00128 
00129 #ifdef _DEBUG
00130 CC_IMPLEMENT_DYNCREATE(OpCreateFontThumbnails, OpMenuImport)
00131 CC_IMPLEMENT_DYNCREATE(OpConvertFileFormats, Operation)
00132 BOOL OpConvertFileFormats::active = FALSE;
00133 
00134 /********************************************************************************************
00135 
00136     How to use this code to create font thumbnails given a folder of TTF fonts
00137 
00138 ********************************************************************************************/
00139 
00140 
00141 /********************************************************************************************
00142 
00143 >   BOOL OpCreateFontThumbnails::Init()
00144 
00145     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00146     Created:    6/6/97
00147     Returns:    TRUE if worked, FALSE if failed (out of memory)
00148     Purpose:    Declares the OpDescriptor. This uses some IDs it shouldn't, but it doesn't
00149                 matter much because this is a debug command.
00150     Errors:     -
00151 
00152 ********************************************************************************************/
00153 
00154 BOOL OpCreateFontThumbnails::Init()
00155 {
00156     return RegisterOpDescriptor(
00157                                     0,                          // Tool ID
00158                                     _R(IDS_CREATEFONTTHUMBNAILS),                   // String resource ID
00159                                     CC_RUNTIME_CLASS(OpCreateFontThumbnails),   // Runtime class
00160                                     OPTOKEN_CREATEFONTTHUMBNAILS,           // Token string
00161                                     GetState,                   // GetState function
00162                                     0,                          // help ID
00163                                     _R(IDBBL_CREATEFONTTHUMBNAILS),         // bubble help
00164                                     _R(IDD_BARCONTROLSTORE),        // resource ID
00165                                     _R(IDC_FILEURLIMPORT),              // control ID
00166                                     SYSTEMBAR_FILE,             // Bar ID
00167                                     TRUE,                       // Receive system messages
00168                                     FALSE,                      // Smart duplicate operation
00169                                     TRUE,                       // Clean operation
00170                                     0,      // String for one copy only error
00171                                     0
00172                                 );
00173     
00174 }
00175 
00176 BOOL OpConvertFileFormats::Init()
00177 {
00178     return RegisterOpDescriptor(
00179                                     0,                          // Tool ID
00180                                     _R(IDS_CONVERTFILEFORMATS),                 // String resource ID
00181                                     CC_RUNTIME_CLASS(OpConvertFileFormats),     // Runtime class
00182                                     OPTOKEN_CONVERTFILEFORMATS,         // Token string
00183                                     GetState,                   // GetState function
00184                                     0,                          // help ID
00185                                     _R(IDBBL_CONVERTFILEFORMATS),           // bubble help
00186                                     _R(IDD_BARCONTROLSTORE),        // resource ID
00187                                     _R(IDC_FILEURLIMPORT),              // control ID
00188                                     SYSTEMBAR_FILE,             // Bar ID
00189                                     TRUE,                       // Receive system messages
00190                                     FALSE,                      // Smart duplicate operation
00191                                     TRUE,                       // Clean operation
00192                                     0,      // String for one copy only error
00193                                     0
00194                                 );
00195     
00196 }
00197 
00198 /********************************************************************************************
00199 
00200 >   void OpCreateFontThumbnails::Do(OpDescriptor*)
00201 
00202     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00203     Created:    6/6/97
00204     Purpose:    Imports a URL into the current document
00205     Errors:     -
00206 
00207 ********************************************************************************************/
00208 
00209 void OpCreateFontThumbnails::Do(OpDescriptor*)
00210 {
00211     //First we put up a CFileDialog to allow the user to enter
00212     //the path to the index file
00213     CFileDialog dlgIndex(TRUE);
00214 
00215     dlgIndex.DoModal();
00216 
00217     PathName pthIndex=(const TCHAR*) dlgIndex.GetPathName();
00218 
00219     //Now we're going to open that file
00220     CCDiskFile fileIndex(1024, FALSE, TRUE);
00221 
00222     fileIndex.open(pthIndex, ios::in | ios::binary);
00223 
00224     //And get it ready for lexical reading...
00225     fileIndex.InitLexer();
00226 
00227     fileIndex.SetDelimiters("\r\n");        
00228     fileIndex.SetCommentMarker('#');
00229     fileIndex.SetWhitespace("\t");
00230     
00231     //This variable will point to the buffer that has been read in
00232     const TCHAR* TokenBuf = fileIndex.GetTokenBuf();
00233 
00234     //And this indicates the sort of token that has been read in
00235     LexTokenType tokType=TOKEN_NORMAL;
00236 
00237     //Now, start reading from the file until we reach the "START" token
00238     //or we reach the end of the file
00239     while (tokType != TOKEN_EOF && camStrcmp(TokenBuf, "START")!=0)
00240     {
00241         //Get a token frm the file
00242         fileIndex.GetToken();
00243 
00244         //Find out what sort of token it is
00245         tokType = fileIndex.GetTokenType();
00246     }
00247 
00248     //Now read until we reach the end of the file
00249     while (tokType!=TOKEN_EOF)
00250     {
00251         //Get a token frm the file
00252         fileIndex.GetToken();
00253 
00254         //Find out what sort of token it is
00255         tokType = fileIndex.GetTokenType();
00256 
00257         //Right, now let's find the first comma in the string
00258         TCHAR* pcFindPtr=camStrchr(TokenBuf, ',');
00259 
00260         //If we've found one
00261         if (pcFindPtr)
00262         {
00263             //Then move the string pointer on by two characters
00264             pcFindPtr=camStrninc(pcFindPtr, 2);
00265 
00266             //And if we didn't go past the end of the string
00267             if (pcFindPtr && *pcFindPtr!='\0')
00268             {
00269                 //Then pcFindPtr should now be pointing to the font name
00270 
00271                 //Then find a pointer to the next comma in the string
00272                 TCHAR* pcSecondComma=camStrchr(pcFindPtr, ',');
00273 
00274                 if (!pcSecondComma)
00275                     break;
00276 
00277                 //And copy everything from the pcFindPtr (inclusive) to that second comma
00278                 //(exclusive) into a new string
00279                 String_256 strFontName;
00280 
00281                 while (pcFindPtr && pcFindPtr!=pcSecondComma && *pcFindPtr!='\0')
00282                 {
00283                     strFontName+=(*pcFindPtr);
00284                     pcFindPtr=camStrinc(pcFindPtr);
00285                 }
00286 
00287                 //Now we want to find the ID of the font. That will occur after the
00288                 //second comma. So set pcFindPtr so it points to two characters
00289                 //after the second comma
00290                 pcFindPtr=camStrninc(pcSecondComma, 2);
00291 
00292                 //And copy everything from the pcFindPtr (inclusive) to the third comma
00293                 //(exclusive) into a new string
00294                 String_256 strFontID;
00295 
00296                 while (pcFindPtr && *pcFindPtr!=',' && *pcFindPtr!='\0')
00297                 {
00298                     strFontID+=(*pcFindPtr);
00299                     pcFindPtr=camStrinc(pcFindPtr);
00300                 }
00301 
00302                 //And translate that string into a number
00303                 INT32 lFontID=atol(strFontID);
00304 
00305                 //Now find the font item with that name
00306                 SGDisplayPreviewFonts* pFontItem=FindFontFromName(strFontName);
00307 
00308                 //And if there is a font with that name
00309                 if (pFontItem)
00310                 {
00311                     //Then create three bitmap thumbnails from that font and
00312                     //save them in the same directory as the index
00313                     CreateThumbnailFiles(pFontItem, lFontID, pthIndex);
00314                 }
00315             }
00316         }
00317     }
00318 }
00319 
00320 
00321 
00322 /********************************************************************************************
00323 
00324 >   void OpConvertFileFormats::Do(OpDescriptor*)
00325 
00326     Author:     Chris_Snook (Xara Group Ltd) <camelotdev@xara.com>
00327     Created:    29/8/2000
00328     Purpose:    Converts all files of a one format into another format (e.g.  *.art => *.xar)
00329     Errors:     -
00330 
00331     NOTE:  The first three lines of this function are REALLY important!  You should do as their
00332     comments say ....  ALSO the code only works for a single directory (i.e.  it does NOT scan
00333     sub directories).  To do this, you will have to ammend this routine.
00334 
00335 ********************************************************************************************/
00336 
00337 void OpConvertFileFormats::Do(OpDescriptor*)
00338 {
00339     ERROR3 ("Please read the following comments BEFORE using this op!");    // comment this out to use the op
00340 
00343     
00344     // set up the search path, file util allows us just to pass the path/*.xar
00345     String_256 SearchPath = TEXT ("d:\\clipart\\xara\\");       // YOU MUST CHANGE THIS PATH
00346     
00347     String_256 FileSpecifier = SearchPath;                      // YOU MUST CHANGE THIS EXTENSION
00348                 FileSpecifier += TEXT("*.art");
00349     String_256 FileSpecifier2 = TEXT("xar");                    // YOU MUST CHANGE THIS EXTENSION
00350 
00353 
00354     BOOL ok = FileUtil::StartFindingFiles(&FileSpecifier);
00355     active = TRUE;
00356     String_256 Filename;
00357     while (ok)
00358     {
00359         // fileutil will give us the next filename
00360         ok = FileUtil::FindNextFile(&Filename);
00361         String_256 FilePath = SearchPath;
00362         FilePath += Filename;
00363         PathName Path (FilePath);
00364 
00365         if (ok)
00366         {
00367             CDocument* pDoc = theApp.OpenDocumentFile((TCHAR*)FilePath);
00368             if (pDoc!=NULL)
00369             {
00370                 // Make sure that the files name is sensible
00371                 theApp.MakeDocumentNative(pDoc, &Path);
00372                 
00373                 Path.SetType (FileSpecifier2);
00374                 String_256 newPath = Path.GetPath ();
00375                 pDoc->DoSave ((TCHAR*) newPath, TRUE);
00376 
00377                 FileCloseAction ();
00378             }
00379         }
00380     }
00381     active = FALSE;
00382     FileUtil::StopFindingFiles ();
00383 }
00384 
00385 
00386 
00387 /********************************************************************************************
00388 
00389 >   void OpCreateFontThumbnails::CreateThumbnailFiles(SGDisplayPreviewFonts* pFontItem, INT32 lFontID, PathName pthIndex)
00390 
00391     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00392     Created:    6/6/97
00393     Purpose:    Creates the thumbnail files
00394     Errors:     -
00395     Notes:      Karim 08/12/00 - modified to take SGDisplayPreviewFonts* instead, for ATM.
00396 
00397 ********************************************************************************************/
00398 
00399 void OpCreateFontThumbnails::CreateThumbnailFiles(SGDisplayPreviewFonts* pFontItem, INT32 lFontID, PathName pthIndex)
00400 {
00401     //We want to create three thumbnails: large, medium and small
00402     
00403     //So for each of the three display modes in the gallery...
00404     for (INT32 iDMode=0; iDMode<3; iDMode++)
00405     {
00406         //Set the display mode into the gallery
00407         SGDisplayPreviewFonts::DMode=iDMode;
00408 
00409         //Now create the thumbnail as a kernel bitmap
00410         KernelBitmap* pThisBitmap=NULL;
00411 
00412         pFontItem->CreateThumbnail(&pThisBitmap);
00413 
00414         //Now let's get a pointer to the PNG export filter.
00415         PNGFilter* pPNGFilter=(PNGFilter*) Filter::FindFilterFromID(FILTERID_PREVIEW_PNG);
00416                 
00417         if (pPNGFilter==NULL)
00418             return;
00419 
00420         //Now create a file for the thumbnail
00421         CCDiskFile fileThumb(1024, FALSE, TRUE);
00422 
00423         //And get a path to save the thumbnail into
00424         TCHAR buf[256];
00425 
00426         switch (iDMode)
00427         {
00428                 case 0:
00429                     wsprintf(buf, TEXT("F%05liL.png"), lFontID);
00430                     break;
00431                 case 2:
00432                     wsprintf(buf, TEXT("F%05liS.png"), lFontID);
00433                     break;
00434                 case 1:
00435                 case 3:
00436                 default:
00437                     wsprintf(buf, TEXT("F%05liM.png"), lFontID);
00438                     break;
00439         }
00440                         
00441         PathName pthThumb=pthIndex;
00442 
00443         String_256 strThumbFile=buf;
00444 
00445         pthThumb.SetFileNameAndType(strThumbFile);
00446 
00447         //Now export the bitmap to that file
00448         pPNGFilter->DoExportBitmap(this, &fileThumb, &pthThumb, pThisBitmap);
00449 
00450         //And delete the bitmap
00451         if (pThisBitmap)
00452             delete pThisBitmap;
00453     }
00454 }
00455 
00456 
00457 /********************************************************************************************
00458 
00459 >   SGDisplayPreviewFonts* OpCreateFontThumbnails::FindFontFromName(String_256& strName)
00460 
00461     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00462     Created:    6/6/97
00463     Purpose:    Gets a pointer to the first font with the same name as that passed
00464 
00465                 Note that to find the font with the same name as the 
00466     Errors:     -
00467 
00468 ********************************************************************************************/
00469 
00470 /*
00471 Clarifying note: 29/9/2000 DY.  I've just spent the day trying to make some font thumnails so I
00472 include here the notes about what to do:
00473 
00474 A quick guide to creating thumbnails for True Type fonts, using a debug
00475 version of CorelXARA.
00476 
00477 The first point to make is: this system is hacked. My brief in writing this
00478 system was to get it done as quickly as possible and not worry about people
00479 using it in the future. For "people using it in the future", read "you".
00480 8-)
00481 
00482 But, briefly speaking, this is how you do it.
00483 
00484 1. First get a folder of TTF files (that is, font files). Don't install
00485 them: instead, just put them in a separate folder somewhere.
00486 
00487 2. Now you must add these files into the font gallery. This is not easy and
00488 works as follows.
00489 
00490 a. Go to winoil\sgindgen.cpp line 51, which reads:
00491 
00492 BOOL GenerateIndexFile::CreateFontIndexes = FALSE;
00493 
00494  And change the FALSE to TRUE. Build a debug version of CorelXARA
00495 
00496 b. Now run your debug version and open the Font Gallery. Click "Disc
00497 fonts..." and locate your folder. You should get the error message:
00498 
00499 "The folder 'D:\Fonts' doesn't have a Font index.Would you like to create a
00500 new index for the folder?..."
00501 
00502 If you haven't followed step 2a, you won't get this message.
00503 
00504 Click "Create".
00505 
00506 Your fonts will be added into the font gallery. However, when you open the
00507 folder, you will see a series of grey boxes instead of the preview bitmaps.
00508 
00509 3. Now to generate the preview bitmaps.
00510 
00511 a. Open the font gallery and open the folder that contains the fonts for
00512 which you want to create bitmaps.
00513 
00514 b. Install all the new fonts so they appear in your Installed fonts folder.
00515 
00516 c. Now go to the Debug menu and choose "Create Font Thumbnails". An open
00517 dialog will appear. Go to the folder with the fonts in and open the
00518 XaraInfo directory within it. Open XaraFont.txt within that directory.
00519 
00520 d. Now go back to the Fonts Gallery and look at the folder of your fonts
00521 again. The preview bitmaps should now be showing.
00522 
00523 e. Scroll through and make sure the preview bitmaps are showing for every
00524 font.
00525 
00526 If they are, you've finished. If not, follow step 4.
00527 
00528 4. The reason some preview bitmaps have not been created is because the
00529 real font names are not the names that the galleries use for the fonts. For
00530 example, the galleries refer to "Calmari Italic" as "CalmarItal".
00531 
00532 I did warn you this was a hack.
00533 
00534 a. Open the file kernel\crthumb.cpp and go to the function
00535 OpCreateFontThumbnails::FindFontFromName. Scroll down until you see the
00536 words "ADD NAMES OF NEW FONTS HERE", at about line 319.
00537 
00538 Take a moment to look at the code and see how it works. This function works
00539 as follows: a name of a font is passed in and a pointer to that font in the
00540 fonts gallery is returned. However, first the name is corrected.
00541 
00542 You're going to have to add two lines of code similar to the following:
00543 
00544 if (strCorrectedName==String_256("CalmarItal"))
00545         strCorrectedName="CalmariItal";
00546 
00547 to correct the name that the function is passed to the name that the
00548 gallery stores.
00549 
00550 b. To find the name that the function is passed (after it's been corrected
00551 for things like spaces and "Italic" has been shortened to "Ital", stick a
00552 breakpoint on line 320:
00553 
00554 if (strCorrectedName==String_256("CacheExtraBold"))
00555         strCorrectedName="CacheExtra";
00556 
00557 Then create some font thumbnails. You'll eventually see the name of your
00558 problem font coming in.
00559 
00560 c. Now stick a breakpoint on line 354:
00561 
00562 String_256 strDescription=pLogFont->lfFaceName;
00563 
00564 And eventually you'll see the name that your problem font is given in the
00565 gallery.
00566 
00567 d. Now actually add the two lines of code to correct the name of the font.
00568 
00569 5. Repeat step 3, debugging the code until all the preview bitmaps are
00570 created.
00571 
00572 */
00573 
00574 
00575 
00576 SGDisplayPreviewFonts* OpCreateFontThumbnails::FindFontFromName(String_256& strName)
00577 {
00578     //First get a pointer to the fonts gallery
00579     FontsSGallery* pGallery=FontsSGallery::ThisGallery;
00580 
00581     if (!pGallery)
00582         return NULL;
00583 
00584     //And a pointer to the display tree
00585     SGDisplayRoot* pTree=pGallery->GetDisplayTree();
00586 
00587     if (!pTree)
00588         return NULL;
00589 
00590     //Welcome to Hack City! Have a nice day...
00591 
00592     //Now we need to remove all the spaces from strName...it's a long story why
00593     String_256 strCorrectedName=strName;
00594 
00595     INT32 iSpace=strCorrectedName.FindNextChar(' ');
00596 
00597     while(iSpace>=0)
00598     {
00599         strCorrectedName.Remove(iSpace, 1);
00600         iSpace=strCorrectedName.FindNextChar(' ');
00601     }
00602 
00603     //And let's all replace all instances of the word italic with "Ital". Another long story.
00604     INT32 iItalic=strCorrectedName.Sub(String_256("Italic"));
00605 
00606     while(iItalic>=0)
00607     {
00608         strCorrectedName.Remove(iItalic, 6);
00609         strCorrectedName.Insert(&String_256("Ital"), iItalic);
00610         iItalic=strCorrectedName.Sub(String_256("Italic"));
00611     }
00612 
00613     //Now let's check for two particular fonts that have strange description strings
00614     if (strCorrectedName==String_256("CacheExtraBold"))
00615         strCorrectedName="CacheExtra";
00616 
00617     else if (strCorrectedName==String_256("CalmarItal"))
00618              strCorrectedName="CalmariItal";
00619 
00620     else if (strCorrectedName==String_256("SerpentineDBolItal"))
00621              strCorrectedName="SerpentineDBol";
00622 
00623     else if (strCorrectedName==String_256("TimesNewRoman"))
00624              strCorrectedName="Times New Roman";
00625 
00626     else if (strCorrectedName==String_256("AbbessRegular"))
00627              strCorrectedName= "Abbess";
00628 
00629     else if (strCorrectedName==String_256("BalthazarRegular"))
00630              strCorrectedName= "Balthazar";
00631 
00632     else if (strCorrectedName==String_256("KlingBoldBold"))
00633              strCorrectedName= "KlingBold";
00634 
00635     else if (strCorrectedName==String_256("MargaretRegular"))
00636              strCorrectedName= "Margaret";
00637 
00638     else if (strCorrectedName==String_256("PhrasticMediumRegular"))
00639              strCorrectedName= "PhrasticMedium";
00640 
00641     else if (strCorrectedName==String_256("TarzanRegular"))
00642              strCorrectedName= "Tarzan";
00643 
00644     else if (strCorrectedName==String_256("BorealisRegular"))
00645              strCorrectedName= "Borealis";
00646 
00647     else if (strCorrectedName.Sub(String_256("FontBank")) == 0)
00648              strCorrectedName.Remove(0, 8);
00649 
00650     else if (strCorrectedName==String_256("GaramondAmericanRegular"))
00651              strCorrectedName= "GaramondAmerican";
00652 
00653     //Select everything in the gallery - (bodge!)
00654     pGallery->SelectItems(TRUE);
00655 
00656     //Get the first selected item
00657     SGDisplayNode* pThisItem = pTree->FindNextSelectedItem(NULL);       
00658 
00659     static BOOL skipall = FALSE;
00660 
00661     //And while we are looking at an item
00662     while (pThisItem)
00663     {
00664         
00665         if (pThisItem->IsKindOf(CC_RUNTIME_CLASS(SGTTFItem)))
00666         {
00667             //Then cast it into a True Type font pointer
00668             SGTTFItem* pTTFItem=(SGTTFItem*) pThisItem;
00669         
00670             //Now we need to get the cached font description for that
00671             //item
00672             LOGFONT* pLogFont=pTTFItem->CachedLogFont;
00673 
00674             if (!pLogFont)
00675                 continue;
00676 
00677             String_256 strDescription=pLogFont->lfFaceName;
00678 
00679             //And if that description is the one we're looking for
00680             if (camStrncmp(strDescription, strCorrectedName, strCorrectedName.Length())==0)
00681             {
00682                 //Return that item
00683                 return pTTFItem;
00684             }
00685 
00686             if (!skipall)
00687             {
00688                 // possible match up - does our name of the font start with the font's own description.
00689                 if (strCorrectedName.Sub(strDescription) == 0)
00690                 {
00691                     // we must only match up GaramondAmerican with itself, not with plain Garamond.
00692                     if (strCorrectedName==String_256("GaramondAmerican"))
00693                     {
00694                         if (strDescription==String_256("GaramondAmerican"))
00695                         {
00696                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00697                             return pTTFItem;
00698                         }
00699                     }
00700 
00701                     // is this a bold-italic font?
00702                     else if (camStrstr(strCorrectedName, "BoldItal") != 0)
00703                     {
00704                         if (camStrstr(strDescription, "BoldItal") != 0)
00705                         {
00706                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00707                             return pTTFItem;
00708                         }
00709                     }
00710 
00711                     // is this a heavy-italic font?
00712                     else if (camStrstr(strCorrectedName, "HeavyItal") != 0)
00713                     {
00714                         if (camStrstr(strDescription, "HeavyItal") != 0)
00715                         {
00716                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00717                             return pTTFItem;
00718                         }
00719                     }
00720 
00721                     // is this a heavy font?
00722                     else if (camStrstr(strCorrectedName, "Heavy") != 0)
00723                     {
00724                         if (camStrstr(strDescription, "Heavy") != 0)
00725                         {
00726                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00727                             return pTTFItem;
00728                         }
00729                     }
00730 
00731                     // is this a bold font?
00732                     else if (camStrstr(strCorrectedName, "Bold") != 0)
00733                     {
00734                         if (camStrstr(strDescription, "Bold") != 0)
00735                         {
00736                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00737                             return pTTFItem;
00738                         }
00739                     }
00740 
00741                     // is this an italic font?
00742                     else if (camStrstr(strCorrectedName, "Ital") != 0)
00743                     {
00744                         if (camStrstr(strDescription, "Ital") != 0)
00745                         {
00746                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00747                             return pTTFItem;
00748                         }
00749                     }
00750 
00751                     // is this an engraved font?
00752                     else if (camStrstr(strCorrectedName, "Engraved") != 0)
00753                     {
00754                         if (camStrstr(strDescription, "Engraved") != 0)
00755                         {
00756                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00757                             return pTTFItem;
00758                         }
00759                     }
00760 
00761                     // not italic or engraved.
00762                     else
00763                     {
00764                         TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00765                         return pTTFItem;
00766                     }
00767                 }
00768             }
00769         }
00770 
00771         else if (pThisItem->IsKindOf(CC_RUNTIME_CLASS(SGATMItem)))
00772         {
00773             //Then cast it into an ATM font pointer
00774             SGATMItem* pATMItem=(SGATMItem*) pThisItem;
00775         
00776             //Now we need to get the cached font description for that
00777             //item
00778             LOGFONT* pLogFont=pATMItem->CachedLogFont;
00779 
00780             if (!pLogFont)
00781                 continue;
00782 
00783             String_256 strDescription=pLogFont->lfFaceName;
00784 
00785             //And if that description is the one we're looking for
00786             if (camStrncmp(strDescription, strCorrectedName, strCorrectedName.Length())==0)
00787             {
00788                 //Return that item
00789                 return pATMItem;
00790             }
00791 
00792             if (!skipall)
00793             {
00794                 // possible match up - does our name of the font start with the font's own description.
00795                 if (strCorrectedName.Sub(strDescription) == 0)
00796                 {
00797                     // we must only match up GaramondAmerican with itself, not with plain Garamond.
00798                     if (strCorrectedName==String_256("GaramondAmerican"))
00799                     {
00800                         if (strDescription==String_256("GaramondAmerican"))
00801                         {
00802                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00803                             return pATMItem;
00804                         }
00805                     }
00806 
00807                     // is this a bold-italic font?
00808                     else if (camStrstr(strCorrectedName, "BoldItal") != 0)
00809                     {
00810                         if (camStrstr(strDescription, "BoldItal") != 0)
00811                         {
00812                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00813                             return pATMItem;
00814                         }
00815                     }
00816 
00817                     // is this a heavy-italic font?
00818                     else if (camStrstr(strCorrectedName, "HeavyItal") != 0)
00819                     {
00820                         if (camStrstr(strDescription, "HeavyItal") != 0)
00821                         {
00822                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00823                             return pATMItem;
00824                         }
00825                     }
00826 
00827                     // is this a heavy font?
00828                     else if (camStrstr(strCorrectedName, "Heavy") != 0)
00829                     {
00830                         if (camStrstr(strDescription, "Heavy") != 0)
00831                         {
00832                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00833                             return pATMItem;
00834                         }
00835                     }
00836 
00837                     // is this a bold font?
00838                     else if (camStrstr(strCorrectedName, "Bold") != 0)
00839                     {
00840                         if (camStrstr(strDescription, "Bold") != 0)
00841                         {
00842                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00843                             return pATMItem;
00844                         }
00845                     }
00846 
00847                     // is this an italic font?
00848                     else if (camStrstr(strCorrectedName, "Ital") != 0)
00849                     {
00850                         if (camStrstr(strDescription, "Ital") != 0)
00851                         {
00852                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00853                             return pATMItem;
00854                         }
00855                     }
00856 
00857                     // is this an engraved font?
00858                     else if (camStrstr(strCorrectedName, "Engraved") != 0)
00859                     {
00860                         if (camStrstr(strDescription, "Engraved") != 0)
00861                         {
00862                             TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00863                             return pATMItem;
00864                         }
00865                     }
00866 
00867                     // not italic or engraved.
00868                     else
00869                     {
00870                         TRACEALL( _T("Matched %s with %s\n"), (TCHAR*)strCorrectedName, (TCHAR*)strDescription);
00871                         return pATMItem;
00872                     }
00873                 }
00874             }
00875         }
00876 
00877         //And move on to the next item
00878         pThisItem = pTree->FindNextSelectedItem(pThisItem);     
00879 
00880     }
00881 
00882     //We haven't found anything. So return NULL.
00883     return NULL;
00884 }
00885 
00886 
00887 
00888 /********************************************************************************************
00889 
00890 >   OpCreateFontThumbnails::OpCreateFontThumbnails()
00891 
00892     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00893     Created:    6/6/97
00894     Purpose:    Default constructor
00895 
00896 ********************************************************************************************/
00897 
00898 OpCreateFontThumbnails::OpCreateFontThumbnails()
00899 {
00900     //
00901 }
00902 
00903 OpConvertFileFormats::OpConvertFileFormats()
00904 {
00905     //
00906 }
00907 
00908 
00909 
00910 /********************************************************************************************
00911 
00912 >   OpState OpCreateFontThumbnails::GetState(String_256*, OpDescriptor*)
00913 
00914     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00915     Created:    6/6/97
00916     Purpose:    This item is always available, so long as a document is visible.
00917 
00918 ********************************************************************************************/
00919 
00920 OpState OpCreateFontThumbnails::GetState(String_256*, OpDescriptor*)
00921 {
00922     OpState OpSt;
00923 
00924     OpSt.Greyed=FALSE; 
00925 
00926     return OpSt;
00927 }
00928 
00929 OpState OpConvertFileFormats::GetState(String_256*, OpDescriptor*)
00930 {
00931     OpState OpSt;
00932 
00933     OpSt.Greyed=FALSE; 
00934 
00935     return OpSt;
00936 }
00937 
00938 #endif //DEBUG

Generated on Sat Nov 10 03:44:55 2007 for Camelot by  doxygen 1.4.4