00001 // $Id: filtirr.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 // ImagemapRenderRegion 00099 00100 #include "camtypes.h" 00101 #include "filtirr.h" 00102 00103 //#include "view.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00104 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 00107 #include "imagemap.h" //For Imagemap 00108 #include "webattr.h" //For WebAddressAttribute 00109 00110 00111 CC_IMPLEMENT_DYNAMIC(ImagemapRenderRegion, RenderRegion) 00112 00113 //These MIN and MAX macros are used below 00114 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 00115 #define MAX(a, b) ((a) < (b) ? (b) : (a)) 00116 00117 /******************************************************************************************** 00118 00119 > ImagemapRenderRegion::ImagemapRenderRegion() : RenderRegion() 00120 00121 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00122 Created: 14/4/97 00123 Purpose: Default constructor 00124 00125 ********************************************************************************************/ 00126 00127 ImagemapRenderRegion::ImagemapRenderRegion() : RenderRegion() 00128 { 00129 m_Options=ImagemapFilterOptions(); 00130 } 00131 00132 /******************************************************************************************** 00133 00134 > ImagemapRenderRegion::ImagemapRenderRegion(ImagemapFilterOptions ifoOptions) 00135 00136 00137 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00138 Created: 14/4/97 00139 Purpose: Specific constructor, using a set of ImagemapFilterOptions. 00140 00141 Note how this contructor works. It calls the RenderRegion constructor: 00142 00143 RenderRegion(ClipRect, ConvertMatrix, ViewScale) 00144 00145 with ClipRect derived from the ImagemapFilterOptions, ConvertMatrix 00146 set to the identity and ViewScale set to 1. 00147 00148 00149 ********************************************************************************************/ 00150 00151 ImagemapRenderRegion::ImagemapRenderRegion(ImagemapFilterOptions ifoOptions) : 00152 RenderRegion(ImagemapFilterOptions::GetSizeOfExportArea(ifoOptions.m_stExportArea), Matrix(), 1) 00153 { 00154 m_Options=ifoOptions; 00155 } 00156 00157 /******************************************************************************************** 00158 00159 > ImagemapRenderRegion::~ImagemapRenderRegion() 00160 00161 00162 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00163 Created: 14/4/97 00164 Purpose: Destructor 00165 00166 00167 ********************************************************************************************/ 00168 00169 ImagemapRenderRegion::~ImagemapRenderRegion() 00170 { 00171 m_Imagemap.DeleteAll(); 00172 } 00173 00174 /******************************************************************************************** 00175 00176 > void ImagemapRenderRegion::DrawDragRect(DocRect *RectToRender)// 00177 00178 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00179 Created: 14/4/97 00180 Purpose: Should not be called for this kind of render region. 00181 Errors: ENSURE failure if called. 00182 SeeAlso: RenderRegion::DrawDragRect 00183 00184 ********************************************************************************************/ 00185 00186 void ImagemapRenderRegion::DrawDragRect(DocRect *RectToRender) 00187 { 00188 ENSURE(FALSE, "DrawDragRect called while exporting!"); 00189 } 00190 00191 /******************************************************************************************** 00192 00193 > void ImagemapRenderRegion::DrawPixel(const DocCoord &Point) 00194 00195 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00196 Created: 14/4/97 00197 Purpose: Should not be called for this kind of render region. 00198 Errors: ENSURE failure if called. 00199 SeeAlso: RenderRegion::DrawPixel 00200 00201 ********************************************************************************************/ 00202 00203 void ImagemapRenderRegion::DrawPixel(const DocCoord &Point) 00204 { 00205 ENSURE(FALSE, "DrawPixel called while exporting!"); 00206 } 00207 00208 /******************************************************************************************** 00209 00210 > void ImagemapRenderRegion::DrawBlob(DocCoord p, BlobType type) 00211 00212 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00213 Created: 14/4/97 00214 Purpose: Should not be called for this kind of render region. 00215 Errors: ENSURE failure if called. 00216 SeeAlso: RenderRegion::DrawBlob 00217 00218 ********************************************************************************************/ 00219 00220 void ImagemapRenderRegion::DrawBlob(DocCoord p, BlobType type) 00221 { 00222 ENSURE(FALSE, "DrawBlob called while exporting!"); 00223 } 00224 00225 /******************************************************************************************** 00226 00227 > void ImagemapRenderRegion::DrawCross(const DocCoord &Point, const UINT32 Size) 00228 00229 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00230 Created: 14/4/97 00231 Purpose: Should not be called for this kind of render region. 00232 Errors: ENSURE failure if called. 00233 SeeAlso: RenderRegion::DrawCross 00234 00235 ********************************************************************************************/ 00236 00237 void ImagemapRenderRegion::DrawCross(const DocCoord &Point, const UINT32 Size) 00238 { 00239 ENSURE(FALSE, "DrawCross called while exporting!"); 00240 } 00241 00242 00243 /******************************************************************************************** 00244 00245 > void ImagemapRenderRegion::DrawPathToOutputDevice(Path *ppthRender, PathShape shapePath=PATHSHAPE_PATH) 00246 00247 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00248 Created: 14/4/97 00249 Inputs: ppthRender - Pointer to the path to render 00250 shapePath - Tag to tell us what shape the path is. The 00251 values we are interested in are: 00252 00253 PATHSHAPE_RECTANGLE (and PATHSHAPE_SQUARE) 00254 PATHSHAPE_CIRCLE 00255 00256 Purpose: Renders this path into the ImagemapRenderRegion 00257 00258 It does this by adding a clickable area into the imagemap list. 00259 00260 SeeAlso: RenderRegion::DrawPath 00261 00262 ********************************************************************************************/ 00263 00264 void ImagemapRenderRegion::DrawPathToOutputDevice(Path *ppthRender, PathShape shapePath) 00265 { 00266 //First check our path parameter 00267 if (ppthRender==NULL) 00268 { 00269 ERROR2RAW("ImagemapRenderRegion::DrawPathToOutputDevice not given a path!"); 00270 return; 00271 } 00272 00273 //Now get the current WebAddressAttribute 00274 WebAddressAttribute* pwaaCurrent=(WebAddressAttribute*) GetCurrentAttribute(ATTR_WEBADDRESS); 00275 00276 if (pwaaCurrent==NULL) 00277 { 00278 ERROR2RAW("ImagemapRenderRegion::DrawPathToOutputDevice - no current WebAddressAttribute!"); 00279 return; 00280 } 00281 00282 00283 //IF the current WebAddressAttribute has a URL 00284 if (pwaaCurrent->HasURL()) 00285 { 00286 //Then we want to add a clickable area into the imagemap 00287 00288 //Now, if EITHER the user has specified that this clickable area is a rectangle 00289 //OR the user has specified all clickable areas should be rectangles 00290 //OR this path is a rectangle shape 00291 if (m_Options.m_fAllRectangles 00292 || pwaaCurrent->UseBoundingRectangle() 00293 || shapePath==PATHSHAPE_RECTANGLE 00294 || shapePath==PATHSHAPE_SQUARE) 00295 { 00296 //Then we want to add a clickable area into the imagemap 00297 00298 //So get the rectangle to add 00299 DocRect rectToAdd=pwaaCurrent->GetClickableRectangleInRendering(); 00300 00301 //And add it 00302 AddRectangleToImagemap(rectToAdd, pwaaCurrent); 00303 00304 } 00305 else 00306 { 00307 //It's not a rectangle 00308 00309 //So, what shape is the path? 00310 if (shapePath==PATHSHAPE_CIRCLE) 00311 //Circular. So add a circle to the imagemap 00312 AddCircleToImagemap(ppthRender, pwaaCurrent); 00313 else 00314 //Otherwise, add a polygon to the imagemap 00315 AddPathToImagemap(ppthRender, pwaaCurrent); 00316 00317 }//End if/else rectangle 00318 00319 } //ENd if/else has URL 00320 00321 } 00322 00323 00324 00325 /******************************************************************************************** 00326 00327 > void ImagemapRenderRegion::DrawRect(DocRect *RectToRender) 00328 00329 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00330 Created: /08/96 00331 Input: RectToRender - The rectangle to render 00332 Purpose: Does nothing 00333 00334 00335 ********************************************************************************************/ 00336 00337 void ImagemapRenderRegion::DrawRect(DocRect *RectToRender) 00338 { 00339 ENSURE(FALSE, "ImagemapRenderRegion::DrawRect called - this should not happen!"); 00340 } 00341 00342 /******************************************************************************************** 00343 00344 > void ImagemapRenderRegion::DrawLine(const DocCoord &StartPoint, const DocCoord &EndPoint) 00345 00346 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00347 Created: 14/4/97 00348 Purpose: None at present - this function should not be called during ink rendering. 00349 Errors: ENSURE failure if called. 00350 00351 ********************************************************************************************/ 00352 00353 void ImagemapRenderRegion::DrawLine(const DocCoord &StartPoint, const DocCoord &EndPoint) 00354 { 00355 ENSURE(FALSE, "ImagemapRenderRegion::DrawLine called - this should not happen!"); 00356 } 00357 00358 /******************************************************************************************** 00359 00360 > MILLIPOINT ImagemapRenderRegion::CalcPixelWidth() 00361 00362 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00363 Created: 14/4/97 00364 Returns: Width of pixels on millipoints. 00365 Purpose: None for Imagemap render regions - just returns 1. 00366 Errors: - 00367 SeeAlso: ImagemapRenderRegion::CalcScaledPixelWidth 00368 00369 ********************************************************************************************/ 00370 00371 MILLIPOINT ImagemapRenderRegion::CalcPixelWidth() 00372 { 00373 //Return an invalid value 00374 return 1; 00375 } 00376 00377 /******************************************************************************************** 00378 00379 > MILLIPOINT ImagemapRenderRegion::CalcScaledPixelWidth() 00380 00381 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00382 Created: 14/4/97 00383 Returns: Scaled width of pixels on millipoints. 00384 Purpose: None for CMX render regions - just returns 1. 00385 Errors: ENSURE failure if called. 00386 SeeAlso: ImagemapRenderRegion::CalcPixelWidth 00387 00388 ********************************************************************************************/ 00389 00390 MILLIPOINT ImagemapRenderRegion::CalcScaledPixelWidth() 00391 { 00392 //Return an invalid value 00393 return 1; 00394 } 00395 00396 /******************************************************************************************** 00397 00398 > virtual void ImagemapRenderRegion::GetRenderRegionCaps(RRCaps* pCaps) 00399 00400 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00401 Created: 14/4/97 00402 Outputs: pCaps - The details about what types of thing this render region can render 00403 Purpose: This function allows render regions to admit to what they can and can not 00404 render. This allows other areas of the program to come in and help render 00405 regions out in some situations, if they are unable to render everything. 00406 eg. an OSRenderRegion can not render transparancy. 00407 00408 ********************************************************************************************/ 00409 00410 void ImagemapRenderRegion::GetRenderRegionCaps(RRCaps* pCaps) 00411 { 00412 //This seems to be what all the other overrides do, so I guess 00413 //I'll do the same 00414 pCaps->CanDoNothing(); 00415 00416 } 00417 00418 00419 00420 00421 /******************************************************************************************** 00422 00423 > virtual BOOL ImagemapRenderRegion::WantsGrids() 00424 00425 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00426 Created: 14/4/97 00427 Returns: FALSE 00428 Purpose: very little 00429 00430 ********************************************************************************************/ 00431 00432 BOOL ImagemapRenderRegion::WantsGrids() 00433 { 00434 return FALSE; 00435 } 00436 00437 /******************************************************************************************** 00438 00439 > INT32 ImagemapRenderRegion::Write(CCLexFile* pfileToWrite=NULL, TCHAR* pcBuffer=NULL) 00440 00441 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00442 Created: 16/4/97 00443 Inputs: pfileToWrite - The file to write to 00444 pcBuffer - Pointer to a text buffer to write to 00445 00446 Either of the above may be NULL. 00447 00448 Returns: The number of TCHARs written. 00449 00450 Purpose: Writes the imagemap HTML, either to the file 00451 or the text buffer or both: 00452 00453 <MAP> 00454 <AREA SHAPE=RECTANGLE...> 00455 <AREA SHAPE=RECTANGLE...> 00456 </MAP> 00457 00458 00459 ********************************************************************************************/ 00460 00461 INT32 ImagemapRenderRegion::Write(CCLexFile* pfileToWrite, TCHAR* pcBuffer) 00462 { 00463 return m_Imagemap.Write(pfileToWrite, pcBuffer); 00464 00465 } 00466 00467 /******************************************************************************************** 00468 00469 > void ImagemapRenderRegion::AddRectangleToImagemap(DocRect rectToScale, WebAddressAttribute* pwaaCurrent) 00470 00471 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00472 Created: 25/4/97 00473 Inputs: rectToAdd The rectangle to add to the imagemap 00474 pwaaToAdd Pointer to the current WebAddressAttribute 00475 00476 Purpose: Scales the rectangle then adds it to the imagemap list. 00477 00478 SeeAlso: ImagemapRenderRegion::DrawPathToOutputDevice 00479 00480 ********************************************************************************************/ 00481 00482 void ImagemapRenderRegion::AddRectangleToImagemap(DocRect rectToScale, WebAddressAttribute* pwaaCurrent) 00483 { 00484 //First get the origin of the export area and the DPI 00485 DocCoord dcOrigin=ImagemapFilterOptions::GetOriginOfExportArea(m_Options.m_stExportArea); 00486 double dDPI=m_Options.m_dDPI; 00487 00488 //Scale the rectangle 00489 rectToScale.lo.Scale(dcOrigin, dDPI); 00490 rectToScale.hi.Scale(dcOrigin, dDPI); 00491 00492 //Now, in scaling the rectangle we may have made it invalid (for example, we 00493 //may have scaled rectToScale.lo so that it is actually higher than recToScale.hi). 00494 00495 //So create a new valid rectangle 00496 DocRect rectToAdd; 00497 00498 rectToAdd.lo.x=MIN(rectToScale.lo.x, rectToScale.hi.x); 00499 rectToAdd.hi.x=MAX(rectToScale.lo.x, rectToScale.hi.x); 00500 rectToAdd.lo.y=MIN(rectToScale.lo.y, rectToScale.hi.y); 00501 rectToAdd.hi.y=MAX(rectToScale.lo.y, rectToScale.hi.y); 00502 00503 //And add it to the imagemap 00504 m_Imagemap.AddRectangle(rectToAdd, pwaaCurrent->m_url.GetWebAddress(), pwaaCurrent->m_pcFrame); 00505 00506 } 00507 00508 /******************************************************************************************** 00509 00510 > void ImagemapRenderRegion::AddCircleToImagemap(Path* ppthToScale, WebAddressAttribute* pwaaCurrent) 00511 00512 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00513 Created: 25/4/97 00514 Inputs: ppthToAdd The circle to add to the imagemap 00515 pwaaToAdd Pointer to the current WebAddressAttribute 00516 00517 Purpose: Scales the path then adds it to the imagemap list as a circle 00518 00519 SeeAlso: ImagemapRenderRegion::DrawPathToOutputDevice 00520 00521 ********************************************************************************************/ 00522 00523 void ImagemapRenderRegion::AddCircleToImagemap(Path* ppthToScale, WebAddressAttribute* pwaaCurrent) 00524 { 00525 //First get the origin of the export area and the DPI 00526 DocCoord dcOrigin=ImagemapFilterOptions::GetOriginOfExportArea(m_Options.m_stExportArea); 00527 double dDPI=m_Options.m_dDPI; 00528 00529 //Now make a copy of the path 00530 Path pthToAdd; 00531 00532 pthToAdd.Initialise(ppthToScale->GetNumCoords()); 00533 00534 pthToAdd.CopyPathDataFrom(ppthToScale); 00535 00536 //Scale it 00537 pthToAdd.Scale(dcOrigin, dDPI); 00538 00539 //And add it to the imagemap 00540 m_Imagemap.AddCircle(&pthToAdd, pwaaCurrent->m_url.GetWebAddress(), pwaaCurrent->m_pcFrame); 00541 00542 } 00543 00544 /******************************************************************************************** 00545 00546 > void ImagemapRenderRegion::AddPathToImagemap(Path* ppthToAdd, WebAddressAttribute* pwaaCurrent) 00547 00548 Author: Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com> 00549 Created: 25/4/97 00550 Inputs: ppthToAdd The path to add to the imagemap 00551 pwaaToAdd Pointer to the current WebAddressAttribute 00552 00553 Purpose: This function goes through the subpaths of the path one by one. 00554 00555 For each closed subpath, it: 00556 a. Scales the subpath 00557 b. Flattens the subpath 00558 c. Adds the result to the imagemap 00559 00560 SeeAlso: ImagemapRenderRegion::DrawPathToOutputDevice 00561 00562 ********************************************************************************************/ 00563 00564 void ImagemapRenderRegion::AddPathToImagemap(Path* ppthToAdd, WebAddressAttribute* pwaaCurrent) 00565 { 00566 //First get the origin of the export area and the DPI 00567 DocCoord dcOrigin=ImagemapFilterOptions::GetOriginOfExportArea(m_Options.m_stExportArea); 00568 double dDPI=m_Options.m_dDPI; 00569 00570 //Now, how many subpaths are there in this path? 00571 INT32 lNumSubpaths=ppthToAdd->GetNumSubpaths(); 00572 00573 //For each subpath in the path 00574 for (INT32 l=0; l<lNumSubpaths; l++) 00575 { 00576 //Create a new path 00577 Path pthSubpath; 00578 00579 pthSubpath.Initialise(ppthToAdd->GetNumCoords()); 00580 00581 //And copy the next subpath into it 00582 ppthToAdd->MakePathFromSubPath(l, &pthSubpath); 00583 00584 //Now, if that subpath is closed 00585 if (pthSubpath.IsSubPathClosed(0)) 00586 { 00587 //Then we want to add it to the imagemap 00588 00589 //So scale it to dDPI and by dcOrigin 00590 pthSubpath.Scale(dcOrigin, dDPI); 00591 00592 //Now we need to flatten it. 00593 //This means creating a new path, because otherwise Path::Flatten 00594 //goes wrong 00595 00596 Path pthFlattened; 00597 00598 pthFlattened.Initialise(pthSubpath.GetNumCoords()); 00599 00600 //So, if we should flatten the path 00601 if (m_Options.m_ffApprox!=FF_NOTATALL) 00602 //Then do it 00603 pthSubpath.Flatten(m_Options.m_ffApprox, &pthFlattened); 00604 else 00605 //Otherwise, simply copy the path across 00606 pthFlattened.CopyPathDataFrom(&pthSubpath); 00607 00608 //Then add the flattened path to the imagemap 00609 m_Imagemap.AddPolygon(&pthFlattened, pwaaCurrent->m_url.GetWebAddress(), pwaaCurrent->m_pcFrame); 00610 } 00611 } 00612 00613 00614 } 00615 00616 00617 00618 00619 00620 00621