EPSFilter Class Reference

Encapsulates a basic Adobe Illustrator EPS import/export filter. This filter can be used as a base class, because most EPS formats are based (more or less) on AI format. Derived filters can override whichever parts they want to implement other flavours of EPS. More...

#include <epsfiltr.h>

Inheritance diagram for EPSFilter:

VectorFilter Filter ListItem CCObject SimpleCCObject AIEPSFilter ArtWorksEPSFilter CorelEPSFilter FreeHandEPSFilter PhotoShopEPSFilter AI5EPSFilter CamelotEPSFilter Corel3EPSFilter Corel4EPSFilter AI8EPSFilter CamelotNativeEPSFilter List of all members.

Public Types

enum  PathType {
  PATH_NORMAL, PATH_DISCARD, PATH_DISCARD_STICKY, PATH_RECT,
  PATH_ELLIPSE, PATH_MANGLED
}

Public Member Functions

 EPSFilter ()
 Constructor for an EPSFilter object. The object should be initialised before use.
virtual BOOL Init ()
 Initialise an EPSFilter object. This is a base class and so should never actually be initialised so this function will always return FALSE, and also ENSURE in debug builds.
INT32 HowCompatible (PathName &Filename, ADDR HeaderStart, UINT32 HeaderSize, UINT32 FileSize)
 Looks at the start of the file to see if it recognises the file as belonging to it.
BOOL IsDefaultDocRequired (const TCHAR *pcszPathName)
 Works out if opening a file of this type requires a default document to be loaded. If the file format supplies the document then return FALSE otherwise return TRUE. An example would be opening a bitmap file. This has no document defined in the file format and so we need to laod the default document before importing the bitmap into this file. In this baseclass version return FALSE and hence assume that the filters that need to will override this function to return TRUE.
BOOL DoImport (SelOperation *Op, CCLexFile *, Document *DestDoc, BOOL, ImportPosition *Pos=NULL, KernelBitmap **ppImportedBitmap=NULL, DocCoord *pPosTranslate=NULL, String_256 *URL=NULL)
 Read EPS data from an EPS file, and convert it into Camelot tree data structures. When the file reading is complete, a forced redraw is issued for the area affected by the new data. At the moment, the data is just put on the first layer of the first spread of the first chapter in the document, and this is a bodge. The operation is terminated (i.e. its End() function is called) if the operation completed succesfully.
BOOL DoExport (Operation *, CCLexFile *, PathName *, Document *, BOOL)
 Exports the File as EPS. The various forms of EPS are to be found in the classes derived from this one.
BOOL ExportBinaryHeader (CCLexFile *)
 Outputs the initial binary Header for EPS files that contain a TIFF preview of the EPS. This format is described on page 729 of the Big Red Postscript book (PostScript Language Reference Manual Second Edition). The basic form is as follows :- MonoOn: Bytes 0-3 C5D0D3C6 Bytes 4-7 Byte pos of start of PostScript in file Bytes 8-11 Length of PostScript section in Bytes Bytes 12-15 Start of MetaFile (always 0 from Camelot) Bytes 16-19 Length of MetaFile (always 0 from Camelot) Bytes 20-23 Start of TIFF file Bytes 24-27 Length of TIFF file Bytes 28-29 Checksum or FFFF.
BOOL CorrectBinaryHeader (CCLexFile *)
 Goes back to the binary header at the start of the file and fills in the correct values to all the fields.
virtual BOOL WriteEPSProlog ()
 Allows the filter a chance to write out something in the Prolog section.
virtual BOOL WriteEPSSetup ()
 Allows the filter a chance to write out something in the Prolog section.
virtual BOOL WriteEPSComments ()
 Allows the filter a chance to write out something in the Prolog section.
virtual BOOL WriteScript ()
 Allows the filter a chance to write out something in the Prolog section.
virtual BOOL NeedsPrintComponents (void)
 Allows the program to determine whether print components are needed for this flavour of EPS.
TCHARGetEPSCommand (EPSCommand Cmd)
 Given an EPS token, return the string representation of it; mainly for debugging purposes.
EPSExportDCGetExportDC ()
EPSRenderRegionGetExportRegion ()
virtual INT32 ImportBinary (ADDR pData, INT32 Length)
 Converts EPS hex strings into binary data. Attempts to read the number of bytes specified from the file.
virtual BOOL AddNewNode (Node *pNewNode)
 When a new node is created, this function puts it into the tree in the correct place. It may add it into a group, or a new layer which is currently being constructed, or onto an existing layer.
void HandleEPSError ()
 Cleans up when a syntax error is encountered in the EPS file. Any objects constructed so far are deleted, and the error message ID is set.
INT32 DecodeHexString (ADDR pData, INT32 Length, INT32 nStart=0)
 Treat the current token as a hex string, and decode it into binary data and place it in the buffer provided by the caller. No more than Length bytes should be placed in the buffer.
BOOL ResetImportOrigin ()
 If the importer changes the pages in the document when loading, this allows it to reset the origin.
BOOL ResetImportOrigin (DocCoord NewOrigin)
 Instructs the filter to use the new origin, because we are importing and otherwise QuickShapes and Text Stories will be incorrectly positioned.

Static Public Member Functions

static BOOL InitPrefs ()
 Initialise preferences for EPS formats. This is used by the Camelot EPS export filter, and includes font mappings, DPI, PostScript language level control, and exporting text as curves.

Static Public Attributes

static INT32 XSEPSExportPSType = 2
static INT32 XSEPSExportDPI = 200
static BOOL XSEPSExportTextAsCurves = FALSE

Protected Member Functions

virtual BOOL PrepareToImport ()
 Prepare to import EPS data using this filter. This sets up the filter to a sensible state for reading.
virtual void CleanUpAfterImport (BOOL Successful)
 Cleans up the memory allocated by EPSFilter::PrepareToImport() - used when the import process ends, either normally or abnormally.
void DecodeToken ()
 Decode the PostScript token that is contained in the 'TokenBuf' buffer. This is not used for strings, comments, or array brackets, but is used to detect tokens which are floating point numbers, integers, EPS keywords, or PostScript 'names' (e.g. font names). In other words, any token which cannot be identified solely by its first character.
virtual void LookUpToken ()
 Determines if the current token is one of the standard Illustrator tokens. The 'Token' variable is set accordingly. If the token is not recognised, it is assumed to be a PostScript 'name'.
virtual BOOL ProcessToken ()
 Examines the current token and performs whatever actions are necessary to process its meaning. Operands are simply pushed onto the EPS stack, and keywords are either acted upon, or ignored if they describe something that Camelot does not yet support (in the latter case, the operands of the keyword, if any, are simply discarded from the stack).
BOOL GetToken ()
 Extract a token from the input stream. The Token variable holds the type of the token, and TokenBuf holds the characters that make up the token (be it a command, a string. a number, or whatever).
BOOL GetLineToken ()
 Extract a token from the input stream in a line-based manner. The Token variable holds the type of the token, and TokenBuf holds the characters that make up the token (be it a command, a string. a number, or whatever).
BOOL HandleToken ()
 'Handles' the current EPS token - if it's an EOL or EOF token, it updates the progress display, otherwise it just calls ProcessToken();
BOOL ProcessEndOfPath (void)
 Processes the end-of-path directive.
BOOL ProcessUnfilledPath (void)
 Processes the end-of-path directive of an unfilled or unstroked path.
BOOL ProcessGroup ()
 Reads in all the elements of a group structure in the EPS file.
virtual BOOL ProcessComment (BOOL BypassDocComponents=FALSE)
 Decodes an EPS comment - usually starting with "%%", e.g. %BeginProlog etc.
BOOL ProcessRectangle (NodeRect *pRect, NodeRegularShape *pQuickShape)
 Having read in a rectangle path, this function builds a QuickShape rectangle as defined by the path.
BOOL ProcessEllipse (NodeEllipse *pEllipse, NodeRegularShape *pQuickShape)
 Having read in a ellipse path, this function builds a QuickShape ellipse as defined by the path.
virtual BOOL ProcessFilterComment ()
 Override this function to claim EPS comments for the filter to decode. This function is called after the usual comments are checked for such as %BeginProlog etc, but *before* the doc components are called. If you want to claim the current token (i.e. as held in TokenBuf), return TRUE.
void HandleNoMemory ()
 Cleans up when the filter runs out of memory when importing a file. Any objects constructed so far are deleted, and the error message ID is set.
virtual BOOL AddAttributes (NodeRenderableBounded *pNode, BOOL Stroked, BOOL Filled)
 Add attributes to an object being constructed. The attributes are optimised so that if they are the same as the document's default attributes, they are not applied.
virtual INT32 EPSHeaderIsOk (ADDR pFileHeader, UINT32 HeaderSize)
 Checks to see if the EPS comment headers specify that this is an Illustrator generated EPS file, as required.
BOOL UseLayer (String_256 &LayerName, BOOL GuideLayer=FALSE)
 This is a wrapper around the new AddLayer method, which now returns a pointer to the newly created layer, which is where all the work is done. I've done this to preserve the original interface.
LayerAddLayer (String_256 &LayerName, BOOL GuideLayer)
 Given a layer name, construct a new layer, or find an existing layer with the same name, and cause new nodes to be added to the resulting layer.
BOOL StartGroup ()
 Used when a group structure needs to be created - after this is called, all new nodes added with AddNewNode() will be added as children of this new group, until EndGroup is called.
BOOL EndGroup (BOOL Masked=FALSE)
 Used when a group has finished being constructed and we want to return to normal node positioning. The group is added to the document when this function is called (although that depending on the current filter mode, i.e. whether this is a new or existing layer, it may not be added directly to the documnent tree straight away - it may be deferred until the next layer is found, or the import has ended).
virtual BOOL ValidateGroup (Node *Group)
 Validate a group. Can be overridden to, for example, ensure that groups have at least two children.
virtual BOOL MaskedGroupEnding ()
 Function to call when a masked group ends. Gives a chance to restore graphic states and the like.
virtual void ProcessTextMatrix (Matrix *pMatrix)
 Having read a text object position matrix from the file, we may (dependent on the filter type), need to process it in some way, ie add in the spread origin.
BOOL AttachAllNodes ()
 Called at the end of an import - attaches any nodes to the tree that have not yet been attached. e.g. a new layer node, or a group node if layers are being ignored.
BOOL InsertNewNode (Node *pNewNode)
 This function adds a node to the tree in an undoable way. It uses DoInsertNewNode() to do this. If it fails then 'pNewNode' and all its children are deleted. It adds the node as a child of the node pointed to by 'pNode'.
virtual BOOL Import_gsave ()
 stores the current path and attributes to emulate a gsave in the imported EPS file. All things are copied. States can be nested.
virtual BOOL Import_grestore ()
 restores path and attributes saved by the matching Import_gsave.
virtual BOOL PrepareToExport (CCLexFile *, Spread *pSpread)
 Prepare to import EPS data using this filter. This sets up the filter to a sensible state for reading.
virtual void CleanUpAfterExport ()
 Cleans up the memory allocated by EPSFilter::PrepareToImport() - used when the import process ends, either normally or abnormally.
virtual EPSExportDCCreateExportDC ()
 This allows the EPS filter to choose which sort of EPSExportDC to use. Most filters will use this default one, but some (Native Save/Load eps) will make use of a different ExportDC derived from EPSExportDC. This function simply returns the result of a 'new' and does no checking on the returned parameter. It is perfectly valid for this function to return NULL (meaning no ExportDC could be created) and the calling function should handle this appropriatly.
void RemoveMessage (CCLexFile *pFile)
 Removes the Copyright message that appears in the middle of our native file format.
virtual BOOL GetExportOptions ()
 Allows the user to be prompted to get information for export. Base class returns True so that nothing happens by default. Scope: Protected.
virtual BOOL ProcessEPSComment ()
 Tries to process the contents of a comment. First it asks the filter and then it tries the document and all the doc components to see if it is one of thiers.
virtual BOOL ProcessEPSTrailer ()
 Handles the end of the page (I think).
virtual BOOL ProcessBoundingBox ()
 Tries to make use of the BoundingBox info in the EPS file.
void ProcessEPSProlog ()
void ProcessEPSSetup ()
void GetEPSColour (DocColour *DestCol, PColourCMYK *pCMYK, TintType Tint, FIXEDPOINT TintVal, String_64 *ColName)
 Used when an EPS colour definition has just been read off the stack. Provides a centralised way of interpreting the usual colour definitions and getting a valid DocColour out of it. This copes with all sorts of things such as creating an indexed colour for named colours, and even handles creation of special colours for tinted named colours. Basically, it's a fire-and-forget function :-). If all else fails, it falls back to an immediate DocColour.
void GetEPSColourRGB (DocColour *DestCol, INT32 red, INT32 green, INT32 blue, TintType Tint, FIXEDPOINT TintVal, String_64 *ColName)
 Identical to EPSFilter::GetEPSColour, except that it deals with RGB colours instead of CMYK ones.
void MakeLayerNameUnique (String_256 &LayerName, Spread *pSpread)
 Given a layer name, ensure it is unique within the spread. If a clash occurs then the following layer names are tried until a unique one is found. (Assuming layer name is "Foreground" in this example).
BOOL ProcessText ()
 Reads in all the elements of a Text structure in the EPS file.
BOOL GetStoryMatrix (Matrix *pMatrix)
 Reads in all the elements of a Text Story Matrix.
BOOL SetStrokeColourNone ()
 Updates the current attribute for StrokeColour with the value of COLOUR_NONE.
BOOL SetFillColourNone ()
 Updates the current attribute for FillColour with the value of COLOUR_NONE.
BOOL MakeNewTextLine (Node *pParent)
 Reads in all the elements of a Text structure in the EPS file.

Protected Attributes

FilePos EPSStart
FilePos EPSEnd
FilePos PreviewStart
FilePos PreviewEnd
UINT32 FilterNameID
UINT32 FilterInfoID
EPSCommentList EPSComments
CCLexFileEPSFile
const TCHARTokenBuf
INT32 LastProgressUpdate
EPSCommand Token
union {
   INT32   Long
   FIXEDPOINT   FixedPoint
   double   Double
   TCHAR *   String
   TCHAR *   Comment
TokenData
EPSStack Stack
DocRect SpreadRect
NodePathpPath
LayerpLayer
PagepPage
NodepNode
EPSFlagsDefn EPSFlags
struct {
   SelOperation *   pOp
   ImportPosition *   Pos
   Spread *   pSpread
ImportInfo
PathType ThePathType
EPSRenderRegionExportRegion
EPSExportDCExportDCPtr
ColourListComponentpColours
DocCoord ShapeBBox [4]
NodepFirstNodeInRange
NodepLastNodeInRange
BOOL AdjustOrigin
BOOL SupportsLayers
BOOL UseLayers
INT32 GroupNesting
INT32 MaskedGroupNesting
BOOL InvalidPathFound
PathpInkPath
EPSClipContext ClipRegion
INT32 TextComment [3]
List GraphicStateStack
EPSFilter::_FontFlags FontFlags
FontClass ClassOfFont
INT32 NewMouldThreshold
BOOL EPS_Group
FilePos EndOfEPS

Static Protected Attributes

static CommandMap Commands []
static RangeList ImportRange

Private Member Functions

 CC_DECLARE_DYNAMIC (EPSFilter)

Classes

struct  _FontFlags

Detailed Description

Encapsulates a basic Adobe Illustrator EPS import/export filter. This filter can be used as a base class, because most EPS formats are based (more or less) on AI format. Derived filters can override whichever parts they want to implement other flavours of EPS.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/10/93
See also:
EPSFilter::Init; EPSFilter::DoImport; EPSFilter::DoExport; Filter; ArtWorksEPSFilter; Corel3Filter; Corel4Filter

Definition at line 455 of file epsfiltr.h.


Member Enumeration Documentation

enum EPSFilter::PathType
 

Enumerator:
PATH_NORMAL 
PATH_DISCARD 
PATH_DISCARD_STICKY 
PATH_RECT 
PATH_ELLIPSE 
PATH_MANGLED 

Definition at line 494 of file epsfiltr.h.

00495     {
00496         PATH_NORMAL,
00497         PATH_DISCARD,
00498         PATH_DISCARD_STICKY,
00499         PATH_RECT,
00500         PATH_ELLIPSE,
00501         PATH_MANGLED
00502     } PathType;


Constructor & Destructor Documentation

EPSFilter::EPSFilter  ) 
 

Constructor for an EPSFilter object. The object should be initialised before use.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/10/93
See also:
EPSFilter::Init

Definition at line 942 of file epsfiltr.cpp.

00943 {
00944     ImportMsgID = _R(IDT_IMPORTMSG_AI);
00945     Flags.CanImport = TRUE;
00946     //WEBSTER-Martin-27/01/97
00947 #ifdef WEBSTER
00948     Flags.CanExport = FALSE;
00949 #else
00950     Flags.CanExport = TRUE;
00951 #endif //WEBSTER
00952     FilterID = FILTERID_AIEPS;
00953 
00954 #ifndef DO_EXPORT
00955     Flags.CanExport = FALSE;
00956 #endif
00957 
00958     EPSFile = NULL;
00959     TokenBuf = NULL;
00960     pColours = NULL;
00961 
00962     ExportDCPtr = NULL;
00963     ExportRegion = NULL;
00964     ExportMsgID = _R(IDT_EXPORTMSG_AI);
00965 
00966     AdjustOrigin = TRUE;
00967     SupportsLayers = TRUE;
00968 
00969     // The offsets into the file for the Preview thing
00970     EPSStart = 0;
00971     EPSEnd = 0;
00972     PreviewStart = 0;
00973     PreviewEnd = 0;
00974 
00975     TextComment[0] = 0;
00976     TextComment[1] = 0;
00977     TextComment[2] = 1;
00978 
00979     // set the font extras block vars. These indicate to the
00980     // filter to do something special with the next set of font attributes
00981     FontFlags.Bold = FALSE;
00982     FontFlags.Italic = FALSE;
00983 
00984     // Set the font type to assume we are loading true type fonts unless
00985     // told otherwise.
00986     ClassOfFont = FC_TRUETYPE;
00987     
00988     // Define the mould threshold default value.
00989     NewMouldThreshold = MOULD_V1THRESHOLD;
00990 
00991     //  We're not in a group at first.
00992     EPS_Group   =   FALSE;
00993 
00994     // Clear the length of the file to the end of the EPS code.
00995     EndOfEPS    = 0;
00996 
00997     // Set up the comment list. These are the known DSC comments, and how to handle them.
00998     EPSComments.Add ( _T("%%BeginProlog"),          _T("%%EndProlog"),          TRUE,   0 );
00999     EPSComments.Add ( _T("%%BeginSetup"),           _T("%%EndSetup"),           TRUE,   0 );
01000     EPSComments.Add ( _T("%%BeginDocument"),        _T("%%EndDocument"),        FALSE,  0 );
01001     EPSComments.Add ( _T("%%BeginPageSetup"),       _T("%%EndPageSetup"),       FALSE,  0 );
01002     EPSComments.Add ( _T("%%BeginDefaults"),        _T("%%EndDefaults"),        FALSE,  0 );
01003     EPSComments.Add ( _T("%%BeginEmulation"),       _T("%%EndEmulation"),       FALSE,  0 );
01004     EPSComments.Add ( _T("%%BeginPreview"),         _T("%%EndPreview"),         FALSE,  0 );
01005     EPSComments.Add ( _T("%%BeginFeature"),         _T("%%EndFeature"),         FALSE,  0 );
01006     EPSComments.Add ( _T("%%BeginFile"),            _T("%%EndFile"),            FALSE,  0 );
01007     EPSComments.Add ( _T("%%BeginFont"),            _T("%%EndFont"),            FALSE,  0 );
01008     EPSComments.Add ( _T("%%BeginProcSet"),         _T("%%EndProcSet"),         FALSE,  0 );
01009     EPSComments.Add ( _T("%%BeginResource"),        _T("%%EndResource"),        FALSE,  0 );
01010     EPSComments.Add ( _T("%%BeginCustomColor"),     _T("%%EndCustomColor"),     FALSE,  0 );
01011     EPSComments.Add ( _T("%%BeginProcessColor"),    _T("%%EndProcessColor"),    FALSE,  0 );
01012 }


Member Function Documentation

BOOL EPSFilter::AddAttributes NodeRenderableBounded pNode,
BOOL  Stroked,
BOOL  Filled
[protected, virtual]
 

Add attributes to an object being constructed. The attributes are optimised so that if they are the same as the document's default attributes, they are not applied.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/10/93
Parameters:
pNode - the bounded renderable node to add atributes to. [INPUTS] Stroked - TRUE if the object to add attributes to should be stroked, FALSE if not. Stroked - TRUE if the object to add attributes to should be filled, FALSE if not.
Returns:
TRUE if the attributes were added ok, FALSE if not.

Errors: Fails (returns FALSE) if not enough memory to add attributes. Scope: Private

Reimplemented in CorelEPSFilter.

Definition at line 2695 of file epsfiltr.cpp.

02696 {
02697     DocColour OldCol;
02698 
02699     // If not stroked, temporarily set the ignore bit on the line colour attribute.
02700     if (!Stroked)
02701     {
02702         StrokeColourAttribute *pAttr = 
02703             (StrokeColourAttribute *) CurrentAttrs[ATTR_STROKECOLOUR].pAttr;
02704 
02705         OldCol = pAttr->Colour;
02706         DocColour trans(COLOUR_TRANS);
02707         if (!SetLineColour(trans))
02708             return FALSE;
02709     }
02710 
02711     // If not filled, then set the ignore bit on the fill attribute.
02712     if (!Filled) //pPath->InkPath.IsFilled)
02713     {
02714         CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = TRUE;
02715     }
02716 
02717     // Add attributes to the path, if they are different from the default...
02718     BOOL Result = AttributeManager::ApplyBasedOnDefaults(pNode, CurrentAttrs);
02719 
02720     // If not stroked, reinstall old line colour.
02721     if (!Stroked)
02722         // This can't fail. (tempting fate or wot!)
02723         SetLineColour(OldCol);
02724 
02725     // Enable the fill attribute again
02726     CurrentAttrs[ATTR_FILLGEOMETRY].Ignore = FALSE;
02727 
02728     // Re-enable path-filling, in case it was disabled for this object
02729     SetPathFilled(TRUE);
02730 
02731     // Return success or failure
02732     return Result;
02733 }

Layer * EPSFilter::AddLayer String_256 LayerName,
BOOL  GuideLayer
[protected]
 

Given a layer name, construct a new layer, or find an existing layer with the same name, and cause new nodes to be added to the resulting layer.

Author:
Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com> (based on Tim's code)
Date:
17/4/00 (originally 16/08/94)
Parameters:
LayerName - The name of the new layer. [INPUTS] GuideLayer - TRUE to create a guide layer, FALSE to create a standard layer.
Returns:
pLayer - A pointer to the newly creaded layer.

Errors: An error is thrown if the layer is not created.

See also:
EPSFilter::AddNewNode

Definition at line 2389 of file epsfiltr.cpp.

02391 {
02392     // Have we currently got a pending new layer to add to the tree?
02393     if (EPSFlags.AddToNewLayer)
02394     {
02395         // Yes - add the new layer to the tree.
02396         EPSFlags.AddToNewLayer = FALSE;
02397         pNode = ImportInfo.pSpread;
02398         if (!InsertNewNode((Node *) pLayer))
02399             return FALSE;
02400 
02401         // Remember it
02402         ImportRange.AddRange(pLayer, pLayer);
02403     }
02404     else if (pFirstNodeInRange != NULL)
02405     {
02406         // We have just finished adding a range of nodes to an existing layer so let's
02407         // remember the nodes.
02408         ImportRange.AddRange(pFirstNodeInRange, pLastNodeInRange);
02409         pFirstNodeInRange = NULL;
02410         pLastNodeInRange  = NULL;
02411     }
02412 
02413     // Find out if we need a new layer name, because there is already one with this name.
02414     String_256 NewLayerName = LayerName;
02415     MakeLayerNameUnique(NewLayerName, ImportInfo.pSpread);
02416 
02417     // Make a new layer using this name.
02418     if (GuideLayer)
02419     {
02420 #if !defined(EXCLUDE_FROM_RALPH)
02421 // WEBSTER - markn 15/1/97
02422 // CreateGuideLayer() used to be part of OpGuideline class, now part of Layer class
02423         pLayer = Layer::CreateGuideLayer();
02424 #else
02425         ERROR3("EPSFilter::UseLayer GuideLayer == TRUE - whoop whoop ! BAD !");
02426 #endif
02427     }
02428     else
02429         pLayer = new Layer;
02430 
02431     ERRORIF(pLayer == NULL, _R(IDT_EPS_NOMEMORY), FALSE);
02432     pLayer->SetLayerID(NewLayerName);
02433     EPSFlags.AddToNewLayer = TRUE;
02434 
02435     // Make it the new destination node for all new nodes.
02436     pNode = (Node *) pLayer;
02437 
02438     // Pass the layer pointer out.
02439     return pLayer;
02440 }

BOOL EPSFilter::AddNewNode Node pNewNode  )  [virtual]
 

When a new node is created, this function puts it into the tree in the correct place. It may add it into a group, or a new layer which is currently being constructed, or onto an existing layer.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/08/94
Parameters:
pNewNode - the new node to add [INPUTS]
Returns:
TRUE if it worked, FALSE if not.

Errors: Out of memory

See also:
EPSFilter::UseLayer

Reimplemented in FreeHandEPSFilter.

Definition at line 2088 of file epsfiltr.cpp.

02089 {
02090     if ((EPSFlags.AddToNewLayer) || (!UseLayers))
02091     {
02092         // Simple case - just add to the new layer node
02093         pNewNode->AttachNode(pNode, LASTCHILD);
02094 
02095         if (pNewNode->IsBounded())
02096         {
02097             // Update the bounds for this object
02098             NodeRenderableBounded *pBounded = (NodeRenderableBounded *) pNewNode;
02099             pBounded->InvalidateBoundingRect();
02100         }
02101     }
02102     else
02103     {
02104         // Tricky case - we have to add the node to the existing layer in the 
02105         // document in an undoable way.
02106         return InsertNewNode(pNewNode);
02107     }
02108 
02109     // All went ok.
02110     return TRUE;
02111 }

BOOL EPSFilter::AttachAllNodes  )  [protected]
 

Called at the end of an import - attaches any nodes to the tree that have not yet been attached. e.g. a new layer node, or a group node if layers are being ignored.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/08/94
Returns:
TRUE if it worked ok; FALSE if not.

Errors: Out of memory

See also:
EPSFilter::AddNewNode

Definition at line 2237 of file epsfiltr.cpp.

02238 {
02239     BOOL Success = TRUE;
02240     NodeGroup *pGroup=NULL;
02241 
02242     if (UseLayers)
02243     {
02244         // Check to see if there is an outstanding layer node to add...
02245         if (EPSFlags.AddToNewLayer)
02246         {
02247             // Yes - add it...
02248 
02249             // We're adding the layer to the spread now
02250             EPSFlags.AddToNewLayer = FALSE;
02251             Node *pLayer = pNode;
02252             pNode = ImportInfo.pSpread;
02253 
02254             // Do it.
02255             Success = AddNewNode(pLayer);
02256 
02257             // Remember it
02258             if (Success)
02259                 ImportRange.AddRange(pLayer, pLayer);
02260         }
02261         else if (pFirstNodeInRange != NULL)
02262         {
02263             // We have just finished adding a range of nodes to an existing layer so let's
02264             // remember the nodes.
02265             ImportRange.AddRange(pFirstNodeInRange, pLastNodeInRange);
02266             pFirstNodeInRange = NULL;
02267             pLastNodeInRange  = NULL;
02268         }
02269     }
02270     else
02271     {
02272         // No layers - always imported as a group, so add it into the tree.
02273         pGroup = (NodeGroup *) pNode;
02274         pNode = (Node *) pLayer;
02275 
02276         Success = InsertNewNode(pGroup);
02277     }
02278 
02279     if (!Success)
02280         return FALSE;
02281 
02282     // we need the bounding rect to do this (not the one with attributes)
02283     DocRect BoundsRect;
02284 
02285     if (UseLayers)
02286         BoundsRect = ImportRange.GetBoundingRect();
02287     else
02288         BoundsRect = pGroup->GetBoundingRect(TRUE);
02289 
02290     // Translate objects to the drag and drop position if necessary...
02291     Coord Offset;
02292 
02293     if (GetDragAndDropTranslation(ImportInfo.Pos, BoundsRect, &Offset))
02294     {
02295         Trans2DMatrix Xlate(Offset.x, Offset.y);
02296 
02297         if (UseLayers)
02298         {
02299             // Transform the range of nodes and then delete the range info.
02300             ImportRange.Transform(Xlate);
02301 
02302             // Transform the bounding rect too because we use it to invalidate the region.
02303             BoundsRect.Translate(Offset.x, Offset.y);
02304         }
02305         else
02306         {
02307             // Just transform the group node
02308             pGroup->Transform(Xlate);
02309         }
02310     }
02311 
02312     // Invalidate the region
02313 
02314     if (UseLayers)
02315     {
02316         // Importing with layers - invalidate the bounds of all the inserted nodes
02317         Success = ImportInfo.pOp->DoInvalidateRegion(ImportInfo.pSpread, BoundsRect);
02318     }
02319     else
02320     {
02321         // When importing as a group, we select the group node at the end, so we need to 
02322         // invalidate the blob bounding rect to get the redraw correct.
02323         Success = ImportInfo.pOp->DoInvalidateNodeRegion(pGroup, TRUE, FALSE);
02324     }
02325 
02326     if (!Success)
02327     {
02328         // Need to add tidy up code here.
02329         return FALSE;
02330     }
02331 
02332     // Make sure the node insertion position is in the correct place
02333     TheDocument->ResetInsertionPosition();
02334 
02335     return Success;
02336 }

EPSFilter::CC_DECLARE_DYNAMIC EPSFilter   )  [private]
 

void EPSFilter::CleanUpAfterExport  )  [protected, virtual]
 

Cleans up the memory allocated by EPSFilter::PrepareToImport() - used when the import process ends, either normally or abnormally.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/02/94
See also:
EPSFilter::PrepareToImport; EPSFilter::DoImport Scope: Private

Definition at line 4839 of file epsfiltr.cpp.

04840 {
04841 #ifdef DO_EXPORT
04842     // Get rid of our dynamic objects
04843     if (ExportDCPtr!=NULL)
04844         delete ExportDCPtr;
04845     ExportDCPtr = NULL;
04846 
04847     if (ExportRegion!=NULL)
04848         delete ExportRegion;
04849     ExportRegion = NULL;
04850 
04851     // Inform all the document components that we have finished exporting
04852     DocComponent *pComponent = TheDocument->EnumerateDocComponents(NULL);
04853 
04854     while (pComponent != NULL)
04855     {
04856         // Inform this document component that we have finished exporting
04857         pComponent->EPSEndExport(this);
04858 
04859         // Look for next doc component
04860         pComponent = TheDocument->EnumerateDocComponents(pComponent);
04861     }
04862 #endif
04863 }

void EPSFilter::CleanUpAfterImport BOOL  Successful  )  [protected, virtual]
 

Cleans up the memory allocated by EPSFilter::PrepareToImport() - used when the import process ends, either normally or abnormally.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/02/94
Parameters:
Successful,: TRUE => the import succeeded [INPUTS] FALSE => something went wrong with the import, so abandon all changes made.
See also:
EPSFilter::PrepareToImport; EPSFilter::DoImport Scope: Private

Reimplemented in AI5EPSFilter, PhotoShopEPSFilter, CamelotEPSFilter, FreeHandEPSFilter, and CamelotNativeEPSFilter.

Definition at line 1264 of file epsfiltr.cpp.

01265 {
01266     DeleteCurrentAttrs();
01267 
01268     // Get rid of file object
01269     EPSFile->DeinitLexer();
01270     EPSFile = NULL;
01271     TokenBuf = NULL;
01272 
01273     // get rid of anything on the graphic state stack
01274     TRACEUSER( "Ben", _T("Entries on GraphicStateStack = %d\n"), GraphicStateStack.GetCount());
01275     GraphicStateStack.DeleteAll();
01276 
01277     // Throw away handle to colour list component.
01278     pColours = NULL;
01279 
01280     // Inform all the document components that we have finished importing
01281     TheDocument->EPSEndImport(this, Successful);
01282     DocComponent *pComponent = TheDocument->EnumerateDocComponents(NULL);
01283 
01284     while (pComponent != NULL)
01285     {
01286         // Inform this document component that we have finished importing
01287         pComponent->EPSEndImport(this, Successful);
01288 
01289         // Look for next doc component
01290         pComponent = TheDocument->EnumerateDocComponents(pComponent);
01291     }
01292 
01293     // If imported with layers, make sure the top layer becomes the active one.
01294     if (Successful) // && UseLayers)
01295     {
01296         LayerSGallery::MakeTopLayerActive(ImportInfo.pSpread);
01297         BROADCAST_TO_ALL(SpreadMsg(ImportInfo.pSpread,SpreadMsg::LAYERCHANGES));
01298     }
01299 
01300     // Inform the user if we found any bad paths
01301     // BODGE: This is disabled while we are doing the clipart so the batch converter
01302     //        can run unattended.
01303     if (0 && InvalidPathFound)
01304         InformWarning(_R(IDT_IMPORT_BAD_PATH_FOUND));
01305 
01306     // Clean up import range items.
01307     ImportRange.DeleteAll();
01308 
01309     TheDocument->PostImport();
01310 }

BOOL EPSFilter::CorrectBinaryHeader CCLexFile pFile  ) 
 

Goes back to the binary header at the start of the file and fills in the correct values to all the fields.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/2/95
Parameters:
pFile - The file we are saving to [INPUTS]
Returns:
TRUE if it worked, FALSE if there was an error
See also:
EPSFilter::ExportBinaryHeader

Definition at line 4571 of file epsfiltr.cpp.

04572 {
04573 #ifdef DO_EXPORT
04574     INT32 Length = 0;
04575     INT32 Zero = 0;
04576 
04577     // Seek back to the first thing that needs changing
04578     // The Start of PostScript
04579     pFile->seek(4);
04580 
04581     // Write out the start of postscript (4-7)
04582     if (pFile->write(&EPSStart, 4).fail())
04583         return FALSE;
04584 
04585     // Write out the length of postscript (8-11)
04586     Length = EPSEnd - EPSStart;
04587     if (pFile->write(&Length, 4).fail())
04588         return FALSE;
04589 
04590     // Write out the Start of metafile (12-15)
04591     if (pFile->write(&Zero, 4).fail())
04592         return FALSE;
04593 
04594     // Write out the length of metafile (16-19)
04595     if (pFile->write(&Zero, 4).fail())
04596         return FALSE;
04597 
04598     // Write out the start of TIFF
04599     if (pFile->write(&PreviewStart, 4).fail())
04600         return FALSE;
04601 
04602     // Write out the legth of TIFF
04603     Length = PreviewEnd - PreviewStart;
04604     if (pFile->write(&Length, 4).fail())
04605         return FALSE;
04606 #endif
04607     // All seemed to work
04608     return TRUE;
04609 }

EPSExportDC * EPSFilter::CreateExportDC  )  [protected, virtual]
 

This allows the EPS filter to choose which sort of EPSExportDC to use. Most filters will use this default one, but some (Native Save/Load eps) will make use of a different ExportDC derived from EPSExportDC. This function simply returns the result of a 'new' and does no checking on the returned parameter. It is perfectly valid for this function to return NULL (meaning no ExportDC could be created) and the calling function should handle this appropriatly.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/12/94
Returns:
pointer to EPSExportDC or NULL

Reimplemented in CamelotNativeEPSFilter.

Definition at line 4710 of file epsfiltr.cpp.

04711 {
04712 #ifdef DO_EXPORT
04713     // Create and return a DC
04714     return new EPSExportDC(this);
04715 #else
04716     return NULL;
04717 #endif
04718 }

INT32 EPSFilter::DecodeHexString ADDR  pData,
INT32  Length,
INT32  nStart = 0
 

Treat the current token as a hex string, and decode it into binary data and place it in the buffer provided by the caller. No more than Length bytes should be placed in the buffer.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/08/94
Parameters:
Length - the maximum number of bytes to read from the hex string. [INPUTS] nStart - where in TokenBuf (the member that contains the semantic value of the token) to start the decoding
pData - the buffer to place the binary data into. [OUTPUTS]
Returns:
The number of bytes read from the current token. If an error occurs (i.e. invalid hex data) then -1 is returned.
See also:
EPSFilter::ImportBinary

Definition at line 5242 of file epsfiltr.cpp.

05243 {
05244     INT32 TokenLen = camStrlen(TokenBuf + nStart);
05245     INT32 Ofs = 0;
05246 
05247     // Assume hex strings are even-numbered in length for the moment
05248     ENSURE((TokenLen & 1) == 0, "Bad hex string length in DecodeHexString");
05249 
05250     // Work out how much of the string we should decode
05251     INT32 MaxOfs = Length * 2;
05252 
05253     // Decode the string two characters at a time
05254     for (INT32 i = nStart; (i < TokenLen) && (i < MaxOfs); i += 2)
05255     {
05256         TCHAR Ch = camToupper(TokenBuf[i]);
05257         BYTE Byte;
05258 
05259         // Decode first digit.
05260         if ((Ch >= '0') && (Ch <= '9'))
05261         {
05262             Byte = (BYTE) (Ch - '0');
05263         }
05264         else if ((Ch >= 'A') && (Ch <= 'F'))
05265         {
05266             Byte = (BYTE) (Ch - 'A') + 10;
05267         }
05268         else
05269         {
05270             // Error in hex data
05271             return -1;
05272         }
05273 
05274         Ch = camToupper(TokenBuf[i+1]);
05275         Byte <<= 4;
05276             
05277         // Decode swcond digit.
05278         if ((Ch >= '0') && (Ch <= '9'))
05279         {
05280             Byte |= (BYTE) (Ch - '0');
05281         }
05282         else if ((Ch >= 'A') && (Ch <= 'F'))
05283         {
05284             Byte |= (BYTE) (Ch - 'A') + 10;
05285         }
05286         else
05287         {
05288             // Error in hex data
05289             return -1;
05290         }
05291 
05292         pData[Ofs++] = Byte;
05293     }
05294 
05295     // How much data did we read?
05296     return Ofs;
05297 }

void EPSFilter::DecodeToken  )  [protected]
 

Decode the PostScript token that is contained in the 'TokenBuf' buffer. This is not used for strings, comments, or array brackets, but is used to detect tokens which are floating point numbers, integers, EPS keywords, or PostScript 'names' (e.g. font names). In other words, any token which cannot be identified solely by its first character.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/10/93
See also:
EPSFilter::GetToken Scope: Private

Definition at line 1781 of file epsfiltr.cpp.

01782 {
01783     //
01784     // Determine what we just read into TokenBuf.
01785     //
01786     ENSURE(camStrcmp(TokenBuf,_T("}bd")) != 0, "Found a }bd token!");
01787         
01788     // Not interested in comments, unless it's actually a strange token
01789     if (Token == EPSC_Comment)
01790     {
01791         LookUpToken();