cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 45ef08f | 2012-12-07 13:13:34 +0000 | [diff] [blame] | 20 | % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 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" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 64 | #if defined(MAGICKCORE_GVC_DELEGATE) |
| 65 | #undef HAVE_CONFIG_H |
| 66 | #include <gvc.h> |
| 67 | static 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 | */ |
| 98 | static 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); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 128 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 129 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 130 | if (status == MagickFalse) |
| 131 | return((Image *) NULL); |
| 132 | read_info=CloneImageInfo(image_info); |
cristy | 98f91ec | 2011-02-03 01:15:48 +0000 | [diff] [blame] | 133 | SetImageInfoBlob(read_info,(void *) NULL,0); |
cristy | b9a7aff | 2010-06-08 14:56:37 +0000 | [diff] [blame] | 134 | (void) CopyMagickString(read_info->magick,"SVG",MaxTextExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 135 | (void) AcquireUniqueFilename(read_info->filename); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 136 | (void) FormatLocaleString(command,MaxTextExtent,"-Tsvg -o%s %s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 137 | read_info->filename,image_info->filename); |
cristy | 7f47ac6 | 2013-02-10 14:16:17 +0000 | [diff] [blame^] | 138 | graph=agread(GetBlobFileHandle(image),(Agdisc_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 139 | if (graph == (graph_t *) NULL) |
| 140 | return ((Image *) NULL); |
| 141 | option=GetImageOption(image_info,"dot:layout-engine"); |
| 142 | if (option == (const char *) NULL) |
| 143 | gvLayout(graphic_context,graph,(char *) "dot"); |
| 144 | else |
| 145 | gvLayout(graphic_context,graph,(char *) option); |
cristy | b9a7aff | 2010-06-08 14:56:37 +0000 | [diff] [blame] | 146 | gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 147 | gvFreeLayout(graphic_context,graph); |
| 148 | /* |
cristy | b9a7aff | 2010-06-08 14:56:37 +0000 | [diff] [blame] | 149 | Read SVG graph. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | */ |
| 151 | image=ReadImage(read_info,exception); |
| 152 | (void) RelinquishUniqueFileResource(read_info->filename); |
| 153 | read_info=DestroyImageInfo(read_info); |
| 154 | if (image == (Image *) NULL) |
| 155 | return((Image *) NULL); |
| 156 | return(GetFirstImageInList(image)); |
| 157 | } |
| 158 | #endif |
| 159 | |
| 160 | /* |
| 161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 162 | % % |
| 163 | % % |
| 164 | % % |
| 165 | % R e g i s t e r D O T I m a g e % |
| 166 | % % |
| 167 | % % |
| 168 | % % |
| 169 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 170 | % |
| 171 | % RegisterDOTImage() adds attributes for the Display Postscript image |
| 172 | % format to the list of supported formats. The attributes include the image |
| 173 | % format tag, a method to read and/or write the format, whether the format |
| 174 | % supports the saving of more than one frame to the same file or blob, |
| 175 | % whether the format supports native in-memory I/O, and a brief |
| 176 | % description of the format. |
| 177 | % |
| 178 | % The format of the RegisterDOTImage method is: |
| 179 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 180 | % size_t RegisterDOTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 181 | % |
| 182 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 183 | ModuleExport size_t RegisterDOTImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | { |
| 185 | MagickInfo |
| 186 | *entry; |
| 187 | |
| 188 | entry=SetMagickInfo("DOT"); |
| 189 | #if defined(MAGICKCORE_GVC_DELEGATE) |
| 190 | entry->decoder=(DecodeImageHandler *) ReadDOTImage; |
| 191 | #endif |
| 192 | entry->blob_support=MagickFalse; |
| 193 | entry->description=ConstantString("Graphviz"); |
| 194 | entry->module=ConstantString("DOT"); |
| 195 | (void) RegisterMagickInfo(entry); |
cristy | 7f47ac6 | 2013-02-10 14:16:17 +0000 | [diff] [blame^] | 196 | entry=SetMagickInfo("GV"); |
| 197 | #if defined(MAGICKCORE_GVC_DELEGATE) |
| 198 | entry->decoder=(DecodeImageHandler *) ReadDOTImage; |
| 199 | #endif |
| 200 | entry->blob_support=MagickFalse; |
| 201 | entry->description=ConstantString("Graphviz"); |
| 202 | entry->module=ConstantString("DOT"); |
| 203 | (void) RegisterMagickInfo(entry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 204 | #if defined(MAGICKCORE_GVC_DELEGATE) |
| 205 | graphic_context=gvContext(); |
| 206 | #endif |
| 207 | return(MagickImageCoderSignature); |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 212 | % % |
| 213 | % % |
| 214 | % % |
| 215 | % U n r e g i s t e r D O T I m a g e % |
| 216 | % % |
| 217 | % % |
| 218 | % % |
| 219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 220 | % |
| 221 | % UnregisterDOTImage() removes format registrations made by the |
| 222 | % DOT module from the list of supported formats. |
| 223 | % |
| 224 | % The format of the UnregisterDOTImage method is: |
| 225 | % |
| 226 | % UnregisterDOTImage(void) |
| 227 | % |
| 228 | */ |
| 229 | ModuleExport void UnregisterDOTImage(void) |
| 230 | { |
cristy | 7f47ac6 | 2013-02-10 14:16:17 +0000 | [diff] [blame^] | 231 | (void) UnregisterMagickInfo("GV"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 232 | (void) UnregisterMagickInfo("DOT"); |
| 233 | #if defined(MAGICKCORE_GVC_DELEGATE) |
| 234 | gvFreeContext(graphic_context); |
| 235 | #endif |
| 236 | } |