ImportedColours Class Reference

Encapsulate the process of importing a number of colours into a document. This object maintains a list of colours to be imported, and implicitly handles all the merging/duplication problems that may occur. More...

#include <impcol.h>

Inheritance diagram for ImportedColours:

CCObject SimpleCCObject List of all members.

Public Member Functions

 ImportedColours (ColourListComponent *, BOOL)
 Create a table of imported colours (initially empty).
 ~ImportedColours ()
 Destroy a table of imported colours. This should only be done after calling AddColoursToDocument() or DestroyColours() - an ERROR3 will occur if this is not done.
BOOL Init ()
 Initialise the table of imported colours.
BOOL AddColour (const String_64 *pColName, ColourCMYK *pCMYK, NewColourInfo *pLinkInfo=NULL)
 Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).
BOOL AddColour (const String_64 *pColName, ColourRGBT *pRGB, NewColourInfo *pLinkInfo=NULL)
 Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).
BOOL AddColour (const String_64 *pColName, ColourHSVT *pHSV, NewColourInfo *pLinkInfo=NULL)
 Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).
BOOL AddColour (const String_64 *pColName, ColourGreyT *pGrey, NewColourInfo *pLinkInfo=NULL)
 Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).
BOOL AddColour (const String_64 *pColName, ImportedNewColour *pCol, NewColourInfo *pLinkInfo=NULL)
 Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo). This version adds a colour of from any colour model (supported by other AddColour functions).
BOOL AddTintOrShade (const String_64 *pColName, NewColourInfo *pColourInfo)
 Add the specified tint or shade to the colour table. Assumes the vital tint information has already been filled in.
BOOL AddTint (const String_64 *pColName, UINT32 Tint)
 Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. This colour is a tint of the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).
BOOL AddShade (const String_64 *pColName, INT32 ShadeX, INT32 ShadeY)
 Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. This colour is a shade of the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).
void SetLinkedColourInherits (UINT32 ComponentID)
void SaveContext ()
 None.
void RestoreContextTo (UINT32 Level)
 None.
IndexedColourGetColour (PCTSTR ColName)
 Find a named colour in the import list. This look up is obviously done purely on the colour name, and as such is a slightly risky thing to do, especially when importing such flaky file formats as EPS - use the version of GetColour that takes a PColourCMYK value to provide more reliable colour lookup.
IndexedColourGetColour (PCTSTR ColName, const PColourCMYK *Defn)
 Searches for a named colour. If the colour name has had duplicate definitions during this import, then the colour definition is compared against the values pointed to by Defn (converting to CMYK first if needed).
BOOL AddColoursToDocument ()
 None.
BOOL SortColoursByEntryNumber ()
 Sorts the list of imported colours by the EntryNumber that is saved in the colour definition in the native file format so that we load the list back in the same order that it was in when the document was saved. This because when we save the colours we cannot save the list in the order they are defined in the colour list as we must save parent colours before children so that the children can reference the parent. Borrowed code from SuperGallery::ApplySortNow as we need a much simpler version.
BOOL DestroyColours ()
 None.
IndexedColourGetColour (INT32 ReqRecordNumber)
 Searches for a previously imported colour definition. Used by the native/web filter to convert a colour reference in a record to an IndexedColour. This must have already been imported in the file as the rule is that reference to colours can only be made if the colour definition has already been output.

Protected Types

typedef CMap< String_64, const
String_64 &, NewColour *,
NewColour * > 
CMapStringToNewColour

Protected Member Functions

BOOL AddColour (const String_64 *pColName, IndexedColour **pCol, NewColourInfo *pLinkInfo=NULL)
 Generic routine for adding a colour to the table of imported colours. All the other AddColour() routines map onto this.

Static Protected Member Functions

static INT32 __cdecl SortComparator (const void *Item1, const void *Item2)
 'qsort' comparator function, used when quicksorting the loaded colour list

Protected Attributes

NewColourList Colours
CMapStringToNewColourpColourMap
ColourListComponentpColourComponent
ColourImportContext Context
BOOL StrictColourMatching

Detailed Description

Encapsulate the process of importing a number of colours into a document. This object maintains a list of colours to be imported, and implicitly handles all the merging/duplication problems that may occur.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
See also:
NewColour; NewColourList

Definition at line 291 of file impcol.h.


Member Typedef Documentation

typedef CMap< String_64, const String_64 &, NewColour *, NewColour * > ImportedColours::CMapStringToNewColour [protected]
 

Definition at line 353 of file impcol.h.


Constructor & Destructor Documentation

ImportedColours::ImportedColours ColourListComponent TheColourComponent,
BOOL  Strict
 

Create a table of imported colours (initially empty).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
TheColourComponent - the relevant colour component for this import. [INPUTS] Strict - TRUE => when servicing calls to GetColour(), check the CMYK colour definition for a match in case a colour is being used which wasn't declared in the colour table (this is what we do for ArtWorks EPS). FALSE => don't bother checking CMYK - just use the name to look up the colour - we use this for Camelot EPS because we know we don't save out brain damaged EPS like ArtWorks does.
See also:
ImportedColours::Init

Definition at line 517 of file impcol.cpp.

00518 {
00519     // Remember this document component
00520     pColourComponent = TheColourComponent;
00521 
00522     // Do we check CMYK values when matching colours?
00523     StrictColourMatching = Strict;
00524 
00525     // No hash table yet
00526     pColourMap = NULL;
00527 }

ImportedColours::~ImportedColours  ) 
 

Destroy a table of imported colours. This should only be done after calling AddColoursToDocument() or DestroyColours() - an ERROR3 will occur if this is not done.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: Colours should be explicitly added to the document or deleted from this table before this function is called => ERROR3

See also:
ImportedColours::AddColoursToDocument; ImportedColours::DestroyColours

Definition at line 547 of file impcol.cpp.

00548 {
00549     // MORE STUFF HERE...
00550 
00551     // Trash the hash table
00552     delete pColourMap;
00553     pColourMap = NULL;
00554 }


Member Function Documentation

BOOL ImportedColours::AddColour const String_64 pColName,
IndexedColour **  pNewIndexedCol,
NewColourInfo pColourInfo = NULL
[protected]
 

Generic routine for adding a colour to the table of imported colours. All the other AddColour() routines map onto this.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Modified: Jason (8/9/95) - Now handles exact duplicates as well as duplicate names (This is needed for new shade-colour saving system which does nasty things in order to retain backward compatability with old loaders)

Parameters:
pColName - the name of the colour [INPUTS] pNewCol - ptr to ptr to the new indexed colour to use (if NULL then just returns FALSE immediately) (see also Outputs) pColourInfo - if NULL, then it is a normal colour; if non-NULL then colour is special in some way, i.e. a tint or a linked colour or a spot colour.
If *pNewCol points to an IndexedColour which already has an *identical* [OUTPUTS] twin colour (i.e. exactly the same colour appears twice in the doc) then pNewCol will be modified to point at the first incarnation of the colour, and the IndexedColour you passed in will be deleted. DO NOT use the previous IndexedColour pointer - only use the pointer as passed back from this method.
Returns:
TRUE if the colour was added ok; FALSE otherwise

Errors: Out of memory => ERROR1 pNewCol is NULL => returns FALSE (no error set)

See also:
ImportedColours Scope: Protected

Definition at line 954 of file impcol.cpp.

00956 {
00957     // Do we have a valid colour?
00958     if (pNewIndexedCol == NULL || *pNewIndexedCol == NULL)
00959         // No!
00960         return FALSE;
00961 
00962     // First, set the colour name to the one supplied. If it is unnamed, then we want
00963     // to set its unique-ID string to the value from the file. At the end of the import,
00964     // we will use SetUnnamed to force it to re-generate a unique name so that it is
00965     // (a) merged properly during import, and (b) doesn't clash with another colour
00966     // already in the same document once it is added.
00967     //String_64 Name = *pColName;
00968     //(*pNewIndexedCol)->SetName(*pColName, (ColName[0] != '_'));
00969     TCHAR ch = (*pColName)[0];
00970     (*pNewIndexedCol)->SetName(*pColName, (ch != '_'));
00971 
00972 
00973     if (pColourInfo != NULL)
00974     {
00975         // Link the colour if required
00976         if ((pColourInfo->Type == COLOURTYPE_LINKED) ||
00977             (pColourInfo->Type == COLOURTYPE_TINT))
00978         {
00979             IndexedColour *pParent = NULL;
00980             if (pColourInfo->WebNativeColour)
00981             {
00982                 pParent = pColourInfo->pParentCol;
00983             }
00984             else
00985             {
00986                 // Importing a non-native or web file colour and so use the context of the colour
00987                 // to define its parent.
00988                 // Get the current colour context
00989                 pParent = Context.GetContext();
00990                 ERROR2IF(pParent == NULL, FALSE, "NULL parent when creating linked colour!");
00991             }
00992 
00993             // Link to it - either as a linked colour or a tint
00994             if (pColourInfo->Type == COLOURTYPE_LINKED)
00995             {
00996                 // Linked colour
00997                 (*pNewIndexedCol)->SetLinkedParent(pParent, COLOURTYPE_LINKED);
00998 
00999                 // Set inheritance flags...
01000                 for (INT32 i = 0; i < 4; i++)
01001                     (*pNewIndexedCol)->SetInheritsComponent(i + 1, pColourInfo->Inherits[i]);
01002             }
01003             else
01004             {
01005                 // Tinted colour
01006                 (*pNewIndexedCol)->SetLinkedParent(pParent, COLOURTYPE_TINT);
01007 
01008                 // Set tint/shade value as appropriate. This makes the 'tint' colour a
01009                 // tint or shade. (Shades are special cases of tints for historical reasons)
01010                 if (pColourInfo->TintIsShade)
01011                     (*pNewIndexedCol)->SetShadeValues(pColourInfo->TintValue, pColourInfo->ShadeValue);
01012                 else
01013                     (*pNewIndexedCol)->SetTintValue(pColourInfo->TintValue);
01014             }
01015         }
01016         else if (pColourInfo->Type == COLOURTYPE_SPOT)
01017         {
01018             // Mark this as a spot colour (in case the caller hasn't already)
01019             (*pNewIndexedCol)->SetLinkedParent(NULL, COLOURTYPE_SPOT);
01020         }
01021     }
01022 
01023     // Is there a colour the same as this in the destination document already?
01024     IndexedColour *pIdenticalCol;
01025     pColourComponent->FindIdenticalColour(*pNewIndexedCol, &pIdenticalCol);
01026 
01027     BOOL AlreadyExists = (pIdenticalCol != NULL);
01028 
01029 /*
01030     Phil, 01/03/2004
01031     If we remove colours from the document before we have added our list of imported colours
01032     anything could come along and add colours back in the meantime.
01033     (e.g. GradFillAttribute::GradFillAttribute)
01034     So leave colours in the list and only move them later on...
01035 */
01036     if (AlreadyExists)
01037     {
01038         // Graeme (5/4/00) - This code now changes the colour list so that an
01039         // existing colour is repositioned where the original definition was.
01040 
01041         // Delete the new one because it duplicates one already in the document.
01042         delete *pNewIndexedCol;
01043 
01044         // Make pNewIndexedCol point to the existing colour
01045         *pNewIndexedCol = pIdenticalCol;
01046 
01047         // Set AlreadyExists to be FALSE so that the colour is included.
01048         AlreadyExists = FALSE;
01049     }
01050 
01051     NewColour *pNewColour = NULL;
01052 
01053     // If we are in web/native filter mode then we MUST always add a new colour item as this
01054     // is where we save the record number which will be reused later. So we must stop the 
01055     // name look up and adding duplicates as this adds the new colour to the a list inside
01056     // the duplicated name that is in the ColourMap.
01057     BOOL WebNative = (pColourInfo && pColourInfo->WebNativeColour);
01058 
01059     // First, check to see if we already have a definition of this colour *NAME*
01060     if( !WebNative && pColourMap->Lookup( *pColName, pNewColour ) )
01061     {
01062         // Yes - mark the current definition as a duplicate and add this new one to it.
01063         if (!pNewColour->AddDuplicateColour(pNewIndexedCol, AlreadyExists))
01064             // Error encountered.
01065             return FALSE;
01066     }
01067     else
01068     {
01069         // No - but is it already in the destination document?
01070         //
01071         // (i.e. is there a colour in the document with the same 
01072         //  name, colour model and definition?)
01073         //
01074         // If yes - add a new colour that references the already existing colour, and
01075         // mark it as being such;
01076         //
01077         // If no  - it's a new colour, so add it to the list.
01078 
01079         pNewColour = Colours.AddColour(*pNewIndexedCol, AlreadyExists);
01080 
01081         if (pNewColour == NULL)
01082             // out of memory
01083             return FALSE;
01084 
01085         // Either way, add it to the colour name map
01086         try
01087         {
01088             (*pColourMap)[ *pColName ] = pNewColour;
01089         }
01090         catch( CMemoryException )
01091         {
01092             // Could not do it - report error to caller.
01093             ERROR(_R(IDS_OUT_OF_MEMORY), FALSE);
01094         }
01095 
01096         // If we are in web/native filter mode then save the record number that we
01097         // have been passed in in the NewColourInfo
01098         // At the same time save out the entry number for where we want this colour in the list
01099         // of colours
01100         if (pColourInfo && pColourInfo->WebNativeColour)
01101         {
01102             pNewColour->RecordNumber = pColourInfo->RecordNumber;
01103             pNewColour->EntryNumber = pColourInfo->EntryNumber;
01104         }
01105     }
01106 
01107     // We added the colour ok so set it as the current context colour
01108     // Note that AddDuplicateColour may have changed our pointer to point at a different
01109     // (identical) colour, but it will always point at the correct colour for us to use here.
01110     Context.SetContext(*pNewIndexedCol);
01111 
01112     // All ok
01113     return TRUE;
01114 }

BOOL ImportedColours::AddColour const String_64 pColName,
ImportedNewColour pCol,
NewColourInfo pColourInfo = NULL
 

Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo). This version adds a colour of from any colour model (supported by other AddColour functions).

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
18 03 95
Parameters:
pColName - the name of the colour to add [INPUTS] pGrey - the definition of the colour to add pColourInfo - if NULL, then it is a normal colour; if non-NULL then colour is special in some way, i.e. a tint or a linked colour or a spot colour.
Returns:
TRUE if the colour could be added; FALSE if not

Errors: -

See also:
ImportedColours; ImportedColours::GetColour; ImportedColours::SaveContext; ImportedColours::RestoreContextTo

Definition at line 770 of file impcol.cpp.

00772 {
00773     switch(pCol->Model)
00774     {
00775         case COLOURMODEL_RGBT:
00776             return AddColour(pColName, (ColourRGBT *)&pCol->Colour, pColourInfo);
00777             break;
00778 
00779         case COLOURMODEL_CMYK:
00780             return AddColour(pColName, (ColourCMYK *)&pCol->Colour, pColourInfo);
00781             break;
00782 
00783         case COLOURMODEL_HSVT:
00784             return AddColour(pColName, (ColourHSVT *)&pCol->Colour, pColourInfo);
00785             break;
00786 
00787         case COLOURMODEL_GREYT:
00788             return AddColour(pColName, (ColourGreyT *)&pCol->Colour, pColourInfo);
00789             break;
00790 
00791         default:
00792             break;
00793     }
00794     
00795     ERROR3("Colour model presented to ImportedColours::AddColour is not a recognised model");
00796 
00797     return FALSE;
00798 }

BOOL ImportedColours::AddColour const String_64 pColName,
ColourGreyT pGrey,
NewColourInfo pColourInfo = NULL
 

Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
pColName - the name of the colour to add [INPUTS] pGrey - the definition of the colour to add pColourInfo - if NULL, then it is a normal colour; if non-NULL then colour is special in some way, i.e. a tint or a linked colour or a spot colour.
Returns:
TRUE if the colour could be added; FALSE if not

Errors: -

See also:
ImportedColours; ImportedColours::GetColour; ImportedColours::SaveContext; ImportedColours::RestoreContextTo

Definition at line 733 of file impcol.cpp.

00735 {
00736     IndexedColour *pNewCol = new INDEXEDCOLOUR_GREYT(pGrey);
00737     return AddColour(pColName, &pNewCol, pColourInfo);
00738 }

BOOL ImportedColours::AddColour const String_64 pColName,
ColourHSVT pHSV,
NewColourInfo pColourInfo = NULL
 

Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
pColName - the name of the colour to add [INPUTS] pHSV - the definition of the colour to add pColourInfo - if NULL, then it is a normal colour; if non-NULL then colour is special in some way, i.e. a tint or a linked colour or a spot colour.
Returns:
TRUE if the colour could be added; FALSE if not

Errors: -

See also:
ImportedColours; ImportedColours::GetColour; ImportedColours::SaveContext; ImportedColours::RestoreContextTo

Definition at line 698 of file impcol.cpp.

00700 {
00701     IndexedColour *pNewCol = new INDEXEDCOLOUR_HSVT(pHSV);
00702     return AddColour(pColName, &pNewCol, pColourInfo);
00703 }

BOOL ImportedColours::AddColour const String_64 pColName,
ColourRGBT pRGB,
NewColourInfo pColourInfo = NULL
 

Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
pColName - the name of the colour to add [INPUTS] pRGB - the definition of the colour to add pColourInfo - if NULL, then it is a normal colour; if non-NULL then colour is special in some way, i.e. a tint or a linked colour or a spot colour.
Returns:
TRUE if the colour could be added; FALSE if not

Errors: -

See also:
ImportedColours; ImportedColours::GetColour; ImportedColours::SaveContext; ImportedColours::RestoreContextTo

Definition at line 663 of file impcol.cpp.

00665 {
00666     IndexedColour *pNewCol = new INDEXEDCOLOUR_RGBT(pRGB);
00667     return AddColour(pColName, &pNewCol, pColourInfo);
00668 }

BOOL ImportedColours::AddColour const String_64 pColName,
ColourCMYK pCMYK,
NewColourInfo pColourInfo = NULL
 

Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. If pColourInfo specifies a linked or tinted colour, then this colour is also linked to the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
pColName - the name of the colour to add [INPUTS] pCMYK - the definition of the colour to add pColourInfo - if NULL, then it is a normal colour; if non-NULL then colour is special in some way, i.e. a tint or a linked colour or a spot colour.
Returns:
TRUE if the colour could be added; FALSE if not

Errors: -

See also:
ImportedColours; ImportedColours::GetColour; ImportedColours::SaveContext; ImportedColours::RestoreContextTo

Definition at line 628 of file impcol.cpp.

00630 {
00631     IndexedColour *pNewCol = new INDEXEDCOLOUR_CMYK(pCMYK);
00632     return AddColour(pColName, &pNewCol, pColourInfo);
00633 }

BOOL ImportedColours::AddColoursToDocument void   ) 
 

None.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1290 of file impcol.cpp.

01291 {
01292     // Make an array for the new colours
01293     INT32 NumNewColours = Colours.GetCount();
01294     INT32 TableSize = sizeof(IndexedColour *) * (NumNewColours + 1);
01295     IndexedColour **pNewArray = (IndexedColour **) CCMalloc(TableSize);
01296     if (pNewArray == NULL)
01297     {
01298         // Out of memory.
01299         return FALSE;
01300     }
01301 
01302     // set up a slow job
01303     String_64 ImportMessage(_R(IDT_ADDCOLOURSTODOC));
01304     BeginSlowJob( NumNewColours, TRUE, &ImportMessage );
01305     INT32 Done = 0;
01306     
01307     // Copy the colour pointers into this array
01308     INT32 i = 0;
01309     NewColour *pColour = (NewColour *) Colours.GetHead();
01310     List *pUnnamedColours = pColourComponent->GetColourList()->GetUnnamedColours();
01311 
01312     while (pColour != NULL)
01313     {
01314         // Remove this colour from the list, and add it (and all duplicates of it) to the 
01315         // palette and the array, but only if it is not already in the document,and it
01316         // is not an unnamed colour (i.e. its name starts with an underscore).
01317         Colours.RemoveItem(pColour);
01318 
01319         while (pColour != NULL)
01320         {
01321             // Is it an unnamed colour?
01322             if (!pColour->pCol->IsNamed())      // Is it an unnamed colour?
01323             {
01324                 // Yes - add to the unnamed colour list (no need for undo)
01325                 // We force it unnamed again now to ensure it generates a new unique
01326                 // ID for its destination document, rather than using the
01327                 // unique-within-file id used during import.
01328                 pColour->pCol->SetUnnamed();
01329                 pUnnamedColours->AddTail(pColour->pCol);
01330             }
01331             else
01332             {
01333                 // It's a named colour - may be already in the doc, may be not
01334                 IndexedColour* pIdenticalColour;
01335                 pColourComponent->FindIdenticalColour(pColour->pCol, &pIdenticalColour);
01336                 if (pIdenticalColour)
01337                 {
01338                     // Already in the doc so just move the existing colour
01339                     // into the required position in the list by unlinking and relinking...
01340                     ColourList *pColourList = pColourComponent->GetColourList ();
01341                     if ( pColourList->RemoveItem ( pIdenticalColour ) != NULL )
01342                     {
01343                         pColourComponent->AddNewColour(pIdenticalColour);
01344                         pNewArray[i++] = pIdenticalColour;
01345                     }
01346 
01347                 }
01348                 else
01349                 {
01350                     pColourComponent->AddNewColour(pColour->pCol);
01351                     pNewArray[i++] = pColour->pCol;
01352                 }
01353             }
01354 
01355             // Try next duplicate and delete this item.
01356             NewColour *pTmp = pColour;
01357             pColour = pColour->pNextDuplicate;
01358             delete pTmp;
01359         }
01360 
01361         // Try the next colour
01362         pColour = (NewColour *) Colours.GetHead();
01363     
01364         // do progess bar stuff
01365         Done++;
01366         if(Done % 0xf == 0)
01367             ContinueSlowJob(Done);
01368     }
01369 
01370     // Terminate the list of pointers
01371     pNewArray[i] = NULL;
01372 
01373     // Add these colours|.
01374     ColourManager::UnHideColours(pColourComponent->GetColourList(), pNewArray);
01375 
01376     // Destroy the list of added colours (UnHideColours copied it, so our copy is useless now)
01377     CCFree(pNewArray);
01378     pNewArray = NULL;
01379 
01380     // Destroy the colour map
01381     delete pColourMap;
01382     pColourMap = NULL;
01383 
01384     // finish the slow job
01385     ContinueSlowJob(NumNewColours);
01386     EndSlowJob();
01387     
01388     // All ok
01389     return TRUE;
01390 }

BOOL ImportedColours::AddShade const String_64 pColName,
INT32  ShadeX,
INT32  ShadeY
 

Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. This colour is a shade of the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> (copied from code by Tim)
Date:
7/9/95 (30/11/94)
Parameters:
pColName - the name of the colour to add [INPUTS] ShadeX - the shade X value (between -100 and 100) ShadeY - the shade Y value (between -100 and 100)
Returns:
TRUE if the colour could be added; FALSE if not

Errors: -

See also:
ImportedColours; ImportedColours::GetColour; ImportedColours::SaveContext; ImportedColours::RestoreContextTo

Definition at line 895 of file impcol.cpp.

00896 {
00897     // Get a new colour to add
00898     IndexedColour *pNewCol = new IndexedColour;
00899 
00900     // Set up the tint information
00901     NewColourInfo ColourInfo;
00902     ColourInfo.Type = COLOURTYPE_TINT;
00903 
00904     // And flag the fact that this "tint" is really a shade!
00905     ColourInfo.TintIsShade = TRUE;
00906 
00907     // Convert -100 <-> 100 to -1.0 <-> 1.0 and pass in as FIXED24.
00908     ColourInfo.TintValue = FIXED24(((double) ShadeX) / 100.0);
00909     ColourInfo.ShadeValue = FIXED24(((double) ShadeY) / 100.0);
00910 
00911     return AddColour(pColName, &pNewCol, &ColourInfo);
00912 }

BOOL ImportedColours::AddTint const String_64 pColName,
UINT32  Tint
 

Add the specified colour to the colour table. If the colour name clashes with any already added or already in the destination document, this does not matter as the name specified in pColName is what should be used to access this colour again. This colour is a tint of the colour currently specified by the colour link context (see SaveContext and RestoreContextTo).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
pColName - the name of the colour to add [INPUTS] Tint - the tint value (between 0 and 100)
Returns:
TRUE if the colour could be added; FALSE if not

Errors: -

See also:
ImportedColours; ImportedColours::GetColour; ImportedColours::SaveContext; ImportedColours::RestoreContextTo

Definition at line 854 of file impcol.cpp.

00855 {
00856     // Get a new colour to add
00857     IndexedColour *pNewCol = new IndexedColour;
00858 
00859     // Set up the tint information
00860     NewColourInfo ColourInfo;
00861     ColourInfo.Type = COLOURTYPE_TINT;
00862 
00863     // Convert 0 <-> 100 to 0.0 <-> 1.0 and pass in as FIXED24.
00864     ColourInfo.TintValue = FIXED24(((double) Tint) / 100.0);
00865 
00866     return AddColour(pColName, &pNewCol, &ColourInfo);
00867 }

BOOL ImportedColours::AddTintOrShade const String_64 pColName,
NewColourInfo pColourInfo
 

Add the specified tint or shade to the colour table. Assumes the vital tint information has already been filled in.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/5/96
Parameters:
pColName - the name of the colour to add [INPUTS] pLinkInfo - the colour information data
Returns:
TRUE if the colour could be added; FALSE if not

Errors: -

See also:
ColourListComponent::ReadTint; ColourListComponent::ReadShade; ColourListComponent::ImportColourDefinition;

Definition at line 818 of file impcol.cpp.

00819 {
00820     // Get a new colour to add
00821     IndexedColour *pNewCol = new IndexedColour;
00822 
00823     // Assumes tint and shade information already set up, this includes:-
00824     // pColourInfo->Type = COLOURTYPE_TINT;
00825     // pColourInfo->TintValue = 0.0; (FIXED24);
00826     // If shade then
00827     // pColourInfo->ShadeValue = 0.0; (FIXED24);
00828 
00829     return AddColour(pColName, &pNewCol, pColourInfo);
00830 }

BOOL ImportedColours::DestroyColours  ) 
 

None.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1407 of file impcol.cpp.

01408 {
01409     NewColour *pColour = (NewColour *) Colours.GetHead();
01410 
01411     while (pColour != NULL)
01412     {
01413         // Remove this colour from the list, and delete the indexed colour it points to
01414         // (if it is not already in the document).
01415         Colours.RemoveItem(pColour);
01416 
01417         while (pColour != NULL)
01418         {
01419             if (!pColour->AlreadyExistsInDoc)
01420             {
01421                 // It's a brand new colour - delete it.
01422                 // Except we don't because it causes an error.
01423 
01424                 // NB.  This is a temporary bodge to stop us from getting Indexed colour
01425                 //      deleted while in use errors - they happen because the undo 
01426                 //      system does not delete the nodes added by InsertNode() yet.
01427                 //      When it does, then we can uncomment this line.  As it stands we
01428                 //      we get a memory leak of new colours when an import fails, but
01429                 //      what the hell - it's only a bodge.
01430 
01431                 //delete pColour->pCol;
01432             }
01433 
01434             // Try next duplicate and delete this item.
01435             NewColour *pTmp = pColour;
01436             pColour = pColour->pNextDuplicate;
01437             delete pTmp;
01438         }
01439 
01440         // Try the next colour
01441         pColour = (NewColour *) Colours.GetHead();
01442     }
01443 
01444     // All done
01445     return TRUE;
01446 }

IndexedColour * ImportedColours::GetColour INT32  ReqRecordNumber  ) 
 

Searches for a previously imported colour definition. Used by the native/web filter to convert a colour reference in a record to an IndexedColour. This must have already been imported in the file as the rule is that reference to colours can only be made if the colour definition has already been output.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/5/96
Parameters:
ReqRecordNumber - the record number to search the list for [INPUTS]
Returns:
Pointer to the indexed colour if successful; NULL if not found.

Errors: -

See also:
ImportedColours; ColourListComponent::ImportColourDefinition;

Definition at line 1466 of file impcol.cpp.

01467 {
01468     // Work our way through the list of imported colours until we find the required record number
01469     NewColour *pColour = (NewColour *) Colours.GetHead();
01470     while (pColour != NULL)
01471     {
01472         if (pColour->RecordNumber == ReqRecordNumber)
01473             return pColour->pCol;
01474 
01475         // Try the next colour
01476         pColour = (NewColour *) Colours.GetNext(pColour);
01477     }
01478 
01479     // Something went a bit wrong and we didn't find the requested record number
01480     // return NULL to the caller 
01481     return NULL;
01482 }

IndexedColour * ImportedColours::GetColour PCTSTR  ColName,
const PColourCMYK Defn
 

Searches for a named colour. If the colour name has had duplicate definitions during this import, then the colour definition is compared against the values pointed to by Defn (converting to CMYK first if needed).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
ColName - the colour name to look for. [INPUTS] Defn - pointer to the CMYK values specified in the imported file.
Returns:
Pointer to the indexed colour if successful; NULL if not found.

Errors: -

See also:
ImportedColours

Definition at line 1216 of file impcol.cpp.

01217 {
01218     // Do we have a definition of this colour name?
01219     NewColour *pNewColour=NULL;
01220     if( pColourMap->Lookup( ColName, pNewColour ) )
01221     {
01222         // Should we check colour values before returning this colour?
01223         if (StrictColourMatching || (pNewColour->pNextDuplicate != NULL))
01224         {
01225             // Yes - find a colour from this entry that matches the colour definition too...
01226             while (pNewColour != NULL) 
01227             {
01228                 // Is this a match?
01229                 // NB. We allow them to be out by one to cope with rounding problems.
01230                 //     This is ok, because it will only happen in ArtWorks EPS files,
01231                 //     and then only on colours that are 1 out in the colour definition,
01232                 //     so I don't think anyone's going to notice!  -- Tim
01233                 if (WITHIN_ONE(pNewColour->ColDefn.Cyan,    Defn->Cyan)    &&
01234                     WITHIN_ONE(pNewColour->ColDefn.Magenta, Defn->Magenta) &&
01235                     WITHIN_ONE(pNewColour->ColDefn.Yellow,  Defn->Yellow)  &&
01236                     WITHIN_ONE(pNewColour->ColDefn.Key,     Defn->Key))
01237                 {
01238                     // Yes - quit loop
01239                     break;
01240                 }
01241 
01242                 // Otherwise try next colour
01243                 pNewColour = pNewColour->pNextDuplicate;
01244             }
01245 
01246             // Did we find one?
01247             if (pNewColour != NULL)
01248             {
01249                 // Yes - return it to the caller.
01250                 return pNewColour->pCol;
01251             }
01252             else
01253             {
01254                 // No - return failure
01255                 return NULL;
01256             }
01257         }
01258         else
01259         {
01260             // No checking needed -just return this colour
01261             return pNewColour->pCol;
01262         }
01263     }
01264     else
01265     {
01266         // No - return failure.
01267         return NULL;
01268     }
01269 }

IndexedColour * ImportedColours::GetColour PCTSTR  ColName  ) 
 

Find a named colour in the import list. This look up is obviously done purely on the colour name, and as such is a slightly risky thing to do, especially when importing such flaky file formats as EPS - use the version of GetColour that takes a PColourCMYK value to provide more reliable colour lookup.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
ColName - the colour name to look for. [INPUTS]
Returns:
Pointer to the indexed colour if successful; NULL if not found.
See also:
ImportedColours

Definition at line 1178 of file impcol.cpp.

01179 {
01180     // Do we have a definition of this colour name?
01181     NewColour *pNewColour=NULL;
01182     if( pColourMap->Lookup( ColName, pNewColour ) )
01183     {
01184         // Yes - return the first entry
01185         return pNewColour->pCol;
01186     }
01187     else
01188     {
01189         // No - return failure.
01190         return NULL;
01191     }
01192 }

BOOL ImportedColours::Init void   ) 
 

Initialise the table of imported colours.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Reimplemented from SimpleCCObject.

Definition at line 571 of file impcol.cpp.

00572 {
00573     // Get a hash table for the colour names...
00574     try
00575     {
00576         pColourMap = new CMapStringToNewColour;
00577     }
00578     catch( CMemoryException )
00579     {
00580         ERROR(_R(IDS_OUT_OF_MEMORY), FALSE);
00581     }
00582 
00583     // Check our document's colour list component...
00584     if (pColourComponent == NULL)
00585     {
00586         // Whoops - something's up
00587         delete pColourMap;
00588         pColourMap = NULL;
00589         ERROR2(FALSE, "NULL colour list component!");
00590     }
00591 
00592     // Ininitalise the colour linking context.
00593     if (!Context.Init())
00594         return FALSE;
00595 
00596     // All ok
00597     return TRUE;
00598 }

void ImportedColours::RestoreContextTo UINT32  Level  ) 
 

None.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1152 of file impcol.cpp.

01153 {
01154     if (Context.RestoreContextTo(Level) == FALSE)
01155     {
01156         ERROR3("Unbalanced colour import context");
01157     }
01158 }

void ImportedColours::SaveContext  ) 
 

None.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/11/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1132 of file impcol.cpp.

01133 {
01134     Context.SaveContext();
01135 }

void ImportedColours::SetLinkedColourInherits UINT32  ComponentID  ) 
 

BOOL ImportedColours::SortColoursByEntryNumber  ) 
 

Sorts the list of imported colours by the EntryNumber that is saved in the colour definition in the native file format so that we load the list back in the same order that it was in when the document was saved. This because when we save the colours we cannot save the list in the order they are defined in the colour list as we must save parent colours before children so that the children can reference the parent. Borrowed code from SuperGallery::ApplySortNow as we need a much simpler version.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/96
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
True if the operation completed successfully False if it failed in some way.

Errors: -

See also:
ImportedColours; ColourListComponent::ImportColourDefinition; ColourListComponent::EndImport; SuperGallery::ApplySortNow

Definition at line 1507 of file impcol.cpp.

01508 {
01509     INT32 NumItems = 0;
01510 
01511     // Count the number of items we have to sort
01512     NewColour *pColour = (NewColour *) Colours.GetHead();
01513     while (pColour != NULL)
01514     {
01515         if (pColour->pCol->IsNamed())       // Is it an named colour?
01516             NumItems++;
01517         pColour = (NewColour *) Colours.GetNext(pColour);
01518     }
01519 
01520     // Start progress indicators, with a percentage based upon the number of items.
01521     // We will update twice for each group (after qsort and shuffle-items stages)
01522     String_64 Description(_R(IDS_NATIVE_SORTCOLOURS));
01523     BeginSlowJob(NumItems * 2, FALSE, &Description);
01524     INT32 NumItemsToSort = 0;
01525 
01526     if (NumItems > 1)
01527     {
01528         // Get memory for an array of pointers to these items
01529         NewColour **SortArray = (NewColour **)CCMalloc(NumItems * sizeof(NewColour *));
01530         if (SortArray == NULL)
01531             return FALSE;
01532 
01533         // Fill in the array with pointers to display items to sort
01534         INT32 i = 0;
01535         NewColour *pColour = (NewColour *) Colours.GetHead();
01536         while (pColour != NULL)
01537         {
01538             if (pColour->pCol->IsNamed())       // Is it an named colour?
01539                 SortArray[i++] = pColour;
01540             pColour = (NewColour *) Colours.GetNext(pColour);
01541         }
01542 
01543         // Sort the array of pointers
01544         qsort(SortArray, NumItems, sizeof(NewColour *), ImportedColours::SortComparator);
01545 
01546         NumItemsToSort += NumItems;
01547         // Update percentage complete for the number of items processed
01548         ContinueSlowJob(NumItemsToSort);
01549 
01550         // Now, take the sorted array, and rearrange the items to be in that order      
01551         // Special case the first item
01552         NewColour *pPrevColour = (NewColour *) Colours.GetPrev(SortArray[0]);
01553         if (pPrevColour != NULL)
01554         {
01555             Colours.RemoveItem(SortArray[0]);
01556             Colours.InsertBefore(SortArray[1], SortArray[0]);
01557         }
01558 
01559         // Then whip through the rest of the items
01560         for (i = 1; i < NumItems; i++)
01561         {
01562             pPrevColour = (NewColour *) Colours.GetPrev(SortArray[i]);
01563             if (pPrevColour != SortArray[i-1])
01564             {
01565                 Colours.RemoveItem(SortArray[i]);
01566                 Colours.InsertAfter(SortArray[i-1], SortArray[i]);
01567             }
01568         }
01569 
01570         // Free our temporary workspace
01571         CCFree(SortArray);
01572     }
01573     
01574     // End the progress bar that we started
01575     EndSlowJob();
01576 
01577     // We seem to have sorted the items ok
01578     return TRUE;
01579 }

INT32 __cdecl ImportedColours::SortComparator const void *  Item1,
const void *  Item2
[static, protected]
 

'qsort' comparator function, used when quicksorting the loaded colour list

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
31/5/96
Parameters:
Item1,Item2 - the display nodes to be compared [INPUTS]
Returns:
negative (I am lesser), 0 (we are equal), or positive (I am greater) result of comparing the items with the EntryNumber stored in each item in the loaded colour list.
See also:
ImportedColours::SortColoursByEntryNumber() SuperGallery::SortComparator; SuperGallery::ApplySortNow

Definition at line 1597 of file impcol.cpp.

01598 {
01599     NewColour *pColourItem1 = *((NewColour **)Item1);
01600     NewColour *pColourItem2 = *((NewColour **)Item2);
01601 
01602     if (pColourItem1 == NULL || pColourItem2 == NULL)
01603     {
01604         ERROR3("ImportedColours::SortComparator bad pointers!");    
01605         return 0;
01606     }
01607 
01608     if (pColourItem1->EntryNumber < pColourItem2->EntryNumber)
01609         return(-1);
01610 
01611     return((pColourItem1->EntryNumber == pColourItem2->EntryNumber) ? 0 : 1);
01612 }


Member Data Documentation

NewColourList ImportedColours::Colours [protected]
 

Definition at line 350 of file impcol.h.

ColourImportContext ImportedColours::Context [protected]
 

Definition at line 360 of file impcol.h.

ColourListComponent* ImportedColours::pColourComponent [protected]
 

Definition at line 357 of file impcol.h.

CMapStringToNewColour* ImportedColours::pColourMap [protected]
 

Definition at line 354 of file impcol.h.

BOOL ImportedColours::StrictColourMatching [protected]
 

Definition at line 363 of file impcol.h.


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