void gtk_glwidget_create_font (GtkWidget *widget) { PangoFontDescription *font_desc; PangoFont *font; PangoFontMetrics *font_metrics; font_list_base = qglGenLists (256); font_desc = pango_font_description_from_string (font_string); font = gdk_gl_font_use_pango_font (font_desc, 0, 256, font_list_base); if(font != NULL) { font_metrics = pango_font_get_metrics (font, NULL); font_height = pango_font_metrics_get_ascent (font_metrics) + pango_font_metrics_get_descent (font_metrics); font_height = PANGO_PIXELS (font_height); pango_font_metrics_unref (font_metrics); } pango_font_description_free (font_desc); }
wxFontProperties::wxFontProperties(wxFont* font): m_ascent(0), m_descent(0), m_lineGap(0), m_lineSpacing(0), m_xHeight(0) { PangoContext* context = gdk_pango_context_get_for_screen( gdk_screen_get_default() ); PangoLayout* layout = pango_layout_new(context); // and use it if it's valid if ( font && font->Ok() ) { pango_layout_set_font_description ( layout, font->GetNativeFontInfo()->description ); } PangoFontMetrics* metrics = pango_context_get_metrics (context, font->GetNativeFontInfo()->description, NULL); int height = font->GetPixelSize().GetHeight(); m_ascent = PANGO_PIXELS(pango_font_metrics_get_ascent(metrics)); m_descent = PANGO_PIXELS(pango_font_metrics_get_descent(metrics)); int h; const char* x = "x"; pango_layout_set_text( layout, x, strlen(x) ); pango_layout_get_pixel_size( layout, NULL, &h ); m_xHeight = h; m_lineGap = (m_ascent + m_descent) / 4; // FIXME: How can we calculate this via Pango? m_lineSpacing = m_ascent + m_descent; pango_font_metrics_unref(metrics); }
gboolean myScreenUpdateFontHeight (ScreenInfo *screen_info) { PangoFontDescription *desc; PangoContext *context; PangoFontMetrics *metrics; GtkWidget *widget; g_return_val_if_fail (screen_info != NULL, FALSE); TRACE ("entering myScreenUpdateFontHeight"); widget = myScreenGetGtkWidget (screen_info); context = getUIPangoContext (widget); desc = getUIPangoFontDesc (widget); if (desc && context) { metrics = pango_context_get_metrics (context, desc, NULL); screen_info->font_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)); pango_font_metrics_unref (metrics); return TRUE; } return FALSE; }
static int ol_scroll_window_get_font_height (OlScrollWindow *scroll) { ol_assert_ret (OL_IS_SCROLL_WINDOW (scroll), 0); OlScrollWindowPrivate *priv = OL_SCROLL_WINDOW_GET_PRIVATE (scroll); PangoContext *pango_context = gdk_pango_context_get (); PangoLayout *pango_layout = pango_layout_new (pango_context); PangoFontDescription *font_desc = pango_font_description_from_string (priv->font_name); pango_layout_set_font_description (pango_layout, font_desc); PangoFontMetrics *metrics = pango_context_get_metrics (pango_context, pango_layout_get_font_description (pango_layout), /* font desc */ NULL); /* languague */ int height = 0; int ascent, descent; ascent = pango_font_metrics_get_ascent (metrics); descent = pango_font_metrics_get_descent (metrics); pango_font_metrics_unref (metrics); height += PANGO_PIXELS (ascent + descent); pango_font_description_free (font_desc); g_object_unref (pango_layout); g_object_unref (pango_context); return height; }
WFontMetrics FontSupport::fontMetrics(const WFont& font) { PANGO_LOCK; enabledFontFormats = enabledFontFormats_; PangoFont *pangoFont = matchFont(font).pangoFont(); PangoFontMetrics *metrics = pango_font_get_metrics(pangoFont, nullptr); double ascent = pangoUnitsToDouble(pango_font_metrics_get_ascent(metrics)); double descent = pangoUnitsToDouble(pango_font_metrics_get_descent(metrics)); double leading = (ascent + descent) - font.sizeLength(12).toPixels(); // ascent < leading is an odd thing. it happens with a font like // Cursive. if (ascent > leading) ascent -= leading; else leading = 0; WFontMetrics result(font, leading, ascent, descent); pango_font_metrics_unref(metrics); return result; }
/* We don't support variable width fonts (yet) */ static gint get_font_width(GtkPrintContext *context, PangoFontDescription *desc) { PangoContext *pc; PangoFontMetrics *metrics; gint width; pc = gtk_print_context_create_pango_context(context); if (!utils_font_desc_check_monospace(pc, desc)) dialogs_show_msgbox_with_secondary(GTK_MESSAGE_WARNING, _("The editor font is not a monospaced font!"), _("Text will be wrongly spaced.")); metrics = pango_context_get_metrics(pc, desc, pango_context_get_language(pc)); /** TODO is this the best result we can get? */ /* digit and char width are mostly equal for monospace fonts, char width might be * for dual width characters(e.g. Japanese) so use digit width to get sure we get the width * for one character */ width = pango_font_metrics_get_approximate_digit_width(metrics) / PANGO_SCALE; pango_font_metrics_unref(metrics); g_object_unref(pc); return width; }
static bool pango_load (Lisp_Font *f) { PangoLanguage *language; PangoFontDescription *fontdesc; PangoFont *font; PangoFontMetrics *metrics; if (pango_context) { language = pango_context_get_language (pango_context); } else { char *langname, *p; #ifdef HAVE_PANGO_XFT pango_context = pango_xft_get_context (dpy, screen_num); #endif langname = g_strdup (setlocale (LC_CTYPE, NULL)); p = strchr (langname, '.'); if (p) *p = 0; p = strchr (langname, '@'); if (p) *p = 0; language = pango_language_from_string (langname); pango_context_set_language (pango_context, language); g_free (langname); } fontdesc = pango_font_description_from_string (rep_STR (f->name)); if (!pango_font_description_get_family (fontdesc)) pango_font_description_set_family (fontdesc, "Sans"); if (pango_font_description_get_size (fontdesc) <= 0) pango_font_description_set_size (fontdesc, 12 * PANGO_SCALE); pango_context_set_font_description (pango_context, fontdesc); font = pango_context_load_font (pango_context, fontdesc); if (!font) { pango_font_description_free(fontdesc); return FALSE; } metrics = pango_font_get_metrics (font, language); f->ascent = metrics->ascent / PANGO_SCALE; f->descent = metrics->descent / PANGO_SCALE; pango_font_metrics_unref (metrics); f->font = fontdesc; /* We save the font description, not the font itself! That's because it seems we can't recover it perfectly later, and the layout routines want a description */ return TRUE; }
static void tab_label_style_set_cb (GtkWidget *hbox, GtkStyle *previous_style, gpointer user_data) { PangoFontMetrics *metrics; PangoContext *context; GtkWidget *button; int char_width, h, w; context = gtk_widget_get_pango_context (hbox); metrics = pango_context_get_metrics (context, hbox->style->font_desc, pango_context_get_language (context)); char_width = pango_font_metrics_get_approximate_digit_width (metrics); pango_font_metrics_unref (metrics); gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (hbox), GTK_ICON_SIZE_MENU, &w, &h); gtk_widget_set_size_request (hbox, TAB_WIDTH_N_CHARS * PANGO_PIXELS(char_width) + 2 * w, -1); button = g_object_get_data (G_OBJECT (hbox), "close-button"); gtk_widget_set_size_request (button, w + 2, h + 2); }
/* * frame_update_titlebar_font * * Returns: void * Description: updates the titlebar font from the pango context, should * be called whenever the gtk style or font has changed */ void frame_update_titlebar_font (decor_frame_t *frame) { const PangoFontDescription *font_desc; PangoFontMetrics *metrics; PangoLanguage *lang; frame = gwd_decor_frame_ref (frame); font_desc = get_titlebar_font (frame); if (!font_desc) { GtkStyle *default_style; default_style = gtk_widget_get_default_style (); font_desc = default_style->font_desc; } pango_context_set_font_description (frame->pango_context, font_desc); lang = pango_context_get_language (frame->pango_context); metrics = pango_context_get_metrics (frame->pango_context, font_desc, lang); frame->text_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)); gwd_decor_frame_unref (frame); pango_font_metrics_unref (metrics); }
static gint _calc_footer_height(GtkHTML * html, GtkPrintOperation * operation, GtkPrintContext * context) { PangoContext *pango_context; PangoFontDescription *desc; PangoFontMetrics *metrics; gint footer_height; pango_context = gtk_print_context_create_pango_context(context); desc = pango_font_description_from_string("Sans Regular 10"); metrics = pango_context_get_metrics(pango_context, desc, pango_language_get_default()); footer_height = pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics); pango_font_metrics_unref(metrics); pango_font_description_free(desc); g_object_unref(pango_context); return footer_height; }
static gint matewnck_selector_get_width (GtkWidget *widget, const char *text) { GtkStyle *style; PangoContext *context; PangoFontMetrics *metrics; gint char_width; PangoLayout *layout; PangoRectangle natural; gint max_width; gint screen_width; gint width; gtk_widget_ensure_style (widget); style = gtk_widget_get_style (widget); context = gtk_widget_get_pango_context (widget); metrics = pango_context_get_metrics (context, style->font_desc, pango_context_get_language (context)); char_width = pango_font_metrics_get_approximate_char_width (metrics); pango_font_metrics_unref (metrics); max_width = PANGO_PIXELS (SELECTOR_MAX_WIDTH * char_width); layout = gtk_widget_create_pango_layout (widget, text); pango_layout_get_pixel_extents (layout, NULL, &natural); g_object_unref (G_OBJECT (layout)); screen_width = gdk_screen_get_width (gtk_widget_get_screen (widget)); width = MIN (natural.width, max_width); width = MIN (width, 3 * (screen_width / 4)); return width; }
/*---------------------------------------------------------------------------------------------- Get Font Ascent and Descent in one go more efficent that making two calls. ----------------------------------------------------------------------------------------------*/ bool VwGraphicsCairo::FontAscentAndDescent(int * ascent, int * descent) { // cache the PangoFont and PangoFontMetricsfont to the m_pangoFontDescription if (m_ascent == -1 && m_descent == -1) { if (m_fontMapForFontContext == NULL) m_fontMapForFontContext = pango_cairo_font_map_get_default(); if (m_fontContext == NULL) m_fontContext = pango_font_map_create_context (m_fontMapForFontContext); PangoFont * font = pango_context_load_font(m_fontContext, m_pangoFontDescription); // TODO-Linux: should we specify a language - for the font? PangoFontMetrics * metrics = pango_font_get_metrics (font, NULL); m_ascent = pango_font_metrics_get_ascent (metrics) / PANGO_SCALE; m_descent = pango_font_metrics_get_descent (metrics) / PANGO_SCALE; pango_font_metrics_unref(metrics); g_object_unref(font); } if (ascent != NULL) *ascent = m_ascent; if (descent != NULL) *descent = m_descent; return true; }
static void measure_font(const RrInstance *inst, RrFont *f) { PangoFontMetrics *metrics; static PangoLanguage *lang = NULL; if (lang == NULL) { #if PANGO_VERSION_MAJOR > 1 || \ (PANGO_VERSION_MAJOR == 1 && PANGO_VERSION_MINOR >= 16) lang = pango_language_get_default(); #else gchar *locale, *p; /* get the default language from the locale (based on gtk_get_default_language in gtkmain.c) */ locale = g_strdup(setlocale(LC_CTYPE, NULL)); if ((p = strchr(locale, '.'))) *p = '\0'; /* strip off the . */ if ((p = strchr(locale, '@'))) *p = '\0'; /* strip off the @ */ lang = pango_language_from_string(locale); g_free(locale); #endif } /* measure the ascent and descent */ metrics = pango_context_get_metrics(inst->pango, f->font_desc, lang); f->ascent = pango_font_metrics_get_ascent(metrics); f->descent = pango_font_metrics_get_descent(metrics); pango_font_metrics_unref(metrics); }
static void e_contact_print_letter_heading (EContactPrintContext *ctxt, gchar *letter) { PangoLayout *layout; PangoFontDescription *desc; PangoFontMetrics *metrics; gint width, height; cairo_t *cr; desc = ctxt->letter_heading_font; layout = gtk_print_context_create_pango_layout (ctxt->context); /* Make the rectangle thrice the average character width. * XXX Works well for English, what about other locales? */ metrics = pango_context_get_metrics ( pango_layout_get_context (layout), desc, pango_language_get_default ()); width = pango_font_metrics_get_approximate_char_width (metrics) * 3; pango_font_metrics_unref (metrics); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); pango_layout_set_font_description (layout, desc); pango_layout_set_text (layout, letter, -1); pango_layout_set_width (layout, width); pango_layout_get_size (layout, NULL, &height); if (ctxt->page_nr == -1 || ctxt->pages != ctxt->page_nr) { /* only calculating number of pages * or on page we do not want to print */ ctxt->y += pango_units_to_double (height); return; } /* Draw white text centered in a black rectangle. */ cr = gtk_print_context_get_cairo_context (ctxt->context); cairo_save (cr); cairo_set_source_rgb (cr, .0, .0, .0); cairo_rectangle ( cr, ctxt->x, ctxt->y, pango_units_to_double (width), pango_units_to_double (height)); cairo_fill (cr); cairo_restore (cr); cairo_save (cr); cairo_move_to (cr, ctxt->x, ctxt->y); cairo_set_source_rgb (cr, 1., 1., 1.); pango_cairo_show_layout (cr, layout); cairo_restore (cr); ctxt->y += pango_units_to_double (height); }
PP_Bool ppb_browser_font_trusted_draw_text_at(PP_Resource font, PP_Resource image_data, const struct PP_BrowserFont_Trusted_TextRun *text, const struct PP_Point *position, uint32_t color, const struct PP_Rect *clip, PP_Bool image_data_is_opaque) { (void)image_data_is_opaque; // TODO: is it worth implementing? struct pp_browser_font_s *bf = pp_resource_acquire(font, PP_RESOURCE_BROWSER_FONT); if (!bf) return PP_FALSE; struct pp_image_data_s *id = pp_resource_acquire(image_data, PP_RESOURCE_IMAGE_DATA); if (!id) { pp_resource_release(font); return PP_FALSE; } cairo_t *cr = cairo_create(id->cairo_surf); if (clip) { cairo_rectangle(cr, clip->point.x, clip->point.y, clip->size.width, clip->size.height); cairo_clip(cr); } PangoFontMetrics *m = pango_font_get_metrics(bf->font, NULL); int32_t ascent = pango_font_metrics_get_ascent(m) / PANGO_SCALE; cairo_surface_mark_dirty(id->cairo_surf); if (position) cairo_move_to(cr, position->x, position->y - ascent); else cairo_move_to(cr, 0, 0); pango_font_metrics_unref(m); cairo_set_source_rgba(cr, ((color >> 16) & 0xffu) / 255.0, ((color >> 8) & 0xffu) / 255.0, ((color >> 0) & 0xffu) / 255.0, ((color >> 24) & 0xffu) / 255.0); PangoLayout *layout = pango_cairo_create_layout(cr); uint32_t len = 0; const char *s = ""; if (text->text.type == PP_VARTYPE_STRING) s = ppb_var_var_to_utf8(text->text, &len); // TODO: factor into rtl direction pango_layout_set_font_description(layout, bf->font_desc); pango_layout_set_text(layout, s, len); pango_cairo_layout_path(cr, layout); cairo_fill(cr); g_object_unref(layout); cairo_surface_flush(id->cairo_surf); cairo_destroy(cr); pp_resource_release(font); pp_resource_release(image_data); return PP_FALSE; }
int draw_get_listview_rowheight (drawctx_t *ctx) { PangoFontDescription *font_desc = ctx->font_style->font_desc; PangoFontMetrics *metrics = pango_context_get_metrics (ctx->pangoctx, font_desc, pango_context_get_language (ctx->pangoctx)); int row_height = (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)); pango_font_metrics_unref (metrics); return PANGO_PIXELS(row_height)+6; }
double textbox_get_estimated_char_width ( void ) { PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font ); // Get width PangoFontMetrics *metric = pango_context_get_metrics ( p_context, pfd, NULL ); int width = pango_font_metrics_get_approximate_char_width ( metric ); pango_font_metrics_unref ( metric ); pango_font_description_free ( pfd ); return ( width ) / (double) PANGO_SCALE; }
void textbox_cleanup ( void ) { if ( p_metrics ) { pango_font_metrics_unref ( p_metrics ); p_metrics = NULL; } if ( p_context ) { g_object_unref ( p_context ); p_context = NULL; } }
static void dump_font_sizes (PangoContext *context, FILE *f, guint flags) { PangoFont *font; PangoFontDescription *pfd; int nf; real height; fprintf (f, "height/cm"); for (nf = 0; test_families[nf] != NULL; ++nf) fprintf (f, "\t%s", test_families[nf]); fprintf (f, "\n"); for (height = 0.1; height <= 10.0; height += 0.1) { fprintf (f, "%g", height); for (nf = 0; test_families[nf] != NULL; ++nf) { pfd = pango_font_description_new (); pango_font_description_set_family (pfd, test_families[nf]); //pango_font_description_set_size (pfd, height * pixels_per_cm * PANGO_SCALE); if (flags & DUMP_ABSOLUTE) pango_font_description_set_absolute_size (pfd, height * pixels_per_cm * PANGO_SCALE); else pango_font_description_set_size (pfd, height * pixels_per_cm * PANGO_SCALE); font = pango_context_load_font (context, pfd); if (font) { PangoFontMetrics *metrics = pango_font_get_metrics (font, NULL); /* now make a font-size where the font/line-height matches the given pixel size */ real total = ((double)pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; real factor = height*pixels_per_cm/total; real line_height; if (flags & DUMP_ABSOLUTE) pango_font_description_set_absolute_size (pfd, factor * height * pixels_per_cm * PANGO_SCALE); else pango_font_description_set_size (pfd, factor * height * pixels_per_cm * PANGO_SCALE); pango_font_metrics_unref (metrics); g_object_unref (font); font = pango_context_load_font (context, pfd); metrics = pango_font_get_metrics (font, NULL); line_height = ((double)pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; fprintf (f, "\t%.3g", flags & DUMP_FACTORS ? factor : line_height); g_object_unref (font); } pango_font_description_free (pfd); } fprintf (f, "\n"); } }
int textbox_get_estimated_char_height ( void ) { // Set font. PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font ); // Get width PangoFontMetrics *metric = pango_context_get_metrics ( p_context, pfd, NULL ); int height = pango_font_metrics_get_ascent ( metric ) + pango_font_metrics_get_descent ( metric ); pango_font_metrics_unref ( metric ); pango_font_description_free ( pfd ); return ( height ) / PANGO_SCALE + 2 * SIDE_MARGIN; }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getFontMetrics (JNIEnv *env, jobject java_font, jdoubleArray java_metrics) { struct peerfont *pfont = NULL; jdouble *native_metrics = NULL; PangoFontMetrics *pango_metrics; gdk_threads_enter(); pfont = (struct peerfont *) NSA_GET_FONT_PTR (env, java_font); g_assert (pfont != NULL); pango_metrics = pango_context_get_metrics (pfont->ctx, pfont->desc, gtk_get_default_language ()); native_metrics = (*env)->GetDoubleArrayElements (env, java_metrics, NULL); g_assert (native_metrics != NULL); native_metrics[FONT_METRICS_ASCENT] = PANGO_PIXELS (pango_font_metrics_get_ascent (pango_metrics)); native_metrics[FONT_METRICS_MAX_ASCENT] = native_metrics[FONT_METRICS_ASCENT]; native_metrics[FONT_METRICS_DESCENT] = PANGO_PIXELS (pango_font_metrics_get_descent (pango_metrics)); if (native_metrics[FONT_METRICS_DESCENT] < 0) native_metrics[FONT_METRICS_DESCENT] = - native_metrics[FONT_METRICS_DESCENT]; native_metrics[FONT_METRICS_MAX_DESCENT] = native_metrics[FONT_METRICS_DESCENT]; native_metrics[FONT_METRICS_MAX_ADVANCE] = PANGO_PIXELS (pango_font_metrics_get_approximate_char_width (pango_metrics)); (*env)->ReleaseDoubleArrayElements (env, java_metrics, native_metrics, 0); pango_font_metrics_unref (pango_metrics); gdk_threads_leave(); }
void dia_font_finalize(GObject* object) { DiaFont* font = DIA_FONT(object); if (font->pfd) pango_font_description_free(font->pfd); font->pfd = NULL; if (font->metrics) pango_font_metrics_unref(font->metrics); font->metrics = NULL; if (font->loaded) g_object_unref(font->loaded); font->loaded = NULL; G_OBJECT_CLASS(parent_class)->finalize(object); }
static PangoAttrList * create_shape_attr_list_for_layout (PangoLayout *layout, IconShapeData *data) { PangoAttrList *attrs; PangoFontMetrics *metrics; gint ascent, descent; PangoRectangle ink_rect, logical_rect; const gchar *p; const gchar *text; gint placeholder_len; /* Get font metrics and prepare fancy shape size */ metrics = pango_context_get_metrics (pango_layout_get_context (layout), pango_layout_get_font_description (layout), NULL); ascent = pango_font_metrics_get_ascent (metrics); descent = pango_font_metrics_get_descent (metrics); pango_font_metrics_unref (metrics); logical_rect.x = 0; logical_rect.y = - ascent; logical_rect.width = ascent + descent; logical_rect.height = ascent + descent; ink_rect = logical_rect; attrs = pango_attr_list_new (); text = pango_layout_get_text (layout); placeholder_len = strlen (data->placeholder_str); for (p = text; (p = strstr (p, data->placeholder_str)); p += placeholder_len) { PangoAttribute *attr; attr = pango_attr_shape_new_with_data (&ink_rect, &logical_rect, GUINT_TO_POINTER (g_utf8_get_char (p)), NULL, NULL); attr->start_index = p - text; attr->end_index = attr->start_index + placeholder_len; pango_attr_list_insert (attrs, attr); } return attrs; }
static void ol_osd_render_update_font_height (OlOsdRenderContext *context) { PangoFontMetrics *metrics = pango_context_get_metrics (context->pango_context, pango_layout_get_font_description (context->pango_layout), /* font desc */ NULL); /* languague */ if (metrics == NULL) { ol_errorf ("Cannot get font metrics\n"); } context->font_height = 0; int ascent, descent; ascent = pango_font_metrics_get_ascent (metrics); descent = pango_font_metrics_get_descent (metrics); pango_font_metrics_unref (metrics); context->font_height += PANGO_PIXELS (ascent + descent); }
static void dma_data_view_data_size_request (DmaDataView *view, GtkRequisition *requisition) { PangoFontMetrics *metrics; PangoContext *context; context = gtk_widget_get_pango_context (view->data); metrics = pango_context_get_metrics (context, gtk_widget_get_style (view->data)->font_desc, pango_context_get_language (context)); requisition->height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)); requisition->width = (pango_font_metrics_get_approximate_char_width (metrics) + PANGO_SCALE - 1) / PANGO_SCALE; pango_font_metrics_unref (metrics); }
int pangox_layout_get_font_height(PangoLayout *layout) { if (layout != NULL) { PangoFontMetrics *metric; PangoContext *context; int h; context = pango_layout_get_context(layout); metric = pango_context_get_metrics(context, pango_context_get_font_description(context), NULL); h = pango_font_metrics_get_ascent(metric) + pango_font_metrics_get_descent(metric); pango_font_metrics_unref(metric); return(h / PANGO_SCALE); } else { return(0); } }
static int sg_font_width(PangoFontDescription *font) { /* returns size in pixels */ int wid = 0; double dpi = 96.0; /* see below */ PangoContext *ctx; PangoFontMetrics *m; #if HAVE_GTK_LINK_BUTTON_NEW dpi = gdk_screen_get_resolution(gdk_display_get_default_screen(gdk_display_get_default())); /* pixels/inch */ #endif ctx = gdk_pango_context_get(); m = pango_context_get_metrics(ctx, font, gtk_get_default_language()); /* returns size in pango-scaled points (1024/72 inch) */ wid = (int)((dpi / 72.0) * PANGO_PIXELS(pango_font_metrics_get_approximate_char_width(m))); pango_font_metrics_unref(m); g_object_unref(ctx); return(wid); }
void initfont(DC *dc, const char *fontstr) { PangoFontMetrics *metrics; dc->pgc = pango_xft_get_context(dc->dpy, 0); dc->pfd = pango_font_description_from_string(fontstr); if(pango_font_description_get_size(dc->pfd) == 0) pango_font_description_set_size(dc->pfd, 12 * PANGO_SCALE); metrics = pango_context_get_metrics(dc->pgc, dc->pfd, pango_language_from_string("")); dc->font.ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; dc->font.descent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE; dc->font.height = dc->font.ascent + dc->font.descent; pango_font_metrics_unref(metrics); dc->plo = pango_layout_new(dc->pgc); pango_layout_set_font_description(dc->plo, dc->pfd); }
/* * frame_update_titlebar_font * * Returns: void * Description: updates the titlebar font from the pango context, should * be called whenever the gtk style or font has changed */ void frame_update_titlebar_font (decor_frame_t *frame) { const PangoFontDescription *font_desc; PangoFontDescription *free_font_desc; PangoFontMetrics *metrics; PangoLanguage *lang; free_font_desc = NULL; frame = gwd_decor_frame_ref (frame); font_desc = get_titlebar_font (frame); if (!font_desc) { GtkCssProvider *provider = gtk_css_provider_get_default (); GtkStyleContext *context = gtk_style_context_new (); GtkWidgetPath *path = gtk_widget_path_new (); gtk_widget_path_prepend_type (path, GTK_TYPE_WIDGET); gtk_style_context_set_path (context, path); gtk_widget_path_free (path); gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK); gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL); font_desc = (const PangoFontDescription *) free_font_desc; } pango_context_set_font_description (frame->pango_context, font_desc); lang = pango_context_get_language (frame->pango_context); metrics = pango_context_get_metrics (frame->pango_context, font_desc, lang); frame->text_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)); gwd_decor_frame_unref (frame); pango_font_metrics_unref (metrics); if (free_font_desc) pango_font_description_free (free_font_desc); }
void glyph_cache_set_font(TGlyphCache *cache, PangoFontDescription *font_desc) { PangoFontMap *font_map; PangoFontMetrics *metrics; if (cache->hash) { g_hash_table_destroy(cache->hash); g_object_unref(cache->font_set); } cache->hash = g_hash_table_new_full(NULL, NULL, NULL, glyph_destroy_gfi); font_map = pango_xft_get_font_map( GDK_DISPLAY_XDISPLAY(cache->display), GDK_SCREEN_XNUMBER(cache->screen) ); g_object_ref (font_map); cache->font_set = pango_font_map_load_fontset( font_map, cache->context, font_desc, cache->lang ); g_object_unref(font_map); font_map = NULL; metrics = pango_fontset_get_metrics(cache->font_set); pango_font_metrics_ref(metrics); cache->ascent = pango_font_metrics_get_ascent(metrics); cache->descent = pango_font_metrics_get_descent(metrics); cache->width = pango_font_metrics_get_approximate_digit_width(metrics); cache->height = cache->ascent + cache->descent; if (cache->width <= 0) { fprintf (stderr, "Warning: cache->width = %d\n", cache->width); cache->width = cache->height / 2; } pango_font_metrics_unref(metrics); }