GraphicsMagick: WMF: ipa_draw_text() Treat pointer inputs as if ...
GraphicsMagick Commits <[email protected]> Tue, 05 Sep 2023 10:50:36 -0500
| Newsgroups | gmane.comp.video.graphicsmagick.cvs |
|---|---|
| Message-ID | <mailman.14298.1693929047.1374.graphicsmagick-commit@lists.sourceforge.net> |
changeset 529828e1ae4e in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=529828e1ae4e summary: WMF: ipa_draw_text() Treat pointer inputs as if they may be NULL. Re-flow entire module. diffstat: ChangeLog | 8 + coders/wmf.c | 562 ++++++++++++++++++++++++++++------------------------ www/Changelog.html | 12 +- 3 files changed, 324 insertions(+), 258 deletions(-) diffs (truncated from 1317 to 500 lines): diff -r 6fd266453dbb -r 529828e1ae4e ChangeLog --- a/ChangeLog Mon Sep 04 18:45:34 2023 -0500 +++ b/ChangeLog Tue Sep 05 10:50:32 2023 -0500 @@ -1,3 +1,11 @@ +2023-09-05 Bob Friesenhahn <[email protected]> + + * coders/wmf.c (ipa_draw_text): Treat pointer inputs as if they + may be NULL. Change live printfs to traces. Adjust white-space + in whole module to current conventions. Addresses SourceForge + issue #724 "Old WMF display: assert fails in draw.c", although I + am unable to reproduce it. + 2023-09-05 Fojtik Jaroslav <[email protected]> * coders/bmp.c Sorry for previous commit. After some diff -r 6fd266453dbb -r 529828e1ae4e coders/wmf.c --- a/coders/wmf.c Mon Sep 04 18:45:34 2023 -0500 +++ b/coders/wmf.c Tue Sep 05 10:50:32 2023 -0500 @@ -1,5 +1,5 @@ /* -% Copyright (C) 2003-2022 GraphicsMagick Group +% Copyright (C) 2003-2023 GraphicsMagick Group % Copyright (C) 2002 ImageMagick Studio % % This program is covered by multiple licenses, which are described in @@ -258,9 +258,9 @@ static int magick_progress_callback(void* context,float quantum); static void util_draw_arc(wmfAPI * API, wmfDrawArc_t * draw_arc,magick_arc_t finish); #if defined(HasWMFlite) -static int util_font_weight( const char* font ); +static int util_font_weight(const char* font); #endif -static double util_pointsize( wmfAPI* API, wmfFont* font, char* str, double font_height); +static double util_pointsize(wmfAPI* API, wmfFont* font, char* str, double font_height); static void util_set_brush(wmfAPI * API, wmfDC * dc, const BrushApply brush_apply); static void util_set_pen(wmfAPI * API, wmfDC * dc); @@ -282,7 +282,7 @@ } /* Set fill color */ -static void draw_color_fill_rgb( wmfAPI* API, const wmfRGB* rgb ) +static void draw_color_fill_rgb(wmfAPI* API, const wmfRGB* rgb) { PixelPacket fill_color; @@ -293,11 +293,10 @@ fill_color.opacity = OpaqueOpacity; DrawSetFillColor(WmfDrawContext,&fill_color); - } /* Set stroke color */ -static void draw_color_stroke_rgb( wmfAPI* API, const wmfRGB* rgb ) +static void draw_color_stroke_rgb(wmfAPI* API, const wmfRGB* rgb) { PixelPacket stroke_color; @@ -310,10 +309,10 @@ DrawSetStrokeColor(WmfDrawContext,&stroke_color); } -static void draw_pattern_push( wmfAPI* API, - unsigned long id, - unsigned long columns, - unsigned long rows ) +static void draw_pattern_push(wmfAPI* API, + unsigned long id, + unsigned long columns, + unsigned long rows) { char pattern_id[MaxTextExtent]; @@ -332,11 +331,11 @@ static void ipa_rop_draw(wmfAPI * API, wmfROP_Draw_t * rop_draw) { -/* wmfBrush */ -/* *brush = WMF_DC_BRUSH(rop_draw->dc); */ - -/* wmfBMP */ -/* *brush_bmp = WMF_BRUSH_BITMAP(brush); */ + /* wmfBrush */ + /* *brush = WMF_DC_BRUSH(rop_draw->dc); */ + + /* wmfBMP */ + /* *brush_bmp = WMF_BRUSH_BITMAP(brush); */ if (!TO_FILL(rop_draw)) return; @@ -347,8 +346,8 @@ /* FIXME: finish implementing (once we know what it is supposed to do!) */ /* - struct _wmfROP_Draw_t - { wmfDC* dc; + struct _wmfROP_Draw_t + { wmfDC* dc; wmfD_Coord TL; wmfD_Coord BR; @@ -357,52 +356,52 @@ double pixel_width; double pixel_height; - }; + }; */ -/* if(brush_bmp && brush_bmp->data != 0) */ -/* printf("Have an image!\n"); */ + /* if (brush_bmp && brush_bmp->data != 0) */ + /* printf("Have an image!\n"); */ switch (rop_draw->ROP) /* Ternary raster operations */ { case SRCCOPY: /* dest = source */ - (void) printf("ipa_rop_draw SRCCOPY ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw SRCCOPY ROP mode not implemented"); break; case SRCPAINT: /* dest = source OR dest */ - (void) printf("ipa_rop_draw SRCPAINT ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw SRCPAINT ROP mode not implemented"); break; case SRCAND: /* dest = source AND dest */ - (void) printf("ipa_rop_draw SRCAND ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw SRCAND ROP mode not implemented"); break; case SRCINVERT: /* dest = source XOR dest */ - (void) printf("ipa_rop_draw SRCINVERT ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw SRCINVERT ROP mode not implemented"); break; case SRCERASE: /* dest = source AND (NOT dest) */ - (void) printf("ipa_rop_draw SRCERASE ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw SRCERASE ROP mode not implemented"); break; case NOTSRCCOPY: /* dest = (NOT source) */ - (void) printf("ipa_rop_draw NOTSRCCOPY ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw NOTSRCCOPY ROP mode not implemented"); break; case NOTSRCERASE: /* dest = (NOT src) AND (NOT dest) */ - (void) printf("ipa_rop_draw NOTSRCERASE ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw NOTSRCERASE ROP mode not implemented"); break; case MERGECOPY: /* dest = (source AND pattern) */ - (void) printf("ipa_rop_draw MERGECOPY ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw MERGECOPY ROP mode not implemented"); break; case MERGEPAINT: /* dest = (NOT source) OR dest */ - (void) printf("ipa_rop_draw MERGEPAINT ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw MERGEPAINT ROP mode not implemented"); break; case PATCOPY: /* dest = pattern */ util_set_brush(API, rop_draw->dc, BrushApplyFill); break; case PATPAINT: /* dest = DPSnoo */ - (void) printf("ipa_rop_draw PATPAINT ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw PATPAINT ROP mode not implemented"); break; case PATINVERT: /* dest = pattern XOR dest */ - (void) printf("ipa_rop_draw PATINVERT ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw PATINVERT ROP mode not implemented"); break; case DSTINVERT: /* dest = (NOT dest) */ - (void) printf("ipa_rop_draw DSTINVERT ROP mode not implemented\n"); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw DSTINVERT ROP mode not implemented"); break; case BLACKNESS: /* dest = BLACK */ DrawSetFillColorString(WmfDrawContext,"black"); @@ -411,13 +410,13 @@ DrawSetFillColorString(WmfDrawContext,"white"); break; default: - (void) printf("ipa_rop_draw 0x%x ROP mode not implemented\n", rop_draw->ROP); + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"ipa_rop_draw 0x%x ROP mode not implemented", rop_draw->ROP); break; } DrawRectangle(WmfDrawContext, - XC(rop_draw->TL.x), YC(rop_draw->TL.y), - XC(rop_draw->BR.x), YC(rop_draw->BR.y)); + XC(rop_draw->TL.x), YC(rop_draw->TL.y), + XC(rop_draw->BR.x), YC(rop_draw->BR.y)); /* Restore graphic context */ DrawPopGraphicContext(WmfDrawContext); @@ -449,15 +448,15 @@ GetExceptionInfo(&exception); image = (Image*)bmp_draw->bmp.data; - if(!image) + if (!image) { CopyException(&ddata->image->exception,&exception); return; } - if(bmp_draw->crop.x || bmp_draw->crop.y || - (bmp_draw->crop.w != bmp_draw->bmp.width) || - (bmp_draw->crop.h != bmp_draw->bmp.height)) + if (bmp_draw->crop.x || bmp_draw->crop.y || + (bmp_draw->crop.w != bmp_draw->bmp.width) || + (bmp_draw->crop.h != bmp_draw->bmp.height)) { /* Image needs to be cropped */ Image @@ -472,9 +471,9 @@ crop_info.height = bmp_draw->crop.h; handler=SetMonitorHandler((MonitorHandler) NULL); - crop_image = CropImage( image, &crop_info, &exception ); + crop_image = CropImage(image, &crop_info, &exception); (void) SetMonitorHandler(handler); - if(crop_image) + if (crop_image) { DestroyImageList(image); image = crop_image; @@ -484,35 +483,45 @@ CopyException(&ddata->image->exception,&exception); } - (void) QueryColorDatabase( "white", &white, &exception ); - - if ( ddata->image_info->texture || - !(ColorMatch(&ddata->image_info->background_color, &white)) || - ddata->image_info->background_color.opacity != OpaqueOpacity ) - { - /* - Set image white background to transparent so that it may be - overlaid over non-white backgrounds. - */ - (void) TransparentImage( image, white, MaxRGB ); - } + (void) QueryColorDatabase("white", &white, &exception); + + if (ddata->image_info->texture || + !(ColorMatch(&ddata->image_info->background_color, &white)) || + ddata->image_info->background_color.opacity != OpaqueOpacity) + { + /* + Set image white background to transparent so that it may be + overlaid over non-white backgrounds. + */ + (void) TransparentImage(image, white, MaxRGB); + } width = AbsoluteValue(bmp_draw->pixel_width * (double) bmp_draw->crop.w); height = AbsoluteValue(bmp_draw->pixel_height * (double) bmp_draw->crop.h); DrawComposite(WmfDrawContext, CopyCompositeOp, XC(bmp_draw->pt.x), YC(bmp_draw->pt.y), - width, height, image ); - -#if 0 - printf("bmp_draw->bmp.data = 0x%lx\n", (long)bmp_draw->bmp.data); - printf("registry id = %li\n", id); - /* printf("pixel_width = %.4g\n", bmp_draw->pixel_width); */ - /* printf("pixel_height = %.4g\n", bmp_draw->pixel_height); */ - printf("bmp_draw->bmp WxH = %ix%i\n", bmp_draw->bmp.width, bmp_draw->bmp.height); - printf("bmp_draw->crop WxH = %ix%i\n", bmp_draw->crop.w, bmp_draw->crop.h); - printf("bmp_draw->crop x,y = %i,%i\n", bmp_draw->crop.x, bmp_draw->crop.y); - printf("image size WxH = %lux%lu\n", image->columns, image->rows); -#endif + width, height, image); + if (ddata->image->logging) + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + "ipa_bmp_draw\n" + " bmp_draw->bmp.data = 0x%lx\n" + /* " registry id = %li\n" */ + " pixel_width = %.4g\n" + " pixel_height = %.4g\n" + " bmp_draw->bmp WxH = %ix%i\n" + " bmp_draw->crop WxH = %ix%i\n" + " bmp_draw->crop x,y = %i,%i\n" + " image size WxH = %lux%lu", + (long) bmp_draw->bmp.data, + /* id, */ + bmp_draw->pixel_width, + bmp_draw->pixel_height, + bmp_draw->bmp.width, bmp_draw->bmp.height, + bmp_draw->crop.w, bmp_draw->crop.h, + bmp_draw->crop.x, bmp_draw->crop.y, + image->columns, image->rows); + } } static void ipa_bmp_read(wmfAPI * API, wmfBMP_Read_t * bmp_read) { @@ -537,7 +546,7 @@ image_info = CloneImageInfo((ImageInfo *) 0); (void) strlcpy(image_info->magick,"DIB",sizeof(image_info->magick)); - if(bmp_read->width || bmp_read->height) + if (bmp_read->width || bmp_read->height) { char size[MaxTextExtent]; @@ -547,12 +556,12 @@ } #if 0 printf("ipa_bmp_read: buffer=0x%lx length=%ld, width=%i, height=%i\n", - (long) bmp_read->buffer, bmp_read->length, - bmp_read->width, bmp_read->height); + (long) bmp_read->buffer, bmp_read->length, + bmp_read->width, bmp_read->height); #endif handler=SetMonitorHandler((MonitorHandler) NULL); image = BlobToImage(image_info, (const void *) bmp_read->buffer, - bmp_read->length, &exception); + bmp_read->length, &exception); (void) SetMonitorHandler(handler); DestroyImageInfo(image_info); if (!image) @@ -562,7 +571,7 @@ FormatString(description,"packed DIB at offset %ld", bmp_read->offset); ThrowException2(&ddata->image->exception,CorruptImageError, - exception.reason,exception.description); + exception.reason,exception.description); } else { @@ -637,7 +646,7 @@ /* Make SVG output happy */ DrawPushGraphicContext(WmfDrawContext); - DrawSetViewbox(WmfDrawContext, 0, 0, ddata->image->columns, ddata->image->rows ); + DrawSetViewbox(WmfDrawContext, 0, 0, ddata->image->columns, ddata->image->rows); FormatString(comment,"Created by %s", GetMagickVersion((unsigned long *) NULL)); @@ -652,13 +661,13 @@ /* Apply rotation */ DrawRotate(WmfDrawContext, ddata->rotate); - if(ddata->image_info->texture == NULL) + if (ddata->image_info->texture == NULL) { /* Draw rectangle in background color */ DrawSetFillColor(WmfDrawContext,&ddata->image->background_color); DrawRectangle(WmfDrawContext, - XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y), - XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y)); + XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y), + XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y)); } else { @@ -678,12 +687,12 @@ (void) strlcpy(image_info->filename, ddata->image_info->texture, sizeof(image_info->filename)); - if ( ddata->image_info->size ) + if (ddata->image_info->size) (void) CloneString(&image_info->size,ddata->image_info->size); image = ReadImage(image_info,&exception); DestroyImageInfo(image_info); - if(image) + if (image) { char pattern_id[MaxTextExtent]; @@ -699,8 +708,8 @@ ++ddata->pattern_id; DrawRectangle(WmfDrawContext, - XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y), - XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y)); + XC(ddata->bbox.TL.x),YC(ddata->bbox.TL.y), + XC(ddata->bbox.BR.x),YC(ddata->bbox.BR.y)); DestroyImageList(image); } else @@ -727,7 +736,7 @@ *ddata = WMF_MAGICK_GetData(API); /* Reset any existing clip paths by popping context */ - if(ddata->clipping) + if (ddata->clipping) DrawPopGraphicContext(WmfDrawContext); ddata->clipping = False; @@ -777,10 +786,10 @@ draw_color_fill_rgb(API,&(draw_pixel->color)); DrawRectangle(WmfDrawContext, - XC(draw_pixel->pt.x), - YC(draw_pixel->pt.y), - XC(draw_pixel->pt.x + draw_pixel->pixel_width), - YC(draw_pixel->pt.y + draw_pixel->pixel_height)); + XC(draw_pixel->pt.x), + YC(draw_pixel->pt.y), + XC(draw_pixel->pt.x + draw_pixel->pixel_width), + YC(draw_pixel->pt.y + draw_pixel->pixel_height)); /* Restore graphic context */ DrawPopGraphicContext(WmfDrawContext); @@ -1088,8 +1097,8 @@ for (i = 0; i < poly_rect->count; i++) { DrawRectangle(WmfDrawContext, - XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y), - XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y)); + XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y), + XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y)); } } @@ -1117,8 +1126,8 @@ for (i = 0; i < poly_rect->count; i++) { DrawRectangle(WmfDrawContext, - XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y), - XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y)); + XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y), + XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y)); } } @@ -1135,11 +1144,11 @@ *ddata = WMF_MAGICK_GetData (API); /* Reset any existing clip paths by popping context */ - if(ddata->clipping) + if (ddata->clipping) DrawPopGraphicContext(WmfDrawContext); ddata->clipping = False; - if(poly_rect->count > 0) + if (poly_rect->count > 0) { char clip_path_id[MaxTextExtent]; @@ -1153,8 +1162,8 @@ for (i = 0; i < poly_rect->count; i++) { DrawRectangle(WmfDrawContext, - XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y), - XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y)); + XC(poly_rect->TL[i].x), YC(poly_rect->TL[i].y), + XC(poly_rect->BR[i].x), YC(poly_rect->BR[i].y)); } DrawPopGraphicContext(WmfDrawContext); DrawPopClipPath(WmfDrawContext); @@ -1176,8 +1185,8 @@ *FR = (wmfFunctionReference *) API->function_reference; /* - IPA function reference links - */ + IPA function reference links + */ FR->device_open = ipa_device_open; FR->device_close = ipa_device_close; FR->device_begin = ipa_device_begin; @@ -1210,8 +1219,8 @@ FR->region_clip = ipa_region_clip; /* - Allocate device data structure - */ + Allocate device data structure + */ ddata = (wmf_magick_t *) wmf_malloc(API, sizeof(wmf_magick_t)); if (ERR(API)) return; @@ -1220,16 +1229,16 @@ API->device_data = (void *) ddata; /* - Device data defaults - */ + Device data defaults + */ ddata->image = 0; } static void ipa_draw_text(wmfAPI * API, wmfDrawText_t * draw_text) { double - angle = 0, /* text rotation angle */ - pointsize = 0; /* pointsize to output font with desired height */ + angle = 0.0, /* text rotation angle */ + pointsize = 0.0; /* pointsize to output font with desired height */ TypeMetric metrics; @@ -1239,7 +1248,7 @@ bbox_height, /* bounding box height */ bbox_width /* bounding box width */ - wmfD_Coord + wmfD_Coord BL, /* bottom left of bounding box */ BR, /* bottom right of bounding box */ TL, /* top left of bounding box */ @@ -1253,7 +1262,7 @@ *font;