2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Graphviz DOT Format %
20 % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % https://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/client.h"
46 #include "MagickCore/constitute.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/image.h"
50 #include "MagickCore/image-private.h"
51 #include "MagickCore/list.h"
52 #include "MagickCore/magick.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/monitor.h"
55 #include "MagickCore/monitor-private.h"
56 #include "MagickCore/option.h"
57 #include "MagickCore/resource_.h"
58 #include "MagickCore/quantum-private.h"
59 #include "MagickCore/static.h"
60 #include "MagickCore/string_.h"
61 #include "MagickCore/module.h"
62 #include "MagickCore/utility.h"
63 #include "MagickCore/xwindow-private.h"
64 #if defined(MAGICKCORE_GVC_DELEGATE)
68 *graphic_context = (GVC_t *) NULL;
71 #if defined(MAGICKCORE_GVC_DELEGATE)
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % R e a d D O T I m a g e %
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
87 % The format of the ReadDOTImage method is:
89 % Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
91 % A description of each parameter follows:
93 % o image_info: the image info.
95 % o exception: return any errors or warnings in this structure.
98 static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
101 command[MagickPathExtent];
121 assert(image_info != (const ImageInfo *) NULL);
122 assert(image_info->signature == MagickCoreSignature);
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 == MagickCoreSignature);
128 assert(graphic_context != (GVC_t *) NULL);
129 image=AcquireImage(image_info,exception);
130 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
131 if (status == MagickFalse)
132 return((Image *) NULL);
133 read_info=CloneImageInfo(image_info);
134 SetImageInfoBlob(read_info,(void *) NULL,0);
135 (void) CopyMagickString(read_info->magick,"SVG",MagickPathExtent);
136 (void) AcquireUniqueFilename(read_info->filename);
137 (void) FormatLocaleString(command,MagickPathExtent,"-Tsvg -o%s %s",
138 read_info->filename,image_info->filename);
139 #if !defined(WITH_CGRAPH)
140 graph=agread(GetBlobFileHandle(image));
142 graph=agread(GetBlobFileHandle(image),(Agdisc_t *) NULL);
144 if (graph == (graph_t *) NULL)
146 (void) RelinquishUniqueFileResource(read_info->filename);
147 return ((Image *) NULL);
149 option=GetImageOption(image_info,"dot:layout-engine");
150 if (option == (const char *) NULL)
151 gvLayout(graphic_context,graph,(char *) "dot");
153 gvLayout(graphic_context,graph,(char *) option);
154 gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename);
155 gvFreeLayout(graphic_context,graph);
160 image=ReadImage(read_info,exception);
161 (void) RelinquishUniqueFileResource(read_info->filename);
162 read_info=DestroyImageInfo(read_info);
163 if (image == (Image *) NULL)
164 return((Image *) NULL);
165 return(GetFirstImageInList(image));
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 % R e g i s t e r D O T I m a g e %
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 % RegisterDOTImage() adds attributes for the Display Postscript image
181 % format to the list of supported formats. The attributes include the image
182 % format tag, a method to read and/or write the format, whether the format
183 % supports the saving of more than one frame to the same file or blob,
184 % whether the format supports native in-memory I/O, and a brief
185 % description of the format.
187 % The format of the RegisterDOTImage method is:
189 % size_t RegisterDOTImage(void)
192 ModuleExport size_t RegisterDOTImage(void)
197 entry=AcquireMagickInfo("DOT","DOT","Graphviz");
198 #if defined(MAGICKCORE_GVC_DELEGATE)
199 entry->decoder=(DecodeImageHandler *) ReadDOTImage;
201 entry->flags^=CoderBlobSupportFlag;
202 (void) RegisterMagickInfo(entry);
203 entry=AcquireMagickInfo("DOT","GV","Graphviz");
204 #if defined(MAGICKCORE_GVC_DELEGATE)
205 entry->decoder=(DecodeImageHandler *) ReadDOTImage;
207 entry->flags^=CoderBlobSupportFlag;
208 (void) RegisterMagickInfo(entry);
209 #if defined(MAGICKCORE_GVC_DELEGATE)
210 graphic_context=gvContext();
212 return(MagickImageCoderSignature);
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 % U n r e g i s t e r D O T I m a g e %
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % UnregisterDOTImage() removes format registrations made by the
227 % DOT module from the list of supported formats.
229 % The format of the UnregisterDOTImage method is:
231 % UnregisterDOTImage(void)
234 ModuleExport void UnregisterDOTImage(void)
236 (void) UnregisterMagickInfo("GV");
237 (void) UnregisterMagickInfo("DOT");
238 #if defined(MAGICKCORE_GVC_DELEGATE)
239 if (graphic_context != (GVC_t *) NULL)
241 gvFreeContext(graphic_context);
242 graphic_context=(GVC_t *) NULL;