rechcol.cpp

Go to the documentation of this file.
00001 // $Id: rechcol.cpp 1688 2006-08-10 12:05:20Z gerry $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // Implementation of the colour record handler class of the v2 file format
00100 
00101 #include "camtypes.h"
00102 
00103 #include "rechcol.h"    // ColourRecordHandler for importing colours from v2 native/web files
00104 #include "colcomp.h"    // Document colour component, handles import of colours
00105 //#include "camfiltr.h" // BaseCamelotFilter - version 2 native filter - in camtypes.h [AUTOMATICALLY REMOVED]
00106 #include "cxftags.h"    // TAG_DEFINERGBCOLOUR TAG_DEFINECOMPLEXCOLOUR
00107 //#include "cxfrec.h"   // TAG_DEFINERGBCOLOUR TAG_DEFINECOMPLEXCOLOUR - in camtypes.h [AUTOMATICALLY REMOVED]
00108 
00109 DECLARE_SOURCE("$Revision: 1688 $");
00110 
00111 // An implement to match the Declare in the .h file.
00112 CC_IMPLEMENT_DYNAMIC(ColourRecordHandler,CamelotRecordHandler);
00113 
00114 // Declare smart memory handling in Debug builds
00115 #define new CAM_DEBUG_NEW
00116 
00117 // #if NEW_NATIVE_FILTER    // New native filters, only available to those who need them at present
00118 
00119 /********************************************************************************************
00120 
00121 >   virtual BOOL ColourRecordHandler::BeginImport()
00122 
00123     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00124     Created:    29/5/96
00125     Inputs:     -
00126     Returns:    TRUE if ok
00127                 FALSE otherwise
00128     Purpose:    Initialises the colour record handler
00129     Errors:     -
00130     SeeAlso:    -
00131 
00132 ********************************************************************************************/
00133 
00134 BOOL ColourRecordHandler::BeginImport()
00135 {
00136     pColComponent = GetColourDocComponent();
00137 
00138     return (pColComponent != NULL);
00139 }
00140 
00141 /********************************************************************************************
00142 
00143 >   virtual UINT32* ColourRecordHandler::GetTagList()
00144 
00145     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00146     Created:    29/5/96
00147     Inputs:     -
00148     Returns:    Ptr to a list of tag values, terminated by CXFRH_TAG_LIST_END
00149     Purpose:    Provides the record handler system with a list of records handled by this
00150                 handler
00151     SeeAlso:    -
00152 
00153 ********************************************************************************************/
00154 
00155 UINT32* ColourRecordHandler::GetTagList()
00156 {
00157     static UINT32 TagList[] = {TAG_DEFINERGBCOLOUR,TAG_DEFINECOMPLEXCOLOUR,CXFRH_TAG_LIST_END};
00158 
00159     return (UINT32*)&TagList;
00160 }
00161 
00162 /********************************************************************************************
00163 
00164 >   virtual BOOL ColourRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord)
00165 
00166     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00167     Created:    29/5/96
00168     Inputs:     pCXaraFileRecord = ptr to record to handle
00169     Returns:    TRUE if handled successfuly
00170                 FALSE otherwise
00171     Purpose:    Handles the given record.
00172     SeeAlso:    -
00173 
00174 ********************************************************************************************/
00175 
00176 BOOL ColourRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord)
00177 {
00178     ERROR2IF(pCXaraFileRecord == NULL,FALSE,"ColourRecordHandler::HandleRecord pCXaraFileRecord is NULL");
00179 
00180     BOOL ok = TRUE;
00181 
00182     switch (pCXaraFileRecord->GetTag())
00183     {
00184         case TAG_DEFINERGBCOLOUR:
00185             // Ask the colour document component class to import that colour for us
00186             if (pColComponent)
00187                 ok = pColComponent->ImportSimpleColour(pCXaraFileRecord);
00188             else
00189                 ERROR3("ColourRecordHandler::HandleRecord no pColComponent");
00190             break;
00191         case TAG_DEFINECOMPLEXCOLOUR:
00192             // Ask the colour document component class to import that colour for us
00193             if (pColComponent)
00194                 ok = pColComponent->ImportColourDefinition(pCXaraFileRecord);
00195             else
00196                 ERROR3("ColourRecordHandler::HandleRecord no pColComponent");
00197             break;
00198 
00199         default:
00200             ok = FALSE;
00201             ERROR3_PF(("ColourRecordHandler::HandleRecord I don't handle records with the tag (%d)\n",pCXaraFileRecord->GetTag()));
00202             break;
00203     }
00204 
00205     return ok;
00206 }
00207 
00208 /********************************************************************************************
00209 
00210 >   virtual void ColourRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord,StringBase* pStr)
00211 
00212     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00213     Created:    12/6/96
00214     Inputs:     pRecord = ptr to a record
00215                 pStr = ptr to string to update
00216     Returns:    -
00217     Purpose:    This provides descriptions for the define colour records.
00218     Errors:     -
00219     SeeAlso:    -
00220 
00221 ********************************************************************************************/
00222 
00223 #ifdef XAR_TREE_DIALOG
00224 void ColourRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord, StringBase* pStr)
00225 {
00226     if (pStr == NULL || pRecord == NULL)
00227         return;
00228 
00229     // Call base class first
00230     // This outputs the tag and size
00231     CamelotRecordHandler::GetRecordDescriptionText(pRecord,pStr);
00232 
00233     UINT32 Tag = pRecord->GetTag();
00234     BOOL ok = TRUE;
00235     TCHAR s[256];
00236     INT32 RecordNumber = pRecord->GetRecordNumber();
00237     switch (Tag)
00238     {
00239         case TAG_DEFINERGBCOLOUR:
00240         {
00241             camSprintf(s,_T("Define simple colour reference %d\r\n\r\n"),RecordNumber);
00242             (*pStr) += s;
00243             // Show what the simple RGB colour is
00244             BYTE Red = 0;
00245             if (ok) ok = pRecord->ReadBYTE(&Red);
00246             camSprintf(s,_T("Red\t= %d\r\n"),Red);
00247             (*pStr) += s;
00248             BYTE Green = 0;
00249             if (ok) ok = pRecord->ReadBYTE(&Green);
00250             camSprintf(s,_T("Green\t= %d\r\n"),Green);
00251             (*pStr) += s;
00252             BYTE Blue = 0;
00253             if (ok) ok = pRecord->ReadBYTE(&Blue);
00254             camSprintf(s,_T("Blue\t= %d\r\n"),Blue);
00255             (*pStr) += s;
00256             break;
00257         }
00258         
00259         case TAG_DEFINECOMPLEXCOLOUR:
00260         {
00261             camSprintf(s,_T("Define complex colour reference %d\r\n"),RecordNumber);
00262             (*pStr) += s;
00263             // Show what the simple RGB colour is
00264             BYTE Red = 0;
00265             if (ok) ok = pRecord->ReadBYTE(&Red);
00266             camSprintf(s,_T("Red\t= %d\r\n"),Red);
00267             (*pStr) += s;
00268             BYTE Green = 0;
00269             if (ok) ok = pRecord->ReadBYTE(&Green);
00270             camSprintf(s,_T("Green\t= %d\r\n"),Green);
00271             (*pStr) += s;
00272             BYTE Blue = 0;
00273             if (ok) ok = pRecord->ReadBYTE(&Blue);
00274             camSprintf(s,_T("Blue\t= %d\r\n"),Blue);
00275             (*pStr) += s;
00276 
00277             // read in the colour model
00278             ColourModel ColModel = COLOURMODEL_RGBT;
00279             BYTE temp;
00280             if (ok) ok = pRecord->ReadBYTE(&temp);
00281             ColModel = (ColourModel)temp;
00282 
00283             // read in the colour type
00284             ExportColourType ColType = EXPORT_COLOURTYPE_NORMAL;
00285             if (ok) ok = pRecord->ReadBYTE(&temp);
00286             ColType = (ExportColourType)temp;
00287 
00288             // read in the entry number that this colour should be in the list of colours
00289             UINT32 EntryNumber = 0;
00290             if (ok) ok = pRecord->ReadUINT32(&EntryNumber);
00291 
00292             // read in the record number of the parent colour
00293             UINT32 ParentColour = 0;
00294             if (ok) ok = pRecord->ReadUINT32(&ParentColour);
00295 
00296             // Read in the four colour components
00297             UINT32 Comp1 = 0;
00298             if (ok) ok = pRecord->ReadUINT32(&Comp1);
00299             UINT32 Comp2 = 0;
00300             if (ok) ok = pRecord->ReadUINT32(&Comp2);
00301             UINT32 Comp3 = 0;
00302             if (ok) ok = pRecord->ReadUINT32(&Comp3);
00303             UINT32 Comp4 = 0;
00304             if (ok) ok = pRecord->ReadUINT32(&Comp4);
00305 
00306             String_64 ColName; 
00307             if (ok) ok = pRecord->ReadUnicode(&ColName);//ColName, ColName.MaxLength());
00308             if (ColName.Length() == 0)
00309                 (*pStr) += _T("Unnamed\r\n\r\n");
00310             else
00311             {
00312                 (*pStr) += _T("Colour name:- ");
00313                 (*pStr) += ColName;
00314                 (*pStr) += _T("\r\n\r\n");
00315             }
00316             if (ParentColour != 0)
00317             {
00318                 camSprintf(s,_T("Parent colour reference = %d\r\n"),ParentColour);
00319                 (*pStr) += s;
00320             }
00321             camSprintf(s,_T("Entry number in list = %d\r\n\r\n"),EntryNumber);
00322             (*pStr) += s;
00323 
00324             // Read the colour components according to the colour model.
00325             BOOL Linked = (ColType == EXPORT_COLOURTYPE_LINKED);
00326             switch (ColType)
00327             {
00328                 case EXPORT_COLOURTYPE_NORMAL:
00329                     (*pStr) += _T("Normal colour\r\n");
00330                     DecodeColour(ColModel, Comp1, Comp2, Comp3, Comp4, Linked, pStr);
00331                     break;
00332                 case EXPORT_COLOURTYPE_SPOT:
00333                     (*pStr) += _T("Spot colour\r\n");
00334                     DecodeColour(ColModel, Comp1, Comp2, Comp3, Comp4, Linked, pStr);
00335                     break;
00336                 case EXPORT_COLOURTYPE_LINKED:
00337                     (*pStr) += _T("Linked colour\r\n");
00338                     DecodeColour(ColModel, Comp1, Comp2, Comp3, Comp4, Linked, pStr);
00339                     break;
00340 
00341                 case EXPORT_COLOURTYPE_TINT:
00342                     {
00343                         (*pStr) += _T("Tint colour\r\n");
00344                         FIXED24 Value24 = 0.0;
00345                         Value24.SetAsFixed24(Comp1);
00346                         camSprintf(s,_T("\tTint\t= %f\r\n"),Value24.MakeDouble());
00347                         (*pStr) += s;
00348                     }
00349                     break;
00350 
00351                 case EXPORT_COLOURTYPE_SHADE:
00352                     {
00353                         (*pStr) += _T("Shade colour\r\n");
00354                         FIXED24 Value24 = 0.0;
00355                         Value24.SetAsFixed24(Comp1);
00356                         camSprintf(s,_T("\tSaturation\t= %f\r\n"),Value24.MakeDouble());
00357                         (*pStr) += s;
00358                         Value24.SetAsFixed24(Comp2);
00359                         camSprintf(s,_T("\tValue\t= %f\r\n"),Value24.MakeDouble());
00360                         (*pStr) += s;
00361                     }
00362                     break;
00363 
00364                 default:
00365                     (*pStr) += _T("Unknown type of colour\r\n");
00366                     break;
00367             }
00368         }
00369         break;
00370     }
00371 
00372     return;
00373 }
00374 
00375 /********************************************************************************************
00376 
00377 >   void ColourRecordHandler::DecodeColour(ColourModel ColModel, UINT32 Comp1, UINT32 Comp2, UINT32 Comp3, UINT32 Comp4,
00378                                            BOOL Linked, StringBase* pStr)
00379 
00380     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00381     Created:    13/6/96
00382     Inputs:     ColModel    - colour model of colour
00383                 Comp1, Comp2, Comp3, Comp4  - colour components
00384                 Linked      - True if this is a linked colour
00385                 pStr        - ptr to string to update
00386     Returns:    -
00387     Purpose:    This provides descriptions for the normal, linked and spot colour records.
00388     Errors:     -
00389     SeeAlso:    -
00390 
00391 ********************************************************************************************/
00392 
00393 void ColourRecordHandler::DecodeColour(ColourModel ColModel, UINT32 Comp1, UINT32 Comp2, UINT32 Comp3, UINT32 Comp4,
00394                                        BOOL Linked, StringBase* pStr)
00395 {
00396     // Decode the contents of the colour according to what model it is  
00397     switch (ColModel)
00398     {
00399         case COLOURMODEL_RGBT:
00400             (*pStr) += _T("\tRed\t= ");
00401             DecodeComponent(Comp1, Linked, pStr);
00402             (*pStr) += _T("\tGreen\t= ");
00403             DecodeComponent(Comp2, Linked, pStr);
00404             (*pStr) += _T("\tBlue\t= ");
00405             DecodeComponent(Comp3, Linked, pStr);
00406             break;
00407 
00408         case COLOURMODEL_CMYK:
00409             (*pStr) += _T("\tCyan\t= ");
00410             DecodeComponent(Comp1, Linked, pStr);
00411             (*pStr) += _T("\tMagenta\t= ");
00412             DecodeComponent(Comp2, Linked, pStr);
00413             (*pStr) += _T("\tYellow\t= ");
00414             DecodeComponent(Comp3, Linked, pStr);
00415             (*pStr) += _T("\tKey\t= ");
00416             DecodeComponent(Comp4, Linked, pStr);
00417             break;
00418         case COLOURMODEL_HSVT:
00419             (*pStr) += _T("\tHue\t\t= ");
00420             DecodeComponent(Comp1, Linked, pStr);
00421             (*pStr) += _T("\tSaturation\t= ");
00422             DecodeComponent(Comp2, Linked, pStr);
00423             (*pStr) += _T("\tValue\t\t= ");
00424             DecodeComponent(Comp3, Linked, pStr);
00425             break;
00426 
00427         case COLOURMODEL_GREYT:
00428             (*pStr) += _T("\tGreyscale\t= ");
00429             DecodeComponent(Comp1, Linked, pStr);
00430             break;
00431         default:
00432             (*pStr) += _T("\tUnknown colour model\r\n");
00433             break;
00434     }
00435 
00436     return;
00437 }
00438 
00439 /********************************************************************************************
00440 
00441 >   void ColourRecordHandler::DecodeComponent(UINT32 Comp, BOOL Linked, StringBase* pStr)
00442 
00443     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00444     Created:    13/6/96
00445     Inputs:     Comp        - colour component
00446                 Linked      - True if this is a linked colour
00447                 pStr        - ptr to string to update
00448     Returns:    -
00449     Purpose:    This provides descriptions for an individual colour component.
00450     Errors:     -
00451     SeeAlso:    -
00452 
00453 ********************************************************************************************/
00454 
00455 void ColourRecordHandler::DecodeComponent(UINT32 Comp, BOOL Linked, StringBase* pStr)
00456 {
00457     TCHAR s[256];
00458     // read the Red colour component in
00459     FIXED24 LinkValue = FIXED24(-8.0);
00460     FIXED24 Value24 = 0.0;
00461     Value24.SetAsFixed24(Comp);
00462     if (Linked && (Value24 == LinkValue))
00463     {
00464         (*pStr) += _T("Inherits\r\n");
00465     }
00466     else
00467     {
00468         camSprintf(s,_T("%f\r\n"),Value24.MakeDouble());
00469         (*pStr) += s;
00470     }
00471 }
00472 
00473 #endif
00474 
00475 // #endif // NEW_NATIVE_FILTER
00476 

Generated on Sat Nov 10 03:46:41 2007 for Camelot by  doxygen 1.4.4