[openbox] LIGHT arabic patch

Mohammed Sameer uniball at gmx.net
Fri Oct 22 23:44:54 EDT 2004


On Mon, Oct 18, 2004 at 04:12:17AM +0200, Mikael Magnusson wrote:
> On Mon, 18 Oct 2004, Mohammed Sameer wrote:
> 
> >Hi,
> >
> >Let me 1st introduce myself, I'm Mohammed, I wrote the initial patch.
> >
> >Yes pango is using fribidi, Pango has a stripped down version of fribidi 
> >to do the shaping. I still don't know how bidi is done.
> >
> >When I wrote the initial patch, I didn't want to add a huge dependency 
> >as pango, And at the same time, I didn't know much about openbox 
> >internals. And we wanted to cook something fast to support Arabic as it 
> >was the primary goal.
> >
> >But I think that using pango is a nice idea, So openbox'll support most 
> >scripts out there, Not just Arabic, But I may need someone to guide me 
> >through the openbox internals.
> >
> >Also while we are at the point, Why not also draw the menus with pango ? 
> >I think this can help in i18n and/or l10n.
> 
> Openbox uses the same functions to draw all text, so if you fix that, 
> everything will use it probably.
> 
> >So it's OK for me, I can try to rewrite the patch to use pango, Let me 
> >be honest, I didn't do anything with pango before, So I may not succeed, 
> >But I'll try hard, And probably I'll need help!
> 
> As you may or may not know, I didn't write most of openbox, but i picked 
> up maintainership after ben decided to do "other things", so I'm not very 
> acquainted with the font functions myself, I've mostly looked at the logic 
> parts so far. I'll try to help if I can. If you use IRC, it's #openbox on 
> irc.oftc.net for faster replies most of the time.
> 

Sorry for being late.

Well, I didn't even know that you are the current maintainer, But now I do! :-)

Here's an alpha patch, The only problem is that I didn't know how to convert xftfont to pangofont, I'm still trying to find a way. That's why the strings are being drawn but incomplete!

I think I'll have to change the _RrFont struct and/or all/most of the font handling API, But as I'm sure you'll hate me if I do.
I've tested the patch for a few minutes and it was fine.

I'll continue working on it, But I'm just busy with my papers these days.

-- 
----------------
-- Katoob Main Developer, Arabbix Maintainer.
Linux registered user #224950
Proud Egyptian GNU/Linux User Group <www.eglug.org> Admin.
Life powered by Debian, Homepage: www.foolab.org
--
Don't send me any attachment in Micro$oft (.DOC, .PPT) format please
Read http://www.fsf.org/philosophy/no-word-attachments.html
Preferable attachments: .PDF, .HTML, .TXT
Thanx for adding this text to Your signature
-------------- next part --------------
diff -Naur -x '*.m4' -x configure -x Makefile.in openbox-3.2.orig/configure.ac openbox-3.2/configure.ac
--- openbox-3.2.orig/configure.ac	2004-04-17 13:44:21.000000000 +0200
+++ openbox-3.2/configure.ac	2004-10-23 05:26:02.000000000 +0200
@@ -73,6 +73,10 @@
 PKG_CHECK_MODULES([GLIB], [glib-2.0])
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
+
+PKG_CHECK_MODULES([PANGO], [pango pangoxft])
+AC_SUBST(PANGO_CFLAGS)
+AC_SUBST(PANGO_LIBS)
 	
 PKG_CHECK_MODULES(XFT, [xft])
 AC_SUBST(XFT_CFLAGS)
diff -Naur -x '*.m4' -x configure -x Makefile.in openbox-3.2.orig/Makefile.am openbox-3.2/Makefile.am
--- openbox-3.2.orig/Makefile.am	2003-10-27 22:14:30.000000000 +0200
+++ openbox-3.2/Makefile.am	2004-10-23 05:29:39.000000000 +0200
@@ -42,6 +42,7 @@
 	render/libobrender.la \
 	$(XFT_LIBS) \
 	$(GLIB_LIBS) \
+	$(PANGO_LIBS) \
 	$(XML_LIBS) \
 	$(X_LIBS)
 render_rendertest_SOURCES = render/test.c
@@ -51,6 +52,7 @@
 	$(XFT_CFLAGS) \
 	$(GLIB_CFLAGS) \
 	$(XML_CFLAGS) \
+	$(PANGO_CFLAGS) \
 	-DG_LOG_DOMAIN=\"ObRender\" \
 	-DDEFAULT_THEME=\"$(theme)\"
 render_libobrender_la_LDFLAGS = \
@@ -113,6 +115,7 @@
 	$(VIDMODE_LIBS) \
 	$(XSHAPE_LIBS) \
 	$(GLIB_LIBS) \
+	$(PANGO_LIBS) \
 	$(X_LIBS) \
 	$(LIBSN_LIBS) \
 	$(XML_LIBS) \
diff -Naur -x '*.m4' -x configure -x Makefile.in openbox-3.2.orig/render/font.c openbox-3.2/render/font.c
--- openbox-3.2.orig/render/font.c	2004-04-01 23:50:11.000000000 +0200
+++ openbox-3.2/render/font.c	2004-10-23 05:30:44.000000000 +0200
@@ -55,6 +55,7 @@
 
 static void measure_font(RrFont *f)
 {
+/* xOff, yOff is the normal spacing to the next glyph. */
     XGlyphInfo info;
 
     /* measure an elipses */
@@ -176,6 +177,15 @@
     size_t l;
     gboolean shortened = FALSE;
 
+    PangoLayout *pl;
+    PangoLayoutLine *pll;
+    PangoContext *context;
+    GSList *p;
+
+    /* TODO: How to Destroy the PangoContext ? */
+    context = pango_xft_get_context (RrDisplay(t->font->inst), RrScreen(t->font->inst));
+    pl = pango_layout_new (context);
+
     /* center vertically */
     y = area->y +
         (area->height - RrFontHeight(t->font)) / 2;
@@ -216,6 +226,10 @@
 
     l = strlen(text->str); /* number of bytes */
 
+    pango_layout_set_text(pl, text->str, l);
+    pango_layout_set_single_paragraph_mode(pl, TRUE);
+    pll = pango_layout_get_line(pl, 0);
+
     if (t->font->shadow) {
         if (t->font->tint >= 0) {
             c.color.red = 0;
@@ -232,9 +246,24 @@
             c.pixel = WhitePixel(RrDisplay(t->font->inst),
                                  RrScreen(t->font->inst));
         }  
-        XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->font->offset,
-                          t->font->xftfont->ascent + y + t->font->offset,
-                          (FcChar8*)text->str, l);
+
+    for (p = pll->runs; p != NULL; p = p->next)
+        {
+            PangoLayoutRun *run = p->data;
+            PangoFont *font = run->item->analysis.font;
+            PangoGlyphString *glyphs = run->glyphs;
+            PangoRectangle rect;
+
+            pango_glyph_string_extents (glyphs, font, NULL, &rect);
+                pango_xft_render (d, &c, font, glyphs, x + t->font->offset, t->font->xftfont->ascent + y + t->font->offset);
+            x += rect.width / PANGO_SCALE;
+        }
+
+        /*        XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->font->offset,
+                        t->font->xftfont->ascent + y + t->font->offset,
+                        (FcChar8*)text->str, l);
+        */
+
     }  
     c.color.red = t->color->r | t->color->r << 8;
     c.color.green = t->color->g | t->color->g << 8;
@@ -242,9 +271,25 @@
     c.color.alpha = 0xff | 0xff << 8; /* fully opaque text */
     c.pixel = t->color->pixel;
 
-    XftDrawStringUtf8(d, &c, t->font->xftfont, x,
-                      t->font->xftfont->ascent + y,
-                      (FcChar8*)text->str, l);
+    for (p = pll->runs; p != NULL; p = p->next)
+        {
+            PangoLayoutRun *run = p->data;
+            PangoFont *font = run->item->analysis.font;
+            PangoGlyphString *glyphs = run->glyphs;
+            PangoRectangle rect;
+
+            pango_glyph_string_extents (glyphs, font, NULL, &rect);
+                pango_xft_render (d, &c, font, glyphs, x, t->font->xftfont->ascent + y);
+            x += rect.width / PANGO_SCALE;
+        }
+
+    /*    XftDrawStringUtf8(d, &c, t->font->xftfont, x,
+          t->font->xftfont->ascent + y,
+          (FcChar8*)text->str, l);
+    */
+
+    pango_layout_line_unref(pll);
+    g_object_unref(pl);
 
     g_string_free(text, TRUE);
     return;
diff -Naur -x '*.m4' -x configure -x Makefile.in openbox-3.2.orig/render/font.h openbox-3.2/render/font.h
--- openbox-3.2.orig/render/font.h	2003-10-15 05:59:35.000000000 +0200
+++ openbox-3.2/render/font.h	2004-10-22 04:46:27.000000000 +0200
@@ -21,6 +21,7 @@
 #define __font_h
 #include "render.h"
 #include "geom.h"
+#include <pango/pango.h>
 
 struct _RrFont {
     const RrInstance *inst;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://icculus.org/pipermail/openbox/attachments/20041023/164b4595/attachment.pgp>


More information about the openbox mailing list