blob: b82b168629526dabf89c499c0eae1f7871cff202 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% DDDD OOO TTTTT %
7% D D O O T %
8% D D O O T %
9% D D O O T %
10% DDDD OOO T %
11% %
12% %
13% Read/Write Graphviz DOT Format %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
42#include "magick/studio.h"
43#include "magick/blob.h"
44#include "magick/blob-private.h"
45#include "magick/client.h"
46#include "magick/constitute.h"
47#include "magick/exception.h"
48#include "magick/exception-private.h"
49#include "magick/image.h"
50#include "magick/image-private.h"
51#include "magick/list.h"
52#include "magick/magick.h"
53#include "magick/memory_.h"
54#include "magick/monitor.h"
55#include "magick/monitor-private.h"
56#include "magick/option.h"
57#include "magick/resource_.h"
58#include "magick/quantum-private.h"
59#include "magick/static.h"
60#include "magick/string_.h"
61#include "magick/module.h"
62#include "magick/utility.h"
63#include "magick/xwindow-private.h"
64#if defined(MAGICKCORE_GVC_DELEGATE)
65#undef HAVE_CONFIG_H
66#include <gvc.h>
67static GVC_t
68 *graphic_context;
69#endif
70
71#if defined(MAGICKCORE_GVC_DELEGATE)
72/*
73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74% %
75% %
76% %
77% R e a d D O T I m a g e %
78% %
79% %
80% %
81%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82%
83% ReadDOTImage() reads a Graphviz image file and returns it. It allocates
84% the memory necessary for the new Image structure and returns a pointer to
85% the new image.
86%
87% The format of the ReadDOTImage method is:
88%
89% Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
90%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
95% o exception: return any errors or warnings in this structure.
96%
97*/
98static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
99{
100 char
101 command[MaxTextExtent];
102
103 const char
104 *option;
105
106 graph_t
107 *graph;
108
109 Image
110 *image;
111
112 ImageInfo
113 *read_info;
114
115 MagickBooleanType
116 status;
117
118 /*
119 Open image file.
120 */
121 assert(image_info != (const ImageInfo *) NULL);
122 assert(image_info->signature == MagickSignature);
123 if (image_info->debug != MagickFalse)
124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
125 image_info->filename);
126 assert(exception != (ExceptionInfo *) NULL);
127 assert(exception->signature == MagickSignature);
128 image=AcquireImage(image_info);
129 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
130 if (status == MagickFalse)
131 return((Image *) NULL);
132 read_info=CloneImageInfo(image_info);
cristyb9a7aff2010-06-08 14:56:37 +0000133 (void) CopyMagickString(read_info->magick,"SVG",MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +0000134 (void) AcquireUniqueFilename(read_info->filename);
cristyb9a7aff2010-06-08 14:56:37 +0000135 (void) FormatMagickString(command,MaxTextExtent,"-Tsvg -o%s %s",
cristy3ed852e2009-09-05 21:47:34 +0000136 read_info->filename,image_info->filename);
137 graph=agread(GetBlobFileHandle(image));
138 if (graph == (graph_t *) NULL)
139 return ((Image *) NULL);
140 option=GetImageOption(image_info,"dot:layout-engine");
141 if (option == (const char *) NULL)
142 gvLayout(graphic_context,graph,(char *) "dot");
143 else
144 gvLayout(graphic_context,graph,(char *) option);
cristyb9a7aff2010-06-08 14:56:37 +0000145 gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename);
cristy3ed852e2009-09-05 21:47:34 +0000146 gvFreeLayout(graphic_context,graph);
147 /*
cristyb9a7aff2010-06-08 14:56:37 +0000148 Read SVG graph.
cristy3ed852e2009-09-05 21:47:34 +0000149 */
150 image=ReadImage(read_info,exception);
151 (void) RelinquishUniqueFileResource(read_info->filename);
152 read_info=DestroyImageInfo(read_info);
153 if (image == (Image *) NULL)
154 return((Image *) NULL);
155 return(GetFirstImageInList(image));
156}
157#endif
158
159/*
160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161% %
162% %
163% %
164% R e g i s t e r D O T I m a g e %
165% %
166% %
167% %
168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169%
170% RegisterDOTImage() adds attributes for the Display Postscript image
171% format to the list of supported formats. The attributes include the image
172% format tag, a method to read and/or write the format, whether the format
173% supports the saving of more than one frame to the same file or blob,
174% whether the format supports native in-memory I/O, and a brief
175% description of the format.
176%
177% The format of the RegisterDOTImage method is:
178%
cristybb503372010-05-27 20:51:26 +0000179% size_t RegisterDOTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000180%
181*/
cristybb503372010-05-27 20:51:26 +0000182ModuleExport size_t RegisterDOTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000183{
184 MagickInfo
185 *entry;
186
187 entry=SetMagickInfo("DOT");
188#if defined(MAGICKCORE_GVC_DELEGATE)
189 entry->decoder=(DecodeImageHandler *) ReadDOTImage;
190#endif
191 entry->blob_support=MagickFalse;
192 entry->description=ConstantString("Graphviz");
193 entry->module=ConstantString("DOT");
194 (void) RegisterMagickInfo(entry);
195#if defined(MAGICKCORE_GVC_DELEGATE)
196 graphic_context=gvContext();
197#endif
198 return(MagickImageCoderSignature);
199}
200
201/*
202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203% %
204% %
205% %
206% U n r e g i s t e r D O T I m a g e %
207% %
208% %
209% %
210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211%
212% UnregisterDOTImage() removes format registrations made by the
213% DOT module from the list of supported formats.
214%
215% The format of the UnregisterDOTImage method is:
216%
217% UnregisterDOTImage(void)
218%
219*/
220ModuleExport void UnregisterDOTImage(void)
221{
222 (void) UnregisterMagickInfo("DOT");
223#if defined(MAGICKCORE_GVC_DELEGATE)
224 gvFreeContext(graphic_context);
225#endif
226}