1 /* 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 % Cristy % 17 % July 1992 % 18 % % 19 % % 20 % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % 21 % 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 /* 41 Include declarations. 42 */ 43 #include "MagickCore/studio.h" 44 #include "MagickCore/blob.h" 45 #include "MagickCore/blob-private.h" 46 #include "MagickCore/client.h" 47 #include "MagickCore/constitute.h" 48 #include "MagickCore/exception.h" 49 #include "MagickCore/exception-private.h" 50 #include "MagickCore/image.h" 51 #include "MagickCore/image-private.h" 52 #include "MagickCore/list.h" 53 #include "MagickCore/magick.h" 54 #include "MagickCore/memory_.h" 55 #include "MagickCore/monitor.h" 56 #include "MagickCore/monitor-private.h" 57 #include "MagickCore/option.h" 58 #include "MagickCore/resource_.h" 59 #include "MagickCore/quantum-private.h" 60 #include "MagickCore/static.h" 61 #include "MagickCore/string_.h" 62 #include "MagickCore/module.h" 63 #include "MagickCore/utility.h" 64 #include "MagickCore/xwindow-private.h" 65 #if defined(MAGICKCORE_GVC_DELEGATE) 66 #undef HAVE_CONFIG_H 67 #include <gvc.h> 68 static GVC_t 69 *graphic_context = (GVC_t *) NULL; 70 #endif 71 72 #if defined(MAGICKCORE_GVC_DELEGATE) 74 /* 75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 76 % % 77 % % 78 % % 79 % R e a d D O T I m a g e % 80 % % 81 % % 82 % % 83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 84 % 85 % ReadDOTImage() reads a Graphviz image file and returns it. It allocates 86 % the memory necessary for the new Image structure and returns a pointer to 87 % the new image. 88 % 89 % The format of the ReadDOTImage method is: 90 % 91 % Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception) 92 % 93 % A description of each parameter follows: 94 % 95 % o image_info: the image info. 96 % 97 % o exception: return any errors or warnings in this structure. 98 % 99 */ 100 static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception) 101 { 102 char 103 command[MagickPathExtent]; 104 105 const char 106 *option; 107 108 graph_t 109 *graph; 110 111 Image 112 *image; 113 114 ImageInfo 115 *read_info; 116 117 MagickBooleanType 118 status; 119 120 /* 121 Open image file. 122 */ 123 assert(image_info != (const ImageInfo *) NULL); 124 assert(image_info->signature == MagickCoreSignature); 125 if (image_info->debug != MagickFalse) 126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 127 image_info->filename); 128 assert(exception != (ExceptionInfo *) NULL); 129 assert(exception->signature == MagickCoreSignature); 130 assert(graphic_context != (GVC_t *) NULL); 131 image=AcquireImage(image_info,exception); 132 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); 133 if (status == MagickFalse) 134 return((Image *) NULL); 135 read_info=CloneImageInfo(image_info); 136 SetImageInfoBlob(read_info,(void *) NULL,0); 137 (void) CopyMagickString(read_info->magick,"SVG",MagickPathExtent); 138 (void) AcquireUniqueFilename(read_info->filename); 139 (void) FormatLocaleString(command,MagickPathExtent,"-Tsvg -o%s %s", 140 read_info->filename,image_info->filename); 141 #if !defined(WITH_CGRAPH) 142 graph=agread(GetBlobFileHandle(image)); 143 #else 144 graph=agread(GetBlobFileHandle(image),(Agdisc_t *) NULL); 145 #endif 146 if (graph == (graph_t *) NULL) 147 { 148 (void) RelinquishUniqueFileResource(read_info->filename); 149 return ((Image *) NULL); 150 } 151 option=GetImageOption(image_info,"dot:layout-engine"); 152 if (option == (const char *) NULL) 153 gvLayout(graphic_context,graph,(char *) "dot"); 154 else 155 gvLayout(graphic_context,graph,(char *) option); 156 gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename); 157 gvFreeLayout(graphic_context,graph); 158 agclose(graph); 159 /* 160 Read SVG graph. 161 */ 162 image=ReadImage(read_info,exception); 163 (void) RelinquishUniqueFileResource(read_info->filename); 164 read_info=DestroyImageInfo(read_info); 165 if (image == (Image *) NULL) 166 return((Image *) NULL); 167 return(GetFirstImageInList(image)); 168 } 169 #endif 170 171 /* 173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 174 % % 175 % % 176 % % 177 % R e g i s t e r D O T I m a g e % 178 % % 179 % % 180 % % 181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 182 % 183 % RegisterDOTImage() adds attributes for the Display Postscript image 184 % format to the list of supported formats. The attributes include the image 185 % format tag, a method to read and/or write the format, whether the format 186 % supports the saving of more than one frame to the same file or blob, 187 % whether the format supports native in-memory I/O, and a brief 188 % description of the format. 189 % 190 % The format of the RegisterDOTImage method is: 191 % 192 % size_t RegisterDOTImage(void) 193 % 194 */ 195 ModuleExport size_t RegisterDOTImage(void) 196 { 197 MagickInfo 198 *entry; 199 200 entry=AcquireMagickInfo("DOT","DOT","Graphviz"); 201 #if defined(MAGICKCORE_GVC_DELEGATE) 202 entry->decoder=(DecodeImageHandler *) ReadDOTImage; 203 #endif 204 entry->flags^=CoderBlobSupportFlag; 205 (void) RegisterMagickInfo(entry); 206 entry=AcquireMagickInfo("DOT","GV","Graphviz"); 207 #if defined(MAGICKCORE_GVC_DELEGATE) 208 entry->decoder=(DecodeImageHandler *) ReadDOTImage; 209 #endif 210 entry->flags^=CoderBlobSupportFlag; 211 (void) RegisterMagickInfo(entry); 212 #if defined(MAGICKCORE_GVC_DELEGATE) 213 graphic_context=gvContext(); 214 #endif 215 return(MagickImageCoderSignature); 216 } 217 218 /* 220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 221 % % 222 % % 223 % % 224 % U n r e g i s t e r D O T I m a g e % 225 % % 226 % % 227 % % 228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 229 % 230 % UnregisterDOTImage() removes format registrations made by the 231 % DOT module from the list of supported formats. 232 % 233 % The format of the UnregisterDOTImage method is: 234 % 235 % UnregisterDOTImage(void) 236 % 237 */ 238 ModuleExport void UnregisterDOTImage(void) 239 { 240 (void) UnregisterMagickInfo("GV"); 241 (void) UnregisterMagickInfo("DOT"); 242 #if defined(MAGICKCORE_GVC_DELEGATE) 243 if (graphic_context != (GVC_t *) NULL) 244 { 245 gvFreeContext(graphic_context); 246 graphic_context=(GVC_t *) NULL; 247 } 248 #endif 249 } 250