00001 // $Id: native.cpp 1479 2006-07-19 17:14:58Z gerry $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // 00099 // The Native file format for Camelot first version. 00100 // This should be the true all singing replacement for the bodge EPS form. 00101 00102 /* 00103 */ 00104 00105 #include "camtypes.h" 00106 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 #include "camdoc.h" 00108 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 #include "native.h" 00110 //#include "rik.h" 00111 //#include "oilfltrs.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00112 00113 //#include "filtrres.h" 00114 00115 #include "cxfile.h" 00116 #include "cxftags.h" 00117 #include "xarprefs.h" 00118 #include "webprefs.h" // Web options dialog handler, WebPrefsDlgParam class 00119 00120 // An implement to match the Declare in the .h file. 00121 CC_IMPLEMENT_DYNAMIC(CamelotNativeFilter, BaseCamelotFilter); 00122 CC_IMPLEMENT_DYNAMIC(CamelotNULLNativeFilter,CamelotNativeFilter); 00123 00124 // This will get Camelot to display the filename and linenumber of any memory allocations 00125 // that are not released at program exit 00126 // Declare smart memory handling in Debug builds 00127 #define new CAM_DEBUG_NEW 00128 00129 /******************************************************************************************** 00130 00131 > CamelotNativeFilter::CamelotNativeFilter() 00132 00133 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00134 Created: 25/5/96 00135 Purpose: Constructor for the Native save/load filter. 00136 00137 ********************************************************************************************/ 00138 00139 CamelotNativeFilter::CamelotNativeFilter() 00140 { 00141 // Set up filter descriptions. 00142 FilterNameID = _R(IDS_FILTERNAME_NATIVE); 00143 FilterInfoID = _R(IDS_NATIVE_FILTERINFO); 00144 ImportMsgID = _R(IDS_IMPORTMSG_NATIVE); 00145 ExportMsgID = _R(IDS_EXPORTMSG_NATIVE); 00146 00147 FilterID = FILTERID_NATIVE; 00148 00149 #ifndef STANDALONE 00150 Flags.CanImport = TRUE; 00151 //WEBSTER-Martin-27/01/97 00152 #ifdef WEBSTER 00153 Flags.CanExport = FALSE; 00154 #else 00155 Flags.CanExport = TRUE; 00156 #endif //WEBSTER 00157 #else 00158 Flags.CanImport = TRUE; 00159 Flags.CanExport = FALSE; 00160 #endif 00161 00162 // Message to show when a problem file is encountered 00163 BadFileMsgID = _R(IDS_NOT_A_NATIVE_FILE); 00164 } 00165 00166 00167 00168 00169 /******************************************************************************************** 00170 00171 > CamelotNativeFilter::~CamelotNativeFilter() 00172 00173 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00174 Created: 25/5/96 00175 Purpose: Tidies up when the filter is destroyed. 00176 00177 ********************************************************************************************/ 00178 00179 CamelotNativeFilter::~CamelotNativeFilter() 00180 { 00181 00182 } 00183 00184 /******************************************************************************************** 00185 00186 > BOOL CamelotNativeFilter::Init() 00187 00188 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00189 Created: 25/5/96 00190 Returns: TRUE if it worked, FALSE if it failed 00191 Purpose: Initalises the Filter ready for use. Will fail if it can not get enough 00192 memory to work with. 00193 00194 ********************************************************************************************/ 00195 00196 BOOL CamelotNativeFilter::Init() 00197 { 00198 // Get the OILFilter object 00199 pOILFilter = new NativeOILFilter(this); 00200 if (pOILFilter == NULL) 00201 return FALSE; 00202 00203 // Load the description strings 00204 FilterName.Load(FilterNameID); 00205 FilterInfo.Load(FilterInfoID); 00206 00207 BOOL ok = CreateRecordHandlers(); 00208 00209 if (Camelot.DeclareSection( _T("Filters"), 10)) 00210 { 00211 // Preference to turn native file compression on or off 00212 Camelot.DeclarePref( NULL, _T("CompressV2Format"), &BaseCamelotFilter::CompressNative, 0, 1 ); 00213 // Preference to turn xpe bitmap saving on or off 00214 Camelot.DeclarePref( NULL, _T("SaveXPEBitmaps"), &BaseCamelotFilter::SaveXPEBitmaps, 0, 1 ); 00215 // Preference to decide what bitmap format to use for preview bitmaps 00216 Camelot.DeclarePref( NULL, _T("PreviewBitmapFilterType"), &BaseCamelotFilter::PreviewBitmapFilterType, 0, 4 ); 00217 // Preference for the optional export as web pathname when native saving 00218 Camelot.DeclarePref( NULL, _T("DefaultWebExportFilterPath"), &BaseCamelotFilter::DefaultExportPath); 00219 // Preference to turn native file checking for similar paths on or off 00220 Camelot.DeclarePref( NULL, _T("NativeCheckSimilarPaths"), &BaseCamelotFilter::NativeCheckSimilarPaths, 0, 1 ); 00221 } 00222 00223 #ifdef DO_EXPORT 00224 00225 // Initialise the native file export options dialog. 00226 if ( ok ) 00227 { 00228 ok = NativePrefsDlg::Init (); 00229 } 00230 00231 #endif 00232 00233 return ok; 00234 } 00235 00236 /******************************************************************************************** 00237 00238 > virtual INT32 CamelotNativeFilter::GetBitmapCompression() 00239 00240 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00241 Created: 15/8/96 00242 Inputs: - 00243 Returns: The current state of the bitmap compression. 00244 Purpose: Public access to the current bitmap compression which the user has requested 00245 to use when saving bitmaps in the web format. 00246 0 means maximum compression e.g. use JPEG filter at 0% lossy compression 00247 100 means minimum compression e.g. use JPEG filter at 100% lossy compression 00248 101 - 200 means lossless compression e.g. us PNG filter. 00249 Could use the no bitmap compression at all e.g. use BMP filter. Unused at present. 00250 (Very much like the JPEG compression percentage). 00251 Note: This overrides the baseclass version to save in the proper native state 00252 00253 ********************************************************************************************/ 00254 00255 INT32 CamelotNativeFilter::GetBitmapCompression() 00256 { 00257 // Always use a lossless format such as PNG in native files 00258 return 200; 00259 } 00260 00261 /******************************************************************************************** 00262 00263 > virtual BOOL CamelotNativeFilter::GetPreviewBitmapExport() 00264 00265 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00266 Created: 15/8/96 00267 Inputs: - 00268 Returns: The current state of the export preview bitmap. 00269 Purpose: Public access to the current export preview bitmap which the user has requested 00270 to use when saving bitmaps in the web format. 00271 True means export a preview bitmap, False means do not. 00272 Note: This overrides the baseclass version to save in the proper native state 00273 00274 ********************************************************************************************/ 00275 00276 BOOL CamelotNativeFilter::GetPreviewBitmapExport() 00277 { 00278 #if (_OLE_VER >= 0x200) 00279 // Get some documents to check up on. 00280 ERROR2IF(!TheDocument, FALSE, 00281 "Null Document* in CamelotNativeFilter::GetPreviewBitmapExport"); 00282 00283 if(TheDocument->IsAClipboard()) 00284 return FALSE; // clipboard docs don't have previews 00285 00286 CCamDoc* pDoc = TheDocument->GetOilDoc(); 00287 ERROR2IF(!TheDocument->GetOilDoc(), FALSE, 00288 "Null CCamDoc* in CamelotNativeFilter::GetPreviewBitmapExport"); 00289 00290 // We *don't* export a preview bitmap if the associated document is embedded in an 00291 // OLE container. Basically, let the document decide. 00292 return pDoc->ShouldExportPreview(); 00293 #else 00294 return TRUE; 00295 #endif 00296 } 00297 00298 /******************************************************************************************** 00299 00300 > virtual BOOL CamelotNativeFilter::GetConvertTextToOutlines() 00301 00302 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00303 Created: 15/8/96 00304 Inputs: - 00305 Returns: The current state of the convert text to outlines. 00306 Purpose: Public access to the current convert text to outlines which the user has requested 00307 to use when saving in the web format. 00308 True means convert text to outlines, False means do not. 00309 Note: This overrides the baseclass version to save in the proper native state 00310 00311 ********************************************************************************************/ 00312 00313 BOOL CamelotNativeFilter::GetConvertTextToOutlines() 00314 { 00315 // In native files ensure text is not converted to outlines 00316 return FALSE; 00317 } 00318 00319 /******************************************************************************************** 00320 00321 > virtual BOOL CamelotNativeFilter::GetRemoveInvisibleLayers() 00322 00323 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00324 Created: 15/8/96 00325 Inputs: - 00326 Returns: The current state of the remove invisible layers. 00327 Purpose: Public access to the current remove invisible layers which the user has requested 00328 to use when saving in the web format. 00329 True means remove invisible layers, False means do not. 00330 Note: This overrides the baseclass version to save in the proper native state 00331 00332 ********************************************************************************************/ 00333 00334 BOOL CamelotNativeFilter::GetRemoveInvisibleLayers() 00335 { 00336 // In native files retain inivisible layers 00337 return FALSE; 00338 } 00339 00340 /******************************************************************************************** 00341 00342 > virtual BOOL CamelotNativeFilter::GetRemoveUnusedColours() 00343 00344 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00345 Created: 15/8/96 00346 Inputs: - 00347 Returns: The current state of the remove unused colours. 00348 Purpose: Public access to the current remove unused colours which the user has requested 00349 to use when saving in the web format. 00350 True means remove unused colours, False means do not. 00351 Note: This overrides the baseclass version to save in the proper native state 00352 00353 ********************************************************************************************/ 00354 00355 BOOL CamelotNativeFilter::GetRemoveUnusedColours() 00356 { 00357 // In native files retain unused colours 00358 return FALSE; 00359 } 00360 00361 /******************************************************************************************** 00362 00363 > virtual BaseCamelotFilter* CamelotNativeFilter::CreateNULLFilter(Document* pDocument) 00364 00365 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00366 Created: 4/6/96 00367 Inputs: pDocument = ptr to the document 00368 Returns: ptr to a filter that can be used to count the number of exported bytes 00369 NULL if there's an error 00370 Purpose: Creates the relevant NULL filter 00371 Scope: Protected. 00372 00373 ********************************************************************************************/ 00374 00375 BaseCamelotFilter* CamelotNativeFilter::CreateNULLFilter(Document* pDocument) 00376 { 00377 BaseCamelotFilter* pFilter = new CamelotNULLNativeFilter(this,pDocument); 00378 00379 return pFilter; 00380 } 00381 00382 /******************************************************************************************** 00383 00384 > virtual BOOL CamelotNativeFilter::BeginDocumentExport() 00385 00386 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00387 Created: 30/7/96 00388 Inputs: - 00389 Returns: TRUE if successful, FALSE otherwise 00390 Purpose: This function is called just before document-related records are written out 00391 to the file. 00392 00393 The native filter writes out a TAG_DOCUMENT record to signify the start of 00394 the document. 00395 00396 SeeAlso: CamelotNativeFilter::EndDocumentExport() 00397 Scope: Protected 00398 00399 ********************************************************************************************/ 00400 00401 BOOL CamelotNativeFilter::BeginDocumentExport() 00402 { 00403 BOOL ok = TRUE; 00404 00405 // Writes out a document rec followed by a down rec 00406 // This will ensure that all doc-related records appear as a child of the doc record 00407 if (ok) ok = WriteZeroSizedRecord(TAG_DOCUMENT); 00408 if (ok) ok = WriteZeroSizedRecord(TAG_DOWN); 00409 00410 return ok; 00411 } 00412 00413 /******************************************************************************************** 00414 00415 > virtual BOOL CamelotNativeFilter::EndDocumentExport() 00416 00417 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00418 Created: 30/7/96 00419 Inputs: - 00420 Returns: TRUE if successful, FALSE otherwise 00421 Purpose: This function is called after document-related records have been are written out 00422 to the file. BeginDocumentExport() is called before the doc records are saved 00423 00424 This should be called for each document that is saved out to the file. 00425 00426 SeeAlso: CamelotNativeFilter::BeginDocumentExport() 00427 Scope: Protected 00428 00429 ********************************************************************************************/ 00430 00431 BOOL CamelotNativeFilter::EndDocumentExport() 00432 { 00433 BOOL ok = TRUE; 00434 00435 // Writes out an up rec 00436 // This will ensure that all doc-related records appear as a child of the doc record 00437 // by matching the down rec written out by BeginDocumentExport() 00438 if (ok) ok = WriteZeroSizedRecord(TAG_UP); 00439 00440 return ok; 00441 } 00442 00443 INT32 CamelotNativeFilter::HowCompatibleIsFileType(char* pFileType) 00444 { 00445 if (strcmp(pFileType,GetExportFileType()) == 0) 00446 return 10; 00447 else 00448 return 9; 00449 } 00450 00451 char* CamelotNativeFilter::GetExportFileType() 00452 { 00453 return EXPORT_FILETYPE_NATIVE; 00454 } 00455 00456 double CamelotNativeFilter::GetSimilarPathTolerance(NodePath* pPath) 00457 { 00458 return 0.0; 00459 } 00460 00461 /******************************************************************************************** 00462 00463 > INT32 CamelotNativeFilter::GetMaxPathLookUp() 00464 00465 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00466 Created: 19/9/96 00467 Inputs: - 00468 Returns: 100 always 00469 Purpose: The max number pf paths that should be looked at by the function FindSimilarPath(). 00470 00471 SeeAlso: BaseCamelotFilter::GetMaxPathLookUp; 00472 Scope: Protected 00473 00474 ********************************************************************************************/ 00475 00476 INT32 CamelotNativeFilter::GetMaxPathLookUp() 00477 { 00478 return -1;//100; 00479 } 00480 00481 00482 00483 00484 /******************************************************************************************** 00485 00486 > BOOL CamelotNativeFilter::WriteCurrentAttributes() 00487 00488 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00489 Created: 19/03/2004 00490 Inputs: - 00491 Outputs: - 00492 Returns: TRUE if worked, FALSE otherwise 00493 Purpose: Write out all current attributes 00494 Errors: - 00495 SeeAlso: - 00496 00497 ********************************************************************************************/ 00498 00499 BOOL CamelotNativeFilter::WriteCurrentAttributes() 00500 { 00501 BOOL ok = TRUE; 00502 00503 if (ok && TheDocument) 00504 { 00505 AttributeManager* pAttrMgr = &(TheDocument->GetAttributeMgr()); 00506 if (pAttrMgr) 00507 ok = pAttrMgr->WriteCurrentAttributes(this); 00508 } 00509 00510 return (ok); 00511 } 00512 00513 00514 00515 00516 //----------------------------------------------------------------------------------------- 00517 //----------------------------------------------------------------------------------------- 00518 //----------------------------------------------------------------------------------------- 00519 00520 /******************************************************************************************** 00521 00522 > CamelotNULLNativeFilter::CamelotNULLNativeFilter(BaseCamelotFilter* pThisParentFilter,Document* pDoc) 00523 00524 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00525 Created: 24/7/96 00526 Inputs: pThisParentFilter = ptr to the filter that created this NULL filter 00527 pDoc = ptr to the source doc 00528 Purpose: The default constructor 00529 00530 ********************************************************************************************/ 00531 00532 CamelotNULLNativeFilter::CamelotNULLNativeFilter(BaseCamelotFilter* pThisParentFilter,Document* pDoc) 00533 { 00534 pParentFilter = pThisParentFilter; 00535 00536 TheDocument = pDoc; 00537 pTheSpread = GetFirstSpread(pDoc); 00538 ERROR3IF(pTheSpread == NULL, "BaseCamelotFilter::DoExport no spread to export"); 00539 } 00540 00541 /******************************************************************************************** 00542 00543 > virtual CXaraFile* CamelotNULLNativeFilter::CreateCXaraFile() 00544 00545 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00546 Created: 4/6/96 00547 Inputs: - 00548 Returns: ptr to a CXaraFile object that can be used for import or export 00549 NULL if there's an error 00550 Purpose: This version creates a NULLXaraFile object that doesn't actually 00551 import or export any bytes 00552 00553 ********************************************************************************************/ 00554 00555 CXaraFile* CamelotNULLNativeFilter::CreateCXaraFile() 00556 { 00557 CXaraFile* pCXaraFile = new NULLXaraFile; 00558 00559 return pCXaraFile; 00560 } 00561 00562 //-------------------------------------------------------------------------- 00563 00564 // WEBSTER - markn 31/1/97 00565 // Replaced with general system 00566 /* 00567 void CamelotNULLNativeFilter::AddTextStoryGroupRefToList(TextStory* pStory,NodeGroup* pGroup) 00568 { 00569 if (pParentFilter != NULL) 00570 pParentFilter->AddTextStoryGroupRefToList(pStory,pGroup); 00571 } 00572 00573 00574 NodeGroup* CamelotNULLNativeFilter::FindTextStoryGroupRefGroup(TextStory* pStory) 00575 { 00576 if (pParentFilter != NULL) 00577 return pParentFilter->FindTextStoryGroupRefGroup(pStory); 00578 00579 return NULL; 00580 } 00581 00582 TextStory* CamelotNULLNativeFilter::FindTextStoryGroupRefTextStory(NodeGroup* pGroup) 00583 { 00584 if (pParentFilter != NULL) 00585 return pParentFilter->FindTextStoryGroupRefTextStory(pGroup); 00586 00587 return NULL; 00588 } 00589 */ 00590 00591 void CamelotNULLNativeFilter::AddNodeGroupRefToList(Node* pNode,NodeGroup* pGroup) 00592 { 00593 if (pParentFilter != NULL) 00594 pParentFilter->AddNodeGroupRefToList(pNode,pGroup); 00595 } 00596 00597 00598 NodeGroup* CamelotNULLNativeFilter::FindGroupForThisNode(Node* pNode) 00599 { 00600 if (pParentFilter != NULL) 00601 return pParentFilter->FindGroupForThisNode(pNode); 00602 00603 return NULL; 00604 } 00605 00606 // WEBSTER - markn 11/2/97 00607 // System for writing tag descriptions to the file (introduced for the TAG_MOULD_BOUNDS record) /**/ 00608 void CamelotNULLNativeFilter::AddTagDescription(UINT32 Tag, UINT32 ID) 00609 { 00610 if (pParentFilter != NULL) 00611 pParentFilter->AddTagDescription(Tag,ID); 00612 } 00613 00614 00615 00616