FlashRenderRegion Class Reference

Provides the necessary functions to convert image data stored in the Camelot tree into the correct values for exporting to the Flash 4 format, and output these to the relevant device context. More...

#include <swfrndr.h>

Inheritance diagram for FlashRenderRegion:

VectorFileRenderRegion RenderRegion ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 FlashRenderRegion (void)
 Constructor for the FlashRenderRegion class.
 FlashRenderRegion (DocRect ClipRect, Matrix ConvertMatrix, FIXED16 ViewScale)
 Constructor for the FlashRenderRegion class.
 ~FlashRenderRegion (void)
 Destructor for the FlashRenderRegion class.
BOOL ExportCharacter (TextChar *pTheLetter)
 Adds the character into the two lists that maintain the strings to be exported to a Flash file.
BOOL ExportBevel (NodeBevel *pBevel)
 Creates a shape record for the bevel's path, and a bitmap fill to do the bevel. It can currently only accurately reproduce bevels with flat fills, since Flash's support of transparent bitmaps is broken at the moment.
BOOL ExportBevelBegin (NodeBevelBegin *pBevel)
 Stub function to prevent NodeBevelBegin from rendering.
BOOL ExportShadow (Path *pShadowPath, OILBitmap *pBitmap, UINT32 Darkness)
 Creates a shape record for a shadow, and stores it inside the Flash file.
BOOL ExportRenderableNode (NodeRenderableInk *pInk)
 Renders a stroked path to the file.
BOOL ExportAll (void)
 Most of the functions within the FlashRenderRegion class are used to create and populate a series of linked lists which contain a processed version of the Camelot tree. This function passes all of these lists to the Render DC, so that they can be outputted to a file, and then cleans up the objects to prevent any memory leaks.
void SetButtonName (TCHAR *pButtonName)
 Sets the name of the current button being exported. If the object being exported doesn't have this attribute, the string is cleared to prevent problems with old button names persisting.
void SetLayerState (LayerState State)
 Sets the value to mButtonState to be State. This is used to determine which of the roll-over states of a button and which object should be used.

Protected Member Functions

void DrawPathToOutputDevice (Path *PathToRender, PathShape shapePath=PATHSHAPE_PATH)
 Outputs a path to the device context.
void InitPointers (void)
 Initialises all pointer values to NULL.
BOOL ProcessPath (Path *pPath)
 Writes all the path attributes to a Flash shape record object, in preparation for storing it in the file.
BOOL ProcessFill (FillGeometryAttribute *pFill, TranspFillAttribute *pTransparency)
BOOL ProcessColour (FillGeometryAttribute *pFill)
 Processes the FillGeometryAttribute of a shape, and fills in the correct fill attributes into the FlashShapeRecord referenced by mpShapeTail.
BOOL ProcessTransparency (TranspFillAttribute *pTransparency, FillGeometryAttribute *pFill)
 Processes the TranspFillAttribute of a shape, and fills in the correct fill attributes into the FlashShapeRecord referenced by mpShapeTail.
BOOL CreateTextRecord (TextChar *pTheLetter)
 Creates a new FlashTextRecord, which is used to store a text character.
BOOL ProcessFlatFill (DocColour *pColour)
 Processes a flat fill, and writes the correct values to the file record.
BOOL ProcessGradientFill (DocColour *pStartColour, DocColour *pMidColour, DocColour *pEndColour, ColourRamp *pRamp, DocCoord *pStartPoint, DocCoord *pEndPoint, DocCoord *pEndPoint2, BYTE FillType)
 Processes a gradient fill, and writes the correct values to the file record.
BOOL ProcessBitmapFill (FillGeometryAttribute *pFill)
 Processes a bitmap fill, and writes the correct values to the file record.
BOOL RecordBitmapFill (BitmapFillAttribute *pFill, WORD BitmapID)
 Records the details of a bitmap fill into a shape record, so that it can be stored within a Flash file.
WORD GetBitmapID (OILBitmap *pBitmap, DocColour *pStartColour, DocColour *pEndColour, UINT32 Transparency)
 Spools through the list of bitmaps, and returns the appropriate bitmap reference. Note: Bevel bitmaps are treated as being contoned, though the process by which their palette is generated is slightly different.
BOOL ProcessFlatTransp (UINT32 Transparency)
 Processes a flat transparency, and writes the correct values to the file record.
BOOL ProcessGradientTransp (UINT32 *pStartTransparency, UINT32 *pMidTransparency, UINT32 *pEndTransparency, DocCoord *pStartPoint, DocCoord *pEndPoint, DocCoord *pEndPoint2, BYTE FillType)
 Processes a gradient transparency, and writes the correct values to the file record.
BOOL ProcessBitmapTransp (TranspFillAttribute *pTransparency, FillGeometryAttribute *pFill)
 Processes a bitmap fill, and writes the correct values to the file record. There were problems with Flash 4 to do with rendering transparent bitmaps, and so this was removed. Flash 5 seems to have cured them, and so this function has ben re-instated.
UINT32 BlendTransparencies (UINT32 *pStart, UINT32 *pEnd1, UINT32 *pEnd2, UINT32 *pEnd3)
 Calculates the average value for the transparency of a shape.
DocColour BlendColours (DocColour *pStart, DocColour *pEnd1, DocColour *pEnd2, DocColour *pEnd3, ColourRamp *pRamp)
 Calculates the average value for the fill colour of a shape, along with the contents of any colour ramp.
FlashButtonRecordProcessURL (WebAddressAttribute *pWebAddress)
 Processes a WebAddressAttribute, and stores the details in a FlashButtonRecord for processing in the Export DC.
BOOL ExportButtonState (FlashButtonRecord *pButton)
 This method is part of the button rollover support that is being added to the Flash export filter. Due to the way that the render region has been implemented, and the fact that I've been asked to do this after writing virtually all of the filter code, it's algorithm is a little strange.
FlashButtonRecordMatchButton (void)
 Spools through the list of button records (pointed to by mpButton), and attempts to match the sprite with the input parameters. If no match is made, a new button record is created, and populated with the correct values.
FlashSpriteMatchSprite (FlashButtonRecord *pButton)
 Spools through the list of sprite records (pointed to by mpSprite), and attempts to match the sprite with the input parameters. If no match is made, a new sprite record is created, and populated with the correct name and LayerState.
BOOL PlaceObject (WORD ID, FlashType ToRender, DocCoord *pPosition=NULL, BOOL DoTransform=FALSE)
 Creates a FlashPlaceObject record for the object with the corresponding ID.

Protected Attributes

FlashBitmapRecordmpBitmap
FlashBitmapRecordmpBitmapTail
FlashTextRecordmpText
FlashTextRecordmpTextTail
FlashFontRecordmpFont
FlashFontRecordmpFontTail
FlashShapeRecordmpShape
FlashShapeRecordmpShapeTail
FlashShapeRecordmpShapeLast
FlashButtonRecordmpButton
FlashButtonRecordmpButtonTail
FlashSpritempSprite
FlashSpritempSpriteTail
FlashPlaceObjectmpPlace
FlashPlaceObjectmpPlaceTail
String_256 mButtonName
LayerState mButtonState
BOOL mSupressLines
BOOL mExportStroke

Detailed Description

Provides the necessary functions to convert image data stored in the Camelot tree into the correct values for exporting to the Flash 4 format, and output these to the relevant device context.

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

Definition at line 234 of file swfrndr.h.


Constructor & Destructor Documentation

FlashRenderRegion::FlashRenderRegion void   ) 
 

Constructor for the FlashRenderRegion class.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/99
See also:
FlashFilter::Init

Definition at line 142 of file swfrndr.cpp.

00142                                             :
00143 VectorFileRenderRegion ()
00144 {
00145     // Ensure that member variable pointers are set to NULL.
00146     InitPointers ();
00147 }

FlashRenderRegion::FlashRenderRegion DocRect  ClipRect,
Matrix  ConvertMatrix,
FIXED16  ViewScale
 

Constructor for the FlashRenderRegion class.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/99
See also:
FlashFilter::Init

Definition at line 162 of file swfrndr.cpp.

00164                                                            :
00165 VectorFileRenderRegion ( ClipRect, ConvertMatrix, ViewScale )
00166 {
00167     // Ensure that member variable pointers are set to NULL.
00168     InitPointers ();
00169 }

FlashRenderRegion::~FlashRenderRegion void   ) 
 

Destructor for the FlashRenderRegion class.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/8/99
See also:
-

Definition at line 182 of file swfrndr.cpp.

00183 {
00184     // Insert clean up code here!
00185     if(mpFont)
00186     {
00187         delete mpFont;
00188         mpFont = NULL;
00189     }
00190 
00191     InitPointers ();
00192 }


Member Function Documentation

DocColour FlashRenderRegion::BlendColours DocColour pStart,
DocColour pEnd1,
DocColour pEnd2,
DocColour pEnd3,
ColourRamp pRamp
[protected]
 

Calculates the average value for the fill colour of a shape, along with the contents of any colour ramp.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/12/99
Returns:
The average value of pStart, pEnd1, pEnd2, and pEnd3.
See also:
FlashRenderRegion::ProcessTransparency ()

Definition at line 2018 of file swfrndr.cpp.

02023 {
02024     // Declare and initialise the local variables.
02025     DocColour   Result;
02026     INT32       TotalRed    = 0;
02027     INT32       TotalGreen  = 0;
02028     INT32       TotalBlue   = 0;
02029     INT32       Count       = 1;
02030     INT32       Red, Green, Blue;
02031 
02032     // Extract the colours from the DocColour.
02033     if ( pStart != NULL )
02034     {
02035         pStart->GetRGBValue ( &TotalRed, &TotalGreen, &TotalBlue );
02036     }
02037 
02038     // I've nested the following if statements for efficiency, since (e.g.) if pEnd1 is
02039     // NULL, pEnd2 and pEnd3 will also be NULL.
02040     if ( pEnd1 != NULL )
02041     {
02042         // Extract the colours from the DocColour.
02043         pEnd1->GetRGBValue ( &Red, &Green, &Blue );
02044 
02045         TotalRed    += Red;
02046         TotalGreen  += Green;
02047         TotalBlue   += Blue;
02048         Count ++;
02049 
02050         // Call the second if, for pEnd2.
02051         if ( pEnd2 != NULL )
02052         {
02053             // Extract the colours from the DocColour.
02054             pEnd2->GetRGBValue ( &Red, &Green, &Blue );
02055 
02056             TotalRed    += Red;
02057             TotalGreen  += Green;
02058             TotalBlue   += Blue;
02059             Count ++;
02060 
02061             // And finally for pEnd3.
02062             if ( pEnd3 != NULL )
02063             {
02064                 // Extract the colours from the DocColour.
02065                 pEnd3->GetRGBValue ( &Red, &Green, &Blue );
02066 
02067                 TotalRed    += Red;
02068                 TotalGreen  += Green;
02069                 TotalBlue   += Blue;
02070                 Count ++;
02071             }
02072         }
02073     }
02074 
02075     // Process the colour ramp.
02076     if ( pRamp != NULL )
02077     {
02078         ColRampItem *pColour = pRamp->GetFirstCol ();
02079 
02080         // Write in the ramp's colour values.
02081         while ( pColour != NULL )
02082         {
02083             // Get the position of the colour in the fill.
02084             DocColour   RampColour  = pColour->GetColour ();
02085 
02086             // Extract the colour.
02087             RampColour.GetRGBValue ( &Red, &Green, &Blue );
02088 
02089             TotalRed    += Red;
02090             TotalGreen  += Green;
02091             TotalBlue   += Blue;
02092             Count ++;
02093 
02094             // Increment the pointer onto the next item.
02095             pColour = pRamp->GetNextCol ( pColour );
02096         }
02097     }
02098 
02099     // Divide the Total* values by Count to get the average colour.
02100     TotalRed    /= Count;
02101     TotalGreen  /= Count;
02102     TotalBlue   /= Count;
02103 
02104     Result.SetRGBValue ( TotalRed, TotalGreen, TotalBlue );
02105 
02106     return Result;
02107 }

UINT32 FlashRenderRegion::BlendTransparencies UINT32 pStart,
UINT32 pEnd1,
UINT32 pEnd2,
UINT32 pEnd3
[protected]
 

Calculates the average value for the transparency of a shape.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/12/99
Returns:
The average value of pStart, pEnd1, pEnd2, and pEnd3.
See also:
FlashRenderRegion::ProcessTransparency ()

Definition at line 1964 of file swfrndr.cpp.

01968 {
01969     // Declare and initialise the local variables.
01970     UINT32 Result   = *pStart;
01971     UINT32 Count    = 1;
01972 
01973     // I've nested the following if statements for efficiency, since (e.g.) if pEnd1 is
01974     // NULL, pEnd2 and pEnd3 will also be NULL.
01975     if ( pEnd1 != NULL )
01976     {
01977         Result += *pEnd1;
01978         Count ++;
01979 
01980         // Call the second if, for pEnd2.
01981         if ( pEnd2 != NULL )
01982         {
01983             Result += *pEnd2;
01984             Count ++;
01985 
01986             // And finally for pEnd3.
01987             if ( pEnd3 != NULL )
01988             {
01989                 Result += *pEnd3;
01990                 Count ++;
01991             }
01992         }
01993     }
01994 
01995     // Divide Result by Count to get the average transparency.
01996     Result /= Count;
01997 
01998     return Result;
01999 }

BOOL FlashRenderRegion::CreateTextRecord TextChar pTheLetter  )  [protected]
 

Creates a new FlashTextRecord, which is used to store a text character.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/11/99
Returns:
TRUE if success.
See also:
FlashRenderRegion::ExportCharacter ()

Definition at line 1180 of file swfrndr.cpp.

01181 {
01182     // Define local variables.
01183     TextLine                *pTextLine      = pTheLetter->FindParentLine ();
01184     DocRect                 Bounds          = pTextLine->GetBoundingRect ();
01185     WORD                    ID              = FlashPlaceObject::GetTextCount ();
01186     FlashType               ToRender        = FLASH_TEXT;
01187     WebAddressAttribute     *pWebAddress    = ( WebAddressAttribute * ) GetCurrentAttribute
01188                                               ( ATTR_WEBADDRESS );
01189     FlashButtonRecord       *pButton        = NULL;
01190     Matrix                  TextMatrix;
01191     FIXED16                 MatrixValues [4];
01192     INT32                   Translate [2];
01193     DocCoord                LowCorner;
01194 
01195     // If no text records, create one.
01196     if ( mpText == NULL )
01197     {
01198         mpText = new FlashTextRecord;
01199         ASSERT ( mpText != NULL );
01200         mpTextTail = mpText;
01201     }
01202     else
01203     {
01204         // mpTextTail points at the tail of the list.
01205         mpTextTail = mpTextTail->AddElement ();
01206         ASSERT ( mpTextTail != NULL );
01207     }
01208 
01209     // Set ID.
01210     mpTextTail->SetTextID ( FlashPlaceObject::GetTextCount () );
01211 
01212     // Set aspect ratio.
01213     mpTextTail->SetAspect ( ( ( TxtAspectRatioAttribute* ) GetCurrentAttribute
01214                             ( ATTR_TXTASPECTRATIO ) )->AspectRatio );
01215 
01216     // Set the bounding box.
01217     mpTextTail->SetBounds ( Bounds );
01218 
01219     // Get the text story matrix...
01220     pTheLetter->GetStoryAndCharMatrix ( &TextMatrix );
01221     TextMatrix.GetComponents ( MatrixValues, Translate );
01222 
01223     // ... and store it.
01224     mpTextTail->SetScaleX ( MatrixValues [0].GetRawLong () );
01225     mpTextTail->SetScaleY ( MatrixValues [3].GetRawLong () );
01226     mpTextTail->SetSkewX  ( MatrixValues [1].GetRawLong () );
01227     mpTextTail->SetSkewY  ( MatrixValues [2].GetRawLong () );
01228 
01229     // Record the text's web address.
01230     pButton = ProcessURL ( pWebAddress );
01231 
01232     // Add a PlaceObject record.
01233     LowCorner.x = Translate [0];                    // Calculate the x position.
01234     LowCorner.y = Translate [1];                    // And also the y position.
01235 
01236     PlaceObject ( ID, ToRender, &LowCorner, TRUE ); // Then create the FlashPlaceObject.
01237 
01238     // Export any button states that might have been created.
01239     ExportButtonState ( pButton );
01240 
01241     return TRUE;
01242 }

void FlashRenderRegion::DrawPathToOutputDevice Path PathToRender,
PathShape  shapePath = PATHSHAPE_PATH
[protected, virtual]
 

Outputs a path to the device context.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/9/99
Returns:
Void
See also:
RenderRegion::InitDevice

Implements RenderRegion.

Definition at line 207 of file swfrndr.cpp.

00209 {
00210     // Step 1:  Define, and set up all the local variables.
00211     FlashButtonRecord       *pButton        = NULL;
00212     DocRect                 Bounds;
00213     DocCoord                LowCorner;
00214     WebAddressAttribute     *pWebAddress    = ( WebAddressAttribute * ) GetCurrentAttribute
00215                                               ( ATTR_WEBADDRESS );
00216 
00217     // Step 2:  Initialise the path, and use the clipping routines to re-order the path to
00218     //          wind in the correct manner for the Flash editing tools to understand. Though
00219     //          the player operates with an even-odd winding rule, the editing tools don't,
00220     //          so this operations is necessary.
00221 
00222     // We only clip if the path is closed, otherwise rendering artefacts occur.
00223     if ( PathToRender->IsClosed () )
00224     {
00225         // Declare a path for storing the clipped path in.
00226         Path ClippedPath;
00227 
00228         // Initialise the path before using it.
00229         ClippedPath.Initialise ( PathToRender->GetNumCoords () );
00230 
00231         // Set up the path to point in the right direction using ClipPathToPath.
00232         ClippedPath.ClipPathToPath ( *PathToRender, &ClippedPath, 3, 20 );
00233 
00234         // Store the path.
00235         ProcessPath ( &ClippedPath );
00236     }
00237 
00238     else
00239     {
00240         // Store the path.
00241         ProcessPath ( PathToRender );
00242     }
00243 
00244     // Step 3:  If the shape has a web address, create a FlashButtonRecord, and add the
00245     //          shape's ID number to this instead. Because exporting button states can
00246     //          alter the list of FlashPlaceObjects, it is necessary to create any buttons
00247     //          here.
00248     pButton = ProcessURL ( pWebAddress );
00249 
00250     // Step 4:  Add a FlashPlaceObject record.
00251 
00252     // Set up the position for the place object record...
00253     Bounds = mpShapeTail->GetBoundingBox ();
00254     LowCorner.x = Bounds.lo.x;
00255     LowCorner.y = Bounds.hi.y;
00256 
00257     // ... and create it.
00258     PlaceObject ( FlashPlaceObject::GetShapeCount (), FLASH_SHAPE, &LowCorner, TRUE );
00259 
00260     // Step 5:  Export any button states that have been created.
00261     ExportButtonState ( pButton );
00262 }

BOOL FlashRenderRegion::ExportAll void   ) 
 

Most of the functions within the FlashRenderRegion class are used to create and populate a series of linked lists which contain a processed version of the Camelot tree. This function passes all of these lists to the Render DC, so that they can be outputted to a file, and then cleans up the objects to prevent any memory leaks.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/10/99 Input: -
Returns:
TRUE if success.
See also:
-

Definition at line 959 of file swfrndr.cpp.

00960 {
00961     // These functions all depend on the objects used by the linked list having the pointer
00962     // to the next instance being initialised to NULL when they are created. If this isn't
00963     // done, this function will throw an error, since the code will attempt to access
00964     // uncreated objects.
00965     
00966     // (ChrisG 18/1/01) Added an error box to warn if a shape is detected that's too big to 
00967     //  render properly when imported into Flash/Internet Browsers, etc...
00968     BOOL invalidSizeFound = FALSE;
00969 
00970     // Step 1:  Get a device context to the Flash file.
00971     FlashExportDC *pFlashDC = ( FlashExportDC * ) CCDC::ConvertFromNativeDC(RenderRegion::GetRenderDC());
00972 
00973     TRACEUSER( "Graeme", _T("Entering ExportAll!\n") );
00974     FlashBitmapRecord *pLastBitmap = NULL;
00975 
00976     // Step 2:  Delete the bitmap records.
00977     while ( mpBitmap != NULL )
00978     {
00979         // The bitmap records have already been exported, so just delete the list.
00980         pLastBitmap = mpBitmap;
00981         mpBitmap = mpBitmap->GetNext();
00982 
00983         // (ChrisG 4/1/01) - These two calls have been removed, as they cause access violations
00984         //  with temporary bitmaps (e.g. in blends), as the bitmaps have already been deleted.
00985 //      pLastBitmap->GetBitmap()->DestroyContonePalette();
00986 //      pLastBitmap->GetBitmap()->DestroyGreyscaleVersion();
00987         delete pLastBitmap;
00988     }
00989 
00990     FlashFontRecord *pLastFont = NULL;
00991 
00992     // Step 3:  Export and delete the font records.
00993     while ( mpFont != NULL )
00994     {
00995         pLastFont = mpFont;
00996 
00997         // Write out the font definitions to the file.
00998         pFlashDC->WriteDefineFont ( mpFont );
00999 
01000         mpFont = mpFont->GetNext ();
01001         delete pLastFont;
01002     }
01003 
01004     FlashTextRecord *pLastText = NULL;
01005 
01006     // Step 4:  Export and delete the text string records.
01007     while ( mpText != NULL )
01008     {
01009         pLastText = mpText;
01010 
01011         // Write out the text strings to the file.
01012         pFlashDC->WriteText ( mpText );
01013 
01014         mpText = mpText->GetNext ();
01015         delete pLastText;
01016     }
01017 
01018     // Step 5:  Export and delete the shape records.
01019     while ( mpShape != NULL )
01020     {
01021         FlashShapeRecord *pLastShape = mpShape;
01022 
01023         // Write out the shapes.
01024         pFlashDC->WritePath ( mpShape );
01025 
01026         // (ChrisG 18/1/01) Check to see whether the shape's size is valid
01027         if (pLastShape->WasInvalidSizeFound () == TRUE)
01028         {
01029             invalidSizeFound = TRUE;
01030         }
01031 
01032         mpShape = mpShape->GetNext ();
01033         delete pLastShape;
01034     }
01035 
01036     // Step 6:  Export and delete the sprite records.
01037     while ( mpSprite != NULL )
01038     {
01039         FlashSprite *pLastSprite = mpSprite;
01040 
01041         // Write out the sprites.
01042         pFlashDC->ProcessSprite ( mpSprite, mpButton );
01043 
01044         mpSprite = mpSprite->GetNext ();
01045         delete pLastSprite;
01046     }
01047 
01048     // Step 7:  Export and delete the button records.
01049     while ( mpButton != NULL )
01050     {
01051         FlashButtonRecord *pLastButton = mpButton;
01052 
01053         // Write out the buttons.
01054         pFlashDC->WriteURLScript ( mpButton );
01055 
01056         mpButton = mpButton->GetNext ();
01057         delete pLastButton;
01058     }
01059 
01060     // Step 8:  Export and delete the place object classes.
01061     while ( mpPlace != NULL )
01062     {
01063         FlashPlaceObject *pLastPlace = mpPlace;
01064 
01065         // Write out the place object tags.
01066         pFlashDC->WritePlaceObject ( mpPlace );
01067 
01068         mpPlace = mpPlace->GetNext ();
01069         delete pLastPlace;
01070     }
01071 
01072     // Step 9:  Reset all pointer values.
01073     InitPointers ();
01074 
01075     // Warn of any invalid shapes that were detected.
01076     if (invalidSizeFound == TRUE)
01077     {
01078         // Display error message.
01079         String_256 WarnMsg;
01080 
01081         WarnMsg.MakeMsg(_R(IDT_FLASH_INVALID_SIZE_WARNING));
01082         Error::SetError(0, WarnMsg, 0);
01083     }
01084 
01085     return TRUE;
01086 }

BOOL FlashRenderRegion::ExportBevel NodeBevel pBevel  ) 
 

Creates a shape record for the bevel's path, and a bitmap fill to do the bevel. It can currently only accurately reproduce bevels with flat fills, since Flash's support of transparent bitmaps is broken at the moment.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/12/99 Input: pBevel - A pointer to a NodeBevel object.
Returns:
TRUE if success.
See also:
-

Definition at line 647 of file swfrndr.cpp.

00648 {
00649     // Set up the range control flags.
00650     RangeControl            ControlFlags    ( TRUE, TRUE );
00651     Range                   ToRender        ( pBevel, pBevel, ControlFlags );
00652     OILBitmap               *pBitmap        = NULL;
00653     KernelBitmap            *pKernBitmap    = NULL;
00654     Path                    *pSourcePath    = &( pBevel->InkPath );
00655     Path                    BevelPath;
00656 
00657     // Create and render the bitmap.
00658     pKernBitmap = pBevel->CreateBitmapCopy(-1.0,FALSE);
00659     pBitmap = pKernBitmap->ActualBitmap;
00660 
00661     // Initialise the path, and copy the data into it.
00662     BevelPath.Initialise ( pSourcePath->GetNumCoords () );
00663 
00664     if ( BevelPath.CopyPathDataFrom ( &( pBevel->InkPath ) ) == FALSE )
00665     {
00666         TRACEUSER( "Graeme", _T("Error, and exiting ExportBevel!\n") );
00667         return FALSE;
00668     }
00669 
00670     DrawPathToOutputDevice ( &BevelPath, PATHSHAPE_CIRCLE );
00671 
00672     // Ensure that we're not writing to a NULL pointer.
00673     if ( mpShapeTail != NULL )
00674     {
00675         // Variables for calculating the transparency.
00676         UINT32  Alpha       = 0;
00677         UINT32  Colours     = mpShapeTail->GetNumberColours ();
00678 
00679         // Sum all the alpha values for the path. I'm assuming that the bevel's
00680         // transparency has already been noted.
00681         for ( UINT32 i = 0; i < Colours; i++ )
00682         {
00683             Alpha += mpShapeTail->GetColour ( i ).Alpha;
00684         }
00685 
00686         // Get the average colour for the bevel.
00687         Alpha /= Colours;
00688 
00689         // There are probably more elegant ways of doing this, but they would involve me
00690         // rewriting a lot of code for one special case. Instead, I'm going to overwrite
00691         // the existing fill colour with the bitmap.
00692         WORD    BitmapID    = GetBitmapID ( pBitmap, NULL, NULL, 255 );
00693         DocRect Bounds      = pBevel->GetBoundingRect ();
00694 
00695         // Remove the boundary lines from the bevel paths.
00696         mpShapeTail->RemoveLines ();
00697 
00698         // Some tweaks to the object inside the bevel.
00699         if ( mpShapeLast != NULL )
00700         {
00701             mpShapeLast->RemoveLines ();
00702         }
00703 
00704         // Record the details of the fill.
00705         mpShapeTail->SetStartPoint  ( Bounds.lo );
00706         mpShapeTail->SetEndPoint    ( DocCoord ( Bounds.hi.x, Bounds.lo.y ) );
00707         mpShapeTail->SetEndPoint2   ( DocCoord ( Bounds.lo.x, Bounds.hi.y ) );
00708         mpShapeTail->SetFill        ( FLASH_CLIPPED_BITMAP );
00709 
00710         // Record the size and ID number of the bitmap used.
00711         mpShapeTail->SetBitmapID    ( BitmapID );
00712         mpShapeTail->SetBitmapWidth ( pBitmap->GetWidth () );
00713         mpShapeTail->SetBitmapHeight ( pBitmap->GetHeight () );
00714     }
00715 
00716     // Clean up the bitmap created.
00717     if(pKernBitmap)
00718     {
00719         pKernBitmap->DestroyGreyscaleVersion();
00720         delete pKernBitmap;
00721     }
00722 
00723     return TRUE;
00724 }

BOOL FlashRenderRegion::ExportBevelBegin NodeBevelBegin pBevel  ) 
 

Stub function to prevent NodeBevelBegin from rendering.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/12/99 Input: pBevel - A pointer to a NodeBevelBegin object.
Returns:
TRUE if success.
See also:
-

Definition at line 739 of file swfrndr.cpp.

00740 {
00741     return TRUE;
00742 }

BOOL FlashRenderRegion::ExportButtonState FlashButtonRecord pButton  )  [protected]
 

This method is part of the button rollover support that is being added to the Flash export filter. Due to the way that the render region has been implemented, and the fact that I've been asked to do this after writing virtually all of the filter code, it's algorithm is a little strange.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/1/00
The Flash filter works by creating a series of linked lists containing a record of the objects to be exported during the pass through the rendering tree, which is a necessary first step to record reuseable resources such as bitmap images, and font definitions. This method is unique in that it goes back to previously created nodes and changes them by removing PlaceObject tags from this list.

A more efficient way to do this would have been to pick up on whether a node was a part of a button before exporting. However, this would require rewriting a lot of code, and would probably end up being much more complex, so I'm willing to tolerate some eccentricity.

Returns:
TRUE if success, FALSE if an error is encountered.
See also:
-

Definition at line 2169 of file swfrndr.cpp.

02170 {
02171     // Define local variables.
02172     FlashPlaceObject    *pLast      = mpPlaceTail;
02173     FlashSprite         *pSprite    = NULL;
02174 
02175     // If the function has been passed a NULL pointer, check whether a button name has been
02176     // set. If not, return from this function.
02177     if ( pButton == NULL )
02178     {
02179         // If a name has been set, then this shape is part of a button array, so go and
02180         // process it.
02181         if ( ( mButtonState == NO_BUTTON ) &&
02182              ( mButtonName.IsEmpty () ) )
02183         {
02184             return FALSE;
02185         }
02186     }
02187 
02188     // Remove the object from the tail of the list. Rewind the PlaceObject tail pointer.
02189     mpPlaceTail = mpPlaceTail->GetLast ();
02190 
02191     // Catch NULL pointers to avoid access violations.
02192     if ( mpPlaceTail != NULL )
02193     {
02194         mpPlaceTail->SetNext ( NULL );
02195     }
02196     else
02197     {
02198         mpPlace = NULL;
02199     }
02200 
02201     // If no button exists at this point, get a match.
02202     pButton = MatchButton ();
02203 
02204     // Get the sprite record ID from the list.
02205     pSprite = MatchSprite ( pButton );
02206 
02207     // Re-attatch the place object record to the sprite record.
02208     pSprite->SetTail ( pLast );
02209 
02210     return TRUE;
02211 }

BOOL FlashRenderRegion::ExportCharacter TextChar pTheLetter  ) 
 

Adds the character into the two lists that maintain the strings to be exported to a Flash file.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/10/99 Input: TheLetter - A Unicode character, which is to be stored
Returns:
TRUE if success.
See also:
-

Definition at line 408 of file swfrndr.cpp.

00409 {
00410     // Assume pointers (member variables) to:
00411     // - mpFont:    A list of font styles being used by the program.
00412     // - mpText:    A list of the text strings being used.
00413     // - mpPlace:   A list of the place object tags.
00414 
00415     // Define local variables.
00416     TextLine                *pTextLine  = pTheLetter->FindParentLine ();
00417     Node                    *pTextStory = pTextLine->FindParent ();
00418     Node                    *pNode      = pTextStory->FindFirstChild ();
00419     FlashFontRecord         *pFont      = NULL;
00420     DWORD                   FlashFontID = 0;
00421     INT32                       CharCode    = 0;
00422     FillGeometryAttribute   *pFill      = static_cast <FillGeometryAttribute*>
00423                                           ( GetCurrentAttribute ( ATTR_FILLGEOMETRY ) );
00424     TranspFillAttribute     *pTransp    = static_cast <TranspFillAttribute*>
00425                                          ( GetCurrentAttribute ( ATTR_TRANSPFILLGEOMETRY ) );
00426     StrokeColourAttribute   *pStroke    = static_cast <StrokeColourAttribute*>
00427                                           ( GetCurrentAttribute ( ATTR_STROKECOLOUR ) );
00428 
00429     // If the text has a gradient or bitmap fill, or any transparency other than flat,
00430     // export it as a path.
00431     if ( !pFill->IsAFlatFill () ||
00432          !pTransp->IsAFlatFill () ||
00433          !pStroke->GetStartColour ()->IsTransparent () )
00434     {
00435         // The fill is too complex to be exported as a straight Flash text character, so
00436         // export it as a path.
00437         return FALSE;
00438     }
00439 
00440     // Cycle through the list of children for the text node. If a NodePath is found, then
00441     // return FALSE. This will cause the letter to be exported as a shape rather than a
00442     // character, and so keep the alignment correct. This is here to export text on a curve,
00443     // which would otherwise not be correctly rendered.
00444     while ( pNode != NULL )
00445     {
00446         if ( pNode->IsNodePath () || pNode->IsARegularShape () )
00447         {
00448             // The text story contains a path, therefore it has to be exported as a set
00449             // of curves.
00450             return FALSE;
00451         }
00452         else
00453         {
00454             // Find the next node.
00455             pNode = pNode->FindNextNonHidden ();
00456         }
00457     }
00458 
00459     // Grab a pointer to the previous VTN in the TextStory. This is used for determining
00460     // whether or not to create a new FlashTextRecord for the successive characters.
00461     VisibleTextNode *pLastVTN   = pTheLetter->FindPrevVTNInLine ();
00462 
00463     // Get the character to be exported from the TextChar record.
00464     WCHAR Glyph = pTheLetter->GetUnicodeValue ();
00465 
00466     // VisibleTextNodes are either renderable characters, carets, or end of line nodes.
00467     // I'm not interested in carets, so I'll skip these.
00468     if ( ( pLastVTN != NULL ) && ( pLastVTN->IsACaret () ) )
00469     {
00470         pLastVTN = pLastVTN->FindPrevVTNInLine ();
00471     }
00472 
00473     // Step 1:  Get the details of the font.
00474 
00475     // First the font's handle.
00476     WORD FontName = ( ( TxtFontTypefaceAttribute* ) GetCurrentAttribute
00477                         ( ATTR_TXTFONTTYPEFACE ) )->HTypeface ;
00478 
00479     // Secondly, whether or not it's bold.
00480     BOOL IsBold = ( ( TxtBoldAttribute* ) GetCurrentAttribute
00481                     ( ATTR_TXTBOLD ) )->BoldOn;
00482 
00483     // Thirdly, whether or not it's italic.
00484     BOOL IsItalic = ( ( TxtItalicAttribute* ) GetCurrentAttribute
00485                       ( ATTR_TXTITALIC ) )->ItalicOn;
00486 
00487     // And finally, it's offset and relative size values.
00488 //  TxtScriptAttribute *pScript = ( TxtScriptAttribute* ) GetCurrentAttribute  ( ATTR_TXTSCRIPT );
00489 
00490 
00491     // Flash doesn't seem to support fonts with obscure aspect ratios, so maybe set
00492     // that into the text matrix, along with rotates.
00493 
00494     // Step 2:  Determine whether a new FlashTextRecord is needed. A new one is
00495     //          required if either there isn't an existing FlashTextRecord to add the
00496     //          characters to, or there's been a new line. Since the first character
00497     //          to be stored will, by definition, be at the start of a new line, and
00498     //          hence this is the only check that I need to make.
00499     if ( pLastVTN == NULL )
00500     {
00501         // Step 2a: Create the new FlashTextRecord to contain the string. If none
00502         //          exist at present, create it at mpText. Otherwise use add element.
00503         CreateTextRecord ( pTheLetter );
00504     }
00505 
00506     // Step 2b: For each font, cycle through the list mpFontStyles, and
00507     //          compare existing resources with the current font style. If a pre
00508     //          -existing style matches, reuse this one, otherwise create a new
00509     //          record.
00510     pFont = mpFont;
00511 
00512     // Spool through the list.
00513     while ( pFont != NULL )
00514     {
00515         // Compare font names and styles.
00516         if ( ( pFont->GetTypeface () == FontName ) &&
00517              ( pFont->GetIsBold () == IsBold ) &&
00518              ( pFont->GetIsItalic () == IsItalic ) )
00519         {
00520             // Break out of the while loop.
00521             break;
00522         }
00523         else
00524         {
00525             pFont = pFont->GetNext ();      // Move on to the next item in the list.
00526             FlashFontID ++;                 // Increment ID number.
00527         }
00528     }
00529 
00530     // If pFont is NULL, no matching font styles have been stored, so create a
00531     // new record.
00532     if ( pFont == NULL )
00533     {
00534         // If there are no existing font records, create one.
00535         if ( mpFont == NULL )
00536         {
00537             mpFont = new FlashFontRecord;
00538             ASSERT ( mpFont != NULL );
00539             pFont = mpFontTail = mpFont;
00540         }
00541         else
00542         {
00543             mpFontTail = mpFontTail->AddElement ();
00544             ASSERT ( mpFontTail != NULL );
00545             pFont = mpFontTail;
00546         }
00547 
00548         // Record the necessary font metrics. There's no need to store FlashFontID
00549         // since that is implicit in the order of the elements in the list. (i.e.
00550         // the first item is #0, and the second is #1, etc.)
00551         pFont->SetTypeface ( FontName );
00552         pFont->SetIsBold ( IsBold );
00553         pFont->SetIsItalic ( IsItalic );
00554 
00555         // Set the ID number for the font.
00556         pFont->SetFontID ( FlashPlaceObject::GetFontCount () );
00557         FlashPlaceObject::IncFontCount ();
00558     }
00559 
00560     // And add the path.
00561     if ( pFont->AddGlyph ( Glyph, CharCode ) )
00562     {
00563         Matrix FontMatrix;
00564 
00565         TxtFontSizeAttribute FlashFontSize ( FLASH_FONT_SIZE );
00566         TxtFontSizeAttribute *pLastSize = ( TxtFontSizeAttribute* ) GetCurrentAttribute
00567                                           ( ATTR_TXTFONTSIZE );
00568 
00569         TxtAspectRatioAttribute FlashAspect ( 1 );
00570         TxtAspectRatioAttribute *pLastAspect = ( TxtAspectRatioAttribute* )
00571                                                GetCurrentAttribute ( ATTR_TXTASPECTRATIO );
00572 
00573         // Set the font size and aspect to the correct values to render the path.
00574         SetTxtFontSize ( &FlashFontSize, FALSE );
00575         SetTxtAspectRatio ( &FlashAspect, FALSE );
00576 
00577         // Add it to the record.
00578         pFont->AddPath ( CreateCharPath ( Glyph, &FontMatrix ), CharCode );
00579 
00580         // Restore the current render region settings.
00581         RestoreTxtFontSize ( pLastSize, FALSE );
00582         RestoreTxtAspectRatio ( pLastAspect, FALSE );
00583     }
00584 
00585     // Step 3:  Add the character to the end of the string, and the font style to the list
00586     //          of characters used in that particular font.
00587     INT32 Index = mpTextTail->AddChar ( pTheLetter, CharCode );
00588 
00589     // Fill in the font's characteristics:
00590     
00591     // Font size.
00592 //  INT32       Offset  = ( pScript->Offset ).GetRawLong ();
00593 //  INT32       Ratio   = ( pScript->Size ).GetRawLong ();
00594 
00595     MILLIPOINT  Size    = ( ( TxtFontSizeAttribute* ) GetCurrentAttribute
00596                           ( ATTR_TXTFONTSIZE ) )->FontSize;
00597 
00598     // Set the font size.
00599     mpTextTail->SetSize ( Size, Index );
00600 
00601     // And the ascent.
00602     mpTextTail->SetAscent ( pTheLetter->GetFontAscent () );
00603 
00604     // Calculate the baseline of the font.
00605 //  double      dDiv    = ( double ) Ratio * ( double ) FLASH_FIXED_ONE;
00606 //  double      dBase   = ( double ) ( Size - pTheLetter->GetFontDescent () ) / dDiv;
00607 
00608     // And the offset.
00609 //  double      dOffset = Size * ( ( double ) Offset / ( double ) FLASH_FIXED_ONE );
00610 
00611     // Use these to calculate the y offset value for the text.
00612 //  double      dYOff   = dBase - dOffset - ( double ) pTheLetter->GetBaseLineShift ();
00613 
00614     // mpTextTail->SetBaseline ( ( INT32 ) dYOff, Index );
00615     mpTextTail->SetOffset ( 0 , Index );
00616 
00617     // Font colour.
00618     mpTextTail->SetColour ( pFill->GetStartColour (),
00619                             pTransp->GetStartTransp (),
00620                             Index );
00621 
00622     // Typeface. Note: I'm using the FlashFontID numbers because these map the font
00623     // definitions (within the Flash file) onto the file's text definitions.
00624     mpTextTail->SetStyle ( ( WORD ) FlashFontID, Index );
00625 
00626     // Step 4:  Return TRUE. This allows me to use the standard error checking macros, which
00627     //          will return FALSE if they hit a problem.
00628 
00629     return TRUE;
00630 }

BOOL FlashRenderRegion::ExportRenderableNode NodeRenderableInk pInk  ) 
 

Renders a stroked path to the file.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/11/00 Input: pInk - The ink node to be exported.
Returns:
TRUE - The node contained a stroke, and was exported by this method. FALSE - Export using the default export code.
See also:
-

Definition at line 836 of file swfrndr.cpp.

00837 {
00838     // Graeme (10/11/00) - I don't think that this is a particularly nice way to export a
00839     // stroked path to a Flash file. The EPS render region will export strokes automatically,
00840     // without any of this messing around, and as a result I suspect that the Flash render
00841     // region hasn't been properly initialised.
00842     //
00843     // There is, however, an advantage to doing it this way: By calling RetroSmoothMe on the
00844     // path, the overall file size required to store a given path is halved, which for is a
00845     // big advantage for the Flash file format, in which the file size is crucial.
00846 
00847     // Pointer to the stroke type attribute.
00848     AttrStrokeType  *pStroke    = NULL;
00849 /*
00850     NodeAttribute   *pAttr      = NULL;
00851     AttrBrushType   *pBrush     = NULL;
00852 
00853     // Find out if we have an applied brush node.
00854     pInk->FindAppliedAttribute ( CC_RUNTIME_CLASS ( AttrBrushType ), &pAttr );
00855 
00856     // Cast it into a brush type attribute to avoid multiple casts in the following code.
00857     pBrush = static_cast <AttrBrushType*> ( pAttr );
00858 
00859     if ( pBrush != NULL &&
00860          pBrush->GetBrushHandle () != BrushHandle_NoBrush )
00861     {
00862         SimpleBecomeA BecomeA ( BECOMEA_PASSBACK, CC_RUNTIME_CLASS ( NodePath ), NULL );
00863 
00864         if ( pBrush->DoBecomeA ( &BecomeA, pInk ) )
00865         {
00866             NodePath *pNodePath = Beco