readeps.cpp

Go to the documentation of this file.
00001 // $Id: readeps.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 /*
00100 
00101 
00102 */
00103 
00104 
00105 #include "camtypes.h"
00106 
00107 #include <fstream.h>
00108 #include <strstrea.h>
00109 #include <ctype.h>
00110 
00111 //#include "node.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "nodepath.h"
00113 //#include "docrect.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 #include "lineattr.h"        
00115 //#include "doccolor.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00117 
00118 #include "readeps.h"
00119 
00120 DECLARE_SOURCE("$Revision: 1282 $");
00121 
00122 // Scale factor of ArtWorks EPS coords -> Camelot DocCoords
00123 const INT32 ScaleFactor = 1000;
00124 
00125 #if 0
00126 /********************************************************************************************
00127 
00128 >   void ReadEPSData(char *FileName, Node *Parent, DocRect& PageRect, BOOL AddAttrs)
00129 
00130     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00131     Created:    20/7/93
00132     Inputs:     FileName - name of EPS file to read.
00133                         Parent - The node to add the EPS data under.
00134                         PageRect - The coordinates of the page to put the data onto.
00135                         AddAttrs - if TRUE, random colour and line width attributes will be added to
00136                         the lines.
00137     Outputs:    -
00138     Returns:    -
00139     Purpose:    Read an ArtWorks EPS file and convert it to paths for use by Camelot by
00140                         constructing path objects in the document tree.  The ArtWorks EPS files
00141                         must be filtered so they only contain moveto, lineto, and curveto
00142                         commands. This can be done with egrep as follows:
00143                 
00144                         egrep " c$| l$| m$" SrcEPS > DestEPS
00145                 
00146     Errors:     -
00147     SeeAlso:    Document
00148 
00149 ********************************************************************************************/
00150 
00151 void ReadEPSData(char *FileName, Node *Parent, DocRect& PageRect, BOOL AddAttrs)
00152 {
00153     // Get the directory of the .EXE file.
00154     char Appname[_MAX_PATH];
00155     GetModuleFileName(AfxGetInstanceHandle(), Appname, _MAX_PATH-1);
00156     char Drive[_MAX_DRIVE];
00157     char Dir  [_MAX_DIR  ];
00158     char Fname[_MAX_FNAME];
00159     char Ext  [_MAX_EXT  ];
00160     _tsplitpath(Appname, Drive, Dir, Fname, Ext);
00161      
00162     // Use this location to construct the full pathname for EPS file
00163     char FullFileName[_MAX_PATH];
00164     camStrcpy(FullFileName, Drive);
00165     camStrcat(FullFileName, Dir);
00166     camStrcatl(FullFileName, FileName);
00167     
00168     // Array to hold coords that are read in from the file.
00169     DocCoord Coords[4];
00170     DocCoord StartPoint;
00171     DocCoord LastPoint;
00172     INT32    SegmentCount = 0;          // counts how long the line is
00173     
00174     // Pointer to path node
00175     NodePath *MyPath = NULL;
00176 
00177     // Path tag
00178     INT32 *Current;
00179     
00180     // Open the data file...    
00181     ifstream in(FullFileName, ios::in | ios::nocreate);
00182     
00183     if (in.is_open())
00184     {
00185         char buf[256];
00186         while (!in.eof())
00187         {
00188             // Read in the next line
00189             in.getline(buf, 255);
00190             
00191             // Prepare to parse the line
00192             unsigned i = 0;
00193             istrstream line(buf);
00194             
00195             BOOL CmdExecuted = FALSE;
00196             
00197             while ((!CmdExecuted) && (i <= 3))
00198             {
00199                 // Read in the next field
00200                 line.eatwhite();
00201 
00202                 // Is it a coordinate or command?
00203                 if (!isdigit(line.peek()))
00204                 {
00205                     // Didn't find an numeric - must be a command
00206                     char Command;
00207                     line >> Command;
00208                     if (Command == 'm')
00209                     {
00210                         // MoveTo - clean up current path and start a new one
00211                         if (SegmentCount < 2  &&  MyPath != NULL)
00212                         {
00213                             MyPath->CascadeDelete();
00214                             MyPath = NULL;
00215                         }
00216                         
00217                         if (MyPath != NULL)
00218                         {
00219                             MyPath->UpdateInkBoundingRect();
00220                             
00221                             if ( LastPoint.x == StartPoint.x  &&  LastPoint.y == StartPoint.y )
00222                                 MyPath->InkPath.SetFilled( TRUE );
00223                             else
00224                                 MyPath->InkPath.SetFilled( FALSE );
00225                             
00226                             //  Testing node attributes here 
00227                             //  ****************************
00228                             if (AddAttrs)
00229                             {
00230                                 DocColour Random((INT32)(rand()%255),
00231                                                  (INT32)(rand()%255),
00232                                                  (INT32)(rand()%255));
00233         
00234                                 AttrFillColour* Attr1 = new AttrFillColour(MyPath, LASTCHILD);
00235                                 Attr1->FillColour = DocColour(Random);
00236     
00237                                 AttrLineColour* Attr2 = new AttrLineColour(MyPath, LASTCHILD);
00238                                 Attr2->LineColour = DocColour(Random);
00239                                                         
00240                                 AttrLineWidth* Attr3 =  new AttrLineWidth(MyPath, LASTCHILD); 
00241                                 Attr3->LineWidth = (MILLIPOINT)(750*((rand()%3) + 1)); 
00242                             }
00243                         }
00244 
00245                         MyPath = new NodePath(Parent, LASTCHILD); 
00246                         if (!MyPath->SetUpPath())
00247                         {
00248                             MyPath->CascadeDelete();
00249                             ENSURE(FALSE, "ReadEPSData: Run out of memory");
00250                             return;
00251                         }
00252                             
00253                         Current = MyPath->InkPath.FindStartOfPath();
00254                         Current = MyPath->InkPath.InsertMoveTo(Coords[0], Current);
00255                         StartPoint = Coords[0];
00256                         LastPoint = StartPoint;
00257                         SegmentCount = 1;
00258                     }
00259                     else if (Command == 'l')
00260                     {
00261                         // LineTo
00262                         Current = MyPath->InkPath.InsertLineTo(Coords[0], Current);
00263                         LastPoint = Coords[0];
00264                         SegmentCount++;
00265                     }
00266                     else if (Command == 'c')
00267                     {
00268                         // CurveTo
00269                         Current = MyPath->InkPath.InsertCurveTo(Coords[0], Coords[1],
00270                                                                 Coords[2], Current);
00271                         LastPoint = Coords[0];
00272                         SegmentCount++;
00273                     }
00274                     else if (IsUserName("Tim"))
00275                     {
00276                         TRACE( _T("ReadEPSData: unknown command in path data file: '%c'\n"),
00277                               Command);
00278                     }
00279                     
00280                     CmdExecuted = TRUE;
00281                 }
00282                 else
00283                 {
00284                     // Coordinate - get the x and y coords, and scale them up
00285                     float NewCoord;
00286 
00287                     line >> NewCoord;
00288                     Coords[i].x = (INT32) (NewCoord * ScaleFactor);
00289                     Coords[i].x += PageRect.lo.x;
00290                     
00291                     line >> NewCoord;
00292                     Coords[i].y = (INT32) (NewCoord * ScaleFactor);
00293                     Coords[i].y += PageRect.lo.y;
00294 
00295                     i++;
00296                 }
00297             }
00298             if ((!CmdExecuted) && IsUserName("Tim"))
00299             {
00300                 TRACE( _T("Document constructor: Too many coords in path data file.\n"));
00301                 break;
00302             }
00303         }
00304         // Set the bounding rectangle for the last path created.
00305         if (SegmentCount < 2)
00306         {
00307             MyPath->CascadeDelete();
00308             MyPath = NULL;
00309         }
00310                         
00311         if (MyPath != NULL)
00312         {
00313             MyPath->UpdateInkBoundingRect(); 
00314             
00315             if ( LastPoint.x == StartPoint.x  &&  LastPoint.y == StartPoint.y )
00316                 MyPath->InkPath.SetFilled( TRUE );
00317             else
00318                 MyPath->InkPath.SetFilled( FALSE );
00319             
00320 
00321             //  Testing node attributes here 
00322             //  ****************************
00323             if (AddAttrs)
00324             {
00325                 DocColour Random((INT32)(rand()%255),
00326                                  (INT32)(rand()%255),
00327                                  (INT32)(rand()%255));
00328         
00329                 AttrFillColour* Attr1 = new AttrFillColour(MyPath, LASTCHILD);
00330                 Attr1->FillColour = DocColour(Random);
00331     
00332                 AttrLineColour* Attr2 = new AttrLineColour(MyPath, LASTCHILD);
00333                                                         
00334                 AttrLineWidth* Attr3 =  new AttrLineWidth(MyPath, LASTCHILD); 
00335                 Attr3->LineWidth = (MILLIPOINT)(750*((rand()%3) + 1)); 
00336             }
00337         }
00338     }
00339     else if (IsUserName("Tim"))
00340         TRACE( _T("Could not open EPS file '%s'\n"), FullFileName);
00341 }
00342 
00343 #endif

Generated on Sat Nov 10 03:48:49 2007 for Camelot by  doxygen 1.4.4