Page 1 of 1

DrawGetVectorGraphics + DrawSetVectorGraphics

Posted: 2015-06-03T04:34:39-07:00
by Danack
Hi,

Not sure if this is a bug, or just weird behaviour. It seems the output of DrawGetVectorGraphics cannot be used as the input for DrawSetVectorGraphics. Instead the text returned must be wrapped with a root node i.e. :

Code: Select all

vector = DrawGetVectorGraphics(drawing_wand_src);
sprintf(encapsulatedGraphics, "<root>%s</root>", vector);
status = DrawSetVectorGraphics(drawing_wand_dst, encapsulatedGraphics);
Please could you either i) say that this behaviour is intentional, and will stay like this forever ii) classify it as a bug and fix it?


cheer
Dan


Full code to reproduce:

Code: Select all


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wand/MagickWand.h>

void ThrowWandException(MagickWand *wand) {
    char *description; 
    ExceptionType severity; 
    description = MagickGetException(wand, &severity);
     
    printf("description is %s \n", description);
     
    (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); 
    description=(char *) MagickRelinquishMemory(description); 
    exit(-1); 
}

PixelWand *makePixelWand(char *string) {
	PixelWand *pixel_wand;
	pixel_wand = NewPixelWand();

	if (PixelSetColor (pixel_wand, string) == MagickFalse) {
		printf("Failed to set color");
		exit(-1);
	}

	return pixel_wand;
}



int main(int argc,char **argv) {

    PixelWand *stroke_color_wand;
    PixelWand *fill_color_wand;
    PixelWand *background_color_wand;
    MagickBooleanType status;
    DrawingWand *drawing_wand_src;
    DrawingWand *drawing_wand_dst;
    char *filename = "vector.png";

    char *vector;
    char encapsulatedGraphics[4096];

    MagickWandGenesis();
  
    drawing_wand_src = NewDrawingWand();

    stroke_color_wand = makePixelWand("red");
    fill_color_wand = makePixelWand("blue");
    DrawSetStrokeColor(drawing_wand_src, stroke_color_wand);
    DrawSetFillColor(drawing_wand_src, fill_color_wand);

    DrawCircle(drawing_wand_src, 50, 50, 100, 100);

    vector = DrawGetVectorGraphics(drawing_wand_src);


    drawing_wand_dst = NewDrawingWand();
    
    //This should work, but doesn't
    //status = DrawSetVectorGraphics(drawing_wand_dst, vector);

    //This works, but isn't documented as needed.
    sprintf(encapsulatedGraphics, "<root>%s</root>", vector);
    status = DrawSetVectorGraphics(drawing_wand_dst, encapsulatedGraphics);


    if (status == MagickFalse) {
        printf("DrawSetVectorGraphics failed.\n");
        return(-1);
    }
    else {
        printf("DrawSetVectorGraphics succeeded.\n");
    }
    
    
    MagickWand *magick_wand;
  
    magick_wand = NewMagickWand();

    background_color_wand = makePixelWand("white");

    status = MagickNewImage(magick_wand, 500, 500, background_color_wand);


    MagickSetImageFormat(magick_wand, "png");

    status = MagickDrawImage(magick_wand, drawing_wand_dst);

    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }
    

    status = MagickWriteImages(magick_wand, filename, MagickTrue);

    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }

    
    MagickWandTerminus();
    return (0);
}

Re: DrawGetVectorGraphics + DrawSetVectorGraphics

Posted: 2015-06-03T05:53:42-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick 6.9.1-5 Beta, available within the next few days. Thanks.