Unicode

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
ccube

Unicode

Post by ccube »

Hi,

I wonder if there is some unicode support in MagickWand.

I am printing some text onto an image with

Code: Select all

MagickAnnotateImage(mwand, dwand, 0, 20, 0, text);
But text can be only a pointer to a char array, which limits the charset to ASCII I think.
Is there something similar for unicode strings?
Or has MagickWand to be extended first?

As far as I know you can use Unicode charecters with convert etc...

Greetings,

ccube
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Unicode

Post by magick »

See http://www.imagemagick.org/Usage/text/ and scroll down to 'Unicode or UTF8 Format Text Labels'.
ccube

Re: Unicode

Post by ccube »

Yeah thanks. I read this page already. But it doesn't help me, or I rust don't see how it could help me.

I know how to use ImageMagick with my unicode console, but not using unicode in MagickWand.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Unicode

Post by el_supremo »

You can use the unicode strings directly. The program below shows how I used unicode chars with annotate to produce this image:
Image

Pete

Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine)
{

	MagickWand *mw = NULL;
	DrawingWand *dw = NULL;

	unsigned char *str = "Hello Magicians \xc4\x9a\xc5\x90\xc4\x9c \x61\xc4\x85\x63\xc4\x87\x65\xc4\x99\x6c\xc5\x82\x6e\xc5\x84\x6f\xc3\xb3\x73\xc5\x9b\x7a\xc5\xbc\x78\xc5\xba\x00";
	double *fm = NULL;

	MagickWandGenesis();
	mw = NewMagickWand();
	dw = NewDrawingWand();

	// Start with an empty image
	MagickReadImage(mw,"xc:");

	// Set the font information in the drawing wand
	DrawSetFontSize(dw,72);
	DrawSetFont(dw,"Times-New-Roman");

	fm = MagickQueryFontMetrics(mw, dw, str);

	// extend the size of the image - I think this is the right one to use
	// but works for me in this case
	MagickExtentImage(mw,(unsigned long)fm[4],(unsigned long)fm[5],0,0);

	// Annotate the image - Note the calculation of the y value which is 
	// because the font metrics use an origin in the lower left whereas IM has
	// its origin at top left
	// The fontmetrics origin is the *bottom* left of the text and the Y axis
	// is the baseline. Therefore, the bounding box can have a negative Y value
	// if the text contains any descenders which go below the baseline
	MagickAnnotateImage(mw,dw, 0 ,(unsigned int)(fm[8]+ fm[5]), 0.0 ,str);

	// Now write the magickwand image
	MagickWriteImage(mw,"metric.gif");

	if(mw)mw = DestroyMagickWand(mw);
	if(dw)dw = DestroyDrawingWand(dw);
	if(fm)RelinquishMagickMemory(fm);
	MagickWandTerminus();
}
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
ccube

Re: Unicode

Post by ccube »

Yeah, thats clear.
But a real unicode has a 16-Bit length with a possibility of 65535 different characters.
Its hard to save them into a char array. :(

On the attached Picture you can see which chars Im able to print.
But the font has much more chracters on different codepages.
My aim is to access all characters on all codepages.

Image
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Unicode

Post by el_supremo »

But a real unicode has a 16-Bit length
Each pair of bytes in the string is a 16-bit character. For example, the first part is \xc4\x9a\xc5\x90\xc4\x9c which is 3 unicode characters - 0xc49a, 0xc590 and 0xc49c which produce the EOG with accents.
Its hard to save them into a char array
Why?

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
ccube

Re: Unicode

Post by ccube »

Wow, thats tricky.
And its working.

Thanks for helping! :)
Post Reply