vectrndr.cpp

Go to the documentation of this file.
00001 // $Id: vectrndr.cpp 1304 2006-06-12 23:03:14Z 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 #include "camtypes.h"
00099 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00100 //#include "rndrgn.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00101 #include "vectrndr.h"
00102 
00103 CC_IMPLEMENT_DYNAMIC( VectorFileRenderRegion, RenderRegion )
00104 
00105 /********************************************************************************************
00106 
00107 >   VectorFileRenderRegion::VectorFileRenderRegion( void );
00108 
00109     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00110     Created:    25/10/00
00111     Purpose:    Default constructor for the VectorFileRenderRegion class.
00112     SeeAlso:    EPSOutputFilter::Init
00113 
00114 ********************************************************************************************/
00115 
00116 VectorFileRenderRegion::VectorFileRenderRegion( void )
00117     : RenderRegion()
00118 {
00119     // Null this pointer to prevent access violations.
00120     LastOutputAttrs = NULL;
00121 }
00122 
00123 /********************************************************************************************
00124 
00125 >   VectorFileRenderRegion::VectorFileRenderRegion( DocRect ClipRect,
00126                                                      Matrix     ConvertMatrix,
00127                                                      FIXED16    ViewScale )
00128 
00129     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00130     Created:    25/10/00
00131     Purpose:    Constructor for the VectorFileRenderRegion class.
00132     SeeAlso:    EPSOutputFilter::Init
00133 
00134 ********************************************************************************************/
00135 
00136 VectorFileRenderRegion::VectorFileRenderRegion( DocRect ClipRect,
00137                                                  Matrix     ConvertMatrix,
00138                                                  FIXED16    ViewScale )
00139     : RenderRegion( ClipRect, ConvertMatrix, ViewScale )
00140 {
00141     // Null this pointer to prevent access violations.
00142     LastOutputAttrs = NULL;
00143 }
00144 
00145 /********************************************************************************************
00146 
00147 >   VectorFileRenderRegion::~VectorFileRenderRegion( void )
00148 
00149     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00150     Created:    25/10/00
00151     Purpose:    Destructor for the VectorFileRenderRegion class.
00152 
00153 ********************************************************************************************/
00154 
00155 VectorFileRenderRegion::~VectorFileRenderRegion( void )
00156 {
00157     // Clear up any attributes that survived the rendering process.
00158     DeInitAttributes();
00159 }
00160 
00161 /********************************************************************************************
00162 
00163 >   BOOL VectorFileRenderRegion::Init( void )
00164 
00165     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00166     Created:    25/10/00
00167     Returns:    TRUE    - Successful.
00168                 FALSE   - An error occured.
00169     Purpose:    Constructor for the VectorFileRenderRegion class.
00170 
00171 ********************************************************************************************/
00172 
00173 BOOL VectorFileRenderRegion::Init( void )
00174 {
00175     // Clear up any previous attributes.
00176     DeInitAttributes();
00177 
00178     return TRUE;
00179 }
00180 
00181 /********************************************************************************************
00182 
00183 >   BOOL VectorFileRenderRegion::StartRender()
00184 
00185     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00186     Created:    30/03/94    ( Moved here on 26/10/00 )
00187     Returns:    TRUE if worked, FALSE if failed.
00188     Purpose:    Prepare the render region for rendering (exporting).
00189     SeeAlso:    EPSRenderRegion::Initialise; EPSRenderRegion::StopRender
00190 
00191 ********************************************************************************************/
00192 
00193 BOOL VectorFileRenderRegion::StartRender()
00194 {
00195     // Call base class first.
00196     if (!RenderRegion::StartRender())
00197         return FALSE;
00198 
00199     InitAttributes();
00200 
00201     return TRUE;
00202 }
00203 
00204 /********************************************************************************************
00205 
00206 >   BOOL VectorFileRenderRegion::StopRender()
00207 
00208     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00209     Created:    30/03/94    ( Moved here on 26/10/00 )
00210     Purpose:    Deinitialise the render region after rendering (exporting).
00211 
00212 ********************************************************************************************/
00213 
00214 BOOL VectorFileRenderRegion::StopRender()
00215 {
00216     DeInitAttributes();
00217     return TRUE;
00218 }
00219 
00220 /********************************************************************************************
00221 
00222 >   void VectorFileRenderRegion::DrawRect( DocRect *RectToRender )
00223 
00224     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00225     Created:    30/03/94    ( Moved here on 26/10/00 )
00226     Purpose:    None at present - this function should not be called during ink rendering.
00227     Errors:     ENSURE failure if called.
00228 
00229 ********************************************************************************************/
00230 
00231 void VectorFileRenderRegion::DrawRect(DocRect *RectToRender)
00232 {
00233     ENSURE( FALSE, "VectorFileRenderRegion::DrawRect called - this should not happen!" );
00234 }
00235 
00236 /********************************************************************************************
00237 
00238 >   void VectorFileRenderRegion::DrawDragRect( DocRect *RectToRender )
00239 
00240     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00241     Created:    30/03/94    ( Moved here on 26/10/00 )
00242     Purpose:    Should not be called for this kind of render region.
00243     Errors:     ENSURE failure if called.
00244     SeeAlso:    RenderRegion::DrawDragRect
00245 
00246 ********************************************************************************************/
00247 
00248 void VectorFileRenderRegion::DrawDragRect( DocRect *RectToRender )
00249 {
00250     ENSURE(FALSE, "DrawDragRect called while exporting!");
00251 }
00252 
00253 /********************************************************************************************
00254 
00255 >   void VectorFileRenderRegion::DrawLine( const DocCoord   &StartPoint,
00256                                             const DocCoord  &EndPoint )
00257 
00258     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00259     Created:    30/03/94    ( Moved here on 26/10/00 )
00260     Purpose:    None at present - this function should not be called during ink rendering.
00261     Errors:     ENSURE failure if called.
00262 
00263 ********************************************************************************************/
00264 
00265 void VectorFileRenderRegion::DrawLine( const DocCoord   &StartPoint,
00266                                         const DocCoord  &EndPoint )
00267 {
00268     ENSURE( FALSE, "EPSRenderRegion::DrawLine called - this should not happen!" );
00269 }
00270 
00271 /********************************************************************************************
00272 
00273 >   void VectorFileRenderRegion::DrawPixel(const DocCoord &Point)
00274 
00275     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00276     Created:    30/03/94    ( Moved here on 26/10/00 )
00277     Purpose:    Should not be called for this kind of render region.
00278     Errors:     ENSURE failure if called.
00279     SeeAlso:    RenderRegion::DrawPixel
00280 
00281 ********************************************************************************************/
00282 
00283 void VectorFileRenderRegion::DrawPixel( const DocCoord &Point )
00284 {
00285     ENSURE( FALSE, "DrawPixel called while exporting!" );
00286 }
00287 
00288 /********************************************************************************************
00289 
00290 >   void VectorFileRenderRegion::DrawBlob( DocCoord p,
00291                                             BlobType    type)
00292 
00293     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00294     Created:    30/03/94    ( Moved here on 26/10/00 )
00295     Purpose:    Should not be called for this kind of render region.
00296     Errors:     ENSURE failure if called.
00297     SeeAlso:    RenderRegion::DrawBlob
00298 
00299 ********************************************************************************************/
00300 
00301 void VectorFileRenderRegion::DrawBlob( DocCoord p,
00302                                         BlobType    type)
00303 {
00304     ENSURE( FALSE, "DrawBlob called while exporting!" );
00305 }
00306 
00307 /********************************************************************************************
00308 
00309 >   void VectorFileRenderRegion::DrawCross( const DocCoord  &Point,
00310                                              const UINT32       Size )
00311 
00312     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00313     Created:    30/03/94    ( Moved here on 26/10/00 )
00314     Purpose:    Should not be called for this kind of render region.
00315     Errors:     ENSURE failure if called.
00316     SeeAlso:    RenderRegion::DrawCross
00317 
00318 ********************************************************************************************/
00319 
00320 void VectorFileRenderRegion::DrawCross( const DocCoord  &Point,
00321                                          const UINT32       Size )
00322 {
00323     ENSURE( FALSE, "DrawCross called while exporting!" );
00324 }
00325 
00326 /********************************************************************************************
00327 
00328 >   void VectorFileRenderRegion::DrawBitmap( const DocCoord &Point,
00329                                               KernelBitmap*     pBitmap )
00330 
00331     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00332     Created:    26/10/00
00333     Purpose:    Should not be called for this kind of render region.
00334     Errors:     ENSURE failure if called.
00335     SeeAlso:    RenderRegion::DrawBitmap
00336 
00337 ********************************************************************************************/
00338 
00339 void VectorFileRenderRegion::DrawBitmap( const DocCoord &Point,
00340                                           KernelBitmap*     pBitmap )
00341 {
00342     ENSURE( FALSE, "DrawBitmap called while exporting!" );
00343 }
00344 
00345 /********************************************************************************************
00346 
00347 >   void VectorFileRenderRegion::DrawBitmap( const DocCoord &Point,
00348                                               UINT32                BitmapID,
00349                                               UINT32                ToolID = NULL )
00350 
00351     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00352     Created:    26/10/00
00353     Purpose:    Should not be called for this kind of render region.
00354     Errors:     ENSURE failure if called.
00355     SeeAlso:    RenderRegion::DrawBitmap
00356 
00357 ********************************************************************************************/
00358 
00359 void VectorFileRenderRegion::DrawBitmap( const DocCoord &Point,
00360                                           UINT32                BitmapID,
00361                                           UINT32                ToolID )
00362 {
00363     ENSURE( FALSE, "DrawBitmap called while exporting!" );
00364 }
00365 
00366 /********************************************************************************************
00367 
00368 >   void VectorFileRenderRegion::DrawBitmap( const DocCoord &Point,
00369                                               KernelBitmap*     pBitmap )
00370 
00371     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00372     Created:    26/10/00
00373     Purpose:    Should not be called for this kind of render region.
00374     Errors:     ENSURE failure if called.
00375     SeeAlso:    RenderRegion::DrawBitmap
00376 
00377 ********************************************************************************************/
00378 
00379 void VectorFileRenderRegion::DrawBitmapBlob( const DocCoord &Point,
00380                                               KernelBitmap*     BlobShape )
00381 {
00382     ENSURE( FALSE, "DrawBitmapBlob called while exporting!" );
00383 }
00384 
00385 /********************************************************************************************
00386 
00387 >   void VectorFileRenderRegion::DrawBitmapBlob( const DocCoord &Point,
00388                                                   UINT32                BitmapID,
00389                                                   UINT32                ToolID = NULL )
00390 
00391     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00392     Created:    26/10/00
00393     Purpose:    Should not be called for this kind of render region.
00394     Errors:     ENSURE failure if called.
00395     SeeAlso:    RenderRegion::DrawBitmap
00396 
00397 ********************************************************************************************/
00398 
00399 void VectorFileRenderRegion::DrawBitmapBlob( const DocCoord &Point,
00400                                               UINT32                BitmapID/*,
00401                                               UINT32                ToolID*/ )
00402 {
00403     ENSURE( FALSE, "DrawBitmapBlob called while exporting!" );
00404 }
00405 
00406 /********************************************************************************************
00407 
00408 >   MILLIPOINT VectorFileRenderRegion::CalcPixelWidth()
00409 
00410     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00411     Created:    30/03/94    ( Moved here on 26/10/00 )
00412     Returns:    Width of pixels on millipoints.
00413     Purpose:    None for vector file render regions - just returns 1.
00414     SeeAlso:    VectorFileRenderRegion::CalcScaledPixelWidth
00415 
00416 ********************************************************************************************/
00417 
00418 MILLIPOINT VectorFileRenderRegion::CalcPixelWidth()
00419 {
00420     return 1;
00421 }
00422 
00423 /********************************************************************************************
00424 
00425 >   MILLIPOINT VectorFileRenderRegion::CalcScaledPixelWidth()
00426 
00427     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00428     Created:    30/03/94    ( Moved here on 26/10/00 )
00429     Returns:    Scaled width of pixels on millipoints.
00430     Purpose:    None for vector file render regions - just returns 1.
00431     SeeAlso:    VectorFileRenderRegion::CalcPixelWidth
00432 
00433 ********************************************************************************************/
00434 
00435 MILLIPOINT VectorFileRenderRegion::CalcScaledPixelWidth()
00436 {
00437     return 1;
00438 }
00439 
00440 /********************************************************************************************
00441 
00442 >   void VectorFileRenderRegion::InitClipping()
00443 
00444     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00445     Created:    26/10/00
00446     Purpose:    Stub function.
00447     SeeAlso:    VectorFileRenderRegion::InitAttributes
00448 
00449 ********************************************************************************************/
00450 
00451 void VectorFileRenderRegion::InitClipping()
00452 {
00453     // Do nothing.
00454 }
00455 
00456 /********************************************************************************************
00457 
00458 >   void VectorFileRenderRegion::InitAttributes()
00459 
00460     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00461     Created:    30/03/94    ( Moved here on 26/10/00 )
00462     Purpose:    Set up the default attributes for the render region.
00463                 (Actually just marks the path attributes as invalid, so that we output
00464                 some attribute commands before the first path we export).
00465     SeeAlso:    VectorFileRenderRegion::InitClipping
00466 
00467 ********************************************************************************************/
00468 
00469 void VectorFileRenderRegion::InitAttributes()
00470 {
00471     // We don't use pens and brushes.
00472     SetOSDrawingMode();
00473     SetLineAttributes();
00474     SetFillAttributes();
00475 
00476     // Set up the Last Output attributes for this device, first making sure that
00477     // any we might have lying around already are cleaned up.
00478     DeInitAttributes();
00479     LastOutputAttrs = AttributeManager::GetDefaultAttributes();
00480 
00481     if ( LastOutputAttrs != NULL )
00482     {
00483         for ( INT32 i = 0; i < NumCurrentAttrs; i++ )
00484         {
00485             // NULL all the pointers to begin with,
00486             // so that all default attribute are output
00487             // with the first object
00488             LastOutputAttrs[i].pAttr    = NULL;
00489             LastOutputAttrs[i].Temp     = FALSE;
00490             LastOutputAttrs[i].Ignore   = FALSE;
00491         }
00492     }
00493 }
00494 
00495 /********************************************************************************************
00496 
00497 >   void VectorFileRenderRegion::DeInitAttributes()
00498 
00499     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00500     Created:    30/03/94    ( Moved here on 26/10/00 )
00501     Purpose:    Cleans up the default attributes for the render region.
00502 
00503 ********************************************************************************************/
00504 
00505 void VectorFileRenderRegion::DeInitAttributes()
00506 {
00507     // Release the 'Last Ouput' array
00508     if ( LastOutputAttrs != NULL )
00509     {
00510         for ( INT32 i = 0; i < NumCurrentAttrs; i++ )
00511         {
00512             if ( LastOutputAttrs[i].Temp )
00513             {
00514                 delete LastOutputAttrs[i].pAttr;
00515             }
00516         }
00517 
00518         // We've finished with this array of attributes now
00519         CCFree( LastOutputAttrs );
00520         LastOutputAttrs = NULL;
00521     }
00522 }
00523 
00524 /********************************************************************************************
00525 
00526 >   void VectorFileRenderRegion::SetOSDrawingMode ()
00527 
00528     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00529     Created:    30/03/94    ( Moved here on 26/10/00 )
00530     Purpose:    Ensures that the drawing mode is set to DM_COPYPEN - any other drawing
00531                 mode doesn't make sense when exporting EPS.
00532     Errors:     If drawing mode is not DM_COPYPEN, ENSURE failure.
00533 
00534 ********************************************************************************************/
00535 
00536 void VectorFileRenderRegion::SetOSDrawingMode()
00537 {
00538     // EPS doesn't care about drawing modes...or at least, we should never set
00539     // anything other than COPYPEN - EOR is right out!
00540     ENSURE( DrawingMode == DM_COPYPEN, "Non-standard drawing mode in EPS output!" );
00541 }
00542 
00543 /********************************************************************************************
00544 
00545 >   void VectorFileRenderRegion::SetQualityLevel()
00546 
00547     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>           ( Modified by Graeme )
00548     Created:    30/03/94    ( Moved here on 26/10/00 )
00549     Purpose:    Sets the quality level for the drawing. Unused.
00550 
00551 ********************************************************************************************/
00552 
00553 void VectorFileRenderRegion::SetQualityLevel()
00554 {
00555 }
00556 
00557 /********************************************************************************************
00558 
00559 >   DocColour VectorFileRenderRegion::AlphaBlend( DocColour *pForeground,
00560                                                    DocColour *pBackground,
00561                                                    UINT32 Transp )
00562 
00563     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00564     Created:    19/1/00
00565     Returns:    A DocColour containing the blend of the two input colours.
00566     Purpose:    Blends the two colours (pForeground and pBackground) together using a
00567                 simple alpha blending algorithm.
00568 
00569                 Moved into the VectorFileRenderRegion on 20/12/00
00570     SeeAlso:    -
00571 
00572 ********************************************************************************************/
00573 
00574 DocColour VectorFileRenderRegion::AlphaBlend( DocColour &Foreground,
00575                                                DocColour &Background,
00576                                                UINT32 Transp )
00577 {
00578     // Step 1:  Declare local variables.
00579     DocColour   Result;
00580     INT32       FGColour [3];
00581     INT32       BGColour [3];
00582     INT32       ResultColour [3];
00583 
00584     // Step 2:  Extract the colours from the DocColour class.
00585     Foreground.GetRGBValue( &( FGColour [0] ), &( FGColour [1] ), &( FGColour [2] ) );
00586     Background.GetRGBValue( &( BGColour [0] ), &( BGColour [1] ), &( BGColour [2] ) );
00587 
00588     // Step 3:  Cycle through the list of colours, perform the alpha blend, and pass the
00589     //          result out.
00590     for ( INT32 i = 0; i < 3; i++ )
00591     {
00592         // Perform the alpha blend.
00593         ResultColour [i] = ( ( ( 255 - Transp ) * FGColour [i] ) +
00594                              ( Transp * BGColour [i] ) ) / 255;
00595     }
00596 
00597     // Step 4:  Set the colour value.
00598     Result.SetRGBValue( ResultColour [0], ResultColour [1], ResultColour [2] );
00599 
00600     // Step 5:  And return it.
00601     return Result;
00602 }

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