FlashFilter Class Reference

Enables Camelot to export images in the Flash (SWF) file format. More...

#include <swffiltr.h>

Inheritance diagram for FlashFilter:

VectorFilter Filter ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 FlashFilter (void)
 Filter constructor, and initialises the default settings.
BOOL Init (void)
 Initialise the filter (attaches a FlashOILFilter object).
BOOL DoImport (SelOperation *Op, CCLexFile *pFile, Document *DestDoc, BOOL AutoChosen, ImportPosition *Pos, KernelBitmap **ppImportedBitmap, DocCoord *pPosTranslate, String_256 *URL)
 Place holder function for Flash import. Since the filter only exports, a false value is always returned.
BOOL DoExport (Operation *pOp, CCLexFile *pFile, PathName *pPath, Document *TheDocument, BOOL ShowOptions)
 Place holder function for Flash export until real function is done.
BOOL PrepareToExport (CCLexFile *pFile, Spread *pSpread)
virtual BOOL ExportSelectionOnly (BOOL MaskedRender=FALSE)
 Determines if the filter wants to export only selected items.
virtual BOOL ExportVisibleLayersOnly ()
 Determines if the filter wants to export only visible layers. NB. This base class version does the default action of making the filter export everything including hidden layers.

Static Public Member Functions

static DocColour GetPageColour (Spread *pSpread, Node **pBackground)
 Used to get the page colour.

Protected Member Functions

virtual BOOL WriteNodes (RenderRegion *pRegion, ExportDC *pDC, BOOL VisibleLayersOnly, BOOL CheckSelected, BOOL ShowProgress)
 Actually export the nodes to the given render region showing a progress bar as we go. Assumes everything has been set up by ExportRender. Assumes that either a progress bar has been started and will be ended by the caller or that it should start and end the progress bar itself.

Private Member Functions

 CC_DECLARE_DYNAMIC (FlashFilter)
void CleanUpAfterExport (BOOL Success)
LayerState GetButtonState (Node *pNode)
 Tests to see whether the node is part of a roll-over button or not.
BOOL GetButtonName (Node *pNode, String_256 &ButtonName)
 If the node has a template attribute containing the name, this function loads it into the ButtonName string, and returns TRUE indicating that it's been found. Basically it extracts an ID name from a template.

Private Attributes

NodempBackgroundNode
BOOL mOnlySelected
DocColourmpBackgroundCol
DocRect mPageRect

Friends

class FlashRenderCallback

Detailed Description

Enables Camelot to export images in the Flash (SWF) file format.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/08/99
See also:
VectorFilter

Definition at line 115 of file swffiltr.h.


Constructor & Destructor Documentation

FlashFilter::FlashFilter void   ) 
 

Filter constructor, and initialises the default settings.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/8/99
Returns:
Void.

Definition at line 145 of file swffiltr.cpp.

00146 {
00147     // Set up filter descriptions.
00148     FilterName.Load(_R(IDT_FLASH_FILTERNAME));
00149     FilterInfo.Load(_R(IDT_FLASH_FILTERINFO));
00150     FilterID = FILTERID_FLASH;
00151 
00152     ExportMsgID = _R(IDT_EXPORTMSG_FLASH);
00153 
00154     Flags.CanImport = FALSE;
00155     Flags.CanExport = TRUE;
00156 
00157     mpBackgroundNode = NULL;
00158     mpBackgroundCol = NULL;
00159 
00160 #if 0
00161     // No attributes yet
00162     DefLineWidthAttr = NULL;
00163     DefLineColAttr = NULL;
00164     DefFillColAttr = NULL;
00165 #endif
00166 }


Member Function Documentation

FlashFilter::CC_DECLARE_DYNAMIC FlashFilter   )  [private]
 

void FlashFilter::CleanUpAfterExport BOOL  Success  )  [private]
 

Definition at line 328 of file swffiltr.cpp.

00329 {
00330     mpBackgroundNode = NULL;
00331     mpBackgroundCol = NULL;
00332 }

BOOL FlashFilter::DoExport Operation pOp,
CCLexFile pFile,
PathName pPath,
Document pDoc,
BOOL  ShowOptions
[virtual]
 

Place holder function for Flash export until real function is done.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/8/99
Returns:
TRUE if export succeeds, otherwise FALSE.
See also:
DoImport

Reimplemented from Filter.

Definition at line 242 of file swffiltr.cpp.

00247 {
00248     Spread              *pSpread    = GetFirstSpread ( pDoc );          // First spread.
00249     FlashRenderRegion   SWFRegion;                                      // Render region.
00250     FlashExportDC       ExDC        ( this );                           // Export DC.
00251     View                *pView      = (View*) pDoc->GetFirstDocView (); // Use current view.
00252 
00253     // Reset the static variables used to maintain the count of the number of Flash objects
00254     // exported of the various types. Without this, Camelot gets a bit confused, and the
00255     // export doesn't quite work.
00256     FlashPlaceObject::ResetStatics ();
00257     
00258     // Get a reference to the selected nodes.
00259     Range               Selection   ( * ( GetApplication ()->FindSelection () ) );
00260 
00261     // If a selection has been made, only export the selected nodes. This if statement
00262     // sets up the local and global variables for either of the options.
00263     if ( Selection.FindFirst () != NULL )
00264     {
00265         // A selection has been made, so don't render everything in the drawing.
00266         mOnlySelected = TRUE;
00267         mPageRect   = Selection.GetBoundingRect ();
00268     }
00269     else
00270     {
00271         // Export all nodes.
00272         mOnlySelected = FALSE;
00273 
00274         // Use a static method in the bitmap filter to extract the size of the drawing to
00275         // render to the file.
00276         mPageRect = BaseBitmapFilter::GetSizeOfDrawing ( pSpread );
00277     }
00278 
00279     // Get the background colour.
00280 
00281     DocColour BackgroundCol = GetPageColour ( pSpread, &mpBackgroundNode );
00282     mpBackgroundCol = &BackgroundCol;
00283 
00284     // Set up the origin of the bounding rectangle according to the Flash file specification.
00285     DocCoord            Origin      ( mPageRect.lo.x, mPageRect.hi.y );     // Flash's lox, loy.
00286 
00287     // Initialise the render region.
00288     SWFRegion.Init ();
00289     SWFRegion.SetBackgroundColour (BackgroundCol);
00290 
00291     // Create an ExportDC within the render region.
00292     SWFRegion.AttachDevice ( pView, &ExDC, pSpread );
00293 
00294     // Get the position of the first page, and set as origin, and convert to SWF co-ords.
00295     ExDC.SetOrigin ( Origin );
00296 
00297     // Ensure file is open: - If closed, attempt to open it.
00298     //                      - If unopenable, return error.
00299     if ( !pFile->isOpen () )
00300     {
00301         if ( pFile->IsKindOf ( CC_RUNTIME_CLASS ( CCDiskFile ) ) )
00302         {
00303             if ( !OpenExportFile ( ( CCDiskFile* ) pFile, pPath ) )
00304                 return FALSE;
00305         }
00306         else
00307         {
00308             TRACEUSER ( "Graeme", _T("Tried to open non-CCDiskFile in FlashFilter::DoExport\n") );
00309             return FALSE;
00310         }
00311     }
00312 
00313     // Initialise the export DC with the file.
00314     ExDC.Init ( pFile );
00315 
00316     // Export Render the tree using the base Filter class method.
00317     ExportRender ( &SWFRegion );
00318 
00319     // Wrap up the file. Tasks to be done are:
00320     // (1) Write end of frame.
00321     // (2) End the file.
00322     // (3) Go back and plug holes in the header struct. (Size of file.)
00323     ExDC.EndFile ();
00324 
00325     return TRUE;
00326 }

BOOL FlashFilter::DoImport SelOperation Op,
CCLexFile pFile,
Document DestDoc,
BOOL  AutoChosen,
ImportPosition Pos,
KernelBitmap **  ppImportedBitmap,
DocCoord pPosTranslate,
String_256 URL
[virtual]
 

Place holder function for Flash import. Since the filter only exports, a false value is always returned.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/8/99
Returns:
FALSE.
See also:
DoExport

Reimplemented from Filter.

Definition at line 213 of file swffiltr.cpp.

00221 {
00222     // Import operations aren't supported. Therefore return FALSE.
00223     return FALSE;
00224 }

BOOL FlashFilter::ExportSelectionOnly BOOL  MaskedRender = FALSE  )  [virtual]
 

Determines if the filter wants to export only selected items.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/12/99
Returns:
True if this filter wants check if an object is selected or not and so export only the selected items Or False if want to export everything. (The value of mOnlySelected.)
See also:
FlashFilter::ExportRender;

Reimplemented from Filter.

Definition at line 672 of file swffiltr.cpp.

00673 {
00674     // Flash defaults to attempt to export a selection first.
00675     return mOnlySelected;
00676 }

BOOL FlashFilter::ExportVisibleLayersOnly  )  [virtual]
 

Determines if the filter wants to export only visible layers. NB. This base class version does the default action of making the filter export everything including hidden layers.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/11/00
Parameters:
- [INPUTS]
Returns:
TRUE - Only export visible layers. FALSE - Export everything.
See also:
Filter::ExportRender; Filter::VisibleLayersOnly

Reimplemented from Filter.

Definition at line 695 of file swffiltr.cpp.

00696 {
00697     // The Flash filter should ignore hidden layers. Unfortunately the button system uses
00698     // hidden layers for its state, so export them in any case.
00699     return FALSE;
00700 }   

BOOL FlashFilter::GetButtonName Node pNode,
String_256 ButtonName
[private]
 

If the node has a template attribute containing the name, this function loads it into the ButtonName string, and returns TRUE indicating that it's been found. Basically it extracts an ID name from a template.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/1/00
Returns:
True if a button has been found, otherwise false.
See also:
FlashFilter::ExportRenderNodes (), FlashFilter::GetButtonState ()

Definition at line 782 of file swffiltr.cpp.

00784 {
00785     // We have a potential button candidate. Now check to see whether or not
00786     // it has a Templater Attribute node. If it does, get the name of the
00787     // button, and export it using the export DC.
00788     Node        *pChild     = pNode->FindFirstChild ();
00789     BOOL        FoundButton = FALSE;
00790 
00791     // Ensure that the string is empty.
00792     ButtonName.Empty ();
00793 
00794     // Try to find a TemplateAttribte amongst the node's children.
00795     while ( pChild != NULL && !FoundButton )
00796     {
00797         // If one is found, the object is a button.
00798         if ( pChild->IsKindOf ( CC_RUNTIME_CLASS ( TemplateAttribute ) ) )
00799         {
00800             // It's a button! First extract the button's name.
00801             ButtonName = ( ( TemplateAttribute * ) pChild )->GetParam ();
00802 
00803             // Break out of the loop.
00804             FoundButton = TRUE;
00805         }
00806         else
00807         {
00808             // Otherwise parse the next record.
00809             pChild = pChild->FindNext ();
00810         }
00811     }
00812 
00813     // Return whether a button has been found.
00814     return FoundButton;
00815 }

LayerState FlashFilter::GetButtonState Node pNode  )  [private]
 

Tests to see whether the node is part of a roll-over button or not.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/1/00
Returns:
LayerState - The layer on which this node resides, or NO_BUTTON if it's on a regular layer.
See also:
FlashFilter::ExportRenderNodes

Definition at line 715 of file swffiltr.cpp.

00716 {
00717     // This function catches button codes, which are inconveniently scattered
00718     // throughout the tree, and uses this information to rebuild the list of nodes to
00719     // export into the correct form for buttons.
00720     Node        *pParent    = pNode->FindParent ();
00721     LayerState  ThisLayer   = NO_BUTTON;
00722 
00723     // Browse up the tree until we either find a layer node, or run out of tree.
00724     while ( pParent != NULL )
00725     {
00726         if ( pParent->IsLayer () )
00727         {
00728             // Extract the layer's name...
00729             String_256  LayerName   = ( ( Layer* ) pParent )->GetLayerID ();
00730 
00731             // ... set up comparison strings...
00732             String_256  Clicked ( _R(IDS_ROLLOVER_CLICKED) );       // = "Clicked"
00733             String_256  Default ( _R(IDS_ROLLOVER_DEFAULT) );       // = "Default"
00734             String_256  Mouse ( _R(IDS_ROLLOVER_MOUSE) );           // = "Mouse"
00735             String_256  Selected ( _R(IDS_ROLLOVER_SELECTED) );     // = "Selected"
00736 
00737             // ... and use these to identify whether it's a button layer, and what part
00738             // of the button it forms.
00739             if ( LayerName.IsIdentical ( Clicked ) )
00740             {
00741                 ThisLayer = CLICKED;
00742             }
00743             else if ( LayerName.IsIdentical ( Default ) )
00744             {
00745                 ThisLayer = DEFAULT;
00746             }
00747             else if ( LayerName.IsIdentical ( Mouse ) )
00748             {
00749                 ThisLayer = MOUSE;
00750             }
00751             else if ( LayerName.IsIdentical ( Selected ) )
00752             {
00753                 ThisLayer = SELECTED;
00754             }
00755 
00756             // Break out of the while loop.
00757             break;
00758         }
00759 
00760         // If it's not a layer, grab the next node and continue.
00761         pParent = pParent->FindParent ();
00762     }
00763 
00764     return ThisLayer;
00765 }

DocColour FlashFilter::GetPageColour Spread pSpread,
Node **  pBackground
[static]
 

Used to get the page colour.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/08/99
Parameters:
pSpread - Pointer to the current spread. [INPUTS]
Returns:
DocColour - the colour of the page background.

Errors: -

See also:
Page::GetPageColour()

Definition at line 349 of file swffiltr.cpp.

00351 {
00352     // Calculate the background colour
00353     DocColour dcol ( COLOUR_WHITE );        // Default to white.
00354     *pBackground = NULL;
00355 
00356     Layer *pLayer = pSpread->FindFirstPageBackgroundLayer();
00357     if (pLayer)
00358     {
00359         Node * pNode = pLayer->FindFirstChild();
00360         while (pNode && !pNode->IsLayer())
00361         {
00362             if (!pNode->IsNodeHidden())
00363             {
00364                 if (pNode->IsARegularShape())
00365                 {
00366                     Node *pAttrNode = pNode->FindFirstChild();
00367                     if ( pAttrNode && pAttrNode->IsAnAttribute()
00368                          && pAttrNode->IsKindOf(CC_RUNTIME_CLASS(AttrFlatFill)))
00369                     {
00370                         dcol = *(((AttrFlatFill *)pAttrNode)->GetStartColour());
00371                         *pBackground = pNode;
00372                     }
00373                 }
00374             }
00375             pNode = pNode->FindNext();
00376         }
00377     }
00378 
00379     return dcol;
00380 }

BOOL FlashFilter::Init void   )  [virtual]
 

Initialise the filter (attaches a FlashOILFilter object).

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/8/99
Returns:
TRUE if Filter initialised, otherwise FALSE.
See also:
FlashOILFilter

Implements Filter.

Definition at line 180 of file swffiltr.cpp.

00181 {
00182     // Get the OILFilter object
00183     pOILFilter = new FlashOILFilter(this);
00184     if (pOILFilter == NULL)
00185         return FALSE;
00186 
00187     mOnlySelected = FALSE;
00188 
00189     // All ok
00190     return TRUE;
00191 }

BOOL FlashFilter::PrepareToExport CCLexFile pFile,
Spread pSpread
 

BOOL FlashFilter::WriteNodes RenderRegion pRegion,
ExportDC pDC,
BOOL  VisibleLayersOnly,
BOOL  CheckSelected,
BOOL  ShowProgress
[protected, virtual]
 

Actually export the nodes to the given render region showing a progress bar as we go. Assumes everything has been set up by ExportRender. Assumes that either a progress bar has been started and will be ended by the caller or that it should start and end the progress bar itself.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com> (from Neville's original code)
Date:
12/4/00
Parameters:
pRegion - the render region to export to. [INPUTS] pDc - device context to use, can be NULL. VisibleLayersOnly - use visible layers or not ShowProgress - TRUE then start up a progress bar or FALSE assume the caller has done it.
Returns:
TRUE if the export process completed successfully, FALSE if an error occured.
See also:
Filter::ExportRender, Filter::ExportRenderNodes

Reimplemented from Filter.

Definition at line 405 of file swffiltr.cpp.

00410 {
00411     // Loop through the tree as usual.
00412     // while ( Nodes Left to Export )
00413 
00414     // if ( Node is a TextStory )
00415     // Create a text record.
00416     // Create a font record if that font hasn't been defined yet.
00417     // Create a place object tag.
00418 
00419     // else
00420     // Create a path record.
00421     // If the path is identical to a previous path, don't store it.
00422     // If the fill is a bitmap fill, make a bitmap record.
00423     // Write a place object tag out.
00424 
00425 #ifdef DO_EXPORT
00426 
00427     // Export the file, but catch any file errors.
00428     try
00429     {
00430         // This function parses through the Camelot tree in common with the other export
00431         // loops. Unlike the other loops, it builds up four linked lists as dictionaries
00432         // of shapes, fonts, and bitmaps, which are then rendered into a file by the
00433         // ExportAll () call at the end of the loop.
00434 
00435         // Future work: Add functions to compare strings and paths to ensure that repeated
00436         // objects or strings are stored once, and invoked several times, rather than
00437         // writing multiple instances to the file.
00438 
00439         // Create a FlashRenderRegion and FlashExportDC pointers by casting the stock ones.
00440         FlashExportDC       *pFDC   = ( FlashExportDC* ) CCDC::ConvertFromNativeDC(pRegion->GetRenderDC ());
00441         FlashRenderRegion   *pFRR   = ( FlashRenderRegion* ) pRegion;
00442 
00443         // Find the first node that we should export from this spread
00444         Spread *pSpread = pRegion->GetRenderSpread ();
00445 /*
00446         Node *pLayer = ( Node * ) pSpread->FindFirstLayer ();
00447         Node *pNode = pSpread->FindFirstForExport( pRegion, TRUE, VisibleLayersOnly, CheckSelected );
00448 
00449         if ( mpBackground != NULL && pNode == mpBackground )
00450         {
00451             // Move onto the next node.
00452             pNode = pNode->FindNextForExport( pRegion, TRUE, VisibleLayersOnly, CheckSelected );
00453         }
00454 
00455         // Create file header, and write it.
00456         pFDC->CreateHeader ( mBackground, mPageRect );
00457 
00458         while ( pNode != NULL )
00459         {
00460             // Declare variables.
00461             LayerState  ThisLayer   = GetButtonState ( pNode );
00462             String_256  ButtonName;
00463 
00464             // Limit the progress display to legal values.
00465             if ( pNode->IsNodeRenderableClass() )
00466             {
00467                 CurrentProgressLimit = NumNodes + ( ( NodeRenderable * ) pNode )
00468                                         -> GetSizeOfExport ( this );
00469             }
00470 
00471             // Set the layer state.
00472             pFRR->SetLayerState ( ThisLayer );
00473 
00474             // Get the layer ID, so that we can tell if it's a button or not.
00475             if ( ThisLayer != NO_BUTTON && GetButtonName ( pNode, ButtonName ) )
00476             {
00477                 // The name has been successfully extracted, and is passed into the render
00478                 // region.
00479                 pFRR->SetButtonName ( ( TCHAR* ) ButtonName );
00480             }
00481             else
00482             {
00483                 // A NULL pointer in this function instructs the RenderRegion to treat the
00484                 // next node as an ordinary shape, rather than a button.
00485                 pFRR->SetButtonName ( NULL );
00486             }
00487 
00488             // Attempt to render the node using custom export code.
00489             if ( !pNode->ExportRender ( pRegion ) )
00490             {
00491                 // No special export rendering - just use the normal rendering
00492                 pNode->Render ( pRegion );      
00493             }
00494 
00495             NumNodes = CurrentProgressLimit;        // Update progress counter.
00496 
00497             if ( NumNodes > ( LastExportProgressUpdate + UpdateEvery ) )
00498             {
00499                 LastExportProgressUpdate = NumNodes;
00500 
00501                 // If we are rendering in strips then we need to add an offset to
00502                 // the position of the progress bar.
00503                 if ( !ContinueSlowJob ( ProgressOffset + NumNodes ) )
00504                 {
00505                     // Error; close down and exit nicely.
00506                     // Must set an error otherwise we will get the dreaded reporting error
00507                     // when none set message.
00508                     // If no error message ID set in this filter then use default
00509                     if ( StopExportMsgID == 0 )
00510                         Error::SetError ( _R(IDW_CANCELEXPORT) );
00511                     else
00512                         Error::SetError ( StopExportMsgID );
00513                     pRegion->StopRender ();
00514                     if ( ShowProgress )
00515                         EndSlowJob ();
00516                     return FALSE;
00517                 }
00518             }
00519 
00520             // Find another one to export
00521             pNode = pNode->FindNextForExport ( pRegion, TRUE, VisibleLayersOnly,
00522                                                CheckSelected );
00523 
00524             if ( mpBackground != NULL && pNode == mpBackground )
00525             {
00526                 // Move onto the next node.
00527                 pNode = pNode->FindNextForExport ( pRegion, TRUE, VisibleLayersOnly,
00528                                                    CheckSelected );
00529             }
00530         }
00531 */
00532         // Create file header, and write it.
00533         pFDC->CreateHeader(*mpBackgroundCol, mPageRect);
00534 
00535         FlashRenderCallback MyCallback(this, pFRR, VisibleLayersOnly, CheckSelected, mpBackgroundNode);
00536         pRegion->RenderTree(pSpread, FALSE, FALSE, &MyCallback);
00537 
00538         // Call the main export function.
00539         pFRR->ExportAll ();
00540     }
00541 
00542     // Handle any file errors, or other exceptions.
00543     catch ( CFileException )
00544     {
00545         // Didn't work - report failure to caller.
00546         if ( pDC )
00547             pDC->ExportFile->SetThrowExceptions ( FALSE );
00548         pRegion->StopRender ();
00549         if ( ShowProgress )
00550             EndSlowJob ();
00551         return FALSE;
00552     }
00553 
00554     // All ok
00555     return TRUE;
00556 #else
00557     return FALSE;
00558 #endif
00559 }


Friends And Related Function Documentation

friend class FlashRenderCallback [friend]
 

Definition at line 117 of file swffiltr.h.


Member Data Documentation

BOOL FlashFilter::mOnlySelected [private]
 

Definition at line 168 of file swffiltr.h.

DocRect FlashFilter::mPageRect [private]
 

Definition at line 170 of file swffiltr.h.

DocColour* FlashFilter::mpBackgroundCol [private]
 

Definition at line 169 of file swffiltr.h.

Node* FlashFilter::mpBackgroundNode [private]
 

Definition at line 167 of file swffiltr.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:54:23 2007 for Camelot by  doxygen 1.4.4