static void style_set_handler (GtkWidget *widget, GtkStyle *previous_style) { PangoLayout *layout; int width, width2; int xpad; layout = gtk_label_get_layout (GTK_LABEL(widget)); layout = pango_layout_copy (layout); pango_layout_set_text (layout, LOCATION_LABEL, -1); pango_layout_get_pixel_size (layout, &width, NULL); pango_layout_set_text (layout, GO_TO_LABEL, -1); pango_layout_get_pixel_size (layout, &width2, NULL); width = MAX (width, width2); gtk_misc_get_padding (GTK_MISC (widget), &xpad, NULL); width += 2 * xpad; gtk_widget_set_size_request (widget, width, -1); g_object_unref (layout); }
static void _mt_draw_string(MT_WINDOW *win, MT_STRING *str, int x_offset, int y_offset, MT_COLOR *color) { MT_GTK_STRING *s = str; PangoLayout *layout = s->layout; int state_type = s->state_type; if (!color && s->color) color = s->color; if (color && !pango_layout_get_text(layout)) color = NULL; if (color) { PangoAttrList *attrlist; PangoAttribute *attr; layout = pango_layout_copy(layout); attrlist = pango_layout_get_attributes(layout); if (attrlist) { pango_attr_list_ref(attrlist); } else { attrlist = pango_attr_list_new(); } if (color) { attr = pango_attr_foreground_new(color->r << 8, color->g << 8, color->b << 8); attr->start_index = 0; attr->end_index = strlen(pango_layout_get_text(layout)); pango_attr_list_insert_before(attrlist, attr); } pango_layout_set_attributes(layout, attrlist); pango_attr_list_unref(attrlist); state_type = GTK_STATE_NORMAL; } s->parent_class->draw_layout(s->style, (GdkWindow *)win, state_type, s->use_text, s->area, s->widget, s->detail, s->x + x_offset, s->y + y_offset, layout); if (color) { g_object_unref(layout); } }
static void ellipsize_layout (PangoLayout *layout, gint width) { PangoLayoutLine *line; PangoLayout *ell; gint h, w, ell_w, x; GString *text; if (width <= 0) { pango_layout_set_text (layout, "", -1); return; } pango_layout_get_pixel_size (layout, &w, &h); if (w <= width) return; /* calculate ellipsis width */ ell = pango_layout_copy (layout); pango_layout_set_text (ell, ELLIPSIS, -1); pango_layout_get_pixel_size (ell, &ell_w, NULL); g_object_unref (ell); if (width < ell_w) { /* not even ellipsis fits, so hide the text */ pango_layout_set_text (layout, "", -1); return; } /* shrink total available width by the width of the ellipsis */ width -= ell_w; line = pango_layout_get_line (layout, 0); text = g_string_new (pango_layout_get_text (layout)); if (pango_layout_line_x_to_index (line, width * PANGO_SCALE, &x, NULL)) { g_string_set_size (text, x); g_string_append (text, ELLIPSIS); pango_layout_set_text (layout, text->str, -1); } g_string_free (text, TRUE); }
static VALUE rg_copy(VALUE self) { return GOBJ2RVAL_UNREF(pango_layout_copy(_SELF(self))); }