26.2.07

A patch to fix some Bidi-text issues in Gaim2

It has been 2 years since I reported bug #1121620 to the Gaim Bug Tracker. I expected that someone will resolve it for Gaim 2.0 but the issue was ignored. A friend told me last week that he doesn't like Gaim because of it's bad Hebrew support in MSN Messenger protocol. I decided that this itch just got too itchy to ignore. So, I looked into it during the weekend and realized I know how to fix it, and so I wrote this patch.

This patch doesn't only fix the problem described in bug #1121620 but also resolves the problems with displaying RTL messages on Gaim's IMHtml Widget.

Before my patch MSN conversation used to look like this:


Notice that the direction of the text was automatically (and correctly) detected in the text input field on the bottom. However, the conversation window displays all lines aligned to the left and the text direction is always LTR - therefore RTL text which includes embedded English words (LTR) becomes unreadable because the words are displayed in the wrong order.

The MSN Messenger user will also see the text displayed using the wrong alignment and the wrong direction:

The patch above will fix all these issues. After patching your Gaim, the above conversation will look like this:

And the MSN Messenger user will see the text displayed correctly:


The Code

Writing the patch was a little tricky - some of the code in there may seem like an ugly hack and there's probably a better way of doing some things. But that's the best I could do with my basic knowledge in GTK and Gaim API.

In this patch I implemented the following:

* Added support for [SPAN dir="rtl"] tag in the parser of the IMHtml Widget. (AFAIK this HTML tag is deprecated, but most browsers implement it and it beats coding CSS support)

* Added text direction detection to outgoing messages and send it with the correct SPAN tag.

* Added support for the "RL=1" flag in Messenger protocol implementation, both in sending and receiving messages.

* Fixed some display issues: Insert RLM and RLE Unicode characters to the conversation display according to the expected alignment and direction.

UPDATE:

Now timestamps will show up on the right side:

in the screenshot:
Hebrew alias + English text
Hebrew alias + Hebrew text
English alias + English text
English alias + Hebrew text

16 comments:

Anonymous said...

Hello Shlomi,

Have you tryed to submit this patch to gaim developers -> include it in the mainstream version?

I think this is great patch and I'll try it, but if the installation requires to download gaim code, patching it and then compilation, it will not be easy for most of users (even experienced one).

shlomil said...

Hi Artyom!

The patch was submitted to Gaim devs: patch #1668681. Now I'm waiting for Gaim devs to comment on the third version of the patch.

Using the patch does require compiling Gaim from source, and I don't expect users to be able to do it themselves, that's why I try to get it accepted to Gaim.

Anonymous said...

Thanks,

It would be one of the most important improvements in Hebrew support in Gaim in recent years. :)

Meanwhile I use gaim-bidi-plugin to solve the issue.

shlomil said...

What "gaim-bidi-plugin"?
Do you refer to the plugin which inserts a newline? That one doesn't doesn't solve the problem in the MSN protocol level.

Anonymous said...

Yes,I mean the plugin that inserts newline.

I just do not use MSN, I use mostly ICQ (when I use it at all)

shlomil said...

Someone told me that there is no way to specify text direction in ICQ protocol.

I wonder if that's true ... because if it's not, the problem is also fixable for ICQ.

Anonymous said...

Unfortunatly I do not know too much on ICQ protocol.

Anyway this solutions would be usefull for ICQ too (I think)

shlomil said...

Patch was ported to Pidgin:
http://developer.pidgin.im/ticket/78

Anonymous said...

That's AWSOME!!! THANK YOU SHLOMI! THANK YOU THANK YOU THANK YOU!

poopenshaft said...

Great job! I can finally drop M$ Windows lol
So this patch should be incorporated into the coming final release?

shlomil said...

Yup.
Next Pidgin release.

Udi Oron said...

Works great on Ubuntu Feisty.

Good job!

Udi

Roee A. said...

Hi Shlomi

Can you explain how to download an application for re compile gaim with new patch?

shlomil said...

No. I recommend installing the packages from the distribution. These will be available soon enough.

Roee A. said...

When will it be distributed?

shlomil said...

The next generation of all new Linux Distributions will probably include Pidgin (Gaim 2) which includes this patch.