Ejemplo n.º 1
0
/* Extends the definition of a natural-language word used by Pango. The
 * underscore is added to the possible characters of a natural-language word.
 */
void
_gtk_source_iter_forward_extra_natural_word_end (GtkTextIter *iter)
{
	GtkTextIter next_word_end = *iter;
	GtkTextIter next_underscore_end = *iter;
	GtkTextIter *limit = NULL;
	gboolean found;

	if (gtk_text_iter_forward_visible_word_end (&next_word_end))
	{
		limit = &next_word_end;
	}

	found = gtk_text_iter_forward_search (iter,
					      "_",
					      GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY,
					      NULL,
					      &next_underscore_end,
					      limit);

	if (found)
	{
		*iter = next_underscore_end;
	}
	else
	{
		*iter = next_word_end;
	}

	while (TRUE)
	{
		if (gtk_text_iter_get_char (iter) == '_')
		{
			gtk_text_iter_forward_visible_cursor_position (iter);
		}
		else if (gtk_text_iter_starts_word (iter))
		{
			gtk_text_iter_forward_visible_word_end (iter);
		}
		else
		{
			break;
		}
	}
}
Ejemplo n.º 2
0
Archivo: myre.c Proyecto: vobiscum/myre
void
my_text_buffer_highlight(GtkTextBuffer *buffer, char *word, short mode) {
    /*mode: 0:title/occurance 1:title 2:keyword, 3:invisible 4:highlight 5:normal others:normal*/
    gboolean found = TRUE, titled = FALSE;
    GtkTextTag *tag = occurance;

    gtk_text_buffer_get_iter_at_offset(text2, &start, 0);
    current = start;
    end = start;

#ifdef MinGW
    int zhTitle = 0;
    int isTitle = 0;
#endif

    while(found) {
        found = gtk_text_iter_forward_search(
                    &end,
                    word,
                    GTK_TEXT_SEARCH_VISIBLE_ONLY,
                    &current,
                    &end,
                    NULL);


        if(found) {

#ifdef MinGW
            /*check zh char*/
            char *sample = gtk_text_iter_get_slice (&current, &end);
            int sampleLen = strlen(sample);
            if( testZh(sample, sampleLen))
                zhTitle = 1;
#endif
            /*title or body*/
            if(1== mode || (0 == mode && !titled && 0 == gtk_text_iter_get_line(&current)))
            {
#ifdef MinGW
                isTitle = 1;
#endif
                tag = title;
                titled = TRUE;
            }
            else if( 0 == mode )
            {
                tag = occurance;
            }
            else if( 2 == mode) {
#ifdef MinGW
                /*keyword, pretend title to use better font*/
                isTitle = 1;
#endif
                tag = keyword;
            }
            else if( 3 == mode) {
                tag = invisible;
#ifdef MinGW
                zhTitle = 0;
                isTitle = 0;
#endif
            }
            else if( 4 == mode) {
                tag = highlight;
            }
            else if( 5 == mode) {
                tag = normal; /* will do remove-tag after extending to full word */
            }
            else {
                tag = normal;
#ifdef MinGW
                zhTitle = 0;
                isTitle = 0;
#endif
            }

            /*extend word*/
            if( 2 != mode && 3 != mode && !gtk_text_iter_starts_word(&current)) {
                gtk_text_iter_backward_visible_word_start(&current);
            }

            if(2 != mode && 3 != mode && !gtk_text_iter_ends_word(&end)) {
                gtk_text_iter_forward_visible_word_end(&end);
            }
            if (5 == mode)
            {
                gtk_text_buffer_remove_tag (buffer, highlight, &current, &end);
            }
#ifdef MinGW
            /*Clear default_font to allow better font only when no zh chars present*/
            if( !zhTitle && isTitle )
                gtk_text_buffer_remove_tag (buffer, default_font, &current, &end);
#endif
            gtk_text_buffer_apply_tag(buffer, tag, &current, &end);
        }
    }

    current = start;
    end = start;

}