2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Graphviz DOT Format %
20 % Copyright 1999-2010 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 % http://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 "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)
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[MaxTextExtent];
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);
133 (void) CopyMagickString(read_info->magick,"PS",MaxTextExtent);
134 (void) AcquireUniqueFilename(read_info->filename);
135 (void) FormatMagickString(command,MaxTextExtent,"-Tps2 -o%s %s",
136 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");
144 gvLayout(graphic_context,graph,(char *) option);
145 gvRenderFilename(graphic_context,graph,(char *) "ps2",read_info->filename);
146 gvFreeLayout(graphic_context,graph);
148 Read Postscript graph.
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));
160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 % R e g i s t e r D O T I m a g e %
168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
177 % The format of the RegisterDOTImage method is:
179 % size_t RegisterDOTImage(void)
182 ModuleExport size_t RegisterDOTImage(void)
187 entry=SetMagickInfo("DOT");
188 #if defined(MAGICKCORE_GVC_DELEGATE)
189 entry->decoder=(DecodeImageHandler *) ReadDOTImage;
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();
198 return(MagickImageCoderSignature);
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 % U n r e g i s t e r D O T I m a g e %
210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 % UnregisterDOTImage() removes format registrations made by the
213 % DOT module from the list of supported formats.
215 % The format of the UnregisterDOTImage method is:
217 % UnregisterDOTImage(void)
220 ModuleExport void UnregisterDOTImage(void)
222 (void) UnregisterMagickInfo("DOT");
223 #if defined(MAGICKCORE_GVC_DELEGATE)
224 gvFreeContext(graphic_context);