2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Windows Metafile Format %
20 % Copyright 1999-2012 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)
454 image=(Image *) context;
455 assert(image->signature == MagickSignature);
456 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
458 return(status == MagickTrue ? 0 : 1);
462 static void draw_fill_color_string(DrawingWand *drawing_wand,const char *color)
467 fill_color=NewPixelWand();
468 PixelSetColor(fill_color,color);
469 DrawSetFillColor(drawing_wand,fill_color);
470 fill_color=DestroyPixelWand(fill_color);
472 static void draw_fill_color_rgb( wmfAPI* API, const wmfRGB* rgb )
477 fill_color=NewPixelWand();
478 PixelSetRedQuantum(fill_color,ScaleCharToQuantum(rgb->r));
479 PixelSetGreenQuantum(fill_color,ScaleCharToQuantum(rgb->g));
480 PixelSetBlueQuantum(fill_color,ScaleCharToQuantum(rgb->b));
481 PixelSetAlphaQuantum(fill_color,OpaqueAlpha);
482 DrawSetFillColor(WmfDrawingWand,fill_color);
483 fill_color=DestroyPixelWand(fill_color);
486 /* Set stroke color */
487 static void draw_stroke_color_string(DrawingWand *drawing_wand,const char *color)
492 stroke_color=NewPixelWand();
493 PixelSetColor(stroke_color,color);
494 DrawSetStrokeColor(drawing_wand,stroke_color);
495 stroke_color=DestroyPixelWand(stroke_color);
498 static void draw_stroke_color_rgb( wmfAPI* API, const wmfRGB* rgb )
503 stroke_color=NewPixelWand();
504 PixelSetRedQuantum(stroke_color,ScaleCharToQuantum(rgb->r));
505 PixelSetGreenQuantum(stroke_color,ScaleCharToQuantum(rgb->g));
506 PixelSetBlueQuantum(stroke_color,ScaleCharToQuantum(rgb->b));
507 PixelSetAlphaQuantum(stroke_color,OpaqueAlpha);
508 DrawSetStrokeColor(WmfDrawingWand,stroke_color);
509 stroke_color=DestroyPixelWand(stroke_color);
512 /* Set under color */
513 static void draw_under_color_string(DrawingWand *drawing_wand,const char *color)
518 under_color=NewPixelWand();
519 PixelSetColor(under_color,color);
520 DrawSetTextUnderColor(drawing_wand,under_color);
521 under_color=DestroyPixelWand(under_color);
524 static void draw_pattern_push( wmfAPI* API,
526 unsigned long columns,
532 (void) FormatLocaleString(pattern_id,MaxTextExtent,"brush_%lu",id);
533 (void) DrawPushPattern(WmfDrawingWand,pattern_id,0,0,columns,rows);
536 /* Pattern/Bit BLT with raster operation (ROP) support. Invoked by
537 META_PATBLT, which is equivalent to Windows PatBlt() call, or by
538 META_DIBBITBLT which is equivalent to Windows BitBlt() call. */
540 /* The BitBlt function transfers pixels from a rectangular area in one
541 device wand called the 'source', to a rectangular area of the
542 same size in another device wand, called the 'destination'. */
544 static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw)
547 /* *brush = WMF_DC_BRUSH(rop_draw->dc); */
550 /* *brush_bmp = WMF_BRUSH_BITMAP(brush); */
552 if (TO_FILL(rop_draw) == 0)
555 /* Save graphic wand */
556 (void) PushDrawingWand(WmfDrawingWand);
558 /* FIXME: finish implementing (once we know what it is supposed to do!) */
561 struct _wmfROP_Draw_t
574 /* if (brush_bmp && brush_bmp->data != 0) */
575 /* printf("Have an image!\n"); */
577 switch (rop_draw->ROP) /* Ternary raster operations */
579 case SRCCOPY: /* dest = source */
580 printf("ipa_rop_draw SRCCOPY ROP mode not implemented\n");
582 case SRCPAINT: /* dest = source OR dest */
583 printf("ipa_rop_draw SRCPAINT ROP mode not implemented\n");
585 case SRCAND: /* dest = source AND dest */
586 printf("ipa_rop_draw SRCAND ROP mode not implemented\n");
588 case SRCINVERT: /* dest = source XOR dest */
589 printf("ipa_rop_draw SRCINVERT ROP mode not implemented\n");
591 case SRCERASE: /* dest = source AND (NOT dest) */
592 printf("ipa_rop_draw SRCERASE ROP mode not implemented\n");
594 case NOTSRCCOPY: /* dest = (NOT source) */
595 printf("ipa_rop_draw NOTSRCCOPY ROP mode not implemented\n");
597 case NOTSRCERASE: /* dest = (NOT src) AND (NOT dest) */
598 printf("ipa_rop_draw NOTSRCERASE ROP mode not implemented\n");
600 case MERGECOPY: /* dest = (source AND pattern) */
601 printf("ipa_rop_draw MERGECOPY ROP mode not implemented\n");
603 case MERGEPAINT: /* dest = (NOT source) OR dest */
604 printf("ipa_rop_draw MERGEPAINT ROP mode not implemented\n");
606 case PATCOPY: /* dest = pattern */
607 util_set_brush(API, rop_draw->dc, BrushApplyFill);
609 case PATPAINT: /* dest = DPSnoo */
610 printf("ipa_rop_draw PATPAINT ROP mode not implemented\n");
612 case PATINVERT: /* dest = pattern XOR dest */
613 printf("ipa_rop_draw PATINVERT ROP mode not implemented\n");
615 case DSTINVERT: /* dest = (NOT dest) */
616 printf("ipa_rop_draw DSTINVERT ROP mode not implemented\n");
618 case BLACKNESS: /* dest = BLACK */
619 draw_fill_color_string(WmfDrawingWand,"black");
621 case WHITENESS: /* dest = WHITE */
622 draw_fill_color_string(WmfDrawingWand,"white");
625 printf("ipa_rop_draw 0x%x ROP mode not implemented\n", rop_draw->ROP);
629 DrawRectangle(WmfDrawingWand,
630 XC(rop_draw->TL.x), YC(rop_draw->TL.y),
631 XC(rop_draw->BR.x), YC(rop_draw->BR.y));
633 /* Restore graphic wand */
634 (void) PopDrawingWand(WmfDrawingWand);
637 static void ipa_bmp_draw(wmfAPI *API, wmfBMP_Draw_t *bmp_draw)
640 *ddata = WMF_MAGICK_GetData(API);
658 if (bmp_draw->bmp.data == 0)
661 image = (Image*)bmp_draw->bmp.data;
665 exception=ddata->exception;
666 if (bmp_draw->crop.x || bmp_draw->crop.y ||
667 (bmp_draw->crop.w != bmp_draw->bmp.width) ||
668 (bmp_draw->crop.h != bmp_draw->bmp.height))
670 /* Image needs to be cropped */
677 crop_info.x = bmp_draw->crop.x;
678 crop_info.y = bmp_draw->crop.y;
679 crop_info.width = bmp_draw->crop.w;
680 crop_info.height = bmp_draw->crop.h;
682 crop_image = CropImage( image, &crop_info, exception );
685 image=DestroyImageList(image);
687 bmp_draw->bmp.data = (void*)image;
691 QueryColorCompliance( "white", AllCompliance, &white, exception );
693 if ( ddata->image_info->texture ||
694 !(IsPixelInfoEquivalent(&ddata->image_info->background_color,&white)) ||
695 ddata->image_info->background_color.alpha != OpaqueAlpha )
698 Set image white background to transparent so that it may be
699 overlaid over non-white backgrounds.
701 QueryColorCompliance( "white", AllCompliance, &white, exception );
702 TransparentPaintImage( image, &white, QuantumRange, MagickFalse, exception );
705 width = fabs(bmp_draw->pixel_width * (double) bmp_draw->crop.w);
706 height = fabs(bmp_draw->pixel_height * (double) bmp_draw->crop.h);
707 magick_wand=NewMagickWandFromImage(image);
708 (void) DrawComposite(WmfDrawingWand, CopyCompositeOp,
709 XC(bmp_draw->pt.x) * ddata->scale_x, YC(bmp_draw->pt.y) * ddata->scale_y,
710 width * ddata->scale_x, height * ddata->scale_y, magick_wand);
711 magick_wand=DestroyMagickWand(magick_wand);
714 printf("bmp_draw->bmp.data = 0x%lx\n", (long)bmp_draw->bmp.data);
715 printf("registry id = %li\n", id);
716 /* printf("pixel_width = %g\n", bmp_draw->pixel_width); */
717 /* printf("pixel_height = %g\n", bmp_draw->pixel_height); */
718 printf("bmp_draw->bmp WxH = %ix%i\n", bmp_draw->bmp.width, bmp_draw->bmp.height);
719 printf("bmp_draw->crop WxH = %ix%i\n", bmp_draw->crop.w, bmp_draw->crop.h);
720 printf("bmp_draw->crop x,y = %i,%i\n", bmp_draw->crop.x, bmp_draw->crop.y);
721 printf("image size WxH = %lux%lu\n", image->columns, image->rows);
725 static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read) {
727 *ddata = WMF_MAGICK_GetData(API);
738 bmp_read->bmp.data = 0;
740 image_info=CloneImageInfo(ddata->image_info);
741 exception=ddata->exception;
742 (void) CopyMagickString(image_info->magick,"DIB",MaxTextExtent);
743 if (bmp_read->width || bmp_read->height)
748 (void) FormatLocaleString(size,MaxTextExtent,"%ux%u",bmp_read->width,
750 CloneString(&image_info->size,size);
753 printf("ipa_bmp_read: buffer=0x%lx length=%ld, width=%i, height=%i\n",
754 (long) bmp_read->buffer, bmp_read->length,
755 bmp_read->width, bmp_read->height);
757 image=BlobToImage(image_info, (const void *) bmp_read->buffer,
758 bmp_read->length, exception);
759 image_info=DestroyImageInfo(image_info);
760 if (image != (Image *) NULL)
763 printf("ipa_bmp_read: rows=%ld,columns=%ld\n\n", image->rows, image->columns);
766 bmp_read->bmp.data = (void*)image;
767 bmp_read->bmp.width = (U16)image->columns;
768 bmp_read->bmp.height = (U16)image->rows;
772 static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp)
775 DestroyImageList((Image*)bmp->data);
776 bmp->data = (void*) 0;
777 bmp->width = (U16) 0;
778 bmp->height = (U16) 0;
782 This called by wmf_play() the *first* time the meta file is played
784 static void ipa_device_open(wmfAPI * API)
787 *ddata = WMF_MAGICK_GetData (API);
789 ddata->pattern_id = 0;
790 ddata->clipping = MagickFalse;
791 ddata->clip_mask_id = 0;
793 ddata->push_depth = 0;
795 ddata->draw_wand = DrawAllocateWand(ddata->draw_info,ddata->image);
799 This called by wmf_api_destroy()
801 static void ipa_device_close(wmfAPI * API)
804 *ddata = WMF_MAGICK_GetData(API);
806 DestroyDrawingWand(ddata->draw_wand);
807 DestroyDrawInfo(ddata->draw_info);
808 RelinquishMagickMemory(WMF_MAGICK_GetFontData(API)->ps_name);
812 This called from the beginning of each play for initial page setup
814 static void ipa_device_begin(wmfAPI * API)
817 comment[MaxTextExtent];
820 *ddata = WMF_MAGICK_GetData(API);
822 /* Make SVG output happy */
823 (void) PushDrawingWand(WmfDrawingWand);
825 DrawSetViewbox(WmfDrawingWand, 0, 0, ddata->image->columns, ddata->image->rows );
827 (void) FormatLocaleString(comment,MaxTextExtent,"Created by ImageMagick %s",
828 GetMagickVersion((size_t *) NULL));
829 DrawComment(WmfDrawingWand,comment);
831 /* Scale width and height to image */
832 DrawScale(WmfDrawingWand, ddata->scale_x, ddata->scale_y);
834 /* Translate to TL corner of bounding box */
835 DrawTranslate(WmfDrawingWand, ddata->translate_x, ddata->translate_y);
838 DrawRotate(WmfDrawingWand, ddata->rotate);
840 if (ddata->image_info->texture == NULL)
845 /* Draw rectangle in background color */
846 background_color=NewPixelWand();
847 PixelSetPixelColor(background_color,&ddata->image->background_color);
848 DrawSetFillColor(WmfDrawingWand,background_color);
849 background_color=DestroyPixelWand(background_color);
850 DrawRectangle(WmfDrawingWand,
851 XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
852 XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
856 /* Draw rectangle with texture image the SVG way */
866 GetExceptionInfo(&exception);
868 image_info = CloneImageInfo((ImageInfo *) 0);
869 (void) CopyMagickString(image_info->filename,ddata->image_info->texture,
871 if ( ddata->image_info->size )
872 CloneString(&image_info->size,ddata->image_info->size);
874 image = ReadImage(image_info,&exception);
875 image_info=DestroyImageInfo(image_info);
884 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
885 DrawPushDefs(WmfDrawingWand);
886 draw_pattern_push(API,ddata->pattern_id,image->columns,image->rows);
887 magick_wand=NewMagickWandFromImage(image);
888 (void) DrawComposite(WmfDrawingWand,CopyCompositeOp,0,0,
889 image->columns,image->rows,magick_wand);
890 magick_wand=DestroyMagickWand(magick_wand);
891 (void) DrawPopPattern(WmfDrawingWand);
892 DrawPopDefs(WmfDrawingWand);
893 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
895 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
897 DrawRectangle(WmfDrawingWand,
898 XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
899 XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
900 image=DestroyImageList(image);
904 LogMagickEvent(CoderEvent,GetMagickModule(),
905 "reading texture image failed!");
909 DrawSetClipRule(WmfDrawingWand,EvenOddRule); /* Default for WMF is ALTERNATE polygon fill mode */
910 draw_fill_color_string(WmfDrawingWand,"none"); /* Default brush is WHITE_BRUSH */
911 draw_stroke_color_string(WmfDrawingWand,"none"); /* Default pen is BLACK_PEN */
912 DrawSetStrokeLineCap(WmfDrawingWand,ButtCap); /* Default linecap is PS_ENDCAP_FLAT */
913 DrawSetStrokeLineJoin(WmfDrawingWand,MiterJoin); /* Default linejoin is PS_JOIN_MITER */
914 draw_under_color_string(WmfDrawingWand,"white"); /* Default text box is white */
918 This called from the end of each play for page termination
920 static void ipa_device_end(wmfAPI * API)
923 *ddata = WMF_MAGICK_GetData(API);
925 /* Reset any existing clip paths by popping wand */
927 (void) PopDrawingWand(WmfDrawingWand);
928 ddata->clipping = MagickFalse;
930 /* Make SVG output happy */
931 (void) PopDrawingWand(WmfDrawingWand);
934 static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood)
936 /* Save graphic wand */
937 (void) PushDrawingWand(WmfDrawingWand);
939 draw_fill_color_rgb(API,&(flood->color));
941 DrawColor(WmfDrawingWand,XC(flood->pt.x), YC(flood->pt.y),
944 /* Restore graphic wand */
945 (void) PopDrawingWand(WmfDrawingWand);
948 static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood)
950 /* Save graphic wand */
951 (void) PushDrawingWand(WmfDrawingWand);
953 draw_fill_color_rgb(API,&(flood->color));
955 if (flood->type == FLOODFILLSURFACE)
956 DrawColor(WmfDrawingWand, XC(flood->pt.x), YC(flood->pt.y),
959 DrawColor(WmfDrawingWand, XC(flood->pt.x), YC(flood->pt.y),
962 /* Restore graphic wand */
963 (void) PopDrawingWand(WmfDrawingWand);
966 static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel)
968 /* Save graphic wand */
969 (void) PushDrawingWand(WmfDrawingWand);
971 draw_stroke_color_string(WmfDrawingWand,"none");
973 draw_fill_color_rgb(API,&(draw_pixel->color));
975 DrawRectangle(WmfDrawingWand,
976 XC(draw_pixel->pt.x),
977 YC(draw_pixel->pt.y),
978 XC(draw_pixel->pt.x + draw_pixel->pixel_width),
979 YC(draw_pixel->pt.y + draw_pixel->pixel_height));
981 /* Restore graphic wand */
982 (void) PopDrawingWand(WmfDrawingWand);
985 static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc)
987 util_draw_arc(API, draw_arc, magick_arc_pie);
990 static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc)
992 util_draw_arc(API, draw_arc, magick_arc_chord);
995 static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc)
997 util_draw_arc(API, draw_arc, magick_arc_open);
1000 static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc)
1002 util_draw_arc(API, draw_arc, magick_arc_ellipse);
1005 static void util_draw_arc(wmfAPI * API,
1006 wmfDrawArc_t * draw_arc, magick_arc_t finish)
1024 /* Save graphic wand */
1025 (void) PushDrawingWand(WmfDrawingWand);
1027 if (TO_FILL(draw_arc) || TO_DRAW(draw_arc))
1029 center.x = (draw_arc->TL.x + draw_arc->BR.x) / 2;
1030 center.y = (draw_arc->TL.y + draw_arc->BR.y) / 2;
1034 if (finish != magick_arc_ellipse)
1036 draw_arc->start.x += center.x;
1037 draw_arc->start.y += center.y;
1039 draw_arc->end.x += center.x;
1040 draw_arc->end.y += center.y;
1048 if (finish != magick_arc_ellipse)
1050 start = draw_arc->start;
1051 end = draw_arc->end;
1054 Rx = (BR.x - TL.x) / 2;
1055 Ry = (BR.y - TL.y) / 2;
1057 if (finish != magick_arc_ellipse)
1065 phi_s = atan2((double) start.y, (double) start.x) * 180 / MagickPI;
1066 phi_e = atan2((double) end.y, (double) end.x) * 180 / MagickPI;
1072 util_set_pen(API, draw_arc->dc);
1073 if (finish == magick_arc_open)
1074 draw_fill_color_string(WmfDrawingWand,"none");
1076 util_set_brush(API, draw_arc->dc, BrushApplyFill);
1078 if (finish == magick_arc_ellipse)
1079 DrawEllipse(WmfDrawingWand, XC(O.x), YC(O.y), Rx, Ry, 0, 360);
1080 else if (finish == magick_arc_pie)
1082 DrawPathStart(WmfDrawingWand);
1083 DrawPathMoveToAbsolute(WmfDrawingWand, XC(O.x+start.x),
1085 DrawPathEllipticArcAbsolute(WmfDrawingWand, Rx, Ry, 0, MagickFalse,
1086 MagickTrue, XC(O.x+end.x), YC(O.y+end.y));
1087 DrawPathLineToAbsolute(WmfDrawingWand, XC(O.x), YC(O.y));
1088 DrawPathClose(WmfDrawingWand);
1089 DrawPathFinish(WmfDrawingWand);
1091 else if (finish == magick_arc_chord)
1093 DrawArc(WmfDrawingWand, XC(draw_arc->TL.x), YC(draw_arc->TL.y),
1094 XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
1095 DrawLine(WmfDrawingWand, XC(draw_arc->BR.x-start.x),
1096 YC(draw_arc->BR.y-start.y), XC(draw_arc->BR.x-end.x),
1097 YC(draw_arc->BR.y-end.y));
1099 else /* if (finish == magick_arc_open) */
1100 DrawArc(WmfDrawingWand, XC(draw_arc->TL.x), YC(draw_arc->TL.y),
1101 XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
1104 /* Restore graphic wand */
1105 (void) PopDrawingWand(WmfDrawingWand);
1108 static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line)
1110 /* Save graphic wand */
1111 (void) PushDrawingWand(WmfDrawingWand);
1113 if (TO_DRAW(draw_line))
1115 util_set_pen(API, draw_line->dc);
1116 DrawLine(WmfDrawingWand,
1117 XC(draw_line->from.x), YC(draw_line->from.y),
1118 XC(draw_line->to.x), YC(draw_line->to.y));
1121 /* Restore graphic wand */
1122 (void) PopDrawingWand(WmfDrawingWand);
1125 static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * polyline)
1127 if (polyline->count <= 2)
1130 if (TO_DRAW(polyline))
1135 /* Save graphic wand */
1136 (void) PushDrawingWand(WmfDrawingWand);
1138 util_set_pen(API, polyline->dc);
1140 DrawPathStart(WmfDrawingWand);
1141 DrawPathMoveToAbsolute(WmfDrawingWand,
1142 XC(polyline->pt[0].x),
1143 YC(polyline->pt[0].y));
1144 for (point = 1; point < polyline->count; point++)
1146 DrawPathLineToAbsolute(WmfDrawingWand,
1147 XC(polyline->pt[point].x),
1148 YC(polyline->pt[point].y));
1150 DrawPathFinish(WmfDrawingWand);
1152 /* Restore graphic wand */
1153 (void) PopDrawingWand(WmfDrawingWand);
1157 static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * polyline)
1159 if (polyline->count <= 2)
1162 if (TO_FILL(polyline) || TO_DRAW(polyline))
1167 /* Save graphic wand */
1168 (void) PushDrawingWand(WmfDrawingWand);
1170 util_set_pen(API, polyline->dc);
1171 util_set_brush(API, polyline->dc, BrushApplyFill);
1173 DrawPathStart(WmfDrawingWand);
1174 DrawPathMoveToAbsolute(WmfDrawingWand,
1175 XC(polyline->pt[0].x),
1176 YC(polyline->pt[0].y));
1177 for (point = 1; point < polyline->count; point++)
1179 DrawPathLineToAbsolute(WmfDrawingWand,
1180 XC(polyline->pt[point].x),
1181 YC(polyline->pt[point].y));
1183 DrawPathClose(WmfDrawingWand);
1184 DrawPathFinish(WmfDrawingWand);
1186 /* Restore graphic wand */
1187 (void) PopDrawingWand(WmfDrawingWand);
1191 /* Draw a polypolygon. A polypolygon is a list of polygons */
1192 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1193 static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon)
1195 if (TO_FILL(polypolygon) || TO_DRAW(polypolygon))
1204 /* Save graphic wand */
1205 (void) PushDrawingWand(WmfDrawingWand);
1207 util_set_pen(API, polypolygon->dc);
1208 util_set_brush(API, polypolygon->dc, BrushApplyFill);
1210 DrawPathStart(WmfDrawingWand);
1211 for (polygon = 0; polygon < polypolygon->npoly; polygon++)
1213 polyline.dc = polypolygon->dc;
1214 polyline.pt = polypolygon->pt[polygon];
1215 polyline.count = polypolygon->count[polygon];
1216 if ((polyline.count > 2) && polyline.pt)
1218 DrawPathMoveToAbsolute(WmfDrawingWand,
1219 XC(polyline.pt[0].x),
1220 YC(polyline.pt[0].y));
1221 for (point = 1; point < polyline.count; point++)
1223 DrawPathLineToAbsolute(WmfDrawingWand,
1224 XC(polyline.pt[point].x),
1225 YC(polyline.pt[point].y));
1227 DrawPathClose(WmfDrawingWand);
1230 DrawPathFinish(WmfDrawingWand);
1232 /* Restore graphic wand */
1233 (void) PopDrawingWand(WmfDrawingWand);
1238 static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect)
1240 /* Save graphic wand */
1241 (void) PushDrawingWand(WmfDrawingWand);
1243 if (TO_FILL(draw_rect) || TO_DRAW(draw_rect))
1245 util_set_pen(API, draw_rect->dc);
1246 util_set_brush(API, draw_rect->dc, BrushApplyFill);
1248 if ((draw_rect->width > 0) || (draw_rect->height > 0))
1249 DrawRoundRectangle(WmfDrawingWand,
1250 XC(draw_rect->TL.x), YC(draw_rect->TL.y),
1251 XC(draw_rect->BR.x), YC(draw_rect->BR.y),
1252 draw_rect->width / 2, draw_rect->height / 2);
1254 DrawRectangle(WmfDrawingWand,
1255 XC(draw_rect->TL.x), YC(draw_rect->TL.y),
1256 XC(draw_rect->BR.x), YC(draw_rect->BR.y));
1259 /* Restore graphic wand */
1260 (void) PopDrawingWand(WmfDrawingWand);
1263 /* Draw an un-filled rectangle using the current brush */
1264 static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
1266 /* Save graphic wand */
1267 (void) PushDrawingWand(WmfDrawingWand);
1269 if (TO_FILL(poly_rect) || TO_DRAW(poly_rect))
1274 draw_fill_color_string(WmfDrawingWand,"none");
1275 util_set_brush(API, poly_rect->dc, BrushApplyStroke);
1277 for (i = 0; i < (long) poly_rect->count; i++)
1279 DrawRectangle(WmfDrawingWand,
1280 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1281 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1285 /* Restore graphic wand */
1286 (void) PopDrawingWand(WmfDrawingWand);
1289 static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
1292 if (poly_rect->count == 0)
1295 /* Save graphic wand */
1296 (void) PushDrawingWand(WmfDrawingWand);
1298 if (TO_FILL (poly_rect))
1303 draw_stroke_color_string(WmfDrawingWand,"none");
1304 util_set_brush(API, poly_rect->dc, BrushApplyFill);
1306 for (i = 0; i < (long) poly_rect->count; i++)
1308 DrawRectangle(WmfDrawingWand,
1309 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1310 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1314 /* Restore graphic wand */
1315 (void) PopDrawingWand(WmfDrawingWand);
1318 static void ipa_region_clip(wmfAPI *API, wmfPolyRectangle_t *poly_rect)
1324 *ddata = WMF_MAGICK_GetData (API);
1326 /* Reset any existing clip paths by popping wand */
1327 if (ddata->clipping)
1328 (void) PopDrawingWand(WmfDrawingWand);
1329 ddata->clipping = MagickFalse;
1331 if (poly_rect->count > 0)
1336 /* Define clip path */
1337 ddata->clip_mask_id++;
1338 DrawPushDefs(WmfDrawingWand);
1339 (void) FormatLocaleString(clip_mask_id,MaxTextExtent,"clip_%lu",
1340 ddata->clip_mask_id);
1341 DrawPushClipPath(WmfDrawingWand,clip_mask_id);
1342 (void) PushDrawingWand(WmfDrawingWand);
1343 for (i = 0; i < (long) poly_rect->count; i++)
1345 DrawRectangle(WmfDrawingWand,
1346 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1347 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1349 (void) PopDrawingWand(WmfDrawingWand);
1350 DrawPopClipPath(WmfDrawingWand);
1351 DrawPopDefs(WmfDrawingWand);
1353 /* Push wand for new clip paths */
1354 (void) PushDrawingWand(WmfDrawingWand);
1355 (void) DrawSetClipPath(WmfDrawingWand,clip_mask_id);
1356 ddata->clipping = MagickTrue;
1360 static void ipa_functions(wmfAPI *API)
1365 wmfFunctionReference
1366 *FR = (wmfFunctionReference *) API->function_reference;
1369 IPA function reference links
1371 FR->device_open = ipa_device_open;
1372 FR->device_close = ipa_device_close;
1373 FR->device_begin = ipa_device_begin;
1374 FR->device_end = ipa_device_end;
1375 FR->flood_interior = ipa_flood_interior;
1376 FR->flood_exterior = ipa_flood_exterior;
1377 FR->draw_pixel = ipa_draw_pixel;
1378 FR->draw_pie = ipa_draw_pie;
1379 FR->draw_chord = ipa_draw_chord;
1380 FR->draw_arc = ipa_draw_arc;
1381 FR->draw_ellipse = ipa_draw_ellipse;
1382 FR->draw_line = ipa_draw_line;
1383 FR->poly_line = ipa_poly_line;
1384 FR->draw_polygon = ipa_draw_polygon;
1385 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1386 FR->draw_polypolygon = ipa_draw_polypolygon;
1388 FR->draw_rectangle = ipa_draw_rectangle;
1389 FR->rop_draw = ipa_rop_draw;
1390 FR->bmp_draw = ipa_bmp_draw;
1391 FR->bmp_read = ipa_bmp_read;
1392 FR->bmp_free = ipa_bmp_free;
1393 FR->draw_text = ipa_draw_text;
1394 FR->udata_init = ipa_udata_init;
1395 FR->udata_copy = ipa_udata_copy;
1396 FR->udata_set = ipa_udata_set;
1397 FR->udata_free = ipa_udata_free;
1398 FR->region_frame = ipa_region_frame;
1399 FR->region_paint = ipa_region_paint;
1400 FR->region_clip = ipa_region_clip;
1403 Allocate device data structure
1405 ddata = (wmf_magick_t *) wmf_malloc(API, sizeof(wmf_magick_t));
1409 (void) ResetMagickMemory((void *) ddata, 0, sizeof(wmf_magick_t));
1410 API->device_data = (void *) ddata;
1413 Device data defaults
1418 static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text)
1421 angle = 0, /* text rotation angle */
1422 bbox_height, /* bounding box height */
1423 bbox_width, /* bounding box width */
1424 pointsize = 0; /* pointsize to output font with desired height */
1433 BL, /* bottom left of bounding box */
1434 BR, /* bottom right of bounding box */
1435 TL, /* top left of bounding box */
1436 TR; /* top right of bounding box */
1439 point; /* text placement point */
1445 * ddata = WMF_MAGICK_GetData(API);
1447 point = draw_text->pt;
1449 /* Choose bounding box and calculate its width and height */
1454 if ( draw_text->flags)
1458 TR.x = draw_text->BR.x;
1459 TR.y = draw_text->TL.y;
1460 BL.x = draw_text->TL.x;
1461 BL.y = draw_text->BR.y;
1465 TL = draw_text->bbox.TL;
1466 BR = draw_text->bbox.BR;
1467 TR = draw_text->bbox.TR;
1468 BL = draw_text->bbox.BL;
1470 dx = ((TR.x - TL.x) + (BR.x - BL.x)) / 2;
1471 dy = ((TR.y - TL.y) + (BR.y - BL.y)) / 2;
1472 bbox_width = hypot(dx,dy);
1473 dx = ((BL.x - TL.x) + (BR.x - TR.x)) / 2;
1474 dy = ((BL.y - TL.y) + (BR.y - TR.y)) / 2;
1475 bbox_height = hypot(dx,dy);
1478 font = WMF_DC_FONT(draw_text->dc);
1480 /* Convert font_height to equivalent pointsize */
1481 exception=ddata->exception;
1482 pointsize = util_pointsize( API, font, draw_text->str, draw_text->font_height, exception);
1484 /* Save graphic wand */
1485 (void) PushDrawingWand(WmfDrawingWand);
1490 printf("\nipa_draw_text\n");
1491 printf("Text = \"%s\"\n", draw_text->str);
1492 /* printf("WMF_FONT_NAME: = \"%s\"\n", WMF_FONT_NAME(font)); */
1493 printf("WMF_FONT_PSNAME: = \"%s\"\n", WMF_FONT_PSNAME(font));
1494 printf("Bounding box TL=%g,%g BR=%g,%g\n",
1495 TL.x, TL.y, BR.x, BR.y );
1496 /* printf("Text box = %gx%g\n", bbox_width, bbox_height); */
1497 /* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
1498 printf("Pointsize = %g\n", pointsize);
1503 * Obtain font metrics if required
1506 if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER) ||
1507 (WMF_TEXT_UNDERLINE(font)) || (WMF_TEXT_STRIKEOUT(font)))
1510 *image = ddata->image;
1515 draw_info=ddata->draw_info;
1516 draw_info->font=WMF_FONT_PSNAME(font);
1517 draw_info->pointsize = pointsize;
1518 draw_info->text=draw_text->str;
1520 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
1522 /* Center the text if it is not yet centered and should be */
1523 if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER))
1526 text_width = metrics.width * (ddata->scale_y / ddata->scale_x);
1528 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1529 point.x -= text_width / 2;
1531 point.x += bbox_width / 2 - text_width / 2;
1535 draw_info->font=NULL;
1536 draw_info->text=NULL;
1539 /* Set text background color */
1540 if (draw_text->flags & ETO_OPAQUE)
1542 /* Draw bounding-box background color (META_EXTTEXTOUT mode) */
1543 draw_stroke_color_string(WmfDrawingWand,"none");
1544 draw_fill_color_rgb(API,WMF_DC_BACKGROUND(draw_text->dc));
1545 DrawRectangle(WmfDrawingWand,
1546 XC(draw_text->TL.x),YC(draw_text->TL.y),
1547 XC(draw_text->BR.x),YC(draw_text->BR.y));
1548 draw_fill_color_string(WmfDrawingWand,"none");
1552 /* Set text undercolor */
1553 if (WMF_DC_OPAQUE(draw_text->dc))
1556 *box = WMF_DC_BACKGROUND(draw_text->dc);
1561 under_color=NewPixelWand();
1562 PixelSetRedQuantum(under_color,ScaleCharToQuantum(box->r));
1563 PixelSetGreenQuantum(under_color,ScaleCharToQuantum(box->g));
1564 PixelSetBlueQuantum(under_color,ScaleCharToQuantum(box->b));
1565 PixelSetAlphaQuantum(under_color,OpaqueAlpha);
1566 DrawSetTextUnderColor(WmfDrawingWand,under_color);
1567 under_color=DestroyPixelWand(under_color);
1570 draw_under_color_string(WmfDrawingWand,"none");
1573 /* Set text clipping (META_EXTTEXTOUT mode) */
1574 if ( draw_text->flags & ETO_CLIPPED)
1578 /* Set stroke color */
1579 draw_stroke_color_string(WmfDrawingWand,"none");
1581 /* Set fill color */
1582 draw_fill_color_rgb(API,WMF_DC_TEXTCOLOR(draw_text->dc));
1584 /* Output font size */
1585 (void) DrawSetFontSize(WmfDrawingWand,pointsize);
1587 /* Output Postscript font name */
1588 (void) DrawSetFont(WmfDrawingWand, WMF_FONT_PSNAME(font));
1590 /* Translate coordinates so target is 0,0 */
1591 DrawTranslate(WmfDrawingWand, XC(point.x), YC(point.y));
1593 /* Transform horizontal scale to draw text at 1:1 ratio */
1594 DrawScale(WmfDrawingWand, ddata->scale_y / ddata->scale_x, 1.0);
1596 /* Apply rotation */
1597 /* ImageMagick's drawing rotation is clockwise from horizontal
1598 while WMF drawing rotation is counterclockwise from horizontal */
1599 angle = fabs(RadiansToDegrees(2 * MagickPI - WMF_TEXT_ANGLE(font)));
1603 DrawRotate(WmfDrawingWand, angle);
1611 DrawAnnotation(WmfDrawingWand, 0, 0, (unsigned char*)draw_text->str);
1613 /* Underline text the Windows way (at the bottom) */
1614 if (WMF_TEXT_UNDERLINE(font))
1620 ulBR, /* bottom right of underline rectangle */
1621 ulTL; /* top left of underline rectangle */
1623 line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
1624 if (metrics.underline_thickness < 1.5)
1625 line_height *= 0.55;
1627 ulTL.y = fabs(metrics.descent) - line_height;
1628 ulBR.x = metrics.width;
1629 ulBR.y = fabs(metrics.descent);
1631 DrawRectangle(WmfDrawingWand,
1632 XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
1635 /* Strikeout text the Windows way */
1636 if (WMF_TEXT_STRIKEOUT(font))
1641 ulBR, /* bottom right of strikeout rectangle */
1642 ulTL; /* top left of strikeout rectangle */
1644 line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
1646 if (metrics.underline_thickness < 2.0)
1647 line_height *= 0.55;
1649 ulTL.y = -(((double) metrics.ascent) / 2 + line_height / 2);
1650 ulBR.x = metrics.width;
1651 ulBR.y = -(((double) metrics.ascent) / 2 - line_height / 2);
1653 DrawRectangle(WmfDrawingWand,
1654 XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
1658 /* Restore graphic wand */
1659 (void) PopDrawingWand(WmfDrawingWand);
1662 (void) PushDrawingWand(WmfDrawingWand);
1663 draw_stroke_color_string(WmfDrawingWand,"red");
1664 draw_fill_color_string(WmfDrawingWand,"none");
1665 DrawRectangle(WmfDrawingWand,
1667 XC(BR.x), YC(BR.y));
1668 draw_stroke_color_string(WmfDrawingWand,"none");
1669 (void) PopDrawingWand(WmfDrawingWand);
1674 static void ipa_udata_init(wmfAPI * API, wmfUserData_t * userdata)
1678 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1682 static void ipa_udata_copy(wmfAPI * API, wmfUserData_t * userdata)
1686 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1690 static void ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata)
1694 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1698 static void ipa_udata_free(wmfAPI * API, wmfUserData_t * userdata)
1702 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1706 static inline double MagickMin(const double x,const double y)
1713 static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply)
1716 *ddata = WMF_MAGICK_GetData(API);
1719 *brush = WMF_DC_BRUSH(dc);
1721 /* Set polygon fill rule */
1722 switch (WMF_DC_POLYFILL(dc)) /* Is this correct ?? */
1725 DrawSetClipRule(WmfDrawingWand,NonZeroRule);
1730 DrawSetClipRule(WmfDrawingWand,EvenOddRule);
1734 switch (WMF_BRUSH_STYLE(brush))
1736 case BS_SOLID /* 0 */:
1737 /* WMF_BRUSH_COLOR specifies brush color, WMF_BRUSH_HATCH
1740 if ( brush_apply == BrushApplyStroke )
1741 draw_stroke_color_rgb(API,WMF_BRUSH_COLOR(brush));
1743 draw_fill_color_rgb(API,WMF_BRUSH_COLOR(brush));
1746 case BS_HOLLOW /* 1 */: /* BS_HOLLOW & BS_NULL share enum */
1747 /* WMF_BRUSH_COLOR and WMF_BRUSH_HATCH ignored */
1749 if ( brush_apply == BrushApplyStroke )
1750 draw_stroke_color_string(WmfDrawingWand,"none");
1752 draw_fill_color_string(WmfDrawingWand,"none");
1755 case BS_HATCHED /* 2 */:
1756 /* WMF_BRUSH_COLOR specifies the hatch color, WMF_BRUSH_HATCH
1757 specifies the hatch brush style. If WMF_DC_OPAQUE, then
1758 WMF_DC_BACKGROUND specifies hatch background color. */
1760 DrawPushDefs(WmfDrawingWand);
1761 draw_pattern_push(API, ddata->pattern_id, 8, 8);
1762 (void) PushDrawingWand(WmfDrawingWand);
1764 if (WMF_DC_OPAQUE(dc))
1766 if ( brush_apply == BrushApplyStroke )
1767 draw_stroke_color_rgb(API,WMF_DC_BACKGROUND(dc));
1769 draw_fill_color_rgb(API,WMF_DC_BACKGROUND(dc));
1771 DrawRectangle(WmfDrawingWand, 0, 0, 7, 7 );
1774 DrawSetStrokeAntialias(WmfDrawingWand, MagickFalse);
1775 DrawSetStrokeWidth(WmfDrawingWand, 1);
1777 draw_stroke_color_rgb(API,WMF_BRUSH_COLOR(brush));
1779 switch ((unsigned int) WMF_BRUSH_HATCH(brush))
1782 case HS_HORIZONTAL: /* ----- */
1784 DrawLine(WmfDrawingWand, 0, 3, 7,3);
1787 case HS_VERTICAL: /* ||||| */
1789 DrawLine(WmfDrawingWand, 3, 0, 3, 7);
1792 case HS_FDIAGONAL: /* \\\\\ */
1794 DrawLine(WmfDrawingWand, 0, 0, 7, 7);
1797 case HS_BDIAGONAL: /* / */
1799 DrawLine(WmfDrawingWand, 0, 7, 7, 0 );
1802 case HS_CROSS: /* +++++ */
1804 DrawLine(WmfDrawingWand, 0, 3, 7, 3 );
1805 DrawLine(WmfDrawingWand, 3, 0, 3, 7 );
1808 case HS_DIAGCROSS: /* xxxxx */
1810 DrawLine(WmfDrawingWand, 0, 0, 7, 7 );
1811 DrawLine(WmfDrawingWand, 0, 7, 7, 0 );
1816 printf("util_set_brush: unexpected brush hatch enumeration %u\n",
1817 (unsigned int)WMF_BRUSH_HATCH(brush));
1820 (void) PopDrawingWand(WmfDrawingWand);
1821 (void) DrawPopPattern(WmfDrawingWand);
1822 DrawPopDefs(WmfDrawingWand);
1827 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
1829 if (brush_apply == BrushApplyStroke )
1830 (void) DrawSetStrokePatternURL(WmfDrawingWand,pattern_id);
1832 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
1833 ++ddata->pattern_id;
1837 case BS_PATTERN /* 3 */:
1838 /* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides handle to
1841 printf("util_set_brush: BS_PATTERN not supported\n");
1844 case BS_INDEXED /* 4 */:
1846 printf("util_set_brush: BS_INDEXED not supported\n");
1849 case BS_DIBPATTERN /* 5 */:
1852 *brush_bmp = WMF_BRUSH_BITMAP(brush);
1854 if (brush_bmp && brush_bmp->data != 0)
1868 GetExceptionInfo(&exception);
1870 image = (Image*)brush_bmp->data;
1872 mode = CopyCompositeOp; /* Default is copy */
1873 switch (WMF_DC_ROP(dc))
1875 /* Binary raster ops */
1877 printf("util_set_brush: R2_BLACK ROP2 mode not supported!\n");
1879 case R2_NOTMERGEPEN:
1880 printf("util_set_brush: R2_NOTMERGEPEN ROP2 mode not supported!\n");
1883 printf("util_set_brush R2_MASKNOTPEN ROP2 mode not supported!\n");
1886 printf("util_set_brush: R2_NOTCOPYPEN ROP2 mode not supported!\n");
1889 printf("util_set_brush: R2_MASKPENNOT ROP2 mode not supported!\n");
1892 printf("util_set_brush: R2_NOT ROP2 mode not supported!\n");
1895 printf("util_set_brush: R2_XORPEN ROP2 mode not supported!\n");
1898 printf("util_set_brush: R2_NOTMASKPEN ROP2 mode not supported!\n");
1901 printf("util_set_brush: R2_MASKPEN ROP2 mode not supported!\n");
1904 printf("util_set_brush: R2_NOTXORPEN ROP2 mode not supported!\n");
1907 printf("util_set_brush: R2_NOP ROP2 mode not supported!\n");
1909 case R2_MERGENOTPEN:
1910 printf("util_set_brush: R2_MERGENOTPEN ROP2 mode not supported!\n");
1913 mode = CopyCompositeOp;
1915 case R2_MERGEPENNOT:
1916 printf("util_set_brush: R2_MERGEPENNOT ROP2 mode not supported!\n");
1919 printf("util_set_brush: R2_MERGEPEN ROP2 mode not supported!\n");
1922 printf("util_set_brush: R2_WHITE ROP2 mode not supported!\n");
1926 printf("util_set_brush: unexpected ROP2 enumeration %u!\n",
1927 (unsigned int)WMF_DC_ROP(dc));
1931 DrawPushDefs(WmfDrawingWand);
1932 draw_pattern_push(API, ddata->pattern_id, brush_bmp->width,
1934 magick_wand=NewMagickWandFromImage(image);
1935 (void) DrawComposite(WmfDrawingWand,mode, 0, 0, brush_bmp->width,
1936 brush_bmp->height, magick_wand);
1937 magick_wand=DestroyMagickWand(magick_wand);
1938 (void) DrawPopPattern(WmfDrawingWand);
1939 DrawPopDefs(WmfDrawingWand);
1945 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
1947 if ( brush_apply == BrushApplyStroke )
1948 (void) DrawSetStrokePatternURL(WmfDrawingWand,pattern_id);
1950 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
1951 ++ddata->pattern_id;
1955 printf("util_set_brush: no BMP image data!\n");
1959 case BS_DIBPATTERNPT /* 6 */:
1960 /* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides pointer to
1963 printf("util_set_brush: BS_DIBPATTERNPT not supported\n");
1966 case BS_PATTERN8X8 /* 7 */:
1968 printf("util_set_brush: BS_PATTERN8X8 not supported\n");
1971 case BS_DIBPATTERN8X8 /* 8 */:
1973 printf("util_set_brush: BS_DIBPATTERN8X8 not supported\n");
1982 static inline double MagickMax(const double x,const double y)
1989 static void util_set_pen(wmfAPI * API, wmfDC * dc)
1992 *ddata = WMF_MAGICK_GetData(API);
2005 pen = WMF_DC_PEN(dc);
2007 pen_width = (WMF_PEN_WIDTH(pen) + WMF_PEN_HEIGHT(pen)) / 2;
2009 /* Pixel width is inverse of pixel scale */
2010 pixel_width = (((double) 1 / (ddata->scale_x)) +
2011 ((double) 1 / (ddata->scale_y))) / 2;
2013 /* Don't allow pen_width to be much less than pixel_width in order
2014 to avoid dissapearing or spider-web lines */
2015 pen_width = MagickMax(pen_width, pixel_width*0.8);
2017 pen_style = (unsigned int) WMF_PEN_STYLE(pen);
2018 pen_type = (unsigned int) WMF_PEN_TYPE(pen);
2021 /* Pen style specified? */
2022 if (pen_style == PS_NULL)
2024 draw_stroke_color_string(WmfDrawingWand,"none");
2028 DrawSetStrokeAntialias(WmfDrawingWand, MagickTrue );
2029 DrawSetStrokeWidth(WmfDrawingWand, (unsigned long) MagickMax(0.0, pen_width));
2035 switch ((unsigned int) WMF_PEN_ENDCAP(pen))
2037 case PS_ENDCAP_SQUARE:
2038 linecap = SquareCap;
2040 case PS_ENDCAP_ROUND:
2043 case PS_ENDCAP_FLAT:
2048 DrawSetStrokeLineCap(WmfDrawingWand, linecap);
2055 switch ((unsigned int) WMF_PEN_JOIN(pen))
2058 linejoin = BevelJoin;
2061 linejoin = RoundJoin;
2065 linejoin = MiterJoin;
2068 DrawSetStrokeLineJoin(WmfDrawingWand,linejoin);
2077 case PS_DASH: /* ------- */
2080 dasharray[0] = pixel_width * 18;
2081 dasharray[1] = pixel_width * 7;
2084 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2085 (void) DrawSetStrokeDashArray(WmfDrawingWand,2,dasharray);
2089 case PS_DOT: /* ....... */
2092 dasharray[0] = pixel_width * 3;
2093 dasharray[1] = pixel_width * 3;
2096 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2097 (void) DrawSetStrokeDashArray(WmfDrawingWand,2,dasharray);
2100 case PS_DASHDOT: /* _._._._ */
2102 /* Pattern 9,6,3,6 */
2103 dasharray[0] = pixel_width * 9;
2104 dasharray[1] = pixel_width * 6;
2105 dasharray[2] = pixel_width * 3;
2106 dasharray[3] = pixel_width * 6;
2109 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2110 (void) DrawSetStrokeDashArray(WmfDrawingWand,4,dasharray);
2113 case PS_DASHDOTDOT: /* _.._.._ */
2115 /* Pattern 9,3,3,3,3,3 */
2116 dasharray[0] = pixel_width * 9;
2117 dasharray[1] = pixel_width * 3;
2118 dasharray[2] = pixel_width * 3;
2119 dasharray[3] = pixel_width * 3;
2120 dasharray[4] = pixel_width * 3;
2121 dasharray[5] = pixel_width * 3;
2124 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2125 (void) DrawSetStrokeDashArray(WmfDrawingWand,6,dasharray);
2128 case PS_INSIDEFRAME: /* There is nothing to do in this case... */
2132 (void) DrawSetStrokeDashArray(WmfDrawingWand,0,(double *)NULL);
2138 draw_stroke_color_rgb(API,WMF_PEN_COLOR(pen));
2141 /* Estimate font pointsize based on Windows font parameters */
2142 static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height, ExceptionInfo *exception)
2145 *ddata = WMF_MAGICK_GetData(API);
2148 *image = ddata->image;
2159 draw_info=ddata->draw_info;
2160 if (draw_info == (const DrawInfo *) NULL)
2163 draw_info->font=WMF_FONT_PSNAME(font);
2164 draw_info->pointsize=font_height;
2165 draw_info->text=str;
2167 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2170 if (strlen(str) == 1)
2172 pointsize = (font_height *
2173 ( font_height / (metrics.ascent + fabs(metrics.descent))));
2174 draw_info->pointsize = pointsize;
2175 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2176 pointsize *= (font_height / ( metrics.ascent + fabs(metrics.descent)));
2180 pointsize = (font_height * (font_height / (metrics.height)));
2181 draw_info->pointsize = pointsize;
2182 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2183 pointsize *= (font_height / metrics.height);
2187 draw_info.pointsize = pointsize;
2188 if (GetTypeMetrics(image, &draw_info, &metrics, exception) != MagickFalse)
2189 pointsize *= (font_height / (metrics.ascent + fabs(metrics.descent)));
2190 pointsize *= 1.114286; /* Magic number computed through trial and error */
2194 draw_info->font=NULL;
2195 draw_info->text=NULL;
2197 printf("String = %s\n", str);
2198 printf("Font = %s\n", WMF_FONT_PSNAME(font));
2199 printf("lfHeight = %g\n", font_height);
2200 printf("bounds = %g,%g %g,%g\n", metrics.bounds.x1, metrics.bounds.y1,
2201 metrics.bounds.x2,metrics.bounds.y2);
2202 printf("ascent = %g\n", metrics.ascent);
2203 printf("descent = %g\n", metrics.descent);
2204 printf("height = %g\n", metrics.height);
2205 printf("Pointsize = %g\n", pointsize);
2208 return floor(pointsize);
2211 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
2212 /* Estimate weight based on font name */
2214 static int util_font_weight( const char* font )
2220 if ((strstr(font,"Normal") || strstr(font,"Regular")))
2222 else if ( strstr(font,"Bold") )
2225 if ((strstr(font,"Semi") || strstr(font,"Demi")))
2227 if ( (strstr(font,"Extra") || strstr(font,"Ultra")))
2230 else if ( strstr(font,"Light") )
2233 if ( (strstr(font,"Extra") || strstr(font,"Ultra")))
2236 else if ((strstr(font,"Heavy") || strstr(font,"Black")))
2238 else if ( strstr(font,"Thin") )
2245 * Returns width of string in points, assuming (unstretched) font size of 1pt
2246 * (similar to wmf_ipa_font_stringwidth)
2248 * This extremely odd at best, particularly since player/meta.h has access
2249 * to the corrected font_height (as drawtext.font_height) when it invokes the
2250 * stringwidth callback. It should be possible to compute the real stringwidth!
2252 static float lite_font_stringwidth( wmfAPI* API, wmfFont* font, char* str)
2255 *ddata = WMF_MAGICK_GetData(API);
2258 *image = ddata->image;
2277 orig_resolution_units;
2279 orig_x_resolution = image->resolution.x;
2280 orig_y_resolution = image->resolution.y;
2281 orig_resolution_units = image->units;
2283 draw_info=ddata->draw_info;
2284 if (draw_info == (const DrawInfo *) NULL)
2287 draw_info->font=WMF_FONT_PSNAME(font);
2288 draw_info->pointsize=12;
2289 draw_info->text=str;
2291 image->resolution.x = 72;
2292 image->resolution.y = 72;
2293 image->units = PixelsPerInchResolution;
2295 exception=ddata->exception;
2296 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2297 stringwidth = ((metrics.width * 72)/(image->resolution.x * draw_info->pointsize)); /* *0.916348; */
2299 draw_info->font=NULL;
2300 draw_info->text=NULL;
2303 printf("\nlite_font_stringwidth\n");
2304 printf("string = \"%s\"\n", str);
2305 printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
2306 printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
2307 printf("stringwidth = %g\n", stringwidth);
2308 /* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
2309 /* printf("WMF_FONT_WIDTH = %i\n", (int)WMF_FONT_WIDTH(font)); */
2313 image->resolution.x = orig_x_resolution;
2314 image->resolution.y = orig_y_resolution;
2315 image->units = orig_resolution_units;
2320 /* Map font (similar to wmf_ipa_font_map) */
2322 /* Mappings to Postscript fonts: family, normal, italic, bold, bolditalic */
2323 static wmfFontMap WMFFontMap[] = {
2324 { (char *) "Courier", (char *) "Courier",
2325 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2326 (char *) "Courier-BoldOblique" },
2327 { (char *) "Helvetica", (char *) "Helvetica",
2328 (char *) "Helvetica-Oblique", (char *) "Helvetica-Bold",
2329 (char *) "Helvetica-BoldOblique" },
2330 { (char *) "Modern", (char *) "Courier",
2331 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2332 (char *) "Courier-BoldOblique" },
2333 { (char *) "Monotype Corsiva", (char *) "Courier",
2334 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2335 (char *) "Courier-BoldOblique" },
2336 { (char *) "News Gothic", (char *) "Helvetica",
2337 (char *) "Helvetica-Oblique", (char *) "Helvetica-Bold",
2338 (char *) "Helvetica-BoldOblique" },
2339 { (char *) "Symbol", (char *) "Symbol",
2340 (char *) "Symbol", (char *) "Symbol",
2341 (char *) "Symbol" },
2342 { (char *) "System", (char *) "Courier",
2343 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2344 (char *) "Courier-BoldOblique" },
2345 { (char *) "Times", (char *) "Times-Roman",
2346 (char *) "Times-Italic", (char *) "Times-Bold",
2347 (char *) "Times-BoldItalic" },
2348 { (char *) NULL, (char *) NULL,
2349 (char *) NULL, (char *) NULL,
2354 /* Mapping between base name and Ghostscript family name */
2355 static wmfMapping SubFontMap[] =
2357 { (char *) "Arial", (char *) "Helvetica", FT_ENCODING_NONE },
2358 { (char *) "Courier", (char *) "Courier", FT_ENCODING_NONE },
2359 { (char *) "Fixed", (char *) "Courier", FT_ENCODING_NONE },
2360 { (char *) "Helvetica", (char *) "Helvetica", FT_ENCODING_NONE },
2361 { (char *) "Sans", (char *) "Helvetica", FT_ENCODING_NONE },
2362 { (char *) "Sym", (char *) "Symbol", FT_ENCODING_NONE },
2363 { (char *) "Terminal", (char *) "Courier", FT_ENCODING_NONE },
2364 { (char *) "Times", (char *) "Times", FT_ENCODING_NONE },
2365 { (char *) "Wingdings", (char *) "Symbol", FT_ENCODING_NONE },
2366 { (char *) NULL, (char *) NULL, FT_ENCODING_NONE }
2369 static void lite_font_map( wmfAPI* API, wmfFont* font)
2378 *ddata = WMF_MAGICK_GetData(API);
2393 font_data = (wmfFontData*)API->font_data;
2394 font->user_data = font_data->user_data;
2395 magick_font = (wmf_magick_font_t*)font->user_data;
2396 wmf_font_name = WMF_FONT_NAME(font);
2398 if (magick_font->ps_name != (char *) NULL)
2399 magick_font->ps_name=DestroyString(magick_font->ps_name);
2401 exception=ddata->exception;
2402 type_info_base=GetTypeInfo("*",exception);
2403 if (type_info_base == 0)
2406 /* Certain short-hand font names are not the proper Windows names
2407 and should be promoted to the proper names */
2408 if (LocaleCompare(wmf_font_name,"Times") == 0)
2409 wmf_font_name = "Times New Roman";
2410 else if (LocaleCompare(wmf_font_name,"Courier") == 0)
2411 wmf_font_name = "Courier New";
2413 /* Look for a family-based best-match */
2414 if (!magick_font->ps_name)
2419 if (WMF_FONT_WEIGHT(font) == 0)
2420 target_weight = 400;
2422 target_weight = WMF_FONT_WEIGHT(font);
2423 type_info=GetTypeInfoByFamily(wmf_font_name,AnyStyle,AnyStretch,
2424 target_weight,exception);
2425 if (type_info == (const TypeInfo *) NULL)
2426 type_info=GetTypeInfoByFamily(wmf_font_name,AnyStyle,AnyStretch,0,
2428 if (type_info != (const TypeInfo *) NULL)
2429 CloneString(&magick_font->ps_name,type_info->name);
2432 /* Now let's try simple substitution mappings from WMFFontMap */
2433 if (!magick_font->ps_name)
2436 target[MaxTextExtent];
2439 target_weight = 400,
2440 want_italic = MagickFalse,
2441 want_bold = MagickFalse,
2444 if ( WMF_FONT_WEIGHT(font) != 0 )
2445 target_weight = WMF_FONT_WEIGHT(font);
2447 if ( (target_weight > 550) || ((strstr(wmf_font_name,"Bold") ||
2448 strstr(wmf_font_name,"Heavy") ||
2449 strstr(wmf_font_name,"Black"))) )
2450 want_bold = MagickTrue;
2452 if ( (WMF_FONT_ITALIC(font)) || ((strstr(wmf_font_name,"Italic") ||
2453 strstr(wmf_font_name,"Oblique"))) )
2454 want_italic = MagickTrue;
2456 (void) CopyMagickString(target,"Times",MaxTextExtent);
2457 for( i=0; SubFontMap[i].name != NULL; i++ )
2459 if (LocaleCompare(wmf_font_name, SubFontMap[i].name) == 0)
2461 (void) CopyMagickString(target,SubFontMap[i].mapping,
2467 for( i=0; WMFFontMap[i].name != NULL; i++ )
2469 if (LocaleNCompare(WMFFontMap[i].name,target,strlen(WMFFontMap[i].name)) == 0)
2471 if (want_bold && want_italic)
2472 CloneString(&magick_font->ps_name,WMFFontMap[i].bolditalic);
2473 else if (want_italic)
2474 CloneString(&magick_font->ps_name,WMFFontMap[i].italic);
2476 CloneString(&magick_font->ps_name,WMFFontMap[i].bold);
2478 CloneString(&magick_font->ps_name,WMFFontMap[i].normal);
2484 printf("\nlite_font_map\n");
2485 printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
2486 printf("WMF_FONT_WEIGHT = %i\n", WMF_FONT_WEIGHT(font));
2487 printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
2493 /* Initialize API font structures */
2494 static void lite_font_init( wmfAPI* API, wmfAPI_Options* options)
2502 /* Allocate wmfFontData data structure */
2503 API->font_data = wmf_malloc(API,sizeof(wmfFontData));
2507 font_data = (wmfFontData*)API->font_data;
2509 /* Assign function to map font (type wmfMap) */
2510 font_data->map = lite_font_map;
2512 /* Assign function to return string width in points (type wmfStringWidth) */
2513 font_data->stringwidth = lite_font_stringwidth;
2515 /* Assign user data, not used by libwmflite (type void*) */
2516 font_data->user_data = wmf_malloc(API,sizeof(wmf_magick_font_t));
2519 ((wmf_magick_font_t*)font_data->user_data)->ps_name = 0;
2520 ((wmf_magick_font_t*)font_data->user_data)->pointsize = 0;
2523 #endif /* MAGICKCORE_WMFLITE_DELEGATE */
2525 /* BLOB read byte */
2526 static int ipa_blob_read(void* wand)
2528 return ReadBlobByte((Image*)wand);
2532 static int ipa_blob_seek(void* wand,long position)
2534 return (int)SeekBlob((Image*)wand,(MagickOffsetType) position,SEEK_SET);
2538 static long ipa_blob_tell(void* wand)
2540 return (long)TellBlob((Image*)wand);
2543 static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
2564 wmf_options_flags = 0;
2581 image=AcquireImage(image_info,exception);
2582 if (OpenBlob(image_info,image,ReadBinaryBlobMode,exception) == MagickFalse)
2584 if (image->debug != MagickFalse)
2586 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2587 " OpenBlob failed");
2588 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2589 "leave ReadWMFImage()");
2591 image=DestroyImageList(image);
2592 return((Image *) NULL);
2600 /* Register callbacks */
2601 wmf_options_flags |= WMF_OPT_FUNCTION;
2602 (void) ResetMagickMemory(&wmf_api_options, 0, sizeof(wmf_api_options));
2603 wmf_api_options.function = ipa_functions;
2605 /* Ignore non-fatal errors */
2606 wmf_options_flags |= WMF_OPT_IGNORE_NONFATAL;
2608 wmf_error = wmf_api_create(&API, wmf_options_flags, &wmf_api_options);
2609 if (wmf_error != wmf_E_None)
2612 wmf_api_destroy(API);
2613 if (image->debug != MagickFalse)
2615 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2616 " wmf_api_create failed");
2617 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2618 "leave ReadWMFImage()");
2620 ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
2623 /* Register progress monitor */
2624 wmf_status_function(API,image,magick_progress_callback);
2626 ddata=WMF_MAGICK_GetData(API);
2628 ddata->image_info=image_info;
2629 ddata->draw_info=CloneDrawInfo(image_info,(const DrawInfo *) NULL);
2630 ddata->exception=exception;
2631 ddata->draw_info->font=(char *)
2632 RelinquishMagickMemory(ddata->draw_info->font);
2633 ddata->draw_info->text=(char *)
2634 RelinquishMagickMemory(ddata->draw_info->text);
2636 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
2637 /* Must initialize font subystem for WMFlite interface */
2638 lite_font_init (API,&wmf_api_options); /* similar to wmf_ipa_font_init in src/font.c */
2639 /* wmf_arg_fontdirs (API,options); */ /* similar to wmf_arg_fontdirs in src/wmf.c */
2644 * Open BLOB input via libwmf API
2647 wmf_error = wmf_bbuf_input(API,ipa_blob_read,ipa_blob_seek,
2648 ipa_blob_tell,(void*)image);
2649 if (wmf_error != wmf_E_None)
2651 wmf_api_destroy(API);
2652 if (image->debug != MagickFalse)
2654 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2655 " wmf_bbuf_input failed");
2656 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2657 "leave ReadWMFImage()");
2659 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
2661 image=DestroyImageList(image);
2662 return((Image *) NULL);
2669 if (image->debug != MagickFalse)
2670 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2671 " Scanning WMF to obtain bounding box");
2672 wmf_error=wmf_scan(API, 0, &bbox);
2673 if (wmf_error != wmf_E_None)
2675 wmf_api_destroy(API);
2676 if (image->debug != MagickFalse)
2678 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2679 " wmf_scan failed with wmf_error %d", wmf_error);
2680 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2681 "leave ReadWMFImage()");
2683 ThrowReaderException(DelegateError,"FailedToScanFile");
2687 * Compute dimensions and scale factors
2693 /* User specified resolution */
2694 resolution_y=DefaultResolution;
2695 if (image->resolution.y > 0)
2697 resolution_y = image->resolution.y;
2698 if (image->units == PixelsPerCentimeterResolution)
2699 resolution_y *= CENTIMETERS_PER_INCH;
2701 resolution_x=DefaultResolution;
2702 if (image->resolution.x > 0)
2704 resolution_x = image->resolution.x;
2705 if (image->units == PixelsPerCentimeterResolution)
2706 resolution_x *= CENTIMETERS_PER_INCH;
2709 /* Obtain output size expressed in metafile units */
2710 wmf_error=wmf_size(API,&wmf_width,&wmf_height);
2711 if (wmf_error != wmf_E_None)
2713 wmf_api_destroy(API);
2714 if (image->debug != MagickFalse)
2716 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2717 " wmf_size failed with wmf_error %d", wmf_error);
2718 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2719 "leave ReadWMFImage()");
2721 ThrowReaderException(DelegateError,"FailedToComputeOutputSize");
2724 /* Obtain (or guess) metafile units */
2725 if ((API)->File->placeable)
2726 units_per_inch=(API)->File->pmh->Inch;
2727 else if ( (wmf_width*wmf_height) < 1024*1024)
2728 units_per_inch=POINTS_PER_INCH; /* MM_TEXT */
2730 units_per_inch=TWIPS_PER_INCH; /* MM_TWIPS */
2732 /* Calculate image width and height based on specified DPI
2734 image_width_inch = (double) wmf_width / units_per_inch;
2735 image_height_inch = (double) wmf_height / units_per_inch;
2736 image_width = image_width_inch * resolution_x;
2737 image_height = image_height_inch * resolution_y;
2739 /* Compute bounding box scale factors and origin translations
2741 * This all just a hack since libwmf does not currently seem to
2742 * provide the mapping between LOGICAL coordinates and DEVICE
2743 * coordinates. This mapping is necessary in order to know
2744 * where to place the logical bounding box within the image.
2748 bounding_width = bbox.BR.x - bbox.TL.x;
2749 bounding_height = bbox.BR.y - bbox.TL.y;
2751 ddata->scale_x = image_width/bounding_width;
2752 ddata->translate_x = 0-bbox.TL.x;
2755 /* Heuristic: guess that if the vertical coordinates mostly span
2756 negative values, then the image must be inverted. */
2757 if ( fabs(bbox.BR.y) > fabs(bbox.TL.y) )
2759 /* Normal (Origin at top left of image) */
2760 ddata->scale_y = (image_height/bounding_height);
2761 ddata->translate_y = 0-bbox.TL.y;
2765 /* Inverted (Origin at bottom left of image) */
2766 ddata->scale_y = (-image_height/bounding_height);
2767 ddata->translate_y = 0-bbox.BR.y;
2770 if (image->debug != MagickFalse)
2772 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2773 " Placeable metafile: %s",
2774 (API)->File->placeable ? "Yes" : "No");
2776 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2777 " Size in metafile units: %gx%g",wmf_width,wmf_height);
2778 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2779 " Metafile units/inch: %g",units_per_inch);
2780 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2781 " Size in inches: %gx%g",
2782 image_width_inch,image_height_inch);
2783 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2784 " Bounding Box: %g,%g %g,%g",
2785 bbox.TL.x, bbox.TL.y, bbox.BR.x, bbox.BR.y);
2786 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2787 " Bounding width x height: %gx%g",bounding_width,
2789 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2790 " Output resolution: %gx%g",resolution_x,resolution_y);
2791 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2792 " Image size: %gx%g",image_width,image_height);
2793 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2794 " Bounding box scale factor: %g,%g",ddata->scale_x,
2796 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2797 " Translation: %g,%g",
2798 ddata->translate_x, ddata->translate_y);
2804 typedef struct _wmfPlayer_t wmfPlayer_t;
2808 wmfBrush default_brush;
2809 wmfFont default_font;
2811 wmfDC* dc; /* current dc */
2817 #define WMF_ELICIT_DC(API) (((wmfPlayer_t*)((API)->player_data))->dc)
2819 dc = WMF_ELICIT_DC(API);
2821 printf("dc->Window.Ox = %d\n", dc->Window.Ox);
2822 printf("dc->Window.Oy = %d\n", dc->Window.Oy);
2823 printf("dc->Window.width = %d\n", dc->Window.width);
2824 printf("dc->Window.height = %d\n", dc->Window.height);
2825 printf("dc->pixel_width = %g\n", dc->pixel_width);
2826 printf("dc->pixel_height = %g\n", dc->pixel_height);
2827 #if defined(MAGICKCORE_WMFLITE_DELEGATE) /* Only in libwmf 0.3 */
2828 printf("dc->Ox = %.d\n", dc->Ox);
2829 printf("dc->Oy = %.d\n", dc->Oy);
2830 printf("dc->width = %.d\n", dc->width);
2831 printf("dc->height = %.d\n", dc->height);
2840 * Create canvas image
2843 image->rows=(unsigned long) ceil(image_height);
2844 image->columns=(unsigned long) ceil(image_width);
2846 if (image_info->ping != MagickFalse)
2848 wmf_api_destroy(API);
2849 (void) CloseBlob(image);
2850 if (image->debug != MagickFalse)
2851 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2852 "leave ReadWMFImage()");
2853 return(GetFirstImageInList(image));
2855 if (image->debug != MagickFalse)
2856 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2857 " Creating canvas image with size %lux%lu",(unsigned long) image->rows,
2858 (unsigned long) image->columns);
2861 * Set solid background color
2864 image->background_color = image_info->background_color;
2865 if (image->background_color.alpha != OpaqueAlpha)
2866 image->matte = MagickTrue;
2867 (void) SetImageBackgroundColor(image,exception);
2870 * Play file to generate Vector drawing commands
2874 if (image->debug != MagickFalse)
2875 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2876 " Playing WMF to prepare vectors");
2878 wmf_error = wmf_play(API, 0, &bbox);
2879 if (wmf_error != wmf_E_None)
2881 wmf_api_destroy(API);
2882 if (image->debug != MagickFalse)
2884 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2885 " Playing WMF failed with wmf_error %d", wmf_error);
2886 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2887 "leave ReadWMFImage()");
2889 ThrowReaderException(DelegateError,"FailedToRenderFile");
2893 * Scribble on canvas image
2897 if (image->debug != MagickFalse)
2898 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2899 " Rendering WMF vectors");
2900 DrawRender(ddata->draw_wand);
2902 if (image->debug != MagickFalse)
2903 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
2905 /* Cleanup allocated data */
2906 wmf_api_destroy(API);
2907 (void) CloseBlob(image);
2915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2919 % R e g i s t e r W M F I m a g e %
2923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2925 % RegisterWMFImage() adds attributes for the WMF image format to
2926 % the list of supported formats. The attributes include the image format
2927 % tag, a method to read and/or write the format, whether the format
2928 % supports the saving of more than one frame to the same file or blob,
2929 % whether the format supports native in-memory I/O, and a brief
2930 % description of the format.
2932 % The format of the RegisterWMFImage method is:
2934 % size_t RegisterWMFImage(void)
2937 ModuleExport size_t RegisterWMFImage(void)
2942 entry = SetMagickInfo("WMZ");
2943 #if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
2944 entry->decoder=ReadWMFImage;
2946 entry->description=ConstantString("Compressed Windows Meta File");
2947 entry->module=ConstantString("WMZ");
2948 entry->seekable_stream=MagickTrue;
2949 (void) RegisterMagickInfo(entry);
2950 entry=SetMagickInfo("WMF");
2951 #if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
2952 entry->decoder=ReadWMFImage;
2954 entry->description=ConstantString("Windows Meta File");
2955 entry->module=ConstantString("WMF");
2956 (void) RegisterMagickInfo(entry);
2957 return(MagickImageCoderSignature);
2961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2965 % U n r e g i s t e r W M F I m a g e %
2969 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2971 % UnregisterWMFImage() removes format registrations made by the
2972 % WMF module from the list of supported formats.
2974 % The format of the UnregisterWMFImage method is:
2976 % UnregisterWMFImage(void)
2979 ModuleExport void UnregisterWMFImage(void)
2981 (void) UnregisterMagickInfo("WMZ");
2982 (void) UnregisterMagickInfo("WMF");