Esempio n. 1
0
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");
  }
}
Esempio n. 2
0
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);

}
Esempio n. 3
0
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;
}
Esempio n. 4
0
static struct font_engine_font_t *do_font_load(const char *name)
{
struct font_engine_font_t *fef = NULL;
PangoFontDescription *desc;

if( (name) && (desc = pango_font_description_from_string(name)) )
	{
	fef = calloc_2(1, sizeof(struct font_engine_font_t));

	fef->desc = desc;
	fef->font = pango_font_map_load_font( pango_cairo_font_map_get_default(), GLOBALS->fonts_context,   fef->desc);
	fef->metrics=pango_font_get_metrics(fef->font, NULL /*pango_language_get_default()*/ );

	fef->ascent  = pango_font_metrics_get_ascent(fef->metrics) / 1000;
	fef->descent = pango_font_metrics_get_descent(fef->metrics) / 1000;

	fef->is_pango = 1;

	if(!strncmp(name, "Monospace", 9))
		{
		int i_width = font_engine_string_measure(fef, "i");
		fef->mono_width = font_engine_string_measure(fef, "O");
		fef->is_mono = (i_width == fef->mono_width);
		}
	}

return(fef);
}
Esempio n. 5
0
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);
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
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;
}
Esempio n. 9
0
/*----------------------------------------------------------------------------------------------
	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;
}
Esempio n. 10
0
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);
}
Esempio n. 11
0
/*
 * 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);
}
Esempio n. 12
0
double textbox_get_estimated_char_height ( void )
{
    if ( char_height < 0 ) {
        int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics );
        char_height = ( height ) / (double) PANGO_SCALE;
    }
    return char_height;
}
Esempio n. 13
0
void
show_text(GtkWidget *window, const char *text)
{
  GtkWidget *dialog, *content_area, *view, *sw;
  GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
  dialog = gtk_dialog_new_with_buttons(PACKAGE_NAME " Help",
				       GTK_WINDOW(window),
				       flags,
				       "_Close",
				       GTK_RESPONSE_CANCEL,
				       NULL);
  content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
  gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);

  sw = gtk_scrolled_window_new(NULL, NULL);
  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
				      GTK_SHADOW_IN);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
				 GTK_POLICY_NEVER,
				 GTK_POLICY_AUTOMATIC);
  gtk_container_add_with_properties(GTK_CONTAINER(content_area), sw,
				    "expand", TRUE,
				    "fill", TRUE,
				    NULL);

  view = gtk_text_view_new();
  gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);

  gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(view)),
			   text, -1);

  gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE);
  gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);

  /* Use font metrics to set the size of the text view. */

  PangoContext *context = gtk_widget_get_pango_context(view);
  PangoFontMetrics *metrics = pango_context_get_metrics(context, NULL, NULL);
  gint char_width = pango_font_metrics_get_approximate_char_width(metrics);
  gint ascent = pango_font_metrics_get_ascent(metrics);
  gint descent = pango_font_metrics_get_descent(metrics);
  gint height = PANGO_PIXELS(ascent + descent);
  gint width = PANGO_PIXELS(char_width);

  gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 2 * width);
  gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view), 2 * width);
  gtk_window_set_default_size(GTK_WINDOW(dialog), 70 * width, 20 * height);

  gtk_container_add(GTK_CONTAINER(sw), view);

  gtk_widget_show_all(dialog);

  gtk_dialog_run(GTK_DIALOG(dialog));

  gtk_widget_destroy(dialog);
}
Esempio n. 14
0
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;
}
Esempio n. 15
0
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;
}
PP_Bool
ppb_browser_font_trusted_describe(PP_Resource font,
                                  struct PP_BrowserFont_Trusted_Description *description,
                                  struct PP_BrowserFont_Trusted_Metrics *metrics)
{
    struct pp_browser_font_s *bf = pp_resource_acquire(font, PP_RESOURCE_BROWSER_FONT);
    if (!bf)
        return PP_FALSE;

    memset(description, 0, sizeof(*description));
    memset(metrics, 0, sizeof(*metrics));

    const char *s_family = pango_font_description_get_family(bf->font_desc);
    description->face = PP_MakeString(s_family);

    description->family = bf->family >= 0 ? bf->family : 0;

    description->size = pango_font_description_get_size(bf->font_desc) / PANGO_SCALE;
    description->weight = pango_font_description_get_weight(bf->font_desc)/100 - 1;
    description->italic = (pango_font_description_get_style(bf->font_desc) != PANGO_STYLE_NORMAL);
    description->small_caps =
            (pango_font_description_get_variant(bf->font_desc) == PANGO_VARIANT_SMALL_CAPS);
    description->letter_spacing = bf->letter_spacing;
    description->word_spacing = bf->word_spacing;

    PangoFontMetrics *m = pango_font_get_metrics(bf->font, NULL);
    // TODO: use fontconfig-specific structures in pango to determine height and x-height
    metrics->ascent = pango_font_metrics_get_ascent(m) / PANGO_SCALE;
    metrics->descent = pango_font_metrics_get_descent(m) / PANGO_SCALE;
    metrics->height = (pango_font_metrics_get_ascent(m) +
                       pango_font_metrics_get_descent(m)) / PANGO_SCALE;
    metrics->line_spacing = 1; // TODO: get actual line spacing
    metrics->x_height = metrics->height;    // TODO: find out actual x-height

    pango_font_metrics_unref(m);
    pp_resource_release(font);
    return PP_TRUE;
}
Esempio n. 17
0
real
dia_font_descent(const char* string, DiaFont* font, real height)
{
  if (font->metrics) {
    real descent = pdu_to_dcm(pango_font_metrics_get_descent (font->metrics));
    return descent * (height / font->height);
  } else {
    /* previous, _expensive_ but string specific way */
    TextLine *text_line = text_line_new(string, font, height);
    real result = text_line_get_descent(text_line);
    text_line_destroy(text_line);
    return result;
  }
}
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();
}
Esempio n. 19
0
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;
}
Esempio n. 20
0
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);
}
int QPushButton::baselinePosition(int height) const
{
    return (int) ((15.0f/20.0f)*(float)height);
#if 0
    GtkWidget *w = getGtkWidget();
    PangoContext *pc= gtk_widget_get_pango_context(w);
    PangoFontDescription *fd = pango_context_get_font_description(pc);
    PangoFontMetrics *fm = pango_context_get_metrics(pc,fd,NULL); //lang=NULL

    float ascender = pango_font_metrics_get_ascent(fm) / PANGO_SCALE;
    float descender =pango_font_metrics_get_descent(fm) / PANGO_SCALE;

    return (int)ceil(- TOP_MARGIN
                     + ((height() + TOP_MARGIN + BOTTOM_MARGIN) - (ascender - descender)) / 2.0
                     + ascender - VERTICAL_FUDGE_FACTOR);
#endif
}
Esempio n. 22
0
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);
}
Esempio n. 23
0
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);
    }
}
Esempio n. 24
0
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);
}
Esempio n. 25
0
/*
 * 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);
}
Esempio n. 26
0
void ZLGtkPaintContext::setFont(const std::string &family, int size, bool bold, bool italic) {
	bool fontChanged = false;

	if (myFontDescription == 0) {
		myFontDescription = pango_font_description_new();
		fontChanged = true;
	}

	const char *oldFamily = pango_font_description_get_family(myFontDescription);
	if ((oldFamily == 0) || (family != oldFamily)) {
		pango_font_description_set_family(myFontDescription, family.c_str());
		fontChanged = true;
	}

	int newSize = size * PANGO_SCALE;
	if (pango_font_description_get_size(myFontDescription) != newSize) {
		pango_font_description_set_size(myFontDescription, newSize);
		fontChanged = true;
	}

	PangoWeight newWeight = bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
	if (pango_font_description_get_weight(myFontDescription) != newWeight) {
		pango_font_description_set_weight(myFontDescription, newWeight);
		fontChanged = true;
	}

	PangoStyle newStyle = italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
	if (pango_font_description_get_style(myFontDescription) != newStyle) {
		pango_font_description_set_style(myFontDescription, newStyle);
		fontChanged = true;
	}

	if (fontChanged) {
		if (myContext != 0) {
			myAnalysis.font = pango_context_load_font(myContext, myFontDescription);
			myAnalysis.shape_engine = pango_font_find_shaper(myAnalysis.font, 0, 0);
			PangoFontMetrics *metrics = pango_font_get_metrics(myAnalysis.font, myAnalysis.language);
			myDescent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
		}
		myStringHeight = -1;
		mySpaceWidth = -1;
	}
}
Esempio n. 27
0
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);
}
Esempio n. 28
0
void gglk_text_init_tags(GglkText *tb) 
{
    PangoContext *context;
    PangoFontMetrics *metrics;
    PangoFontDescription *font_desc = NULL;
    GtkTextTag *tag;
    
    tb->buffer = gtk_text_view_get_buffer(&tb->view);
    gtk_text_buffer_get_end_iter(tb->buffer, &tb->iter);

    tb->startedit=gtk_text_buffer_create_mark(tb->buffer,NULL,&tb->iter,TRUE);
    tb->endedit  =gtk_text_buffer_create_mark(tb->buffer,NULL,&tb->iter,FALSE);
    tb->scrollmark=gtk_text_buffer_create_mark(tb->buffer,NULL,&tb->iter,TRUE);
    tb->endmark  =gtk_text_buffer_create_mark(tb->buffer,NULL,&tb->iter,FALSE);
    tb->hypermark=gtk_text_buffer_create_mark(tb->buffer,NULL,&tb->iter,TRUE);

    tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(tb->buffer),
				    "Normal");
    if(!tag) return;

    gglk_text_set_style(tb, tag);

    /* Measure default font size */
    g_object_get(G_OBJECT(tag), "font-desc", &font_desc, NULL);

    font_desc = pango_font_description_copy(font_desc);
    pango_font_description_merge(font_desc,
				 GTK_WIDGET(tb)->style->font_desc,FALSE);

    context = gtk_widget_get_pango_context(GTK_WIDGET(tb));
    metrics = pango_context_get_metrics(context,
					font_desc,
					pango_context_get_language(context));

    pango_font_description_free(font_desc);

    tb->xunits = PANGO_PIXELS(pango_font_metrics_get_approximate_digit_width(
				  metrics));
    tb->yunits = PANGO_PIXELS(pango_font_metrics_get_ascent(metrics) +
			      pango_font_metrics_get_descent(metrics));
    pango_font_metrics_unref(metrics);
}
Esempio n. 29
0
File: cdgdk.c Progetto: LuaDist/cd
static void cdgetfontdim(cdCtxCanvas *ctxcanvas, int *max_width, int *height, int *ascent, int *descent)
{
  PangoFontMetrics* metrics;
  int charwidth, charheight, charascent, chardescent;

  if(!ctxcanvas->fontdesc)
    return;

  metrics = pango_context_get_metrics(ctxcanvas->fontcontext, ctxcanvas->fontdesc, pango_context_get_language(ctxcanvas->fontcontext));
  charascent  = pango_font_metrics_get_ascent(metrics);
  chardescent = pango_font_metrics_get_descent(metrics);
  charheight  = charascent + chardescent;
  charwidth   = pango_font_metrics_get_approximate_char_width(metrics);

  if (max_width) *max_width = (((charwidth)   + PANGO_SCALE/2) / PANGO_SCALE);
  if (height)    *height    = (((charheight)  + PANGO_SCALE/2) / PANGO_SCALE);
  if (ascent)    *ascent    = (((charascent)  + PANGO_SCALE/2) / PANGO_SCALE);
  if (descent)   *descent   = (((chardescent) + PANGO_SCALE/2) / PANGO_SCALE);

  pango_font_metrics_unref(metrics); 
}
static int
get_font_height_for_widget (GtkWidget *widget)
{
        PangoFontMetrics *metrics;
        PangoContext     *context;
        int               ascent;
        int               descent;
        int               height;

        gtk_widget_ensure_style (widget);
        context = gtk_widget_get_pango_context (widget);
        metrics = pango_context_get_metrics (context,
                                             widget->style->font_desc,
                                             pango_context_get_language (context));

        ascent = pango_font_metrics_get_ascent (metrics);
        descent = pango_font_metrics_get_descent (metrics);
        height = PANGO_PIXELS (ascent + descent);
        pango_font_metrics_unref (metrics);
        return height;
}