CorelPaletteFilter Class Reference

Corel Palette file importing class. More...

#include <coplfilr.h>

Inheritance diagram for CorelPaletteFilter:

PaletteFilter Filter ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 CorelPaletteFilter ()
 Constructor.
BOOL Init ()
 Initialisation.
INT32 HowCompatible (PathName &Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
 Examines a file to see how compatable it is with this filter.
virtual BOOL PreImport ()
 Called before import of a Corel palette.
virtual BOOL ImportPalette ()
 Called to import a Corel Palette file (.pal or .cpl).
virtual BOOL PostImport ()
 Called after import of a Corel palette file.

Protected Member Functions

INT32 HowCompatible4 (PathName &Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
 Examines a file to see how compatable it is with this filter - checks for version 3 and 4 .pal files (textual CMYK only).
INT32 HowCompatible5 (PathName &Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
 Examines a file to see how compatable it is with this filter - checks for version 5 .cpl files (binary).
BOOL DoImport4 ()
 Does the import of a Corel .pal file.
BOOL DoImport5 ()

Protected Attributes

INT32 m_FileVersion

Private Member Functions

 CC_DECLARE_DYNAMIC (CorelPaletteFilter)

Detailed Description

Corel Palette file importing class.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
15 03 95

Definition at line 334 of file coplfilr.h.


Constructor & Destructor Documentation

CorelPaletteFilter::CorelPaletteFilter  ) 
 

Constructor.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
15 03 95
Parameters:
As for the Filter class [INPUTS]
Returns:
As for the Filter class
See also:
Filter

Definition at line 1033 of file coplfilr.cpp.

01034 {
01035     // Set up filter descriptions.
01036     FilterName.Load(_R(IDT_CORELPALETTEFILTER_FILTERNAME));
01037     FilterInfo.Load(_R(IDT_CORELPALETTEFILTER_FILTERINFO));
01038     FilterID = FILTERID_CORELPALETTEFILE;
01039 
01040 #ifndef STANDALONE
01041     Flags.CanImport = TRUE;
01042     Flags.CanExport = FALSE;
01043 #else
01044     Flags.CanImport = FALSE;
01045     Flags.CanExport = FALSE;
01046 #endif
01047 
01048 #ifndef DO_EXPORT
01049     Flags.CanExport = FALSE;
01050 #endif
01051 
01052     m_FileVersion = CPL_FVU;
01053 }


Member Function Documentation

CorelPaletteFilter::CC_DECLARE_DYNAMIC CorelPaletteFilter   )  [private]
 

BOOL CorelPaletteFilter::DoImport4  )  [protected]
 

Does the import of a Corel .pal file.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
15 03 95
Parameters:
As for the Filter class [INPUTS]
Returns:
As for the Filter class

Definition at line 1265 of file coplfilr.cpp.

01266 {
01267     StartPercentage();
01268 
01269     // init lex handling of the file
01270     if (!m_pImportFile->InitLexer())
01271         return FALSE;
01272 
01273     INT32 count = 0;            // count of colours so far
01274     while (!m_pImportFile->eof())
01275     {
01276         // check file is OK
01277         if (m_pImportFile->bad())
01278             return FALSE;
01279 
01280         // Read a token
01281         m_pImportFile->GetLineToken();
01282         const TCHAR* Line = m_pImportFile->GetTokenBuf();
01283 
01284         // is it a quoted name?
01285         if (Line[0] != '"')                 
01286             continue;
01287 
01288         // extract the string name
01289         String_32 ColName;
01290         INT32 l = 1;
01291         while (Line[l] != '"' && l < CPF_MAX_COLNAME_SIZE)
01292         {
01293             ((TCHAR*)ColName)[l - 1] = Line[l];
01294             l++;
01295         }
01296         ((TCHAR*)ColName)[l - 1] = '\0';                // terminate it nicely
01297 
01298         // find the end of the string name
01299         while(Line[l] != '"' && Line[l] != '\0')
01300           l++;
01301 
01302         l++;    // skip "
01303 
01304         // Read the CMYK colour components
01305         INT32 c, m, y, k;
01306         if (camSscanf(Line + l, "%d %d %d %d", &c, &m, &y, &k) == 4)
01307         {
01308             if (!ProcessCMYKColour(c/100.0, m/100.0, y/100.0, k/100.0, &ColName))
01309                 return FALSE;
01310 
01311             count++;
01312         }
01313 
01314         SetPercentage();
01315     }
01316 
01317     if (count == 0)     // no colour imported... oh dear, something was horrible wrong with that file
01318         ERROR1(FALSE, _R(IDE_CORELPALETTEFILTER_BADPALFILE));
01319 
01320     return TRUE;
01321 }

BOOL CorelPaletteFilter::DoImport5  )  [protected]
 

Definition at line 1347 of file coplfilr.cpp.

01348 {
01349     char ColName[CPF_MAX_COLNAME_SIZE + MAX_PREFIX_LEN];
01350     cpl_header hdr;             // file header
01351     INT32 Len;                  // how many of those bytes we're going to use
01352     INT32 l;
01353     INT32 ColNameOffset;            // where to start adding the colour name - allows prefixes
01354 
01355     // Set the progress indicator, this next bit might take a while.
01356     StartPercentage();
01357 
01358     // init lex handling of the file
01359     if (!m_pImportFile->InitLexer())
01360         return FALSE;
01361 
01362     INT32 count = 0;
01363     // get the header of the file
01364     if (!m_pImportFile->read(&hdr, sizeof(hdr)))
01365         return FALSE;
01366 
01367     UINT32 Entries = hdr.Entries[0] + (hdr.Entries[1] * 256);
01368 
01369     // depending on the filename, fudge a prefix in somewhere.
01370     PathName Path;
01371     String_256 FileName;
01372     TCHAR *fn;
01373 
01374     if (m_pImportFile->IS_KIND_OF(CCDiskFile))
01375     {
01376         Path = ((CCDiskFile*) m_pImportFile)->GetPathName();
01377         FileName = Path.GetFileName();
01378         fn = FileName;
01379     }
01380     else
01381     {
01382         FileName = String_256(_R(IDS_K_COPLFILR_UNKNOWN));
01383         fn = FileName;
01384     }
01385 
01386     PalettePrefix Prefix = PalettePrefix_None;
01387 
01388     if(Entries == ENTRIES_FOCOLTONE && _tcsncicmp(fn, FILENAME_FOCOLTONE, 16) == 0)
01389         Prefix = PalettePrefix_Focoltone;
01390     else if(Entries == ENTRIES_TRUMATCH && _tcsncicmp(fn, FILENAME_TRUMATCH, 16) == 0)
01391         Prefix = PalettePrefix_Trumatch;
01392     else if(Entries == ENTRIES_UNIFORM && _tcsncicmp(fn, FILENAME_UNIFORM, 16) == 0)
01393         Prefix = PalettePrefix_RGB;
01394 
01395     ColNameOffset = 0;
01396     if (!ImportIntoGallery)
01397     {
01398         // When importing into the gallery, we save an awful lot of memory
01399         // by just recording the prefix type rather than the entire prefix string
01400         switch (Prefix)
01401         {
01402             case PalettePrefix_Pantone:
01403                 camStrcpy(ColName, PREFIX_PANTONE);
01404                 ColNameOffset = sizeof(PREFIX_PANTONE) - 1;
01405                 break;
01406 
01407             case PalettePrefix_Focoltone:
01408                 camStrcpy(ColName, PREFIX_FOCOLTONE);
01409                 ColNameOffset = sizeof(PREFIX_FOCOLTONE) - 1;
01410                 break;
01411 
01412             case PalettePrefix_Trumatch:
01413                 camStrcpy(ColName, PREFIX_TRUMATCH);
01414                 ColNameOffset = sizeof(PREFIX_TRUMATCH) - 1;
01415                 break;
01416 
01417             case PalettePrefix_RGB:
01418                 camStrcpy(ColName, PREFIX_UNIFORM);
01419                 ColNameOffset = sizeof(PREFIX_UNIFORM) - 1;
01420                 break;
01421         }
01422     }
01423 
01424     // try and import hdr.Entries colours
01425     for (UINT32 Entry = 0; Entry < Entries; Entry++)
01426     {
01427         // OK, the format of each entry is...
01428         // a cdrfColour
01429         // a byte giving the length of the name
01430         // n bytes of name. No terminator.
01431 
01432         // get the colour definition from the file
01433         cdrfColour ColIn;
01434         if (!m_pImportFile->read(&ColIn, sizeof(ColIn)))
01435             return FALSE;
01436 
01437         // convert it
01438         ImportedNewColour NewCol;
01439         CDRColour::Convert5(&ColIn, &NewCol);   // return code can be ignored
01440 
01441         // get the name
01442         BYTE NameCount;             // count of bytes of name in the file
01443         if (!m_pImportFile->read(&NameCount, sizeof(NameCount)))
01444             return FALSE;
01445 
01446         Len = __min(NameCount, CPF_MAX_COLNAME_SIZE - 1);
01447         if (!m_pImportFile->read(((char *)&ColName) + ColNameOffset, Len))
01448             return FALSE;
01449         ColName[Len + ColNameOffset] = '\0';
01450         if (Len != NameCount)               // need to skip any unread bytes?
01451             m_pImportFile->seek(m_pImportFile->tell() + (NameCount - Len));
01452 
01453         // check the name
01454         for (l = ColNameOffset; l < (Len + ColNameOffset); l++)
01455         {
01456             if (!camIsprint(ColName[l]))
01457                 ColName[l] = '\0';
01458         }
01459 
01460         // create the colour
01461         String_64 ColNameS(ColName);
01462 
01463         if (ImportIntoGallery)
01464         {
01465             BOOL NewlineAfterThisColour = FALSE;
01466 
01467             // In the pantone file, if the colour name ends in a "9" character, it's the last colour
01468             // in a pantone page, so we let it know that it should place a newline after itself.
01469             if (Prefix == PalettePrefix_Pantone)
01470             {
01471                 String_8 LastChar;
01472                 ColNameS.Right((StringBase *)&LastChar, 1);
01473                 if (LastChar == String_16(TEXT("9")))
01474                     NewlineAfterThisColour = TRUE;
01475             }
01476 
01477             AddColourToGallery(Prefix, &ColNameS, &NewCol.Colour, NewCol.Model,
01478                                 NewlineAfterThisColour);
01479         }
01480         else
01481         {
01482             if (!m_pNewColours->AddColour(&ColNameS, &NewCol))
01483                 return FALSE;
01484         }
01485 
01486         count++;
01487         SetPercentage();
01488     }
01489 
01490     if (count == 0)     // no colour imported... oh dear, something was horrible wrong with that file
01491         ERROR1(FALSE, _R(IDE_CORELPALETTEFILTER_BADCPLFILE));
01492 
01493     return TRUE;
01494 }

INT32 CorelPaletteFilter::HowCompatible PathName Filename,
ADDR  HeaderStart,
UINT32  HeaderSize,
UINT32  FileSize
[virtual]
 

Examines a file to see how compatable it is with this filter.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
15 03 95
Parameters:
As for the Filter class [INPUTS]
Returns:
As for the Filter class
See also:
Filter

Reimplemented from Filter.

Definition at line 1089 of file coplfilr.cpp.

01090 {
01091 PORTNOTE("byteorder", "TODO: Check byte ordering")
01092     // Check the filetype matches
01093     if (!pOILFilter->DoesExtensionOfPathNameMatch(&Filename))
01094         return 0;
01095 
01096     m_FileVersion = CPL_FVU;
01097     
01098     // is it a .pal file (textualally based)?
01099     INT32 result = 0;
01100     if ((result = HowCompatible4(Filename, HeaderStart, HeaderSize, FileSize)) != 0)
01101         return result;
01102 
01103     // is it a .cpl file (binary)?
01104     if ((result = HowCompatible5(Filename, HeaderStart, HeaderSize, FileSize)) != 0)
01105         return result;
01106 
01107     // it's not a palette file.
01108     return 0;
01109 }

INT32 CorelPaletteFilter::HowCompatible4 PathName Filename,
ADDR  HeaderStart,
UINT32  HeaderSize,
UINT32  FileSize
[protected]
 

Examines a file to see how compatable it is with this filter - checks for version 3 and 4 .pal files (textual CMYK only).

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
17 03 95
Parameters:
As for the Filter class [INPUTS]
Returns:
As for the Filter class
See also:
Filter

Definition at line 1124 of file coplfilr.cpp.

01126 {
01127     char *start = (char *)HeaderStart;
01128     UINT32 l;
01129 
01130     // is it a .pal file (textualally based?)
01131     if(start[0] == '"')
01132     {
01133         l = 1;
01134         while(start[l] != '"')
01135         {
01136             if(l >= HeaderSize)
01137             {
01138                 return 0;       // if we over run the header size, it's probably not one of ours...
01139             }
01140             if(!camIsprint(start[l]))
01141             {
01142                 return 0;       // a non alphanumerical character
01143             }
01144 
01145             l++;
01146         }
01147 
01148         // find the next non-quoted character
01149         l++;
01150         while(camIsspace(start[l]) && l < HeaderSize)
01151           l++;
01152 
01153         // and the next a digit?
01154         if(isdigit(start[l]))
01155         {
01156             m_FileVersion = CPL_FV4;
01157             return 10;          // well, it's resonably likely to be...
01158         }
01159     }
01160 
01161     // it's not a palette file.
01162     return 0;
01163 }

INT32 CorelPaletteFilter::HowCompatible5 PathName Filename,
ADDR  HeaderStart,
UINT32  HeaderSize,
UINT32  FileSize
[protected]
 

Examines a file to see how compatable it is with this filter - checks for version 5 .cpl files (binary).

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
17 03 95
Parameters:
As for the Filter class [INPUTS]
Returns:
As for the Filter class
See also:
Filter

Definition at line 1178 of file coplfilr.cpp.

01180 {
01181     // Peter (3/5/96)
01182     // Ben used to check that the first colour was named (so it failed if first colour didn't have a name!)
01183     // Changed to check magic word at start of file (extension already checked)
01184 
01185     if (HeaderStart[0]==0xCC && HeaderStart[1]==0xDC)
01186     {
01187         m_FileVersion = CPL_FV5;
01188         return 10;
01189     }
01190     else
01191         return 0;
01192 }

BOOL CorelPaletteFilter::ImportPalette  )  [virtual]
 

Called to import a Corel Palette file (.pal or .cpl).

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> - from Ben code
Date:
7/5/96
Parameters:
- [INPUTS]
Returns:
TRUE/FALSE for success/failure

Implements PaletteFilter.

Definition at line 1237 of file coplfilr.cpp.

01238 {
01239     switch(m_FileVersion)
01240     {
01241         case CPL_FV4:
01242             return DoImport4();
01243             break;
01244 
01245         case CPL_FV5:
01246             return DoImport5();
01247             break;
01248 
01249         default:
01250             ERROR2(FALSE, "Unknown FileVersion - HowCompatible gone horrible wrong or not called?");
01251             break;
01252     }
01253 }

BOOL CorelPaletteFilter::Init void   )  [virtual]
 

Initialisation.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
15 03 95
Parameters:
As for the Filter class [INPUTS]
Returns:
As for the Filter class
See also:
Filter

Implements Filter.

Definition at line 1066 of file coplfilr.cpp.

01067 {
01068     // Get the OILFilter object
01069     pOILFilter = new CorelPaletteFileOILFilter(this);
01070     if (pOILFilter == NULL)
01071         return FALSE;
01072 
01073     // All ok
01074     return TRUE;
01075 }

BOOL CorelPaletteFilter::PostImport void   )  [virtual]
 

Called after import of a Corel palette file.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> - from Ben code
Date:
7/5/96
Parameters:
- [INPUTS]
Returns:
TRUE/FALSE for success/failure

Implements PaletteFilter.

Definition at line 1506 of file coplfilr.cpp.

01507 {
01508     m_FileVersion = CPL_FVU;
01509 
01510     return TRUE;
01511 }

BOOL CorelPaletteFilter::PreImport  )  [virtual]
 

Called before import of a Corel palette.

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> - from Ben code
Date:
7/5/96
Parameters:
- [INPUTS]
Returns:
TRUE/FALSE for success/failure

Implements PaletteFilter.

Definition at line 1204 of file coplfilr.cpp.

01205 {
01206     // make sure we know which flavour this palette is
01207     if (m_FileVersion!=CPL_FV4 && m_FileVersion!=CPL_FV5)
01208     {
01209         // call HowCompatable
01210         BYTE Buffer[1024];
01211 
01212         INT32 FileSize = m_pImportFile->Size();
01213         INT32 LoadSize = (FileSize<sizeof(Buffer)) ? FileSize : sizeof(Buffer);
01214 
01215         if (m_pImportFile->read(Buffer, LoadSize).bad() || m_pImportFile->seek(0).bad())
01216             return FALSE;
01217 
01218         PathName WibblePath(_R(IDS_K_COPLFILR_INVALID));
01219         
01220         if (HowCompatible(WibblePath, (ADDR)&Buffer, LoadSize, FileSize) != 10)
01221             ERROR1(FALSE, _R(IDE_CORELPALETTEFILTER_NOTCPLORPAL));
01222     }
01223 
01224     return TRUE;
01225 }


Member Data Documentation

INT32 CorelPaletteFilter::m_FileVersion [protected]
 

Definition at line 360 of file coplfilr.h.


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