Bug 156558 - libthai dynamic loading and work breaking related problems
Summary: libthai dynamic loading and work breaking related problems
Status: RESOLVED WAITINGFORINFO
Alias: None
Product: konqueror
Classification: Applications
Component: khtml (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-24 16:56 UTC by Pattara Kiatisevi
Modified: 2011-06-24 16:01 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to fix Thai word break related problems in KHTML (2.87 KB, patch)
2008-01-24 16:57 UTC, Pattara Kiatisevi
Details
Fix KLibLoader - libthai + libthai th_brk return value issues (1.45 KB, patch)
2008-01-26 06:10 UTC, Pattara Kiatisevi
Details
khtml thai word break using Qt 4.4 / Harfbuzz instead of libthai (1.58 KB, patch)
2008-08-28 10:31 UTC, Pattara Kiatisevi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pattara Kiatisevi 2008-01-24 16:56:27 UTC
Version:            (using KDE 4.0.0)
Installed from:    Ubuntu Packages

This patch (by Jakkapun Kwanroengjai) fixes the following problems Thai word breaking problems in KDE 4

1. The existing code uses "KLibLoder" to dynamically load libthai Thai library (if libthai is not linked since compile time). And KLibLoader requires "libthai.la", which is 

a) usually in the libthai-dev package of distros -- making it weird for users having to install the devel package just to use the library 

b) recently not shippped at all in some distros, e.g., Debian, Ubuntu, resulting in broken Thai word breaking support in KDE/KHTML.

The patch changes the code to load the library using "QLibrary" which 

i) does not require libthai.la to work

ii) allows specifying the library version number, e.g., libthai.so.0, eleminating the need to install "libthai-dev" package at all (if it looks for "libthai.so" then we will still need libthai-dev package)

2) There was a bug in this part of code (excerpted from the patch):

             cache->numwbrpos = th_brk((const unsigned char*) cstr.data(), cache->wbrpos, cache->allocated);
             //fprintf(stderr,"libthai returns with value %d\n",cache->numwbrpos);
-            if (cache->numwbrpos > cache->allocated) {
-                cache->allocated = cache->numwbrpos;
+            if (cache->numwbrpos >= cache->allocated) {
+                cache->allocated = len;
                 cache->wbrpos = (int *)realloc(cache->wbrpos, cache->allocated*sizeof(int));
                 cache->numwbrpos = th_brk((const unsigned char*) cstr.data(), cache->wbrpos, cache->allocated);
             }

We misunderstood that th_brk would return the actual number of breakable positions in the string regardless of the input parameter "cache->allocated", which denotes the size of the array cache->wbrpos in which the break positions should be stored. But after discussing with libthai developers, we realized that this return value will always be less than or equal the "cache->allocated" value. Therefore the patch will fix the algorithm to realloc the array to the string length ("len" variable) in such cases that the return value is equal to cache->allocated.

Ref:
[1] <a href=https://bugs.kde.org/show_bug.cgi?id=86199>Bug 86199: Thai word break support in KHTML</a>
Comment 1 Pattara Kiatisevi 2008-01-24 16:57:31 UTC
Created attachment 23241 [details]
Patch to fix Thai word break related problems in KHTML

By Jakkapun Kwangroengjai
Comment 2 Maksim Orlovich 2008-01-24 17:47:09 UTC
Is this really about KDE4, or KDE3? KLibLoader in KDE4 does not use libtool files.
Comment 3 Pattara Kiatisevi 2008-01-24 18:12:50 UTC
Aow, right, okay, sorry. Maybe it was another problem (likely the library "path") with KDE4's KLibLoader. Will test more and come up with an updated patch. Thanks.
Comment 4 Pattara Kiatisevi 2008-01-26 06:07:42 UTC
It was that PATH problem, KLibLoader didn't look for libthai in /usr/lib. The new attached patch uses KLibLoader and tries to find libthai at /usr/lib if the first attempt failed.
Comment 5 Pattara Kiatisevi 2008-01-26 06:10:11 UTC
Created attachment 23292 [details]
Fix KLibLoader - libthai + libthai th_brk return value issues
Comment 6 Pattara Kiatisevi 2008-08-28 10:31:36 UTC
Created attachment 27098 [details]
khtml thai word break using Qt 4.4 / Harfbuzz instead of libthai

Use Qt 4.4 / Harfbuzz for Thai word breaking (which will in turn use libthai external library) instead of loading libthai directly in KHTML.

(Patch by Thanomsub Noppaburana)

Please kindly review, cheers, 
Pattara
Comment 7 Pattara Kiatisevi 2009-09-20 06:38:27 UTC
Any comment with the patch?

Commit it?
Comment 8 Martin Koller 2011-06-24 16:01:17 UTC
If this patch is still valid for current KDE, please put it on reviewboard.kde.org, otherwise it is getting lost.