Page 1 of 1

Unicode

Posted: 2008-12-13T10:17:08-07:00
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

Re: Unicode

Posted: 2008-12-13T10:42:23-07:00
by magick
See http://www.imagemagick.org/Usage/text/ and scroll down to 'Unicode or UTF8 Format Text Labels'.

Re: Unicode

Posted: 2008-12-13T12:52:34-07:00
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.

Re: Unicode

Posted: 2008-12-13T15:13:14-07:00
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();
}

Re: Unicode

Posted: 2008-12-14T10:20:39-07:00
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

Re: Unicode

Posted: 2008-12-14T11:04:54-07:00
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

Re: Unicode

Posted: 2008-12-14T11:18:05-07:00
by ccube
Wow, thats tricky.
And its working.

Thanks for helping! :)