Re: GTK & Pango string measurement

From: Wesley Smith <wesley hoke gmail com>

> In the situation I'm talking about, there is no GtkWidget object so
> your technique won't work.  This is the code I'm going off of
> actually.  Thus my question is how can I get a pango context from  a
> GtkCellRendererText?

AFAIK, the pango context used by the GtkCellRenderer is the same used
by the treeview, so try to make something like:

context = gtk_widget_get_pango_context (my_treeview)

About how to get what you want, I think that the next pseudocode could
be your base:

compute_break_position_on_my_text (my_tree_view, text)
    width = gtk_tree_view_column_get_width(the_column_of_my_treeview)

    context = gtk_widget_get_pango_context(my_tree_view);
    layout = pango_layout_new(context);

    pango_layout_set_markup(layout, text, -1);

    pango_layout_xy_to_index(layout, width  * PANGO_SCALE,
                             0, &offs, &trailing);

    brk = g_utf8_offset_to_pointer(text + offs, trailing);

    return brk - text;

But I'm not sure, as I'm not a pango expert. Hope this helps.

API (apinheiro igalia com)

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