00001 // $Id: rechunit.cpp 1688 2006-08-10 12:05:20Z gerry $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 // Implementation of the colour record handler class of the v2 file format 00100 00101 #include "camtypes.h" 00102 00103 #include "rechunit.h" // UnitsRecordHandler for importing units from v2 native/web files 00104 #include "unitcomp.h" // Document units component, handles import of units 00105 //#include "camfiltr.h" // BaseCamelotFilter - version 2 native filter - in camtypes.h [AUTOMATICALLY REMOVED] 00106 #include "cxftags.h" // TAG_DEFINERGBCOLOUR TAG_DEFINECOMPLEXCOLOUR 00107 //#include "cxfrec.h" // TAG_DEFINERGBCOLOUR TAG_DEFINECOMPLEXCOLOUR - in camtypes.h [AUTOMATICALLY REMOVED] 00108 #include "cxfunits.h" // default export unit types 00109 00110 DECLARE_SOURCE("$Revision: 1688 $"); 00111 00112 // Declare smart memory handling in Debug builds 00113 #define new CAM_DEBUG_NEW 00114 00115 // An implement to match the Declare in the .h file. 00116 CC_IMPLEMENT_DYNAMIC(UnitsRecordHandler,CamelotRecordHandler); 00117 00118 // #if NEW_NATIVE_FILTER // New native filters, only available to those who need them at present 00119 00120 /******************************************************************************************** 00121 00122 > virtual BOOL UnitsRecordHandler::BeginImport() 00123 00124 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00125 Created: 24/7/96 00126 Inputs: 0 00127 Returns: TRUE if ok 00128 FALSE otherwise 00129 Purpose: Initialises the units record handler. 00130 Errors: - 00131 SeeAlso: - 00132 00133 ********************************************************************************************/ 00134 00135 BOOL UnitsRecordHandler::BeginImport() 00136 { 00137 pUnitsComponent = GetUnitDocComponent(); 00138 00139 return (pUnitsComponent != NULL); 00140 } 00141 00142 /******************************************************************************************** 00143 00144 > virtual UINT32* UnitsRecordHandler::GetTagList() 00145 00146 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00147 Created: 24/7/96 00148 Inputs: - 00149 Returns: Ptr to a list of tag values, terminated by CXFRH_TAG_LIST_END 00150 Purpose: Provides the record handler system with a list of records handled by this 00151 handler 00152 SeeAlso: - 00153 00154 ********************************************************************************************/ 00155 00156 UINT32* UnitsRecordHandler::GetTagList() 00157 { 00158 static UINT32 TagList[] = {TAG_DEFINE_PREFIXUSERUNIT, TAG_DEFINE_SUFFIXUSERUNIT, 00159 TAG_DEFINE_DEFAULTUNITS, 00160 CXFRH_TAG_LIST_END}; 00161 00162 return (UINT32*)&TagList; 00163 } 00164 00165 /******************************************************************************************** 00166 00167 > virtual BOOL UnitsRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord) 00168 00169 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00170 Created: 24/7/96 00171 Inputs: pCXaraFileRecord = ptr to record to handle 00172 Returns: TRUE if handled successfuly 00173 FALSE otherwise 00174 Purpose: Handles the given record. 00175 SeeAlso: - 00176 00177 ********************************************************************************************/ 00178 00179 BOOL UnitsRecordHandler::HandleRecord(CXaraFileRecord* pCXaraFileRecord) 00180 { 00181 // WEBSTER - markn 17/12/96 00182 // No unit record handling needed 00183 #ifdef WEBSTER 00184 return TRUE; 00185 #else 00186 ERROR2IF(pCXaraFileRecord == NULL,FALSE,"UnitsRecordHandler::HandleRecord pCXaraFileRecord is NULL"); 00187 00188 BOOL ok = TRUE; 00189 Document * pDoc = GetDocument(); 00190 INT32 Tag = pCXaraFileRecord->GetTag(); 00191 switch (Tag) 00192 { 00193 case TAG_DEFINE_DEFAULTUNITS: 00194 // Ask the units document component class to import those default display units for us 00195 // If we are just importing data from this document into an existing one, 00196 // then don't import this data. 00197 if (IsImporting()) 00198 break; 00199 if (pUnitsComponent) 00200 pUnitsComponent->ImportDefaultDisplayUnits(pCXaraFileRecord, pDoc); 00201 else 00202 ERROR3("UnitsRecordHandler::HandleRecord no pUnitsComponent"); 00203 break; 00204 case TAG_DEFINE_PREFIXUSERUNIT: 00205 case TAG_DEFINE_SUFFIXUSERUNIT: 00206 // Ask the units document component class to import this user unit definition for us 00207 if (pUnitsComponent) 00208 pUnitsComponent->ImportUserUnitDefinition(pCXaraFileRecord, pDoc, Tag); 00209 else 00210 ERROR3("UnitsRecordHandler::HandleRecord no pUnitsComponent"); 00211 break; 00212 00213 default: 00214 ok = FALSE; 00215 ERROR3_PF(("UnitsRecordHandler::HandleRecord I don't handle records with the tag (%d)\n",pCXaraFileRecord->GetTag())); 00216 break; 00217 } 00218 00219 return ok; 00220 #endif // WEBSTER 00221 } 00222 00223 /******************************************************************************************** 00224 00225 > virtual void UnitsRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord,StringBase* pStr) 00226 00227 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00228 Created: 24/7/96 00229 Inputs: pRecord = ptr to a record 00230 pStr = ptr to string to update 00231 Returns: - 00232 Purpose: This provides descriptions for the define units records. 00233 Errors: - 00234 SeeAlso: - 00235 00236 ********************************************************************************************/ 00237 00238 #ifdef XAR_TREE_DIALOG 00239 void UnitsRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord, StringBase* pStr) 00240 { 00241 if (pStr == NULL || pRecord == NULL) 00242 return; 00243 00244 // Call base class first 00245 // This outputs the tag and size 00246 CamelotRecordHandler::GetRecordDescriptionText(pRecord,pStr); 00247 00248 UINT32 Tag = pRecord->GetTag(); 00249 BOOL ok = TRUE; 00250 TCHAR s[256]; 00251 // INT32 RecordNumber = pRecord->GetRecordNumber(); 00252 switch (Tag) 00253 { 00254 case TAG_DEFINE_DEFAULTUNITS: 00255 { 00256 // Read in the export unit types 00257 INT32 ExportPageUnits = 0L; 00258 INT32 ExportFontUnits = 0L; 00259 if (ok) ok = pRecord->ReadINT32(&ExportPageUnits); 00260 (*pStr) += _T("Page units: "); 00261 DescribeDefaultUnit(ExportPageUnits, pStr); 00262 (*pStr) += _T("\r\n"); 00263 if (ok) ok = pRecord->ReadINT32(&ExportFontUnits); 00264 (*pStr) += _T("Font units: "); 00265 DescribeDefaultUnit(ExportFontUnits, pStr); 00266 (*pStr) += _T("\r\n"); 00267 break; 00268 } 00269 00270 case TAG_DEFINE_PREFIXUSERUNIT: 00271 case TAG_DEFINE_SUFFIXUSERUNIT: 00272 { 00273 // BOOL Prefix = TRUE; 00274 switch (Tag) 00275 { 00276 case TAG_DEFINE_PREFIXUSERUNIT: 00277 (*pStr) += _T("Define prefix unit: \r\n\r\n"); 00278 break; 00279 case TAG_DEFINE_SUFFIXUSERUNIT: 00280 (*pStr) += _T("Define suffix unit: \r\n\r\n"); 00281 break; 00282 default: 00283 ERROR3("Bad tag in ImportUserUnitDefinition"); 00284 } 00285 00286 // Read in the main full name of the unit 00287 String_32 Name; 00288 pRecord->ReadUnicode(&Name);//Name, Name.MaxLength()); 00289 (*pStr) += _T("Name of unit: \t\t= "); 00290 (*pStr) += Name; 00291 (*pStr) += _T("\r\n"); 00292 00293 // And the abbreviation 00294 String_32 Abbrev; 00295 pRecord->ReadUnicode(&Abbrev);//Abbrev, Abbrev.MaxLength()); 00296 (*pStr) += _T("Abbreviation for unit: \t= "); 00297 (*pStr) += Abbrev; 00298 (*pStr) += _T("\r\n\r\n"); 00299 00300 // Read in the size of this unit, 0 means based on 00301 double UnitSize = 0.0; 00302 pRecord->ReadDOUBLE(&UnitSize); 00303 camSprintf(s,_T("Size of unit: \t\t= %f\r\n"),UnitSize); 00304 (*pStr) += s; 00305 00306 // Read in the exported base unit type 00307 INT32 ExportBaseUnit = 0L; 00308 pRecord->ReadINT32(&ExportBaseUnit); 00309 (*pStr) += _T("Based on unit: \t\t= "); 00310 DescribeDefaultUnit(ExportBaseUnit, pStr); 00311 (*pStr) += _T("\r\n"); 00312 00313 // Read in the multipliers for this unit 00314 double BaseNumerator = 0.0; 00315 double BaseDenominator = 0.0; 00316 pRecord->ReadDOUBLE(&BaseNumerator); 00317 pRecord->ReadDOUBLE(&BaseDenominator); 00318 camSprintf(s,_T("Numerator: \t\t= %f\r\n"),BaseNumerator); 00319 (*pStr) += s; 00320 camSprintf(s,_T("Denominator: \t\t= %f\r\n"),BaseDenominator); 00321 (*pStr) += s; 00322 00323 break; 00324 } 00325 } 00326 00327 return; 00328 } 00329 00330 /******************************************************************************************** 00331 00332 > virtual void UnitsRecordHandler::GetRecordDescriptionText(CXaraFileRecord* pRecord,StringBase* pStr) 00333 00334 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00335 Created: 25/7/96 00336 Inputs: ExportUnit(*pStr) += default unit to describe 00337 pStr = ptr to string to update 00338 Returns: - 00339 Purpose: Converts the ExportUnitType into a textual description. 00340 Errors: - 00341 SeeAlso: - 00342 00343 ********************************************************************************************/ 00344 00345 void UnitsRecordHandler::DescribeDefaultUnit(INT32 ExportUnitType, StringBase* pStr) 00346 { 00347 TCHAR s[256]; 00348 if (ExportUnitType < 0) 00349 { 00350 switch (ExportUnitType) 00351 { 00352 case REF_DEFAULTUNIT_MILLIMETRES: (*pStr) += _T("MILLIMETRES"); break; 00353 case REF_DEFAULTUNIT_CENTIMETRES: (*pStr) += _T("CENTIMETRES"); break; 00354 case REF_DEFAULTUNIT_METRES: (*pStr) += _T("METRES"); break; 00355 case REF_DEFAULTUNIT_KILOMETRES: (*pStr) += _T("KILOMETRES"); break; 00356 case REF_DEFAULTUNIT_MILLIPOINTS: (*pStr) += _T("MILLIPOINTS"); break; 00357 case REF_DEFAULTUNIT_COMP_POINTS: (*pStr) += _T("COMP_POINTS"); break; 00358 case REF_DEFAULTUNIT_PICAS: (*pStr) += _T("PICAS"); break; 00359 case REF_DEFAULTUNIT_INCHES: (*pStr) += _T("INCHES"); break; 00360 case REF_DEFAULTUNIT_FEET: (*pStr) += _T("FEET"); break; 00361 case REF_DEFAULTUNIT_YARDS: (*pStr) += _T("YARDS"); break; 00362 case REF_DEFAULTUNIT_MILES: (*pStr) += _T("MILES"); break; 00363 case REF_DEFAULTUNIT_PIXELS: (*pStr) += _T("PIXELS"); break; 00364 00365 case REF_DEFAULTUNIT_NOTYPE: (*pStr) += _T("NOTYPE"); break; 00366 default: 00367 camSprintf(s,_T("%d"),ExportUnitType); 00368 (*pStr) += s; 00369 break; 00370 } 00371 } 00372 else 00373 { 00374 camSprintf(s,_T("%d"),ExportUnitType); 00375 (*pStr) += s; 00376 } 00377 } 00378 00379 #endif // _DEBUG 00380 00381 // #endif // NEW_NATIVE_FILTER 00382