2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read Windows Metafile Format %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 #include "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(MAGICKCORE_WMF_DELEGATE)
67 #include "libwmf/api.h"
68 #include "libwmf/eps.h"
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 % R e a d W M F I m a g e %
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 % ReadWMFImage() reads an Windows Metafile image file and returns it. It
82 % allocates the memory necessary for the new Image structure and returns a
83 % pointer to the new image.
85 % The format of the ReadWMFImage method is:
87 % Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
89 % A description of each parameter follows:
91 % o image_info: the image info.
93 % o exception: return any errors or warnings in this structure.
97 static int WMFReadBlob(void *image)
99 return(ReadBlobByte((Image *) image));
102 static int WMFSeekBlob(void *image,long offset)
104 return((int) SeekBlob((Image *) image,(MagickOffsetType) offset,SEEK_SET));
107 static long WMFTellBlob(void *image)
109 return((long) TellBlob((Image*) image));
112 static Image *ReadWMFImage(const ImageInfo *image_info,ExceptionInfo *exception)
115 filename[MaxTextExtent];
153 image=AcquireImage(image_info,exception);
154 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
155 if (status == MagickFalse)
157 image=DestroyImageList(image);
158 return((Image *) NULL);
160 wmf_info=(wmfAPI *) NULL;
162 flags|=WMF_OPT_IGNORE_NONFATAL;
163 flags|=WMF_OPT_FUNCTION;
164 options.function=wmf_eps_function;
165 wmf_status=wmf_api_create(&wmf_info,(unsigned long) flags,&options);
166 if (wmf_status != wmf_E_None)
168 if (wmf_info != (wmfAPI *) NULL)
169 wmf_api_destroy(wmf_info);
170 ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
172 wmf_status=wmf_bbuf_input(wmf_info,WMFReadBlob,WMFSeekBlob,WMFTellBlob,
174 if (wmf_status != wmf_E_None)
176 wmf_api_destroy(wmf_info);
177 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
179 image=DestroyImageList(image);
180 return((Image *) NULL);
182 wmf_status=wmf_scan(wmf_info,0,&bounding_box);
183 if (wmf_status != wmf_E_None)
185 wmf_api_destroy(wmf_info);
186 ThrowReaderException(DelegateError,"FailedToScanFile");
188 eps_info=WMF_EPS_GetData(wmf_info);
190 unique_file=AcquireUniqueFileResource(filename);
191 if (unique_file != -1)
192 file=fdopen(unique_file,"wb");
193 if ((unique_file == -1) || (file == (FILE *) NULL))
195 wmf_api_destroy(wmf_info);
196 ThrowReaderException(FileOpenError,"UnableToCreateTemporaryFile");
198 eps_info->out=wmf_stream_create(wmf_info,file);
199 eps_info->bbox=bounding_box;
200 wmf_status=wmf_play(wmf_info,0,&bounding_box);
201 if (wmf_status != wmf_E_None)
203 wmf_api_destroy(wmf_info);
204 ThrowReaderException(DelegateError,"FailedToRenderFile");
207 wmf_api_destroy(wmf_info);
208 (void) CloseBlob(image);
209 image=DestroyImage(image);
213 read_info=CloneImageInfo(image_info);
214 SetImageInfoBlob(read_info,(void *) NULL,0);
215 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"eps:%s",
217 image=ReadImage(read_info,exception);
218 read_info=DestroyImageInfo(read_info);
219 if (image != (Image *) NULL)
221 (void) CopyMagickString(image->filename,image_info->filename,
223 (void) CopyMagickString(image->magick_filename,image_info->filename,
225 (void) CopyMagickString(image->magick,"WMF",MaxTextExtent);
227 (void) RelinquishUniqueFileResource(filename);
228 return(GetFirstImageInList(image));
230 #elif defined(MAGICKCORE_WMFLITE_DELEGATE)
232 #define ERR(API) ((API)->err != wmf_E_None)
233 #define XC(x) ((double) x)
234 #define YC(y) ((double) y)
237 # define M_PI MagickPI
240 #if defined(MAGICKCORE_HAVE_FT2BUILD_H)
241 # include <ft2build.h>
244 #include "libwmf/fund.h"
245 #include "libwmf/types.h"
246 #include "libwmf/api.h"
263 /* The following additinal undefs were required for MinGW */
266 #undef PS_ENDCAP_ROUND
267 #undef PS_ENDCAP_SQUARE
268 #undef PS_ENDCAP_FLAT
269 #undef PS_ENDCAP_MASK
276 #undef STRETCH_ANDSCANS
277 #undef STRETCH_ORSCANS
278 #undef STRETCH_DELETESCANS
279 #undef STRETCH_HALFTONE
282 #undef ETO_GLYPH_INDEX
283 #undef ETO_RTLREADING
285 #include "libwmf/defs.h"
286 #include "libwmf/ipa.h"
287 #include "libwmf/color.h"
288 #include "libwmf/macro.h"
290 /* Unit conversions */
291 #define TWIPS_PER_INCH 1440
292 #define CENTIMETERS_PER_INCH 2.54
293 #define POINTS_PER_INCH 72
295 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
296 # define wmf_api_create(api,flags,options) wmf_lite_create(api,flags,options)
297 # define wmf_api_destroy(api) wmf_lite_destroy(api)
298 # undef WMF_FONT_PSNAME
299 # define WMF_FONT_PSNAME(F) ((F)->user_data ? ((wmf_magick_font_t*) (F)->user_data)->ps_name : 0)
301 typedef struct _wmf_magick_font_t wmf_magick_font_t;
303 struct _wmf_magick_font_t
311 typedef struct _wmf_magick_t wmf_magick_t;
319 /* Scale and translation factors */
334 /* ImageMagick image */
364 #define WMF_MAGICK_GetData(Z) ((wmf_magick_t*)((Z)->device_data))
365 #define WMF_MAGICK_GetFontData(Z) \
366 ((wmf_magick_font_t*)((wmfFontData *)Z->font_data)->user_data)
368 #define WmfDrawingWand (((wmf_magick_t*)((API)->device_data))->draw_wand)
370 /* Enum to control whether util_set_brush applies brush to fill or
379 /* Enum to specify arc type */
382 magick_arc_ellipse = 0,
389 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
390 static void lite_font_init (wmfAPI* API, wmfAPI_Options* options);
391 static void lite_font_map(wmfAPI* API,wmfFont* font);
392 static float lite_font_stringwidth(wmfAPI* API, wmfFont* font, char* str);
395 static void draw_fill_color_rgb(wmfAPI* API, const wmfRGB* rgb);
396 static void draw_stroke_color_rgb(wmfAPI* API, const wmfRGB* rgb);
397 static void draw_pattern_push(wmfAPI* API, unsigned long id, unsigned long columns, unsigned long rows);
398 static int ipa_blob_read(void* wand);
399 static int ipa_blob_seek(void* wand,long position);
400 static long ipa_blob_tell(void* wand);
401 static void ipa_bmp_draw(wmfAPI * API, wmfBMP_Draw_t * bmp_draw);
402 static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp);
403 static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read);
404 static void ipa_device_begin(wmfAPI * API);
405 static void ipa_device_close(wmfAPI * API);
406 static void ipa_device_end(wmfAPI * API);
407 static void ipa_device_open(wmfAPI * API);
408 static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc);
409 static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc);
410 static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc);
411 static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line);
412 static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc);
413 static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel);
414 static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * poly_line);
415 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
416 static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon);
418 static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect);
419 static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text);
420 static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood);
421 static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood);
422 static void ipa_functions(wmfAPI * API);
423 static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * poly_line);
424 static void ipa_region_clip(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
425 static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
426 static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
427 static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw);
428 static void ipa_udata_copy(wmfAPI * API, wmfUserData_t * userdata);
429 static void ipa_udata_free(wmfAPI * API, wmfUserData_t * userdata);
430 static void ipa_udata_init(wmfAPI * API, wmfUserData_t * userdata);
431 static void ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata);
432 static int magick_progress_callback(void* wand,float quantum);
433 static void util_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc,magick_arc_t finish);
434 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
435 /*static int util_font_weight( const char* font );*/
437 static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height, ExceptionInfo *);
438 static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply);
439 static void util_set_pen(wmfAPI * API, wmfDC * dc);
441 /* Progress callback */
442 int magick_progress_callback(void *context,float quantum)
450 image=(Image *) context;
451 assert(image->signature == MagickSignature);
452 status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
454 return(status == MagickTrue ? 0 : 1);
458 static void draw_fill_color_string(DrawingWand *drawing_wand,const char *color)
463 fill_color=NewPixelWand();
464 PixelSetColor(fill_color,color);
465 DrawSetFillColor(drawing_wand,fill_color);
466 fill_color=DestroyPixelWand(fill_color);
468 static void draw_fill_color_rgb( wmfAPI* API, const wmfRGB* rgb )
473 fill_color=NewPixelWand();
474 PixelSetRedQuantum(fill_color,ScaleCharToQuantum(rgb->r));
475 PixelSetGreenQuantum(fill_color,ScaleCharToQuantum(rgb->g));
476 PixelSetBlueQuantum(fill_color,ScaleCharToQuantum(rgb->b));
477 PixelSetAlphaQuantum(fill_color,OpaqueAlpha);
478 DrawSetFillColor(WmfDrawingWand,fill_color);
479 fill_color=DestroyPixelWand(fill_color);
482 /* Set stroke color */
483 static void draw_stroke_color_string(DrawingWand *drawing_wand,const char *color)
488 stroke_color=NewPixelWand();
489 PixelSetColor(stroke_color,color);
490 DrawSetStrokeColor(drawing_wand,stroke_color);
491 stroke_color=DestroyPixelWand(stroke_color);
494 static void draw_stroke_color_rgb( wmfAPI* API, const wmfRGB* rgb )
499 stroke_color=NewPixelWand();
500 PixelSetRedQuantum(stroke_color,ScaleCharToQuantum(rgb->r));
501 PixelSetGreenQuantum(stroke_color,ScaleCharToQuantum(rgb->g));
502 PixelSetBlueQuantum(stroke_color,ScaleCharToQuantum(rgb->b));
503 PixelSetAlphaQuantum(stroke_color,OpaqueAlpha);
504 DrawSetStrokeColor(WmfDrawingWand,stroke_color);
505 stroke_color=DestroyPixelWand(stroke_color);
508 /* Set under color */
509 static void draw_under_color_string(DrawingWand *drawing_wand,const char *color)
514 under_color=NewPixelWand();
515 PixelSetColor(under_color,color);
516 DrawSetTextUnderColor(drawing_wand,under_color);
517 under_color=DestroyPixelWand(under_color);
520 static void draw_pattern_push( wmfAPI* API,
522 unsigned long columns,
528 (void) FormatLocaleString(pattern_id,MaxTextExtent,"brush_%lu",id);
529 (void) DrawPushPattern(WmfDrawingWand,pattern_id,0,0,columns,rows);
532 /* Pattern/Bit BLT with raster operation (ROP) support. Invoked by
533 META_PATBLT, which is equivalent to Windows PatBlt() call, or by
534 META_DIBBITBLT which is equivalent to Windows BitBlt() call. */
536 /* The BitBlt function transfers pixels from a rectangular area in one
537 device wand called the 'source', to a rectangular area of the
538 same size in another device wand, called the 'destination'. */
540 static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw)
543 /* *brush = WMF_DC_BRUSH(rop_draw->dc); */
546 /* *brush_bmp = WMF_BRUSH_BITMAP(brush); */
548 if (TO_FILL(rop_draw) == 0)
551 /* Save graphic wand */
552 (void) PushDrawingWand(WmfDrawingWand);
554 /* FIXME: finish implementing (once we know what it is supposed to do!) */
557 struct _wmfROP_Draw_t
570 /* if (brush_bmp && brush_bmp->data != 0) */
571 /* printf("Have an image!\n"); */
573 switch (rop_draw->ROP) /* Ternary raster operations */
575 case SRCCOPY: /* dest = source */
576 printf("ipa_rop_draw SRCCOPY ROP mode not implemented\n");
578 case SRCPAINT: /* dest = source OR dest */
579 printf("ipa_rop_draw SRCPAINT ROP mode not implemented\n");
581 case SRCAND: /* dest = source AND dest */
582 printf("ipa_rop_draw SRCAND ROP mode not implemented\n");
584 case SRCINVERT: /* dest = source XOR dest */
585 printf("ipa_rop_draw SRCINVERT ROP mode not implemented\n");
587 case SRCERASE: /* dest = source AND (NOT dest) */
588 printf("ipa_rop_draw SRCERASE ROP mode not implemented\n");
590 case NOTSRCCOPY: /* dest = (NOT source) */
591 printf("ipa_rop_draw NOTSRCCOPY ROP mode not implemented\n");
593 case NOTSRCERASE: /* dest = (NOT src) AND (NOT dest) */
594 printf("ipa_rop_draw NOTSRCERASE ROP mode not implemented\n");
596 case MERGECOPY: /* dest = (source AND pattern) */
597 printf("ipa_rop_draw MERGECOPY ROP mode not implemented\n");
599 case MERGEPAINT: /* dest = (NOT source) OR dest */
600 printf("ipa_rop_draw MERGEPAINT ROP mode not implemented\n");
602 case PATCOPY: /* dest = pattern */
603 util_set_brush(API, rop_draw->dc, BrushApplyFill);
605 case PATPAINT: /* dest = DPSnoo */
606 printf("ipa_rop_draw PATPAINT ROP mode not implemented\n");
608 case PATINVERT: /* dest = pattern XOR dest */
609 printf("ipa_rop_draw PATINVERT ROP mode not implemented\n");
611 case DSTINVERT: /* dest = (NOT dest) */
612 printf("ipa_rop_draw DSTINVERT ROP mode not implemented\n");
614 case BLACKNESS: /* dest = BLACK */
615 draw_fill_color_string(WmfDrawingWand,"black");
617 case WHITENESS: /* dest = WHITE */
618 draw_fill_color_string(WmfDrawingWand,"white");
621 printf("ipa_rop_draw 0x%x ROP mode not implemented\n", rop_draw->ROP);
625 DrawRectangle(WmfDrawingWand,
626 XC(rop_draw->TL.x), YC(rop_draw->TL.y),
627 XC(rop_draw->BR.x), YC(rop_draw->BR.y));
629 /* Restore graphic wand */
630 (void) PopDrawingWand(WmfDrawingWand);
633 static void ipa_bmp_draw(wmfAPI *API, wmfBMP_Draw_t *bmp_draw)
636 *ddata = WMF_MAGICK_GetData(API);
654 if (bmp_draw->bmp.data == 0)
657 image = (Image*)bmp_draw->bmp.data;
661 exception=ddata->exception;
662 if (bmp_draw->crop.x || bmp_draw->crop.y ||
663 (bmp_draw->crop.w != bmp_draw->bmp.width) ||
664 (bmp_draw->crop.h != bmp_draw->bmp.height))
666 /* Image needs to be cropped */
673 crop_info.x = bmp_draw->crop.x;
674 crop_info.y = bmp_draw->crop.y;
675 crop_info.width = bmp_draw->crop.w;
676 crop_info.height = bmp_draw->crop.h;
678 crop_image = CropImage( image, &crop_info, exception );
681 image=DestroyImageList(image);
683 bmp_draw->bmp.data = (void*)image;
687 QueryColorCompliance( "white", AllCompliance, &white, exception );
689 if ( ddata->image_info->texture ||
690 !(IsPixelInfoEquivalent(&ddata->image_info->background_color,&white)) ||
691 ddata->image_info->background_color.alpha != OpaqueAlpha )
694 Set image white background to transparent so that it may be
695 overlaid over non-white backgrounds.
697 QueryColorCompliance( "white", AllCompliance, &white, exception );
698 TransparentPaintImage( image, &white, QuantumRange, MagickFalse, exception );
701 width = fabs(bmp_draw->pixel_width * (double) bmp_draw->crop.w);
702 height = fabs(bmp_draw->pixel_height * (double) bmp_draw->crop.h);
703 magick_wand=NewMagickWandFromImage(image);
704 (void) DrawComposite(WmfDrawingWand, CopyCompositeOp,
705 XC(bmp_draw->pt.x) * ddata->scale_x, YC(bmp_draw->pt.y) * ddata->scale_y,
706 width * ddata->scale_x, height * ddata->scale_y, magick_wand);
707 magick_wand=DestroyMagickWand(magick_wand);
710 printf("bmp_draw->bmp.data = 0x%lx\n", (long)bmp_draw->bmp.data);
711 printf("registry id = %li\n", id);
712 /* printf("pixel_width = %g\n", bmp_draw->pixel_width); */
713 /* printf("pixel_height = %g\n", bmp_draw->pixel_height); */
714 printf("bmp_draw->bmp WxH = %ix%i\n", bmp_draw->bmp.width, bmp_draw->bmp.height);
715 printf("bmp_draw->crop WxH = %ix%i\n", bmp_draw->crop.w, bmp_draw->crop.h);
716 printf("bmp_draw->crop x,y = %i,%i\n", bmp_draw->crop.x, bmp_draw->crop.y);
717 printf("image size WxH = %lux%lu\n", image->columns, image->rows);
721 static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read) {
723 *ddata = WMF_MAGICK_GetData(API);
734 bmp_read->bmp.data = 0;
736 image_info=CloneImageInfo(ddata->image_info);
737 exception=ddata->exception;
738 (void) CopyMagickString(image_info->magick,"DIB",MaxTextExtent);
739 if (bmp_read->width || bmp_read->height)
744 (void) FormatLocaleString(size,MaxTextExtent,"%ux%u",bmp_read->width,
746 CloneString(&image_info->size,size);
749 printf("ipa_bmp_read: buffer=0x%lx length=%ld, width=%i, height=%i\n",
750 (long) bmp_read->buffer, bmp_read->length,
751 bmp_read->width, bmp_read->height);
753 image=BlobToImage(image_info, (const void *) bmp_read->buffer,
754 bmp_read->length, exception);
755 image_info=DestroyImageInfo(image_info);
756 if (image != (Image *) NULL)
759 printf("ipa_bmp_read: rows=%ld,columns=%ld\n\n", image->rows, image->columns);
762 bmp_read->bmp.data = (void*)image;
763 bmp_read->bmp.width = (U16)image->columns;
764 bmp_read->bmp.height = (U16)image->rows;
768 static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp)
771 DestroyImageList((Image*)bmp->data);
772 bmp->data = (void*) 0;
773 bmp->width = (U16) 0;
774 bmp->height = (U16) 0;
778 This called by wmf_play() the *first* time the meta file is played
780 static void ipa_device_open(wmfAPI * API)
783 *ddata = WMF_MAGICK_GetData (API);
785 ddata->pattern_id = 0;
786 ddata->clipping = MagickFalse;
787 ddata->clip_mask_id = 0;
789 ddata->push_depth = 0;
791 ddata->draw_wand = DrawAllocateWand(ddata->draw_info,ddata->image);
795 This called by wmf_api_destroy()
797 static void ipa_device_close(wmfAPI * API)
800 *ddata = WMF_MAGICK_GetData(API);
802 DestroyDrawingWand(ddata->draw_wand);
803 DestroyDrawInfo(ddata->draw_info);
804 RelinquishMagickMemory(WMF_MAGICK_GetFontData(API)->ps_name);
808 This called from the beginning of each play for initial page setup
810 static void ipa_device_begin(wmfAPI * API)
813 comment[MaxTextExtent];
816 *ddata = WMF_MAGICK_GetData(API);
818 /* Make SVG output happy */
819 (void) PushDrawingWand(WmfDrawingWand);
821 DrawSetViewbox(WmfDrawingWand, 0, 0, ddata->image->columns, ddata->image->rows );
823 (void) FormatLocaleString(comment,MaxTextExtent,"Created by ImageMagick %s",
824 GetMagickVersion((unsigned long *) NULL));
825 DrawComment(WmfDrawingWand,comment);
827 /* Scale width and height to image */
828 DrawScale(WmfDrawingWand, ddata->scale_x, ddata->scale_y);
830 /* Translate to TL corner of bounding box */
831 DrawTranslate(WmfDrawingWand, ddata->translate_x, ddata->translate_y);
834 DrawRotate(WmfDrawingWand, ddata->rotate);
836 if (ddata->image_info->texture == NULL)
841 /* Draw rectangle in background color */
842 background_color=NewPixelWand();
843 PixelSetPixelColor(background_color,&ddata->image->background_color);
844 DrawSetFillColor(WmfDrawingWand,background_color);
845 background_color=DestroyPixelWand(background_color);
846 DrawRectangle(WmfDrawingWand,
847 XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
848 XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
852 /* Draw rectangle with texture image the SVG way */
862 GetExceptionInfo(&exception);
864 image_info = CloneImageInfo((ImageInfo *) 0);
865 (void) CopyMagickString(image_info->filename,ddata->image_info->texture,
867 if ( ddata->image_info->size )
868 CloneString(&image_info->size,ddata->image_info->size);
870 image = ReadImage(image_info,&exception);
871 image_info=DestroyImageInfo(image_info);
880 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
881 DrawPushDefs(WmfDrawingWand);
882 draw_pattern_push(API,ddata->pattern_id,image->columns,image->rows);
883 magick_wand=NewMagickWandFromImage(image);
884 (void) DrawComposite(WmfDrawingWand,CopyCompositeOp,0,0,
885 image->columns,image->rows,magick_wand);
886 magick_wand=DestroyMagickWand(magick_wand);
887 (void) DrawPopPattern(WmfDrawingWand);
888 DrawPopDefs(WmfDrawingWand);
889 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
891 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
894 DrawRectangle(WmfDrawingWand,
895 XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
896 XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
897 image=DestroyImageList(image);
901 LogMagickEvent(CoderEvent,GetMagickModule(),
902 "reading texture image failed!");
906 DrawSetClipRule(WmfDrawingWand,EvenOddRule); /* Default for WMF is ALTERNATE polygon fill mode */
907 draw_fill_color_string(WmfDrawingWand,"none"); /* Default brush is WHITE_BRUSH */
908 draw_stroke_color_string(WmfDrawingWand,"none"); /* Default pen is BLACK_PEN */
909 DrawSetStrokeLineCap(WmfDrawingWand,ButtCap); /* Default linecap is PS_ENDCAP_FLAT */
910 DrawSetStrokeLineJoin(WmfDrawingWand,MiterJoin); /* Default linejoin is PS_JOIN_MITER */
911 draw_under_color_string(WmfDrawingWand,"white"); /* Default text box is white */
915 This called from the end of each play for page termination
917 static void ipa_device_end(wmfAPI * API)
920 *ddata = WMF_MAGICK_GetData(API);
922 /* Reset any existing clip paths by popping wand */
924 (void) PopDrawingWand(WmfDrawingWand);
925 ddata->clipping = MagickFalse;
927 /* Make SVG output happy */
928 (void) PopDrawingWand(WmfDrawingWand);
931 static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood)
933 /* Save graphic wand */
934 (void) PushDrawingWand(WmfDrawingWand);
936 draw_fill_color_rgb(API,&(flood->color));
938 DrawColor(WmfDrawingWand,XC(flood->pt.x), YC(flood->pt.y),
941 /* Restore graphic wand */
942 (void) PopDrawingWand(WmfDrawingWand);
945 static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood)
947 /* Save graphic wand */
948 (void) PushDrawingWand(WmfDrawingWand);
950 draw_fill_color_rgb(API,&(flood->color));
952 if (flood->type == FLOODFILLSURFACE)
953 DrawColor(WmfDrawingWand, XC(flood->pt.x), YC(flood->pt.y),
956 DrawColor(WmfDrawingWand, XC(flood->pt.x), YC(flood->pt.y),
959 /* Restore graphic wand */
960 (void) PopDrawingWand(WmfDrawingWand);
963 static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel)
965 /* Save graphic wand */
966 (void) PushDrawingWand(WmfDrawingWand);
968 draw_stroke_color_string(WmfDrawingWand,"none");
970 draw_fill_color_rgb(API,&(draw_pixel->color));
972 DrawRectangle(WmfDrawingWand,
973 XC(draw_pixel->pt.x),
974 YC(draw_pixel->pt.y),
975 XC(draw_pixel->pt.x + draw_pixel->pixel_width),
976 YC(draw_pixel->pt.y + draw_pixel->pixel_height));
978 /* Restore graphic wand */
979 (void) PopDrawingWand(WmfDrawingWand);
982 static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc)
984 util_draw_arc(API, draw_arc, magick_arc_pie);
987 static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc)
989 util_draw_arc(API, draw_arc, magick_arc_chord);
992 static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc)
994 util_draw_arc(API, draw_arc, magick_arc_open);
997 static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc)
999 util_draw_arc(API, draw_arc, magick_arc_ellipse);
1002 static void util_draw_arc(wmfAPI * API,
1003 wmfDrawArc_t * draw_arc, magick_arc_t finish)
1021 /* Save graphic wand */
1022 (void) PushDrawingWand(WmfDrawingWand);
1024 if (TO_FILL(draw_arc) || TO_DRAW(draw_arc))
1026 center.x = (draw_arc->TL.x + draw_arc->BR.x) / 2;
1027 center.y = (draw_arc->TL.y + draw_arc->BR.y) / 2;
1031 if (finish != magick_arc_ellipse)
1033 draw_arc->start.x += center.x;
1034 draw_arc->start.y += center.y;
1036 draw_arc->end.x += center.x;
1037 draw_arc->end.y += center.y;
1045 if (finish != magick_arc_ellipse)
1047 start = draw_arc->start;
1048 end = draw_arc->end;
1051 Rx = (BR.x - TL.x) / 2;
1052 Ry = (BR.y - TL.y) / 2;
1054 if (finish != magick_arc_ellipse)
1062 phi_s = atan2((double) start.y, (double) start.x) * 180 / MagickPI;
1063 phi_e = atan2((double) end.y, (double) end.x) * 180 / MagickPI;
1069 util_set_pen(API, draw_arc->dc);
1070 if (finish == magick_arc_open)
1071 draw_fill_color_string(WmfDrawingWand,"none");
1073 util_set_brush(API, draw_arc->dc, BrushApplyFill);
1075 if (finish == magick_arc_ellipse)
1076 DrawEllipse(WmfDrawingWand, XC(O.x), YC(O.y), Rx, Ry, 0, 360);
1077 else if (finish == magick_arc_pie)
1079 DrawPathStart(WmfDrawingWand);
1080 DrawPathMoveToAbsolute(WmfDrawingWand, XC(O.x+start.x),
1082 DrawPathEllipticArcAbsolute(WmfDrawingWand, Rx, Ry, 0, MagickFalse,
1083 MagickTrue, XC(O.x+end.x), YC(O.y+end.y));
1084 DrawPathLineToAbsolute(WmfDrawingWand, XC(O.x), YC(O.y));
1085 DrawPathClose(WmfDrawingWand);
1086 DrawPathFinish(WmfDrawingWand);
1088 else if (finish == magick_arc_chord)
1090 DrawArc(WmfDrawingWand, XC(draw_arc->TL.x), YC(draw_arc->TL.y),
1091 XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
1092 DrawLine(WmfDrawingWand, XC(draw_arc->BR.x-start.x),
1093 YC(draw_arc->BR.y-start.y), XC(draw_arc->BR.x-end.x),
1094 YC(draw_arc->BR.y-end.y));
1096 else /* if (finish == magick_arc_open) */
1097 DrawArc(WmfDrawingWand, XC(draw_arc->TL.x), YC(draw_arc->TL.y),
1098 XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
1101 /* Restore graphic wand */
1102 (void) PopDrawingWand(WmfDrawingWand);
1105 static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line)
1107 /* Save graphic wand */
1108 (void) PushDrawingWand(WmfDrawingWand);
1110 if (TO_DRAW(draw_line))
1112 util_set_pen(API, draw_line->dc);
1113 DrawLine(WmfDrawingWand,
1114 XC(draw_line->from.x), YC(draw_line->from.y),
1115 XC(draw_line->to.x), YC(draw_line->to.y));
1118 /* Restore graphic wand */
1119 (void) PopDrawingWand(WmfDrawingWand);
1122 static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * polyline)
1124 if (polyline->count <= 2)
1127 if (TO_DRAW(polyline))
1132 /* Save graphic wand */
1133 (void) PushDrawingWand(WmfDrawingWand);
1135 util_set_pen(API, polyline->dc);
1137 DrawPathStart(WmfDrawingWand);
1138 DrawPathMoveToAbsolute(WmfDrawingWand,
1139 XC(polyline->pt[0].x),
1140 YC(polyline->pt[0].y));
1141 for (point = 1; point < polyline->count; point++)
1143 DrawPathLineToAbsolute(WmfDrawingWand,
1144 XC(polyline->pt[point].x),
1145 YC(polyline->pt[point].y));
1147 DrawPathFinish(WmfDrawingWand);
1149 /* Restore graphic wand */
1150 (void) PopDrawingWand(WmfDrawingWand);
1154 static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * polyline)
1156 if (polyline->count <= 2)
1159 if (TO_FILL(polyline) || TO_DRAW(polyline))
1164 /* Save graphic wand */
1165 (void) PushDrawingWand(WmfDrawingWand);
1167 util_set_pen(API, polyline->dc);
1168 util_set_brush(API, polyline->dc, BrushApplyFill);
1170 DrawPathStart(WmfDrawingWand);
1171 DrawPathMoveToAbsolute(WmfDrawingWand,
1172 XC(polyline->pt[0].x),
1173 YC(polyline->pt[0].y));
1174 for (point = 1; point < polyline->count; point++)
1176 DrawPathLineToAbsolute(WmfDrawingWand,
1177 XC(polyline->pt[point].x),
1178 YC(polyline->pt[point].y));
1180 DrawPathClose(WmfDrawingWand);
1181 DrawPathFinish(WmfDrawingWand);
1183 /* Restore graphic wand */
1184 (void) PopDrawingWand(WmfDrawingWand);
1188 /* Draw a polypolygon. A polypolygon is a list of polygons */
1189 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1190 static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon)
1192 if (TO_FILL(polypolygon) || TO_DRAW(polypolygon))
1201 /* Save graphic wand */
1202 (void) PushDrawingWand(WmfDrawingWand);
1204 util_set_pen(API, polypolygon->dc);
1205 util_set_brush(API, polypolygon->dc, BrushApplyFill);
1207 DrawPathStart(WmfDrawingWand);
1208 for (polygon = 0; polygon < polypolygon->npoly; polygon++)
1210 polyline.dc = polypolygon->dc;
1211 polyline.pt = polypolygon->pt[polygon];
1212 polyline.count = polypolygon->count[polygon];
1213 if ((polyline.count > 2) && polyline.pt)
1215 DrawPathMoveToAbsolute(WmfDrawingWand,
1216 XC(polyline.pt[0].x),
1217 YC(polyline.pt[0].y));
1218 for (point = 1; point < polyline.count; point++)
1220 DrawPathLineToAbsolute(WmfDrawingWand,
1221 XC(polyline.pt[point].x),
1222 YC(polyline.pt[point].y));
1224 DrawPathClose(WmfDrawingWand);
1227 DrawPathFinish(WmfDrawingWand);
1229 /* Restore graphic wand */
1230 (void) PopDrawingWand(WmfDrawingWand);
1235 static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect)
1237 /* Save graphic wand */
1238 (void) PushDrawingWand(WmfDrawingWand);
1240 if (TO_FILL(draw_rect) || TO_DRAW(draw_rect))
1242 util_set_pen(API, draw_rect->dc);
1243 util_set_brush(API, draw_rect->dc, BrushApplyFill);
1245 if ((draw_rect->width > 0) || (draw_rect->height > 0))
1246 DrawRoundRectangle(WmfDrawingWand,
1247 XC(draw_rect->TL.x), YC(draw_rect->TL.y),
1248 XC(draw_rect->BR.x), YC(draw_rect->BR.y),
1249 draw_rect->width / 2, draw_rect->height / 2);
1251 DrawRectangle(WmfDrawingWand,
1252 XC(draw_rect->TL.x), YC(draw_rect->TL.y),
1253 XC(draw_rect->BR.x), YC(draw_rect->BR.y));
1256 /* Restore graphic wand */
1257 (void) PopDrawingWand(WmfDrawingWand);
1260 /* Draw an un-filled rectangle using the current brush */
1261 static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
1263 /* Save graphic wand */
1264 (void) PushDrawingWand(WmfDrawingWand);
1266 if (TO_FILL(poly_rect) || TO_DRAW(poly_rect))
1271 draw_fill_color_string(WmfDrawingWand,"none");
1272 util_set_brush(API, poly_rect->dc, BrushApplyStroke);
1274 for (i = 0; i < (long) poly_rect->count; i++)
1276 DrawRectangle(WmfDrawingWand,
1277 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1278 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1282 /* Restore graphic wand */
1283 (void) PopDrawingWand(WmfDrawingWand);
1286 static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
1289 if (poly_rect->count == 0)
1292 /* Save graphic wand */
1293 (void) PushDrawingWand(WmfDrawingWand);
1295 if (TO_FILL (poly_rect))
1300 draw_stroke_color_string(WmfDrawingWand,"none");
1301 util_set_brush(API, poly_rect->dc, BrushApplyFill);
1303 for (i = 0; i < (long) poly_rect->count; i++)
1305 DrawRectangle(WmfDrawingWand,
1306 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1307 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1311 /* Restore graphic wand */
1312 (void) PopDrawingWand(WmfDrawingWand);
1315 static void ipa_region_clip(wmfAPI *API, wmfPolyRectangle_t *poly_rect)
1321 *ddata = WMF_MAGICK_GetData (API);
1323 /* Reset any existing clip paths by popping wand */
1324 if (ddata->clipping)
1325 (void) PopDrawingWand(WmfDrawingWand);
1326 ddata->clipping = MagickFalse;
1328 if (poly_rect->count > 0)
1333 /* Define clip path */
1334 ddata->clip_mask_id++;
1335 DrawPushDefs(WmfDrawingWand);
1336 (void) FormatLocaleString(clip_mask_id,MaxTextExtent,"clip_%lu",
1337 ddata->clip_mask_id);
1338 DrawPushClipPath(WmfDrawingWand,clip_mask_id);
1339 (void) PushDrawingWand(WmfDrawingWand);
1340 for (i = 0; i < (long) poly_rect->count; i++)
1342 DrawRectangle(WmfDrawingWand,
1343 XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1344 XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1346 (void) PopDrawingWand(WmfDrawingWand);
1347 DrawPopClipPath(WmfDrawingWand);
1348 DrawPopDefs(WmfDrawingWand);
1350 /* Push wand for new clip paths */
1351 (void) PushDrawingWand(WmfDrawingWand);
1352 (void) DrawSetClipPath(WmfDrawingWand,clip_mask_id);
1353 ddata->clipping = MagickTrue;
1357 static void ipa_functions(wmfAPI *API)
1362 wmfFunctionReference
1363 *FR = (wmfFunctionReference *) API->function_reference;
1366 IPA function reference links
1368 FR->device_open = ipa_device_open;
1369 FR->device_close = ipa_device_close;
1370 FR->device_begin = ipa_device_begin;
1371 FR->device_end = ipa_device_end;
1372 FR->flood_interior = ipa_flood_interior;
1373 FR->flood_exterior = ipa_flood_exterior;
1374 FR->draw_pixel = ipa_draw_pixel;
1375 FR->draw_pie = ipa_draw_pie;
1376 FR->draw_chord = ipa_draw_chord;
1377 FR->draw_arc = ipa_draw_arc;
1378 FR->draw_ellipse = ipa_draw_ellipse;
1379 FR->draw_line = ipa_draw_line;
1380 FR->poly_line = ipa_poly_line;
1381 FR->draw_polygon = ipa_draw_polygon;
1382 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1383 FR->draw_polypolygon = ipa_draw_polypolygon;
1385 FR->draw_rectangle = ipa_draw_rectangle;
1386 FR->rop_draw = ipa_rop_draw;
1387 FR->bmp_draw = ipa_bmp_draw;
1388 FR->bmp_read = ipa_bmp_read;
1389 FR->bmp_free = ipa_bmp_free;
1390 FR->draw_text = ipa_draw_text;
1391 FR->udata_init = ipa_udata_init;
1392 FR->udata_copy = ipa_udata_copy;
1393 FR->udata_set = ipa_udata_set;
1394 FR->udata_free = ipa_udata_free;
1395 FR->region_frame = ipa_region_frame;
1396 FR->region_paint = ipa_region_paint;
1397 FR->region_clip = ipa_region_clip;
1400 Allocate device data structure
1402 ddata = (wmf_magick_t *) wmf_malloc(API, sizeof(wmf_magick_t));
1406 (void) ResetMagickMemory((void *) ddata, 0, sizeof(wmf_magick_t));
1407 API->device_data = (void *) ddata;
1410 Device data defaults
1415 static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text)
1418 angle = 0, /* text rotation angle */
1419 bbox_height, /* bounding box height */
1420 bbox_width, /* bounding box width */
1421 pointsize = 0; /* pointsize to output font with desired height */
1430 BL, /* bottom left of bounding box */
1431 BR, /* bottom right of bounding box */
1432 TL, /* top left of bounding box */
1433 TR; /* top right of bounding box */
1436 point; /* text placement point */
1442 * ddata = WMF_MAGICK_GetData(API);
1444 point = draw_text->pt;
1446 /* Choose bounding box and calculate its width and height */
1451 if ( draw_text->flags)
1455 TR.x = draw_text->BR.x;
1456 TR.y = draw_text->TL.y;
1457 BL.x = draw_text->TL.x;
1458 BL.y = draw_text->BR.y;
1462 TL = draw_text->bbox.TL;
1463 BR = draw_text->bbox.BR;
1464 TR = draw_text->bbox.TR;
1465 BL = draw_text->bbox.BL;
1467 dx = ((TR.x - TL.x) + (BR.x - BL.x)) / 2;
1468 dy = ((TR.y - TL.y) + (BR.y - BL.y)) / 2;
1469 bbox_width = hypot(dx,dy);
1470 dx = ((BL.x - TL.x) + (BR.x - TR.x)) / 2;
1471 dy = ((BL.y - TL.y) + (BR.y - TR.y)) / 2;
1472 bbox_height = hypot(dx,dy);
1475 font = WMF_DC_FONT(draw_text->dc);
1477 /* Convert font_height to equivalent pointsize */
1478 exception=ddata->exception;
1479 pointsize = util_pointsize( API, font, draw_text->str, draw_text->font_height, exception);
1481 /* Save graphic wand */
1482 (void) PushDrawingWand(WmfDrawingWand);
1487 printf("\nipa_draw_text\n");
1488 printf("Text = \"%s\"\n", draw_text->str);
1489 /* printf("WMF_FONT_NAME: = \"%s\"\n", WMF_FONT_NAME(font)); */
1490 printf("WMF_FONT_PSNAME: = \"%s\"\n", WMF_FONT_PSNAME(font));
1491 printf("Bounding box TL=%g,%g BR=%g,%g\n",
1492 TL.x, TL.y, BR.x, BR.y );
1493 /* printf("Text box = %gx%g\n", bbox_width, bbox_height); */
1494 /* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
1495 printf("Pointsize = %g\n", pointsize);
1500 * Obtain font metrics if required
1503 if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER) ||
1504 (WMF_TEXT_UNDERLINE(font)) || (WMF_TEXT_STRIKEOUT(font)))
1507 *image = ddata->image;
1512 draw_info=ddata->draw_info;
1513 draw_info->font=WMF_FONT_PSNAME(font);
1514 draw_info->pointsize = pointsize;
1515 draw_info->text=draw_text->str;
1517 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
1519 /* Center the text if it is not yet centered and should be */
1520 if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER))
1523 text_width = metrics.width * (ddata->scale_y / ddata->scale_x);
1525 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
1526 point.x -= text_width / 2;
1528 point.x += bbox_width / 2 - text_width / 2;
1532 draw_info->font=NULL;
1533 draw_info->text=NULL;
1536 /* Set text background color */
1537 if (draw_text->flags & ETO_OPAQUE)
1539 /* Draw bounding-box background color (META_EXTTEXTOUT mode) */
1540 draw_stroke_color_string(WmfDrawingWand,"none");
1541 draw_fill_color_rgb(API,WMF_DC_BACKGROUND(draw_text->dc));
1542 DrawRectangle(WmfDrawingWand,
1543 XC(draw_text->TL.x),YC(draw_text->TL.y),
1544 XC(draw_text->BR.x),YC(draw_text->BR.y));
1545 draw_fill_color_string(WmfDrawingWand,"none");
1549 /* Set text undercolor */
1550 if (WMF_DC_OPAQUE(draw_text->dc))
1553 *box = WMF_DC_BACKGROUND(draw_text->dc);
1558 under_color=NewPixelWand();
1559 PixelSetRedQuantum(under_color,ScaleCharToQuantum(box->r));
1560 PixelSetGreenQuantum(under_color,ScaleCharToQuantum(box->g));
1561 PixelSetBlueQuantum(under_color,ScaleCharToQuantum(box->b));
1562 PixelSetAlphaQuantum(under_color,OpaqueAlpha);
1563 DrawSetTextUnderColor(WmfDrawingWand,under_color);
1564 under_color=DestroyPixelWand(under_color);
1567 draw_under_color_string(WmfDrawingWand,"none");
1570 /* Set text clipping (META_EXTTEXTOUT mode) */
1571 if ( draw_text->flags & ETO_CLIPPED)
1575 /* Set stroke color */
1576 draw_stroke_color_string(WmfDrawingWand,"none");
1578 /* Set fill color */
1579 draw_fill_color_rgb(API,WMF_DC_TEXTCOLOR(draw_text->dc));
1581 /* Output font size */
1582 (void) DrawSetFontSize(WmfDrawingWand,pointsize);
1584 /* Output Postscript font name */
1585 (void) DrawSetFont(WmfDrawingWand, WMF_FONT_PSNAME(font));
1587 /* Translate coordinates so target is 0,0 */
1588 DrawTranslate(WmfDrawingWand, XC(point.x), YC(point.y));
1590 /* Transform horizontal scale to draw text at 1:1 ratio */
1591 DrawScale(WmfDrawingWand, ddata->scale_y / ddata->scale_x, 1.0);
1593 /* Apply rotation */
1594 /* ImageMagick's drawing rotation is clockwise from horizontal
1595 while WMF drawing rotation is counterclockwise from horizontal */
1596 angle = fabs(RadiansToDegrees(2 * MagickPI - WMF_TEXT_ANGLE(font)));
1600 DrawRotate(WmfDrawingWand, angle);
1608 DrawAnnotation(WmfDrawingWand, 0, 0, (unsigned char*)draw_text->str);
1610 /* Underline text the Windows way (at the bottom) */
1611 if (WMF_TEXT_UNDERLINE(font))
1617 ulBR, /* bottom right of underline rectangle */
1618 ulTL; /* top left of underline rectangle */
1620 line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
1621 if (metrics.underline_thickness < 1.5)
1622 line_height *= 0.55;
1624 ulTL.y = fabs(metrics.descent) - line_height;
1625 ulBR.x = metrics.width;
1626 ulBR.y = fabs(metrics.descent);
1628 DrawRectangle(WmfDrawingWand,
1629 XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
1632 /* Strikeout text the Windows way */
1633 if (WMF_TEXT_STRIKEOUT(font))
1638 ulBR, /* bottom right of strikeout rectangle */
1639 ulTL; /* top left of strikeout rectangle */
1641 line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
1643 if (metrics.underline_thickness < 2.0)
1644 line_height *= 0.55;
1646 ulTL.y = -(((double) metrics.ascent) / 2 + line_height / 2);
1647 ulBR.x = metrics.width;
1648 ulBR.y = -(((double) metrics.ascent) / 2 - line_height / 2);
1650 DrawRectangle(WmfDrawingWand,
1651 XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
1655 /* Restore graphic wand */
1656 (void) PopDrawingWand(WmfDrawingWand);
1659 (void) PushDrawingWand(WmfDrawingWand);
1660 draw_stroke_color_string(WmfDrawingWand,"red");
1661 draw_fill_color_string(WmfDrawingWand,"none");
1662 DrawRectangle(WmfDrawingWand,
1664 XC(BR.x), YC(BR.y));
1665 draw_stroke_color_string(WmfDrawingWand,"none");
1666 (void) PopDrawingWand(WmfDrawingWand);
1671 static void ipa_udata_init(wmfAPI * API, wmfUserData_t * userdata)
1675 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1679 static void ipa_udata_copy(wmfAPI * API, wmfUserData_t * userdata)
1683 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1687 static void ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata)
1691 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1695 static void ipa_udata_free(wmfAPI * API, wmfUserData_t * userdata)
1699 /* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1703 static inline double MagickMin(const double x,const double y)
1710 static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply)
1713 *ddata = WMF_MAGICK_GetData(API);
1716 *brush = WMF_DC_BRUSH(dc);
1718 /* Set polygon fill rule */
1719 switch (WMF_DC_POLYFILL(dc)) /* Is this correct ?? */
1722 DrawSetClipRule(WmfDrawingWand,NonZeroRule);
1727 DrawSetClipRule(WmfDrawingWand,EvenOddRule);
1731 switch (WMF_BRUSH_STYLE(brush))
1733 case BS_SOLID /* 0 */:
1734 /* WMF_BRUSH_COLOR specifies brush color, WMF_BRUSH_HATCH
1737 if ( brush_apply == BrushApplyStroke )
1738 draw_stroke_color_rgb(API,WMF_BRUSH_COLOR(brush));
1740 draw_fill_color_rgb(API,WMF_BRUSH_COLOR(brush));
1743 case BS_HOLLOW /* 1 */: /* BS_HOLLOW & BS_NULL share enum */
1744 /* WMF_BRUSH_COLOR and WMF_BRUSH_HATCH ignored */
1746 if ( brush_apply == BrushApplyStroke )
1747 draw_stroke_color_string(WmfDrawingWand,"none");
1749 draw_fill_color_string(WmfDrawingWand,"none");
1752 case BS_HATCHED /* 2 */:
1753 /* WMF_BRUSH_COLOR specifies the hatch color, WMF_BRUSH_HATCH
1754 specifies the hatch brush style. If WMF_DC_OPAQUE, then
1755 WMF_DC_BACKGROUND specifies hatch background color. */
1757 DrawPushDefs(WmfDrawingWand);
1758 draw_pattern_push(API, ddata->pattern_id, 8, 8);
1759 (void) PushDrawingWand(WmfDrawingWand);
1761 if (WMF_DC_OPAQUE(dc))
1763 if ( brush_apply == BrushApplyStroke )
1764 draw_stroke_color_rgb(API,WMF_DC_BACKGROUND(dc));
1766 draw_fill_color_rgb(API,WMF_DC_BACKGROUND(dc));
1768 DrawRectangle(WmfDrawingWand, 0, 0, 7, 7 );
1771 DrawSetStrokeAntialias(WmfDrawingWand, MagickFalse);
1772 DrawSetStrokeWidth(WmfDrawingWand, 1);
1774 draw_stroke_color_rgb(API,WMF_BRUSH_COLOR(brush));
1776 switch ((unsigned int) WMF_BRUSH_HATCH(brush))
1779 case HS_HORIZONTAL: /* ----- */
1781 DrawLine(WmfDrawingWand, 0, 3, 7,3);
1784 case HS_VERTICAL: /* ||||| */
1786 DrawLine(WmfDrawingWand, 3, 0, 3, 7);
1789 case HS_FDIAGONAL: /* \\\\\ */
1791 DrawLine(WmfDrawingWand, 0, 0, 7, 7);
1794 case HS_BDIAGONAL: /* / */
1796 DrawLine(WmfDrawingWand, 0, 7, 7, 0 );
1799 case HS_CROSS: /* +++++ */
1801 DrawLine(WmfDrawingWand, 0, 3, 7, 3 );
1802 DrawLine(WmfDrawingWand, 3, 0, 3, 7 );
1805 case HS_DIAGCROSS: /* xxxxx */
1807 DrawLine(WmfDrawingWand, 0, 0, 7, 7 );
1808 DrawLine(WmfDrawingWand, 0, 7, 7, 0 );
1813 printf("util_set_brush: unexpected brush hatch enumeration %u\n",
1814 (unsigned int)WMF_BRUSH_HATCH(brush));
1817 (void) PopDrawingWand(WmfDrawingWand);
1818 (void) DrawPopPattern(WmfDrawingWand);
1819 DrawPopDefs(WmfDrawingWand);
1824 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
1826 if (brush_apply == BrushApplyStroke )
1827 (void) DrawSetStrokePatternURL(WmfDrawingWand,pattern_id);
1829 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
1830 ++ddata->pattern_id;
1834 case BS_PATTERN /* 3 */:
1835 /* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides handle to
1838 printf("util_set_brush: BS_PATTERN not supported\n");
1841 case BS_INDEXED /* 4 */:
1843 printf("util_set_brush: BS_INDEXED not supported\n");
1846 case BS_DIBPATTERN /* 5 */:
1849 *brush_bmp = WMF_BRUSH_BITMAP(brush);
1851 if (brush_bmp && brush_bmp->data != 0)
1865 GetExceptionInfo(&exception);
1867 image = (Image*)brush_bmp->data;
1869 mode = CopyCompositeOp; /* Default is copy */
1870 switch (WMF_DC_ROP(dc))
1872 /* Binary raster ops */
1874 printf("util_set_brush: R2_BLACK ROP2 mode not supported!\n");
1876 case R2_NOTMERGEPEN:
1877 printf("util_set_brush: R2_NOTMERGEPEN ROP2 mode not supported!\n");
1880 printf("util_set_brush R2_MASKNOTPEN ROP2 mode not supported!\n");
1883 printf("util_set_brush: R2_NOTCOPYPEN ROP2 mode not supported!\n");
1886 printf("util_set_brush: R2_MASKPENNOT ROP2 mode not supported!\n");
1889 printf("util_set_brush: R2_NOT ROP2 mode not supported!\n");
1892 printf("util_set_brush: R2_XORPEN ROP2 mode not supported!\n");
1895 printf("util_set_brush: R2_NOTMASKPEN ROP2 mode not supported!\n");
1898 printf("util_set_brush: R2_MASKPEN ROP2 mode not supported!\n");
1901 printf("util_set_brush: R2_NOTXORPEN ROP2 mode not supported!\n");
1904 printf("util_set_brush: R2_NOP ROP2 mode not supported!\n");
1906 case R2_MERGENOTPEN:
1907 printf("util_set_brush: R2_MERGENOTPEN ROP2 mode not supported!\n");
1910 mode = CopyCompositeOp;
1912 case R2_MERGEPENNOT:
1913 printf("util_set_brush: R2_MERGEPENNOT ROP2 mode not supported!\n");
1916 printf("util_set_brush: R2_MERGEPEN ROP2 mode not supported!\n");
1919 printf("util_set_brush: R2_WHITE ROP2 mode not supported!\n");
1923 printf("util_set_brush: unexpected ROP2 enumeration %u!\n",
1924 (unsigned int)WMF_DC_ROP(dc));
1928 DrawPushDefs(WmfDrawingWand);
1929 draw_pattern_push(API, ddata->pattern_id, brush_bmp->width,
1931 magick_wand=NewMagickWandFromImage(image);
1932 (void) DrawComposite(WmfDrawingWand,mode, 0, 0, brush_bmp->width,
1933 brush_bmp->height, magick_wand);
1934 magick_wand=DestroyMagickWand(magick_wand);
1935 (void) DrawPopPattern(WmfDrawingWand);
1936 DrawPopDefs(WmfDrawingWand);
1942 (void) FormatLocaleString(pattern_id,MaxTextExtent,"#brush_%lu",
1945 if ( brush_apply == BrushApplyStroke )
1946 (void) DrawSetStrokePatternURL(WmfDrawingWand,pattern_id);
1948 (void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
1949 ++ddata->pattern_id;
1953 printf("util_set_brush: no BMP image data!\n");
1957 case BS_DIBPATTERNPT /* 6 */:
1958 /* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides pointer to
1961 printf("util_set_brush: BS_DIBPATTERNPT not supported\n");
1964 case BS_PATTERN8X8 /* 7 */:
1966 printf("util_set_brush: BS_PATTERN8X8 not supported\n");
1969 case BS_DIBPATTERN8X8 /* 8 */:
1971 printf("util_set_brush: BS_DIBPATTERN8X8 not supported\n");
1980 static inline double MagickMax(const double x,const double y)
1987 static void util_set_pen(wmfAPI * API, wmfDC * dc)
1990 *ddata = WMF_MAGICK_GetData(API);
2003 pen = WMF_DC_PEN(dc);
2005 pen_width = (WMF_PEN_WIDTH(pen) + WMF_PEN_HEIGHT(pen)) / 2;
2007 /* Pixel width is inverse of pixel scale */
2008 pixel_width = (((double) 1 / (ddata->scale_x)) +
2009 ((double) 1 / (ddata->scale_y))) / 2;
2011 /* Don't allow pen_width to be much less than pixel_width in order
2012 to avoid dissapearing or spider-web lines */
2013 pen_width = MagickMax(pen_width, pixel_width*0.8);
2015 pen_style = (unsigned int) WMF_PEN_STYLE(pen);
2016 pen_type = (unsigned int) WMF_PEN_TYPE(pen);
2019 /* Pen style specified? */
2020 if (pen_style == PS_NULL)
2022 draw_stroke_color_string(WmfDrawingWand,"none");
2026 DrawSetStrokeAntialias(WmfDrawingWand, MagickTrue );
2027 DrawSetStrokeWidth(WmfDrawingWand, (unsigned long) MagickMax(0.0, pen_width));
2033 switch ((unsigned int) WMF_PEN_ENDCAP(pen))
2035 case PS_ENDCAP_SQUARE:
2036 linecap = SquareCap;
2038 case PS_ENDCAP_ROUND:
2041 case PS_ENDCAP_FLAT:
2046 DrawSetStrokeLineCap(WmfDrawingWand, linecap);
2053 switch ((unsigned int) WMF_PEN_JOIN(pen))
2056 linejoin = BevelJoin;
2059 linejoin = RoundJoin;
2063 linejoin = MiterJoin;
2066 DrawSetStrokeLineJoin(WmfDrawingWand,linejoin);
2075 case PS_DASH: /* ------- */
2078 dasharray[0] = pixel_width * 18;
2079 dasharray[1] = pixel_width * 7;
2082 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2083 (void) DrawSetStrokeDashArray(WmfDrawingWand,2,dasharray);
2087 case PS_DOT: /* ....... */
2090 dasharray[0] = pixel_width * 3;
2091 dasharray[1] = pixel_width * 3;
2094 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2095 (void) DrawSetStrokeDashArray(WmfDrawingWand,2,dasharray);
2098 case PS_DASHDOT: /* _._._._ */
2100 /* Pattern 9,6,3,6 */
2101 dasharray[0] = pixel_width * 9;
2102 dasharray[1] = pixel_width * 6;
2103 dasharray[2] = pixel_width * 3;
2104 dasharray[3] = pixel_width * 6;
2107 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2108 (void) DrawSetStrokeDashArray(WmfDrawingWand,4,dasharray);
2111 case PS_DASHDOTDOT: /* _.._.._ */
2113 /* Pattern 9,3,3,3,3,3 */
2114 dasharray[0] = pixel_width * 9;
2115 dasharray[1] = pixel_width * 3;
2116 dasharray[2] = pixel_width * 3;
2117 dasharray[3] = pixel_width * 3;
2118 dasharray[4] = pixel_width * 3;
2119 dasharray[5] = pixel_width * 3;
2122 DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
2123 (void) DrawSetStrokeDashArray(WmfDrawingWand,6,dasharray);
2126 case PS_INSIDEFRAME: /* There is nothing to do in this case... */
2130 (void) DrawSetStrokeDashArray(WmfDrawingWand,0,(double *)NULL);
2136 draw_stroke_color_rgb(API,WMF_PEN_COLOR(pen));
2139 /* Estimate font pointsize based on Windows font parameters */
2140 static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height, ExceptionInfo *exception)
2143 *ddata = WMF_MAGICK_GetData(API);
2146 *image = ddata->image;
2157 draw_info=ddata->draw_info;
2158 if (draw_info == (const DrawInfo *) NULL)
2161 draw_info->font=WMF_FONT_PSNAME(font);
2162 draw_info->pointsize=font_height;
2163 draw_info->text=str;
2165 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2168 if (strlen(str) == 1)
2170 pointsize = (font_height *
2171 ( font_height / (metrics.ascent + fabs(metrics.descent))));
2172 draw_info->pointsize = pointsize;
2173 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2174 pointsize *= (font_height / ( metrics.ascent + fabs(metrics.descent)));
2178 pointsize = (font_height * (font_height / (metrics.height)));
2179 draw_info->pointsize = pointsize;
2180 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2181 pointsize *= (font_height / metrics.height);
2185 draw_info.pointsize = pointsize;
2186 if (GetTypeMetrics(image, &draw_info, &metrics, exception) != MagickFalse)
2187 pointsize *= (font_height / (metrics.ascent + fabs(metrics.descent)));
2188 pointsize *= 1.114286; /* Magic number computed through trial and error */
2192 draw_info->font=NULL;
2193 draw_info->text=NULL;
2195 printf("String = %s\n", str);
2196 printf("Font = %s\n", WMF_FONT_PSNAME(font));
2197 printf("lfHeight = %g\n", font_height);
2198 printf("bounds = %g,%g %g,%g\n", metrics.bounds.x1, metrics.bounds.y1,
2199 metrics.bounds.x2,metrics.bounds.y2);
2200 printf("ascent = %g\n", metrics.ascent);
2201 printf("descent = %g\n", metrics.descent);
2202 printf("height = %g\n", metrics.height);
2203 printf("Pointsize = %g\n", pointsize);
2206 return floor(pointsize);
2209 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
2210 /* Estimate weight based on font name */
2212 static int util_font_weight( const char* font )
2218 if ((strstr(font,"Normal") || strstr(font,"Regular")))
2220 else if ( strstr(font,"Bold") )
2223 if ((strstr(font,"Semi") || strstr(font,"Demi")))
2225 if ( (strstr(font,"Extra") || strstr(font,"Ultra")))
2228 else if ( strstr(font,"Light") )
2231 if ( (strstr(font,"Extra") || strstr(font,"Ultra")))
2234 else if ((strstr(font,"Heavy") || strstr(font,"Black")))
2236 else if ( strstr(font,"Thin") )
2243 * Returns width of string in points, assuming (unstretched) font size of 1pt
2244 * (similar to wmf_ipa_font_stringwidth)
2246 * This extremely odd at best, particularly since player/meta.h has access
2247 * to the corrected font_height (as drawtext.font_height) when it invokes the
2248 * stringwidth callback. It should be possible to compute the real stringwidth!
2250 static float lite_font_stringwidth( wmfAPI* API, wmfFont* font, char* str)
2253 *ddata = WMF_MAGICK_GetData(API);
2256 *image = ddata->image;
2275 orig_resolution_units;
2277 orig_x_resolution = image->resolution.x;
2278 orig_y_resolution = image->resolution.y;
2279 orig_resolution_units = image->units;
2281 draw_info=ddata->draw_info;
2282 if (draw_info == (const DrawInfo *) NULL)
2285 draw_info->font=WMF_FONT_PSNAME(font);
2286 draw_info->pointsize=12;
2287 draw_info->text=str;
2289 image->resolution.x = 72;
2290 image->resolution.y = 72;
2291 image->units = PixelsPerInchResolution;
2293 exception=ddata->exception;
2294 if (GetTypeMetrics(image, draw_info, &metrics, exception) != MagickFalse)
2295 stringwidth = ((metrics.width * 72)/(image->resolution.x * draw_info->pointsize)); /* *0.916348; */
2297 draw_info->font=NULL;
2298 draw_info->text=NULL;
2301 printf("\nlite_font_stringwidth\n");
2302 printf("string = \"%s\"\n", str);
2303 printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
2304 printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
2305 printf("stringwidth = %g\n", stringwidth);
2306 /* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
2307 /* printf("WMF_FONT_WIDTH = %i\n", (int)WMF_FONT_WIDTH(font)); */
2311 image->resolution.x = orig_x_resolution;
2312 image->resolution.y = orig_y_resolution;
2313 image->units = orig_resolution_units;
2318 /* Map font (similar to wmf_ipa_font_map) */
2320 /* Mappings to Postscript fonts: family, normal, italic, bold, bolditalic */
2321 static wmfFontMap WMFFontMap[] = {
2322 { (char *) "Courier", (char *) "Courier",
2323 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2324 (char *) "Courier-BoldOblique" },
2325 { (char *) "Helvetica", (char *) "Helvetica",
2326 (char *) "Helvetica-Oblique", (char *) "Helvetica-Bold",
2327 (char *) "Helvetica-BoldOblique" },
2328 { (char *) "Modern", (char *) "Courier",
2329 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2330 (char *) "Courier-BoldOblique" },
2331 { (char *) "Monotype Corsiva", (char *) "Courier",
2332 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2333 (char *) "Courier-BoldOblique" },
2334 { (char *) "News Gothic", (char *) "Helvetica",
2335 (char *) "Helvetica-Oblique", (char *) "Helvetica-Bold",
2336 (char *) "Helvetica-BoldOblique" },
2337 { (char *) "Symbol", (char *) "Symbol",
2338 (char *) "Symbol", (char *) "Symbol",
2339 (char *) "Symbol" },
2340 { (char *) "System", (char *) "Courier",
2341 (char *) "Courier-Oblique", (char *) "Courier-Bold",
2342 (char *) "Courier-BoldOblique" },
2343 { (char *) "Times", (char *) "Times-Roman",
2344 (char *) "Times-Italic", (char *) "Times-Bold",
2345 (char *) "Times-BoldItalic" },
2346 { (char *) NULL, (char *) NULL,
2347 (char *) NULL, (char *) NULL,
2352 /* Mapping between base name and Ghostscript family name */
2353 static wmfMapping SubFontMap[] =
2355 { (char *) "Arial", (char *) "Helvetica", FT_ENCODING_NONE },
2356 { (char *) "Courier", (char *) "Courier", FT_ENCODING_NONE },
2357 { (char *) "Fixed", (char *) "Courier", FT_ENCODING_NONE },
2358 { (char *) "Helvetica", (char *) "Helvetica", FT_ENCODING_NONE },
2359 { (char *) "Sans", (char *) "Helvetica", FT_ENCODING_NONE },
2360 { (char *) "Sym", (char *) "Symbol", FT_ENCODING_NONE },
2361 { (char *) "Terminal", (char *) "Courier", FT_ENCODING_NONE },
2362 { (char *) "Times", (char *) "Times", FT_ENCODING_NONE },
2363 { (char *) "Wingdings", (char *) "Symbol", FT_ENCODING_NONE },
2364 { (char *) NULL, (char *) NULL, FT_ENCODING_NONE }
2367 static void lite_font_map( wmfAPI* API, wmfFont* font)
2376 *ddata = WMF_MAGICK_GetData(API);
2391 font_data = (wmfFontData*)API->font_data;
2392 font->user_data = font_data->user_data;
2393 magick_font = (wmf_magick_font_t*)font->user_data;
2394 wmf_font_name = WMF_FONT_NAME(font);
2396 if (magick_font->ps_name != (char *) NULL)
2397 magick_font->ps_name=DestroyString(magick_font->ps_name);
2399 exception=ddata->exception;
2400 type_info_base=GetTypeInfo("*",exception);
2401 if (type_info_base == 0)
2404 /* Certain short-hand font names are not the proper Windows names
2405 and should be promoted to the proper names */
2406 if (LocaleCompare(wmf_font_name,"Times") == 0)
2407 wmf_font_name = "Times New Roman";
2408 else if (LocaleCompare(wmf_font_name,"Courier") == 0)
2409 wmf_font_name = "Courier New";
2411 /* Look for a family-based best-match */
2412 if (!magick_font->ps_name)
2417 if (WMF_FONT_WEIGHT(font) == 0)
2418 target_weight = 400;
2420 target_weight = WMF_FONT_WEIGHT(font);
2421 type_info=GetTypeInfoByFamily(wmf_font_name,AnyStyle,AnyStretch,
2422 target_weight,exception);
2423 if (type_info == (const TypeInfo *) NULL)
2424 type_info=GetTypeInfoByFamily(wmf_font_name,AnyStyle,AnyStretch,0,
2426 if (type_info != (const TypeInfo *) NULL)
2427 CloneString(&magick_font->ps_name,type_info->name);
2430 /* Now let's try simple substitution mappings from WMFFontMap */
2431 if (!magick_font->ps_name)
2434 target[MaxTextExtent];
2437 target_weight = 400,
2438 want_italic = MagickFalse,
2439 want_bold = MagickFalse,
2442 if ( WMF_FONT_WEIGHT(font) != 0 )
2443 target_weight = WMF_FONT_WEIGHT(font);
2445 if ( (target_weight > 550) || ((strstr(wmf_font_name,"Bold") ||
2446 strstr(wmf_font_name,"Heavy") ||
2447 strstr(wmf_font_name,"Black"))) )
2448 want_bold = MagickTrue;
2450 if ( (WMF_FONT_ITALIC(font)) || ((strstr(wmf_font_name,"Italic") ||
2451 strstr(wmf_font_name,"Oblique"))) )
2452 want_italic = MagickTrue;
2454 (void) CopyMagickString(target,"Times",MaxTextExtent);
2455 for( i=0; SubFontMap[i].name != NULL; i++ )
2457 if (LocaleCompare(wmf_font_name, SubFontMap[i].name) == 0)
2459 (void) CopyMagickString(target,SubFontMap[i].mapping,
2465 for( i=0; WMFFontMap[i].name != NULL; i++ )
2467 if (LocaleNCompare(WMFFontMap[i].name,target,strlen(WMFFontMap[i].name)) == 0)
2469 if (want_bold && want_italic)
2470 CloneString(&magick_font->ps_name,WMFFontMap[i].bolditalic);
2471 else if (want_italic)
2472 CloneString(&magick_font->ps_name,WMFFontMap[i].italic);
2474 CloneString(&magick_font->ps_name,WMFFontMap[i].bold);
2476 CloneString(&magick_font->ps_name,WMFFontMap[i].normal);
2482 printf("\nlite_font_map\n");
2483 printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
2484 printf("WMF_FONT_WEIGHT = %i\n", WMF_FONT_WEIGHT(font));
2485 printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
2491 /* Initialize API font structures */
2492 static void lite_font_init( wmfAPI* API, wmfAPI_Options* options)
2500 /* Allocate wmfFontData data structure */
2501 API->font_data = wmf_malloc(API,sizeof(wmfFontData));
2505 font_data = (wmfFontData*)API->font_data;
2507 /* Assign function to map font (type wmfMap) */
2508 font_data->map = lite_font_map;
2510 /* Assign function to return string width in points (type wmfStringWidth) */
2511 font_data->stringwidth = lite_font_stringwidth;
2513 /* Assign user data, not used by libwmflite (type void*) */
2514 font_data->user_data = wmf_malloc(API,sizeof(wmf_magick_font_t));
2517 ((wmf_magick_font_t*)font_data->user_data)->ps_name = 0;
2518 ((wmf_magick_font_t*)font_data->user_data)->pointsize = 0;
2521 #endif /* MAGICKCORE_WMFLITE_DELEGATE */
2523 /* BLOB read byte */
2524 static int ipa_blob_read(void* wand)
2526 return ReadBlobByte((Image*)wand);
2530 static int ipa_blob_seek(void* wand,long position)
2532 return (int)SeekBlob((Image*)wand,(MagickOffsetType) position,SEEK_SET);
2536 static long ipa_blob_tell(void* wand)
2538 return (long)TellBlob((Image*)wand);
2541 static Image *ReadWMFImage(const ImageInfo *image_info,
2542 ExceptionInfo * exception)
2563 wmf_options_flags = 0;
2580 image = AcquireImage(image_info,exception);
2581 if (OpenBlob(image_info,image,ReadBinaryBlobMode,exception) == MagickFalse)
2583 if (image->debug != MagickFalse)
2585 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2586 " OpenBlob failed");
2587 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2588 "leave ReadWMFImage()");
2590 image=DestroyImageList(image);
2591 return((Image *) NULL);
2599 /* Register callbacks */
2600 wmf_options_flags |= WMF_OPT_FUNCTION;
2601 (void) ResetMagickMemory(&wmf_api_options, 0, sizeof(wmf_api_options));
2602 wmf_api_options.function = ipa_functions;
2604 /* Ignore non-fatal errors */
2605 wmf_options_flags |= WMF_OPT_IGNORE_NONFATAL;
2607 wmf_error = wmf_api_create(&API, wmf_options_flags, &wmf_api_options);
2608 if (wmf_error != wmf_E_None)
2611 wmf_api_destroy(API);
2612 if (image->debug != MagickFalse)
2614 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2615 " wmf_api_create failed");
2616 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2617 "leave ReadWMFImage()");
2619 ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
2622 /* Register progress monitor */
2623 wmf_status_function(API,image,magick_progress_callback);
2625 ddata = WMF_MAGICK_GetData(API);
2626 ddata->image = image;
2627 ddata->image_info = image_info;
2628 ddata->draw_info = CloneDrawInfo((const ImageInfo *) NULL, (const DrawInfo *) NULL);
2629 ddata->exception = exception;
2630 RelinquishMagickMemory(ddata->draw_info->font);
2631 RelinquishMagickMemory(ddata->draw_info->text);
2634 #if defined(MAGICKCORE_WMFLITE_DELEGATE)
2635 /* Must initialize font subystem for WMFlite interface */
2636 lite_font_init (API,&wmf_api_options); /* similar to wmf_ipa_font_init in src/font.c */
2637 /* wmf_arg_fontdirs (API,options); */ /* similar to wmf_arg_fontdirs in src/wmf.c */
2642 * Open BLOB input via libwmf API
2645 wmf_error = wmf_bbuf_input(API,ipa_blob_read,ipa_blob_seek,
2646 ipa_blob_tell,(void*)image);
2647 if (wmf_error != wmf_E_None)
2649 wmf_api_destroy(API);
2650 if (image->debug != MagickFalse)
2652 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2653 " wmf_bbuf_input failed");
2654 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2655 "leave ReadWMFImage()");
2657 ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
2659 image=DestroyImageList(image);
2660 return((Image *) NULL);
2667 if (image->debug != MagickFalse)
2668 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2669 " Scanning WMF to obtain bounding box");
2670 wmf_error = wmf_scan(API, 0, &bbox);
2671 if (wmf_error != wmf_E_None)
2673 wmf_api_destroy(API);
2674 if (image->debug != MagickFalse)
2676 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2677 " wmf_scan failed with wmf_error %d", wmf_error);
2678 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2679 "leave ReadWMFImage()");
2681 ThrowReaderException(DelegateError,"FailedToScanFile");
2685 * Compute dimensions and scale factors
2691 /* User specified resolution */
2692 resolution_y=DefaultResolution;
2693 if (image->resolution.y > 0)
2695 resolution_y = image->resolution.y;
2696 if (image->units == PixelsPerCentimeterResolution)
2697 resolution_y *= CENTIMETERS_PER_INCH;
2700 resolution_x=DefaultResolution;
2701 if (image->resolution.x > 0)
2703 resolution_x = image->resolution.x;
2704 if (image->units == PixelsPerCentimeterResolution)
2705 resolution_x *= CENTIMETERS_PER_INCH;
2708 /* Obtain output size expressed in metafile units */
2709 wmf_error = wmf_size(API, &wmf_width, &wmf_height);
2710 if (wmf_error != wmf_E_None)
2712 wmf_api_destroy(API);
2713 if (image->debug != MagickFalse)
2715 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2716 " wmf_size failed with wmf_error %d", wmf_error);
2717 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2718 "leave ReadWMFImage()");
2720 ThrowReaderException(DelegateError,"FailedToComputeOutputSize");
2723 /* Obtain (or guess) metafile units */
2724 if ((API)->File->placeable)
2725 units_per_inch = (API)->File->pmh->Inch;
2726 else if ( (wmf_width*wmf_height) < 1024*1024)
2727 units_per_inch = POINTS_PER_INCH; /* MM_TEXT */
2729 units_per_inch = TWIPS_PER_INCH; /* MM_TWIPS */
2731 /* Calculate image width and height based on specified DPI
2733 image_width_inch = (double) wmf_width / units_per_inch;
2734 image_height_inch = (double) wmf_height / units_per_inch;
2735 image_width = image_width_inch * resolution_x;
2736 image_height = image_height_inch * resolution_y;
2738 /* Compute bounding box scale factors and origin translations
2740 * This all just a hack since libwmf does not currently seem to
2741 * provide the mapping between LOGICAL coordinates and DEVICE
2742 * coordinates. This mapping is necessary in order to know
2743 * where to place the logical bounding box within the image.
2747 bounding_width = bbox.BR.x - bbox.TL.x;
2748 bounding_height = bbox.BR.y - bbox.TL.y;
2750 ddata->scale_x = image_width/bounding_width;
2751 ddata->translate_x = 0-bbox.TL.x;
2754 /* Heuristic: guess that if the vertical coordinates mostly span
2755 negative values, then the image must be inverted. */
2756 if ( fabs(bbox.BR.y) > fabs(bbox.TL.y) )
2758 /* Normal (Origin at top left of image) */
2759 ddata->scale_y = (image_height/bounding_height);
2760 ddata->translate_y = 0-bbox.TL.y;
2764 /* Inverted (Origin at bottom left of image) */
2765 ddata->scale_y = (-image_height/bounding_height);
2766 ddata->translate_y = 0-bbox.BR.y;
2769 if (image->debug != MagickFalse)
2771 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2772 " Placeable metafile: %s",
2773 (API)->File->placeable ? "Yes" : "No");
2775 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2776 " Size in metafile units: %gx%g",wmf_width,wmf_height);
2777 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2778 " Metafile units/inch: %g",units_per_inch);
2779 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2780 " Size in inches: %gx%g",
2781 image_width_inch,image_height_inch);
2782 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2783 " Bounding Box: %g,%g %g,%g",
2784 bbox.TL.x, bbox.TL.y, bbox.BR.x, bbox.BR.y);
2785 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2786 " Bounding width x height: %gx%g",bounding_width,
2788 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2789 " Output resolution: %gx%g",resolution_x,resolution_y);
2790 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2791 " Image size: %gx%g",image_width,image_height);
2792 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2793 " Bounding box scale factor: %g,%g",ddata->scale_x,
2795 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2796 " Translation: %g,%g",
2797 ddata->translate_x, ddata->translate_y);
2803 typedef struct _wmfPlayer_t wmfPlayer_t;
2807 wmfBrush default_brush;
2808 wmfFont default_font;
2810 wmfDC* dc; /* current dc */
2816 #define WMF_ELICIT_DC(API) (((wmfPlayer_t*)((API)->player_data))->dc)
2818 dc = WMF_ELICIT_DC(API);
2820 printf("dc->Window.Ox = %d\n", dc->Window.Ox);
2821 printf("dc->Window.Oy = %d\n", dc->Window.Oy);
2822 printf("dc->Window.width = %d\n", dc->Window.width);
2823 printf("dc->Window.height = %d\n", dc->Window.height);
2824 printf("dc->pixel_width = %g\n", dc->pixel_width);
2825 printf("dc->pixel_height = %g\n", dc->pixel_height);
2826 #if defined(MAGICKCORE_WMFLITE_DELEGATE) /* Only in libwmf 0.3 */
2827 printf("dc->Ox = %.d\n", dc->Ox);
2828 printf("dc->Oy = %.d\n", dc->Oy);
2829 printf("dc->width = %.d\n", dc->width);
2830 printf("dc->height = %.d\n", dc->height);
2839 * Create canvas image
2842 image->rows=(unsigned long) ceil(image_height);
2843 image->columns=(unsigned long) ceil(image_width);
2845 if (image_info->ping != MagickFalse)
2847 wmf_api_destroy(API);
2848 (void) CloseBlob(image);
2849 if (image->debug != MagickFalse)
2850 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2851 "leave ReadWMFImage()");
2852 return(GetFirstImageInList(image));
2854 if (image->debug != MagickFalse)
2855 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2856 " Creating canvas image with size %ldx%ld",
2857 image->rows,image->columns);
2860 * Set solid background color
2863 image->background_color = image_info->background_color;
2864 if (image->background_color.alpha != OpaqueAlpha)
2865 image->matte = MagickTrue;
2866 (void) SetImageBackgroundColor(image,exception);
2869 * Play file to generate Vector drawing commands
2873 if (image->debug != MagickFalse)
2874 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2875 " Playing WMF to prepare vectors");
2877 wmf_error = wmf_play(API, 0, &bbox);
2878 if (wmf_error != wmf_E_None)
2880 wmf_api_destroy(API);
2881 if (image->debug != MagickFalse)
2883 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2884 " Playing WMF failed with wmf_error %d", wmf_error);
2885 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2886 "leave ReadWMFImage()");
2888 ThrowReaderException(DelegateError,"FailedToRenderFile");
2892 * Scribble on canvas image
2896 if (image->debug != MagickFalse)
2897 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
2898 " Rendering WMF vectors");
2899 DrawRender(ddata->draw_wand);
2901 if (image->debug != MagickFalse)
2902 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
2904 /* Cleanup allocated data */
2905 wmf_api_destroy(API);
2906 (void) CloseBlob(image);
2914 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2918 % R e g i s t e r W M F I m a g e %
2922 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2924 % RegisterWMFImage() adds attributes for the WMF image format to
2925 % the list of supported formats. The attributes include the image format
2926 % tag, a method to read and/or write the format, whether the format
2927 % supports the saving of more than one frame to the same file or blob,
2928 % whether the format supports native in-memory I/O, and a brief
2929 % description of the format.
2931 % The format of the RegisterWMFImage method is:
2933 % size_t RegisterWMFImage(void)
2936 ModuleExport size_t RegisterWMFImage(void)
2941 entry = SetMagickInfo("WMZ");
2942 #if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
2943 entry->decoder=ReadWMFImage;
2945 entry->description=ConstantString("Compressed Windows Meta File");
2946 entry->module=ConstantString("WMZ");
2947 entry->seekable_stream=MagickTrue;
2948 (void) RegisterMagickInfo(entry);
2949 entry=SetMagickInfo("WMF");
2950 #if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
2951 entry->decoder=ReadWMFImage;
2953 entry->description=ConstantString("Windows Meta File");
2954 entry->module=ConstantString("WMF");
2955 (void) RegisterMagickInfo(entry);
2956 return(MagickImageCoderSignature);
2960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2964 % U n r e g i s t e r W M F I m a g e %
2968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2970 % UnregisterWMFImage() removes format registrations made by the
2971 % WMF module from the list of supported formats.
2973 % The format of the UnregisterWMFImage method is:
2975 % UnregisterWMFImage(void)
2978 ModuleExport void UnregisterWMFImage(void)
2980 (void) UnregisterMagickInfo("WMZ");
2981 (void) UnregisterMagickInfo("WMF");