[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: miniBidi



On Friday 04 March 2005 21:42, Ahmad Khalifa wrote:

> I see up there that you might be calling doShape yourself ?
> why not let doBidi() do it ?
> if thats the case then you have to copy the original string
> to the destination string first. doBidi() takes care of that
> if you pass applyShape == 1.

I tried that (applyShape = 1) but it seemed to have no effect, maybe I was 
doing something wrong.

I attach a bit of the code (it's a bit of a hack, I'll tidy up later). BTW one 
thing I noticed is that doShape doesn't tell you the length of the returned 
string even though it could be shorter due to ligatures. I didn't notice in 
the code any zero-termination marker either (in doShape). I currently assume 
that the string stays the same length.

=================
	//convert QString to utf16 zero-terminated
	//printf(": qs length is %d\n",s.length());
        int loopc;
	int slength = sizeof(unsigned short) * (s.length() + 1);
	//printf(": slength is %d\n",slength);
	unsigned short* sutf16 = (unsigned short*)malloc(slength);
	unsigned short* sutf16s = (unsigned short*)malloc(slength);
	for( loopc=0; loopc < int(s.length()); loopc++ ) {
	  sutf16[loopc] = s[loopc].unicode();
	  //printf(": char %d is %x\n",loopc,sutf16[loopc]);
	}
	//printf(": mark 0\n");
	sutf16[s.length()] = 0;

	//printf(": do shape\n");
	doShape(sutf16, sutf16s,0,s.length());
	sutf16s[s.length()] = 0;

	//printf(": do bidi\n");
	doBidi(sutf16s, s.length(),0,0,0);
	sutf16s[s.length()] = 0;

	//printf(": back to QString\n");
	news = "";
	for( loopc=0; sutf16s[loopc] != 0; loopc++ ) {
	  QChar newChar((short) sutf16s[loopc]);
	  news = news + newChar;
	  //printf(": add char %x\n",newChar.unicode());
	}

	free(sutf16);
	free(sutf16s);

	return news;
======================



> 4024 probably was there before the doShape() call.
>
I don't think so but I can't promise:-) By the way I found that I had to call 
shape first - the inline comments seem to suggest calling doBidi before 
doShape.

> I know that copying the string can be dodged by copying
> each char in the doShape() iterations, but I had a motive for
> that which I cant seem to remember, so if I cant remember it by
> next week I'll move the string copying thing inside doShape()
> and you wont have to do it yourself.
>
> BTW, whats that QString you're using ? take a look at this...
>
> [code]
> /*
>   * Datatype Extension Macros
>   */
> #define BLOCKTYPE unsigned short*
> #define CHARTYPE unsigned short
> #define GETCHAR(from,i) from[i]
> [/code]
>
> at the begining of minibidi.c you'll find these macros, if you can fit
> QString's usage into these macros, you can call doBidi directly on a
> QString, i.e doBidi will use the QString and you wont have to copy to
> another array. is there an online doc for it ? something like an MSDN
> page or doxygen ?

QString is Qt's string class - I see what you mean and it might be possible. 
QString does have the [] operator but it returns a QChar that needs to have 
its unicode() function called to return the 16bit val. The docs are here:

http://www.handhelds.org/~zecke/apidocs/qt/qstring.html

thanks again
wassalaam
abdulhaq