cxfile.h

Go to the documentation of this file.
00001 // $Id: cxfile.h 1688 2006-08-10 12:05:20Z gerry $
00002 // Header for the controlling class of the v2 file format
00003 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00004 ================================XARAHEADERSTART===========================
00005  
00006                Xara LX, a vector drawing and manipulation program.
00007                     Copyright (C) 1993-2006 Xara Group Ltd.
00008        Copyright on certain contributions may be held in joint with their
00009               respective authors. See AUTHORS file for details.
00010 
00011 LICENSE TO USE AND MODIFY SOFTWARE
00012 ----------------------------------
00013 
00014 This file is part of Xara LX.
00015 
00016 Xara LX is free software; you can redistribute it and/or modify it
00017 under the terms of the GNU General Public License version 2 as published
00018 by the Free Software Foundation.
00019 
00020 Xara LX and its component source files are distributed in the hope
00021 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00022 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00023 See the GNU General Public License for more details.
00024 
00025 You should have received a copy of the GNU General Public License along
00026 with Xara LX (see the file GPL in the root directory of the
00027 distribution); if not, write to the Free Software Foundation, Inc., 51
00028 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00029 
00030 
00031 ADDITIONAL RIGHTS
00032 -----------------
00033 
00034 Conditional upon your continuing compliance with the GNU General Public
00035 License described above, Xara Group Ltd grants to you certain additional
00036 rights. 
00037 
00038 The additional rights are to use, modify, and distribute the software
00039 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00040 library and any other such library that any version of Xara LX relased
00041 by Xara Group Ltd requires in order to compile and execute, including
00042 the static linking of that library to XaraLX. In the case of the
00043 "CDraw" library, you may satisfy obligation under the GNU General Public
00044 License to provide source code by providing a binary copy of the library
00045 concerned and a copy of the license accompanying it.
00046 
00047 Nothing in this section restricts any of the rights you have under
00048 the GNU General Public License.
00049 
00050 
00051 SCOPE OF LICENSE
00052 ----------------
00053 
00054 This license applies to this program (XaraLX) and its constituent source
00055 files only, and does not necessarily apply to other Xara products which may
00056 in part share the same code base, and are subject to their own licensing
00057 terms.
00058 
00059 This license does not apply to files in the wxXtra directory, which
00060 are built into a separate library, and are subject to the wxWindows
00061 license contained within that directory in the file "WXXTRA-LICENSE".
00062 
00063 This license does not apply to the binary libraries (if any) within
00064 the "libs" directory, which are subject to a separate license contained
00065 within that directory in the file "LIBS-LICENSE".
00066 
00067 
00068 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00069 ----------------------------------------------
00070 
00071 Subject to the terms of the GNU Public License (see above), you are
00072 free to do whatever you like with your modifications. However, you may
00073 (at your option) wish contribute them to Xara's source tree. You can
00074 find details of how to do this at:
00075   http://www.xaraxtreme.org/developers/
00076 
00077 Prior to contributing your modifications, you will need to complete our
00078 contributor agreement. This can be found at:
00079   http://www.xaraxtreme.org/developers/contribute/
00080 
00081 Please note that Xara will not accept modifications which modify any of
00082 the text between the start and end of this header (marked
00083 XARAHEADERSTART and XARAHEADEREND).
00084 
00085 
00086 MARKS
00087 -----
00088 
00089 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00090 designs are registered or unregistered trademarks, design-marks, and/or
00091 service marks of Xara Group Ltd. All rights in these marks are reserved.
00092 
00093 
00094       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00095                         http://www.xara.com/
00096 
00097 =================================XARAHEADEREND============================
00098  */
00099 
00100 #ifndef INC_CXFILE
00101 #define INC_CXFILE
00102 
00103 //#include "doccoord.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "list.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 //#include "ccfile.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 #include "taglists.h"
00107 //#include "cxfrech.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 #if defined(EXCLUDE_FROM_XARLIB)
00109 #include "xarlib.h"
00110 #endif
00111 
00112 class CCLexFile;
00113 class Progress;
00114 class StringBase;
00115 class BaseCamelotFilter;
00116 class CCPanose;
00117 class BitmapSource;
00118 
00119 class CXaraFileRecord;
00120 class CXaraFileRecordHandler;
00121 class CamelotRecordHandler;
00122 class StandardDefaultRecordHandler;
00123 class StripSubTreeRecordHandler;
00124 class CXaraFileMapTagToHandler;
00125 
00126 // Unicode characters in the XAR file format are always 16-bit UTF16
00127 #define SIZEOF_XAR_UTF16 2                  // UTF16 characters are only 2 byte
00128 
00129 /********************************************************************************************
00130 
00131 >   class CXaraFile : public CCObject
00132 
00133     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00134     Created:    20/5/96
00135     Base Class: -
00136     Purpose:    Encapsulates the v2 file format functionality.
00137                 It provides a standard way for reading and writing v2 format files.
00138 
00139                 It uses a general file handling class (in this case CCFile) to do all the reading
00140                 and writing to the file.  This class provides a record-based interface,
00141                 which also allows this class (and asscociated class) to provide extra error handling
00142                 functionality.
00143 
00144     SeeAlso:    CCFile
00145 
00146 ********************************************************************************************/
00147 
00148 
00149 class CXaraFile : public CCObject
00150 {
00151     // Give my name in memory dumps
00152     CC_DECLARE_DYNAMIC(CXaraFile);
00153 
00154 public:
00155     CXaraFile();
00156     virtual ~CXaraFile() { /* empty */ }
00157 
00158     virtual BOOL OpenToWrite(CCLexFile* pCCFile);
00159     virtual BOOL OpenToRead(CCLexFile* pCCFile);
00160     virtual BOOL Close();
00161 
00162     // Function to turn Compression on or off on the underlying CCFile
00163     // Reading
00164     BOOL SetCompression(BOOL NewState);
00165 
00166     // Writing
00167     virtual BOOL StartCompression();
00168     virtual BOOL StopCompression();
00169     virtual BOOL IsCompressionOn();
00170 
00171     // This allows people access to the CCFile which is being used
00172     // Note: only people who have a genuine reason need to access this - e.g. bitmap savers
00173     virtual CCLexFile* GetCCFile(void) const;
00174 
00175     // This allows the record size to be got at when reading
00176     UINT32 GetCurrentRecordSize();
00177 
00178     virtual INT32 StartRecord(UINT32 Tag,INT32 Size);
00179     virtual BOOL EndRecord(void);
00180     virtual INT32 StartStreamedRecord(UINT32 Tag,INT32 Size);
00181     virtual BOOL EndStreamedRecord(UINT32 *RecordSize);
00182 
00183     // These are used during writing???
00184     UINT32 GetRecordTag();
00185     INT32  GetRecordNum();
00186 
00187     // Write functions
00188     virtual BOOL Write(BYTE b);
00189 
00190     BOOL Write(UINT32 n);
00191     BOOL Write(INT32 n);
00192     BOOL Write(const DocCoord& Coord);
00193     BOOL Write(BYTE* pBuf,UINT32 Size);
00194     BOOL Write(FLOAT f);
00195     BOOL Write(double d);
00196 
00197     BOOL WriteWCHAR(WCHAR w);
00198 
00199     BOOL WriteCCPanose(const CCPanose& Panose);
00200 
00201 #if !defined(EXCLUDE_FROM_XARLIB)
00202     BOOL WriteBitmapSource(const BitmapSource& Source, UINT32 Height, BaseCamelotFilter* pThisFilter);
00203 #endif
00204 
00205     BOOL Write(TCHAR* pStr);                // Calls WriteUnicode() (Use WriteASCII() for ASCII writing)
00206     BOOL WriteASCII(TCHAR* pStr);
00207     BOOL WriteUnicode(TCHAR* pStr);
00208 
00209     // Writes a complete record out to file
00210     // DO NOT use this for records which will be referenced
00211     virtual UINT32 Write(CXaraFileRecord* pRecord);
00212 
00213     // Writes a complete record out to file
00214     // Use this for records which will be referenced
00215     virtual UINT32 WriteDefinitionRecord(CXaraFileRecord* pRecord);
00216 
00217     // Read functions
00218     BOOL Read(UINT32* pUINT32);
00219     BOOL Read(BYTE* pBuf,UINT32 Size);
00220     BOOL Read(BYTE* pBYTE);
00221     BOOL Read(FLOAT* pf);
00222     BOOL Read(double* pd);
00223 
00224     BOOL ReadWCHAR(WCHAR *pw);
00225 
00226     BOOL ReadCCPanose(CCPanose *pPanose);
00227 
00228     BOOL Read(TCHAR* pStr,UINT32 MaxChars);
00229     BOOL ReadUnicode(TCHAR* pStr,UINT32 MaxChars);
00230 
00231     BOOL ReadNextRecord();
00232     BOOL ReadNextRecordHeader();
00233 
00234     virtual UINT32  GetNumBytesWritten()            { return NumBytesWritten; }
00235     virtual UINT32  GetNumBytesRead()               { return NumBytesRead; }
00236     virtual UINT32  GetTotalNumBytesToRead()        { return TotalNumBytesToRead; }
00237     virtual void    SetTotalNumBytesToRead(UINT32 n)    { TotalNumBytesToRead = n; }
00238 
00239     virtual FilePos GetFilePos();
00240 
00241 #if !defined(EXCLUDE_FROM_XARLIB)
00242     virtual BOOL SetUpHandlers(BaseCamelotFilter* pThisFilter);
00243 #else
00244     virtual BOOL SetUpHandlers(void);
00245     void SetExternalRecordHandler(void* pMagic, RecordHandler* pfnRecordHandler);
00246 
00247     void SetEndOfFile() { EndOfFile = TRUE; }
00248     BOOL IsEndOfFile() { return(EndOfFile); }
00249 #endif
00250 
00251     virtual void SetDefaultRecordHandler(CXaraFileRecordHandler* pHandler);
00252     virtual CXaraFileRecordHandler* GetDefaultRecordHandler();
00253 
00254     virtual void SetStripSubTreeRecordHandler(StripSubTreeRecordHandler* pHandler);
00255     virtual StripSubTreeRecordHandler* GetStripSubTreeRecordHandler();
00256 
00257     // This function will ensure that the next sub tree is thrown away.
00258     void StripNextSubTree();
00259 
00260     // Error function
00261     void GotError(UINT32 errorID);
00262     void GotError( UINT32 errorID , const TCHAR* errorString);
00263 
00264     // Record Handler registration
00265     BOOL RegisterRecordHandlers(List* pListOfHandlers);
00266 
00267     // Camelot-specific stuff
00268     UINT32              GetLastReadTag()                            { return ReadTag; }
00269 
00270 #if !defined(EXCLUDE_FROM_XARLIB)
00271     void                SetFilter(BaseCamelotFilter* pThisFilter)   { pFilter = pThisFilter; }
00272     BaseCamelotFilter*  GetFilter()                                 { return pFilter; }
00273 #else
00274     // Tag management functions
00275     void AddAtomicTag(AtomicTagListItem* pItem);
00276     void AddEssentialTag(EssentialTagListItem* pItem);
00277 
00278     BOOL IsTagInAtomicList(UINT32 Tag);
00279     BOOL IsTagInEssentialList(UINT32 Tag);
00280 
00281     BOOL WriteRemainingAtomicTagDefinitions();
00282 #endif
00283 
00284 protected:
00285 
00286     virtual CXaraFileRecordHandler* FindHandler(UINT32 Tag);
00287     virtual CXaraFileRecordHandler* SearchForHandler(UINT32 Tag);
00288     virtual CXaraFileRecordHandler* LookUpHandler(UINT32 Tag);
00289 
00290     virtual void SetUpHandlerMap();
00291     virtual void ResetHandlers();
00292 
00293 protected:
00294     // Should only be used by people who know what they are doing e.g. compression
00295     // Hence why it is protected
00296     UINT32 WriteRecordHeader(UINT32 Tag, INT32 Size);
00297 
00298     virtual BOOL FixStreamedRecordHeader(UINT32 *RecordSize);
00299 
00300     virtual void IncNumBytesWritten(UINT32 n){ NumBytesWritten += n; }
00301     virtual void IncNumBytesRead(UINT32 n)  { NumBytesRead    += n; }
00302 
00303 protected:
00304     CXaraFileRecord*    pRecord;
00305     BOOL                WriteToRecord;
00306 
00307 // This rampant private changed by Gerry on 14/7/97
00308 //private:
00309 protected:
00310     CCLexFile*          pCCFile;
00311     INT32               RecordNumber;
00312     UINT32              NumBytesWritten;
00313     UINT32              NumBytesRead;
00314     UINT32              TotalNumBytesToRead;
00315     UINT32              ProgressID;
00316 
00317     // Header data for the record currently being read in
00318     UINT32              ReadTag;
00319     UINT32              ReadSize;
00320 
00321     // Record Handler list
00322     List* pRecordHandlerList;
00323 
00324     // The default record handler
00325     CXaraFileRecordHandler* pDefaultRecordHandler;
00326     CamelotRecordHandler* pStandardDefaultRecordHandler;
00327 
00328     // Handler used to strip sub trees when an unrecognised atomic record is read
00329     StripSubTreeRecordHandler* pStripSubTreeRecordHandler;
00330     StripSubTreeRecordHandler* pStandardStripSubTreeRecordHandler;
00331 
00332     // Streamed Record vars
00333     FilePos StartOfStreamedRecord;
00334     BOOL    WritingStreamedRecord;
00335     BOOL    CompOffDueToStreamedRecord;
00336 
00337     // Camelot-specific stuff
00338     BaseCamelotFilter*          pFilter;
00339     CXaraFileMapTagToHandler*   pMap;
00340 
00341 #if defined(EXCLUDE_FROM_XARLIB)
00342     // Tag management variables
00343     AtomicTagList*      pAtomicTagList;
00344     EssentialTagList*   pEssentialTagList;
00345 
00346     BOOL    EndOfFile;
00347 #endif
00348 };
00349 
00350 /********************************************************************************************
00351 
00352 >   class NULLXaraFile : public CXaraFile
00353 
00354     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00355     Created:    3/6/96
00356     Base Class: CXaraFile
00357     Purpose:    Dummy CXaraFile that swallows up all bytes written to it
00358 
00359     SeeAlso:    CXaraFile
00360 
00361 ********************************************************************************************/
00362 
00363 class NULLXaraFile : public CXaraFile
00364 {
00365     // Give my name in memory dumps
00366     CC_DECLARE_DYNAMIC(NULLXaraFile);
00367 
00368 public:
00369     NULLXaraFile() { /* empty */ }
00370 
00371     virtual BOOL OpenToWrite(CCLexFile* pThisCCFile);
00372     virtual BOOL Close();
00373     virtual BOOL Write(BYTE b);
00374 
00375     virtual FilePos GetFilePos();
00376 
00377     virtual BOOL IsCompressionOn();
00378     virtual BOOL StartCompression();
00379     virtual BOOL StopCompression();
00380 
00381     // This allows people access to the CCFile which is being used
00382     // Note: only people who have a genuine reason need to access this - e.g. bitmap savers
00383     virtual CCLexFile* GetCCFile() const;
00384 
00385 protected:
00386     virtual BOOL FixStreamedRecordHeader(UINT32 *RecordSize);
00387 };
00388 
00389 
00390 
00391 class StandardDefaultRecordHandler : public CamelotRecordHandler
00392 {
00393     // Give my name in memory dumps
00394     CC_DECLARE_DYNAMIC(StandardDefaultRecordHandler);
00395 
00396 public:
00397     StandardDefaultRecordHandler()
00398     {
00399 #if defined(EXCLUDE_FROM_XARLIB)
00400         m_pfnRecordHandler = NULL;
00401         m_pMagic = NULL;
00402 #endif
00403     };
00404 
00405     // Pure virtual functions that must be overridden.
00406     virtual UINT32* GetTagList() { static UINT32 TagList[]={CXFRH_TAG_LIST_END}; return (UINT32*)TagList; }
00407     virtual BOOL    HandleRecord(CXaraFileRecord* pCXaraFileRecord);
00408 
00409     virtual void    IncProgressBarCount(UINT32 n) {};
00410     virtual BOOL    IsStreamed(UINT32 Tag) { return FALSE; }
00411 
00412 #if defined(EXCLUDE_FROM_XARLIB)
00413     void SetExternalHandler(void* pMagic, RecordHandler pfnRecordHandler)
00414     {
00415         m_pfnRecordHandler = pfnRecordHandler;
00416         m_pMagic = pMagic;
00417     }
00418 
00419 protected:
00420     RecordHandler* m_pfnRecordHandler;
00421     void* m_pMagic;
00422 #endif
00423 };
00424 
00425 /********************************************************************************************
00426 
00427 >   class GeneralRecordHandler : public CamelotRecordHandler
00428 
00429     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00430     Created:    30/5/96
00431     Purpose:    This is the general record handler.
00432                 It handles all the general record types, such as the End Of File, file header, etc.
00433 
00434 ********************************************************************************************/
00435 
00436 class GeneralRecordHandler : public CamelotRecordHandler
00437 {
00438     // Give my name in memory dumps
00439     CC_DECLARE_DYNAMIC(GeneralRecordHandler);
00440 
00441 public:
00442     virtual UINT32* GetTagList();
00443     virtual BOOL HandleRecord(CXaraFileRecord* pCXaraFileRecord);
00444     virtual void IncProgressBarCount(UINT32 n) {};
00445 
00446 #ifdef XAR_TREE_DIALOG
00447     virtual void GetRecordDescriptionText(CXaraFileRecord* pCXaraFileRecord,StringBase* Str);
00448 #endif
00449 
00450 private:
00451     BOOL HandleFileHeader(CXaraFileRecord* pCXaraFileRecord);
00452     BOOL HandleAtomicTagsRecord(CXaraFileRecord* pCXaraFileRecord);
00453     BOOL HandleEssentialTagsRecord(CXaraFileRecord* pCXaraFileRecord);
00454 #if !defined(EXCLUDE_FROM_XARLIB)
00455     BOOL HandleTagDescriptionRecord(CXaraFileRecord* pCXaraFileRecord);
00456     BOOL HandleTagNudgeSizeRecord(CXaraFileRecord* pCXaraFileRecord);
00457 #endif
00458 };
00459 
00460 #endif  // INC_CXFILE

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