00001 // $Id: pmaskrgn.cpp 1288 2006-06-09 13:16:24Z phil $ 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 // Printing Masked Render Region 00099 00100 /* 00101 */ 00102 00103 #include "camtypes.h" 00104 #include "pmaskrgn.h" 00105 #include "osrndrgn.h" 00106 #include "nodebmp.h" 00107 //#include "fillval.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 00110 // An implement to match the Declare in the .h file. 00111 CC_IMPLEMENT_DYNAMIC(PrintingMaskedRenderRegion, MaskedRenderRegion) 00112 00113 // This will get Camelot to display the filename and linenumber of any memory allocations 00114 // that are not released at program exit 00115 #define new CAM_DEBUG_NEW 00116 00117 00118 /******************************************************************************************** 00119 00120 > PrintingMaskedRenderRegion::PrintingMaskedRenderRegion(DocRect Rect, Matrix Mat, 00121 FIXED16 Scale, double dpi) 00122 00123 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00124 Created: 24/7/95 00125 Inputs: Rect - The Clip Rect of the region 00126 Mat - the rendering matrix to use 00127 Scale - the View Scale 00128 dpi - the dpi to render to 00129 Purpose: Constructs a PrintingMaskedRenderReigon 00130 INT32 dpi changed to double dpi (12/12/95) to improve the range of values allowed 00131 at the < 1000dpi settings that we will be using. 00132 00133 ********************************************************************************************/ 00134 00135 PrintingMaskedRenderRegion::PrintingMaskedRenderRegion(DocRect Rect, Matrix Mat, FIXED16 Scale, double dpi, BOOL Printing) : 00136 MaskedRenderRegion(Rect, Mat, Scale, dpi) 00137 { 00138 // Default to a non complex run 00139 IsComplexRun = FALSE; 00140 RenderFlags.Printing = Printing; 00141 } 00142 00143 00144 /******************************************************************************************** 00145 00146 > PrintingMaskedRenderRegion::~PrintingMaskedRenderRegion() 00147 00148 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00149 Created: 24/7/95 00150 Purpose: destructor - the base classes do all the work here 00151 00152 ********************************************************************************************/ 00153 00154 PrintingMaskedRenderRegion::~PrintingMaskedRenderRegion() 00155 { 00156 } 00157 00158 00159 /******************************************************************************************** 00160 00161 > virtual WinRect PrintingMaskedRenderRegion::CalculateWinRect( const Matrix& RenderMatrix, const DocRect& docrect, 00162 const double dpi) 00163 00164 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00165 Created: 4/10/96 00166 Inputs: DocRect is a rectangle on document co-ords. 00167 dpi is the resolution of the device we are rendering to 00168 Outputs: RenderMatrix is the rendering matrix, may have e anf f components changed by the call 00169 Returns: Object containing the new rectangle coordinates. 00170 Purpose: To convert a rectangle in Doc coordinates to a rectangle in Win coordinates 00171 taking account of the destination dpi rather than assuming screen dpi. 00172 Virtual so that it can be overriden by different render regions if so required. 00173 SeeAlso: OSRenderRegion::DocRectToWin; 00174 00175 ********************************************************************************************/ 00176 00177 WinRect PrintingMaskedRenderRegion::CalculateWinRect( Matrix& RenderMatrix, const DocRect& docrect, 00178 const double dpi) 00179 { 00180 // lets get the Rect into screen co-ords so we can use our big screen bitmap 00181 // Use a version of OSRenderRegion::DocRectToWin that uses the actual dpi we have stored 00182 // in PixelsPerInch 00183 // This goes back to the GRenderRegion form rather than the GRenderBitmap special form 00184 00185 return OSRenderRegion::BitmapDocRectToWin( RenderMatrix, docrect, dpi ); 00186 // return OSRenderRegion::DocRectToWin( RenderMatrix, docrect, dpi ); 00187 } 00188 00189 00190 /******************************************************************************************** 00191 00192 > virtual GMATRIX PrintingMaskedRenderRegion::MakeGavinMatrix(Matrix NewRenderMatrix, DocRect ClipRect, double dPixelsPerInch, BOOL bMasterCapture) 00193 00194 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> (from Will (from Phil code)) 00195 Created: ??/??/2004 00196 Inputs: The Kernel Matrix and cliprect to use to create the Gavin Matrix. 00197 Returns: TRUE if the GMatrix was created ok. 00198 Purpose: Make a Gavin Matrix out of a Kernel Matrix 00199 SeeAlso: GRenderRegion::SetGavinMatrix 00200 Notes: Doesn't rely on current state of CurrentClipRect like the above version 00201 00202 ********************************************************************************************/ 00203 00204 GMATRIX PrintingMaskedRenderRegion::MakeGavinMatrix(Matrix NewRenderMatrix, DocRect ClipRect, double dPixelsPerInch, BOOL bMasterCapture) 00205 { 00206 // Bypass the behaviour inherited from GRenderBitmap because we don't want it 00207 return GRenderRegion::MakeGavinMatrix(NewRenderMatrix, ClipRect, dPixelsPerInch, bMasterCapture); 00208 } 00209 00210 00211 /******************************************************************************************** 00212 00213 > void PrintingMaskedRenderRegion::SetMaskDrawingMode(BOOL OnOff) 00214 00215 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00216 Created: 24/7/95 00217 Inputs: OnOff - TRUE means the nodes we are about render will all be treated as 00218 complex nodes. FALSE means that all the nodes we are about to render are 00219 treated as simple nodes. 00220 Purpose: The render region can either be rendering simple nodes or complex nodes in 00221 runs (ie you get a block or complex one, then a block of simple ones). This 00222 function allows you to change the render regions idea of whether the nodes 00223 are complex or simple. 00224 00225 ********************************************************************************************/ 00226 00227 void PrintingMaskedRenderRegion::SetMaskDrawingMode(BOOL OnOff) 00228 { 00229 // Set our bool, making sure that it is always either TRUE or FALSE 00230 IsComplexRun = (OnOff) ? TRUE : FALSE; 00231 } 00232 00233 00234 /******************************************************************************************** 00235 00236 > virtual void PrintingMaskedRenderRegion::DrawPathToOutputDevice(Path *PathToRender) 00237 00238 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00239 Created: 24/7/95 00240 Inputs: PathToRender - the path to render 00241 Purpose: Renders a path black if we are in a complex run, or white if not 00242 00243 ********************************************************************************************/ 00244 00245 void PrintingMaskedRenderRegion::DrawPathToOutputDevice(Path *PathToRender, PathShape) 00246 { 00247 // Save the context 00248 SaveContext(); 00249 00250 // Does this shape make use of complex things 00251 if (IsComplexRun) 00252 SetNextShapeColour(Black); 00253 else 00254 SetNextShapeColour(White); 00255 00256 // Draw the path 00257 GRenderBitmap::DrawPathToOutputDevice(PathToRender); 00258 00259 /* BOOL RenderFill = FALSE; 00260 00261 // Get the current fill attr 00262 FillGeometryAttribute* pFillAttr = (FillGeometryAttribute*) CurrentAttrs[ATTR_FILLGEOMETRY].pAttr; 00263 00264 if (pFillAttr->GetBitmap() != NULL && pFillAttr->GetBitmap()->GetBPP() <= 8) 00265 { 00266 INT32 TranspIndex; 00267 00268 // If it's a masked bitmap fill, then we'll need to actually render it 00269 // (but we'll force all the non-masked pixels to be rendered black) 00270 if (pFillAttr->GetBitmap()->GetTransparencyIndex(&TranspIndex)) 00271 RenderFill = TRUE; 00272 } 00273 00274 if (RenderFill) 00275 { 00276 BOOL OldVMState = RenderFlags.VeryMono; 00277 RenderFlags.VeryMono = TRUE; // Forces non-masked pixels to be plotted black 00278 00279 // Draw the path, with the bitmap fill 00280 GRenderBitmap::DrawPathToOutputDevice(PathToRender); 00281 00282 RenderFlags.VeryMono = OldVMState; 00283 } 00284 else 00285 { 00286 // Does this shape make use of complex things 00287 if (IsComplexRun) 00288 SetNextShapeColour(Black); 00289 else 00290 SetNextShapeColour(White); 00291 00292 // Draw the path 00293 GRenderBitmap::DrawPathToOutputDevice(PathToRender); 00294 } 00295 */ 00296 00297 // restore the context 00298 RestoreContext(); 00299 } 00300 00301 00302 /******************************************************************************************** 00303 00304 > virtual void PrintingMaskedRenderRegion::DrawRect(DocRect *RectToRender) 00305 00306 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00307 Created: 24/7/95 00308 Inputs: The rect to render 00309 Purpose: Renders a path black if we are in a complex run, or white if not 00310 00311 ********************************************************************************************/ 00312 00313 void PrintingMaskedRenderRegion::DrawRect(DocRect *RectToRender) 00314 { 00315 // Save the context 00316 SaveContext(); 00317 00318 // Does this shape make use of complex things 00319 if (IsComplexRun) 00320 SetNextShapeColour(Black); 00321 else 00322 SetNextShapeColour(White); 00323 00324 // Draw the Rect 00325 GRenderBitmap::DrawRect(RectToRender); 00326 00327 // restore the context 00328 RestoreContext(); 00329 } 00330 00331 00332 /******************************************************************************************** 00333 00334 > virtual void PrintingMaskedRenderRegion::DrawLine(const DocCoord &StartPoint, 00335 const DocCoord &EndPoint) 00336 00337 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00338 Created: 24/7/95 00339 Inputs: StartPoint, EndPoint - the ends of the line 00340 Purpose: Renders a path black if we are in a complex run, or white if not 00341 00342 ********************************************************************************************/ 00343 00344 void PrintingMaskedRenderRegion::DrawLine(const DocCoord &StartPoint, const DocCoord &EndPoint) 00345 { 00346 // Save the context 00347 SaveContext(); 00348 00349 // Does this shape make use of complex things 00350 if (IsComplexRun) 00351 SetNextShapeColour(Black); 00352 else 00353 SetNextShapeColour(White); 00354 00355 // Draw the Line 00356 GRenderBitmap::DrawLine(StartPoint, EndPoint); 00357 00358 // restore the context 00359 RestoreContext(); 00360 } 00361 00362 00363 /******************************************************************************************** 00364 00365 > virtual void PrintingMaskedRenderRegion::DrawPixel(const DocCoord &Point) 00366 00367 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00368 Created: 24/7/95 00369 Inputs: Point - the point to draw the pixel at 00370 Purpose: Renders a path black if we are in a complex run, or white if not 00371 00372 ********************************************************************************************/ 00373 00374 void PrintingMaskedRenderRegion::DrawPixel(const DocCoord &Point) 00375 { 00376 // Save the context 00377 SaveContext(); 00378 00379 // Does this shape make use of complex things 00380 if (IsComplexRun) 00381 SetNextShapeColour(Black); 00382 else 00383 SetNextShapeColour(White); 00384 00385 // Draw the Pixel 00386 GRenderBitmap::DrawPixel(Point); 00387 00388 // restore the context 00389 RestoreContext(); 00390 } 00391 00392 00393 /******************************************************************************************** 00394 00395 > virtual void PrintingMaskedRenderRegion::DrawBitmap(const DocCoord &Point, 00396 KernelBitmap* pBitmap) 00397 00398 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00399 Created: 24/7/95 00400 Inputs: Point - The point to draw the bitmap at 00401 pBitmap - at the bitmap 00402 Purpose: Renders a path black if we are in a complex run, or white if not 00403 00404 ********************************************************************************************/ 00405 00406 void PrintingMaskedRenderRegion::DrawBitmap(const DocCoord &Point, KernelBitmap* pBitmap) 00407 { 00408 // Save the context 00409 SaveContext(); 00410 00411 // Does this shape make use of complex things 00412 if (IsComplexRun) 00413 SetNextShapeColour(Black); 00414 else 00415 SetNextShapeColour(White); 00416 00417 // Draw the bitmap 00418 GRenderBitmap::DrawBitmap(Point, pBitmap); 00419 00420 // restore the context 00421 RestoreContext(); 00422 } 00423 00424 00425 /******************************************************************************************** 00426 00427 > virtual void PrintingMaskedRenderRegion::DrawBitmap(const DocCoord &Point, UINT32 BitmapID, UINT32 ToolID = NULL) 00428 00429 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00430 Created: 24/7/95 00431 Inputs: Point - the point to draw the bitmap at 00432 BitmapID - The ID of the bitmap to draw 00433 ToolID - the ID of the tool the resource is part of 00434 Purpose: Renders a path black if we are in a complex run, or white if not 00435 00436 ********************************************************************************************/ 00437 00438 void PrintingMaskedRenderRegion::DrawBitmap(const DocCoord &Point, UINT32 BitmapID, UINT32 ToolID) 00439 { 00440 // Save the context 00441 SaveContext(); 00442 00443 // Does this shape make use of complex things 00444 if (IsComplexRun) 00445 SetNextShapeColour(Black); 00446 else 00447 SetNextShapeColour(White); 00448 00449 // Draw the Bitmap 00450 GRenderBitmap::DrawBitmap(Point, BitmapID, ToolID); 00451 00452 // restore the context 00453 RestoreContext(); 00454 } 00455 00456 00457 /******************************************************************************************** 00458 00459 > virtual BOOL PrintingMaskedRenderRegion::DrawTransformedBitmap(NodeBitmap *pNodeBitmap) 00460 00461 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00462 Created: 24/7/95 00463 Inputs: pNodeBitmap - the Node bitmap to render 00464 Purpose: Renders a path black if we are in a complex run, or white if not 00465 00466 ********************************************************************************************/ 00467 00468 BOOL PrintingMaskedRenderRegion::DrawTransformedBitmap(NodeBitmap *pNodeBitmap) 00469 { 00470 // Save the context 00471 SaveContext(); 00472 00473 // Does this shape make use of complex things 00474 if (IsComplexRun) 00475 SetNextShapeColour(Black); 00476 else 00477 SetNextShapeColour(White); 00478 00479 // Draw the Bitmap 00480 BOOL Result = GRenderBitmap::DrawTransformedBitmap(pNodeBitmap); 00481 00482 /* BOOL Result = TRUE; 00483 00484 // Work out if we can do this bitmap directly 00485 BOOL CanDoBitmap = FALSE; 00486 00487 // Does this shape make use of complex things 00488 if (!(IsComplexRun || pNodeBitmap->NeedsTransparency())) 00489 { 00490 // See what kind of bitmaps this render region can do 00491 if (HostCaps.ArbitraryBitmaps) 00492 { 00493 // We can do anything... 00494 CanDoBitmap = TRUE; 00495 } 00496 else 00497 { 00498 if (HostCaps.SimpleBitmaps) 00499 { 00500 // Check that the bitmap area is rectangular, and is perpendicular to 00501 // the x and y axes. 00502 if (pNodeBitmap->HasSimpleOrientation(this)) 00503 { 00504 // Yes - simple scaling - the render region can do this. 00505 CanDoBitmap = TRUE; 00506 } 00507 } 00508 } 00509 } 00510 00511 // Here we set up reasonable attributes - we want to fill the bitmap 00512 // path but not stroke it. NB. This is very important - do not remove 00513 // otherwise the mask will be wrong! 00514 SetFillColour(DocColour(COLOUR_BLACK)); 00515 SetLineColour(DocColour(COLOUR_NONE)); 00516 00517 if (CanDoBitmap) 00518 { 00519 SetNextShapeColour(White); 00520 00521 // Draw the path (that represents the bitmap object) 00522 GRenderBitmap::DrawPathToOutputDevice(&pNodeBitmap->InkPath); 00523 } 00524 else 00525 { 00526 if (pNodeBitmap->NeedsTransparency()) 00527 { 00528 // It's a masked bitmap, so we'll need to actually render the non-masked 00529 // pixels as black 00530 BOOL OldVMState = RenderFlags.VeryMono; 00531 RenderFlags.VeryMono = TRUE; // Forces non-masked pixels to be plotted black 00532 00533 // Call base class to plot the bitmap 00534 RenderRegion::DrawTransformedBitmap(pNodeBitmap); 00535 00536 RenderFlags.VeryMono = OldVMState; 00537 } 00538 else 00539 { 00540 SetNextShapeColour(Black); 00541 00542 // Draw the path (that represents the bitmap object) 00543 GRenderBitmap::DrawPathToOutputDevice(&pNodeBitmap->InkPath); 00544 } 00545 } 00546 */ 00547 00548 // restore the context 00549 RestoreContext(); 00550 00551 // return if it worked or not 00552 return Result; 00553 } 00554 00555 00556 00557 00558 /******************************************************************************************** 00559 00560 > virtual BOOL PrintingMaskedRenderRegion::RenderChar(WCHAR ch, Matrix* pMatrix) 00561 00562 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00563 Created: 2/8/95 00564 Inputs: ch - the char to render 00565 Outputs: pMatrix - the matrix to use to render with 00566 Returns: TRUE if it worked, FALSE if not. 00567 Purpose: Renders a char into the mask sometimes - there are times when we do not want 00568 the char to render - eps when we are dealing with postscript, where what we 00569 render and what postscript renders may be different. 00570 00571 ********************************************************************************************/ 00572 00573 BOOL PrintingMaskedRenderRegion::RenderChar(WCHAR ch, Matrix* pMatrix) 00574 { 00575 // Save the context 00576 SaveContext(); 00577 00578 // Get ready to return 00579 BOOL Result = TRUE; 00580 00581 // Does this shape make use of complex things 00582 // if it is not complex them do not try and punch it out of the mask, as this 00583 // causes problems on postscript devices. 00584 if (IsComplexRun) 00585 { 00586 SetNextShapeColour(Black); 00587 Result = GRenderBitmap::RenderChar(ch, pMatrix); 00588 } 00589 00590 // restore the context 00591 RestoreContext(); 00592 00593 // return 00594 return Result; 00595 } 00596