2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Windows Metafile Format %
20 % Copyright 1999-2011 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 #include "magick/studio.h"
41 #include "magick/property.h"
42 #include "magick/blob.h"
43 #include "magick/blob-private.h"
44 #include "magick/color.h"
45 #include "magick/color-private.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/log.h"
53 #include "magick/magick.h"
54 #include "magick/memory_.h"
55 #include "magick/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/paint.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/type.h"
63 #include "magick/module.h"
64 #include "wand/MagickWand.h"
66 #if defined(MAGICKCORE_WMF_DELEGATE)
67 #include "libwmf/api.h"
68 #include "libwmf/eps.h"
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 % R e a d W M F I m a g e %
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % ReadWMFImage() reads an Windows Metafile image file and returns it. It
82 % allocates the memory necessary for the new Image structure and returns a
83 % pointer to the new image.
85 % The format of the ReadWMFImage method is:
87 % Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
89 % A description of each parameter follows:
91 % o image_info: the image info.
93 % o exception: return any errors or warnings in this structure.
97 static int WMFReadBlob(void *image)
99 return(ReadBlobByte((Image *) image));
102 static int WMFSeekBlob(void *image,long offset)
104 return((int) SeekBlob((Image *) image,(MagickOffsetType) offset,SEEK_SET));
107 static long WMFTellBlob(void *image)
109 return((long) TellBlob((Image*) image));
112 static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
115 filename[MaxTextExtent];
153 image=AcquireImage(image_info);
154 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
155 if (status == MagickFalse)
157 image=DestroyImageList(image);
158 return((Image *) NULL);
160 wmf_info=(wmfAPI *) NULL;
162 flags|=WMF_OPT_IGNORE_NONFATAL;
163 flags|=WMF_OPT_FUNCTION;
164 options.function=wmf_eps_function;
165 wmf_status=wmf_api_create(&wmf_info,(unsigned long) flags,&options);
166 if (wmf_status != wmf_E_None)
168 if (wmf_info != (wmfAPI *) NULL)
169 wmf_api_destroy(wmf_info);
170 ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
172 wmf_status=wmf_bbuf_input(wmf_info,WMFReadBlob,WMFSeekBlob,WMFTellBlob,
174 if (wmf_status != wmf_E_None)
176 wmf_api_destroy(wmf_info);
177 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
179 image=DestroyImageList(image);
180 return((Image *) NULL);
182 wmf_status=wmf_scan(wmf_info,0,&bounding_box);
183 if (wmf_status != wmf_E_None)
185 wmf_api_destroy(wmf_info);
186 ThrowReaderException(DelegateError,"FailedToScanFile");
188 eps_info=WMF_EPS_GetData(wmf_info);
190 unique_file=AcquireUniqueFileResource(filename);
191 if (unique_file != -1)
192 file=fdopen(unique_file,"wb");
193 if ((unique_file == -1) || (file == (FILE *) NULL))
195 wmf_api_destroy(wmf_info);
196 ThrowReaderException(FileOpenError,"UnableToCreateTemporaryFile");
198 eps_info->out=wmf_stream_create(wmf_info,file);
199 eps_info->bbox=bounding_box;
200 wmf_status=wmf_play(wmf_info,0,&bounding_box);
201 if (wmf_status != wmf_E_None)
203 wmf_api_destroy(wmf_info);
204 ThrowReaderException(DelegateError,"FailedToRenderFile");
207 wmf_api_destroy(wmf_info);
208 (void) CloseBlob(image);
209 image=DestroyImage(image);
213 read_info=CloneImageInfo(image_info);
214 SetImageInfoBlob(read_info,(void *) NULL,0);
215 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"eps:%s",
217 image=ReadImage(read_info,exception);
218 read_info=DestroyImageInfo(read_info);
219 if (image != (Image *) NULL)
221 (void) CopyMagickString(image->filename,image_info->filename,
223 (void) CopyMagickString(image->magick_filename,image_info->filename,
225 (void) CopyMagickString(image->magick,"WMF",MaxTextExtent);
227 (void) RelinquishUniqueFileResource(filename);
228 return(GetFirstImageInList(image));
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 % R e g i s t e r W M F I m a g e %
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 % RegisterWMFImage() adds attributes for the WMF image format to
244 % the list of supported formats. The attributes include the image format
245 % tag, a method to read and/or write the format, whether the format
246 % supports the saving of more than one frame to the same file or blob,
247 % whether the format supports native in-memory I/O, and a brief
248 % description of the format.
250 % The format of the RegisterWMFImage method is:
252 % size_t RegisterWMFImage(void)
255 ModuleExport size_t RegisterWMFImage(void)
260 entry = SetMagickInfo("WMZ");
261 #if defined(MAGICKCORE_WMF_DELEGATE)
262 entry->decoder=ReadWMFImage;
264 entry->description=ConstantString("Compressed Windows Meta File");
265 entry->module=ConstantString("WMZ");
266 entry->seekable_stream=MagickTrue;
267 (void) RegisterMagickInfo(entry);
268 entry=SetMagickInfo("WMF");
269 #if defined(MAGICKCORE_WMF_DELEGATE)
270 entry->decoder=ReadWMFImage;
272 entry->description=ConstantString("Windows Meta File");
273 entry->module=ConstantString("WMF");
274 (void) RegisterMagickInfo(entry);
275 return(MagickImageCoderSignature);
279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
283 % U n r e g i s t e r W M F I m a g e %
287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 % UnregisterWMFImage() removes format registrations made by the
290 % WMF module from the list of supported formats.
292 % The format of the UnregisterWMFImage method is:
294 % UnregisterWMFImage(void)
297 ModuleExport void UnregisterWMFImage(void)
299 (void) UnregisterMagickInfo("WMZ");
300 (void) UnregisterMagickInfo("WMF");