Menu

#24 apostrophe stops spell check in some cases

open
nobody
None
3
2024-05-01
2024-05-01
No

When a single quote (ASCII apostrophe) is at the beginning of a word, subsequent misspelled words are not marked.

I am using Ubuntu MATE 22.04
libgtkspell3-3-0 3.0.10-1
libgtkspell3-3-dev

Compile the C program below with the makefile shown.

If you run the program with no command line arg, you see misspelled words marked properly. Then run it with an argument (any arg),, this inserts a ' char into the text. You will see that after the ' char, imisspelled words are not marked.

Makefile

CFLAGS = `pkg-config --cflags gtk+-3.0`
OBJECTS = tv.o 

default: tv

%.o: %.c
    gcc $(CFLAGS) -c $<

tv: $(OBJECTS)
    gcc $(CFLAGS) $(OBJECTS) `pkg-config --libs gtk+-3.0` \
        /usr/lib/x86_64-linux-gnu/libgtkspell3-3.so -o $@

clean:
    -rm -f $(OBJECTS)
    -rm -f tv

Program

#include <gtk/gtk.h>
#include <gtkspell-3.0/gtkspell/gtkspell.h>

    int
main(int argc, char *argv[])
{
    GtkWidget *window, *text_view, *scrolled_window;
    GtkSpellChecker *spell_checker;
    GtkTextBuffer *buffer;
    GtkTextIter start, end;
    char *cp;

    if (argc > 1)  
        cp = "Here is a sentince 'with rong spelling.\n\nAnd here is some more rong text.\n";
    else
        cp = "Here is a sentince with rong spelling.\n\nAnd here is some more rong text.\n";

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "TextView Example");
    gtk_window_set_default_size (GTK_WINDOW (window), 600, 200);


    buffer = gtk_text_buffer_new (NULL);

    spell_checker = gtk_spell_checker_new();
    g_object_ref_sink(spell_checker);
    gtk_spell_checker_set_language(spell_checker, "en_US", NULL);

    text_view = gtk_text_view_new_with_buffer (buffer);
    gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD); 

    scrolled_window = gtk_scrolled_window_new (NULL, NULL);

    gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
    gtk_container_add (GTK_CONTAINER (window), scrolled_window);

    g_signal_connect_after(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all (window);
    gtk_spell_checker_attach(spell_checker, GTK_TEXT_VIEW(text_view));

    gtk_text_buffer_create_tag(buffer, "large", "scale", PANGO_SCALE_X_LARGE, NULL);
    gtk_text_buffer_set_text(buffer, cp, -1);
    gtk_text_buffer_get_bounds(buffer, &start, &end);
    gtk_text_buffer_apply_tag_by_name(buffer, "large", &start, &end);

    gtk_main();       // main loop

    g_object_unref(spell_checker);

}

Discussion


Log in to post a comment.

MongoDB Logo MongoDB