cxfrec.cpp

Go to the documentation of this file.
00001 // $Id: cxfrec.cpp 1695 2006-08-12 19:08:10Z alex $
00002 // Implementation of the record 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 #include "camtypes.h"
00101 
00102 //#include "cxfrec.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00103 #include "cxfile.h"
00104 //#include "cxfdefs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 
00106 #if !defined(EXCLUDE_FROM_XARLIB)
00107 //#include "camfiltr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 #endif
00109 
00110 //#include "ccpanose.h"
00111 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "paths.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 #include "unicdman.h"
00114 
00115 #include "fttyplis.h"
00116 
00117 #include "hardwaremanager.h"
00118 using namespace oilHardwareManager;
00119 
00120 // This define has different meaning under Linux
00121 #if !defined(__WXMSW__)
00122 #undef UNICODE
00123 #endif
00124 
00125 CC_IMPLEMENT_DYNAMIC(CXaraFileRecord,CCObject);
00126 CC_IMPLEMENT_DYNAMIC(CamelotFileRecord,CXaraFileRecord);
00127 
00128 // This will get Camelot to display the filename and linenumber of any memory allocations
00129 // that are not released at program exit
00130 // Declare smart memory handling in Debug builds
00131 #define new CAM_DEBUG_NEW
00132 
00133 
00134 #define RELPATHINTERLEAVE
00135 
00136 #ifndef SIZEOF_XAR_UTF16
00137 // Unicode characters in the XAR file format are always 16-bit UTF16
00138 #define SIZEOF_XAR_UTF16 2                  // UTF16 characters are only 2 byte
00139 #endif
00140 
00141 
00142 
00143 //-------------------------------------------------------------------------------------------
00144 //-------------------------------------------------------------------------------------------
00145 //-------------------------------------------------------------------------------------------
00146 
00147 
00148 /********************************************************************************************
00149 
00150 >   CXaraFileRecord::CXaraFileRecord(UINT32 Tag,INT32 Size)
00151 
00152     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00153     Created:    21/5/96
00154     Inputs:     Tag - Tag value for the record
00155                 Size- The exact size of the record in bytes, or CXF_UNKNOWN_SIZE
00156     Purpose:    Creates a record object.
00157                 These are used by CXaraFile for reading and writing records.
00158     Errors:     -
00159     SeeAlso:    -
00160 
00161 ********************************************************************************************/
00162 
00163 CXaraFileRecord::CXaraFileRecord(UINT32 Tag,INT32 Size)
00164 {
00165     SetUpVars(Tag,Size);
00166 }
00167 
00168 /********************************************************************************************
00169 
00170 >   void CXaraFileRecord::SetUpVars(UINT32 ThisTag,INT32 Size)
00171 
00172     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00173     Created:    21/5/96
00174     Inputs:     ThisTag - Tag value for the record
00175                 Size    - The exact size of the record in bytes, or CXF_UNKNOWN_SIZE
00176     Returns:    -
00177     Purpose:    Sets up the member vars for this record
00178 
00179     Errors:     -
00180     SeeAlso:    -
00181 
00182 ********************************************************************************************/
00183 
00184 void CXaraFileRecord::SetUpVars(UINT32 ThisTag,INT32 Size)
00185 {
00186     Tag         = ThisTag;
00187     KnownSize   = Size;
00188     SizeIsKnown = (Size != CXF_UNKNOWN_SIZE);
00189     RecordNumber= 0;
00190 
00191     pBuffer     = NULL;
00192     BufferSize  = 0;
00193     CurrentPos  = 0;
00194     Overflow    = FALSE;
00195     m_pTypeList = NULL;
00196     Initialised = FALSE;
00197 }
00198 
00199 /********************************************************************************************
00200 
00201 >   CXaraFileRecord::~CXaraFileRecord()
00202 
00203     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00204     Created:    21/5/96
00205     Purpose:    Default destructor
00206 
00207     Errors:     -
00208     SeeAlso:    -
00209 
00210 ********************************************************************************************/
00211 
00212 CXaraFileRecord::~CXaraFileRecord()
00213 {
00214     FreeBuffer();
00215 }
00216 
00217 /********************************************************************************************
00218 
00219 >   BOOL CXaraFileRecord::Init(BOOL ZeroMemBlock = FALSE)
00220 
00221     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00222     Created:    21/5/96
00223     Inputs:     ZeroMemBlock = If TRUE, any memory allocated for the record is filled with zeros
00224     Returns:    TRUE if initialised OK
00225                 FALSE otherwise
00226     Purpose:    You must call this function before use use any of the Write functions.
00227                 It initialises the record ready for writing data to (i.e. allocates a buffer)               
00228 
00229     Errors:     -
00230     SeeAlso:    -
00231 
00232 ********************************************************************************************/
00233 
00234 BOOL CXaraFileRecord::Init(BOOL ZeroMemBlock)
00235 {
00236     if (!Initialised)
00237     {
00238         ERROR2IF(SizeIsKnown && KnownSize < 0,FALSE,"A -ve size has been given");
00239 
00240         ERROR3IF(pBuffer != NULL,"Initialising the record, yet it already has a buffer");
00241         
00242         if (SizeIsKnown)
00243             Initialised = AllocBuffer(KnownSize);
00244         else
00245             Initialised = AllocBuffer(CXF_RECORD_CHUNK);
00246     }
00247 
00248     if (Initialised && ZeroMemBlock)
00249     {
00250         BYTE* pBuf = GetBuffer();
00251         if (pBuf != NULL)
00252         {
00253             for (UINT32 i=0;i<BufferSize;i++)
00254                 pBuf[i] = 0;
00255         }
00256     }
00257 
00258     if (Initialised)
00259     {
00260         m_pTypeList = new FTTypeList;
00261         if (m_pTypeList == NULL)
00262             TRACEUSER( "Gerry", _T("Failed to create FTTypeList\n"));
00263     }
00264     
00265     return Initialised;
00266 }
00267 
00268 
00269 /********************************************************************************************
00270 
00271 >   void CXaraFileRecord::DumpTypes(void)
00272 
00273     Author:     Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
00274     Created:    12/07/97
00275     Purpose:    Dumps the type list to TRACE
00276 
00277 ********************************************************************************************/
00278 
00279 void CXaraFileRecord::DumpTypes(void)
00280 {
00281     TRACEUSER( "Gerry", _T("Tag:% 5d  Size:% 6d  Data:"), Tag, GetSize());
00282 
00283     if (m_pTypeList == NULL ||
00284         m_pTypeList->GetCount() == 0)
00285     {
00286         TRACEUSER( "Gerry", _T(" None\n"));
00287         return;
00288     }
00289 
00290     BYTE* pPtr = m_pTypeList->GetBuffer();
00291     DWORD Count = m_pTypeList->GetCount();
00292     DWORD Index;
00293     for (Index = 0; Index < Count; Index++)
00294     {
00295         PTSTR           pType = NULL;
00296         DWORD len = 0;
00297         switch (pPtr[Index])
00298         {
00299         case FTT_BYTE:      pType = _T(" Byte");        break;
00300         case FTT_UINT32:        pType = _T(" ULong");       break;
00301         case FTT_INT32:     pType = _T(" Long");        break;
00302         case FTT_UINT16:    pType = _T(" UInt16");      break;
00303         case FTT_INT16:     pType = _T(" Int16");       break;
00304         case FTT_FLOAT:     pType = _T(" Float");       break;
00305         case FTT_DOUBLE:    pType = _T(" Double");      break;
00306         case FTT_WCHAR:     pType = _T(" WChar");       break;
00307         case FTT_ASCII:     pType = _T(" Ascii");       break;
00308         case FTT_UNICODE:   pType = _T(" Unicode");     break;
00309         case FTT_COORD:     pType = _T(" Coord");       break;
00310         case FTT_INTCOORD:  pType = _T(" IntCoord");    break;
00311         case FTT_BINHEX:
00312             {
00313                 pType = _T(" Buffer");
00314                 len = *((DWORD*)(pPtr+Index+1));    // Get the length (BYTE pointer arithmetic)
00315                 Index += 4;                         // and skip it
00316                 break;
00317             }
00318         default:            pType = _T(" <BAD TYPE>");  break;
00319         }
00320 
00321         if (pType)
00322             TRACEUSER("Gerry", pType);
00323         if (len != 0)
00324             TRACEUSER( "Gerry", _T("(%d)"), len);
00325     }
00326     TRACEUSER( "Gerry", _T("\n"));
00327 }
00328 
00329 
00330 /********************************************************************************************
00331 
00332 >   BOOL CXaraFileRecord::Reinit(UINT32 ThisTag,INT32 ThisSize)
00333 
00334     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00335     Created:    31/5/96
00336     Inputs:     ThisTag = tag for the record
00337                 ThisSize= The exact size of the record in bytes, or CXF_UNKNOWN_SIZE
00338     Returns:    TRUE if initialised OK
00339                 FALSE otherwise
00340     Purpose:    Allows you to reinit the record with a different record tag & size
00341 
00342     Errors:     -
00343     SeeAlso:    -
00344 
00345 ********************************************************************************************/
00346 
00347 BOOL CXaraFileRecord::Reinit(UINT32 ThisTag,INT32 ThisSize)
00348 {
00349     FreeBuffer();
00350     SetUpVars(ThisTag,ThisSize);
00351     return Init();
00352 }
00353 
00354 /********************************************************************************************
00355 
00356 >   CXaraFileRecord* CXaraFileRecord::GetCopy()
00357 
00358     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00359     Created:    7/6/96
00360     Inputs:     -
00361     Returns:    ptr to a CXaraFileRecord, which is an exact copy
00362     Purpose:    Copy function
00363     Errors:     -
00364     SeeAlso:    -
00365 
00366 ********************************************************************************************/
00367 
00368 CXaraFileRecord* CXaraFileRecord::GetCopy()
00369 {
00370     BOOL ok = TRUE;
00371     UINT32 Size = GetSize();
00372 
00373     CXaraFileRecord* pRecord = new CXaraFileRecord(GetTag(),Size);
00374 
00375     if (pRecord != NULL && Size > 0)
00376     {
00377         ok = pRecord->Init();
00378 
00379         if (ok)
00380         {
00381             BYTE* pSrcBuf  = GetBuffer();
00382             BYTE* pDestBuf = pRecord->GetBuffer();
00383 
00384             ok = (pSrcBuf != NULL) && (pDestBuf != NULL);
00385             if (ok) memcpy(pDestBuf,pSrcBuf,Size);
00386         }
00387     }
00388 
00389     if (pRecord != NULL && RecordNumber > 0)
00390         pRecord->SetRecordNumber(RecordNumber);
00391 
00392     if (!ok && pRecord != NULL)
00393     {
00394         delete pRecord;
00395         pRecord = NULL;
00396     }
00397     
00398     return pRecord;
00399 }
00400 
00401 /********************************************************************************************
00402 
00403 >   UINT32 CXaraFileRecord::GetSize()
00404 
00405     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00406     Created:    10/6/96
00407     Inputs:     -
00408     Returns:    The size of the record
00409     Purpose:    Returns the size of the record.
00410 
00411                 If the size of the record is known exactly, it returns the size of the buffer
00412                 that's been allocated for the record.
00413 
00414                 If it is not known (i.e. when creating a rec of unknown length for writing purposes)
00415                 the current write position in the buffer is returned.  This is the dangerous case, because
00416                 it is possible that the size returned is not the correct final size.
00417 
00418     Errors:     -
00419     SeeAlso:    -
00420 
00421 ********************************************************************************************/
00422 
00423 UINT32 CXaraFileRecord::GetSize()
00424 {
00425     if (SizeIsKnown)
00426         return BufferSize;
00427     else
00428     {
00429         //TRACEUSER( "Markn", _T("*+*+* Getting the size of a record, yet don't know it's exact size\n"));
00430         return CurrentPos;
00431     }
00432 }
00433 
00434 /********************************************************************************************
00435 
00436 >   void CXaraFileRecord::FreeBuffer()
00437 
00438     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00439     Created:    21/5/96
00440     Inputs:     -
00441     Returns:    -
00442     Purpose:    Deallocates the associated buffer, if it has one.
00443                 Can be safely called if the record no longer has a buffer.
00444     Errors:     -
00445     SeeAlso:    -
00446 
00447 ********************************************************************************************/
00448 
00449 void CXaraFileRecord::FreeBuffer()
00450 {
00451     if (pBuffer != NULL)
00452     {
00453         CCFree(pBuffer);
00454         pBuffer = NULL;
00455         BufferSize = 0;
00456     }
00457 
00458     if (m_pTypeList != NULL)
00459     {
00460         delete m_pTypeList;
00461         m_pTypeList = NULL;
00462     }
00463 
00464     Initialised = FALSE;
00465 }
00466 
00467 /********************************************************************************************
00468 
00469 >   BOOL CXaraFileRecord::AllocBuffer(INT32 Size)
00470 
00471     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00472     Created:    21/5/96
00473     Inputs:     Size = Size of buffer in bytes
00474     Returns:    TRUE if ok, FALSE otherwise
00475     Purpose:    Allocates a buffer of the given size.
00476 
00477                 If Size == 0, no buffer is allocated, but TRUE is still returned.
00478 
00479     Errors:     -
00480     SeeAlso:    -
00481 
00482 ********************************************************************************************/
00483 
00484 BOOL CXaraFileRecord::AllocBuffer(INT32 Size)
00485 {
00486     ERROR3IF(Size < 0,"Buffer size is < 0, it's a bit difficult to allocate that many bytes");
00487 
00488     FreeBuffer();
00489 
00490     if (Size == 0)
00491         return TRUE;
00492 
00493     if (Size > 0)
00494         pBuffer = CCMalloc(Size);
00495 
00496     if (pBuffer != NULL)
00497     {
00498         BufferSize = Size;
00499         return TRUE;
00500     }
00501     else
00502         return FALSE;
00503 }
00504 
00505 /********************************************************************************************
00506 
00507 >   BOOL CXaraFileRecord::ExtendBuffer(INT32 Size)
00508 
00509     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00510     Created:    21/5/96
00511     Inputs:     Size = number of *extra* bytes to add to the buffer
00512     Returns:    TRUE if ok, FALSE otherwise
00513     Purpose:    Extends the buffer by the given amount of bytes
00514     Errors:     -
00515     SeeAlso:    -
00516 
00517 ********************************************************************************************/
00518 
00519 BOOL CXaraFileRecord::ExtendBuffer(INT32 Size)
00520 {
00521     ERROR3IF(pBuffer == NULL,"No buffer to extend");
00522     if (pBuffer == NULL)
00523         return FALSE;
00524 
00525     pBuffer = CCRealloc(pBuffer,BufferSize+Size);
00526 
00527     if (pBuffer != NULL)
00528     {
00529         BufferSize += Size;
00530         return TRUE;
00531     }
00532     else
00533         return FALSE;
00534 }
00535 
00536 /********************************************************************************************
00537 
00538 >   INT32 CXaraFileRecord::GetRecordNumber()
00539 
00540     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00541     Created:    30/5/96
00542     Inputs:     -
00543     Returns:    The record number of this record
00544     Purpose:    Returns the record's number.
00545                 This value is set by a call to SetRecordNumber()
00546 
00547     Errors:     -
00548     SeeAlso:    -
00549 
00550 ********************************************************************************************/
00551 
00552 INT32 CXaraFileRecord::GetRecordNumber()
00553 {
00554     ERROR3IF(RecordNumber == 0,"Record number has not been set, or set incorrectly");
00555 
00556     return RecordNumber;
00557 }
00558 
00559 /********************************************************************************************
00560 
00561 >   void CXaraFileRecord::SetRecordNumber(INT32 n)
00562 
00563     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00564     Created:    30/5/96
00565     Inputs:     n = The record number of this record (must be > 0)
00566     Returns:    -
00567     Purpose:    Sets the record's number.
00568                 This value is read by a call to GetRecordNumber()
00569 
00570     Errors:     -
00571     SeeAlso:    -
00572 
00573 ********************************************************************************************/
00574 
00575 void CXaraFileRecord::SetRecordNumber(UINT32 n)
00576 {
00577     ERROR3IF(n < 1,"Record number is invalid.  Must be >= 1");
00578 
00579     RecordNumber = n;
00580 }
00581 
00582 /********************************************************************************************
00583 
00584 >   BOOL CXaraFileRecord::Write(UINT32 n)
00585 
00586     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00587     Created:    21/5/96
00588     Inputs:     n = a UINT32 value
00589     Returns:    TRUE if OK, FALSE otherwise
00590     Purpose:    Writes the UINT32 to the record's data section
00591 
00592     Errors:     -
00593     SeeAlso:    -
00594 
00595 ********************************************************************************************/
00596 
00597 BOOL CXaraFileRecord::WriteUINT32(UINT32 n)
00598 {
00599     ENTERWRITEFUNCTION(FTT_UINT32);
00600     n = NativetoLE(n);
00601     BOOL ok = WriteBuffer((BYTE*)&n,sizeof(UINT32));
00602     LEAVEWRITEFUNCTION;
00603     return (ok);
00604 }   
00605 
00606 BOOL CXaraFileRecord::WriteINT32(INT32 n)
00607 {
00608     ENTERWRITEFUNCTION(FTT_INT32);
00609     n = NativetoLE(n);
00610     BOOL ok = WriteBuffer((BYTE*)&n,sizeof(INT32));
00611     LEAVEWRITEFUNCTION;
00612     return (ok);
00613 }   
00614 
00615 BOOL CXaraFileRecord::WriteReference(INT32 n)
00616 {
00617     ENTERWRITEFUNCTION(FTT_REFERENCE);
00618     n = NativetoLE(n);
00619     BOOL ok = WriteBuffer((BYTE*)&n,sizeof(INT32));
00620     LEAVEWRITEFUNCTION;
00621     return (ok);
00622 }   
00623 
00624 BOOL CXaraFileRecord::WriteFLOAT(FLOAT f)
00625 {
00626     ENTERWRITEFUNCTION(FTT_FLOAT);
00627     FloatUnion u=NativetoLEU(f);
00628     BOOL ok = WriteBuffer((BYTE*)&(u.u_INT32),sizeof(u.u_INT32));
00629     LEAVEWRITEFUNCTION;
00630     return (ok);
00631 }   
00632 
00633 BOOL CXaraFileRecord::WriteUINT16(UINT16 f)
00634 {
00635     ENTERWRITEFUNCTION(FTT_UINT16);
00636     f = NativetoLE(f);
00637     BOOL ok = WriteBuffer((BYTE*)&f,sizeof(UINT16));
00638     LEAVEWRITEFUNCTION;
00639     return (ok);
00640 }   
00641 
00642 BOOL CXaraFileRecord::WriteINT16(INT16 f)
00643 {
00644     ENTERWRITEFUNCTION(FTT_INT16);
00645     f = NativetoLE(f);
00646     BOOL ok = WriteBuffer((BYTE*)&f,sizeof(INT16));
00647     LEAVEWRITEFUNCTION;
00648     return (ok);
00649 }   
00650 
00651 BOOL CXaraFileRecord::WriteFIXED16(FIXED16 f)
00652 {
00653     ENTERWRITEFUNCTION(FTT_INT32);
00654     f = NativetoLE(f);
00655     BOOL ok = WriteBuffer((BYTE*)&f,sizeof(FIXED16));
00656     LEAVEWRITEFUNCTION;
00657     return (ok);
00658 }
00659 
00660 BOOL CXaraFileRecord::WriteANGLE(ANGLE a)
00661 {
00662     ENTERWRITEFUNCTION(FTT_INT32);
00663     a = NativetoLE(a);
00664     BOOL ok = WriteBuffer((BYTE*)&a,sizeof(ANGLE));
00665     LEAVEWRITEFUNCTION;
00666     return (ok);
00667 }
00668 
00669 BOOL CXaraFileRecord::WriteDOUBLE(double d)
00670 {
00671     ENTERWRITEFUNCTION(FTT_DOUBLE);
00672     DoubleUnion u=NativetoLEU(d);
00673     BOOL ok = WriteBuffer((BYTE*)&(u.u_INT64),sizeof(u.u_INT64));
00674     LEAVEWRITEFUNCTION;
00675     return (ok);
00676 }   
00677 
00678 BOOL CXaraFileRecord::WriteWCHAR(WCHAR w)
00679 {
00680     ENTERWRITEFUNCTION(FTT_WCHAR);
00681     w = NativeToUTF16(w);
00682     w = NativetoLE(w);
00683     BOOL ok = WriteBuffer((BYTE*)&w, SIZEOF_XAR_UTF16); //sizeof(WCHAR));   2-byte UNICODE stored in Xar files
00684     LEAVEWRITEFUNCTION;
00685     return (ok);
00686 }
00687 
00688 BOOL CXaraFileRecord::WriteWCHARs(const WCHAR* pw, UINT32 Count)
00689 {
00690     BOOL ok = TRUE;
00691     UINT32 i;
00692     for (i = 0; ok && i < Count; i++)
00693         ok = WriteWCHAR(pw[i]);
00694     return (ok);
00695 }
00696 
00697 
00698 /********************************************************************************************
00699 
00700 >   BOOL CXaraFileRecord::WriteCoord(const DocCoord& Coord)
00701 
00702     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00703     Created:    31/5/96
00704     Inputs:     Coord = a coord
00705     Returns:    TRUE if written successfully
00706                 FALSE otherwise
00707     Purpose:    Writes out the coord
00708     Errors:     -
00709     SeeAlso:    -
00710 
00711 ********************************************************************************************/
00712 
00713 BOOL CXaraFileRecord::WriteCoord(const DocCoord& Coord)
00714 {
00715     ENTERWRITEFUNCTION(FTT_COORD);
00716     BOOL ok = WriteINT32(Coord.x) && WriteINT32(Coord.y);
00717     LEAVEWRITEFUNCTION;
00718     return (ok);
00719 }
00720 
00721 BOOL CXaraFileRecord::WriteCoordTrans(const DocCoord& Coord,INT32 dx,INT32 dy)
00722 {
00723     ENTERWRITEFUNCTION(FTT_COORD);
00724     BOOL ok = WriteINT32(Coord.x + dx) && WriteINT32(Coord.y + dy);
00725     LEAVEWRITEFUNCTION;
00726     return (ok);
00727 }
00728 
00729 /********************************************************************************************
00730 
00731 >   virtual BOOL CXaraFileRecord::WriteCoordInterleaved(const DocCoord& Coord)
00732 
00733     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00734     Created:    27/8/96
00735     Inputs:     Coord = coord to write to the record
00736     Returns:    TRUE if OK, FALSE otherwise
00737     Purpose:    Writes out the coord to the record, in an interleaved format.
00738 
00739                 The Coord is translated to the origin set up in the filter
00740                 that was used to construct this object
00741 
00742                 This version interleaves the bytes of the X & Y components, to try and
00743                 maximise the run of common bytes, in order to improve the zlib compression.
00744 
00745                 It writes out the top byte of x, then top byte of y, then next byte of x,
00746                 then next byte of y, and so on.
00747     Errors:     -
00748     SeeAlso:    -
00749 
00750 ********************************************************************************************/
00751 
00752 BOOL CXaraFileRecord::WriteCoordInterleaved(const DocCoord& Coord)
00753 {
00754     ENTERWRITEFUNCTION(FTT_INTCOORD);
00755     BOOL ok = WriteCoordTransInterleaved(Coord,0,0);
00756     LEAVEWRITEFUNCTION;
00757     return (ok);
00758 }
00759 
00760 BOOL CXaraFileRecord::WriteCoordTransInterleaved(const DocCoord& Coord,INT32 dx,INT32 dy)
00761 {
00762     ENTERWRITEFUNCTION(FTT_INTCOORD);
00763     INT32 x = Coord.x + dx;
00764     INT32 y = Coord.y + dy;
00765 
00766     BOOL ok = TRUE;
00767 
00768     if (ok) ok = WriteBYTE(BYTE((x >> 24) & 0xff));
00769     if (ok) ok = WriteBYTE(BYTE((y >> 24) & 0xff));
00770 
00771     if (ok) ok = WriteBYTE(BYTE((x >> 16) & 0xff));
00772     if (ok) ok = WriteBYTE(BYTE((y >> 16) & 0xff));
00773 
00774     if (ok) ok = WriteBYTE(BYTE((x >>  8) & 0xff));
00775     if (ok) ok = WriteBYTE(BYTE((y >>  8) & 0xff));
00776 
00777     if (ok) ok = WriteBYTE(BYTE((x >>  0) & 0xff));
00778     if (ok) ok = WriteBYTE(BYTE((y >>  0) & 0xff));
00779 
00780     LEAVEWRITEFUNCTION;
00781     return ok;
00782 }
00783 
00784 /********************************************************************************************
00785 
00786 >   BOOL CXaraFileRecord::WriteBuffer(BYTE* pBuf,UINT32 BufSize)
00787 
00788     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00789     Created:    21/5/96
00790     Inputs:     pBuf    = ptr to a BYTE buffer
00791                 BufSize = the number of bytes in the buffer
00792     Returns:    TRUE if OK, FALSE otherwise
00793     Purpose:    Writes out a buffer of BYTEs to the record's data section.
00794     Errors:     -
00795     SeeAlso:    -
00796 
00797 ********************************************************************************************/
00798 
00799 BOOL CXaraFileRecord::WriteBuffer(BYTE* pBuf,size_t BufSize)
00800 {
00801     ERROR3IF(pBuf == NULL,"NULL pBuf param");
00802 
00803     BOOL ok = (pBuf != NULL);
00804     ENTERWRITEFUNCTION(FTT_BINHEX);
00805     STORELENGTH( DWORD(BufSize) );
00806 
00807     for (UINT32 i=0;i<BufSize && ok;i++)
00808         ok = WriteBYTE(pBuf[i]);
00809 
00810     LEAVEWRITEFUNCTION;
00811     return ok;
00812 }
00813 
00814 /********************************************************************************************
00815 
00816 >   BOOL CXaraFileRecord::WriteCCPanose(const CCPanose &MyCCPanose)
00817 
00818     Author:     Andy_Hayward (Xara Group Ltd) <camelotdev@xara.com>
00819     Created:    09/08/96
00820     Inputs:     Panose  - CCPanose structure to write out
00821     Returns:    TRUE if successful, FALSE otherwise
00822     Purpose:    Writes a CCPanose structure to th file
00823 
00824 ********************************************************************************************/
00825 
00826 BOOL CXaraFileRecord::WriteCCPanose(const CCPanose &MyCCPanose)
00827 {
00828     BOOL ok = TRUE;
00829 
00830 PORTNOTE("other","Removed CCPanose usage - write NULL")
00831 #ifndef EXCLUDE_FROM_XARALX
00832     if (ok) ok = WriteBYTE(MyCCPanose.GetFamilyType());
00833     if (ok) ok = WriteBYTE(MyCCPanose.GetSerifStyle());
00834     if (ok) ok = WriteBYTE(MyCCPanose.GetWeight());
00835     if (ok) ok = WriteBYTE(MyCCPanose.GetProportion());
00836     if (ok) ok = WriteBYTE(MyCCPanose.GetContrast());
00837     if (ok) ok = WriteBYTE(MyCCPanose.GetStrokeVariation());
00838     if (ok) ok = WriteBYTE(MyCCPanose.GetArmStyle());
00839     if (ok) ok = WriteBYTE(MyCCPanose.GetLetterform());
00840     if (ok) ok = WriteBYTE(MyCCPanose.GetMidline());
00841     if (ok) ok = WriteBYTE(MyCCPanose.GetXHeight());
00842 #else
00843     if (ok) ok = WriteBYTE( 0 );
00844     if (ok) ok = WriteBYTE( 0 );
00845     if (ok) ok = WriteBYTE( 0 );
00846     if (ok) ok = WriteBYTE( 0 );
00847     if (ok) ok = WriteBYTE( 0 );
00848     if (ok) ok = WriteBYTE( 0 );
00849     if (ok) ok = WriteBYTE( 0 );
00850     if (ok) ok = WriteBYTE( 0 );
00851     if (ok) ok = WriteBYTE( 0 );
00852     if (ok) ok = WriteBYTE( 0 );
00853 #endif
00854     return ok;
00855 }
00856 
00857 /********************************************************************************************
00858 
00859 >   BOOL CXaraFileRecord::WriteUnicode(const TCHAR* pStr)
00860 
00861     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00862     Created:    23/5/96
00863     Inputs:     pStr = ptr to zero-terminated string
00864     Returns:    TRUE if written successfully
00865                 FALSE otherwise
00866     Purpose:    Writes out the string as a Unicode string
00867     Errors:     -
00868     SeeAlso:    -
00869 
00870 ********************************************************************************************/
00871 
00872 BOOL CXaraFileRecord::WriteUnicode(const TCHAR* pStr)
00873 {
00874     ERROR3IF(pStr == NULL,"NULL pStr");
00875     if (pStr == NULL)
00876         return FALSE;
00877 
00878     ENTERWRITEFUNCTION(FTT_UNICODE);
00879     BOOL ok = TRUE;
00880     
00881 #ifdef _UNICODE
00882 
00883     // We must cope with byte-order differences between native storage and XAR file storage:
00884     // Native may be big-endian or little-endian, XAR is always little-endian
00885     // Native WCHAR may be 16 or 32 bits, XAR is always 16 bits
00886     // These differences are handled in WriteWCHAR
00887     WCHAR c = 0;
00888     INT32 i = 0;
00889 
00890     do
00891     {
00892         c = pStr[i++];
00893         ok = WriteWCHAR(c);                     // Read two bytes into the WCHAR buffer
00894         if (!ok) c = 0;                         // If the read failed then write a terminator
00895     }
00896     while (c!=0);// Until end of string or no longer OK to write
00897 
00898 #else
00899     // pStr points to an ASCII or DBCS string, and we want it written as a Unicode string
00900     // Write out each char separately, converting it to the correct Unicode value
00901     // using TextManager::MultiByteToUnicode()
00902 
00903     // skip along the string, saving each character in turn
00904     TCHAR* pCurrentChar = pStr;
00905 
00906     while (*pCurrentChar!=0 && ok)
00907     {
00908         // Convert the char to Unicode
00909         UINT32 mc = 0;
00910         if (UnicodeManager::IsDBCSOS() && UnicodeManager::IsDBCSLeadByte(*pCurrentChar))
00911         {
00912             mc = UnicodeManager::ComposeMultiBytes(*pCurrentChar, *(pCurrentChar+1));
00913             pCurrentChar += 2;
00914         }
00915         else
00916         {
00917             mc = *pCurrentChar;
00918             pCurrentChar += 1;
00919         }
00920 
00921         WCHAR wc = UnicodeManager::MultiByteToUnicode(mc);
00922 
00923         ok = WriteBuffer( (BYTE*)&wc, sizeof(WCHAR) );
00924     }
00925 
00926     // Now write a zero terminator
00927     if (ok)
00928     {
00929         WCHAR wc = 0;
00930         ok = WriteBuffer( (BYTE*)&wc, sizeof(WCHAR) );
00931     }
00932 
00933 #endif  // _UNICODE
00934 
00935     LEAVEWRITEFUNCTION;
00936     return ok;
00937 }
00938 
00939 /********************************************************************************************
00940 
00941 >   BOOL CXaraFileRecord::WriteASCII(const TCHAR* pStr)
00942 
00943     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00944     Created:    23/5/96
00945     Inputs:     pStr = ptr to zero-terminated string
00946     Returns:    TRUE if written successfully
00947                 FALSE otherwise
00948     Purpose:    Writes out the string as an ASCII string
00949     Errors:     -
00950     SeeAlso:    -
00951 
00952 ********************************************************************************************/
00953 
00954 BOOL CXaraFileRecord::WriteASCII(const TCHAR* pStr)
00955 {
00956     ERROR3IF(pStr == NULL,"NULL pStr");
00957     if (pStr == NULL)
00958         return FALSE;
00959 
00960     ENTERWRITEFUNCTION(FTT_ASCII);
00961     size_t len = camStrlen(pStr);
00962     BOOL ok= TRUE;
00963 
00964 #ifdef _UNICODE
00965     // Writing a Unicode string at pStr as an ASCII string
00966     // Just write out the first byte of each unicode char.
00967 
00968     for (size_t i=0;ok && i<=len;i++)
00969     {
00970 PORTNOTE( "record", "UNICODE characters that don't fit into 1 mb character need better handling" )
00971         char    acTmp[MB_CUR_MAX];
00972         if( 1 == wctomb( acTmp, pStr[i] ) )
00973             ok = WriteBYTE( acTmp[0] );
00974         else
00975             ok = WriteBYTE( '.' );
00976     }
00977 
00978     LEAVEWRITEFUNCTION;
00979     return ok;
00980 #else
00981     // pStr points at an ASCII string, so write it out
00982     ok = WriteBuffer((BYTE*)pStr,len+1);
00983     LEAVEWRITEFUNCTION;
00984     return (ok);
00985 #endif
00986 }
00987 
00988 /********************************************************************************************
00989 
00990 >   BOOL CXaraFileRecord::WriteBSTR(_bstr_t bstr)
00991 
00992     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00993     Created:    29/01/2004
00994     Inputs:     bstr - ptr to zero-terminated WCHAR string
00995     Returns:    TRUE if written successfully
00996                 FALSE otherwise
00997     Purpose:    Writes out the string as a Unicode string
00998     Errors:     -
00999     SeeAlso:    -
01000 
01001 ********************************************************************************************/
01002 
01003 /*BOOL CXaraFileRecord::WriteBSTR(_bstr_t bstr)
01004 {
01005     ERROR3IF((wchar_t*)bstr == NULL, "NULL bstr");
01006     if ((wchar_t*)bstr == NULL)
01007         return FALSE;
01008 
01009     ENTERWRITEFUNCTION(FTT_UNICODE);
01010 
01011     BOOL ok = WriteBuffer((unsigned char*)((wchar_t*)bstr), bstr.length()*sizeof(WCHAR));
01012     ok = ok && WriteWCHAR(0);                   // Zero terminate to be consistent with FTT_UNICODE
01013 
01014     LEAVEWRITEFUNCTION;
01015 
01016     return (ok);
01017 } */
01018 
01019 /********************************************************************************************
01020 
01021 >   BOOL CXaraFileRecord::WriteUTF16STR(const StringVar& pvstr)
01022 
01023     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01024     Created:    28/Mar/2006
01025     Inputs:     pvstr - pointer to StringVar
01026     Outputs:    -
01027     Returns:    TRUE if OK, FALSE otherwise
01028     Purpose:    Writes a variable length string as a stream of UTF16 unicode characters
01029     Errors:     -
01030     SeeAlso:    StartRecord(), EndRecord()
01031 
01032 ********************************************************************************************/
01033 
01034 BOOL CXaraFileRecord::WriteUTF16STR(const StringVar& pvstr)
01035 {
01036 #ifdef _UNICODE
01037     ENTERWRITEFUNCTION(FTT_UNICODE);
01038 
01039     BOOL ok = TRUE;
01040     WCHAR c = 0;
01041     INT32 i = 0;
01042 
01043     do
01044     {
01045         c = pvstr.CharAt(i++);
01046         ok = WriteWCHAR(c);                     // Read two bytes into the WCHAR buffer
01047         if (!ok) c = 0;                         // If the read failed then write a terminator
01048     }
01049     while (c!=0);// Until end of string or no longer OK to write
01050 
01051     LEAVEWRITEFUNCTION;
01052 
01053     return ok;                                  // If we terminated due to Read failure tell the caller
01054 #else
01055     ERROR3("StringVar only holds UNICODE data in UNICODE builds");
01056     return FALSE;
01057 #endif
01058 }
01059 
01060 /********************************************************************************************
01061 
01062 >   BOOL CXaraFileRecord::WriteBYTE(BYTE b)
01063 
01064     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01065     Created:    21/5/96
01066     Inputs:     b = a BYTE
01067     Returns:    TRUE if OK, FALSE otherwise
01068     Purpose:    Writes a BYTE to the record's data section
01069 
01070     Errors:     -
01071     SeeAlso:    StartRecord(), EndRecord()
01072 
01073 ********************************************************************************************/
01074 
01075 BOOL CXaraFileRecord::WriteBYTE(BYTE b)
01076 {
01077     ERROR3IF(!Initialised,"Writing to an uninitialised record");
01078 
01079     if (Overflow)
01080         return FALSE;
01081 
01082     ENTERWRITEFUNCTION(FTT_BYTE);
01083     BOOL ok = TRUE;
01084 
01085     if (CurrentPos >= BufferSize)
01086     {
01087         if (SizeIsKnown)
01088         {
01089             ERROR3("Record Write Overflow");
01090             Overflow = TRUE;
01091             LEAVEWRITEFUNCTION;
01092             return FALSE;
01093         }
01094         else
01095         {
01096             while (ok && CurrentPos >= BufferSize)
01097                 ok = ExtendBuffer(CXF_RECORD_CHUNK);
01098         }
01099     }
01100 
01101     if (ok)
01102     {
01103         BYTE* pBuf = (BYTE*)pBuffer;
01104 
01105         if (CurrentPos < BufferSize)
01106             pBuf[CurrentPos++] = b;
01107     }
01108 
01109     LEAVEWRITEFUNCTION;
01110     return ok;
01111 }
01112 
01113 /********************************************************************************************
01114 
01115 >   void CXaraFileRecord::ResetReadPos()
01116 
01117     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01118     Created:    12/6/96
01119     Inputs:     -
01120     Returns:    -
01121     Purpose:    Resets the read position, so that the next Read() func call starts from the beginning
01122                 of the data section.
01123     Errors:     -
01124     SeeAlso:    StartRecord(), EndRecord()
01125 
01126 ********************************************************************************************/
01127 
01128 void CXaraFileRecord::ResetReadPos()
01129 {
01130     CurrentPos = 0;
01131 }
01132 
01133 /********************************************************************************************
01134 
01135 >   BOOL CXaraFileRecord::ReadBYTE(BYTE* pBYTE)
01136 
01137     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01138     Created:    21/5/96
01139     Inputs:     pBYTE = ptr to place to stick data
01140     Returns:    TRUE if OK, FALSE otherwise
01141     Purpose:    Reads a BYTE from the record's data section
01142 
01143     Errors:     -
01144     SeeAlso:    StartRecord(), EndRecord()
01145 
01146 ********************************************************************************************/
01147 
01148 BOOL CXaraFileRecord::ReadBYTE(BYTE* pBYTE)
01149 {
01150     ERROR3IF(pBYTE == NULL,"pBYTE is NULL");
01151     if (pBYTE == NULL)
01152         return FALSE;
01153 
01154     ERROR3IF(CurrentPos >= BufferSize,"No more data in record");
01155     if (CurrentPos >= BufferSize)
01156         return FALSE;
01157 
01158     BYTE* pBuf = (BYTE*)pBuffer;
01159     *pBYTE = pBuf[CurrentPos++];
01160 
01161     return TRUE;
01162 }
01163 
01164 
01165 /********************************************************************************************
01166 
01167 >   BOOL CXaraFileRecord::ReadBYTEtoBOOL(BOOL* pbool)
01168 
01169     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01170     Created:    07/Feb/2006
01171     Inputs:     pbool = ptr to place to stick data
01172     Returns:    TRUE if OK, FALSE otherwise
01173     Purpose:    Reads a BYTE from the record's data section
01174 
01175     Errors:     -
01176     SeeAlso:    StartRecord(), EndRecord()
01177 
01178 ********************************************************************************************/
01179 
01180 BOOL CXaraFileRecord::ReadBYTEtoBOOL(BOOL* pbool)
01181 {
01182     ERROR3IF(pbool == NULL,"pbool is NULL");
01183     if (pbool == NULL)
01184         return FALSE;
01185 
01186     ERROR3IF(CurrentPos >= BufferSize,"No more data in record");
01187     if (CurrentPos >= BufferSize)
01188         return FALSE;
01189 
01190     BYTE* pBuf = (BYTE*)pBuffer;
01191     *pbool = (BOOL)pBuf[CurrentPos++];
01192 
01193     return TRUE;
01194 }
01195 
01196 
01197 /********************************************************************************************
01198 
01199 >   BOOL CXaraFileRecord::ReadBYTEnoError(BOOL* pBYTE)
01200 
01201     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
01202     Created:    05/02/2001
01203     Returns:    TRUE if successfully read a BYTE,
01204                 FALSE if we didn't read a BYTE for any reason.
01205     Purpose:    Dangerous, no-error version of CXaraFileRecord::ReadBYTE().
01206 
01207                 !!! DO NOT USE UNLESS YOU ***KNOW EXACTLY*** WHAT YOU ARE DOING !!!
01208 
01209     See Also:   ReadBuffernoError() .
01210 
01211 ********************************************************************************************/
01212 BOOL CXaraFileRecord::ReadBYTEnoError(BYTE* pBYTE)
01213 {
01214     ERROR3IF(pBYTE == NULL, "pBYTE is NULL");
01215     if (pBYTE == NULL)
01216         return FALSE;
01217 
01218     // if we run out of buffer, fail quietly (no error!).
01219     if (CurrentPos >= BufferSize)
01220         return FALSE;
01221 
01222     BYTE* pBuf = (BYTE*)pBuffer;
01223     *pBYTE = pBuf[CurrentPos++];
01224 
01225     return TRUE;
01226 }
01227 
01228 
01229 BOOL CXaraFileRecord::ReadBuffer(BYTE* pBuf,UINT32 BufSize)
01230 {
01231     ERROR3IF(pBuf == NULL,"pBuf is NULL");
01232     if (pBuf == NULL)
01233         return FALSE;
01234 
01235     BOOL ok = TRUE;
01236 
01237     for (UINT32 i=0;ok && i < BufSize;i++)
01238         ok = ReadBYTE(pBuf+i);
01239 
01240     return ok;
01241 }
01242 
01243 /*  The following function allows us to still open up old CX2/CX3 files that do NOT contain
01244     profiling data.  This was necessary since the standard ReadBuffer will error on such a case.
01245     Obviously it is only CORRECT to call this function when we are trying to retain backward
01246     compatibility within CX3.
01247 */
01248 
01249 BOOL CXaraFileRecord::ReadBuffernoError(BYTE* pBuf,UINT32 BufSize)
01250 {
01251     ERROR3IF(pBuf == NULL,"pBuf is NULL");
01252     if (pBuf == NULL)
01253         return FALSE;
01254 
01255     BOOL ok = TRUE;
01256 
01257     if (CurrentPos >= BufferSize)
01258     {
01259         pBuf = NULL;
01260         return ok;
01261     }
01262     else
01263     {
01264         for (UINT32 i=0;ok && i < BufSize;i++)
01265         {
01266             ok = ReadBYTE(pBuf+i);
01267         }
01268     }
01269 
01270     return ok;
01271 }
01272 
01273 BOOL CXaraFileRecord::ReadUINT32(UINT32* pUINT32)
01274 {
01275 //  return ReadBuffer((BYTE*)pUINT32,sizeof(UINT32));
01276     BOOL ok = ReadBuffer((BYTE*)pUINT32,sizeof(UINT32));
01277     *pUINT32 = LEtoNative(*pUINT32);
01278     return ok;
01279 }
01280 
01281 
01282 BOOL CXaraFileRecord::ReadINT32(INT32* pINT32)
01283 {
01284 //  return ReadBuffer((BYTE*)pINT32,sizeof(INT32));
01285     BOOL ok = ReadBuffer((BYTE*)pINT32,sizeof(INT32));
01286     *pINT32 = LEtoNative(*pINT32);
01287     return ok;
01288 }
01289 
01290 BOOL CXaraFileRecord::ReadINT32noError(INT32* pINT32)
01291 {
01292 //  return ReadBuffernoError((BYTE*)pINT32,sizeof(INT32));
01293     BOOL ok = ReadBuffernoError((BYTE*)pINT32,sizeof(INT32));
01294     *pINT32 = LEtoNative(*pINT32);
01295     return ok;
01296 }
01297 
01298 BOOL CXaraFileRecord::ReadFIXED16(FIXED16* pn)
01299 {
01300     BOOL ok = ReadBuffer((BYTE*)pn,sizeof(FIXED16));
01301     *pn = LEtoNative(*pn);
01302     return ok;
01303 }
01304 
01305 BOOL CXaraFileRecord::ReadANGLE(ANGLE *pa)
01306 {
01307     BOOL ok = ReadBuffer((BYTE*)pa,sizeof(ANGLE));
01308     *pa = LEtoNative(*pa);
01309     return ok;
01310 }
01311 
01312 BOOL CXaraFileRecord::ReadUINT16(UINT16* pn)
01313 {
01314     BOOL ok = ReadBuffer((BYTE*)pn,sizeof(UINT16));
01315     *pn = LEtoNative(*pn);
01316     return ok;
01317 }
01318 
01319 BOOL CXaraFileRecord::ReadINT16(INT16* pn)
01320 {
01321     BOOL ok = ReadBuffer((BYTE*)pn,sizeof(INT16));
01322     *pn = LEtoNative(*pn);
01323     return ok;
01324 }
01325 
01326 BOOL CXaraFileRecord::ReadFLOAT(FLOAT* pf)
01327 {
01328     FloatUnion f;
01329     BOOL ok = ReadBuffer((BYTE*)&(f.u_INT32),sizeof(f.u_INT32));
01330     *pf = LEtoNative(f);
01331     return ok;
01332 }
01333 
01334 BOOL CXaraFileRecord::ReadDOUBLE(double* pd)
01335 {
01336     DoubleUnion f;
01337     BOOL ok = ReadBuffer((BYTE*)&(f.u_INT64),sizeof(f.u_INT64));
01338     *pd = LEtoNative(f);
01339     return ok;
01340 }
01341 
01342 BOOL CXaraFileRecord::ReadDOUBLEnoError(double* pd)
01343 {
01344     DoubleUnion f;
01345     BOOL ok = ReadBuffernoError((BYTE*)&(f.u_INT64),sizeof(f.u_INT64));
01346     *pd = LEtoNative(f);
01347     return ok;
01348 }
01349 
01350 BOOL CXaraFileRecord::ReadWCHAR(WCHAR *pw)
01351 {
01352     *pw = 0;
01353     BOOL ok = ReadBuffer((BYTE*)pw, SIZEOF_XAR_UTF16);  //sizeof(WCHAR)); 2-byte UNICODE stored in Xar files
01354     *pw = LEtoNative(*pw);
01355     *pw = UTF16ToNative(*pw);
01356     return ok;
01357 }
01358 
01359 BOOL CXaraFileRecord::ReadCoord(DocCoord* pCoord)
01360 {
01361     if (pCoord != NULL)
01362         return ReadINT32(&(pCoord->x)) && ReadINT32(&(pCoord->y));
01363     else
01364         return FALSE;
01365 }
01366 
01367 BOOL CXaraFileRecord::ReadCoordTrans(DocCoord* pCoord,INT32 dx,INT32 dy)
01368 {
01369     if (pCoord != NULL)
01370     {
01371         if (ReadINT32(&(pCoord->x)) && ReadINT32(&(pCoord->y)))
01372         {
01373             pCoord->x += dx;
01374             pCoord->y += dy;
01375             return TRUE;
01376         }
01377     }
01378 
01379     return FALSE;
01380 }
01381 
01382 BOOL CXaraFileRecord::ReadCoordInterleaved(DocCoord* pCoord)
01383 {
01384     return ReadCoordTransInterleaved(pCoord,0,0);
01385 }
01386 
01387 BOOL CXaraFileRecord::ReadCoordTransInterleaved(DocCoord* pCoord,INT32 dx,INT32 dy)
01388 {
01389     BOOL ok = TRUE;
01390 
01391     if (pCoord != NULL)
01392     {
01393         BYTE b;
01394         INT32 x = 0;
01395         INT32 y = 0;
01396 
01397         if (ok) { ok = ReadBYTE(&b); x += (b << 24); }
01398         if (ok) { ok = ReadBYTE(&b); y += (b << 24); }
01399 
01400         if (ok) { ok = ReadBYTE(&b); x += (b << 16); }
01401         if (ok) { ok = ReadBYTE(&b); y += (b << 16); }
01402 
01403         if (ok) { ok = ReadBYTE(&b); x += (b <<  8); }
01404         if (ok) { ok = ReadBYTE(&b); y += (b <<  8); }
01405 
01406         if (ok) { ok = ReadBYTE(&b); x += (b <<  0); }
01407         if (ok) { ok = ReadBYTE(&b); y += (b <<  0); }
01408 
01409         pCoord->x = x + dx;
01410         pCoord->y = y + dy;
01411     }
01412 
01413     return ok;
01414 }
01415 
01416 BOOL CXaraFileRecord::ReadCCPanose(CCPanose *pMyCCPanose)
01417 {
01418     BOOL ok = TRUE;
01419 
01420     BYTE value;
01421 
01422 PORTNOTE("other","Removed CCPanose usage - read to NULL")
01423 #ifndef EXCLUDE_FROM_XARALX
01424     if (ok) ok = pMyCCPanose->SetFamilyType(value);
01425     if (ok) ok = pMyCCPanose->SetSerifStyle(value);
01426     if (ok) ok = pMyCCPanose->SetWeight(value);
01427     if (ok) ok = pMyCCPanose->SetProportion(value);
01428     if (ok) ok = pMyCCPanose->SetContrast(value);
01429     if (ok) ok = pMyCCPanose->SetStrokeVariation(value);
01430     if (ok) ok = pMyCCPanose->SetArmStyle(value);
01431     if (ok) ok = pMyCCPanose->SetLetterform(value);
01432     if (ok) ok = pMyCCPanose->SetMidline(value);
01433     if (ok) ok = pMyCCPanose->SetXHeight(value);
01434 #else
01435     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetFamilyType(value);
01436     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetSerifStyle(value);
01437     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetWeight(value);
01438     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetProportion(value);
01439     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetContrast(value);
01440     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetStrokeVariation(value);
01441     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetArmStyle(value);
01442     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetLetterform(value);
01443     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetMidline(value);
01444     if (ok) ok = ReadBYTE(&value); // pMyCCPanose->SetXHeight(value);
01445 #endif
01446     return ok;
01447 }
01448 
01449 BOOL CXaraFileRecord::ReadUnicode(StringBase* pStr)
01450 {
01451     // ASUMPTION!!!!
01452     // This function assumes the pStr->MaxLength() will return the max buffer size -1,
01453     // i.e. a value is returned that excludes room for a zero-terminated character.
01454     //
01455     // As the func that does all the hard work takes a TCHAR*, we need to pass in the total buffer
01456     // size, otherwise it will fail for strings that exactly fit into the StringBase object.
01457     //
01458     // This is why MaxLength()+1 is passed in.
01459 
01460     if (pStr != NULL)
01461         return ReadUnicode((TCHAR*)(*pStr),pStr->MaxLength()+1);
01462 
01463     return FALSE;
01464 }
01465 
01466 BOOL CXaraFileRecord::ReadUnicode(TCHAR* pStr,UINT32 MaxChars)
01467 {
01468     BOOL ok = TRUE;
01469     BYTE* pBuf = (BYTE*)pStr;
01470 
01471 #ifdef _UNICODE 
01472     BYTE b1 = 1;
01473     BYTE b2 = 1;
01474     BYTE* pBufEnd = pBuf + ( MaxChars * sizeof(wchar_t) );
01475     
01476     while (ok && !(b1 == 0 && b2 == 0))
01477     {
01478         ok = ReadBYTE( &b1 ) && ReadBYTE( &b2 );
01479 
01480         if (ok) ok = (pBuf < pBufEnd);
01481         if (ok) *pBuf++ = b1;
01482         if (ok) ok = (pBuf < pBufEnd);
01483         if (ok) *pBuf++ = b2;
01484 
01485         // Yick, Linux has 4 byte unicdoe chars
01486         if (sizeof(TCHAR) == 4)
01487         {
01488             *pBuf++ = '\0';
01489             *pBuf++ = '\0';
01490         }   
01491     }
01492 #else
01493     BYTE* pBufEnd = pBuf+MaxChars;
01494     WCHAR wc = 1;
01495     BYTE* pwcBuf = (BYTE*)&wc;
01496 
01497     while (ok && wc != 0)
01498     {
01499         // Read in the two bytes that make up the Unicode value, and stuff them into 'wc'
01500         ok = ReadBYTE(pwcBuf) && ReadBYTE(pwcBuf+1);
01501 
01502         // Check for buffer overflow
01503         if (ok) ok = (pBuf < pBufEnd);
01504 
01505         if (ok)
01506         {
01507             // Convert to an ASCII or DBCS
01508             if (UnicodeManager::IsDBCSOS())
01509             {
01510                 UINT32 AsciiCode = UnicodeManager::UnicodeToMultiByte(wc);
01511                 BYTE LeadByte = 0;
01512                 BYTE TrailByte = 0;
01513                 UnicodeManager::DecomposeMultiBytes(AsciiCode, &LeadByte, &TrailByte);
01514 
01515                 if (LeadByte == 0)
01516                     *pBuf++ = TrailByte;
01517                 else
01518                 {
01519                     if (UnicodeManager::IsDBCSLeadByte(LeadByte))
01520                     {
01521                         ok = (pBuf < pBufEnd-1);
01522                         if (ok)
01523                         {
01524                             *pBuf++ = LeadByte;
01525                             *pBuf++ = TrailByte;
01526                         }
01527                     }
01528                     else
01529                         *pBuf++ = TrailByte;
01530                 }
01531             }
01532             else
01533             {
01534                 UINT32 AsciiCode = UnicodeManager::UnicodeToMultiByte(wc);
01535                 *pBuf++ = BYTE(AsciiCode & 0xff);
01536             }
01537         }
01538     }
01539 
01540 #endif // _UNICODE
01541 
01542     return ok;
01543 }
01544 
01545 
01546 BOOL CXaraFileRecord::ReadASCII(TCHAR* pStr,UINT32 MaxChars)
01547 {
01548     BOOL ok = TRUE;
01549     BYTE b = 1;
01550     TCHAR* pBuf = pStr;
01551     TCHAR* pBufEnd = pBuf + MaxChars;
01552 
01553     while (ok && b != 0)
01554     {
01555         ok = ReadBYTE(&b);
01556         if (ok) ok = (pBuf < pBufEnd);
01557         if (ok) *pBuf++ = b;
01558     }
01559 
01560     return ok;
01561 }
01562 
01563 #ifdef _UNICODE 
01564 BOOL CXaraFileRecord::ReadASCII( char *pStr, UINT32 MaxChars )
01565 {
01566     BOOL ok = TRUE;
01567     BYTE b=1;
01568     BYTE* pBuf = (BYTE*)pStr;
01569 
01570     BYTE* pBufEnd = pBuf+MaxChars;
01571 
01572     while (ok && b != 0)
01573     {
01574         ok = ReadBYTE(&b);
01575 
01576         if (ok) ok = (pBuf < pBufEnd);
01577         if (ok) *pBuf++ = b;
01578     }
01579 
01580     return ok;
01581 }
01582 #endif
01583 
01584 /********************************************************************************************
01585 
01586 >   BOOL CXaraFileRecord::ReadBSTR(_bstr_t* pbstr, UINT32 MaxChars)
01587 
01588     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01589     Created:    29/01/2004
01590     Inputs:     bstr - pointer to WCHAR buffer
01591                 MaxChars - size of buffer in WCHARS
01592     Returns:    TRUE if OK, FALSE otherwise
01593     Purpose:    Reads a BSTR from the record's data section (i.e. a run of WCHARs)
01594 
01595     Errors:     -
01596     SeeAlso:    StartRecord(), EndRecord()
01597 
01598 ********************************************************************************************/
01599 
01600 /*BOOL CXaraFileRecord::ReadBSTR(_bstr_t* pbstr, UINT32 MaxChars)
01601 {
01602     BOOL ok = TRUE;
01603     WCHAR c[2] = {0, 0};
01604     *pbstr = "";
01605 
01606     do
01607     {
01608         ok = ReadWCHAR(c);                      // Read two bytes into the WCHAR buffer
01609         if (!ok) c[0]=0;                        // If the read failed then write a terminator
01610         *pbstr += c;                            // Add the character to the BSTR
01611     }
01612     while (c[0]!=0 && pbstr->length()<MaxChars);// Until end of string or out of room in buffer
01613 
01614     return ok;                                  // If we terminated due to Read failure tell the caller
01615 } */
01616 
01617 
01618 
01619 
01620 /********************************************************************************************
01621 
01622 >   BOOL CXaraFileRecord::ReadUTF16STR(StringVar* pvstr, UINT32 MaxChars)
01623 
01624     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01625     Created:    31/Jan/2006
01626     Inputs:     vstr - pointer to StringVar
01627                 MaxChars - size of buffer in WCHARS
01628     Returns:    TRUE if OK, FALSE otherwise
01629     Purpose:    Reads a BSTR from the record's data section (i.e. a run of WCHARs)
01630 
01631     Errors:     -
01632     SeeAlso:    StartRecord(), EndRecord()
01633 
01634 ********************************************************************************************/
01635 
01636 BOOL CXaraFileRecord::ReadUTF16STR(StringVar* pvstr, UINT32 MaxChars)
01637 {
01638 #ifdef _UNICODE
01639     BOOL ok = TRUE;
01640     pvstr->Empty();
01641     WCHAR c = 0;
01642 
01643     do
01644     {
01645         ok = ReadWCHAR(&c);                     // Read two bytes into the WCHAR buffer
01646         if (!ok) c = 0;                         // If the read failed then write a terminator
01647         *pvstr += c;                            // Add the character to the VSTR
01648     }
01649     while (c!=0 && ((UINT32)(pvstr->Length()))<MaxChars);// Until end of string or out of room in buffer
01650 
01651 //TRACEUSER("Phil", _T("ReadUTF16: %s\n"), (TCHAR*)*pvstr);
01652 
01653     return ok;                                  // If we terminated due to Read failure tell the caller
01654 #else
01655     ERROR3("StringVar only holds UNICODE data in UNICODE builds");
01656     return FALSE;
01657 #endif
01658 }
01659 
01660 
01661 
01662 
01663 BOOL CXaraFileRecord::WritePath(Path* pPath)
01664 {
01665     return WritePathTrans(pPath,0,0);
01666 }
01667 
01668 BOOL CXaraFileRecord::WritePathTrans(Path* pPath,INT32 dx,INT32 dy)
01669 {
01670     if (pPath == NULL)
01671         return FALSE;
01672 
01673     INT32 NumCoords = pPath->GetNumCoords();
01674 
01675     // Write out num coords
01676     BOOL ok = WriteINT32(NumCoords);
01677 
01678     // Write out path verbs
01679     if (ok)
01680     {
01681         PathVerb* pVerb = pPath->GetVerbArray();
01682         if (pVerb != NULL)
01683         {
01684             for (INT32 i=0;ok && i < NumCoords;i++)
01685                 ok = WriteBYTE(pVerb[i]);
01686         }
01687         else
01688             ok = FALSE;
01689     }
01690 
01691     // Write out coord array
01692     if (ok)
01693     {
01694         DocCoord* pCoord = pPath->GetCoordArray();
01695         if (pCoord != NULL)
01696         {
01697             for (INT32 i=0;ok && i < NumCoords;i++)
01698                 ok = WriteCoordTrans(pCoord[i],dx,dy);
01699         }
01700         else
01701             ok = FALSE;
01702     }
01703 
01704     return ok;
01705 }
01706 
01707 BOOL CXaraFileRecord::ReadPath(Path* pPath)
01708 {
01709     return ReadPathTrans(pPath,0,0);
01710 }
01711 
01712 
01713 BOOL CXaraFileRecord::ReadPathTrans(Path* pPath,INT32 dx,INT32 dy)
01714 {
01715     if (pPath == NULL)
01716         return FALSE;
01717 
01718     INT32 NumCoords;
01719     if (!ReadINT32(&NumCoords))
01720         return FALSE;
01721 
01722     if (NumCoords < 0)
01723         return TRUE;
01724 
01725     BOOL ok = pPath->ClearPath(FALSE) && pPath->MakeSpaceAtEnd(NumCoords);
01726 
01727     if (ok)
01728     {
01729         INT32 i;
01730 
01731         PathVerb* pVerb = pPath->GetVerbArray();
01732 
01733         ok = (pVerb != NULL);
01734         for (i=0;ok && i<NumCoords;i++)
01735             ok = ReadBYTE(pVerb+i);
01736 
01737         DocCoord* pCoord = pPath->GetCoordArray();
01738 
01739         if (ok) ok = (pCoord != NULL);
01740         for (i=0;ok && i<NumCoords;i++)
01741             ok = ReadCoordTrans(pCoord+i,dx,dy);
01742 
01743         if (ok) ok = pPath->ExternalArraysAdded(NumCoords);
01744     }
01745 
01746     return ok;
01747 }
01748 
01749 BOOL CXaraFileRecord::WritePathRelative(Path* pPath)
01750 {
01751     return WritePathRelativeTrans(pPath,0,0);
01752 }
01753 
01754 BOOL CXaraFileRecord::WritePathRelativeTrans(Path* pPath,INT32 dx,INT32 dy)
01755 {
01756     if (pPath == NULL)
01757         return FALSE;
01758 
01759     BOOL ok = TRUE;
01760 
01761     INT32 NumCoords = pPath->GetNumCoords();
01762 
01763 #ifndef RELPATHINTERLEAVE
01764 
01765     // Write out path verbs
01766     if (ok)
01767     {
01768         PathVerb* pVerb = pPath->GetVerbArray();
01769         if (pVerb != NULL)
01770         {
01771             for (INT32 i=0;ok && i < NumCoords;i++)
01772                 ok = WriteBYTE(pVerb[i]);
01773         }
01774         else
01775             ok = FALSE;
01776     }
01777 
01778     // Write out coord array
01779     if (ok)
01780     {
01781         DocCoord* pCoord = pPath->GetCoordArray();
01782         if (pCoord != NULL)
01783         {
01784             ok = WriteCoordTrans(pCoord[0],dx,dy);
01785 
01786             for (INT32 i=1;ok && i < NumCoords;i++)
01787             {
01788                 INT32 RelX = pCoord[i-1].x - pCoord[i].x;
01789                 INT32 RelY = pCoord[i-1].y - pCoord[i].y;
01790 
01791                         ok = WriteINT32(RelX);
01792                 if (ok) ok = WriteINT32(RelY);
01793             }
01794         }
01795         else
01796             ok = FALSE;
01797     }
01798 #else
01799     if (ok)
01800     {
01801         PathVerb* pVerb = pPath->GetVerbArray();
01802         DocCoord* pCoord = pPath->GetCoordArray();
01803         if (pVerb != NULL && pCoord != NULL && NumCoords > 0)
01804         {
01805             DocCoord TempCoord;
01806 
01807             ok = WriteBYTE(pVerb[0]);
01808             if (ok) ok = WriteCoordTransInterleaved(pCoord[0],dx,dy);
01809 
01810             for (INT32 i=1;ok && i < NumCoords;i++)
01811             {
01812                 ok = WriteBYTE(pVerb[i]);
01813 
01814                 TempCoord.x = pCoord[i-1].x - pCoord[i].x;
01815                 TempCoord.y = pCoord[i-1].y - pCoord[i].y;
01816 
01817                 if (ok) ok = WriteCoordTransInterleaved(TempCoord,0,0);
01818             }
01819         }
01820         else
01821             ok = FALSE;
01822     }
01823 #endif
01824 
01825     return ok;
01826 }
01827 
01828 BOOL CXaraFileRecord::ReadPathRelative(Path* pPath)
01829 {
01830     return ReadPathRelativeTrans(pPath,0,0);
01831 }
01832 
01833 
01834 BOOL CXaraFileRecord::ReadPathRelativeTrans(Path* pPath,INT32 dx,INT32 dy)
01835 {
01836     if (pPath == NULL)
01837         return FALSE;
01838 
01839     INT32 NumCoords = INT32(GetSize())/(sizeof(BYTE)+sizeof(INT32)+sizeof(INT32));
01840 
01841     if (NumCoords < 0)
01842         return TRUE;
01843 
01844     BOOL ok = pPath->ClearPath(FALSE) && pPath->MakeSpaceAtEnd(NumCoords);
01845 
01846 #ifndef RELPATHINTERLEAVE
01847 
01848     if (ok)
01849     {
01850         INT32 i;
01851 
01852         PathVerb* pVerb = pPath->GetVerbArray();
01853 
01854         ok = (pVerb != NULL);
01855         for (i=0;ok && i<NumCoords;i++)
01856             ok = ReadBYTE(pVerb+i);
01857 
01858         DocCoord* pCoord = pPath->GetCoordArray();
01859 
01860         if (ok) ok = (pCoord != NULL);
01861         if (ok) ok = ReadCoordTrans(pCoord,dx,dy);
01862 
01863         if (ok)
01864         {
01865             INT32 RelX,RelY;
01866 
01867             for (i=1;ok && i<NumCoords;i++)
01868             {
01869                         ok = ReadINT32(&RelX);
01870                 if (ok) ok = ReadINT32(&RelY);
01871 
01872                 pCoord[i].x = pCoord[i-1].x - RelX;
01873                 pCoord[i].y = pCoord[i-1].y - RelY;
01874             }
01875         }
01876     }
01877 #else
01878     if (ok)
01879     {
01880         PathVerb* pVerb = pPath->GetVerbArray();
01881         DocCoord* pCoord = pPath->GetCoordArray();
01882         ok = (pVerb != NULL) && (pCoord != NULL);
01883 
01884         if (ok) ok = ReadBYTE(pVerb);
01885         if (ok) ok = ReadCoordTransInterleaved(pCoord,dx,dy);
01886 
01887         if (ok)
01888         {
01889             DocCoord TempCoord;
01890 
01891             for (INT32 i=1;ok && i<NumCoords;i++)
01892             {
01893                 ok = ReadBYTE(pVerb+i);
01894                 if (ok) ok = ReadCoordTransInterleaved(&TempCoord,0,0);
01895 
01896                 pCoord[i].x = pCoord[i-1].x - TempCoord.x;
01897                 pCoord[i].y = pCoord[i-1].y - TempCoord.y;
01898             }
01899         }
01900     }
01901 #endif
01902 
01903     if (ok) ok = pPath->ExternalArraysAdded(NumCoords);
01904 
01905     return ok;
01906 }
01907 
01908 BOOL CXaraFileRecord::WriteMatrix(const Matrix & m)
01909 {
01910     return WriteMatrixTrans(m,0,0);
01911 }
01912 
01913 BOOL CXaraFileRecord::WriteMatrixTrans(const Matrix & m,INT32 dx,INT32 dy)
01914 {
01915     BOOL ok = TRUE;
01916     
01917     FIXED16 abcd[4];        // matrix components
01918     INT32 ef[2];                // translation
01919 
01920     m.GetComponents(&abcd[0], &ef[0]);
01921 
01922     if (ok) ok = WriteFIXED16(abcd[0]);
01923     if (ok) ok = WriteFIXED16(abcd[1]);
01924     if (ok) ok = WriteFIXED16(abcd[2]);
01925     if (ok) ok = WriteFIXED16(abcd[3]);
01926 
01927     if (ok) ok = WriteINT32(ef[0]+dx);
01928     if (ok) ok = WriteINT32(ef[1]+dy);
01929 
01930     return ok;
01931 }
01932 
01933 BOOL CXaraFileRecord::ReadMatrix(Matrix *pMatrix)
01934 {
01935     return ReadMatrixTrans(pMatrix,0,0);
01936 }
01937 
01938 BOOL CXaraFileRecord::ReadMatrixTrans(Matrix *pMatrix,INT32 dx,INT32 dy)
01939 {
01940     BOOL ok = TRUE;
01941 
01942     FIXED16 a;
01943     FIXED16 b;
01944     FIXED16 c;
01945     FIXED16 d;
01946     INT32 e;
01947     INT32 f;
01948 
01949     if (ok) ok = ReadFIXED16(&a);
01950     if (ok) ok = ReadFIXED16(&b);
01951     if (ok) ok = ReadFIXED16(&c);
01952     if (ok) ok = ReadFIXED16(&d);
01953     if (ok) ok = ReadINT32(&e);
01954     if (ok) ok = ReadINT32(&f);
01955 
01956     (*pMatrix) = Matrix(a,b,c,d,e+dx,f+dy);
01957 
01958     return ok;
01959 }
01960 
01961 /********************************************************************************************
01962 
01963 >   virtual BOOL CXaraFileRecord::WriteXOrd(INT32 XOrdinate)
01964 
01965     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01966     Created:    8/8/96
01967     Inputs:     XOrdinate = x ordinate to write to the record
01968     Returns:    TRUE if OK, FALSE otherwise
01969     Purpose:    Writes out the x ordinate to the record.
01970 
01971                 Base class performs the same function as WriteINT32()
01972     Errors:     -
01973     SeeAlso:    -
01974 
01975 ********************************************************************************************/
01976 
01977 BOOL CXaraFileRecord::WriteXOrd(INT32 XOrdinate)
01978 {
01979     return WriteINT32(XOrdinate);
01980 }
01981 
01982 BOOL CXaraFileRecord::WriteYOrd(INT32 YOrdinate)
01983 {
01984     return WriteINT32(YOrdinate);
01985 }
01986 
01987 /********************************************************************************************
01988 
01989 >   virtual BOOL CXaraFileRecord::ReadXOrd(INT32* pXOrdinate)
01990 
01991     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01992     Created:    8/8/96
01993     Inputs:     pXOrdinate = ptr place to stick the x ordinate read in
01994     Returns:    TRUE if OK, FALSE otherwise
01995     Purpose:    Reads the x ordinate from the record.
01996 
01997                 Base class performs the same function as ReadINT32()
01998     Errors:     -
01999     SeeAlso:    -
02000 
02001 ********************************************************************************************/
02002 
02003 BOOL CXaraFileRecord::ReadXOrd(INT32* pXOrdinate)
02004 {
02005     return ReadINT32(pXOrdinate);
02006 }
02007 
02008 BOOL CXaraFileRecord::ReadYOrd(INT32* pYOrdinate)
02009 {
02010     return ReadINT32(pYOrdinate);
02011 }
02012 
02013 //-------------------------------------------------------------------------------------
02014 //-------------------------------------------------------------------------------------
02015 //-------------------------------------------------------------------------------------
02016 
02017 /********************************************************************************************
02018 
02019 >   CamelotFileRecord::CamelotFileRecord(BaseCamelotFilter* pFilter,UINT32 Tag,INT32 Size)
02020 
02021     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02022     Created:    24/6/96
02023     Inputs:     pFilter - ptr to the filter doing the importing/exporting
02024                 Tag     - Tag value for the record
02025                 Size    - The exact size of the record in bytes, or CXF_UNKNOWN_SIZE
02026     Purpose:    Creates a record object.
02027                 These are used by CXaraFile for reading and writing records.
02028 
02029                 This derived version sets up the coord origin using the supplied BaseCamelotFilter.
02030                 This origin is used when writing & reading coords.
02031     Errors:     -
02032     SeeAlso:    -
02033 
02034 ********************************************************************************************/
02035 
02036 CamelotFileRecord::CamelotFileRecord(BaseCamelotFilter* pFilter,UINT32 Tag,INT32 Size) : CXaraFileRecord(Tag,Size)
02037 {
02038 #if !defined(EXCLUDE_FROM_XARLIB)
02039     CoordOrigin = DocCoord(0,0);
02040 
02041     if (pFilter != NULL)
02042         CoordOrigin = pFilter->GetCoordOrigin();
02043 #endif
02044 }
02045 
02046 /********************************************************************************************
02047 
02048 >   CamelotFileRecord::~CamelotFileRecord()
02049 
02050     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02051     Created:    24/6/96
02052     Purpose:    Default destructor
02053     Errors:     -
02054     SeeAlso:    -
02055 
02056 ********************************************************************************************/
02057 
02058 CamelotFileRecord::~CamelotFileRecord()
02059 {
02060 }
02061 
02062 #if !defined(EXCLUDE_FROM_XARLIB)
02063 /********************************************************************************************
02064 
02065 >   virtual BOOL CamelotFileRecord::WritePath(Path* pPath)
02066 
02067     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02068     Created:    24/6/96
02069     Inputs:     pPath = ptr to a path
02070     Returns:    TRUE if OK, FALSE otherwise
02071     Purpose:    Writes out the path to the record.
02072 
02073                 All Coords in the path are translated to the origin set up in the filter
02074                 that was used to construct this object
02075     Errors:     -
02076     SeeAlso:    -
02077 
02078 ********************************************************************************************/
02079 
02080 BOOL CamelotFileRecord::WritePath(Path* pPath)
02081 {
02082     return WritePathTrans(pPath,-CoordOrigin.x,-CoordOrigin.y);
02083 }
02084 
02085 /********************************************************************************************
02086 
02087 >   virtual BOOL CamelotFileRecord::WritePathRelative(Path* pPath)
02088 
02089     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02090     Created:    24/6/96
02091     Inputs:     pPath = ptr to a path
02092     Returns:    TRUE if OK, FALSE otherwise
02093     Purpose:    Writes out the relative path to the record.
02094 
02095                 All Coords in the path are translated to the origin set up in the filter
02096                 that was used to construct this object
02097     Errors:     -
02098     SeeAlso:    -
02099 
02100 ********************************************************************************************/
02101 
02102 BOOL CamelotFileRecord::WritePathRelative(Path* pPath)
02103 {
02104     return WritePathRelativeTrans(pPath,-CoordOrigin.x,-CoordOrigin.y);
02105 }
02106 
02107 /********************************************************************************************
02108 
02109 >   virtual BOOL CamelotFileRecord::WriteCoord(const DocCoord& Coord)
02110 
02111     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02112     Created:    24/6/96
02113     Inputs:     Coord = coord to write to the record
02114     Returns:    TRUE if OK, FALSE otherwise
02115     Purpose:    Writes out the coord to the record.
02116 
02117                 The Coord is translated to the origin set up in the filter
02118                 that was used to construct this object
02119     Errors:     -
02120     SeeAlso:    -
02121 
02122 ********************************************************************************************/
02123 
02124 BOOL CamelotFileRecord::WriteCoord(const DocCoord& Coord)
02125 {
02126     return WriteCoordTrans(Coord,-CoordOrigin.x,-CoordOrigin.y);
02127 }
02128 
02129 BOOL CamelotFileRecord::WriteCoordInterleaved(const DocCoord& Coord)
02130 {
02131     return WriteCoordTransInterleaved(Coord,-CoordOrigin.x,-CoordOrigin.y);
02132 }
02133 
02134 BOOL CamelotFileRecord::WriteMatrix(const Matrix & m)
02135 {
02136     return WriteMatrixTrans(m,-CoordOrigin.x,-CoordOrigin.y);
02137 }
02138 
02139 /********************************************************************************************
02140 
02141 >   virtual BOOL CamelotFileRecord::WriteXOrd(INT32 XOrdinate)
02142 
02143     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02144     Created:    8/8/96
02145     Inputs:     XOrdinate = x ordinate to write to the record
02146     Returns:    TRUE if OK, FALSE otherwise
02147     Purpose:    Writes out the x ordinate to the record.
02148 
02149                 The ordinate is translated to the origin set up in the filter
02150                 that was used to construct this object
02151     Errors:     -
02152     SeeAlso:    -
02153 
02154 ********************************************************************************************/
02155 
02156 BOOL CamelotFileRecord::WriteXOrd(INT32 XOrdinate)
02157 {
02158     return WriteINT32(XOrdinate-CoordOrigin.x);
02159 }
02160 
02161 BOOL CamelotFileRecord::WriteYOrd(INT32 YOrdinate)
02162 {
02163     return WriteINT32(YOrdinate-CoordOrigin.y);
02164 }
02165 
02166 /********************************************************************************************
02167 
02168 >   virtual BOOL CamelotFileRecord::ReadPath(Path* pPath)
02169 
02170     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02171     Created:    24/6/96
02172     Inputs:     pPath = ptr to a path
02173     Returns:    TRUE if OK, FALSE otherwise
02174     Purpose:    Reads a path from the record.
02175 
02176                 All Coords in the path are translated to the origin set up in the filter
02177                 that was used to construct this object
02178     Errors:     -
02179     SeeAlso:    -
02180 
02181 ********************************************************************************************/
02182 
02183 BOOL CamelotFileRecord::ReadPath(Path* pPath)
02184 {
02185     return ReadPathTrans(pPath,CoordOrigin.x,CoordOrigin.y);
02186 }
02187 
02188 /********************************************************************************************
02189 
02190 >   virtual BOOL CamelotFileRecord::ReadPathRelative(Path* pPath)
02191 
02192     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02193     Created:    22/8/96
02194     Inputs:     pPath = ptr to a path
02195     Returns:    TRUE if OK, FALSE otherwise
02196     Purpose:    Reads a relative path from the record.
02197 
02198                 All Coords in the path are translated to the origin set up in the filter
02199                 that was used to construct this object
02200     Errors:     -
02201     SeeAlso:    -
02202 
02203 ********************************************************************************************/
02204 
02205 BOOL CamelotFileRecord::ReadPathRelative(Path* pPath)
02206 {
02207     return ReadPathRelativeTrans(pPath,CoordOrigin.x,CoordOrigin.y);
02208 }
02209 
02210 /********************************************************************************************
02211 
02212 >   virtual BOOL CamelotFileRecord::ReadCoord(DocCoord* pCoord)
02213 
02214     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02215     Created:    24/6/96
02216     Inputs:     pCoord = ptr coord to read into
02217     Returns:    TRUE if OK, FALSE otherwise
02218     Purpose:    Read in the coord from the record.
02219 
02220                 The Coord is translated to the origin set up in the filter
02221                 that was used to construct this object
02222     Errors:     -
02223     SeeAlso:    -
02224 
02225 ********************************************************************************************/
02226 
02227 BOOL CamelotFileRecord::ReadCoord(DocCoord* pCoord)
02228 {
02229     return ReadCoordTrans(pCoord,CoordOrigin.x,CoordOrigin.y);
02230 }
02231 
02232 BOOL CamelotFileRecord::ReadCoordInterleaved(DocCoord* pCoord)
02233 {
02234     return ReadCoordTransInterleaved(pCoord,CoordOrigin.x,CoordOrigin.y);
02235 }
02236 
02237 BOOL CamelotFileRecord::ReadMatrix(Matrix* pm)
02238 {
02239     return ReadMatrixTrans(pm,CoordOrigin.x,CoordOrigin.y);
02240 }
02241 
02242 /********************************************************************************************
02243 
02244 >   virtual BOOL CamelotFileRecord::ReadXOrd(INT32* pXOrdinate)
02245 
02246     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
02247     Created:    8/8/96
02248     Inputs:     pXOrdinate = ptr place to stick the x ordinate read in
02249     Returns:    TRUE if OK, FALSE otherwise
02250     Purpose:    Reads the x ordinate from the record.
02251 
02252                 The ordinate is translated to the origin set up in the filter
02253                 that was used to construct this object
02254     Errors:     -
02255     SeeAlso:    -
02256 
02257 ********************************************************************************************/
02258 
02259 BOOL CamelotFileRecord::ReadXOrd(INT32* pXOrdinate)
02260 {
02261     if (ReadINT32(pXOrdinate))
02262     {
02263         *pXOrdinate += CoordOrigin.x;
02264         return TRUE;
02265     }
02266 
02267     return FALSE;
02268 }
02269 
02270 BOOL CamelotFileRecord::ReadYOrd(INT32* pYOrdinate)
02271 {
02272     if (ReadINT32(pYOrdinate))
02273     {
02274         *pYOrdinate += CoordOrigin.y;
02275         return TRUE;
02276     }
02277 
02278     return FALSE;
02279 }
02280 #endif

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