cmxrendr.cpp

Go to the documentation of this file.
00001 // $Id: cmxrendr.cpp 1319 2006-06-14 12:22:54Z 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 // CMX RenderRegion, for exporting
00099 
00100 #include "camtypes.h"
00101 #include "cmxrendr.h"
00102 #include "cmxexdc.h"
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 //#include "rrcaps.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 //#include "range.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "rendsel.h"
00110 #include "nbevcont.h"
00111 
00112 CC_IMPLEMENT_DYNAMIC(CMXRenderRegion, VectorFileRenderRegion)
00113 
00114 /********************************************************************************************
00115 
00116 >   CMXRenderRegion::CMXRenderRegion(DocRect ClipRect, Matrix ConvertMatrix, 
00117                                      FIXED16 ViewScale) :
00118                                         RenderRegion(ClipRect, ConvertMatrix, ViewScale)
00119 
00120     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
00121     Created:    18/06/96
00122     Purpose:    Constructor for an CMXOutputFilter object.  The object should be initialised
00123                 before use.
00124     SeeAlso:    CMXOutputFilter::Init
00125 
00126 ********************************************************************************************/
00127 
00128 CMXRenderRegion::CMXRenderRegion(DocRect ClipRect, Matrix ConvertMatrix, FIXED16 ViewScale) :
00129     VectorFileRenderRegion(ClipRect, ConvertMatrix, ViewScale)
00130 {
00131 }
00132 
00133 /********************************************************************************************
00134 
00135 >   BOOL CMXRenderRegion::AttachDevice(View* pView, CDC* pDC, Spread* pSpread)
00136 
00137     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
00138     Created:    18/06/96
00139     Inputs:     pView - the view to attach this region to - ignored (must be NULL).
00140                 pDC - the device context to attach the render region to.
00141                 pSpread - the spread to attach the render region to.
00142     Purpose:    Attach the CMX render region to a device context and a spread to export.
00143     SeeAlso:    RenderRegion::AttachDevice; CMXExportDC
00144 
00145 ********************************************************************************************/
00146 
00147 BOOL CMXRenderRegion::AttachDevice(View* pView, CDC* pDC, Spread* pSpread)
00148 {
00149     // Call the base class first
00150     if (!RenderRegion::AttachDevice(pView, pDC, pSpread))
00151         return FALSE;
00152     
00153     // Save the first node we need to export.
00154 //  CurrentRenderState = pSpread->FindFirstForExport(this, FALSE);
00155 
00156     // Get a pointer to the CCDiskFile object
00157     CMXExportDC *pCMXDC = (CMXExportDC *) pDC;
00158     ExportFile = pCMXDC->ExportFile;
00159 
00160     // let it our lovely matrix
00161     pCMXDC->SetTransMatrix(&RenderMatrix);
00162 
00163     // All okey dokey
00164     return TRUE;
00165 }
00166 
00167 
00168 /********************************************************************************************
00169 
00170 >   BOOL CMXRenderRegion::InitDevice()
00171 
00172     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
00173     Created:    18/06/96
00174     Returns:    TRUE if the device context is initialised ok;
00175                 FALSE if not.
00176     Purpose:    Initialise the device specific mechanisms for this render region.
00177     Errors:     Same as base class.
00178     SeeAlso:    RenderRegion::InitDevice
00179 
00180 ********************************************************************************************/
00181 
00182 BOOL CMXRenderRegion::InitDevice()
00183 {
00184     // Call base class
00185     if (!RenderRegion::InitDevice())
00186         return FALSE;
00187 
00188     // Set the render caps up
00189     GetRenderRegionCaps(&Caps);
00190 
00191     // Find out which document we're using
00192     ENSURE(RenderView->GetDoc() != NULL, "View's document is NULL!");
00193     Document *TheDocument = RenderView->GetDoc();
00194 
00195     KernelDC *pDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
00196     cmxDC = (CMXExportDC *)RenderDC;
00197 
00198     // Set up render region
00199     InitClipping();
00200 
00201     // All ok
00202     return TRUE;
00203 }
00204 
00205 // 
00206 // These are the functions that are not used for exporting files...
00207 
00208 /********************************************************************************************
00209 
00210 >   void CMXRenderRegion::DrawPathToOutputDevice(Path *DrawPath, BOOL DataOnly)
00211 
00212     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
00213     Created:    18/06/96
00214     Inputs:     DrawPath - the path to render.
00215     Purpose:    Output all the commands required to render this path to the CMX file.
00216     SeeAlso:    RenderRegion::DrawPath; CMXRenderRegion::GetValidPathAttributes
00217                 CMXRenderRegion::ExportPath
00218 
00219 ********************************************************************************************/
00220 
00221 void CMXRenderRegion::DrawPathToOutputDevice(Path *DrawPath, PathShape)
00222 {
00223     ExportPath(DrawPath, FALSE);
00224 }
00225 
00226 /********************************************************************************************
00227 
00228 >   BOOL CMXRenderRegion::ExportPath(Path *DrawPath, BOOL DataOnly)
00229 
00230     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
00231     Created:    18/06/96
00232     Inputs:     DrawPath - the path to render.
00233                 DataOnly - if TRUE, only output the line/curve/moveto data, and not the stroke
00234                             or fill operators.
00235                            if FALSE, just output path normally.  NB. see Purpose
00236     Purpose:    Output all the commands required to render this path to the CMX file.
00237                 If this is a compound path, the stroke/fill operators will always be output,
00238                 regardless of the value of the DataOnly parameter.
00239     SeeAlso:    RenderRegion::DrawPath; CMXRenderRegion::GetValidPathAttributes
00240 
00241 ********************************************************************************************/
00242 
00243 BOOL CMXRenderRegion::ExportPath ( Path *DrawPath, BOOL DataOnly )
00244 {
00245     // Get the device context for our export file.
00246     KernelDC *pDC = (KernelDC*)CCDC::ConvertFromNativeDC(RenderDC);
00247 
00248     DocCoord*   Coords      = DrawPath->GetCoordArray();
00249     PathVerb*   Verbs       = DrawPath->GetVerbArray();
00250     INT32           NumCoords   = DrawPath->GetNumCoords();
00251 
00252     // No need to export a zero length path.
00253     if ( NumCoords != 0 )
00254     {
00255         // There were some points on the path, so attempt to export it.
00256         return cmxDC->WritePath ( Coords, Verbs, NumCoords, DrawPath->IsFilled );
00257     }
00258 
00259     else
00260     {
00261         // Pretend that it worked to prevent any errors from being thrown.
00262         return TRUE;
00263     }
00264 }
00265 
00266 /********************************************************************************************
00267 
00268 >   BOOL CMXRenderRegion::ExportBevel ( NodeBevel *pBevel )
00269 
00270     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00271     Created:    18/2/00
00272     Inputs:     pBevel  - A pointer to a bevel node.
00273     Returns:    TRUE if the node was successfully exported, FALSE if it wasn't.
00274     Purpose:    Contains the custom export code for the bevel node.
00275 
00276 ********************************************************************************************/
00277 
00278 BOOL CMXRenderRegion::ExportBevel ( NodeBevel *pBevel )
00279 {
00280     ColourFillAttribute     *pFill          = ( ColourFillAttribute * ) GetCurrentAttribute
00281                                               ( ATTR_FILLGEOMETRY );
00282     StrokeColourAttribute   *pLine          = ( StrokeColourAttribute * ) GetCurrentAttribute
00283                                               ( ATTR_STROKECOLOUR );
00284     OILBitmap               *pBMP           = NULL;
00285     DocColour               OldColour       ( pLine->Colour );
00286     BitmapFillAttribute     BevFill;
00287     BOOL                    Result          = FALSE;
00288     DocRect                 Bounds          = pBevel->GetBoundingRect ();
00289     RangeControl            ControlFlags    ( TRUE, TRUE );
00290     Range                   ToRender        ( pBevel, pBevel, ControlFlags );
00291     DocColour               Transparent     ( COLOUR_TRANS );
00292     KernelBitmap* pBevelBMP = NULL;
00293 
00294     NodeBevelController* pControl = (NodeBevelController*)pBevel->GetParentController();
00295 
00296     if(pControl)
00297         pBevelBMP = pBevel->CreateBitmapCopy(pControl->GetDPI());
00298     else
00299     {
00300         ERROR2(FALSE,"Failed to find a bevel controller node!");
00301     }
00302 
00303     ERROR2IF(!pBevelBMP,FALSE,"Failed to create a new Export BevelBitmap!");
00304 
00305     // Copy the information over.
00306     BevFill.SimpleCopy ( pBevel->GetBitmapFillAttribute () );
00307 
00308     // Set the line colour to be transparent.
00309     pLine->Colour = Transparent;
00310 
00311     // For some reason, the pBevFill attribute isn't correctly instansiated at this point.
00312     // Thus it's necessary to load up the points describing its position before export is
00313     // attempted. Note: In the Flash export filter, these points are pre-loaded, so there
00314     // must be some weird bug somewhere.
00315     BevFill.SetStartPoint   ( &Bounds.lo );
00316     BevFill.SetEndPoint     ( &DocCoord ( Bounds.hix, Bounds.loy ) );
00317     BevFill.SetEndPoint2    ( &DocCoord ( Bounds.lox, Bounds.hiy ) );
00318     
00319     // Attach the new bitmap to the bevel fill attribute.
00320     BevFill.AttachBitmap ( pBevelBMP );
00321 
00322     // Set up the bevel fill as a standard bitmap fill.
00323     SetFillGeometry ( &BevFill, FALSE );
00324 
00325     // Export the bevel.
00326     Result = ExportPath ( &( pBevel->InkPath ), FALSE );
00327 
00328     // Pop the attribute off the stack.
00329     RestoreFillGeometry ( pFill, FALSE );
00330 
00331     // Restore the line colour.
00332     pLine->Colour = OldColour;
00333 
00334     // Now delete the Copy Bitmap!
00335     delete pBevelBMP;
00336     pBevelBMP = NULL;
00337 
00338     return Result;
00339 }
00340 
00341 /********************************************************************************************
00342 
00343 >   BOOL CMXRenderRegion::ExportBevelBegin ( NodeBevelBegin *pBevel )
00344 
00345     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00346     Created:    21/2/00
00347     Input:      pBevel - A pointer to a NodeBevelBegin object.
00348     Returns:    TRUE if success.
00349     Purpose:    Stub function to prevent NodeBevelBegin from rendering.
00350     SeeAlso:    -
00351 
00352 ********************************************************************************************/
00353 
00354 BOOL CMXRenderRegion::ExportBevelBegin ( NodeBevelBegin *pBevel )
00355 {
00356     return TRUE;
00357 }
00358 
00359 /********************************************************************************************
00360 
00361 >   BOOL CMXRenderRegion::ExportShadow ( OILBitmap  *pBitmap,
00362                                          UINT32     Darkness,
00363                                          DocRect    &Bounds )
00364 
00365     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00366     Created:    18/2/00
00367     Inputs:     pShadow - A pointer to a Shadow node.
00368     Returns:    TRUE if the node was successfully exported, FALSE if it wasn't.
00369     Purpose:    Contains the custom export code for the shadow node.
00370 
00371 ********************************************************************************************/
00372 
00373 BOOL CMXRenderRegion::ExportShadow ( OILBitmap  *pBitmap,
00374                                      UINT32     Darkness,
00375                                      DocRect    &Bounds )
00376 {
00377     // The bitmap export code for CMX in Camelot is a mess, due to it being done at the last
00378     // minute when the last version was shipped. Because of this, the ExportShadow function
00379     // repeats a few lines of code from NodeBitmap::ExportRender.
00380     CMXExportDC             *pDC            = static_cast<CMXExportDC *> ( RenderDC );
00381     ColourFillAttribute     *pFill          = ( ColourFillAttribute * ) GetCurrentAttribute
00382                                               ( ATTR_FILLGEOMETRY );
00383     StrokeColourAttribute   *pLine          = ( StrokeColourAttribute * ) GetCurrentAttribute
00384                                               ( ATTR_STROKECOLOUR );
00385     ADDR                    BitmapAddress   = pBitmap->GetBitmapBits ();
00386     DocColour               ShadowColour    = *( static_cast<FillGeometryAttribute*>
00387                                                 ( GetCurrentAttribute ( ATTR_FILLGEOMETRY ) )
00388                                                 ->GetStartColour () );
00389     DocColour               Background      ( COLOUR_WHITE );   // I don't do backgrounds yet.
00390     DocColour               BlendedShadow   = AlphaBlend ( ShadowColour, Background,
00391                                                            Darkness );
00392     DocCoord                Parallel [4];
00393     StrokeColourAttribute   StartColAttr    ( BlendedShadow );
00394     FlatFillAttribute       EndColAttr;
00395 
00396     // I need to set the line colour (temporarily) to be the start colour, and the fill
00397     // colour to be the end colour. This sets the attributes up for a contone bitmap
00398     // fill.
00399     EndColAttr.SetStartColour ( &Background );
00400 
00401     SetLineColour   ( &StartColAttr, FALSE );
00402     SetFillGeometry ( &EndColAttr, FALSE );
00403 
00404     // Get the rectangle describing the shadow's path.
00405     Parallel [0] = DocCoord ( Bounds.lox, Bounds.hiy );
00406     Parallel [1] = DocCoord ( Bounds.hix, Bounds.hiy );
00407     Parallel [2] = DocCoord ( Bounds.hix, Bounds.loy );
00408     Parallel [3] = DocCoord ( Bounds.lox, Bounds.loy );
00409 
00410     // Quickly knock up a kernel bitmap.
00411     KernelBitmap Bitmap ( pBitmap );
00412 
00413     // And export it.
00414     pDC->WriteBitmap ( &Bitmap, Parallel, CMXExportDC::CMXBITMAPCOLOURSOURCE_LINEANDFILL );
00415 
00416     // Restore the old settings.
00417     RestoreFillGeometry ( pFill, FALSE );
00418     RestoreLineColour   ( pLine, FALSE );
00419 
00420     // It all worked - so return TRUE.
00421     return TRUE;
00422 }
00423 
00424 /********************************************************************************************
00425 
00426 >   virtual void CMXRenderRegion::GetRenderRegionCaps(RRCaps* pCaps)
00427 
00428     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
00429     Created:    18/06/96
00430     Outputs:    pCaps - The details about what types of thing this render region can render
00431     Purpose:    This function allows render regions to admit to what they can and can not
00432                 render. This allows other areas of the program to come in and help render
00433                 regions out in some situations, if they are unable to render everything.
00434                 eg. an OSRenderRegion can not render transparancy.
00435 
00436 ********************************************************************************************/
00437 
00438 void CMXRenderRegion::GetRenderRegionCaps(RRCaps* pCaps)
00439 {
00440     // This forces line attributes - dash patterns and arrow heads to be output
00441     // properly for CMX, rather than using Camelot 'shorthand' tokens.
00442     pCaps->CanDoNothing();
00443     pCaps->ArrowHeads = TRUE;
00444     pCaps->DashPatterns = TRUE;
00445 }
00446 
00447 /********************************************************************************************
00448 
00449 >   virtual BOOL CMXRenderRegion::WantsGrids()
00450 
00451     Author:     Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
00452     Created:    18/06/96
00453     Returns:    FALSE
00454     Purpose:    very little
00455 
00456 ********************************************************************************************/
00457 
00458 BOOL CMXRenderRegion::WantsGrids()
00459 {
00460     return FALSE;
00461 }

Generated on Sat Nov 10 03:44:46 2007 for Camelot by  doxygen 1.4.4