JNIEXPORT void JNICALL Java_org_gnome_pango_PangoLayoutLine_pango_1layout_1line_1get_1pixel_1extents ( JNIEnv* env, jclass cls, jlong _self, jlong _inkRect, jlong _logicalRect ) { PangoLayoutLine* self; PangoRectangle* inkRect; PangoRectangle* logicalRect; // convert parameter self self = (PangoLayoutLine*) _self; // convert parameter inkRect inkRect = (PangoRectangle*) _inkRect; // convert parameter logicalRect logicalRect = (PangoRectangle*) _logicalRect; // call function pango_layout_line_get_pixel_extents(self, inkRect, logicalRect); // cleanup parameter self // cleanup parameter inkRect // cleanup parameter logicalRect }
static VALUE rg_pixel_extents(VALUE self) { PangoRectangle ink_rect, logical_rect; pango_layout_line_get_pixel_extents(_SELF(self), &ink_rect, &logical_rect); return rb_assoc_new(PANGORECTANGLE2RVAL(&ink_rect), PANGORECTANGLE2RVAL(&logical_rect)); }
gboolean text_get_extents (const gchar *fontname, const gchar *text, gint *width, gint *height, gint *ascent, gint *descent) { PangoFontDescription *font_desc; PangoContext *context; PangoLayout *layout; PangoFontMap *fontmap; PangoRectangle rect; g_return_val_if_fail (fontname != NULL, FALSE); g_return_val_if_fail (text != NULL, FALSE); fontmap = pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT); if (! fontmap) g_error ("You are using a Pango that has been built against a cairo " "that lacks the Freetype font backend"); pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (fontmap), 72.0); /* FIXME: resolution */ context = pango_font_map_create_context (fontmap); g_object_unref (fontmap); layout = pango_layout_new (context); g_object_unref (context); font_desc = pango_font_description_from_string (fontname); pango_layout_set_font_description (layout, font_desc); pango_font_description_free (font_desc); pango_layout_set_text (layout, text, -1); pango_layout_get_pixel_extents (layout, NULL, &rect); if (width) *width = rect.width; if (height) *height = rect.height; if (ascent || descent) { PangoLayoutIter *iter; PangoLayoutLine *line; iter = pango_layout_get_iter (layout); line = pango_layout_iter_get_line_readonly (iter); pango_layout_iter_free (iter); pango_layout_line_get_pixel_extents (line, NULL, &rect); if (ascent) *ascent = PANGO_ASCENT (rect); if (descent) *descent = - PANGO_DESCENT (rect); } g_object_unref (layout); return TRUE; }
static gboolean set_tooltip_widget_from_marks (GtkSourceView *view, GtkTooltip *tooltip, GSList *marks) { GtkWidget *vbox = NULL; for (; marks; marks = g_slist_next (marks)) { const gchar *category; GtkSourceMark *mark; GtkSourceMarkAttributes *attrs; gchar *text; gboolean ismarkup = FALSE; GtkWidget *label; GtkWidget *hbox; const GdkPixbuf *pixbuf; gint size; mark = marks->data; category = gtk_source_mark_get_category (mark); attrs = gtk_source_view_get_mark_attributes (view, category, NULL); if (attrs == NULL) { continue; } text = gtk_source_mark_attributes_get_tooltip_markup (attrs, mark); if (text == NULL) { text = gtk_source_mark_attributes_get_tooltip_text (attrs, mark); } else { ismarkup = TRUE; } if (text == NULL) { continue; } if (vbox == NULL) { vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_widget_show (vbox); } hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); gtk_widget_show (hbox); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); label = gtk_label_new (NULL); if (ismarkup) { gtk_label_set_markup (GTK_LABEL (label), text); } else { gtk_label_set_text (GTK_LABEL (label), text); } gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_widget_show (label); gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, NULL, &size); pixbuf = gtk_source_mark_attributes_render_icon (attrs, GTK_WIDGET (view), size); if (pixbuf != NULL) { GtkWidget *image; PangoLayoutLine *line; PangoRectangle rect; GtkWidget *align; GdkPixbuf *copy; align = gtk_alignment_new (0, 0, 0, 0); gtk_widget_show (align); copy = gdk_pixbuf_copy (pixbuf); image = gtk_image_new_from_pixbuf (copy); g_object_unref (copy); gtk_misc_set_alignment (GTK_MISC (image), 0, 0); gtk_widget_show (image); /* Measure up to align exact */ line = pango_layout_get_line (gtk_label_get_layout (GTK_LABEL (label)), 0); pango_layout_line_get_pixel_extents (line, NULL, &rect); gtk_alignment_set_padding (GTK_ALIGNMENT (align), (rect.height > size ? rect.height - size : size - rect.height) - 1, 0, 0, 0); if (rect.height > size) { gtk_container_add (GTK_CONTAINER (align), image); image = align; } else if (size > rect.height) { gtk_container_add (GTK_CONTAINER (align), label); label = align; } else { gtk_widget_destroy (align); } gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); } gtk_box_pack_end (GTK_BOX (hbox), label, TRUE, TRUE, 0); if (g_slist_length (marks) != 1) { GtkWidget *separator; separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); gtk_widget_show (separator); gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0); } g_free (text); } if (vbox == NULL) { return FALSE; } gtk_tooltip_set_custom (tooltip, vbox); return TRUE; }