webfiltr.cpp

Go to the documentation of this file.
00001 // $Id: webfiltr.cpp 1282 2006-06-09 09:46:49Z alex $
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 Web file format for Camelot first version.
00100 // This is the minimalistic form of the new native file filter 
00101 
00102 /*
00103 */
00104 
00105 #include "camtypes.h"
00106 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "chapter.h"
00108 #include "nodepath.h"
00109 
00110 #include "webfiltr.h"
00111 //#include "oilfltrs.h" // Web oil filter i.e. Windows UI specific details e.g. extension - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "filtrres.h" // IDs
00113 #include "xarprefs.h"   // The native filter options dialogue.
00114 #include "webprefs.h"   // Web options dialog handle.
00115 #include "cxfile.h"     // CXaraFile classes
00116 #include "cxftags.h"    // The tags dude!
00117 
00118 // An implement to match the Declare in the .h file.
00119 CC_IMPLEMENT_DYNAMIC(CamelotWebFilter, BaseCamelotFilter);
00120 CC_IMPLEMENT_DYNAMIC(CamelotNULLWebFilter,CamelotWebFilter);
00121 
00122 // This will get Camelot to display the filename and linenumber of any memory allocations
00123 // that are not released at program exit
00124 #define new CAM_DEBUG_NEW
00125 
00126 /********************************************************************************************
00127 
00128 >   CamelotWebFilter::CamelotWebFilter()
00129 
00130     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00131     Created:    29/5/96
00132     Purpose:    Constructor for the Native save/load filter.
00133 
00134 ********************************************************************************************/
00135 
00136 CamelotWebFilter::CamelotWebFilter()
00137 {
00138     // Set up filter descriptions.
00139     FilterNameID = _R(IDS_FILTERNAME_WEB);
00140     FilterInfoID = _R(IDS_WEB_FILTERINFO);
00141     ImportMsgID  = _R(IDS_IMPORTMSG_WEB);
00142     ExportMsgID  = _R(IDS_EXPORTMSG_WEB);
00143 
00144     FilterID = FILTERID_WEB;
00145 
00146     Flags.CanImport = TRUE;
00147 
00148 #ifndef DO_EXPORT
00149     Flags.CanExport = FALSE;
00150 #else
00151     //WEBSTER-Martin-27/01/97
00152 #ifdef WEBSTER
00153     Flags.CanExport = FALSE;
00154 #else
00155     Flags.CanExport = TRUE;
00156 #endif //WEBSTER
00157 #endif
00158 
00159     // Message to show when a problem file is encountered
00160     BadFileMsgID = _R(IDS_NOT_A_WEB_FILE);
00161 
00162     MinWebFormat = FALSE;
00163 }
00164 
00165 
00166 /********************************************************************************************
00167 
00168 >   CamelotWebFilter::~CamelotWebFilter()
00169 
00170     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00171     Created:    29/5/96
00172     Purpose:    Tidies up when the filter is destroyed.
00173 
00174 ********************************************************************************************/
00175 
00176 CamelotWebFilter::~CamelotWebFilter()
00177 {
00178 
00179 }
00180 
00181 /********************************************************************************************
00182 
00183 >   BOOL CamelotWebFilter::Init()
00184 
00185     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00186     Created:    29/5/96
00187     Returns:    TRUE if it worked, FALSE if it failed
00188     Purpose:    Initalises the Filter ready for use. Will fail if it can not get enough
00189                 memory to work with.
00190 
00191 ********************************************************************************************/
00192 
00193 BOOL CamelotWebFilter::Init()
00194 {
00195     // Get the OILFilter object
00196     pOILFilter = new WebOILFilter(this);
00197     if (pOILFilter == NULL)
00198         return FALSE;
00199 
00200     // Load the description strings
00201     FilterName.Load(FilterNameID);
00202     FilterInfo.Load(FilterInfoID);
00203 
00204     BOOL ok = TRUE;
00205 
00206 #ifdef DO_EXPORT
00207     // Init the export web file options dialog
00208     ok = WebPrefsDlg::Init();
00209 #endif
00210 
00211     if (ok) ok = CreateRecordHandlers();
00212 
00213     BaseCamelotFilter::DontConvertTheseFontsToOutlines = String_256(_R(IDS_WEB_GUARANTEED_FONTS));
00214 
00215     if (Camelot.DeclareSection("Filters", 15))
00216     {
00217         // Preferences form the web export options dialog box
00218 
00219         // Preference for bitmap compression requested by the user
00220         // 101 -201 means use PNG but remember old JPEG setting
00221         // 0-100 use JPEG with this quality setting
00222         Camelot.DeclarePref( NULL, "BitmapCompression", &BaseCamelotFilter::BitmapCompression, 0, 201 );
00223         // Preference for whether we export a preview bitmap in web files
00224         Camelot.DeclarePref( NULL, "ExportPreviewBitmap", &BaseCamelotFilter::PreviewBitmapExport, 0, 1 );
00225         // Preference for whether we convert all text to outlines in web files (baring some assumed fonts)
00226         Camelot.DeclarePref( NULL, "ConvertTextToOutlines", &BaseCamelotFilter::ConvertTextToOutlines, 0, 1 );
00227         // Preference for whether we export invisible layers in web files or not (only applicable in non-minimal mode)
00228         Camelot.DeclarePref( NULL, "RemoveInvisibleLayers", &BaseCamelotFilter::RemoveInvisibleLayers, 0, 1 );
00229         // Preference for whether we export unused colours in web files or not (only applicable in non-minimal mode)
00230         Camelot.DeclarePref( NULL, "RemoveUnusedColours", &BaseCamelotFilter::RemoveUnusedColours, 0, 1 );
00231         // Preference for whether we export an HTML tag to the clipboard
00232         Camelot.DeclarePref( NULL, "HTMLToClipboard", &BaseCamelotFilter::HTMLToClipboard, 0, 1 );
00233         // Preference for whether we export a minimal web file or a stripped down native file
00234         Camelot.DeclarePref( NULL, "MinimalWebFormat", &BaseCamelotFilter::MinimalWebFormat, 0, 1 );
00235         
00236         // WEBSTER - markn 28/1/97
00237         // Preference for whether we convert all blends to outlines in web files
00238         Camelot.DeclarePref( NULL, "ConvertBlendsToOutlines", &BaseCamelotFilter::ConvertBlendsToOutlines, 0, 1 );
00239 
00240         // Other preferences
00241         // Preference for whether we write relative paths or not
00242         Camelot.DeclarePref( NULL, "WriteRelativePaths", &BaseCamelotFilter::WriteRelativePaths, 0, 1 );
00243         // Preference which lists the fonts not to be converted into outlines
00244         Camelot.DeclarePref( NULL, "DontConvertTheseFontsToOutlines", &BaseCamelotFilter::DontConvertTheseFontsToOutlines);
00245         // Preference for the tolerence we use to test for similar paths
00246         Camelot.DeclarePref( NULL, "WebSimilarPathTolerence", &BaseCamelotFilter::WebSimilarPathTolerence, 0, 500 );
00247 
00248         // Webster - Neville 29/7/97
00249         // Whether non-frame layers in an imported file are combined onto the active layer or the
00250         // first non-frame layer in the import
00251         Camelot.DeclarePref( NULL, "ImportNonFramesOntoActivelayer", &BaseCamelotFilter::ImportNonFramesOntoActivelayer, 0, 1 );
00252     }
00253 
00254     // All ok?
00255     return ok;
00256 }
00257 
00258 /********************************************************************************************
00259 
00260 >   virtual BaseCamelotFilter* CamelotWebFilter::CreateNULLFilter(Document* pDocument)
00261 
00262     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00263     Created:    4/6/96
00264     Inputs:     pDocument = ptr to the document
00265     Returns:    ptr to a filter that can be used to count the number of exported bytes
00266                 NULL if there's an error
00267     Purpose:    Creates the relevant NULL filter
00268     Scope:      Protected.
00269 
00270 ********************************************************************************************/
00271 
00272 BaseCamelotFilter* CamelotWebFilter::CreateNULLFilter(Document* pDocument)
00273 {
00274     BaseCamelotFilter* pFilter = new CamelotNULLWebFilter(this,pDocument);
00275 
00276     return pFilter;
00277 }
00278 
00279 /********************************************************************************************
00280 
00281 >   virtual BOOL CamelotWebFilter::IsDefaultDocRequired(const TCHAR* pcszPathName)
00282 
00283     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00284     Created:    14/6/96
00285     Inputs:     pcszPathName    pointer to the pathname to check
00286     Returns:    TRUE
00287     Purpose:    Web files need a document to live in, so TRUE is returned
00288 
00289                 (Unless it's a stupid hybrid, in which case it returns FALSE).
00290     SeeAlso:    Filter; Filter::IsDefaultDocRequired; CCamDoc::OnOpenDocument;
00291     SeeAlso:    FilterFamily::DoImport; Filter::DoImport;
00292 
00293 ********************************************************************************************/
00294 
00295 BOOL CamelotWebFilter::IsDefaultDocRequired(const TCHAR* pcszPathName)
00296 {
00297 /*
00298     // If hybrid format, when destory any elegant code that exists in the system with
00299     // stupid special cases.
00300     // The compact native format doesn't need the default doc.
00301     if (IsCompactNativeFilter())
00302         return FALSE;
00303 
00304     return TRUE;
00305 */
00306     return MinWebFormat;    // if min format, default doc is required
00307 }   
00308 
00309 /********************************************************************************************
00310 
00311 >   virtual BOOL CamelotWebFilter::BeginDocumentExport()
00312 
00313     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00314     Created:    16/8/96
00315     Inputs:     -
00316     Returns:    TRUE if successful, FALSE otherwise
00317     Purpose:    This function is called just before document-related records are written out
00318                 to the file.
00319 
00320                 The web filter writes out a TAG_DOCUMENT record to signify the start of
00321                 the document WHEN IT'S THE COMPACT NATIVE FILTER!.
00322 
00323     SeeAlso:    CamelotWebFilter::EndDocumentExport()
00324     Scope:      Protected
00325 
00326 ********************************************************************************************/
00327 
00328 BOOL CamelotWebFilter::BeginDocumentExport()
00329 {
00330     BOOL ok = TRUE;
00331 
00332     // If it's the hybrid format, do as the native filter does
00333     if (IsCompactNativeFilter())
00334     {
00335         // Writes out a document rec followed by a down rec
00336         // This will ensure that all doc-related records appear as a child of the doc record
00337         if (ok) ok = WriteZeroSizedRecord(TAG_DOCUMENT);
00338         if (ok) ok = WriteZeroSizedRecord(TAG_DOWN);
00339     }
00340 
00341     return ok;
00342 }
00343 
00344 /********************************************************************************************
00345 
00346 >   virtual BOOL CamelotWebFilter::EndDocumentExport()
00347 
00348     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00349     Created:    16/8/96
00350     Inputs:     -
00351     Returns:    TRUE if successful, FALSE otherwise
00352     Purpose:    This function is called after document-related records have been are written out
00353                 to the file.  BeginDocumentExport() is called before the doc records are saved
00354 
00355                 This should be called for each document that is saved out to the file.
00356 
00357     SeeAlso:    CamelotWebFilter::BeginDocumentExport()
00358     Scope:      Protected
00359 
00360 ********************************************************************************************/
00361 
00362 BOOL CamelotWebFilter::EndDocumentExport()
00363 {
00364     BOOL ok = TRUE;
00365 
00366     // If it's the hybrid format, do as the native filter does
00367     if (IsCompactNativeFilter())
00368     {
00369         // Writes out an up rec
00370         // This will ensure that all doc-related records appear as a child of the doc record
00371         // by matching the down rec written out by BeginDocumentExport()
00372         if (ok) ok = WriteZeroSizedRecord(TAG_UP);
00373     }
00374 
00375     return ok;
00376 }
00377 
00378 INT32 CamelotWebFilter::HowCompatibleIsFileType(char* pFileType)
00379 {
00380     MinWebFormat = TRUE;        // Default to needing default doc
00381     INT32 compatibility = 10;
00382 
00383     if (strcmp(pFileType,EXPORT_FILETYPE_WEB) == 0)         // If web file, not minimal so no default doc required
00384         MinWebFormat = FALSE;
00385     else if (strcmp(pFileType,EXPORT_FILETYPE_MIN) == 0)    // If Minimal web file, default doc is required
00386         MinWebFormat = TRUE;
00387     else
00388         compatibility = 9;                                  // You what?
00389 
00390     return compatibility;
00391 }
00392 
00393 char* CamelotWebFilter::GetExportFileType()
00394 {
00395     if (IsCompactNativeFilter())
00396         return EXPORT_FILETYPE_WEB;
00397     else
00398         return EXPORT_FILETYPE_MIN;
00399 }
00400 
00401 double CamelotWebFilter::GetSimilarPathTolerance(NodePath* pPath)
00402 {
00403     double Tolerance = 0.0;
00404 
00405     if (pPath != NULL)
00406     {
00407         // Don't get attribute-related bounds because the path might not be in the tree
00408         // (e.g. it may be generated by the 'convert text to outlines' system which keeps
00409         // all paths created from text stories in out-of-line groups)
00410         // The TRUE parameter means don't bother with attributes
00411         DocRect Rect = pPath->GetBoundingRect(TRUE);
00412         INT32 MaxDist = min(Rect.Width(),Rect.Height());
00413 
00414         Tolerance = double(MaxDist)*0.01;
00415         if (Tolerance > GetWebSimilarPathTolerence())
00416             Tolerance = GetWebSimilarPathTolerence(); 
00417     }
00418 
00419     return Tolerance;
00420 }
00421 
00422 /********************************************************************************************
00423 
00424 >   virtual BOOL CamelotWebFilter::ShouldExportHTMLTag()
00425 
00426     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00427     Created:    21/5/97
00428     Inputs:     -
00429     Returns:    The current state of the HTMLToClipboard
00430     Purpose:    Public access to the HTML to clipboard
00431     
00432 ********************************************************************************************/
00433 
00434 BOOL CamelotWebFilter::ShouldExportHTMLTag()
00435 {
00436     return BaseCamelotFilter::HTMLToClipboard;
00437 }
00438 
00439 /********************************************************************************************
00440 
00441 >   INT32 CamelotWebFilter::GetMaxPathLookUp()
00442 
00443     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00444     Created:    11/2/97
00445     Inputs:     -
00446     Returns:    100 always
00447     Purpose:    The max number pf paths that should be looked at by the function FindSimilarPath().
00448 
00449     // WEBSTER - markn 11/2/97
00450     // Added to Webster so saving .web files isn't so slow for certain git files
00451 
00452     SeeAlso:    BaseCamelotFilter::GetMaxPathLookUp;
00453     Scope:      Protected
00454 
00455 ********************************************************************************************/
00456 
00457 INT32 CamelotWebFilter::GetMaxPathLookUp()
00458 {
00459 #ifdef WEBSTER
00460     return 100;
00461 #else
00462     return -1;
00463 #endif // WEBSTER
00464 }
00465 
00466 /********************************************************************************************
00467 
00468 >   virtual OpDescriptor* CamelotWebFilter::GetDialogueOp ( void )
00469 
00470     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00471     Created:    25/10/00
00472     Inputs:     -
00473     Returns:    The OpDescriptor pointing to the dialogue used by the export proceedure.
00474     Purpose:    Obtains a pointer to the OpDescriptor to be used to access the relevant
00475                 export dialogue.
00476 
00477 ********************************************************************************************/
00478 
00479 OpDescriptor* CamelotWebFilter::GetDialogueOp ( void )
00480 {
00481     // Just return the found OpDescriptor.
00482     return OpDescriptor::FindOpDescriptor ( CC_RUNTIME_CLASS ( WebPrefsDlg ) );
00483 }
00484 
00485 //-----------------------------------------------------------------------------------------
00486 //-----------------------------------------------------------------------------------------
00487 //-----------------------------------------------------------------------------------------
00488 
00489 /********************************************************************************************
00490 
00491 >   CamelotNULLWebFilter::CamelotNULLWebFilter(BaseCamelotFilter* pThisParentFilter,Document* pDoc)
00492 
00493     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00494     Created:    24/7/96
00495     Inputs:     pThisParentFilter = ptr to the filter that created this NULL filter
00496                 pDoc = ptr to the source doc
00497     Purpose:    The default constructor
00498 
00499 ********************************************************************************************/
00500 
00501 CamelotNULLWebFilter::CamelotNULLWebFilter(BaseCamelotFilter* pThisParentFilter,Document* pDoc)
00502 {
00503     pParentFilter = pThisParentFilter;
00504 
00505     TheDocument = pDoc;
00506     pTheSpread = GetFirstSpread(pDoc);
00507     ERROR3IF(pTheSpread == NULL,"BaseCamelotFilter::DoExport no spread to export");
00508 }
00509  
00510 /********************************************************************************************
00511 
00512 >   virtual CXaraFile* CamelotNULLWebFilter::CreateCXaraFile()
00513 
00514     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00515     Created:    4/6/96
00516     Inputs:     -
00517     Returns:    ptr to a CXaraFile object that can be used for import or export
00518                 NULL if there's an error
00519     Purpose:    This version creates a NULLXaraFile object that doesn't actually
00520                 import or export any bytes
00521 
00522 ********************************************************************************************/
00523 
00524 CXaraFile* CamelotNULLWebFilter::CreateCXaraFile()
00525 {
00526     CXaraFile* pCXaraFile = new NULLXaraFile;
00527 
00528     return pCXaraFile;
00529 }
00530 
00531 void CamelotNULLWebFilter::AddNodeGroupRefToList(Node* pNode,NodeGroup* pGroup)
00532 {
00533     if (pParentFilter != NULL)
00534         pParentFilter->AddNodeGroupRefToList(pNode,pGroup);
00535 }
00536 
00537 
00538 NodeGroup* CamelotNULLWebFilter::FindGroupForThisNode(Node* pNode)
00539 {
00540     if (pParentFilter != NULL)
00541         return pParentFilter->FindGroupForThisNode(pNode);
00542 
00543     return NULL;
00544 }
00545   
00546 // WEBSTER - markn 11/2/97
00547 // System for writing tag descriptions to the file (introduced for the TAG_MOULD_BOUNDS record) /**/
00548 void CamelotNULLWebFilter::AddTagDescription(UINT32 Tag, UINT32 ID)
00549 {
00550     if (pParentFilter != NULL)
00551         pParentFilter->AddTagDescription(Tag,ID);
00552 }

Generated on Sat Nov 10 03:47:21 2007 for Camelot by  doxygen 1.4.4