2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Windows Metafile Format %
20 % Copyright 1999-2014 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 "MagickCore/studio.h"
41 #include "MagickCore/property.h"
42 #include "MagickCore/blob.h"
43 #include "MagickCore/blob-private.h"
44 #include "MagickCore/color.h"
45 #include "MagickCore/color-private.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/log.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/paint.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/type.h"
63 #include "MagickCore/module.h"
64 #include "MagickWand/MagickWand.h"
66 #if defined(__CYGWIN__)
67 #undef MAGICKCORE_WMF_DELEGATE
70 #if defined(MAGICKCORE_WMF_DELEGATE)
71 #include "libwmf/api.h"
72 #include "libwmf/eps.h"
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % R e a d W M F I m a g e %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % ReadWMFImage() reads an Windows Metafile image file and returns it. It
86 % allocates the memory necessary for the new Image structure and returns a
87 % pointer to the new image.
89 % The format of the ReadWMFImage method is:
91 % Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
93 % A description of each parameter follows:
95 % o image_info: the image info.
97 % o exception: return any errors or warnings in this structure.
101 static int WMFReadBlob(void *image)
103 return(ReadBlobByte((Image *) image));
106 static int WMFSeekBlob(void *image,long offset)
108 return((int) SeekBlob((Image *) image,(MagickOffsetType) offset,SEEK_SET));
111 static long WMFTellBlob(void *image)
113 return((long) TellBlob((Image*) image));
116 static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
119 filename[MaxTextExtent];
157 image=AcquireImage(image_info,exception);
158 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
159 if (status == MagickFalse)
161 image=DestroyImageList(image);
162 return((Image *) NULL);
164 wmf_info=(wmfAPI *) NULL;
166 flags|=WMF_OPT_IGNORE_NONFATAL;
167 flags|=WMF_OPT_FUNCTION;
168 options.function=wmf_eps_function;
169 wmf_status=wmf_api_create(&wmf_info,(unsigned long) flags,&options);
170 if (wmf_status != wmf_E_None)
172 if (wmf_info != (wmfAPI *) NULL)
173 wmf_api_destroy(wmf_info);
174 ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
176 wmf_status=wmf_bbuf_input(wmf_info,WMFReadBlob,WMFSeekBlob,WMFTellBlob,
178 if (wmf_status != wmf_E_None)
180 wmf_api_destroy(wmf_info);
181 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
183 image=DestroyImageList(image);
184 return((Image *) NULL);
186 wmf_status=wmf_scan(wmf_info,0,&bounding_box);
187 if (wmf_status != wmf_E_None)
189 wmf_api_destroy(wmf_info);
190 ThrowReaderException(DelegateError,"FailedToScanFile");
192 eps_info=WMF_EPS_GetData(wmf_info);
194 unique_file=AcquireUniqueFileResource(filename);
195 if (unique_file != -1)
196 file=fdopen(unique_file,"wb");
197 if ((unique_file == -1) || (file == (FILE *) NULL))
199 wmf_api_destroy(wmf_info);
200 ThrowReaderException(FileOpenError,"UnableToCreateTemporaryFile");
202 eps_info->out=wmf_stream_create(wmf_info,file);
203 eps_info->bbox=bounding_box;
204 wmf_status=wmf_play(wmf_info,0,&bounding_box);
205 if (wmf_status != wmf_E_None)
207 wmf_api_destroy(wmf_info);
208 ThrowReaderException(DelegateError,"FailedToRenderFile");
211 wmf_api_destroy(wmf_info);
212 (void) CloseBlob(image);
213 image=DestroyImage(image);
217 read_info=CloneImageInfo(image_info);
218 SetImageInfoBlob(read_info,(void *) NULL,0);
219 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"eps:%s",
221 image=ReadImage(read_info,exception);
222 read_info=DestroyImageInfo(read_info);
223 if (image != (Image *) NULL)
225 (void) CopyMagickString(image->filename,image_info->filename,
227 (void) CopyMagickString(image->magick_filename,image_info->filename,
229 (void) CopyMagickString(image->magick,"WMF",MaxTextExtent);
231 (void) RelinquishUniqueFileResource(filename);
232 return(GetFirstImageInList(image));
234 #elif defined(MAGICKCORE_WMFLITE_DELEGATE)
236 #define ERR(API) ((API)->err != wmf_E_None)
237 #define XC(x) ((double) x)
238 #define YC(y) ((double) y)
241 # define M_PI MagickPI
244 #if defined(MAGICKCORE_HAVE_FT2BUILD_H)
245 # include <ft2build.h>
248 #include "libwmf/fund.h"
249 #include "libwmf/types.h"
250 #include "libwmf/api.h"
267 /* The following additinal undefs were required for MinGW */
270 #undef PS_ENDCAP_ROUND
271 #undef PS_ENDCAP_SQUARE
272 #undef PS_ENDCAP_FLAT
273 #undef PS_ENDCAP_MASK
280 #undef STRETCH_ANDSCANS
281 #undef STRETCH_ORSCANS
282 #undef STRETCH_DELETESCANS
283 #undef STRETCH_HALFTONE
286 #undef ETO_GLYPH_INDEX
287 #undef ETO_RTLREADING
289 #include "libwmf/defs.h"
290 #include "libwmf/ipa.h"
291 #include "libwmf/color.h"
292 #include "libwmf/macro.h"
294 /* Unit conversions */
295 #define TWIPS_PER_INCH 1440
296 #define CENTIMETERS_PER_INCH 2.54
297 #define POINTS_PER_INCH 72
299 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
300 # define wmf_api_create(api,flags,options) wmf_lite_create(api,flags,options)
301 # define wmf_api_destroy(api) wmf_lite_destroy(api)
302 # undef WMF_FONT_PSNAME
303 # define WMF_FONT_PSNAME(F) ((F)->user_data ? ((wmf_magick_font_t*) (F)->user_data)->ps_name : 0)
305 typedef struct _wmf_magick_font_t wmf_magick_font_t;
307 struct _wmf_magick_font_t
315 typedef struct _wmf_magick_t wmf_magick_t;
323 /* Scale and translation factors */
338 /* ImageMagick image */
368 #define WMF_MAGICK_GetData(Z) ((wmf_magick_t*)((Z)->device_data))
369 #define WMF_MAGICK_GetFontData(Z) \
370 ((wmf_magick_font_t*)((wmfFontData *)Z->font_data)->user_data)
372 #define WmfDrawingWand (((wmf_magick_t*)((API)->device_data))->draw_wand)
374 /* Enum to control whether util_set_brush applies brush to fill or
383 /* Enum to specify arc type */
386 magick_arc_ellipse = 0,
393 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
394 static void lite_font_init (wmfAPI* API, wmfAPI_Options* options);
395 static void lite_font_map(wmfAPI* API,wmfFont* font);
396 static float lite_font_stringwidth(wmfAPI* API, wmfFont* font, char* str);
399 static void draw_fill_color_rgb(wmfAPI* API, const wmfRGB* rgb);
400 static void draw_stroke_color_rgb(wmfAPI* API, const wmfRGB* rgb);
401 static void draw_pattern_push(wmfAPI* API, unsigned long id, unsigned long columns, unsigned long rows);
402 static int ipa_blob_read(void* wand);
403 static int ipa_blob_seek(void* wand,long position);
404 static long ipa_blob_tell(void* wand);
405 static void ipa_bmp_draw(wmfAPI * API, wmfBMP_Draw_t * bmp_draw);
406 static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp);
407 static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read);
408 static void ipa_device_begin(wmfAPI * API);
409 static void ipa_device_close(wmfAPI * API);
410 static void ipa_device_end(wmfAPI * API);
411 static void ipa_device_open(wmfAPI * API);
412 static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc);
413 static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc);
414 static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc);
415 static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line);
416 static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc);
417 static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel);
418 static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * poly_line);
419 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
420 static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon);
422 static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect);
423 static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text);
424 static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood);
425 static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood);
426 static void ipa_functions(wmfAPI * API);
427 static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * poly_line);
428 static void ipa_region_clip(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
429 static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
430 static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
431 static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw);
432 static void ipa_udata_copy(wmfAPI * API, wmfUserData_t * userdata);
433 static void ipa_udata_free(wmfAPI * API, wmfUserData_t * userdata);
434 static void ipa_udata_init(wmfAPI * API, wmfUserData_t * userdata);
435 static void ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata);
436 static int magick_progress_callback(void* wand,float quantum);
437 static void util_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc,magick_arc_t finish);
438 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
439 /*static int util_font_weight( const char* font );*/
441 static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height, ExceptionInfo *);
442 static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply);
443 static void util_set_pen(wmfAPI * API, wmfDC * dc);
445 /* Progress callback */
446 int magick_progress_callback(void *context,float quantum)
455 image=(Image *) context;
456 assert(image->signature == MagickSignature);
457 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
459 return(status != MagickFalse ? 0 : 1);
463 static void draw_fill_color_string(DrawingWand *drawing_wand,const char *color)
468 fill_color=NewPixelWand();
469 PixelSetColor(fill_color,color);
470 DrawSetFillColor(drawing_wand,fill_color);
471 fill_color=DestroyPixelWand(fill_color);
473 static void draw_fill_color_rgb( wmfAPI* API, const wmfRGB* rgb )
478 fill_color=NewPixelWand();
479 PixelSetRedQuantum(fill_color,ScaleCharToQuantum(rgb->r));
480 PixelSetGreenQuantum(fill_color,ScaleCharToQuantum(rgb->g));
481 PixelSetBlueQuantum(fill_color,ScaleCharToQuantum(rgb->b));
482 PixelSetAlphaQuantum(fill_color,OpaqueAlpha);
483 DrawSetFillColor(WmfDrawingWand,fill_color);
484 fill_color=DestroyPixelWand(fill_color);
487 /* Set stroke color */
488 static void draw_stroke_color_string(DrawingWand *drawing_wand,const char *color)
493 stroke_color=NewPixelWand();
494 PixelSetColor(stroke_color,color);
495 DrawSetStrokeColor(drawing_wand,stroke_color);
496 stroke_color=DestroyPixelWand(stroke_color);
499 static void draw_stroke_color_rgb( wmfAPI* API, const wmfRGB* rgb )
504 stroke_color=NewPixelWand();
505 PixelSetRedQuantum(stroke_color,ScaleCharToQuantum(rgb->r));
506 PixelSetGreenQuantum(stroke_color,ScaleCharToQuantum(rgb->g));
507 PixelSetBlueQuantum(stroke_color,ScaleCharToQuantum(rgb->b));
508 PixelSetAlphaQuantum(stroke_color,OpaqueAlpha);
509 DrawSetStrokeColor(WmfDrawingWand,stroke_color);
510 stroke_color=DestroyPixelWand(stroke_color);
513 /* Set under color */
514 static void draw_under_color_string(DrawingWand *drawing_wand,const char *color)
519 under_color=NewPixelWand();
520 PixelSetColor(under_color,color);
521 DrawSetTextUnderColor(drawing_wand,under_color);
522 under_color=DestroyPixelWand(under_color);
525 static void draw_pattern_push( wmfAPI* API,
527 unsigned long columns,
533 (void) FormatLocaleString(pattern_id,MaxTextExtent,"brush_%lu",id);
534 (void) DrawPushPattern(WmfDrawingWand,pattern_id,0,0,columns,rows);
537 /* Pattern/Bit BLT with raster operation (ROP) support. Invoked by
538 META_PATBLT, which is equivalent to Windows PatBlt() call, or by
539 META_DIBBITBLT which is equivalent to Windows BitBlt() call. */
541 /* The BitBlt function transfers pixels from a rectangular area in one
542 device wand called the 'source', to a rectangular area of the
543 same size in another device wand, called the 'destination'. */
545 static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw)
548 /* *brush = WMF_DC_BRUSH(rop_draw->dc); */
551 /* *brush_bmp = WMF_BRUSH_BITMAP(brush); */
553 if (TO_FILL(rop_draw) == 0)
556 /* Save graphic wand */
557 (void) PushDrawingWand(WmfDrawingWand);
559 /* FIXME: finish implementing (once we know what it is supposed to do!) */
562 struct _wmfROP_Draw_t
575 /* if (brush_bmp && brush_bmp->data != 0) */
576 /* printf("Have an image!\n"); */
578 switch (rop_draw->ROP) /* Ternary raster operations */
580 case SRCCOPY: /* dest = source */
581 printf("ipa_rop_draw SRCCOPY ROP mode not implemented\n");
583 case SRCPAINT: /* dest = source OR dest */
584 printf("ipa_rop_draw SRCPAINT ROP mode not implemented\n");
586 case SRCAND: /* dest = source AND dest */
587 printf("ipa_rop_draw SRCAND ROP mode not implemented\n");
589 case SRCINVERT: /* dest = source XOR dest */
590 printf("ipa_rop_draw SRCINVERT ROP mode not implemented\n");
592 case SRCERASE: /* dest = source AND (NOT dest) */
593 printf("ipa_rop_draw SRCERASE ROP mode not implemented\n");
595 case NOTSRCCOPY: /* dest = (NOT source) */
596 printf("ipa_rop_draw NOTSRCCOPY ROP mode not implemented\n");
598 case NOTSRCERASE: /* dest = (NOT src) AND (NOT dest) */
599 printf("ipa_rop_draw NOTSRCERASE ROP mode not implemented\n");
601 case MERGECOPY: /* dest = (source AND pattern) */
602 printf("ipa_rop_draw MERGECOPY ROP mode not implemented\n");
604 case MERGEPAINT: /* dest = (NOT source) OR dest */
605 printf("ipa_rop_draw MERGEPAINT ROP mode not implemented\n");
607 case PATCOPY: /* dest = pattern */
608 util_set_brush(API, rop_draw->dc, BrushApplyFill);
610 case PATPAINT: /* dest = DPSnoo */
611 printf("ipa_rop_draw PATPAINT ROP mode not implemented\n");
613 case PATINVERT: /* dest = pattern XOR dest */
614 printf("ipa_rop_draw PATINVERT ROP mode not implemented\n");
616 case DSTINVERT: /* dest = (NOT dest) */
617 printf("ipa_rop_draw DSTINVERT ROP mode not implemented\n");
619 case BLACKNESS: /* dest = BLACK */
620 draw_fill_color_string(WmfDrawingWand,"black");
622 case WHITENESS: /* dest = WHITE */
623 draw_fill_color_string(WmfDrawingWand,"white");
626 printf("ipa_rop_draw 0x%x ROP mode not implemented\n", rop_draw->ROP);
630 DrawRectangle(WmfDrawingWand,
631 XC(rop_draw->TL.x), YC(rop_draw->TL.y),
632 XC(rop_draw->BR.x), YC(rop_draw->BR.y));
634 /* Restore graphic wand */
635 (void) PopDrawingWand(WmfDrawingWand);
638 static void ipa_bmp_draw(wmfAPI *API, wmfBMP_Draw_t *bmp_draw)
641 *ddata = WMF_MAGICK_GetData(API);
659 if (bmp_draw->bmp.data == 0)
662 image = (Image*)bmp_draw->bmp.data;
666 exception=ddata->exception;
667 if (bmp_draw->crop.x || bmp_draw->crop.y ||
668 (bmp_draw->crop.w != bmp_draw->bmp.width) ||
669 (bmp_draw->crop.h != bmp_draw->bmp.height))
671 /* Image needs to be cropped */
678 crop_info.x = bmp_draw->crop.x;
679 crop_info.y = bmp_draw->crop.y;
680 crop_info.width = bmp_draw->crop.w;
681 crop_info.height = bmp_draw->crop.h;
683 crop_image = CropImage( image, &crop_info, exception );
686 image=DestroyImageList(image);
688 bmp_draw->bmp.data = (void*)image;
692 QueryColorCompliance( "white", AllCompliance, &white, exception );
694 if ( ddata->image_info->texture ||
695 !(IsPixelInfoEquivalent(&ddata->image_info->background_color,&white)) ||
696 ddata->image_info->background_color.alpha != OpaqueAlpha )
699 Set image white background to transparent so that it may be
700 overlaid over non-white backgrounds.
702 QueryColorCompliance( "white", AllCompliance, &white, exception );
703 TransparentPaintImage( image, &white, QuantumRange, MagickFalse, exception );
706 width = fabs(bmp_draw->pixel_width * (double) bmp_draw->crop.w);
707 height = fabs(bmp_draw->pixel_height * (double) bmp_draw->crop.h);
708 magick_wand=NewMagickWandFromImage(image);
709 (void) DrawComposite(WmfDrawingWand, CopyCompositeOp,
710 XC(bmp_draw->pt.x) * ddata->scale_x, YC(bmp_draw->pt.y) * ddata->scale_y,
711 width * ddata->scale_x, height * ddata->scale_y, magick_wand);
712 magick_wand=DestroyMagickWand(magick_wand);
715 printf("bmp_draw->bmp.data = 0x%lx\n", (long)bmp_draw->bmp.data);
716 printf("registry id = %li\n", id);
717 /* printf("pixel_width = %g\n", bmp_draw->pixel_width); */
718 /* printf("pixel_height = %g\n", bmp_draw->pixel_height); */
719 printf("bmp_draw->bmp WxH = %ix%i\n", bmp_draw->bmp.width, bmp_draw->bmp.height);
720 printf("bmp_draw->crop WxH = %ix%i\n", bmp_draw->crop.w, bmp_draw->crop.h);
721 printf("bmp_draw->crop x,y = %i,%i\n", bmp_draw->crop.x, bmp_draw->crop.y);
722 printf("image size WxH = %lux%lu\n", image->columns, image->rows);
726 static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read) {
728 *ddata = WMF_MAGICK_GetData(API);
739 bmp_read->bmp.data = 0;
741 image_info=CloneImageInfo(ddata->image_info);
742 exception=ddata->exception;
743 (void) CopyMagickString(image_info->magick,"DIB",MaxTextExtent);
744 if (bmp_read->width || bmp_read->height)
749 (void) FormatLocaleString(size,MaxTextExtent,"%ux%u",bmp_read->width,
751 CloneString(&image_info->size,size);
754 printf("ipa_bmp_read: buffer=0x%lx length=%ld, width=%i, height=%i\n",
755 (long) bmp_read->buffer, bmp_read->length,
756 bmp_read->width, bmp_read->height);
758 image=BlobToImage(image_info, (const void *) bmp_read->buffer,
759 bmp_read->length, exception);
760 image_info=DestroyImageInfo(image_info);
761 if (image != (Image *) NULL)
764 printf("ipa_bmp_read: rows=%ld,columns=%ld\n\n", image->rows, image->columns);
767 bmp_read->bmp.data = (void*)image;
768 bmp_read->bmp.width = (U16)image->columns;
769 bmp_read->bmp.height = (U16)image->rows;
773 static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp)
776 DestroyImageList((Image*)bmp->data);
777 bmp->data = (void*) 0;
778 bmp->width = (U16) 0;
779 bmp->height = (U16) 0;
783 This called by wmf_play() the *first* time the meta file is played
785 static void ipa_device_open(wmfAPI * API)
788 *ddata = WMF_MAGICK_GetData (API);
790 ddata->pattern_id = 0;
791 ddata->clipping = MagickFalse;
792 ddata->clip_mask_id = 0;
794 ddata->push_depth = 0;
796 ddata->draw_wand = DrawAllocateWand(ddata->draw_info,ddata->image);
800 This called by wmf_api_destroy()
802 static void ipa_device_close(wmfAPI * API)
805 *ddata = WMF_MAGICK_GetData(API);
807 DestroyDrawingWand(ddata->draw_wand);
808 DestroyDrawInfo(ddata->draw_info);
809 RelinquishMagickMemory(WMF_MAGICK_GetFontData(API)->ps_name);
813 This called from the beginning of each play for initial page setup
815 static void ipa_device_begin(wmfAPI * API)
818 comment[MaxTextExtent];
821 *ddata = WMF_MAGICK_GetData(API);
823 /* Make SVG output happy */
824 (void) PushDrawingWand(WmfDrawingWand);
826 DrawSetViewbox(WmfDrawingWand, 0, 0, ddata->image->columns, ddata->image->rows );
828 (void) FormatLocaleString(comment,MaxTextExtent,"Created by ImageMagick %s",
829 GetMagickVersion((size_t *) NULL));
830 DrawComment(WmfDrawingWand,comment);
832 /* Scale width and height to image */
833 DrawScale(WmfDrawingWand, ddata->scale_x, ddata->scale_y);
835 /* Translate to TL corner of bounding box */
836 DrawTranslate(WmfDrawingWand, ddata->translate_x, ddata->translate_y);
839 DrawRotate(WmfDrawingWand, ddata->rotate);
841 if (ddata->image_info->texture == NULL)
846 /* Draw rectangle in background color */
847 background_color=NewPixelWand();
848 PixelSetPixelColor(background_color,&ddata->image->background_color);
849 DrawSetFillColor(WmfDrawingWand,background_color);
850 background_color=DestroyPixelWand(background_color);
851 DrawRectangle(WmfDrawingWand,
852 XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
853 XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
857 /* Draw rectangle with texture image the SVG way */
867 GetExceptionInfo(&exception);
869 image_info = CloneImageInfo((ImageInfo *) 0);
870 (void) CopyMagickString(image_info->filename,ddata->image_info->texture,
872 if ( ddata->image_info->size )
873 CloneString(&image_info->size,ddata->image_info->size);
875 image = ReadImage(image_info,&exception);
876 image_info=DestroyImageInfo(image_info);
885 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
886 DrawPushDefs(WmfDrawingWand);
887 draw_pattern_push(API,ddata->pattern_id,image->columns,image->rows);
888 magick_wand=NewMagickWandFromImage(image);
889 (void) DrawComposite(WmfDrawingWand,CopyCompositeOp,0,0,
890 image->columns,image->rows,magick_wand);
891 magick_wand=DestroyMagickWand(magick_wand);
892 (void) DrawPopPattern(WmfDrawingWand);
893 DrawPopDefs(WmfDrawingWand);
894 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
896 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
898 DrawRectangle(WmfDrawingWand,
899 XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
900 XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
901 image=DestroyImageList(image);
905 LogMagickEvent(CoderEvent,GetMagickModule(),
906 "reading texture image failed!");
910 DrawSetClipRule(WmfDrawingWand,EvenOddRule); /* Default for WMF is ALTERNATE polygon fill mode */
911 draw_fill_color_string(WmfDrawingWand,"none"); /* Default brush is WHITE_BRUSH */
912 draw_stroke_color_string(WmfDrawingWand,"none"); /* Default pen is BLACK_PEN */
913 DrawSetStrokeLineCap(WmfDrawingWand,ButtCap); /* Default linecap is PS_ENDCAP_FLAT */
914 DrawSetStrokeLineJoin(WmfDrawingWand,MiterJoin); /* Default linejoin is PS_JOIN_MITER */
915 draw_under_color_string(WmfDrawingWand,"white"); /* Default text box is white */
919 This called from the end of each play for page termination
921 static void ipa_device_end(wmfAPI * API)
924 *ddata = WMF_MAGICK_GetData(API);
926 /* Reset any existing clip paths by popping wand */
928 (void) PopDrawingWand(WmfDrawingWand);
929 ddata->clipping = MagickFalse;
931 /* Make SVG output happy */
932 (void) PopDrawingWand(WmfDrawingWand);
935 static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood)
937 /* Save graphic wand */
938 (void) PushDrawingWand(WmfDrawingWand);
940 draw_fill_color_rgb(API,&(flood->color));
942 DrawColor(WmfDrawingWand,XC(flood->pt.x), YC(flood->pt.y),
945 /* Restore graphic wand */
946 (void) PopDrawingWand(WmfDrawingWand);
949 static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood)
951 /* Save graphic wand */
952 (void) PushDrawingWand(WmfDrawingWand);
954 draw_fill_color_rgb(API,&(flood->color));
956 if (flood->type == FLOODFILLSURFACE)
957 DrawColor(WmfDrawingWand, XC(flood->pt.x), YC(flood->pt.y),
960 DrawColor(WmfDrawingWand, XC(flood->pt.x), YC(flood->pt.y),
963 /* Restore graphic wand */
964 (void) PopDrawingWand(WmfDrawingWand);
967 static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel)
969 /* Save graphic wand */
970 (void) PushDrawingWand(WmfDrawingWand);
972 draw_stroke_color_string(WmfDrawingWand,"none");
974 draw_fill_color_rgb(API,&(draw_pixel->color));
976 DrawRectangle(WmfDrawingWand,
977 XC(draw_pixel->pt.x),
978 YC(draw_pixel->pt.y),
979 XC(draw_pixel->pt.x + draw_pixel->pixel_width),
980 YC(draw_pixel->pt.y + draw_pixel->pixel_height));
982 /* Restore graphic wand */
983 (void) PopDrawingWand(WmfDrawingWand);
986 static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc)
988 util_draw_arc(API, draw_arc, magick_arc_pie);
991 static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc)
993 util_draw_arc(API, draw_arc, magick_arc_chord);
996 static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc)
998 util_draw_arc(API, draw_arc, magick_arc_open);
1001 static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc)
1003 util_draw_arc(API, draw_arc, magick_arc_ellipse);
1006 static void util_draw_arc(wmfAPI * API,
1007 wmfDrawArc_t * draw_arc, magick_arc_t finish)
1025 /* Save graphic wand */
1026 (void) PushDrawingWand(WmfDrawingWand);
1028 if (TO_FILL(draw_arc) || TO_DRAW(draw_arc))
1030 center.x = (draw_arc->TL.x + draw_arc->BR.x) / 2;
1031 center.y = (draw_arc->TL.y + draw_arc->BR.y) / 2;
1035 if (finish != magick_arc_ellipse)
1037 draw_arc->start.x += center.x;
1038 draw_arc->start.y += center.y;
1040 draw_arc->end.x += center.x;
1041 draw_arc->end.y += center.y;
1049 if (finish != magick_arc_ellipse)
1051 start = draw_arc->start;
1052 end = draw_arc->end;
1055 Rx = (BR.x - TL.x) / 2;
1056 Ry = (BR.y - TL.y) / 2;
1058 if (finish != magick_arc_ellipse)
1066 phi_s = atan2((double) start.y, (double) start.x) * 180 / MagickPI;
1067 phi_e = atan2((double) end.y, (double) end.x) * 180 / MagickPI;
1073 util_set_pen(API, draw_arc->dc);
1074 if (finish == magick_arc_open)
1075 draw_fill_color_string(WmfDrawingWand,"none");
1077 util_set_brush(API, draw_arc->dc, BrushApplyFill);
1079 if (finish == magick_arc_ellipse)
1080 DrawEllipse(WmfDrawingWand, XC(O.x), YC(O.y), Rx, Ry, 0, 360);
1081 else if (finish == magick_arc_pie)
1083 DrawPathStart(WmfDrawingWand);
1084 DrawPathMoveToAbsolute(WmfDrawingWand, XC(O.x+start.x),
1086 DrawPathEllipticArcAbsolute(WmfDrawingWand, Rx, Ry, 0, MagickFalse,
1087 MagickTrue, XC(O.x+end.x), YC(O.y+end.y));
1088 DrawPathLineToAbsolute(WmfDrawingWand, XC(O.x), YC(O.y));
1089 DrawPathClose(WmfDrawingWand);
1090 DrawPathFinish(WmfDrawingWand);
1092 else if (finish == magick_arc_chord)
1094 DrawArc(WmfDrawingWand, XC(draw_arc->TL.x), YC(draw_arc->TL.y),
1095 XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
1096 DrawLine(WmfDrawingWand, XC(draw_arc->BR.x-start.x),
1097 YC(draw_arc->BR.y-start.y), XC(draw_arc->BR.x-end.x),
1098 YC(draw_arc->BR.y-end.y));
1100 else /* if (finish == magick_arc_open) */
1101 DrawArc(WmfDrawingWand, XC(draw_arc->TL.x), YC(draw_arc->TL.y),
1102 XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
1105 /* Restore graphic wand */
1106 (void) PopDrawingWand(WmfDrawingWand);
1109 static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line)
1111 /* Save graphic wand */
1112 (void) PushDrawingWand(WmfDrawingWand);
1114 if (TO_DRAW(draw_line))
1116 util_set_pen(API, draw_line->dc);
1117 DrawLine(WmfDrawingWand,
1118 XC(draw_line->from.x), YC(draw_line->from.y),
1119 XC(draw_line->to.x), YC(draw_line->to.y));
1122 /* Restore graphic wand */
1123 (void) PopDrawingWand(WmfDrawingWand);
1126 static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * polyline)
1128 if (polyline->count <= 2)
1131 if (TO_DRAW(polyline))
1136 /* Save graphic wand */
1137 (void) PushDrawingWand(WmfDrawingWand);
1139 util_set_pen(API, polyline->dc);
1141 DrawPathStart(WmfDrawingWand);
1142 DrawPathMoveToAbsolute(WmfDrawingWand,
1143 XC(polyline->pt[0].x),
1144 YC(polyline->pt[0].y));
1145 for (point = 1; point < polyline->count; point++)
1147 DrawPathLineToAbsolute(WmfDrawingWand,
1148 XC(polyline->pt[point].x),
1149 YC(polyline->pt[point].y));
1151 DrawPathFinish(WmfDrawingWand);
1153 /* Restore graphic wand */
1154 (void) PopDrawingWand(WmfDrawingWand);
1158 static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * polyline)
1160 if (polyline->count <= 2)
1163 if (TO_FILL(polyline) || TO_DRAW(polyline))
1168 /* Save graphic wand */
1169 (void) PushDrawingWand(WmfDrawingWand);
1171 util_set_pen(API, polyline->dc);
1172 util_set_brush(API, polyline->dc, BrushApplyFill);
1174 DrawPathStart(WmfDrawingWand);
1175 DrawPathMoveToAbsolute(WmfDrawingWand,
1176 XC(polyline->pt[0].x),
1177 YC(polyline->pt[0].y));
1178 for (point = 1; point < polyline->count; point++)
1180 DrawPathLineToAbsolute(WmfDrawingWand,
1181 XC(polyline->pt[point].x),
1182 YC(polyline->pt[point].y));
1184 DrawPathClose(WmfDrawingWand);
1185 DrawPathFinish(WmfDrawingWand);
1187 /* Restore graphic wand */
1188 (void) PopDrawingWand(WmfDrawingWand);
1192 /* Draw a polypolygon. A polypolygon is a list of polygons */
1193 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1194 static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon)
1196 if (TO_FILL(polypolygon) || TO_DRAW(polypolygon))
1205 /* Save graphic wand */
1206 (void) PushDrawingWand(WmfDrawingWand);
1208 util_set_pen(API, polypolygon->dc);
1209 util_set_brush(API, polypolygon->dc, BrushApplyFill);
1211 DrawPathStart(WmfDrawingWand);
1212 for (polygon = 0; polygon < polypolygon->npoly; polygon++)
1214 polyline.dc = polypolygon->dc;
1215 polyline.pt = polypolygon->pt[polygon];
1216 polyline.count = polypolygon->count[polygon];
1217 if ((polyline.count > 2) && polyline.pt)
1219 DrawPathMoveToAbsolute(WmfDrawingWand,
1220 XC(polyline.pt[0].x),
1221 YC(polyline.pt[0].y));
1222 for (point = 1; point < polyline.count; point++)
1224 DrawPathLineToAbsolute(WmfDrawingWand,
1225 XC(polyline.pt[point].x),
1226 YC(polyline.pt[point].y));
1228 DrawPathClose(WmfDrawingWand);
1231 DrawPathFinish(WmfDrawingWand);
1233 /* Restore graphic wand */
1234 (void) PopDrawingWand(WmfDrawingWand);
1239 static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect)
1241 /* Save graphic wand */
1242 (void) PushDrawingWand(WmfDrawingWand);
1244 if (TO_FILL(draw_rect) || TO_DRAW(draw_rect))
1246 util_set_pen(API, draw_rect->dc);
1247 util_set_brush(API, draw_rect->dc, BrushApplyFill);
1249 if ((draw_rect->width > 0) || (draw_rect->height > 0))
1250 DrawRoundRectangle(WmfDrawingWand,
1251 XC(draw_rect->TL.x), YC(draw_rect->TL.y),
1252 XC(draw_rect->BR.x), YC(draw_rect->BR.y),
1253 draw_rect->width / 2, draw_rect->height / 2);
1255 DrawRectangle(WmfDrawingWand,
1256 XC(draw_rect->TL.x), YC(draw_rect->TL.y),
1257 XC(draw_rect->BR.x), YC(draw_rect->BR.y));
1260 /* Restore graphic wand */
1261 (void) PopDrawingWand(WmfDrawingWand);
1264 /* Draw an un-filled rectangle using the current brush */
1265 static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
1267 /* Save graphic wand */
1268 (void) PushDrawingWand(WmfDrawingWand);
1270 if (TO_FILL(poly_rect) || TO_DRAW(poly_rect))
1275 draw_fill_color_string(WmfDrawingWand,"none");
1276 util_set_brush(API, poly_rect->dc, BrushApplyStroke);
1278 for (i = 0; i < (long) poly_rect->count; i++)
1280 DrawRectangle(WmfDrawingWand,
1281 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1282 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1286 /* Restore graphic wand */
1287 (void) PopDrawingWand(WmfDrawingWand);
1290 static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
1293 if (poly_rect->count == 0)
1296 /* Save graphic wand */
1297 (void) PushDrawingWand(WmfDrawingWand);
1299 if (TO_FILL (poly_rect))
1304 draw_stroke_color_string(WmfDrawingWand,"none");
1305 util_set_brush(API, poly_rect->dc, BrushApplyFill);
1307 for (i = 0; i < (long) poly_rect->count; i++)
1309 DrawRectangle(WmfDrawingWand,
1310 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1311 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1315 /* Restore graphic wand */
1316 (void) PopDrawingWand(WmfDrawingWand);
1319 static void ipa_region_clip(wmfAPI *API, wmfPolyRectangle_t *poly_rect)
1325 *ddata = WMF_MAGICK_GetData (API);
1327 /* Reset any existing clip paths by popping wand */
1328 if (ddata->clipping)
1329 (void) PopDrawingWand(WmfDrawingWand);
1330 ddata->clipping = MagickFalse;
1332 if (poly_rect->count > 0)
1337 /* Define clip path */
1338 ddata->clip_mask_id++;
1339 DrawPushDefs(WmfDrawingWand);
1340 (void) FormatLocaleString(clip_mask_id,MaxTextExtent,"clip_%lu",
1341 ddata->clip_mask_id);
1342 DrawPushClipPath(WmfDrawingWand,clip_mask_id);
1343 (void) PushDrawingWand(WmfDrawingWand);
1344 for (i = 0; i < (long) poly_rect->count; i++)
1346 DrawRectangle(WmfDrawingWand,
1347 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1348 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1350 (void) PopDrawingWand(WmfDrawingWand);
1351 DrawPopClipPath(WmfDrawingWand);
1352 DrawPopDefs(WmfDrawingWand);
1354 /* Push wand for new clip paths */
1355 (void) PushDrawingWand(WmfDrawingWand);
1356 (void) DrawSetClipPath(WmfDrawingWand,clip_mask_id);
1357 ddata->clipping = MagickTrue;
1361 static void ipa_functions(wmfAPI *API)
1366 wmfFunctionReference
1367 *FR = (wmfFunctionReference *) API->function_reference;
1370 IPA function reference links
1372 FR->device_open = ipa_device_open;
1373 FR->device_close = ipa_device_close;
1374 FR->device_begin = ipa_device_begin;
1375 FR->device_end = ipa_device_end;
1376 FR->flood_interior = ipa_flood_interior;
1377 FR->flood_exterior = ipa_flood_exterior;
1378 FR->draw_pixel = ipa_draw_pixel;
1379 FR->draw_pie = ipa_draw_pie;
1380 FR->draw_chord = ipa_draw_chord;
1381 FR->draw_arc = ipa_draw_arc;
1382 FR->draw_ellipse = ipa_draw_ellipse;
1383 FR->draw_line = ipa_draw_line;
1384 FR->poly_line = ipa_poly_line;
1385 FR->draw_polygon = ipa_draw_polygon;
1386 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1387 FR->draw_polypolygon = ipa_draw_polypolygon;
1389 FR->draw_rectangle = ipa_draw_rectangle;
1390 FR->rop_draw = ipa_rop_draw;
1391 FR->bmp_draw = ipa_bmp_draw;
1392 FR->bmp_read = ipa_bmp_read;
1393 FR->bmp_free = ipa_bmp_free;
1394 FR->draw_text = ipa_draw_text;
1395 FR->udata_init = ipa_udata_init;
1396 FR->udata_copy = ipa_udata_copy;
1397 FR->udata_set = ipa_udata_set;
1398 FR->udata_free = ipa_udata_free;
1399 FR->region_frame = ipa_region_frame;
1400 FR->region_paint = ipa_region_paint;
1401 FR->region_clip = ipa_region_clip;
1404 Allocate device data structure
1406 ddata = (wmf_magick_t *) wmf_malloc(API, sizeof(wmf_magick_t));
1410 (void) ResetMagickMemory((void *) ddata, 0, sizeof(wmf_magick_t));
1411 API->device_data = (void *) ddata;
1414 Device data defaults
1419 static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text)
1422 angle = 0, /* text rotation angle */
1423 bbox_height, /* bounding box height */
1424 bbox_width, /* bounding box width */
1425 pointsize = 0; /* pointsize to output font with desired height */
1434 BL, /* bottom left of bounding box */
1435 BR, /* bottom right of bounding box */
1436 TL, /* top left of bounding box */
1437 TR; /* top right of bounding box */
1440 point; /* text placement point */
1446 * ddata = WMF_MAGICK_GetData(API);
1448 point = draw_text->pt;
1450 /* Choose bounding box and calculate its width and height */
1455 if ( draw_text->flags)
1459 TR.x = draw_text->BR.x;
1460 TR.y = draw_text->TL.y;
1461 BL.x = draw_text->TL.x;
1462 BL.y = draw_text->BR.y;
1466 TL = draw_text->bbox.TL;
1467 BR = draw_text->bbox.BR;
1468 TR = draw_text->bbox.TR;
1469 BL = draw_text->bbox.BL;
1471 dx = ((TR.x - TL.x) + (BR.x - BL.x)) / 2;
1472 dy = ((TR.y - TL.y) + (BR.y - BL.y)) / 2;
1473 bbox_width = hypot(dx,dy);
1474 dx = ((BL.x - TL.x) + (BR.x - TR.x)) / 2;
1475 dy = ((BL.y - TL.y) + (BR.y - TR.y)) / 2;
1476 bbox_height = hypot(dx,dy);
1479 font = WMF_DC_FONT(draw_text->dc);
1481 /* Convert font_height to equivalent pointsize */
1482 exception=ddata->exception;
1483 pointsize = util_pointsize( API, font, draw_text->str, draw_text->font_height, exception);
1485 /* Save graphic wand */
1486 (void) PushDrawingWand(WmfDrawingWand);
1491 printf("\nipa_draw_text\n");
1492 printf("Text = \"%s\"\n", draw_text->str);
1493 /* printf("WMF_FONT_NAME: = \"%s\"\n", WMF_FONT_NAME(font)); */
1494 printf("WMF_FONT_PSNAME: = \"%s\"\n", WMF_FONT_PSNAME(font));
1495 printf("Bounding box TL=%g,%g BR=%g,%g\n",
1496 TL.x, TL.y, BR.x, BR.y );
1497 /* printf("Text box = %gx%g\n", bbox_width, bbox_height); */
1498 /* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
1499 printf("Pointsize = %g\n", pointsize);
1504 * Obtain font metrics if required
1507 if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER) ||
1508 (WMF_TEXT_UNDERLINE(font)) || (WMF_TEXT_STRIKEOUT(font)))
1511 *image = ddata->image;
1516 draw_info=ddata->draw_info;
1517 draw_info->font=WMF_FONT_PSNAME(font);
1518 draw_info->pointsize = pointsize;
1519 draw_info->text=draw_text->str;
1521 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
1523 /* Center the text if it is not yet centered and should be */
1524 if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER))
1527 text_width = metrics.width * (ddata->scale_y / ddata->scale_x);
1529 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1530 point.x -= text_width / 2;
1532 point.x += bbox_width / 2 - text_width / 2;
1536 draw_info->font=NULL;
1537 draw_info->text=NULL;
1540 /* Set text background color */
1541 if (draw_text->flags & ETO_OPAQUE)
1543 /* Draw bounding-box background color (META_EXTTEXTOUT mode) */
1544 draw_stroke_color_string(WmfDrawingWand,"none");
1545 draw_fill_color_rgb(API,WMF_DC_BACKGROUND(draw_text->dc));
1546 DrawRectangle(WmfDrawingWand,
1547 XC(draw_text->TL.x),YC(draw_text->TL.y),
1548 XC(draw_text->BR.x),YC(draw_text->BR.y));
1549 draw_fill_color_string(WmfDrawingWand,"none");
1553 /* Set text undercolor */
1554 if (WMF_DC_OPAQUE(draw_text->dc))
1557 *box = WMF_DC_BACKGROUND(draw_text->dc);
1562 under_color=NewPixelWand();
1563 PixelSetRedQuantum(under_color,ScaleCharToQuantum(box->r));
1564 PixelSetGreenQuantum(under_color,ScaleCharToQuantum(box->g));
1565 PixelSetBlueQuantum(under_color,ScaleCharToQuantum(box->b));
1566 PixelSetAlphaQuantum(under_color,OpaqueAlpha);
1567 DrawSetTextUnderColor(WmfDrawingWand,under_color);
1568 under_color=DestroyPixelWand(under_color);
1571 draw_under_color_string(WmfDrawingWand,"none");
1574 /* Set text clipping (META_EXTTEXTOUT mode) */
1575 if ( draw_text->flags & ETO_CLIPPED)
1579 /* Set stroke color */
1580 draw_stroke_color_string(WmfDrawingWand,"none");
1582 /* Set fill color */
1583 draw_fill_color_rgb(API,WMF_DC_TEXTCOLOR(draw_text->dc));
1585 /* Output font size */
1586 (void) DrawSetFontSize(WmfDrawingWand,pointsize);
1588 /* Output Postscript font name */
1589 (void) DrawSetFont(WmfDrawingWand, WMF_FONT_PSNAME(font));
1591 /* Translate coordinates so target is 0,0 */
1592 DrawTranslate(WmfDrawingWand, XC(point.x), YC(point.y));
1594 /* Transform horizontal scale to draw text at 1:1 ratio */
1595 DrawScale(WmfDrawingWand, ddata->scale_y / ddata->scale_x, 1.0);
1597 /* Apply rotation */
1598 /* ImageMagick's drawing rotation is clockwise from horizontal
1599 while WMF drawing rotation is counterclockwise from horizontal */
1600 angle = fabs(RadiansToDegrees(2 * MagickPI - WMF_TEXT_ANGLE(font)));
1604 DrawRotate(WmfDrawingWand, angle);
1612 DrawAnnotation(WmfDrawingWand, 0, 0, (unsigned char*)draw_text->str);
1614 /* Underline text the Windows way (at the bottom) */
1615 if (WMF_TEXT_UNDERLINE(font))
1621 ulBR, /* bottom right of underline rectangle */
1622 ulTL; /* top left of underline rectangle */
1624 line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
1625 if (metrics.underline_thickness < 1.5)
1626 line_height *= 0.55;
1628 ulTL.y = fabs(metrics.descent) - line_height;
1629 ulBR.x = metrics.width;
1630 ulBR.y = fabs(metrics.descent);
1632 DrawRectangle(WmfDrawingWand,
1633 XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
1636 /* Strikeout text the Windows way */
1637 if (WMF_TEXT_STRIKEOUT(font))
1642 ulBR, /* bottom right of strikeout rectangle */
1643 ulTL; /* top left of strikeout rectangle */
1645 line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
1647 if (metrics.underline_thickness < 2.0)
1648 line_height *= 0.55;
1650 ulTL.y = -(((double) metrics.ascent) / 2 + line_height / 2);
1651 ulBR.x = metrics.width;
1652 ulBR.y = -(((double) metrics.ascent) / 2 - line_height / 2);
1654 DrawRectangle(WmfDrawingWand,
1655 XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
1659 /* Restore graphic wand */
1660 (void) PopDrawingWand(WmfDrawingWand);
1663 (void) PushDrawingWand(WmfDrawingWand);
1664 draw_stroke_color_string(WmfDrawingWand,"red");
1665 draw_fill_color_string(WmfDrawingWand,"none");
1666 DrawRectangle(WmfDrawingWand,
1668 XC(BR.x), YC(BR.y));
1669 draw_stroke_color_string(WmfDrawingWand,"none");
1670 (void) PopDrawingWand(WmfDrawingWand);
1675 static void ipa_udata_init(wmfAPI * API, wmfUserData_t * userdata)
1679 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1683 static void ipa_udata_copy(wmfAPI * API, wmfUserData_t * userdata)
1687 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1691 static void ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata)
1695 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1699 static void ipa_udata_free(wmfAPI * API, wmfUserData_t * userdata)
1703 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1707 static inline double MagickMin(const double x,const double y)
1714 static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply)
1717 *ddata = WMF_MAGICK_GetData(API);
1720 *brush = WMF_DC_BRUSH(dc);
1722 /* Set polygon fill rule */
1723 switch (WMF_DC_POLYFILL(dc)) /* Is this correct ?? */
1726 DrawSetClipRule(WmfDrawingWand,NonZeroRule);
1731 DrawSetClipRule(WmfDrawingWand,EvenOddRule);
1735 switch (WMF_BRUSH_STYLE(brush))
1737 case BS_SOLID /* 0 */:
1738 /* WMF_BRUSH_COLOR specifies brush color, WMF_BRUSH_HATCH
1741 if ( brush_apply == BrushApplyStroke )
1742 draw_stroke_color_rgb(API,WMF_BRUSH_COLOR(brush));
1744 draw_fill_color_rgb(API,WMF_BRUSH_COLOR(brush));
1747 case BS_HOLLOW /* 1 */: /* BS_HOLLOW & BS_NULL share enum */
1748 /* WMF_BRUSH_COLOR and WMF_BRUSH_HATCH ignored */
1750 if ( brush_apply == BrushApplyStroke )
1751 draw_stroke_color_string(WmfDrawingWand,"none");
1753 draw_fill_color_string(WmfDrawingWand,"none");
1756 case BS_HATCHED /* 2 */:
1757 /* WMF_BRUSH_COLOR specifies the hatch color, WMF_BRUSH_HATCH
1758 specifies the hatch brush style. If WMF_DC_OPAQUE, then
1759 WMF_DC_BACKGROUND specifies hatch background color. */
1761 DrawPushDefs(WmfDrawingWand);
1762 draw_pattern_push(API, ddata->pattern_id, 8, 8);
1763 (void) PushDrawingWand(WmfDrawingWand);
1765 if (WMF_DC_OPAQUE(dc))
1767 if ( brush_apply == BrushApplyStroke )
1768 draw_stroke_color_rgb(API,WMF_DC_BACKGROUND(dc));
1770 draw_fill_color_rgb(API,WMF_DC_BACKGROUND(dc));
1772 DrawRectangle(WmfDrawingWand, 0, 0, 7, 7 );
1775 DrawSetStrokeAntialias(WmfDrawingWand, MagickFalse);
1776 DrawSetStrokeWidth(WmfDrawingWand, 1);
1778 draw_stroke_color_rgb(API,WMF_BRUSH_COLOR(brush));
1780 switch ((unsigned int) WMF_BRUSH_HATCH(brush))
1783 case HS_HORIZONTAL: /* ----- */
1785 DrawLine(WmfDrawingWand, 0, 3, 7,3);
1788 case HS_VERTICAL: /* ||||| */
1790 DrawLine(WmfDrawingWand, 3, 0, 3, 7);
1793 case HS_FDIAGONAL: /* \\\\\ */
1795 DrawLine(WmfDrawingWand, 0, 0, 7, 7);
1798 case HS_BDIAGONAL: /* / */
1800 DrawLine(WmfDrawingWand, 0, 7, 7, 0 );
1803 case HS_CROSS: /* +++++ */
1805 DrawLine(WmfDrawingWand, 0, 3, 7, 3 );
1806 DrawLine(WmfDrawingWand, 3, 0, 3, 7 );
1809 case HS_DIAGCROSS: /* xxxxx */
1811 DrawLine(WmfDrawingWand, 0, 0, 7, 7 );
1812 DrawLine(WmfDrawingWand, 0, 7, 7, 0 );
1817 printf("util_set_brush: unexpected brush hatch enumeration %u\n",
1818 (unsigned int)WMF_BRUSH_HATCH(brush));
1821 (void) PopDrawingWand(WmfDrawingWand);
1822 (void) DrawPopPattern(WmfDrawingWand);
1823 DrawPopDefs(WmfDrawingWand);
1828 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
1830 if (brush_apply == BrushApplyStroke )
1831 (void) DrawSetStrokePatternURL(WmfDrawingWand,pattern_id);
1833 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
1834 ++ddata->pattern_id;
1838 case BS_PATTERN /* 3 */:
1839 /* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides handle to
1842 printf("util_set_brush: BS_PATTERN not supported\n");
1845 case BS_INDEXED /* 4 */:
1847 printf("util_set_brush: BS_INDEXED not supported\n");
1850 case BS_DIBPATTERN /* 5 */:
1853 *brush_bmp = WMF_BRUSH_BITMAP(brush);
1855 if (brush_bmp && brush_bmp->data != 0)
1869 GetExceptionInfo(&exception);
1871 image = (Image*)brush_bmp->data;
1873 mode = CopyCompositeOp; /* Default is copy */
1874 switch (WMF_DC_ROP(dc))
1876 /* Binary raster ops */
1878 printf("util_set_brush: R2_BLACK ROP2 mode not supported!\n");
1880 case R2_NOTMERGEPEN:
1881 printf("util_set_brush: R2_NOTMERGEPEN ROP2 mode not supported!\n");
1884 printf("util_set_brush R2_MASKNOTPEN ROP2 mode not supported!\n");
1887 printf("util_set_brush: R2_NOTCOPYPEN ROP2 mode not supported!\n");
1890 printf("util_set_brush: R2_MASKPENNOT ROP2 mode not supported!\n");
1893 printf("util_set_brush: R2_NOT ROP2 mode not supported!\n");
1896 printf("util_set_brush: R2_XORPEN ROP2 mode not supported!\n");
1899 printf("util_set_brush: R2_NOTMASKPEN ROP2 mode not supported!\n");
1902 printf("util_set_brush: R2_MASKPEN ROP2 mode not supported!\n");
1905 printf("util_set_brush: R2_NOTXORPEN ROP2 mode not supported!\n");
1908 printf("util_set_brush: R2_NOP ROP2 mode not supported!\n");
1910 case R2_MERGENOTPEN:
1911 printf("util_set_brush: R2_MERGENOTPEN ROP2 mode not supported!\n");
1914 mode = CopyCompositeOp;
1916 case R2_MERGEPENNOT:
1917 printf("util_set_brush: R2_MERGEPENNOT ROP2 mode not supported!\n");
1920 printf("util_set_brush: R2_MERGEPEN ROP2 mode not supported!\n");
1923 printf("util_set_brush: R2_WHITE ROP2 mode not supported!\n");
1927 printf("util_set_brush: unexpected ROP2 enumeration %u!\n",
1928 (unsigned int)WMF_DC_ROP(dc));
1932 DrawPushDefs(WmfDrawingWand);
1933 draw_pattern_push(API, ddata->pattern_id, brush_bmp->width,
1935 magick_wand=NewMagickWandFromImage(image);
1936 (void) DrawComposite(WmfDrawingWand,mode, 0, 0, brush_bmp->width,
1937 brush_bmp->height, magick_wand);
1938 magick_wand=DestroyMagickWand(magick_wand);
1939 (void) DrawPopPattern(WmfDrawingWand);
1940 DrawPopDefs(WmfDrawingWand);
1946 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
1948 if ( brush_apply == BrushApplyStroke )
1949 (void) DrawSetStrokePatternURL(WmfDrawingWand,pattern_id);
1951 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
1952 ++ddata->pattern_id;
1956 printf("util_set_brush: no BMP image data!\n");
1960 case BS_DIBPATTERNPT /* 6 */:
1961 /* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides pointer to
1964 printf("util_set_brush: BS_DIBPATTERNPT not supported\n");
1967 case BS_PATTERN8X8 /* 7 */:
1969 printf("util_set_brush: BS_PATTERN8X8 not supported\n");
1972 case BS_DIBPATTERN8X8 /* 8 */:
1974 printf("util_set_brush: BS_DIBPATTERN8X8 not supported\n");
1983 static inline double MagickMax(const double x,const double y)
1990 static void util_set_pen(wmfAPI * API, wmfDC * dc)
1993 *ddata = WMF_MAGICK_GetData(API);
2006 pen = WMF_DC_PEN(dc);
2008 pen_width = (WMF_PEN_WIDTH(pen) + WMF_PEN_HEIGHT(pen)) / 2;
2010 /* Pixel width is inverse of pixel scale */
2011 pixel_width = (((double) 1 / (ddata->scale_x)) +
2012 ((double) 1 / (ddata->scale_y))) / 2;
2014 /* Don't allow pen_width to be much less than pixel_width in order
2015 to avoid dissapearing or spider-web lines */
2016 pen_width = MagickMax(pen_width, pixel_width*0.8);
2018 pen_style = (unsigned int) WMF_PEN_STYLE(pen);
2019 pen_type = (unsigned int) WMF_PEN_TYPE(pen);
2022 /* Pen style specified? */
2023 if (pen_style == PS_NULL)
2025 draw_stroke_color_string(WmfDrawingWand,"none");
2029 DrawSetStrokeAntialias(WmfDrawingWand, MagickTrue );
2030 DrawSetStrokeWidth(WmfDrawingWand, (unsigned long) MagickMax(0.0, pen_width));
2036 switch ((unsigned int) WMF_PEN_ENDCAP(pen))
2038 case PS_ENDCAP_SQUARE:
2039 linecap = SquareCap;
2041 case PS_ENDCAP_ROUND:
2044 case PS_ENDCAP_FLAT:
2049 DrawSetStrokeLineCap(WmfDrawingWand, linecap);
2056 switch ((unsigned int) WMF_PEN_JOIN(pen))
2059 linejoin = BevelJoin;
2062 linejoin = RoundJoin;
2066 linejoin = MiterJoin;
2069 DrawSetStrokeLineJoin(WmfDrawingWand,linejoin);
2078 case PS_DASH: /* ------- */
2081 dasharray[0] = pixel_width * 18;
2082 dasharray[1] = pixel_width * 7;
2085 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2086 (void) DrawSetStrokeDashArray(WmfDrawingWand,2,dasharray);
2090 case PS_DOT: /* ....... */
2093 dasharray[0] = pixel_width * 3;
2094 dasharray[1] = pixel_width * 3;
2097 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2098 (void) DrawSetStrokeDashArray(WmfDrawingWand,2,dasharray);
2101 case PS_DASHDOT: /* _._._._ */
2103 /* Pattern 9,6,3,6 */
2104 dasharray[0] = pixel_width * 9;
2105 dasharray[1] = pixel_width * 6;
2106 dasharray[2] = pixel_width * 3;
2107 dasharray[3] = pixel_width * 6;
2110 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2111 (void) DrawSetStrokeDashArray(WmfDrawingWand,4,dasharray);
2114 case PS_DASHDOTDOT: /* _.._.._ */
2116 /* Pattern 9,3,3,3,3,3 */
2117 dasharray[0] = pixel_width * 9;
2118 dasharray[1] = pixel_width * 3;
2119 dasharray[2] = pixel_width * 3;
2120 dasharray[3] = pixel_width * 3;
2121 dasharray[4] = pixel_width * 3;
2122 dasharray[5] = pixel_width * 3;
2125 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2126 (void) DrawSetStrokeDashArray(WmfDrawingWand,6,dasharray);
2129 case PS_INSIDEFRAME: /* There is nothing to do in this case... */
2133 (void) DrawSetStrokeDashArray(WmfDrawingWand,0,(double *)NULL);
2139 draw_stroke_color_rgb(API,WMF_PEN_COLOR(pen));
2142 /* Estimate font pointsize based on Windows font parameters */
2143 static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height, ExceptionInfo *exception)
2146 *ddata = WMF_MAGICK_GetData(API);
2149 *image = ddata->image;
2160 draw_info=ddata->draw_info;
2161 if (draw_info == (const DrawInfo *) NULL)
2164 draw_info->font=WMF_FONT_PSNAME(font);
2165 draw_info->pointsize=font_height;
2166 draw_info->text=str;
2168 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2171 if (strlen(str) == 1)
2173 pointsize = (font_height *
2174 ( font_height / (metrics.ascent + fabs(metrics.descent))));
2175 draw_info->pointsize = pointsize;
2176 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2177 pointsize *= (font_height / ( metrics.ascent + fabs(metrics.descent)));
2181 pointsize = (font_height * (font_height / (metrics.height)));
2182 draw_info->pointsize = pointsize;
2183 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2184 pointsize *= (font_height / metrics.height);
2188 draw_info.pointsize = pointsize;
2189 if (GetTypeMetrics(image, &draw_info, &metrics, exception) != MagickFalse)
2190 pointsize *= (font_height / (metrics.ascent + fabs(metrics.descent)));
2191 pointsize *= 1.114286; /* Magic number computed through trial and error */
2195 draw_info->font=NULL;
2196 draw_info->text=NULL;
2198 printf("String = %s\n", str);
2199 printf("Font = %s\n", WMF_FONT_PSNAME(font));
2200 printf("lfHeight = %g\n", font_height);
2201 printf("bounds = %g,%g %g,%g\n", metrics.bounds.x1, metrics.bounds.y1,
2202 metrics.bounds.x2,metrics.bounds.y2);
2203 printf("ascent = %g\n", metrics.ascent);
2204 printf("descent = %g\n", metrics.descent);
2205 printf("height = %g\n", metrics.height);
2206 printf("Pointsize = %g\n", pointsize);
2209 return floor(pointsize);
2212 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
2213 /* Estimate weight based on font name */
2215 static int util_font_weight( const char* font )
2221 if ((strstr(font,"Normal") || strstr(font,"Regular")))
2223 else if ( strstr(font,"Bold") )
2226 if ((strstr(font,"Semi") || strstr(font,"Demi")))
2228 if ( (strstr(font,"Extra") || strstr(font,"Ultra")))
2231 else if ( strstr(font,"Light") )
2234 if ( (strstr(font,"Extra") || strstr(font,"Ultra")))
2237 else if ((strstr(font,"Heavy") || strstr(font,"Black")))
2239 else if ( strstr(font,"Thin") )
2246 * Returns width of string in points, assuming (unstretched) font size of 1pt
2247 * (similar to wmf_ipa_font_stringwidth)
2249 * This extremely odd at best, particularly since player/meta.h has access
2250 * to the corrected font_height (as drawtext.font_height) when it invokes the
2251 * stringwidth callback. It should be possible to compute the real stringwidth!
2253 static float lite_font_stringwidth( wmfAPI* API, wmfFont* font, char* str)
2257 *ddata = WMF_MAGICK_GetData(API);
2260 *image = ddata->image;
2279 orig_resolution_units;
2281 orig_x_resolution = image->resolution.x;
2282 orig_y_resolution = image->resolution.y;
2283 orig_resolution_units = image->units;
2285 draw_info=ddata->draw_info;
2286 if (draw_info == (const DrawInfo *) NULL)
2289 draw_info->font=WMF_FONT_PSNAME(font);
2290 draw_info->pointsize=12;
2291 draw_info->text=str;
2293 image->resolution.x = 72;
2294 image->resolution.y = 72;
2295 image->units = PixelsPerInchResolution;
2297 exception=ddata->exception;
2298 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2299 stringwidth = ((metrics.width * 72)/(image->resolution.x * draw_info->pointsize)); /* *0.916348; */
2301 draw_info->font=NULL;
2302 draw_info->text=NULL;
2305 printf("\nlite_font_stringwidth\n");
2306 printf("string = \"%s\"\n", str);
2307 printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
2308 printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
2309 printf("stringwidth = %g\n", stringwidth);
2310 /* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
2311 /* printf("WMF_FONT_WIDTH = %i\n", (int)WMF_FONT_WIDTH(font)); */
2315 image->resolution.x = orig_x_resolution;
2316 image->resolution.y = orig_y_resolution;
2317 image->units = orig_resolution_units;
2329 /* Map font (similar to wmf_ipa_font_map) */
2331 /* Mappings to Postscript fonts: family, normal, italic, bold, bolditalic */
2332 static wmfFontMap WMFFontMap[] = {
2333 { (char *) "Courier", (char *) "Courier",
2334 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2335 (char *) "Courier-BoldOblique" },
2336 { (char *) "Helvetica", (char *) "Helvetica",
2337 (char *) "Helvetica-Oblique", (char *) "Helvetica-Bold",
2338 (char *) "Helvetica-BoldOblique" },
2339 { (char *) "Modern", (char *) "Courier",
2340 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2341 (char *) "Courier-BoldOblique" },
2342 { (char *) "Monotype Corsiva", (char *) "Courier",
2343 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2344 (char *) "Courier-BoldOblique" },
2345 { (char *) "News Gothic", (char *) "Helvetica",
2346 (char *) "Helvetica-Oblique", (char *) "Helvetica-Bold",
2347 (char *) "Helvetica-BoldOblique" },
2348 { (char *) "Symbol", (char *) "Symbol",
2349 (char *) "Symbol", (char *) "Symbol",
2350 (char *) "Symbol" },
2351 { (char *) "System", (char *) "Courier",
2352 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2353 (char *) "Courier-BoldOblique" },
2354 { (char *) "Times", (char *) "Times-Roman",
2355 (char *) "Times-Italic", (char *) "Times-Bold",
2356 (char *) "Times-BoldItalic" },
2357 { (char *) NULL, (char *) NULL,
2358 (char *) NULL, (char *) NULL,
2363 /* Mapping between base name and Ghostscript family name */
2364 static wmfMapping SubFontMap[] =
2366 { (char *) "Arial", (char *) "Helvetica", FT_ENCODING_NONE },
2367 { (char *) "Courier", (char *) "Courier", FT_ENCODING_NONE },
2368 { (char *) "Fixed", (char *) "Courier", FT_ENCODING_NONE },
2369 { (char *) "Helvetica", (char *) "Helvetica", FT_ENCODING_NONE },
2370 { (char *) "Sans", (char *) "Helvetica", FT_ENCODING_NONE },
2371 { (char *) "Sym", (char *) "Symbol", FT_ENCODING_NONE },
2372 { (char *) "Terminal", (char *) "Courier", FT_ENCODING_NONE },
2373 { (char *) "Times", (char *) "Times", FT_ENCODING_NONE },
2374 { (char *) "Wingdings", (char *) "Symbol", FT_ENCODING_NONE },
2375 { (char *) NULL, (char *) NULL, FT_ENCODING_NONE }
2378 static void lite_font_map( wmfAPI* API, wmfFont* font)
2387 *ddata = WMF_MAGICK_GetData(API);
2402 font_data = (wmfFontData*)API->font_data;
2403 font->user_data = font_data->user_data;
2404 magick_font = (wmf_magick_font_t*)font->user_data;
2405 wmf_font_name = WMF_FONT_NAME(font);
2407 if (magick_font->ps_name != (char *) NULL)
2408 magick_font->ps_name=DestroyString(magick_font->ps_name);
2410 exception=ddata->exception;
2411 type_info_base=GetTypeInfo("*",exception);
2412 if (type_info_base == 0)
2415 /* Certain short-hand font names are not the proper Windows names
2416 and should be promoted to the proper names */
2417 if (LocaleCompare(wmf_font_name,"Times") == 0)
2418 wmf_font_name = "Times New Roman";
2419 else if (LocaleCompare(wmf_font_name,"Courier") == 0)
2420 wmf_font_name = "Courier New";
2422 /* Look for a family-based best-match */
2423 if (!magick_font->ps_name)
2428 if (WMF_FONT_WEIGHT(font) == 0)
2429 target_weight = 400;
2431 target_weight = WMF_FONT_WEIGHT(font);
2432 type_info=GetTypeInfoByFamily(wmf_font_name,AnyStyle,AnyStretch,
2433 target_weight,exception);
2434 if (type_info == (const TypeInfo *) NULL)
2435 type_info=GetTypeInfoByFamily(wmf_font_name,AnyStyle,AnyStretch,0,
2437 if (type_info != (const TypeInfo *) NULL)
2438 CloneString(&magick_font->ps_name,type_info->name);
2441 /* Now let's try simple substitution mappings from WMFFontMap */
2442 if (!magick_font->ps_name)
2445 target[MaxTextExtent];
2448 target_weight = 400,
2449 want_italic = MagickFalse,
2450 want_bold = MagickFalse,
2453 if ( WMF_FONT_WEIGHT(font) != 0 )
2454 target_weight = WMF_FONT_WEIGHT(font);
2456 if ( (target_weight > 550) || ((strstr(wmf_font_name,"Bold") ||
2457 strstr(wmf_font_name,"Heavy") ||
2458 strstr(wmf_font_name,"Black"))) )
2459 want_bold = MagickTrue;
2461 if ( (WMF_FONT_ITALIC(font)) || ((strstr(wmf_font_name,"Italic") ||
2462 strstr(wmf_font_name,"Oblique"))) )
2463 want_italic = MagickTrue;
2465 (void) CopyMagickString(target,"Times",MaxTextExtent);
2466 for( i=0; SubFontMap[i].name != NULL; i++ )
2468 if (LocaleCompare(wmf_font_name, SubFontMap[i].name) == 0)
2470 (void) CopyMagickString(target,SubFontMap[i].mapping,
2476 for( i=0; WMFFontMap[i].name != NULL; i++ )
2478 if (LocaleNCompare(WMFFontMap[i].name,target,strlen(WMFFontMap[i].name)) == 0)
2480 if (want_bold && want_italic)
2481 CloneString(&magick_font->ps_name,WMFFontMap[i].bolditalic);
2482 else if (want_italic)
2483 CloneString(&magick_font->ps_name,WMFFontMap[i].italic);
2485 CloneString(&magick_font->ps_name,WMFFontMap[i].bold);
2487 CloneString(&magick_font->ps_name,WMFFontMap[i].normal);
2493 printf("\nlite_font_map\n");
2494 printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
2495 printf("WMF_FONT_WEIGHT = %i\n", WMF_FONT_WEIGHT(font));
2496 printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
2502 /* Initialize API font structures */
2503 static void lite_font_init( wmfAPI* API, wmfAPI_Options* options)
2511 /* Allocate wmfFontData data structure */
2512 API->font_data = wmf_malloc(API,sizeof(wmfFontData));
2516 font_data = (wmfFontData*)API->font_data;
2518 /* Assign function to map font (type wmfMap) */
2519 font_data->map = lite_font_map;
2521 /* Assign function to return string width in points (type wmfStringWidth) */
2522 font_data->stringwidth = lite_font_stringwidth;
2524 /* Assign user data, not used by libwmflite (type void*) */
2525 font_data->user_data = wmf_malloc(API,sizeof(wmf_magick_font_t));
2528 ((wmf_magick_font_t*)font_data->user_data)->ps_name = 0;
2529 ((wmf_magick_font_t*)font_data->user_data)->pointsize = 0;
2532 #endif /* MAGICKCORE_WMFLITE_DELEGATE */
2534 /* BLOB read byte */
2535 static int ipa_blob_read(void* wand)
2537 return ReadBlobByte((Image*)wand);
2541 static int ipa_blob_seek(void* wand,long position)
2543 return (int)SeekBlob((Image*)wand,(MagickOffsetType) position,SEEK_SET);
2547 static long ipa_blob_tell(void* wand)
2549 return (long)TellBlob((Image*)wand);
2552 static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
2573 wmf_options_flags = 0;
2590 image=AcquireImage(image_info,exception);
2591 if (OpenBlob(image_info,image,ReadBinaryBlobMode,exception) == MagickFalse)
2593 if (image->debug != MagickFalse)
2595 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2596 " OpenBlob failed");
2597 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2598 "leave ReadWMFImage()");
2600 image=DestroyImageList(image);
2601 return((Image *) NULL);
2609 /* Register callbacks */
2610 wmf_options_flags |= WMF_OPT_FUNCTION;
2611 (void) ResetMagickMemory(&wmf_api_options, 0, sizeof(wmf_api_options));
2612 wmf_api_options.function = ipa_functions;
2614 /* Ignore non-fatal errors */
2615 wmf_options_flags |= WMF_OPT_IGNORE_NONFATAL;
2617 wmf_error = wmf_api_create(&API, wmf_options_flags, &wmf_api_options);
2618 if (wmf_error != wmf_E_None)
2621 wmf_api_destroy(API);
2622 if (image->debug != MagickFalse)
2624 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2625 " wmf_api_create failed");
2626 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2627 "leave ReadWMFImage()");
2629 ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
2632 /* Register progress monitor */
2633 wmf_status_function(API,image,magick_progress_callback);
2635 ddata=WMF_MAGICK_GetData(API);
2637 ddata->image_info=image_info;
2638 ddata->draw_info=CloneDrawInfo(image_info,(const DrawInfo *) NULL);
2639 ddata->exception=exception;
2640 ddata->draw_info->font=(char *)
2641 RelinquishMagickMemory(ddata->draw_info->font);
2642 ddata->draw_info->text=(char *)
2643 RelinquishMagickMemory(ddata->draw_info->text);
2645 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
2646 /* Must initialize font subystem for WMFlite interface */
2647 lite_font_init (API,&wmf_api_options); /* similar to wmf_ipa_font_init in src/font.c */
2648 /* wmf_arg_fontdirs (API,options); */ /* similar to wmf_arg_fontdirs in src/wmf.c */
2653 * Open BLOB input via libwmf API
2656 wmf_error = wmf_bbuf_input(API,ipa_blob_read,ipa_blob_seek,
2657 ipa_blob_tell,(void*)image);
2658 if (wmf_error != wmf_E_None)
2660 wmf_api_destroy(API);
2661 if (image->debug != MagickFalse)
2663 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2664 " wmf_bbuf_input failed");
2665 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2666 "leave ReadWMFImage()");
2668 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
2670 image=DestroyImageList(image);
2671 return((Image *) NULL);
2678 if (image->debug != MagickFalse)
2679 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2680 " Scanning WMF to obtain bounding box");
2681 wmf_error=wmf_scan(API, 0, &bbox);
2682 if (wmf_error != wmf_E_None)
2684 wmf_api_destroy(API);
2685 if (image->debug != MagickFalse)
2687 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2688 " wmf_scan failed with wmf_error %d", wmf_error);
2689 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2690 "leave ReadWMFImage()");
2692 ThrowReaderException(DelegateError,"FailedToScanFile");
2696 * Compute dimensions and scale factors
2702 /* User specified resolution */
2703 resolution_y=DefaultResolution;
2704 if (image->resolution.y != 0.0)
2706 resolution_y = image->resolution.y;
2707 if (image->units == PixelsPerCentimeterResolution)
2708 resolution_y *= CENTIMETERS_PER_INCH;
2710 resolution_x=DefaultResolution;
2711 if (image->resolution.x != 0.0)
2713 resolution_x = image->resolution.x;
2714 if (image->units == PixelsPerCentimeterResolution)
2715 resolution_x *= CENTIMETERS_PER_INCH;
2718 /* Obtain output size expressed in metafile units */
2719 wmf_error=wmf_size(API,&wmf_width,&wmf_height);
2720 if (wmf_error != wmf_E_None)
2722 wmf_api_destroy(API);
2723 if (image->debug != MagickFalse)
2725 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2726 " wmf_size failed with wmf_error %d", wmf_error);
2727 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2728 "leave ReadWMFImage()");
2730 ThrowReaderException(DelegateError,"FailedToComputeOutputSize");
2733 /* Obtain (or guess) metafile units */
2734 if ((API)->File->placeable)
2735 units_per_inch=(API)->File->pmh->Inch;
2736 else if ( (wmf_width*wmf_height) < 1024*1024)
2737 units_per_inch=POINTS_PER_INCH; /* MM_TEXT */
2739 units_per_inch=TWIPS_PER_INCH; /* MM_TWIPS */
2741 /* Calculate image width and height based on specified DPI
2743 image_width_inch = (double) wmf_width / units_per_inch;
2744 image_height_inch = (double) wmf_height / units_per_inch;
2745 image_width = image_width_inch * resolution_x;
2746 image_height = image_height_inch * resolution_y;
2748 /* Compute bounding box scale factors and origin translations
2750 * This all just a hack since libwmf does not currently seem to
2751 * provide the mapping between LOGICAL coordinates and DEVICE
2752 * coordinates. This mapping is necessary in order to know
2753 * where to place the logical bounding box within the image.
2757 bounding_width = bbox.BR.x - bbox.TL.x;
2758 bounding_height = bbox.BR.y - bbox.TL.y;
2760 ddata->scale_x = image_width/bounding_width;
2761 ddata->translate_x = 0-bbox.TL.x;
2764 /* Heuristic: guess that if the vertical coordinates mostly span
2765 negative values, then the image must be inverted. */
2766 if ( fabs(bbox.BR.y) > fabs(bbox.TL.y) )
2768 /* Normal (Origin at top left of image) */
2769 ddata->scale_y = (image_height/bounding_height);
2770 ddata->translate_y = 0-bbox.TL.y;
2774 /* Inverted (Origin at bottom left of image) */
2775 ddata->scale_y = (-image_height/bounding_height);
2776 ddata->translate_y = 0-bbox.BR.y;
2779 if (image->debug != MagickFalse)
2781 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2782 " Placeable metafile: %s",
2783 (API)->File->placeable ? "Yes" : "No");
2785 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2786 " Size in metafile units: %gx%g",wmf_width,wmf_height);
2787 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2788 " Metafile units/inch: %g",units_per_inch);
2789 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2790 " Size in inches: %gx%g",
2791 image_width_inch,image_height_inch);
2792 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2793 " Bounding Box: %g,%g %g,%g",
2794 bbox.TL.x, bbox.TL.y, bbox.BR.x, bbox.BR.y);
2795 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2796 " Bounding width x height: %gx%g",bounding_width,
2798 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2799 " Output resolution: %gx%g",resolution_x,resolution_y);
2800 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2801 " Image size: %gx%g",image_width,image_height);
2802 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2803 " Bounding box scale factor: %g,%g",ddata->scale_x,
2805 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2806 " Translation: %g,%g",
2807 ddata->translate_x, ddata->translate_y);
2813 typedef struct _wmfPlayer_t wmfPlayer_t;
2817 wmfBrush default_brush;
2818 wmfFont default_font;
2820 wmfDC* dc; /* current dc */
2826 #define WMF_ELICIT_DC(API) (((wmfPlayer_t*)((API)->player_data))->dc)
2828 dc = WMF_ELICIT_DC(API);
2830 printf("dc->Window.Ox = %d\n", dc->Window.Ox);
2831 printf("dc->Window.Oy = %d\n", dc->Window.Oy);
2832 printf("dc->Window.width = %d\n", dc->Window.width);
2833 printf("dc->Window.height = %d\n", dc->Window.height);
2834 printf("dc->pixel_width = %g\n", dc->pixel_width);
2835 printf("dc->pixel_height = %g\n", dc->pixel_height);
2836 #if defined(MAGICKCORE_WMFLITE_DELEGATE) /* Only in libwmf 0.3 */
2837 printf("dc->Ox = %.d\n", dc->Ox);
2838 printf("dc->Oy = %.d\n", dc->Oy);
2839 printf("dc->width = %.d\n", dc->width);
2840 printf("dc->height = %.d\n", dc->height);
2849 * Create canvas image
2852 image->rows=(unsigned long) ceil(image_height);
2853 image->columns=(unsigned long) ceil(image_width);
2855 if (image_info->ping != MagickFalse)
2857 wmf_api_destroy(API);
2858 (void) CloseBlob(image);
2859 if (image->debug != MagickFalse)
2860 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2861 "leave ReadWMFImage()");
2862 return(GetFirstImageInList(image));
2864 if (image->debug != MagickFalse)
2865 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2866 " Creating canvas image with size %lux%lu",(unsigned long) image->rows,
2867 (unsigned long) image->columns);
2870 * Set solid background color
2873 image->background_color = image_info->background_color;
2874 if (image->background_color.alpha != OpaqueAlpha)
2875 image->alpha_trait=BlendPixelTrait;
2876 (void) SetImageBackgroundColor(image,exception);
2879 * Play file to generate Vector drawing commands
2883 if (image->debug != MagickFalse)
2884 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2885 " Playing WMF to prepare vectors");
2887 wmf_error = wmf_play(API, 0, &bbox);
2888 if (wmf_error != wmf_E_None)
2890 wmf_api_destroy(API);
2891 if (image->debug != MagickFalse)
2893 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2894 " Playing WMF failed with wmf_error %d", wmf_error);
2895 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2896 "leave ReadWMFImage()");
2898 ThrowReaderException(DelegateError,"FailedToRenderFile");
2902 * Scribble on canvas image
2906 if (image->debug != MagickFalse)
2907 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2908 " Rendering WMF vectors");
2909 DrawRender(ddata->draw_wand);
2911 if (image->debug != MagickFalse)
2912 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
2914 /* Cleanup allocated data */
2915 wmf_api_destroy(API);
2916 (void) CloseBlob(image);
2924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2928 % R e g i s t e r W M F I m a g e %
2932 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2934 % RegisterWMFImage() adds attributes for the WMF image format to
2935 % the list of supported formats. The attributes include the image format
2936 % tag, a method to read and/or write the format, whether the format
2937 % supports the saving of more than one frame to the same file or blob,
2938 % whether the format supports native in-memory I/O, and a brief
2939 % description of the format.
2941 % The format of the RegisterWMFImage method is:
2943 % size_t RegisterWMFImage(void)
2946 ModuleExport size_t RegisterWMFImage(void)
2951 entry = SetMagickInfo("WMZ");
2952 #if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
2953 entry->decoder=ReadWMFImage;
2955 entry->description=ConstantString("Compressed Windows Meta File");
2956 entry->module=ConstantString("WMZ");
2957 entry->seekable_stream=MagickTrue;
2958 (void) RegisterMagickInfo(entry);
2959 entry=SetMagickInfo("WMF");
2960 #if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
2961 entry->decoder=ReadWMFImage;
2963 entry->description=ConstantString("Windows Meta File");
2964 entry->module=ConstantString("WMF");
2965 (void) RegisterMagickInfo(entry);
2966 return(MagickImageCoderSignature);
2970 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2974 % U n r e g i s t e r W M F I m a g e %
2978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2980 % UnregisterWMFImage() removes format registrations made by the
2981 % WMF module from the list of supported formats.
2983 % The format of the UnregisterWMFImage method is:
2985 % UnregisterWMFImage(void)
2988 ModuleExport void UnregisterWMFImage(void)
2990 (void) UnregisterMagickInfo("WMZ");
2991 (void) UnregisterMagickInfo("WMF");