예제 #1
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);

}
예제 #2
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);
}
예제 #3
0
파일: screen.c 프로젝트: Distrotech/xfwm4
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;
}
예제 #4
0
파일: printing.c 프로젝트: Hamakor/geany
/* 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;
}
예제 #5
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;
}
예제 #6
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);
}
예제 #7
0
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);
}
예제 #8
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;
}
예제 #9
0
파일: textbox.c 프로젝트: guyhughes/rofi
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;
}
예제 #10
0
파일: textbox.c 프로젝트: guyhughes/rofi
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();
}
예제 #12
0
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
}
예제 #13
0
파일: data_view.c 프로젝트: tuxdna/anjuta
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);
}
예제 #14
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;
}
예제 #15
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);
}
예제 #16
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);
    }
}
예제 #17
0
파일: draw.c 프로젝트: ralfwierzbicki/dwm
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);
}
예제 #18
0
파일: snd-gutils.c 프로젝트: huangjs/cl
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);
}
예제 #19
0
파일: decorator.c 프로젝트: micove/compiz
/*
 * 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);
}
예제 #20
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);
}
예제 #21
0
파일: data_view.c 프로젝트: tuxdna/anjuta
static void
get_widget_char_size (GtkWidget *widget, gint *width, gint *height)
{
	PangoFontMetrics *metrics;
	PangoContext *context;
	PangoFontDescription *font_desc;

	font_desc = pango_font_description_from_string ("Monospace 10");
	
	context = gtk_widget_get_pango_context (widget);
	metrics = pango_context_get_metrics (context,
				       /*widget->style->font_desc,*/
					   font_desc,
				       pango_context_get_language (context));

	*height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
							   pango_font_metrics_get_descent (metrics));
	*width = (pango_font_metrics_get_approximate_char_width (metrics) + PANGO_SCALE - 1) / PANGO_SCALE;
	pango_font_metrics_unref (metrics);
	pango_font_description_free (font_desc);
}
예제 #22
0
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;
}
예제 #23
0
파일: cdgdk.c 프로젝트: 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); 
}
예제 #24
0
PangoAttrList *
create_fancy_attr_list_for_layout (PangoLayout *layout)
{
  PangoAttrList *attrs;
  PangoFontMetrics *metrics;
  int ascent;
  PangoRectangle ink_rect, logical_rect;
  const char *p;

  /* 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);
  logical_rect.x = 0;
  logical_rect.width = ascent;
  logical_rect.y = -ascent;
  logical_rect.height = ascent;
  ink_rect = logical_rect;
  pango_font_metrics_unref (metrics);

  /* Set fancy shape attributes for all hearts */
  attrs = pango_attr_list_new ();
  for (p = text; (p = strstr (p, HEART)); p += strlen (HEART))
    {
      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 + strlen (HEART);

      pango_attr_list_insert (attrs, attr);
    }

  return attrs;
}
예제 #25
0
static void rc_ui_scrollable_label_get_preferred_height(GtkWidget *widget,
        gint *min_height, gint *nat_height)
{
    RCUiScrollableLabelPrivate *priv;
    PangoFontMetrics *metrics;
    PangoContext *context;
    gint ascent, descent;
    gint height;
    if(widget==NULL) return;
    priv = RC_UI_SCROLLABLE_LABEL(widget)->priv;
    if(priv==NULL) return;
    context = pango_layout_get_context(priv->layout);
    if(context==NULL) return;
    metrics = pango_context_get_metrics(context,
                                        pango_layout_get_font_description(priv->layout), NULL);
    ascent = pango_font_metrics_get_ascent(metrics);
    descent = pango_font_metrics_get_descent(metrics);
    pango_font_metrics_unref(metrics);
    height = PANGO_PIXELS(ascent + descent);
    *min_height = height;
    *nat_height = height;
}
static int
get_pango_vertical_offset (PangoLayout *layout)
{
	const PangoFontDescription *desc;
	PangoContext               *context;
	PangoLanguage              *language;
	PangoFontMetrics           *metrics;
	int                         baseline;
	int                         strikethrough;
	int                         thickness;

	context = pango_layout_get_context (layout);
	language = pango_language_get_default ();
	desc = pango_layout_get_font_description (layout);
	metrics = pango_context_get_metrics (context, desc, language);

	baseline = pango_layout_get_baseline (layout);
	strikethrough =  pango_font_metrics_get_strikethrough_position (metrics);
	thickness =  pango_font_metrics_get_underline_thickness (metrics);

	return PANGO_PIXELS (baseline - strikethrough - thickness / 2);
}
예제 #27
0
파일: snd-gutils.c 프로젝트: huangjs/cl
static int sg_font_height(PangoFontDescription *font)
{
  /* returns size in pixels */
  double dpi = 96.0; /* a plausible guess */
  int hgt = 0;
  PangoContext *ctx;
  PangoFontMetrics *m;

#if HAVE_GTK_LINK_BUTTON_NEW
  /* gtk 2.1: gdk_display_get_default, gdk_display_get_default_screen */
  /* gtk 2.9: gdk_screen_get_resolution */
  dpi = gdk_screen_get_resolution(gdk_display_get_default_screen(gdk_display_get_default()));
#endif

  ctx = gdk_pango_context_get();
  m = pango_context_get_metrics(ctx, font, gtk_get_default_language());
  hgt = (int)((dpi / 72.0) * PANGO_PIXELS(pango_font_metrics_get_ascent(m)));
  pango_font_metrics_unref(m);
  g_object_unref(ctx);
      
  return(hgt);
}
예제 #28
0
static gint
wnck_selector_get_width (GtkWidget *widget, const char *text)
{
  GtkStyleContext *style_context;
  GtkStateFlags state;
  PangoContext *context;
  PangoFontMetrics *metrics;
  PangoFontDescription *description;
  gint char_width;
  PangoLayout *layout;
  PangoRectangle natural;
  gint max_width;
  gint screen_width;
  gint width;

  state = gtk_widget_get_state_flags (widget);
  style_context = gtk_widget_get_style_context (widget);
  gtk_style_context_get (style_context, state, GTK_STYLE_PROPERTY_FONT, &description, NULL);

  context = gtk_widget_get_pango_context (widget);
  metrics = pango_context_get_metrics (context, description,
                                       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;
}
예제 #29
0
static void
bytes_view_ensure_layout(BytesView *bv)
{
	if (bv->context == NULL) {
		bv->context = gtk_widget_get_pango_context(GTK_WIDGET(bv));
		g_object_ref(bv->context);

		{
		PangoLanguage *lang;
		PangoFontMetrics *metrics;

			/* vte and xchat does it this way */
			lang = pango_context_get_language(bv->context);
			metrics = pango_context_get_metrics(bv->context, bv->font, lang);
			bv->font_ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE;
			bv->font_descent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
			pango_font_metrics_unref(metrics);

			bv->fontsize = bv->font_ascent + bv->font_descent;
		}
		g_assert(bv->context);
		bytes_view_adjustment_set(bv);
	}
}
예제 #30
0
static void
schgui_cairo_drafter_draw_text(SchGUICairoDrafter *drafter, const struct _SchText *text)
{
    if (text != NULL)
    {
        int visible;

        sch_text_get_visible(text, &visible);

        if (visible)
        {

    SchGUICairoDrafterPrivate *privat = SCHGUI_CAIRO_DRAFTER_GET_PRIVATE(drafter);

    if (privat->cairo != NULL)
    {
        PangoLayout *layout;
        SchMultiline *multiline = sch_text_get_multiline(text);
        int point_size = sch_text_get_size(text);
        float height;
        int alignment;
        cairo_font_options_t *options;
        PangoContext *context;
        int baseline;
        PangoLayoutIter *iter;
        int index;
        int show;
        SchGUIDrawingCfgColor color;
        int          enabled;

        sch_text_get_color(text, &index);

        enabled = schgui_drawing_cfg_get_color(privat->config, index, &color);

        if (enabled)
        {
            if (0) /* show ink rect */
            {
                GeomBounds bounds;
                int        success;

                success = schgui_cairo_drafter_text_bounds(drafter, text, &bounds);

                if (success)
                {
                    cairo_set_source_rgb(privat->cairo, 1.0, 0, 0);
                
                    cairo_move_to(privat->cairo, bounds.min_x, bounds.min_y);
                    cairo_line_to(privat->cairo, bounds.max_x, bounds.min_y);
                
                    cairo_stroke(privat->cairo);

                    cairo_set_source_rgb(privat->cairo, 0.75, 0, 0);
                
                    cairo_move_to(privat->cairo, bounds.max_x, bounds.min_y);
                    cairo_line_to(privat->cairo, bounds.max_x, bounds.max_y);
                    cairo_line_to(privat->cairo, bounds.min_x, bounds.max_y);
                    cairo_line_to(privat->cairo, bounds.min_x, bounds.min_y);
                    //cairo_close_path(privat->cairo);

                    cairo_stroke(privat->cairo);
                
                    cairo_set_source_rgb(privat->cairo, 0, 0, 0);
                }

                cairo_set_source_rgb(privat->cairo, 0, 0, 1.0);
                cairo_new_sub_path(privat->cairo);
                cairo_arc(privat->cairo, sch_text_get_x(text), sch_text_get_y(text), 10, 0, 2 * M_PI);
                cairo_stroke(privat->cairo);
                cairo_set_source_rgb(privat->cairo, 0, 0, 0);
            }

            cairo_save(privat->cairo);
   
            height = 1000 * point_size / 72;

            layout = pango_cairo_create_layout(privat->cairo);
            pango_cairo_context_set_resolution(pango_layout_get_context(layout), 936);

//  context = pango_layout_get_context(layout);
//  options = cairo_font_options_create ();
//  cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
//  cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_MEDIUM);
//  pango_cairo_context_set_font_options (context, options);
//  cairo_font_options_destroy (options);


            cairo_set_source_rgb(privat->cairo, color.red, color.green, color.blue);


            pango_font_description_set_size(privat->desc, point_size * PANGO_SCALE );
            pango_layout_set_spacing(layout, 40000);
        
            pango_layout_set_font_description(layout, privat->desc);

            sch_text_get_show(text, &show);
            pango_layout_set_markup(layout, sch_multiline_peek_markup(multiline, show), -1);


            PangoFontMetrics *metrics = pango_context_get_metrics(
                pango_layout_get_context(layout),
                privat->desc,
                NULL
                );

        
            cairo_move_to(privat->cairo, sch_text_get_x(text), sch_text_get_y(text));
        
            cairo_rotate(privat->cairo, M_PI * sch_text_get_angle(text) / 180);

            cairo_scale(privat->cairo, 1, -1);

            baseline = pango_layout_get_baseline(layout); 

            alignment = sch_text_get_alignment(text);
#if 1
            switch (alignment)
            {
                case 2:
                case 5:
                case 8: 
                /* upper */
                //cairo_rel_move_to(privat->cairo, 0, -pango_font_metrics_get_ascent(metrics)/(privat->zoom * PANGO_SCALE));
                //cairo_rel_move_to(privat->cairo, 0, height);
                break;

                case 1:
                case 4:
                case 7:
                    /* center */
                    cairo_rel_move_to(privat->cairo, 0, -pango_font_metrics_get_ascent(metrics)/(privat->zoom * PANGO_SCALE));
                    cairo_rel_move_to(privat->cairo, 0, height);
                    cairo_rel_move_to(privat->cairo, 0, -pango_font_metrics_get_ascent(metrics) * sch_multiline_lines(multiline)/(2 * privat->zoom * PANGO_SCALE));
                    cairo_rel_move_to(privat->cairo, 0, -pango_font_metrics_get_descent(metrics) * (sch_multiline_lines(multiline) - 1)/(2 * privat->zoom * PANGO_SCALE));
                    break;

                case 0:
                case 3:
                case 6:
                default:
                    /* lower */
                    //cairo_rel_move_to(privat->cairo, 0, -pango_font_metrics_get_ascent(metrics) * sch_multiline_lines(multiline)/(privat->zoom * PANGO_SCALE));
                    //cairo_rel_move_to(privat->cairo, 0, -pango_font_metrics_get_descent(metrics) * (sch_multiline_lines(multiline)-1)/(privat->zoom * PANGO_SCALE));
                    //cairo_rel_move_to(privat->cairo, 0, -pango_layout_get_spacing(layout) * (sch_multiline_lines(multiline)-1)/ PANGO_SCALE);
                    iter = pango_layout_get_iter(layout);
                    while (!pango_layout_iter_at_last_line(iter))
                    {
                        pango_layout_iter_next_line(iter);
                    }
                    cairo_rel_move_to(privat->cairo, 0, -pango_layout_iter_get_baseline(iter) / PANGO_SCALE);
                    pango_layout_iter_free(iter);
            }
#endif

            //g_debug("Ascent:    %d", pango_font_metrics_get_ascent(metrics));
            //g_debug("Descent:   %d", pango_font_metrics_get_descent(metrics));
            //g_debug("Spacing:   %d", pango_layout_get_spacing(layout));
            //g_debug("Font size: %d", pango_font_description_get_size(privat->desc));
            //g_debug("Baseline   %d", pango_layout_get_baseline(layout));            

            pango_font_metrics_unref(metrics);

            pango_cairo_show_layout(privat->cairo, layout);

            cairo_restore(privat->cairo);

            g_object_unref(layout);
        }
    }
}
}
 
}