68
63
#include "magick/module.h"
69
64
#include "wand/MagickWand.h"
71
#if defined(MAGICKCORE_WMF_DELEGATE) || defined(MAGICKCORE_WMFLITE_DELEGATE)
73
#define ERR(API) ((API)->err != wmf_E_None)
74
#define XC(x) ((double) x)
75
#define YC(y) ((double) y)
78
# define M_PI MagickPI
81
#if defined(MAGICKCORE_HAVE_FT2BUILD_H)
82
# include <ft2build.h>
85
#include "libwmf/fund.h"
86
#include "libwmf/types.h"
66
#if defined(MAGICKCORE_WMF_DELEGATE)
87
67
#include "libwmf/api.h"
104
/* The following additinal undefs were required for MinGW */
107
#undef PS_ENDCAP_ROUND
108
#undef PS_ENDCAP_SQUARE
109
#undef PS_ENDCAP_FLAT
110
#undef PS_ENDCAP_MASK
117
#undef STRETCH_ANDSCANS
118
#undef STRETCH_ORSCANS
119
#undef STRETCH_DELETESCANS
120
#undef STRETCH_HALFTONE
123
#undef ETO_GLYPH_INDEX
124
#undef ETO_RTLREADING
126
#include "libwmf/defs.h"
127
#include "libwmf/ipa.h"
128
#include "libwmf/color.h"
129
#include "libwmf/macro.h"
131
/* Unit conversions */
132
#define TWIPS_PER_INCH 1440
133
#define CENTIMETERS_PER_INCH 2.54
134
#define POINTS_PER_INCH 72
136
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
137
# define wmf_api_create(api,flags,options) wmf_lite_create(api,flags,options)
138
# define wmf_api_destroy(api) wmf_lite_destroy(api)
139
# undef WMF_FONT_PSNAME
140
# define WMF_FONT_PSNAME(F) ((F)->user_data ? ((wmf_magick_font_t*) (F)->user_data)->ps_name : 0)
142
typedef struct _wmf_magick_font_t wmf_magick_font_t;
144
struct _wmf_magick_font_t
152
typedef struct _wmf_magick_t wmf_magick_t;
160
/* Scale and translation factors */
172
/* ImageMagick image */
202
#define WMF_MAGICK_GetData(Z) ((wmf_magick_t*)((Z)->device_data))
203
#define WMF_MAGICK_GetFontData(Z) \
204
((wmf_magick_font_t*)((wmfFontData *)Z->font_data)->user_data)
206
#define WmfDrawingWand (((wmf_magick_t*)((API)->device_data))->draw_wand)
208
/* Enum to control whether util_set_brush applies brush to fill or
217
/* Enum to specify arc type */
220
magick_arc_ellipse = 0,
227
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
228
static void lite_font_init (wmfAPI* API, wmfAPI_Options* options);
229
static void lite_font_map(wmfAPI* API,wmfFont* font);
230
static float lite_font_stringwidth(wmfAPI* API, wmfFont* font, char* str);
233
static void draw_fill_color_rgb(wmfAPI* API, const wmfRGB* rgb);
234
static void draw_stroke_color_rgb(wmfAPI* API, const wmfRGB* rgb);
235
static void draw_pattern_push(wmfAPI* API, unsigned long id, unsigned long columns, unsigned long rows);
236
static int ipa_blob_read(void* wand);
237
static int ipa_blob_seek(void* wand,long position);
238
static long ipa_blob_tell(void* wand);
239
static void ipa_bmp_draw(wmfAPI * API, wmfBMP_Draw_t * bmp_draw);
240
static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp);
241
static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read);
242
static void ipa_device_begin(wmfAPI * API);
243
static void ipa_device_close(wmfAPI * API);
244
static void ipa_device_end(wmfAPI * API);
245
static void ipa_device_open(wmfAPI * API);
246
static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc);
247
static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc);
248
static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc);
249
static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line);
250
static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc);
251
static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel);
252
static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * poly_line);
253
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
254
static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon);
256
static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect);
257
static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text);
258
static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood);
259
static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood);
260
static void ipa_functions(wmfAPI * API);
261
static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * poly_line);
262
static void ipa_region_clip(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
263
static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
264
static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect);
265
static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw);
266
static void ipa_udata_copy(wmfAPI * API, wmfUserData_t * userdata);
267
static void ipa_udata_free(wmfAPI * API, wmfUserData_t * userdata);
268
static void ipa_udata_init(wmfAPI * API, wmfUserData_t * userdata);
269
static void ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata);
270
static int magick_progress_callback(void* wand,float quantum);
271
static void util_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc,magick_arc_t finish);
272
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
273
/*static int util_font_weight( const char* font );*/
275
static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height);
276
static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply);
277
static void util_set_pen(wmfAPI * API, wmfDC * dc);
279
/* Progress callback */
280
int magick_progress_callback(void *context,float quantum)
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];
285
129
MagickBooleanType
294
image=(Image *) context;
295
assert(image->signature == MagickSignature);
296
offset=(MagickOffsetType) floor((double) (100.0*quantum));
298
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
300
return(status == MagickTrue ? 0 : 1);
304
static void draw_fill_color_string(DrawingWand *drawing_wand,const char *color)
309
fill_color=NewPixelWand();
310
PixelSetColor(fill_color,color);
311
DrawSetFillColor(drawing_wand,fill_color);
312
fill_color=DestroyPixelWand(fill_color);
314
static void draw_fill_color_rgb( wmfAPI* API, const wmfRGB* rgb )
319
fill_color=NewPixelWand();
320
PixelSetRedQuantum(fill_color,ScaleCharToQuantum(rgb->r));
321
PixelSetGreenQuantum(fill_color,ScaleCharToQuantum(rgb->g));
322
PixelSetBlueQuantum(fill_color,ScaleCharToQuantum(rgb->b));
323
PixelSetOpacityQuantum(fill_color,OpaqueOpacity);
324
DrawSetFillColor(WmfDrawingWand,fill_color);
325
fill_color=DestroyPixelWand(fill_color);
328
/* Set stroke color */
329
static void draw_stroke_color_string(DrawingWand *drawing_wand,const char *color)
334
stroke_color=NewPixelWand();
335
PixelSetColor(stroke_color,color);
336
DrawSetStrokeColor(drawing_wand,stroke_color);
337
stroke_color=DestroyPixelWand(stroke_color);
340
static void draw_stroke_color_rgb( wmfAPI* API, const wmfRGB* rgb )
345
stroke_color=NewPixelWand();
346
PixelSetRedQuantum(stroke_color,ScaleCharToQuantum(rgb->r));
347
PixelSetGreenQuantum(stroke_color,ScaleCharToQuantum(rgb->g));
348
PixelSetBlueQuantum(stroke_color,ScaleCharToQuantum(rgb->b));
349
PixelSetOpacityQuantum(stroke_color,OpaqueOpacity);
350
DrawSetStrokeColor(WmfDrawingWand,stroke_color);
351
stroke_color=DestroyPixelWand(stroke_color);
354
/* Set under color */
355
static void draw_under_color_string(DrawingWand *drawing_wand,const char *color)
360
under_color=NewPixelWand();
361
PixelSetColor(under_color,color);
362
DrawSetTextUnderColor(drawing_wand,under_color);
363
under_color=DestroyPixelWand(under_color);
366
static void draw_pattern_push( wmfAPI* API,
368
unsigned long columns,
374
(void) FormatMagickString(pattern_id,MaxTextExtent,"brush_%lu",id);
375
(void) DrawPushPattern(WmfDrawingWand,pattern_id,0,0,columns,rows);
378
/* Pattern/Bit BLT with raster operation (ROP) support. Invoked by
379
META_PATBLT, which is equivalent to Windows PatBlt() call, or by
380
META_DIBBITBLT which is equivalent to Windows BitBlt() call. */
382
/* The BitBlt function transfers pixels from a rectangular area in one
383
device wand called the 'source', to a rectangular area of the
384
same size in another device wand, called the 'destination'. */
386
static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw)
389
/* *brush = WMF_DC_BRUSH(rop_draw->dc); */
392
/* *brush_bmp = WMF_BRUSH_BITMAP(brush); */
394
if (TO_FILL(rop_draw) == 0)
397
/* Save graphic wand */
398
(void) PushDrawingWand(WmfDrawingWand);
400
/* FIXME: finish implementing (once we know what it is supposed to do!) */
403
struct _wmfROP_Draw_t
416
/* if (brush_bmp && brush_bmp->data != 0) */
417
/* printf("Have an image!\n"); */
419
switch (rop_draw->ROP) /* Ternary raster operations */
421
case SRCCOPY: /* dest = source */
422
printf("ipa_rop_draw SRCCOPY ROP mode not implemented\n");
424
case SRCPAINT: /* dest = source OR dest */
425
printf("ipa_rop_draw SRCPAINT ROP mode not implemented\n");
427
case SRCAND: /* dest = source AND dest */
428
printf("ipa_rop_draw SRCAND ROP mode not implemented\n");
430
case SRCINVERT: /* dest = source XOR dest */
431
printf("ipa_rop_draw SRCINVERT ROP mode not implemented\n");
433
case SRCERASE: /* dest = source AND (NOT dest) */
434
printf("ipa_rop_draw SRCERASE ROP mode not implemented\n");
436
case NOTSRCCOPY: /* dest = (NOT source) */
437
printf("ipa_rop_draw NOTSRCCOPY ROP mode not implemented\n");
439
case NOTSRCERASE: /* dest = (NOT src) AND (NOT dest) */
440
printf("ipa_rop_draw NOTSRCERASE ROP mode not implemented\n");
442
case MERGECOPY: /* dest = (source AND pattern) */
443
printf("ipa_rop_draw MERGECOPY ROP mode not implemented\n");
445
case MERGEPAINT: /* dest = (NOT source) OR dest */
446
printf("ipa_rop_draw MERGEPAINT ROP mode not implemented\n");
448
case PATCOPY: /* dest = pattern */
449
util_set_brush(API, rop_draw->dc, BrushApplyFill);
451
case PATPAINT: /* dest = DPSnoo */
452
printf("ipa_rop_draw PATPAINT ROP mode not implemented\n");
454
case PATINVERT: /* dest = pattern XOR dest */
455
printf("ipa_rop_draw PATINVERT ROP mode not implemented\n");
457
case DSTINVERT: /* dest = (NOT dest) */
458
printf("ipa_rop_draw DSTINVERT ROP mode not implemented\n");
460
case BLACKNESS: /* dest = BLACK */
461
draw_fill_color_string(WmfDrawingWand,"black");
463
case WHITENESS: /* dest = WHITE */
464
draw_fill_color_string(WmfDrawingWand,"white");
467
printf("ipa_rop_draw 0x%x ROP mode not implemented\n", rop_draw->ROP);
471
DrawRectangle(WmfDrawingWand,
472
XC(rop_draw->TL.x), YC(rop_draw->TL.y),
473
XC(rop_draw->BR.x), YC(rop_draw->BR.y));
475
/* Restore graphic wand */
476
(void) PopDrawingWand(WmfDrawingWand);
479
static void ipa_bmp_draw(wmfAPI *API, wmfBMP_Draw_t *bmp_draw)
482
*ddata = WMF_MAGICK_GetData(API);
500
if (bmp_draw->bmp.data == 0)
503
GetExceptionInfo(&exception);
504
image = (Image*)bmp_draw->bmp.data;
507
InheritException(&ddata->image->exception,&exception);
511
if (bmp_draw->crop.x || bmp_draw->crop.y ||
512
(bmp_draw->crop.w != bmp_draw->bmp.width) ||
513
(bmp_draw->crop.h != bmp_draw->bmp.height))
515
/* Image needs to be cropped */
522
crop_info.x = bmp_draw->crop.x;
523
crop_info.y = bmp_draw->crop.y;
524
crop_info.width = bmp_draw->crop.w;
525
crop_info.height = bmp_draw->crop.h;
527
crop_image = CropImage( image, &crop_info, &exception );
530
image=DestroyImageList(image);
532
bmp_draw->bmp.data = (void*)image;
535
InheritException(&ddata->image->exception,&exception);
538
QueryColorDatabase( "white", &white, &exception );
540
if ( ddata->image_info->texture ||
541
!(IsColorEqual(&ddata->image_info->background_color,&white)) ||
542
ddata->image_info->background_color.opacity != OpaqueOpacity )
548
Set image white background to transparent so that it may be
549
overlaid over non-white backgrounds.
551
QueryMagickColor( "white", &white, &exception );
552
TransparentPaintImage( image, &white, QuantumRange, MagickFalse );
555
width = fabs(bmp_draw->pixel_width * (double) bmp_draw->crop.w);
556
height = fabs(bmp_draw->pixel_height * (double) bmp_draw->crop.h);
557
magick_wand=NewMagickWandFromImage(image);
558
(void) DrawComposite(WmfDrawingWand, CopyCompositeOp,
559
XC(bmp_draw->pt.x) * ddata->scale_x, YC(bmp_draw->pt.y) * ddata->scale_y,
560
width * ddata->scale_x, height * ddata->scale_y, magick_wand);
561
magick_wand=DestroyMagickWand(magick_wand);
564
printf("bmp_draw->bmp.data = 0x%lx\n", (long)bmp_draw->bmp.data);
565
printf("registry id = %li\n", id);
566
/* printf("pixel_width = %g\n", bmp_draw->pixel_width); */
567
/* printf("pixel_height = %g\n", bmp_draw->pixel_height); */
568
printf("bmp_draw->bmp WxH = %ix%i\n", bmp_draw->bmp.width, bmp_draw->bmp.height);
569
printf("bmp_draw->crop WxH = %ix%i\n", bmp_draw->crop.w, bmp_draw->crop.h);
570
printf("bmp_draw->crop x,y = %i,%i\n", bmp_draw->crop.x, bmp_draw->crop.y);
571
printf("image size WxH = %lux%lu\n", image->columns, image->rows);
575
static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read) {
577
*ddata = WMF_MAGICK_GetData(API);
588
bmp_read->bmp.data = 0;
590
GetExceptionInfo(&exception);
592
image_info=CloneImageInfo((ImageInfo *) 0);
593
(void) CopyMagickString(image_info->magick,"DIB",MaxTextExtent);
594
if (bmp_read->width || bmp_read->height)
599
(void) FormatMagickString(size,MaxTextExtent,"%ux%u",bmp_read->width,
601
CloneString(&image_info->size,size);
604
printf("ipa_bmp_read: buffer=0x%lx length=%ld, width=%i, height=%i\n",
605
(long) bmp_read->buffer, bmp_read->length,
606
bmp_read->width, bmp_read->height);
608
image=BlobToImage(image_info, (const void *) bmp_read->buffer,
609
bmp_read->length, &exception);
610
image_info=DestroyImageInfo(image_info);
611
if (image == (Image *) NULL)
614
description[MaxTextExtent];
616
(void) FormatMagickString(description,MaxTextExtent,
617
"packed DIB at offset %ld",bmp_read->offset);
618
(void) ThrowMagickException(&ddata->image->exception,GetMagickModule(),
619
CorruptImageError,exception.reason,"`%s'",exception.description);
624
printf("ipa_bmp_read: rows=%ld,columns=%ld\n\n", image->rows, image->columns);
627
bmp_read->bmp.data = (void*)image;
628
bmp_read->bmp.width = (U16)image->columns;
629
bmp_read->bmp.height = (U16)image->rows;
633
static void ipa_bmp_free(wmfAPI * API, wmfBMP * bmp)
636
DestroyImageList((Image*)bmp->data);
637
bmp->data = (void*) 0;
638
bmp->width = (U16) 0;
639
bmp->height = (U16) 0;
643
This called by wmf_play() the *first* time the meta file is played
645
static void ipa_device_open(wmfAPI * API)
648
*ddata = WMF_MAGICK_GetData (API);
650
ddata->pattern_id = 0;
651
ddata->clipping = MagickFalse;
652
ddata->clip_mask_id = 0;
654
ddata->push_depth = 0;
656
ddata->draw_wand = DrawAllocateWand(ddata->draw_info,ddata->image);
660
This called by wmf_api_destroy()
662
static void ipa_device_close(wmfAPI * API)
665
*ddata = WMF_MAGICK_GetData(API);
667
DestroyDrawingWand(ddata->draw_wand);
668
DestroyDrawInfo(ddata->draw_info);
669
RelinquishMagickMemory(WMF_MAGICK_GetFontData(API)->ps_name);
673
This called from the beginning of each play for initial page setup
675
static void ipa_device_begin(wmfAPI * API)
678
comment[MaxTextExtent];
681
*ddata = WMF_MAGICK_GetData(API);
683
/* Make SVG output happy */
684
(void) PushDrawingWand(WmfDrawingWand);
686
DrawSetViewbox(WmfDrawingWand, 0, 0, ddata->image->columns, ddata->image->rows );
688
(void) FormatMagickString(comment,MaxTextExtent,"Created by ImageMagick %s",
689
GetMagickVersion((unsigned long *) NULL));
690
DrawComment(WmfDrawingWand,comment);
692
/* Scale width and height to image */
693
DrawScale(WmfDrawingWand, ddata->scale_x, ddata->scale_y);
695
/* Translate to TL corner of bounding box */
696
DrawTranslate(WmfDrawingWand, ddata->translate_x, ddata->translate_y);
699
DrawRotate(WmfDrawingWand, ddata->rotate);
701
if (ddata->image_info->texture == NULL)
706
/* Draw rectangle in background color */
707
background_color=NewPixelWand();
708
PixelSetQuantumColor(background_color,&ddata->image->background_color);
709
DrawSetFillColor(WmfDrawingWand,background_color);
710
background_color=DestroyPixelWand(background_color);
711
DrawRectangle(WmfDrawingWand,
712
XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
713
XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
717
/* Draw rectangle with texture image the SVG way */
727
GetExceptionInfo(&exception);
729
image_info = CloneImageInfo((ImageInfo *) 0);
730
(void) CopyMagickString(image_info->filename,ddata->image_info->texture,
732
if ( ddata->image_info->size )
733
CloneString(&image_info->size,ddata->image_info->size);
735
image = ReadImage(image_info,&exception);
736
image_info=DestroyImageInfo(image_info);
745
(void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
746
DrawPushDefs(WmfDrawingWand);
747
draw_pattern_push(API,ddata->pattern_id,image->columns,image->rows);
748
magick_wand=NewMagickWandFromImage(image);
749
(void) DrawComposite(WmfDrawingWand,CopyCompositeOp,0,0,
750
image->columns,image->rows,magick_wand);
751
magick_wand=DestroyMagickWand(magick_wand);
752
(void) DrawPopPattern(WmfDrawingWand);
753
DrawPopDefs(WmfDrawingWand);
754
(void) FormatMagickString(pattern_id,MaxTextExtent,"#brush_%lu",
756
(void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
759
DrawRectangle(WmfDrawingWand,
760
XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y),
761
XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y));
762
image=DestroyImageList(image);
766
LogMagickEvent(CoderEvent,GetMagickModule(),
767
"reading texture image failed!");
768
InheritException(&ddata->image->exception,&exception);
772
DrawSetClipRule(WmfDrawingWand,EvenOddRule); /* Default for WMF is ALTERNATE polygon fill mode */
773
draw_fill_color_string(WmfDrawingWand,"none"); /* Default brush is WHITE_BRUSH */
774
draw_stroke_color_string(WmfDrawingWand,"none"); /* Default pen is BLACK_PEN */
775
DrawSetStrokeLineCap(WmfDrawingWand,ButtCap); /* Default linecap is PS_ENDCAP_FLAT */
776
DrawSetStrokeLineJoin(WmfDrawingWand,MiterJoin); /* Default linejoin is PS_JOIN_MITER */
777
draw_under_color_string(WmfDrawingWand,"white"); /* Default text box is white */
781
This called from the end of each play for page termination
783
static void ipa_device_end(wmfAPI * API)
786
*ddata = WMF_MAGICK_GetData(API);
788
/* Reset any existing clip paths by popping wand */
790
(void) PopDrawingWand(WmfDrawingWand);
791
ddata->clipping = MagickFalse;
793
/* Make SVG output happy */
794
(void) PopDrawingWand(WmfDrawingWand);
797
static void ipa_flood_interior(wmfAPI * API, wmfFlood_t * flood)
799
/* Save graphic wand */
800
(void) PushDrawingWand(WmfDrawingWand);
802
draw_fill_color_rgb(API,&(flood->color));
804
DrawColor(WmfDrawingWand,XC(flood->pt.x), YC(flood->pt.y),
807
/* Restore graphic wand */
808
(void) PopDrawingWand(WmfDrawingWand);
811
static void ipa_flood_exterior(wmfAPI * API, wmfFlood_t * flood)
813
/* Save graphic wand */
814
(void) PushDrawingWand(WmfDrawingWand);
816
draw_fill_color_rgb(API,&(flood->color));
818
if (flood->type == FLOODFILLSURFACE)
819
DrawColor(WmfDrawingWand, XC(flood->pt.x), YC(flood->pt.y),
822
DrawColor(WmfDrawingWand, XC(flood->pt.x), YC(flood->pt.y),
825
/* Restore graphic wand */
826
(void) PopDrawingWand(WmfDrawingWand);
829
static void ipa_draw_pixel(wmfAPI * API, wmfDrawPixel_t * draw_pixel)
831
/* Save graphic wand */
832
(void) PushDrawingWand(WmfDrawingWand);
834
draw_stroke_color_string(WmfDrawingWand,"none");
836
draw_fill_color_rgb(API,&(draw_pixel->color));
838
DrawRectangle(WmfDrawingWand,
839
XC(draw_pixel->pt.x),
840
YC(draw_pixel->pt.y),
841
XC(draw_pixel->pt.x + draw_pixel->pixel_width),
842
YC(draw_pixel->pt.y + draw_pixel->pixel_height));
844
/* Restore graphic wand */
845
(void) PopDrawingWand(WmfDrawingWand);
848
static void ipa_draw_pie(wmfAPI * API, wmfDrawArc_t * draw_arc)
850
util_draw_arc(API, draw_arc, magick_arc_pie);
853
static void ipa_draw_chord(wmfAPI * API, wmfDrawArc_t * draw_arc)
855
util_draw_arc(API, draw_arc, magick_arc_chord);
858
static void ipa_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc)
860
util_draw_arc(API, draw_arc, magick_arc_open);
863
static void ipa_draw_ellipse(wmfAPI * API, wmfDrawArc_t * draw_arc)
865
util_draw_arc(API, draw_arc, magick_arc_ellipse);
868
static void util_draw_arc(wmfAPI * API,
869
wmfDrawArc_t * draw_arc, magick_arc_t finish)
887
/* Save graphic wand */
888
(void) PushDrawingWand(WmfDrawingWand);
890
if (TO_FILL(draw_arc) || TO_DRAW(draw_arc))
892
center.x = (draw_arc->TL.x + draw_arc->BR.x) / 2;
893
center.y = (draw_arc->TL.y + draw_arc->BR.y) / 2;
897
if (finish != magick_arc_ellipse)
899
draw_arc->start.x += center.x;
900
draw_arc->start.y += center.y;
902
draw_arc->end.x += center.x;
903
draw_arc->end.y += center.y;
911
if (finish != magick_arc_ellipse)
913
start = draw_arc->start;
917
Rx = (BR.x - TL.x) / 2;
918
Ry = (BR.y - TL.y) / 2;
920
if (finish != magick_arc_ellipse)
928
phi_s = atan2((double) start.y, (double) start.x) * 180 / MagickPI;
929
phi_e = atan2((double) end.y, (double) end.x) * 180 / MagickPI;
935
util_set_pen(API, draw_arc->dc);
936
if (finish == magick_arc_open)
937
draw_fill_color_string(WmfDrawingWand,"none");
939
util_set_brush(API, draw_arc->dc, BrushApplyFill);
941
if (finish == magick_arc_ellipse)
942
DrawEllipse(WmfDrawingWand, XC(O.x), YC(O.y), Rx, Ry, 0, 360);
943
else if (finish == magick_arc_pie)
945
DrawPathStart(WmfDrawingWand);
946
DrawPathMoveToAbsolute(WmfDrawingWand, XC(O.x+start.x),
948
DrawPathEllipticArcAbsolute(WmfDrawingWand, Rx, Ry, 0, MagickFalse,
949
MagickTrue, XC(O.x+end.x), YC(O.y+end.y));
950
DrawPathLineToAbsolute(WmfDrawingWand, XC(O.x), YC(O.y));
951
DrawPathClose(WmfDrawingWand);
952
DrawPathFinish(WmfDrawingWand);
954
else if (finish == magick_arc_chord)
956
DrawArc(WmfDrawingWand, XC(draw_arc->TL.x), YC(draw_arc->TL.y),
957
XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
958
DrawLine(WmfDrawingWand, XC(draw_arc->BR.x-start.x),
959
YC(draw_arc->BR.y-start.y), XC(draw_arc->BR.x-end.x),
960
YC(draw_arc->BR.y-end.y));
962
else /* if (finish == magick_arc_open) */
963
DrawArc(WmfDrawingWand, XC(draw_arc->TL.x), YC(draw_arc->TL.y),
964
XC(draw_arc->BR.x), XC(draw_arc->BR.y), phi_s, phi_e);
967
/* Restore graphic wand */
968
(void) PopDrawingWand(WmfDrawingWand);
971
static void ipa_draw_line(wmfAPI * API, wmfDrawLine_t * draw_line)
973
/* Save graphic wand */
974
(void) PushDrawingWand(WmfDrawingWand);
976
if (TO_DRAW(draw_line))
978
util_set_pen(API, draw_line->dc);
979
DrawLine(WmfDrawingWand,
980
XC(draw_line->from.x), YC(draw_line->from.y),
981
XC(draw_line->to.x), YC(draw_line->to.y));
984
/* Restore graphic wand */
985
(void) PopDrawingWand(WmfDrawingWand);
988
static void ipa_poly_line(wmfAPI * API, wmfPolyLine_t * polyline)
990
if (polyline->count <= 2)
993
if (TO_DRAW(polyline))
998
/* Save graphic wand */
999
(void) PushDrawingWand(WmfDrawingWand);
1001
util_set_pen(API, polyline->dc);
1003
DrawPathStart(WmfDrawingWand);
1004
DrawPathMoveToAbsolute(WmfDrawingWand,
1005
XC(polyline->pt[0].x),
1006
YC(polyline->pt[0].y));
1007
for (point = 1; point < polyline->count; point++)
1009
DrawPathLineToAbsolute(WmfDrawingWand,
1010
XC(polyline->pt[point].x),
1011
YC(polyline->pt[point].y));
1013
DrawPathFinish(WmfDrawingWand);
1015
/* Restore graphic wand */
1016
(void) PopDrawingWand(WmfDrawingWand);
1020
static void ipa_draw_polygon(wmfAPI * API, wmfPolyLine_t * polyline)
1022
if (polyline->count <= 2)
1025
if (TO_FILL(polyline) || TO_DRAW(polyline))
1030
/* Save graphic wand */
1031
(void) PushDrawingWand(WmfDrawingWand);
1033
util_set_pen(API, polyline->dc);
1034
util_set_brush(API, polyline->dc, BrushApplyFill);
1036
DrawPathStart(WmfDrawingWand);
1037
DrawPathMoveToAbsolute(WmfDrawingWand,
1038
XC(polyline->pt[0].x),
1039
YC(polyline->pt[0].y));
1040
for (point = 1; point < polyline->count; point++)
1042
DrawPathLineToAbsolute(WmfDrawingWand,
1043
XC(polyline->pt[point].x),
1044
YC(polyline->pt[point].y));
1046
DrawPathClose(WmfDrawingWand);
1047
DrawPathFinish(WmfDrawingWand);
1049
/* Restore graphic wand */
1050
(void) PopDrawingWand(WmfDrawingWand);
1054
/* Draw a polypolygon. A polypolygon is a list of polygons */
1055
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
1056
static void ipa_draw_polypolygon(wmfAPI * API, wmfPolyPoly_t* polypolygon)
1058
if (TO_FILL(polypolygon) || TO_DRAW(polypolygon))
1067
/* Save graphic wand */
1068
(void) PushDrawingWand(WmfDrawingWand);
1070
util_set_pen(API, polypolygon->dc);
1071
util_set_brush(API, polypolygon->dc, BrushApplyFill);
1073
DrawPathStart(WmfDrawingWand);
1074
for (polygon = 0; polygon < polypolygon->npoly; polygon++)
1076
polyline.dc = polypolygon->dc;
1077
polyline.pt = polypolygon->pt[polygon];
1078
polyline.count = polypolygon->count[polygon];
1079
if ((polyline.count > 2) && polyline.pt)
1081
DrawPathMoveToAbsolute(WmfDrawingWand,
1082
XC(polyline.pt[0].x),
1083
YC(polyline.pt[0].y));
1084
for (point = 1; point < polyline.count; point++)
1086
DrawPathLineToAbsolute(WmfDrawingWand,
1087
XC(polyline.pt[point].x),
1088
YC(polyline.pt[point].y));
1090
DrawPathClose(WmfDrawingWand);
1093
DrawPathFinish(WmfDrawingWand);
1095
/* Restore graphic wand */
1096
(void) PopDrawingWand(WmfDrawingWand);
1101
static void ipa_draw_rectangle(wmfAPI * API, wmfDrawRectangle_t * draw_rect)
1103
/* Save graphic wand */
1104
(void) PushDrawingWand(WmfDrawingWand);
1106
if (TO_FILL(draw_rect) || TO_DRAW(draw_rect))
1108
util_set_pen(API, draw_rect->dc);
1109
util_set_brush(API, draw_rect->dc, BrushApplyFill);
1111
if ((draw_rect->width > 0) || (draw_rect->height > 0))
1112
DrawRoundRectangle(WmfDrawingWand,
1113
XC(draw_rect->TL.x), YC(draw_rect->TL.y),
1114
XC(draw_rect->BR.x), YC(draw_rect->BR.y),
1115
draw_rect->width / 2, draw_rect->height / 2);
1117
DrawRectangle(WmfDrawingWand,
1118
XC(draw_rect->TL.x), YC(draw_rect->TL.y),
1119
XC(draw_rect->BR.x), YC(draw_rect->BR.y));
1122
/* Restore graphic wand */
1123
(void) PopDrawingWand(WmfDrawingWand);
1126
/* Draw an un-filled rectangle using the current brush */
1127
static void ipa_region_frame(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
1129
/* Save graphic wand */
1130
(void) PushDrawingWand(WmfDrawingWand);
1132
if (TO_FILL(poly_rect) || TO_DRAW(poly_rect))
1137
draw_fill_color_string(WmfDrawingWand,"none");
1138
util_set_brush(API, poly_rect->dc, BrushApplyStroke);
1140
for (i = 0; i < (long) poly_rect->count; i++)
1142
DrawRectangle(WmfDrawingWand,
1143
XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1144
XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1148
/* Restore graphic wand */
1149
(void) PopDrawingWand(WmfDrawingWand);
1152
static void ipa_region_paint(wmfAPI * API, wmfPolyRectangle_t * poly_rect)
1155
if (poly_rect->count == 0)
1158
/* Save graphic wand */
1159
(void) PushDrawingWand(WmfDrawingWand);
1161
if (TO_FILL (poly_rect))
1166
draw_stroke_color_string(WmfDrawingWand,"none");
1167
util_set_brush(API, poly_rect->dc, BrushApplyFill);
1169
for (i = 0; i < (long) poly_rect->count; i++)
1171
DrawRectangle(WmfDrawingWand,
1172
XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1173
XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1177
/* Restore graphic wand */
1178
(void) PopDrawingWand(WmfDrawingWand);
1181
static void ipa_region_clip(wmfAPI *API, wmfPolyRectangle_t *poly_rect)
1187
*ddata = WMF_MAGICK_GetData (API);
1189
/* Reset any existing clip paths by popping wand */
1190
if (ddata->clipping)
1191
(void) PopDrawingWand(WmfDrawingWand);
1192
ddata->clipping = MagickFalse;
1194
if (poly_rect->count > 0)
1199
/* Define clip path */
1200
ddata->clip_mask_id++;
1201
DrawPushDefs(WmfDrawingWand);
1202
(void) FormatMagickString(clip_mask_id,MaxTextExtent,"clip_%lu",
1203
ddata->clip_mask_id);
1204
DrawPushClipPath(WmfDrawingWand,clip_mask_id);
1205
(void) PushDrawingWand(WmfDrawingWand);
1206
for (i = 0; i < (long) poly_rect->count; i++)
1208
DrawRectangle(WmfDrawingWand,
1209
XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y),
1210
XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y));
1212
(void) PopDrawingWand(WmfDrawingWand);
1213
DrawPopClipPath(WmfDrawingWand);
1214
DrawPopDefs(WmfDrawingWand);
1216
/* Push wand for new clip paths */
1217
(void) PushDrawingWand(WmfDrawingWand);
1218
(void) DrawSetClipPath(WmfDrawingWand,clip_mask_id);
1219
ddata->clipping = MagickTrue;
1223
static void ipa_functions(wmfAPI *API)
1228
wmfFunctionReference
1229
*FR = (wmfFunctionReference *) API->function_reference;
1232
IPA function reference links
1234
FR->device_open = ipa_device_open;
1235
FR->device_close = ipa_device_close;
1236
FR->device_begin = ipa_device_begin;
1237
FR->device_end = ipa_device_end;
1238
FR->flood_interior = ipa_flood_interior;
1239
FR->flood_exterior = ipa_flood_exterior;
1240
FR->draw_pixel = ipa_draw_pixel;
1241
FR->draw_pie = ipa_draw_pie;
1242
FR->draw_chord = ipa_draw_chord;
1243
FR->draw_arc = ipa_draw_arc;
1244
FR->draw_ellipse = ipa_draw_ellipse;
1245
FR->draw_line = ipa_draw_line;
1246
FR->poly_line = ipa_poly_line;
1247
FR->draw_polygon = ipa_draw_polygon;
1248
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
1249
FR->draw_polypolygon = ipa_draw_polypolygon;
1251
FR->draw_rectangle = ipa_draw_rectangle;
1252
FR->rop_draw = ipa_rop_draw;
1253
FR->bmp_draw = ipa_bmp_draw;
1254
FR->bmp_read = ipa_bmp_read;
1255
FR->bmp_free = ipa_bmp_free;
1256
FR->draw_text = ipa_draw_text;
1257
FR->udata_init = ipa_udata_init;
1258
FR->udata_copy = ipa_udata_copy;
1259
FR->udata_set = ipa_udata_set;
1260
FR->udata_free = ipa_udata_free;
1261
FR->region_frame = ipa_region_frame;
1262
FR->region_paint = ipa_region_paint;
1263
FR->region_clip = ipa_region_clip;
1266
Allocate device data structure
1268
ddata = (wmf_magick_t *) wmf_malloc(API, sizeof(wmf_magick_t));
1272
(void) ResetMagickMemory((void *) ddata, 0, sizeof(wmf_magick_t));
1273
API->device_data = (void *) ddata;
1276
Device data defaults
1281
static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text)
1284
angle = 0, /* text rotation angle */
1285
bbox_height, /* bounding box height */
1286
bbox_width, /* bounding box width */
1287
pointsize = 0; /* pointsize to output font with desired height */
1293
BL, /* bottom left of bounding box */
1294
BR, /* bottom right of bounding box */
1295
TL, /* top left of bounding box */
1296
TR; /* top right of bounding box */
1299
point; /* text placement point */
1305
* ddata = WMF_MAGICK_GetData(API);
1307
point = draw_text->pt;
1309
/* Choose bounding box and calculate its width and height */
1314
if ( draw_text->flags)
1318
TR.x = draw_text->BR.x;
1319
TR.y = draw_text->TL.y;
1320
BL.x = draw_text->TL.x;
1321
BL.y = draw_text->BR.y;
1325
TL = draw_text->bbox.TL;
1326
BR = draw_text->bbox.BR;
1327
TR = draw_text->bbox.TR;
1328
BL = draw_text->bbox.BL;
1330
dx = ((TR.x - TL.x) + (BR.x - BL.x)) / 2;
1331
dy = ((TR.y - TL.y) + (BR.y - BL.y)) / 2;
1332
bbox_width = hypot(dx,dy);
1333
dx = ((BL.x - TL.x) + (BR.x - TR.x)) / 2;
1334
dy = ((BL.y - TL.y) + (BR.y - TR.y)) / 2;
1335
bbox_height = hypot(dx,dy);
1338
font = WMF_DC_FONT(draw_text->dc);
1340
/* Convert font_height to equivalent pointsize */
1341
pointsize = util_pointsize( API, font, draw_text->str, draw_text->font_height);
1343
/* Save graphic wand */
1344
(void) PushDrawingWand(WmfDrawingWand);
1347
printf("\nipa_draw_text\n");
1348
printf("Text = \"%s\"\n", draw_text->str);
1349
/* printf("WMF_FONT_NAME: = \"%s\"\n", WMF_FONT_NAME(font)); */
1350
printf("WMF_FONT_PSNAME: = \"%s\"\n", WMF_FONT_PSNAME(font));
1351
printf("Bounding box TL=%g,%g BR=%g,%g\n",
1352
TL.x, TL.y, BR.x, BR.y );
1353
/* printf("Text box = %gx%g\n", bbox_width, bbox_height); */
1354
/* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
1355
printf("Pointsize = %g\n", pointsize);
1360
* Obtain font metrics if required
1363
if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER) ||
1364
(WMF_TEXT_UNDERLINE(font)) || (WMF_TEXT_STRIKEOUT(font)))
1367
*image = ddata->image;
1372
draw_info=ddata->draw_info;
1373
draw_info->font=WMF_FONT_PSNAME(font);
1374
draw_info->pointsize = pointsize;
1375
draw_info->text=draw_text->str;
1377
if (GetTypeMetrics(image, draw_info, &metrics) != MagickFalse)
1379
/* Center the text if it is not yet centered and should be */
1380
if ((WMF_DC_TEXTALIGN(draw_text->dc) & TA_CENTER))
1383
text_width = metrics.width * (ddata->scale_y / ddata->scale_x);
1385
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
1386
point.x -= text_width / 2;
1388
point.x += bbox_width / 2 - text_width / 2;
1392
draw_info->font=NULL;
1393
draw_info->text=NULL;
1396
/* Set text background color */
1397
if (draw_text->flags & ETO_OPAQUE)
1399
/* Draw bounding-box background color (META_EXTTEXTOUT mode) */
1400
draw_stroke_color_string(WmfDrawingWand,"none");
1401
draw_fill_color_rgb(API,WMF_DC_BACKGROUND(draw_text->dc));
1402
DrawRectangle(WmfDrawingWand,
1403
XC(draw_text->TL.x),YC(draw_text->TL.y),
1404
XC(draw_text->BR.x),YC(draw_text->BR.y));
1405
draw_fill_color_string(WmfDrawingWand,"none");
1409
/* Set text undercolor */
1410
if (WMF_DC_OPAQUE(draw_text->dc))
1413
*box = WMF_DC_BACKGROUND(draw_text->dc);
1418
under_color=NewPixelWand();
1419
PixelSetRedQuantum(under_color,ScaleCharToQuantum(box->r));
1420
PixelSetGreenQuantum(under_color,ScaleCharToQuantum(box->g));
1421
PixelSetBlueQuantum(under_color,ScaleCharToQuantum(box->b));
1422
PixelSetOpacityQuantum(under_color,OpaqueOpacity);
1423
DrawSetTextUnderColor(WmfDrawingWand,under_color);
1424
under_color=DestroyPixelWand(under_color);
1427
draw_under_color_string(WmfDrawingWand,"none");
1430
/* Set text clipping (META_EXTTEXTOUT mode) */
1431
if ( draw_text->flags & ETO_CLIPPED)
1435
/* Set stroke color */
1436
draw_stroke_color_string(WmfDrawingWand,"none");
1438
/* Set fill color */
1439
draw_fill_color_rgb(API,WMF_DC_TEXTCOLOR(draw_text->dc));
1441
/* Output font size */
1442
(void) DrawSetFontSize(WmfDrawingWand,pointsize);
1444
/* Output Postscript font name */
1445
(void) DrawSetFont(WmfDrawingWand, WMF_FONT_PSNAME(font));
1447
/* Translate coordinates so target is 0,0 */
1448
DrawTranslate(WmfDrawingWand, XC(point.x), YC(point.y));
1450
/* Transform horizontal scale to draw text at 1:1 ratio */
1451
DrawScale(WmfDrawingWand, ddata->scale_y / ddata->scale_x, 1.0);
1453
/* Apply rotation */
1454
/* ImageMagick's drawing rotation is clockwise from horizontal
1455
while WMF drawing rotation is counterclockwise from horizontal */
1456
angle = fabs(RadiansToDegrees(2 * MagickPI - WMF_TEXT_ANGLE(font)));
1460
DrawRotate(WmfDrawingWand, angle);
1468
DrawAnnotation(WmfDrawingWand, 0, 0, (unsigned char*)draw_text->str);
1470
/* Underline text the Windows way (at the bottom) */
1471
if (WMF_TEXT_UNDERLINE(font))
1477
ulBR, /* bottom right of underline rectangle */
1478
ulTL; /* top left of underline rectangle */
1480
line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
1481
if (metrics.underline_thickness < 1.5)
1482
line_height *= 0.55;
1484
ulTL.y = fabs(metrics.descent) - line_height;
1485
ulBR.x = metrics.width;
1486
ulBR.y = fabs(metrics.descent);
1488
DrawRectangle(WmfDrawingWand,
1489
XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
1492
/* Strikeout text the Windows way */
1493
if (WMF_TEXT_STRIKEOUT(font))
1498
ulBR, /* bottom right of strikeout rectangle */
1499
ulTL; /* top left of strikeout rectangle */
1501
line_height = ((double)1/(ddata->scale_x))*metrics.underline_thickness;
1503
if (metrics.underline_thickness < 2.0)
1504
line_height *= 0.55;
1506
ulTL.y = -(((double) metrics.ascent) / 2 + line_height / 2);
1507
ulBR.x = metrics.width;
1508
ulBR.y = -(((double) metrics.ascent) / 2 - line_height / 2);
1510
DrawRectangle(WmfDrawingWand,
1511
XC(ulTL.x), YC(ulTL.y), XC(ulBR.x), YC(ulBR.y));
1515
/* Restore graphic wand */
1516
(void) PopDrawingWand(WmfDrawingWand);
1519
(void) PushDrawingWand(WmfDrawingWand);
1520
draw_stroke_color_string(WmfDrawingWand,"red");
1521
draw_fill_color_string(WmfDrawingWand,"none");
1522
DrawRectangle(WmfDrawingWand,
1524
XC(BR.x), YC(BR.y));
1525
draw_stroke_color_string(WmfDrawingWand,"none");
1526
(void) PopDrawingWand(WmfDrawingWand);
1531
static void ipa_udata_init(wmfAPI * API, wmfUserData_t * userdata)
1535
/* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1539
static void ipa_udata_copy(wmfAPI * API, wmfUserData_t * userdata)
1543
/* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1547
static void ipa_udata_set(wmfAPI * API, wmfUserData_t * userdata)
1551
/* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1555
static void ipa_udata_free(wmfAPI * API, wmfUserData_t * userdata)
1559
/* wmf_magick_t* ddata = WMF_MAGICK_GetData (API); */
1563
static inline double MagickMin(const double x,const double y)
1570
static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply)
1573
*ddata = WMF_MAGICK_GetData(API);
1576
*brush = WMF_DC_BRUSH(dc);
1578
/* Set polygon fill rule */
1579
switch (WMF_DC_POLYFILL(dc)) /* Is this correct ?? */
1582
DrawSetClipRule(WmfDrawingWand,NonZeroRule);
1587
DrawSetClipRule(WmfDrawingWand,EvenOddRule);
1591
switch (WMF_BRUSH_STYLE(brush))
1593
case BS_SOLID /* 0 */:
1594
/* WMF_BRUSH_COLOR specifies brush color, WMF_BRUSH_HATCH
1597
if ( brush_apply == BrushApplyStroke )
1598
draw_stroke_color_rgb(API,WMF_BRUSH_COLOR(brush));
1600
draw_fill_color_rgb(API,WMF_BRUSH_COLOR(brush));
1603
case BS_HOLLOW /* 1 */: /* BS_HOLLOW & BS_NULL share enum */
1604
/* WMF_BRUSH_COLOR and WMF_BRUSH_HATCH ignored */
1606
if ( brush_apply == BrushApplyStroke )
1607
draw_stroke_color_string(WmfDrawingWand,"none");
1609
draw_fill_color_string(WmfDrawingWand,"none");
1612
case BS_HATCHED /* 2 */:
1613
/* WMF_BRUSH_COLOR specifies the hatch color, WMF_BRUSH_HATCH
1614
specifies the hatch brush style. If WMF_DC_OPAQUE, then
1615
WMF_DC_BACKGROUND specifies hatch background color. */
1617
DrawPushDefs(WmfDrawingWand);
1618
draw_pattern_push(API, ddata->pattern_id, 8, 8);
1619
(void) PushDrawingWand(WmfDrawingWand);
1621
if (WMF_DC_OPAQUE(dc))
1623
if ( brush_apply == BrushApplyStroke )
1624
draw_stroke_color_rgb(API,WMF_DC_BACKGROUND(dc));
1626
draw_fill_color_rgb(API,WMF_DC_BACKGROUND(dc));
1628
DrawRectangle(WmfDrawingWand, 0, 0, 7, 7 );
1631
DrawSetStrokeAntialias(WmfDrawingWand, MagickFalse);
1632
DrawSetStrokeWidth(WmfDrawingWand, 1);
1634
draw_stroke_color_rgb(API,WMF_BRUSH_COLOR(brush));
1636
switch ((unsigned int) WMF_BRUSH_HATCH(brush))
1639
case HS_HORIZONTAL: /* ----- */
1641
DrawLine(WmfDrawingWand, 0, 3, 7,3);
1644
case HS_VERTICAL: /* ||||| */
1646
DrawLine(WmfDrawingWand, 3, 0, 3, 7);
1649
case HS_FDIAGONAL: /* \\\\\ */
1651
DrawLine(WmfDrawingWand, 0, 0, 7, 7);
1654
case HS_BDIAGONAL: /* / */
1656
DrawLine(WmfDrawingWand, 0, 7, 7, 0 );
1659
case HS_CROSS: /* +++++ */
1661
DrawLine(WmfDrawingWand, 0, 3, 7, 3 );
1662
DrawLine(WmfDrawingWand, 3, 0, 3, 7 );
1665
case HS_DIAGCROSS: /* xxxxx */
1667
DrawLine(WmfDrawingWand, 0, 0, 7, 7 );
1668
DrawLine(WmfDrawingWand, 0, 7, 7, 0 );
1673
printf("util_set_brush: unexpected brush hatch enumeration %u\n",
1674
(unsigned int)WMF_BRUSH_HATCH(brush));
1677
(void) PopDrawingWand(WmfDrawingWand);
1678
(void) DrawPopPattern(WmfDrawingWand);
1679
DrawPopDefs(WmfDrawingWand);
1684
(void) FormatMagickString(pattern_id,MaxTextExtent,"#brush_%lu",
1686
if (brush_apply == BrushApplyStroke )
1687
(void) DrawSetStrokePatternURL(WmfDrawingWand,pattern_id);
1689
(void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
1690
++ddata->pattern_id;
1694
case BS_PATTERN /* 3 */:
1695
/* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides handle to
1698
printf("util_set_brush: BS_PATTERN not supported\n");
1701
case BS_INDEXED /* 4 */:
1703
printf("util_set_brush: BS_INDEXED not supported\n");
1706
case BS_DIBPATTERN /* 5 */:
1709
*brush_bmp = WMF_BRUSH_BITMAP(brush);
1711
if (brush_bmp && brush_bmp->data != 0)
1725
GetExceptionInfo(&exception);
1727
image = (Image*)brush_bmp->data;
1729
mode = CopyCompositeOp; /* Default is copy */
1730
switch (WMF_DC_ROP(dc))
1732
/* Binary raster ops */
1734
printf("util_set_brush: R2_BLACK ROP2 mode not supported!\n");
1736
case R2_NOTMERGEPEN:
1737
printf("util_set_brush: R2_NOTMERGEPEN ROP2 mode not supported!\n");
1740
printf("util_set_brush R2_MASKNOTPEN ROP2 mode not supported!\n");
1743
printf("util_set_brush: R2_NOTCOPYPEN ROP2 mode not supported!\n");
1746
printf("util_set_brush: R2_MASKPENNOT ROP2 mode not supported!\n");
1749
printf("util_set_brush: R2_NOT ROP2 mode not supported!\n");
1752
printf("util_set_brush: R2_XORPEN ROP2 mode not supported!\n");
1755
printf("util_set_brush: R2_NOTMASKPEN ROP2 mode not supported!\n");
1758
printf("util_set_brush: R2_MASKPEN ROP2 mode not supported!\n");
1761
printf("util_set_brush: R2_NOTXORPEN ROP2 mode not supported!\n");
1764
printf("util_set_brush: R2_NOP ROP2 mode not supported!\n");
1766
case R2_MERGENOTPEN:
1767
printf("util_set_brush: R2_MERGENOTPEN ROP2 mode not supported!\n");
1770
mode = CopyCompositeOp;
1772
case R2_MERGEPENNOT:
1773
printf("util_set_brush: R2_MERGEPENNOT ROP2 mode not supported!\n");
1776
printf("util_set_brush: R2_MERGEPEN ROP2 mode not supported!\n");
1779
printf("util_set_brush: R2_WHITE ROP2 mode not supported!\n");
1783
printf("util_set_brush: unexpected ROP2 enumeration %u!\n",
1784
(unsigned int)WMF_DC_ROP(dc));
1788
DrawPushDefs(WmfDrawingWand);
1789
draw_pattern_push(API, ddata->pattern_id, brush_bmp->width,
1791
magick_wand=NewMagickWandFromImage(image);
1792
(void) DrawComposite(WmfDrawingWand,mode, 0, 0, brush_bmp->width,
1793
brush_bmp->height, magick_wand);
1794
magick_wand=DestroyMagickWand(magick_wand);
1795
(void) DrawPopPattern(WmfDrawingWand);
1796
DrawPopDefs(WmfDrawingWand);
1802
(void) FormatMagickString(pattern_id,MaxTextExtent,"#brush_%lu",
1805
if ( brush_apply == BrushApplyStroke )
1806
(void) DrawSetStrokePatternURL(WmfDrawingWand,pattern_id);
1808
(void) DrawSetFillPatternURL(WmfDrawingWand,pattern_id);
1809
++ddata->pattern_id;
1813
printf("util_set_brush: no BMP image data!\n");
1817
case BS_DIBPATTERNPT /* 6 */:
1818
/* WMF_BRUSH_COLOR ignored, WMF_BRUSH_HATCH provides pointer to
1821
printf("util_set_brush: BS_DIBPATTERNPT not supported\n");
1824
case BS_PATTERN8X8 /* 7 */:
1826
printf("util_set_brush: BS_PATTERN8X8 not supported\n");
1829
case BS_DIBPATTERN8X8 /* 8 */:
1831
printf("util_set_brush: BS_DIBPATTERN8X8 not supported\n");
1840
static inline double MagickMax(const double x,const double y)
1847
static void util_set_pen(wmfAPI * API, wmfDC * dc)
1850
*ddata = WMF_MAGICK_GetData(API);
1863
pen = WMF_DC_PEN(dc);
1865
pen_width = (WMF_PEN_WIDTH(pen) + WMF_PEN_HEIGHT(pen)) / 2;
1867
/* Pixel width is inverse of pixel scale */
1868
pixel_width = (((double) 1 / (ddata->scale_x)) +
1869
((double) 1 / (ddata->scale_y))) / 2;
1871
/* Don't allow pen_width to be much less than pixel_width in order
1872
to avoid dissapearing or spider-web lines */
1873
pen_width = MagickMax(pen_width, pixel_width*0.8);
1875
pen_style = (unsigned int) WMF_PEN_STYLE(pen);
1876
pen_type = (unsigned int) WMF_PEN_TYPE(pen);
1878
/* Pen style specified? */
1879
if (pen_style == PS_NULL)
1881
draw_stroke_color_string(WmfDrawingWand,"none");
1885
DrawSetStrokeAntialias(WmfDrawingWand, MagickTrue );
1886
DrawSetStrokeWidth(WmfDrawingWand, (unsigned long) MagickMax(0.0, pen_width));
1892
switch ((unsigned int) WMF_PEN_ENDCAP(pen))
1894
case PS_ENDCAP_SQUARE:
1895
linecap = SquareCap;
1897
case PS_ENDCAP_ROUND:
1900
case PS_ENDCAP_FLAT:
1905
DrawSetStrokeLineCap(WmfDrawingWand, linecap);
1912
switch ((unsigned int) WMF_PEN_JOIN(pen))
1915
linejoin = BevelJoin;
1918
linejoin = RoundJoin;
1922
linejoin = MiterJoin;
1925
DrawSetStrokeLineJoin(WmfDrawingWand,linejoin);
1934
case PS_DASH: /* ------- */
1937
dasharray[0] = pixel_width * 18;
1938
dasharray[1] = pixel_width * 7;
1941
DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
1942
(void) DrawSetStrokeDashArray(WmfDrawingWand,2,dasharray);
1946
case PS_DOT: /* ....... */
1949
dasharray[0] = pixel_width * 3;
1950
dasharray[1] = pixel_width * 3;
1953
DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
1954
(void) DrawSetStrokeDashArray(WmfDrawingWand,2,dasharray);
1957
case PS_DASHDOT: /* _._._._ */
1959
/* Pattern 9,6,3,6 */
1960
dasharray[0] = pixel_width * 9;
1961
dasharray[1] = pixel_width * 6;
1962
dasharray[2] = pixel_width * 3;
1963
dasharray[3] = pixel_width * 6;
1966
DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
1967
(void) DrawSetStrokeDashArray(WmfDrawingWand,4,dasharray);
1970
case PS_DASHDOTDOT: /* _.._.._ */
1972
/* Pattern 9,3,3,3,3,3 */
1973
dasharray[0] = pixel_width * 9;
1974
dasharray[1] = pixel_width * 3;
1975
dasharray[2] = pixel_width * 3;
1976
dasharray[3] = pixel_width * 3;
1977
dasharray[4] = pixel_width * 3;
1978
dasharray[5] = pixel_width * 3;
1981
DrawSetStrokeAntialias(WmfDrawingWand,MagickFalse);
1982
(void) DrawSetStrokeDashArray(WmfDrawingWand,6,dasharray);
1985
case PS_INSIDEFRAME: /* There is nothing to do in this case... */
1989
(void) DrawSetStrokeDashArray(WmfDrawingWand,0,(double *)NULL);
1995
draw_stroke_color_rgb(API,WMF_PEN_COLOR(pen));
1998
/* Estimate font pointsize based on Windows font parameters */
1999
static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height)
2002
*ddata = WMF_MAGICK_GetData(API);
2005
*image = ddata->image;
2016
draw_info=ddata->draw_info;
2017
if (draw_info == (const DrawInfo *) NULL)
2020
draw_info->font=WMF_FONT_PSNAME(font);
2021
draw_info->pointsize=font_height;
2022
draw_info->text=str;
2024
if (GetTypeMetrics(image, draw_info, &metrics) != MagickFalse)
2027
if (strlen(str) == 1)
2029
pointsize = (font_height *
2030
( font_height / (metrics.ascent + fabs(metrics.descent))));
2031
draw_info->pointsize = pointsize;
2032
if (GetTypeMetrics(image, draw_info, &metrics) != MagickFalse)
2033
pointsize *= (font_height / ( metrics.ascent + fabs(metrics.descent)));
2037
pointsize = (font_height * (font_height / (metrics.height)));
2038
draw_info->pointsize = pointsize;
2039
if (GetTypeMetrics(image, draw_info, &metrics) != MagickFalse)
2040
pointsize *= (font_height / metrics.height);
2044
draw_info.pointsize = pointsize;
2045
if (GetTypeMetrics(image, &draw_info, &metrics) != MagickFalse)
2046
pointsize *= (font_height / (metrics.ascent + fabs(metrics.descent)));
2047
pointsize *= 1.114286; /* Magic number computed through trial and error */
2051
draw_info->font=NULL;
2052
draw_info->text=NULL;
2054
printf("String = %s\n", str);
2055
printf("Font = %s\n", WMF_FONT_PSNAME(font));
2056
printf("lfHeight = %g\n", font_height);
2057
printf("bounds = %g,%g %g,%g\n", metrics.bounds.x1, metrics.bounds.y1,
2058
metrics.bounds.x2,metrics.bounds.y2);
2059
printf("ascent = %g\n", metrics.ascent);
2060
printf("descent = %g\n", metrics.descent);
2061
printf("height = %g\n", metrics.height);
2062
printf("Pointsize = %g\n", pointsize);
2065
return floor(pointsize);
2068
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
2069
/* Estimate weight based on font name */
2071
static int util_font_weight( const char* font )
2077
if ((strstr(font,"Normal") || strstr(font,"Regular")))
2079
else if ( strstr(font,"Bold") )
2082
if ((strstr(font,"Semi") || strstr(font,"Demi")))
2084
if ( (strstr(font,"Extra") || strstr(font,"Ultra")))
2087
else if ( strstr(font,"Light") )
2090
if ( (strstr(font,"Extra") || strstr(font,"Ultra")))
2093
else if ((strstr(font,"Heavy") || strstr(font,"Black")))
2095
else if ( strstr(font,"Thin") )
2102
* Returns width of string in points, assuming (unstretched) font size of 1pt
2103
* (similar to wmf_ipa_font_stringwidth)
2105
* This extremely odd at best, particularly since player/meta.h has access
2106
* to the corrected font_height (as drawtext.font_height) when it invokes the
2107
* stringwidth callback. It should be possible to compute the real stringwidth!
2109
static float lite_font_stringwidth( wmfAPI* API, wmfFont* font, char* str)
2112
*ddata = WMF_MAGICK_GetData(API);
2115
*image = ddata->image;
2131
orig_resolution_units;
2133
orig_x_resolution = image->x_resolution;
2134
orig_y_resolution = image->y_resolution;
2135
orig_resolution_units = image->units;
2137
draw_info=ddata->draw_info;
2138
if (draw_info == (const DrawInfo *) NULL)
2141
draw_info->font=WMF_FONT_PSNAME(font);
2142
draw_info->pointsize=12;
2143
draw_info->text=str;
2145
image->x_resolution = 72;
2146
image->y_resolution = 72;
2147
image->units = PixelsPerInchResolution;
2149
if (GetTypeMetrics(image, draw_info, &metrics) != MagickFalse)
2150
stringwidth = ((metrics.width * 72)/(image->x_resolution * draw_info->pointsize)); /* *0.916348; */
2152
draw_info->font=NULL;
2153
draw_info->text=NULL;
2156
printf("\nlite_font_stringwidth\n");
2157
printf("string = \"%s\"\n", str);
2158
printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
2159
printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
2160
printf("stringwidth = %g\n", stringwidth);
2161
/* printf("WMF_FONT_HEIGHT = %i\n", (int)WMF_FONT_HEIGHT(font)); */
2162
/* printf("WMF_FONT_WIDTH = %i\n", (int)WMF_FONT_WIDTH(font)); */
2166
image->x_resolution = orig_x_resolution;
2167
image->y_resolution = orig_y_resolution;
2168
image->units = orig_resolution_units;
2173
/* Map font (similar to wmf_ipa_font_map) */
2175
/* Mappings to Postscript fonts: family, normal, italic, bold, bolditalic */
2176
static wmfFontMap WMFFontMap[] = {
2177
{ (char *) "Courier", (char *) "Courier", (char *) "Courier-Oblique", (char *) "Courier-Bold", (char *) "Courier-BoldOblique" }, { (char *) "Helvetica", (char *) "Helvetica", (char *) "Helvetica-Oblique", (char *) "Helvetica-Bold", (char *) "Helvetica-BoldOblique" }, { (char *) "Modern", (char *) "Courier", (char *) "Courier-Oblique", (char *) "Courier-Bold", (char *) "Courier-BoldOblique" }, { (char *) "Monotype Corsiva", (char *) "Courier", (char *) "Courier-Oblique", (char *) "Courier-Bold", (char *) "Courier-BoldOblique" },
2178
{ (char *) "News Gothic", (char *) "Helvetica", (char *) "Helvetica-Oblique", (char *) "Helvetica-Bold", (char *) "Helvetica-BoldOblique" },
2179
{ (char *) "Symbol", (char *) "Symbol", (char *) "Symbol", (char *) "Symbol", (char *) "Symbol" },
2180
{ (char *) "System", (char *) "Courier", (char *) "Courier-Oblique", (char *) "Courier-Bold", (char *) "Courier-BoldOblique" },
2181
{ (char *) "Times", (char *) "Times-Roman", (char *) "Times-Italic", (char *) "Times-Bold", (char *) "Times-BoldItalic" },
2182
{ (char *) NULL, (char *) NULL, (char *) NULL, (char *) NULL, (char *) NULL }
2186
/* Mapping between base name and Ghostscript family name */
2187
static wmfMapping SubFontMap[] =
2189
{ (char *) "Arial", (char *) "Helvetica", FT_ENCODING_NONE },
2190
{ (char *) "Courier", (char *) "Courier", FT_ENCODING_NONE },
2191
{ (char *) "Fixed", (char *) "Courier", FT_ENCODING_NONE },
2192
{ (char *) "Helvetica", (char *) "Helvetica", FT_ENCODING_NONE },
2193
{ (char *) "Sans", (char *) "Helvetica", FT_ENCODING_NONE },
2194
{ (char *) "Sym", (char *) "Symbol", FT_ENCODING_NONE },
2195
{ (char *) "Terminal", (char *) "Courier", FT_ENCODING_NONE },
2196
{ (char *) "Times", (char *) "Times", FT_ENCODING_NONE },
2197
{ (char *) "Wingdings", (char *) "Symbol", FT_ENCODING_NONE },
2198
{ (char *) NULL, (char *) NULL, FT_ENCODING_NONE }
2201
static void lite_font_map( wmfAPI* API, wmfFont* font)
2210
*ddata = WMF_MAGICK_GetData(API);
2225
font_data = (wmfFontData*)API->font_data;
2226
font->user_data = font_data->user_data;
2227
magick_font = (wmf_magick_font_t*)font->user_data;
2228
wmf_font_name = WMF_FONT_NAME(font);
2230
if (magick_font->ps_name != (char *) NULL)
2231
magick_font->ps_name=DestroyString(magick_font->ps_name);
2233
GetExceptionInfo(&exception);
2234
type_info_base=GetTypeInfo("*",&exception);
2235
if (type_info_base == 0)
2237
InheritException(&ddata->image->exception,&exception);
2241
/* Certain short-hand font names are not the proper Windows names
2242
and should be promoted to the proper names */
2243
if (LocaleCompare(wmf_font_name,"Times") == 0)
2244
wmf_font_name = "Times New Roman";
2245
else if (LocaleCompare(wmf_font_name,"Courier") == 0)
2246
wmf_font_name = "Courier New";
2248
/* Look for a family-based best-match */
2249
if (!magick_font->ps_name)
2254
if (WMF_FONT_WEIGHT(font) == 0)
2255
target_weight = 400;
2257
target_weight = WMF_FONT_WEIGHT(font);
2258
type_info=GetTypeInfoByFamily(wmf_font_name,AnyStyle,AnyStretch,
2259
target_weight,&exception);
2260
if (type_info == (const TypeInfo *) NULL)
2261
type_info=GetTypeInfoByFamily(wmf_font_name,AnyStyle,AnyStretch,0,
2263
if (type_info != (const TypeInfo *) NULL)
2264
CloneString(&magick_font->ps_name,type_info->name);
2267
/* Now let's try simple substitution mappings from WMFFontMap */
2268
if (!magick_font->ps_name)
2271
target[MaxTextExtent];
2274
target_weight = 400,
2275
want_italic = MagickFalse,
2276
want_bold = MagickFalse,
2279
if ( WMF_FONT_WEIGHT(font) != 0 )
2280
target_weight = WMF_FONT_WEIGHT(font);
2282
if ( (target_weight > 550) || ((strstr(wmf_font_name,"Bold") ||
2283
strstr(wmf_font_name,"Heavy") ||
2284
strstr(wmf_font_name,"Black"))) )
2285
want_bold = MagickTrue;
2287
if ( (WMF_FONT_ITALIC(font)) || ((strstr(wmf_font_name,"Italic") ||
2288
strstr(wmf_font_name,"Oblique"))) )
2289
want_italic = MagickTrue;
2291
(void) CopyMagickString(target,"Times",MaxTextExtent);
2292
for( i=0; SubFontMap[i].name != NULL; i++ )
2294
if (LocaleCompare(wmf_font_name, SubFontMap[i].name) == 0)
2296
(void) CopyMagickString(target,SubFontMap[i].mapping,
2302
for( i=0; WMFFontMap[i].name != NULL; i++ )
2304
if (LocaleNCompare(WMFFontMap[i].name,target,strlen(WMFFontMap[i].name)) == 0)
2306
if (want_bold && want_italic)
2307
CloneString(&magick_font->ps_name,WMFFontMap[i].bolditalic);
2308
else if (want_italic)
2309
CloneString(&magick_font->ps_name,WMFFontMap[i].italic);
2311
CloneString(&magick_font->ps_name,WMFFontMap[i].bold);
2313
CloneString(&magick_font->ps_name,WMFFontMap[i].normal);
2319
printf("\nlite_font_map\n");
2320
printf("WMF_FONT_NAME = \"%s\"\n", WMF_FONT_NAME(font));
2321
printf("WMF_FONT_WEIGHT = %i\n", WMF_FONT_WEIGHT(font));
2322
printf("WMF_FONT_PSNAME = \"%s\"\n", WMF_FONT_PSNAME(font));
2328
/* Initialize API font structures */
2329
static void lite_font_init( wmfAPI* API, wmfAPI_Options* options)
2337
/* Allocate wmfFontData data structure */
2338
API->font_data = wmf_malloc(API,sizeof(wmfFontData));
2342
font_data = (wmfFontData*)API->font_data;
2344
/* Assign function to map font (type wmfMap) */
2345
font_data->map = lite_font_map;
2347
/* Assign function to return string width in points (type wmfStringWidth) */
2348
font_data->stringwidth = lite_font_stringwidth;
2350
/* Assign user data, not used by libwmflite (type void*) */
2351
font_data->user_data = wmf_malloc(API,sizeof(wmf_magick_font_t));
2354
((wmf_magick_font_t*)font_data->user_data)->ps_name = 0;
2355
((wmf_magick_font_t*)font_data->user_data)->pointsize = 0;
2358
#endif /* MAGICKCORE_WMFLITE_DELEGATE */
2360
/* BLOB read byte */
2361
static int ipa_blob_read(void* wand)
2363
return ReadBlobByte((Image*)wand);
2367
static int ipa_blob_seek(void* wand,long position)
2369
return (int)SeekBlob((Image*)wand,(MagickOffsetType) position,SEEK_SET);
2373
static long ipa_blob_tell(void* wand)
2375
return (long)TellBlob((Image*)wand);
2378
static Image *ReadWMFImage(const ImageInfo * image_info, ExceptionInfo * exception)
2399
wmf_options_flags = 0;
2416
image = AcquireImage(image_info);
2417
if (OpenBlob(image_info,image,ReadBinaryBlobMode,exception) == MagickFalse)
153
image=AcquireImage(image_info);
154
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
155
if (status == MagickFalse)
2419
if (image->debug != MagickFalse)
2421
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2422
" OpenBlob failed");
2423
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2424
"leave ReadWMFImage()");
2426
157
image=DestroyImageList(image);
2427
158
return((Image *) NULL);
2435
/* Register callbacks */
2436
wmf_options_flags |= WMF_OPT_FUNCTION;
2437
(void) ResetMagickMemory(&wmf_api_options, 0, sizeof(wmf_api_options));
2438
wmf_api_options.function = ipa_functions;
2440
/* Ignore non-fatal errors */
2441
wmf_options_flags |= WMF_OPT_IGNORE_NONFATAL;
2443
wmf_error = wmf_api_create(&API, wmf_options_flags, &wmf_api_options);
2444
if (wmf_error != wmf_E_None)
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)
2447
wmf_api_destroy(API);
2448
if (image->debug != MagickFalse)
2450
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2451
" wmf_api_create failed");
2452
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2453
"leave ReadWMFImage()");
168
if (wmf_info != (wmfAPI *) NULL)
169
wmf_api_destroy(wmf_info);
2455
170
ThrowReaderException(DelegateError,"UnableToInitializeWMFLibrary");
2458
/* Register progress monitor */
2459
wmf_status_function(API,image,magick_progress_callback);
2461
ddata = WMF_MAGICK_GetData(API);
2462
ddata->image = image;
2463
ddata->image_info = image_info;
2464
ddata->draw_info = CloneDrawInfo((const ImageInfo *) NULL, (const DrawInfo *) NULL);
2465
RelinquishMagickMemory(ddata->draw_info->font);
2466
RelinquishMagickMemory(ddata->draw_info->text);
2469
#if defined(MAGICKCORE_WMFLITE_DELEGATE)
2470
/* Must initialize font subystem for WMFlite interface */
2471
lite_font_init (API,&wmf_api_options); /* similar to wmf_ipa_font_init in src/font.c */
2472
/* wmf_arg_fontdirs (API,options); */ /* similar to wmf_arg_fontdirs in src/wmf.c */
2477
* Open BLOB input via libwmf API
2480
wmf_error = wmf_bbuf_input(API,ipa_blob_read,ipa_blob_seek,
2481
ipa_blob_tell,(void*)image);
2482
if (wmf_error != wmf_E_None)
172
wmf_status=wmf_bbuf_input(wmf_info,WMFReadBlob,WMFSeekBlob,WMFTellBlob,
174
if (wmf_status != wmf_E_None)
2484
wmf_api_destroy(API);
2485
if (image->debug != MagickFalse)
2487
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2488
" wmf_bbuf_input failed");
2489
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2490
"leave ReadWMFImage()");
176
wmf_api_destroy(wmf_info);
2492
177
ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
2493
178
image->filename);
2494
179
image=DestroyImageList(image);
2495
180
return((Image *) NULL);
2502
if (image->debug != MagickFalse)
2503
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2504
" Scanning WMF to obtain bounding box");
2505
wmf_error = wmf_scan(API, 0, &bbox);
2506
if (wmf_error != wmf_E_None)
182
wmf_status=wmf_scan(wmf_info,0,&bounding_box);
183
if (wmf_status != wmf_E_None)
2508
wmf_api_destroy(API);
2509
if (image->debug != MagickFalse)
2511
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2512
" wmf_scan failed with wmf_error %d", wmf_error);
2513
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2514
"leave ReadWMFImage()");
185
wmf_api_destroy(wmf_info);
2516
186
ThrowReaderException(DelegateError,"FailedToScanFile");
2520
* Compute dimensions and scale factors
2526
/* User specified resolution */
2527
resolution_y=DefaultResolution;
2528
if (image->y_resolution > 0)
2530
resolution_y = image->y_resolution;
2531
if (image->units == PixelsPerCentimeterResolution)
2532
resolution_y *= CENTIMETERS_PER_INCH;
2535
resolution_x=DefaultResolution;
2536
if (image->x_resolution > 0)
2538
resolution_x = image->x_resolution;
2539
if (image->units == PixelsPerCentimeterResolution)
2540
resolution_x *= CENTIMETERS_PER_INCH;
2543
/* Obtain output size expressed in metafile units */
2544
wmf_error = wmf_size(API, &wmf_width, &wmf_height);
2545
if (wmf_error != wmf_E_None)
2547
wmf_api_destroy(API);
2548
if (image->debug != MagickFalse)
2550
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2551
" wmf_size failed with wmf_error %d", wmf_error);
2552
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2553
"leave ReadWMFImage()");
2555
ThrowReaderException(DelegateError,"FailedToComputeOutputSize");
2558
/* Obtain (or guess) metafile units */
2559
if ((API)->File->placeable)
2560
units_per_inch = (API)->File->pmh->Inch;
2561
else if ( (wmf_width*wmf_height) < 1024*1024)
2562
units_per_inch = POINTS_PER_INCH; /* MM_TEXT */
2564
units_per_inch = TWIPS_PER_INCH; /* MM_TWIPS */
2566
/* Calculate image width and height based on specified DPI
2568
image_width_inch = (double) wmf_width / units_per_inch;
2569
image_height_inch = (double) wmf_height / units_per_inch;
2570
image_width = image_width_inch * resolution_x;
2571
image_height = image_height_inch * resolution_y;
2573
/* Compute bounding box scale factors and origin translations
2575
* This all just a hack since libwmf does not currently seem to
2576
* provide the mapping between LOGICAL coordinates and DEVICE
2577
* coordinates. This mapping is necessary in order to know
2578
* where to place the logical bounding box within the image.
2582
bounding_width = bbox.BR.x - bbox.TL.x;
2583
bounding_height = bbox.BR.y - bbox.TL.y;
2585
ddata->scale_x = image_width/bounding_width;
2586
ddata->translate_x = 0-bbox.TL.x;
2589
/* Heuristic: guess that if the vertical coordinates mostly span
2590
negative values, then the image must be inverted. */
2591
if ( fabs(bbox.BR.y) > fabs(bbox.TL.y) )
2593
/* Normal (Origin at top left of image) */
2594
ddata->scale_y = (image_height/bounding_height);
2595
ddata->translate_y = 0-bbox.TL.y;
2599
/* Inverted (Origin at bottom left of image) */
2600
ddata->scale_y = (-image_height/bounding_height);
2601
ddata->translate_y = 0-bbox.BR.y;
2604
if (image->debug != MagickFalse)
2606
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2607
" Placeable metafile: %s",
2608
(API)->File->placeable ? "Yes" : "No");
2610
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2611
" Size in metafile units: %gx%g",wmf_width,wmf_height);
2612
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2613
" Metafile units/inch: %g",units_per_inch);
2614
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2615
" Size in inches: %gx%g",
2616
image_width_inch,image_height_inch);
2617
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2618
" Bounding Box: %g,%g %g,%g",
2619
bbox.TL.x, bbox.TL.y, bbox.BR.x, bbox.BR.y);
2620
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2621
" Bounding width x height: %gx%g",bounding_width,bounding_height);
2622
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2623
" Output resolution: %gx%g",resolution_x,resolution_y);
2624
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2625
" Image size: %gx%g",image_width,image_height);
2626
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2627
" Bounding box scale factor: %g,%g",ddata->scale_x,ddata->scale_y);
2628
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2629
" Translation: %g,%g",
2630
ddata->translate_x, ddata->translate_y);
2636
typedef struct _wmfPlayer_t wmfPlayer_t;
2640
wmfBrush default_brush;
2641
wmfFont default_font;
2643
wmfDC* dc; /* current dc */
2649
#define WMF_ELICIT_DC(API) (((wmfPlayer_t*)((API)->player_data))->dc)
2651
dc = WMF_ELICIT_DC(API);
2653
printf("dc->Window.Ox = %d\n", dc->Window.Ox);
2654
printf("dc->Window.Oy = %d\n", dc->Window.Oy);
2655
printf("dc->Window.width = %d\n", dc->Window.width);
2656
printf("dc->Window.height = %d\n", dc->Window.height);
2657
printf("dc->pixel_width = %g\n", dc->pixel_width);
2658
printf("dc->pixel_height = %g\n", dc->pixel_height);
2659
#if defined(MAGICKCORE_WMFLITE_DELEGATE) /* Only in libwmf 0.3 */
2660
printf("dc->Ox = %.d\n", dc->Ox);
2661
printf("dc->Oy = %.d\n", dc->Oy);
2662
printf("dc->width = %.d\n", dc->width);
2663
printf("dc->height = %.d\n", dc->height);
2672
* Create canvas image
2675
image->rows=(unsigned long) ceil(image_height);
2676
image->columns=(unsigned long) ceil(image_width);
2678
if (image_info->ping != MagickFalse)
2680
wmf_api_destroy(API);
2681
(void) CloseBlob(image);
2682
if (image->debug != MagickFalse)
2683
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2684
"leave ReadWMFImage()");
2685
return(GetFirstImageInList(image));
2687
if (image->debug != MagickFalse)
2688
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2689
" Creating canvas image with size %ldx%ld",
2690
image->rows,image->columns);
2693
* Set solid background color
2704
background_color = image_info->background_color;
2705
image->background_color = background_color;
2706
if (background_color.opacity != OpaqueOpacity)
2707
image->matte = MagickTrue;
2709
for (row=0; row < image->rows; row++)
2711
pixel=QueueAuthenticPixels(image,0,row,image->columns,1,exception);
2712
if (pixel == (PixelPacket *) NULL)
2714
for (column=image->columns; column; column--)
2715
*pixel++ = background_color;
2716
if (SyncAuthenticPixels(image,exception) == MagickFalse)
2721
* Play file to generate Vector drawing commands
2725
if (image->debug != MagickFalse)
2726
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2727
" Playing WMF to prepare vectors");
2729
wmf_error = wmf_play(API, 0, &bbox);
2730
if (wmf_error != wmf_E_None)
2732
wmf_api_destroy(API);
2733
if (image->debug != MagickFalse)
2735
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2736
" Playing WMF failed with wmf_error %d", wmf_error);
2737
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2738
"leave ReadWMFImage()");
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);
2740
204
ThrowReaderException(DelegateError,"FailedToRenderFile");
2744
* Scribble on canvas image
2748
if (image->debug != MagickFalse)
2749
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
2750
" Rendering WMF vectors");
2751
DrawRender(ddata->draw_wand);
2753
/* Check for and report any rendering error */
2754
if (image->exception.severity != UndefinedException)
2755
(void) ThrowMagickException(exception,GetMagickModule(),CoderWarning,
2756
ddata->image->exception.reason,"`%s'",ddata->image->exception.description);
2758
if (image->debug != MagickFalse)
2759
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"leave ReadWMFImage()");
2761
/* Cleanup allocated data */
2762
wmf_api_destroy(API);
207
wmf_api_destroy(wmf_info);
2763
208
(void) CloseBlob(image);
209
image=DestroyImage(image);
213
read_info=CloneImageInfo(image_info);
214
(void) FormatMagickString(read_info->filename,MaxTextExtent,"eps:%.1024s",
216
image=ReadImage(read_info,exception);
217
read_info=DestroyImageInfo(read_info);
218
if (image != (Image *) NULL)
220
(void) CopyMagickString(image->filename,image_info->filename,
222
(void) CopyMagickString(image->magick_filename,image_info->filename,
224
(void) CopyMagickString(image->magick,"WMF",MaxTextExtent);
226
(void) RelinquishUniqueFileResource(filename);
227
return(GetFirstImageInList(image));
2769
#endif /* MAGICKCORE_WMF_DELEGATE || MAGICKCORE_WMFLITE_DELEGATE */
2772
232
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%