Fwd: Using GtkTextTags with Cursive script like Arabic


I sent this query to the i18list, but received no response.  Maybe it
is more of a generic issue with GtkTextTags, so I thought I will post
it to this list.

Please do let me know if you have any comments on this problem.


I'm trying to allow rich-text editing in a GtKTextView using
GtkTextTags.  What I want is that for every character typed, I listen
to the key-press-event, and then I ask the GtkIMContext to filter the
keypress, and if it handles it well, I apply a GtkTextTag with some
text attribute (such as Underline) to the text in the GtkTextBuffer.

I wrote a small code for this, followed at the end of this mail.  This
works fine when I'm typing English.  But as soon as I start typing
Arabic, the cursive nature of the script is lost.  That is, all the
typed characters remai independent ones, and don't join autumatically
as I type.  Note that if I don't apply the GtkTextTag, then it works
fine.  So the problem lies in the way I'm applying the tags.

Could you please tell me where I went wrong?


here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>

static gboolean mykeypressed(GtkWidget *widget, GdkEvent *event, gpointer data)
        if (gtk_im_context_filter_keypress(GTK_TEXT_VIEW(data)->im_context,
                GtkTextIter iterAfter, iterBefore;
                GtkTextBuffer *tBuf =
                gtk_text_buffer_get_start_iter(tBuf, &iterBefore);
                gtk_text_buffer_get_end_iter(tBuf, &iterAfter);
                GtkTextTag *styleTag = gtk_text_buffer_create_tag
(tBuf, NULL, NULL);
                g_object_set(G_OBJECT(styleTag), "underline",
                gtk_text_buffer_apply_tag(tBuf, styleTag, &iterBefore,
                return TRUE;

        return FALSE;

int main( int   argc,
                char *argv[] )

        GtkWidget *window;
        GtkWidget *vbox;
        GtkWidget *text_view;

        gtk_init (&argc, &argv);

        /* create a new window */
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_widget_set_size_request (GTK_WIDGET (window), 200, 100);
        gtk_window_set_title (GTK_WINDOW (window), "Typing Arabic");
        g_signal_connect (G_OBJECT (window), "destroy",
                        G_CALLBACK (gtk_main_quit), NULL);
        g_signal_connect_swapped (G_OBJECT (window), "delete_event",
                        G_CALLBACK (gtk_widget_destroy),
                        G_OBJECT (window));

        vbox = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (window), vbox);
        gtk_widget_show (vbox);

        /* create a text entry */
        text_view = gtk_text_view_new();
        gtk_box_pack_start (GTK_BOX (vbox), text_view, TRUE, TRUE, 0);
        gtk_widget_show (text_view);
        GtkTextBuffer *tBuf =
        g_signal_connect (G_OBJECT (text_view), "key-press-event",
                        G_CALLBACK (mykeypressed), (gpointer)text_view);

        /* show the window */
        gtk_widget_show (window);


        return 0;

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