blob: 78a6bb81e6edf5b89c164d7074eb43a49a6f64b8 [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 %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
Cristyf6ff9ea2016-12-05 09:53:35 -050020% Copyright 1999-2017 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*/
cristy4c08aed2011-07-01 19:47:50 +000042#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"
cristy3ed852e2009-09-05 21:47:34 +000064#if defined(MAGICKCORE_GVC_DELEGATE)
65#undef HAVE_CONFIG_H
66#include <gvc.h>
67static GVC_t
Cristy7f8db422015-09-21 18:18:44 -040068 *graphic_context = (GVC_t *) NULL;
cristy3ed852e2009-09-05 21:47:34 +000069#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
cristy151b66d2015-04-15 10:50:31 +0000101 command[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +0000102
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);
cristye1c94d92015-06-28 12:16:33 +0000122 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000123 if (image_info->debug != MagickFalse)
124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
125 image_info->filename);
126 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000127 assert(exception->signature == MagickCoreSignature);
dirk52ec99e2015-09-22 07:18:34 +0200128 assert(graphic_context != (GVC_t *) NULL);
cristy9950d572011-10-01 18:22:35 +0000129 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000130 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
131 if (status == MagickFalse)
132 return((Image *) NULL);
133 read_info=CloneImageInfo(image_info);
cristy98f91ec2011-02-03 01:15:48 +0000134 SetImageInfoBlob(read_info,(void *) NULL,0);
cristy151b66d2015-04-15 10:50:31 +0000135 (void) CopyMagickString(read_info->magick,"SVG",MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000136 (void) AcquireUniqueFilename(read_info->filename);
cristy151b66d2015-04-15 10:50:31 +0000137 (void) FormatLocaleString(command,MagickPathExtent,"-Tsvg -o%s %s",
cristy3ed852e2009-09-05 21:47:34 +0000138 read_info->filename,image_info->filename);
cristy371f49b2013-02-10 16:02:04 +0000139#if !defined(WITH_CGRAPH)
140 graph=agread(GetBlobFileHandle(image));
141#else
cristy7f47ac62013-02-10 14:16:17 +0000142 graph=agread(GetBlobFileHandle(image),(Agdisc_t *) NULL);
cristy371f49b2013-02-10 16:02:04 +0000143#endif
cristy3ed852e2009-09-05 21:47:34 +0000144 if (graph == (graph_t *) NULL)
dirkce6b1222014-11-06 21:09:46 +0000145 {
146 (void) RelinquishUniqueFileResource(read_info->filename);
147 return ((Image *) NULL);
148 }
cristy092ec8d2013-04-26 13:46:22 +0000149 option=GetImageOption(image_info,"dot:layout-engine");
cristy3ed852e2009-09-05 21:47:34 +0000150 if (option == (const char *) NULL)
151 gvLayout(graphic_context,graph,(char *) "dot");
152 else
153 gvLayout(graphic_context,graph,(char *) option);
cristyb9a7aff2010-06-08 14:56:37 +0000154 gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename);
cristy3ed852e2009-09-05 21:47:34 +0000155 gvFreeLayout(graphic_context,graph);
cristy371f49b2013-02-10 16:02:04 +0000156 agclose(graph);
cristy3ed852e2009-09-05 21:47:34 +0000157 /*
cristyb9a7aff2010-06-08 14:56:37 +0000158 Read SVG graph.
cristy3ed852e2009-09-05 21:47:34 +0000159 */
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));
166}
167#endif
168
169/*
170%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171% %
172% %
173% %
174% R e g i s t e r D O T I m a g e %
175% %
176% %
177% %
178%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179%
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.
186%
187% The format of the RegisterDOTImage method is:
188%
cristybb503372010-05-27 20:51:26 +0000189% size_t RegisterDOTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000190%
191*/
cristybb503372010-05-27 20:51:26 +0000192ModuleExport size_t RegisterDOTImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000193{
194 MagickInfo
195 *entry;
196
dirk06b627a2015-04-06 18:59:17 +0000197 entry=AcquireMagickInfo("DOT","DOT","Graphviz");
cristy3ed852e2009-09-05 21:47:34 +0000198#if defined(MAGICKCORE_GVC_DELEGATE)
199 entry->decoder=(DecodeImageHandler *) ReadDOTImage;
200#endif
dirk08e9a112015-02-22 01:51:41 +0000201 entry->flags^=CoderBlobSupportFlag;
cristy3ed852e2009-09-05 21:47:34 +0000202 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +0000203 entry=AcquireMagickInfo("DOT","GV","Graphviz");
cristy7f47ac62013-02-10 14:16:17 +0000204#if defined(MAGICKCORE_GVC_DELEGATE)
205 entry->decoder=(DecodeImageHandler *) ReadDOTImage;
206#endif
dirk08e9a112015-02-22 01:51:41 +0000207 entry->flags^=CoderBlobSupportFlag;
cristy7f47ac62013-02-10 14:16:17 +0000208 (void) RegisterMagickInfo(entry);
cristy3ed852e2009-09-05 21:47:34 +0000209#if defined(MAGICKCORE_GVC_DELEGATE)
210 graphic_context=gvContext();
211#endif
212 return(MagickImageCoderSignature);
213}
214
215/*
216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217% %
218% %
219% %
220% U n r e g i s t e r D O T I m a g e %
221% %
222% %
223% %
224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225%
226% UnregisterDOTImage() removes format registrations made by the
227% DOT module from the list of supported formats.
228%
229% The format of the UnregisterDOTImage method is:
230%
231% UnregisterDOTImage(void)
232%
233*/
234ModuleExport void UnregisterDOTImage(void)
235{
cristy7f47ac62013-02-10 14:16:17 +0000236 (void) UnregisterMagickInfo("GV");
cristy3ed852e2009-09-05 21:47:34 +0000237 (void) UnregisterMagickInfo("DOT");
238#if defined(MAGICKCORE_GVC_DELEGATE)
dirk52ec99e2015-09-22 07:18:34 +0200239 if (graphic_context != (GVC_t *) NULL)
240 {
241 gvFreeContext(graphic_context);
242 graphic_context=(GVC_t *) NULL;
243 }
cristy3ed852e2009-09-05 21:47:34 +0000244#endif
245}