PangoContext* wxApp::GetPangoContext() { static PangoContext *s_pangoContext = NULL; if ( !s_pangoContext ) { Display *dpy = wxGlobalDisplay(); #ifdef HAVE_PANGO_XFT int xscreen = DefaultScreen(dpy); static int use_xft = -1; if (use_xft == -1) { wxString val = wxGetenv( L"GDK_USE_XFT" ); use_xft = val == L"1"; } if (use_xft) s_pangoContext = pango_xft_get_context(dpy, xscreen); else #endif // HAVE_PANGO_XFT s_pangoContext = pango_x_get_context(dpy); if (!PANGO_IS_CONTEXT(s_pangoContext)) { wxLogError( wxT("No pango context.") ); } } return s_pangoContext; }
static PangoContext * pangox_view_get_context (gpointer instance) { XViewer *x = (XViewer *) instance; PangoContext *context; PangoMatrix matrix = {0., 0., 0., 0., 0., 0.}; context = pango_x_get_context (x->display); /* We set an all-zero matrix on the context, to negotiate that * this backend doesn't support transformations. */ pango_context_set_matrix (context, &matrix); return context; }
static void _vte_pango_x_start(struct _vte_draw *draw) { struct _vte_pango_x_data *data; Display *display; GdkDrawable *drawable; int x_offs, y_offs; data = (struct _vte_pango_x_data*) draw->impl_data; display = gdk_x11_drawable_get_xdisplay(draw->widget->window); if (data->ctx != NULL) { g_object_unref(data->ctx); } data->ctx = pango_x_get_context(display); if (data->layout != NULL) { g_object_unref(data->layout); } data->layout = pango_layout_new(data->ctx); if (data->font != NULL) { pango_layout_set_font_description(data->layout, data->font); } if (data->gc != NULL) { g_object_unref(data->gc); } data->gc = gdk_gc_new(draw->widget->window); gdk_rgb_find_color(gdk_drawable_get_colormap(draw->widget->window), &data->color); gdk_window_get_internal_paint_info(draw->widget->window, &drawable, &x_offs, &y_offs); data->drawable = gdk_x11_drawable_get_xid(drawable); data->x_offs = x_offs; data->y_offs = y_offs; }
static void _vte_pango_x_set_text_font(struct _vte_draw *draw, const PangoFontDescription *fontdesc, VteTerminalAntiAlias antialias) { PangoContext *ctx; Display *display; PangoLayout *layout; PangoLayoutIter *iter; PangoRectangle ink, logical; gunichar full_codepoints[] = {VTE_DRAW_DOUBLE_WIDE_IDEOGRAPHS}; GString *full_string; gint full_width; guint i; struct _vte_pango_x_data *data; data = (struct _vte_pango_x_data*) draw->impl_data; display = gdk_x11_display_get_xdisplay(gtk_widget_get_display(draw->widget)); if (data->ctx != NULL) { g_object_unref(data->ctx); } ctx = pango_x_get_context(display); layout = pango_layout_new(ctx); if (data->font != NULL) { pango_font_description_free(data->font); } data->font = pango_font_description_copy(fontdesc); pango_layout_set_font_description(layout, data->font); /* Estimate for ASCII characters. */ pango_layout_set_text(layout, VTE_DRAW_SINGLE_WIDE_CHARACTERS, strlen(VTE_DRAW_SINGLE_WIDE_CHARACTERS)); pango_layout_get_extents(layout, &ink, &logical); draw->width = logical.width; draw->width = howmany(draw->width, strlen(VTE_DRAW_SINGLE_WIDE_CHARACTERS)); iter = pango_layout_get_iter(layout); draw->height = PANGO_PIXELS(logical.height); draw->ascent = PANGO_PIXELS(pango_layout_iter_get_baseline(iter)); pango_layout_iter_free(iter); /* Estimate for CJK characters. */ full_string = g_string_new(NULL); for (i = 0; i < G_N_ELEMENTS(full_codepoints); i++) { g_string_append_unichar(full_string, full_codepoints[i]); } pango_layout_set_text(layout, full_string->str, full_string->len); pango_layout_get_extents(layout, &ink, &logical); full_width = howmany(logical.width, G_N_ELEMENTS(full_codepoints)); g_string_free(full_string, TRUE); /* If they're the same, then we have a screwy font. */ if (full_width == draw->width) { /* add 1 to round up when dividing by 2 */ draw->width = (draw->width + 1) / 2; } draw->width = PANGO_PIXELS(draw->width); iter = pango_layout_get_iter(layout); if (draw->height == 0) { draw->height = PANGO_PIXELS(logical.height); } if (draw->ascent == 0) { draw->ascent = PANGO_PIXELS(pango_layout_iter_get_baseline(iter)); } pango_layout_iter_free(iter); _vte_debug_print(VTE_DEBUG_MISC, "VtePangoX font metrics = %dx%d (%d).\n", draw->width, draw->height, draw->ascent); g_object_unref(layout); g_object_unref(ctx); }