[ icewm-Patches-1440618 ] bidi support (fribidi)

"SourceForge.net" <[email protected]> Wed, 16 Dec 2009 12:36:32 +0000
Newsgroups gmane.comp.window-managers.icewm.devel
Message-ID <[email protected]>
Patches item #1440618, was opened at 2006-03-01 00:13
Message generated for change (Comment added) made by gilboa
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=300031&aid=1440618&group_id=31

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: another bloating feature
Group: None
Status: Open
Resolution: None
Priority: 4
Private: No
Submitted By: Tzafrir Cohen (tzafrir)
Assigned to: Nobody/Anonymous (nobody)
Summary: bidi support (fribidi)

Initial Comment:
LAnguages such as Hebrew and Arabic are written from
right to left. Hence processing them requires
"bidirectiona" text rendering: the text flows in some
cases from left to right and in others: from left to right.

fribidi is one of the libraries used for bidirectional
text rendering. It is used in, e.g., GTK. It provides
methods for converting logical text string (the text as
it is stored) to a visual string (the text as it is
displayed, after rearanges). 

In IceWM texts are all very simple: all of them are in
a single line, and normally without special formatting.
Thus all that is needed to be done for bidirectional
rendering is to filter them once (exactly once) through
fribidi's log2vis function. And this is what this
function does.

This is a preliminary patch against 1.2.21pre1 (the
version in Debian Sarge) which I have installed.

Note that the patch only handles the case of UTF-8. 

Possible optimization: only filter through it strings
with right-to-left characters.

----------------------------------------------------------------------

Comment By: Gilboa Davara (gilboa)
Date: 2009-12-16 14:36

Message:
--- src/yfontxft.cc.old 2009-09-25 00:07:51.000000000 +0300                
                          
+++ src/yfontxft.cc     2009-09-25 00:18:09.000000000 +0300               
                           
@@ -6,6 +6,11 @@                                                          
                           
 #include "ypaint.h"                                                      
                           
 #include "yxapp.h"                                                       
                           
 #include "intl.h"                                                        
                           
+#include <stdio.h>                                                       
                           
+                                                                         
                           
+#ifdef CONFIG_FRIBIDI                                                    
                           
+    #include <fribidi/fribidi.h>                                         
                           
+#endif                                                                   
                           
                                                                          
                           

/******************************************************************************/
                    
                                                                          
                           
@@ -68,10 +73,45 @@                                                       
                           
                            char_t * str, size_t len)                     
                           
     {                                                                    
                           
         XftColor *c = *g.color();                                        
                           
+                                                                         
                           
+#ifdef CONFIG_FRIBIDI                                                    
                           
+                                                                         
                           
+#define STATIC_STRING_SIZE     256                                       
                           
+                                                                         
                           
+               // Based around upstream (1.3.2) patch with some
optimization                         
+               //   on my end. (reduce unnecessary memory allocation)    
                           
+               // - Gilboa                                               
                           
+                                                                         
                           
+               char_t static_str[STATIC_STRING_SIZE];                    
                           
+               char_t *vis_str = static_str;                             
                           
+                                                                         
                           
+               if (len >= STATIC_STRING_SIZE)                            
                           
+               {                                                         
                           
+                       vis_str = new char_t[len+1];                      
                           
+                       if (!vis_str)                                     
                           
+                               return;                                   
                           
+               }                                                         
                           
+                                                                         
                           
+               FriBidiCharType pbase_dir = FRIBIDI_TYPE_N;               
                           
+               fribidi_log2vis(str, len, &pbase_dir, //input             
                           
+                                               vis_str, // output        
                           
+                                               NULL, NULL, NULL //
"statistics" that we don't need   
+                                               );
+               str = vis_str;
+#endif
+
         XftDrawString(g.handleXft(), c, font,
                       x - g.xorigin(),
                       y - g.yorigin(),
                       str, len);
+
+#ifdef CONFIG_FRIBIDI
+
+               if (vis_str != static_str)
+                       delete[] str;
+
+#endif
+
     }

     static void textExtents(XftFont * font, char_t * str, size_t len,
--- configure.in.old    2009-09-25 00:05:08.000000000 +0300
+++ configure.in        2009-09-25 00:07:14.000000000 +0300
@@ -307,6 +307,20 @@
       features="${features} i18n"
 fi

+dnl =================================================== Right to left
support ===
+dnl
+AC_ARG_ENABLE(fribidi,
+  [  --disable-fribidi       Disable right to left support])
+
+if test "$enable_fribidi" != "no" && test "$enable_i18n" != "no"; then
+  PKG_CHECK_MODULES(FRIBIDI, fribidi)
+
+  AC_DEFINE(CONFIG_FRIBIDI,1, [Define to enable fribidi support])
+
+  CORE_CFLAGS="${CORE_CFLAGS} ${FRIBIDI_CFLAGS}"
+  CORE_LIBS="${CORE_LIBS} ${FRIBIDI_LIBS}"
+fi
+
 dnl ============================================================ NLS
Support ===
 dnl
 AC_ARG_ENABLE(nls,


----------------------------------------------------------------------

Comment By: Gilboa Davara (gilboa)
Date: 2009-12-16 14:35

Message:
In case anyone wants to apply a patch against previous versions of icewm
(1.2.x tree), the following patch was used to fix RTL issues in Fedora.

Patch attached.

----------------------------------------------------------------------

Comment By: Usama Akkad (uaa)
Date: 2008-08-28 10:29

Message:
Logged In: YES 
user_id=2188446
Originator: NO

Developers please look at the batch it works fine for the Arabic users.


----------------------------------------------------------------------

Comment By: Khaled Hosny (khaledhosny)
Date: 2008-08-24 01:30

Message:
Logged In: YES 
user_id=1669997
Originator: NO

Sorry for the spam, but he comments are wrapped witch breaks the patch, so
I uploaded it here http://www.khaledhosny.org/files/fribidi.patch as I'm
yet to figure how to attach a patch!

----------------------------------------------------------------------

Comment By: Khaled Hosny (khaledhosny)
Date: 2008-08-24 01:21

Message:
Logged In: YES 
user_id=1669997
Originator: NO

Updated the patch per comment in
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=362994#20

==== CUT HERE ====
diff -Naur icewm-1.3.2/configure.in icewm-1.3.2~/configure.in
--- icewm-1.3.2/configure.in	2007-12-27 20:51:56.000000000 +0200
+++ icewm-1.3.2~/configure.in	2008-08-23 19:01:33.000000000 +0300
@@ -307,6 +307,20 @@
       features="${features} i18n"
 fi
 
+dnl =================================================== Right to left
suport ===
+dnl
+AC_ARG_ENABLE(fribidi,
+  [  --disable-fribidi       Disable right to left support])
+      
+if test "$enable_fribidi" != "no" && test "$enable_i18n" != "no"; then
+  PKG_CHECK_MODULES(FRIBIDI, fribidi)
+
+  AC_DEFINE(CONFIG_FRIBIDI,1, [Define to enable fribidi support])
+        
+  CORE_CFLAGS="${CORE_CFLAGS} ${FRIBIDI_CFLAGS}"
+  CORE_LIBS="${CORE_LIBS} ${FRIBIDI_LIBS}"
+fi
+
 dnl ============================================================ NLS
Support ===
 dnl
 AC_ARG_ENABLE(nls,
diff -Naur icewm-1.3.2/src/yfontxft.cc icewm-1.3.2~/src/yfontxft.cc
--- icewm-1.3.2/src/yfontxft.cc	2007-12-27 20:51:56.000000000 +0200
+++ icewm-1.3.2~/src/yfontxft.cc	2008-08-23 18:56:14.000000000 +0300
@@ -6,6 +6,11 @@
 #include "ypaint.h"
 #include "yxapp.h"
 #include "intl.h"
+#include <stdio.h>
+
+#ifdef CONFIG_FRIBIDI
+    #include <fribidi/fribidi.h>
+#endif
 

/******************************************************************************/
 
@@ -69,10 +74,26 @@
                            char_t * str, size_t len)
     {
         XftColor *c = *g.color();
+#ifdef CONFIG_FRIBIDI
+        char_t *vis_str = new char_t[len+1];
+        if (vis_str != NULL) {
+          FriBidiCharType pbase_dir = FRIBIDI_TYPE_N;
+          fribidi_log2vis(str, len, &pbase_dir, //input
+              vis_str, // output
+              NULL, NULL, NULL // "statistics" that we don't need
+          );
+          str = vis_str;
+        }
+#endif
         XftDrawString(g.handleXft(), c, font,
                       x - g.xorigin(),
                       y - g.yorigin(),
                       str, len);
+#ifdef CONFIG_FRIBIDI
+        if (vis_str != NULL)
+          vis_str[len] = 0;
+          delete[] vis_str;
+#endif 
     }
 
     static void textExtents(XftFont * font, char_t * str, size_t len,
==== CUT HERE ====

----------------------------------------------------------------------

Comment By: Khaled Hosny (khaledhosny)
Date: 2008-08-23 19:50

Message:
Logged In: YES 
user_id=1669997
Originator: NO

I dunno why I can't attach a file here, so here is the patch. 
Note: it will detect only fribidi-0.19.1 since older releases doesn't use
pkg-config, it isn't a problem for Arabic since fribidi pre 0.19.1 doesn't
support Arabic shaping any way.

==== CUT HERE ====
diff -Naur icewm-1.3.2/configure.in icewm-1.3.2~/configure.in
--- icewm-1.3.2/configure.in    2007-12-27 20:51:56.000000000 +0200
+++ icewm-1.3.2~/configure.in   2008-08-23 19:01:33.000000000 +0300
@@ -307,6 +307,20 @@
       features="${features} i18n"
 fi

+dnl =================================================== Right to left
suport ===
+dnl
+AC_ARG_ENABLE(fribidi,
+  [  --disable-fribidi       Disable right to left support])
+      
+if test "$enable_fribidi" != "no" && test "$enable_i18n" != "no"; then
+  PKG_CHECK_MODULES(FRIBIDI, fribidi)
+
+  AC_DEFINE(CONFIG_FRIBIDI,1, [Define to enable fribidi support])
+        
+  CORE_CFLAGS="${CORE_CFLAGS} ${FRIBIDI_CFLAGS}"
+  CORE_LIBS="${CORE_LIBS} ${FRIBIDI_LIBS}"
+fi
+
 dnl ============================================================ NLS
Support ===
 dnl
 AC_ARG_ENABLE(nls,
diff -Naur icewm-1.3.2/src/yfontxft.cc icewm-1.3.2~/src/yfontxft.cc
--- icewm-1.3.2/src/yfontxft.cc 2007-12-27 20:51:56.000000000 +0200
+++ icewm-1.3.2~/src/yfontxft.cc        2008-08-23 18:56:14.000000000
+0300
@@ -6,6 +6,11 @@
 #include "ypaint.h"
 #include "yxapp.h"
 #include "intl.h"
+#include <stdio.h>
+
+#ifdef CONFIG_FRIBIDI
+    #include <fribidi/fribidi.h>
+#endif


/******************************************************************************/

@@ -69,10 +74,26 @@
                            char_t * str, size_t len)
     {
         XftColor *c = *g.color();
+#ifdef CONFIG_FRIBIDI
+        char_t *vis_str = new char_t[len+1];
+        if (vis_str != NULL) {
+          FriBidiCharType pbase_dir = FRIBIDI_TYPE_N;
+          fribidi_log2vis(str, len, &pbase_dir, //input
+              vis_str, // output
+              NULL, NULL, NULL // "statistics" that we don't need
+          );
+          str = vis_str;
+        }
+        vis_str[len] = 0;
+#endif
         XftDrawString(g.handleXft(), c, font,
                       x - g.xorigin(),
                       y - g.yorigin(),
                       str, len);
+#ifdef CONFIG_FRIBIDI
+        if (vis_str != NULL)
+          delete vis_str;
+#endif 
     }

     static void textExtents(XftFont * font, char_t * str, size_t len,
==== CUT HERE ====

----------------------------------------------------------------------

Comment By: Khaled Hosny (khaledhosny)
Date: 2008-08-23 19:32

Message:
Logged In: YES 
user_id=1669997
Originator: NO

This an updated version of the patch against icwm-1.3.2, now fribidi
support can be disabled at build time (it is on by default if i18n is
enabled), I also used simple 'diff' instead of dpatch.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=300031&aid=1440618&group_id=31

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev