Пример #1
1
static void try_to_get_windows_font (void)
{
    gchar *fontspec = default_windows_menu_fontspec();

    if (fontspec != NULL) {
        int match = 0;
        PangoFontDescription *pfd;
        PangoFont *pfont;
        PangoContext *pc;
        GtkWidget *w;

        pfd = pango_font_description_from_string(fontspec);

        w = gtk_label_new(NULL);
        pc = gtk_widget_get_pango_context(w);
        pfont = pango_context_load_font(pc, pfd);
        match = (pfont != NULL);

        pango_font_description_free(pfd);
        g_object_unref(G_OBJECT(pc));
        gtk_widget_destroy(w);

        if (match) set_app_font(fontspec);
        g_free(fontspec);
    }
}
Пример #2
0
LoadGraph *load_graph_new(gint size)
{
    LoadGraph *lg;

    lg = g_new0(LoadGraph, 1);

    size++;

    lg->suffix = g_strdup("");
    lg->area = gtk_drawing_area_new();
    lg->size = (size * 3) / 2;
    lg->data = g_new0(gint, lg->size);

    lg->scale = 1.0;

    lg->width = size * 6;
    lg->height = size * 2;

    lg->max_value = 1;
    lg->remax_count = 0;

    lg->layout = pango_layout_new(gtk_widget_get_pango_context(lg->area));

    gtk_widget_set_size_request(lg->area, lg->width, lg->height);
    gtk_widget_show(lg->area);

    return lg;
}
Пример #3
0
GtkWidget *
lmplayer_lyric_widget_da_new()
{
	LmplayerLyricWidgetDa *lyric;
	LmplayerLyricWidgetDaPrivate *priv;

	lyric = g_object_new(LMPLAYER_TYPE_LYRIC_WIDGET_DA, NULL);

	priv = lyric->priv;
	priv->alignment = gtk_alignment_new(0, 0, 1, 1);
	gtk_widget_show(priv->alignment);

	priv->da = gtk_drawing_area_new();
	gtk_widget_show(priv->da);

	//priv->da_gc = gdk_gc_new(priv->da->window);
	priv->pango_context = gtk_widget_get_pango_context(priv->da);
	priv->pango_layout = pango_layout_new(priv->pango_context);

	gtk_container_add(GTK_CONTAINER(priv->alignment), priv->da);
	gtk_container_add(GTK_CONTAINER(lyric), priv->alignment);

	gtk_widget_set_events(priv->da, GDK_EXPOSURE_MASK);

	g_signal_connect(G_OBJECT(lyric), "expose-event", G_CALLBACK(layout_expose_cb), lyric);
	g_signal_connect(G_OBJECT(priv->da), "expose-event", G_CALLBACK(da_expose_cb), lyric);
	g_signal_connect(G_OBJECT(priv->da), "configure-event", G_CALLBACK(da_configure_cb), lyric);

	return GTK_WIDGET(lyric);
}
Пример #4
0
//		Narysowanie zawartosci calego okna (z legenda, opisami osi i charakterystykami)
void t_display_przerysuj(T_Display *w)
{
		int szer, wys ;
		double units_per_pixel_x ;
		//double units_per_pixel_y ;
		
		szer = w->canvas->allocation.width ;
		wys = w->canvas->allocation.height ;
		
		units_per_pixel_x = (double)w->time_range / ((double)szer) ;
		
		//PangoLayout *etykieta = gtk_widget_create_pango_layout (w->canvas, "");									
		PangoContext *pc = gtk_widget_get_pango_context (w->canvas) ;
		PangoFontDescription* pfd = pango_context_get_font_description (pc) ;
		//printf ("czcionka %d\n", pango_font_description_get_size(pfd)) ;
		pango_font_description_set_size (pfd, w->font_size * PANGO_SCALE) ;
		//pango_layout_context_changed(etykieta) ;
		
		
		t_display_draw_legend(w) ;
		t_display_calculate_borders(w) ;
		t_display_rysuj_siatke_czas(w) ;
		t_display_rysuj_siatke_temp(w) ;
		t_display_draw_plots(w) ;
		
} ;
Пример #5
0
static void
gimp_number_pair_entry_modify_font (GimpNumberPairEntry *entry,
                                    gboolean             italic)
{
  GimpNumberPairEntryPrivate *priv = GIMP_NUMBER_PAIR_ENTRY_GET_PRIVATE (entry);
  GtkRcStyle                 *rc_style;

  if (priv->font_italic == italic)
    return;

  rc_style = gtk_widget_get_modifier_style (GTK_WIDGET (entry));

  if (! rc_style->font_desc)
    {
      PangoContext         *context;
      PangoFontDescription *font_desc;

      context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
      font_desc = pango_context_get_font_description (context);

      rc_style->font_desc = pango_font_description_copy (font_desc);
    }

  pango_font_description_set_style (rc_style->font_desc,
                                    italic ?
                                    PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);

  gtk_widget_modify_style (GTK_WIDGET (entry), rc_style);

  priv->font_italic = italic;
}
Пример #6
0
static void
apply_values (void)
{
	gchar *utf;
	grg_ctx_set_crypt_algo (gctx, tmp_pref_crypto);
	grg_ctx_set_hash_algo (gctx, tmp_pref_hash);
	grg_ctx_set_comp_algo (gctx, tmp_pref_comp);
	grg_ctx_set_comp_ratio (gctx, tmp_pref_ratio);
	g_free (grg_pref_file);
	grg_pref_file =
		g_strdup (gtk_entry_get_text (GTK_ENTRY (file_entry)));
	utf = g_filename_from_utf8 (grg_pref_file, -1, NULL, NULL, NULL);
	if (!g_file_test (utf, G_FILE_TEST_IS_REGULAR))
	{
		g_free (grg_pref_file);
		grg_pref_file = NULL;
		gtk_entry_set_text (GTK_ENTRY (file_entry), "");
	}
	g_free (utf);

	set_pref_font_string (pango_font_description_to_string
			      (pango_context_get_font_description
			       (gtk_widget_get_pango_context
				(gtk_bin_get_child (GTK_BIN (but_font))))));
	set_editor_font (grg_prefs_editor_font);

	update_saveable (GRG_SAVE_ACTIVE);
	grg_save_prefs ();
}
Пример #7
0
static GdkPixbuf* accessx_status_applet_get_glyph_pixbuf(AccessxStatusApplet* sapplet, GtkWidget* widget, GdkPixbuf* base, GdkColor* fg, GdkColor* bg, gchar* glyphstring)
{
	GdkPixbuf* glyph_pixbuf;
	cairo_surface_t *surface;
	PangoLayout* layout;
	PangoRectangle ink, logic;
	PangoContext* pango_context;
	gint w = gdk_pixbuf_get_width(base);
	gint h = gdk_pixbuf_get_height(base);
	cairo_t *cr;

	surface = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR_ALPHA, w, h);
	pango_context = gtk_widget_get_pango_context(widget);
	layout = pango_layout_new(pango_context);
	pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
	pango_layout_set_text(layout, glyphstring, -1);

	cr = cairo_create (surface);
	gdk_cairo_set_source_color (cr, bg);
	cairo_paint (cr);
	gdk_cairo_set_source_color (cr, fg);

	pango_layout_get_pixel_extents(layout, &ink, &logic);

	cairo_move_to (cr, (w - ink.x - ink.width)/2, (h - ink.y - ink.height)/2);
	pango_cairo_show_layout (cr, layout);
	cairo_destroy (cr);

	g_object_unref(layout);
	glyph_pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h);
	cairo_surface_destroy (surface);

	return glyph_pixbuf;
}
Пример #8
0
static GnomeFont *find_proper_font(gunichar ch)
{
//	GnomeFont *gfont;
    GnomeFontFace *gface;
    PangoFont *pfont;
    PangoFontset *pfontset;

    pfontset = pango_context_load_fontset(
                   gtk_widget_get_pango_context(pub->mw->view),
                   gtk_widget_get_style(pub->mw->view)->font_desc,
                   gtk_get_default_language());
    pfont = pango_fontset_get_font(pfontset, ch);
    /*
    	g_print("\n%s\n",
    		pango_font_description_to_string(
    			pango_font_describe(pfont)
    		)
    	);
    */
    gface =
        gnome_font_face_find_closest_from_pango_font(pfont);
    g_object_unref(pfont);

    return gnome_font_face_get_font_default(gface, FONT_SIZE);
}
Пример #9
0
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;
}
static PangoLayout *
create_layout_with_attrs (GtkWidget *widget,
                          GdTwoLinesRenderer *self,
                          PangoEllipsizeMode ellipsize)
{
  PangoLayout *layout;
  gint wrap_width;
  PangoWrapMode wrap_mode;
  PangoAlignment alignment;

  g_object_get (self,
                "wrap-width", &wrap_width,
                "wrap-mode", &wrap_mode,
                "alignment", &alignment,
                NULL);

  layout = pango_layout_new (gtk_widget_get_pango_context (widget));

  pango_layout_set_ellipsize (layout, ellipsize);
  pango_layout_set_wrap (layout, wrap_mode);
  pango_layout_set_alignment (layout, alignment);

  if (wrap_width != -1)
    pango_layout_set_width (layout, wrap_width * PANGO_SCALE);

  return layout;
}
static gboolean
expose_cb (GtkWidget		*widget,
	   GdkEventExpose	*event,
	   ccss_style_t const	*style)
{
	cairo_t	 *cr;	
	char    *font_family;

	cr = gdk_cairo_create (widget->window);

	font_family = NULL;
	ccss_style_get_string (style, "font-family", &font_family);

	if (font_family) {
		PangoContext			 *context;
		PangoLayout			 *layout;

		context = gtk_widget_get_pango_context (widget);
		layout = pango_layout_new (context);
		pango_layout_set_text (layout, font_family, strlen (font_family));
		pango_cairo_show_layout (cr, layout);
		g_object_unref (G_OBJECT (layout)), layout = NULL;
	}

	cairo_destroy (cr);

	return FALSE;
}
Пример #12
0
GdkPixbuf *
gitg_label_renderer_render_ref (GtkWidget *widget, PangoFontDescription *description, GitgRef *ref, gint height, gint minwidth)
{
	PangoContext *ctx = gtk_widget_get_pango_context(widget);
	PangoLayout *layout = pango_layout_new(ctx);
	pango_layout_set_font_description(layout, description);

	gint width = MAX(get_label_width (layout, ref), minwidth);

	cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width + 2, height + 2);
	cairo_t *context = cairo_create (surface);

	cairo_set_line_width (context, 1);

	render_label (context, layout, ref, 1, 1, height, FALSE);

	guint8 *data = cairo_image_surface_get_data (surface);
	GdkPixbuf *ret = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width + 2, height + 2);
	guint8 *pixdata = gdk_pixbuf_get_pixels (ret);

	convert_bgra_to_rgba (data, pixdata, width + 2, height + 2);

	cairo_destroy (context);
	cairo_surface_destroy (surface);

	g_object_unref (layout);

	return ret;
}
Пример #13
0
static void
run_fontsel_settings_dlg(SettingsWidget *sw) {
    GtkWidget *dlg;
    const gchar *newfont;
    gchar *oldfont;

    dlg = gtk_font_selection_dialog_new(_("Select font"));
    gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dlg),
                                            gtk_label_get_text(GTK_LABEL(sw->widget)));

    if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK) {
        gtk_label_set_text(GTK_LABEL(sw->widget),
                           gtk_font_selection_dialog_get_font_name(
                               GTK_FONT_SELECTION_DIALOG(dlg)));
    }


    newfont = gtk_label_get_text(GTK_LABEL(sw->widget));
    oldfont = pango_font_description_to_string(
                  pango_context_get_font_description(
                      gtk_widget_get_pango_context(GTK_WIDGET(sw->data))));

    if (newfont && g_ascii_strcasecmp(oldfont, newfont) != 0) {
        string_replace(sw->conf, g_strdup(newfont));
        jam_widget_set_font(sw->widget, newfont);
        jam_widget_set_font(sw->data, newfont);
    }
    g_free(oldfont);

    gtk_widget_destroy(dlg);
}
Пример #14
0
//__________________________________________________________________
_HYRect _HYPullDown::_SuggestDimensions (void)
{
    _HYRect res = {25,100,25,100,HY_COMPONENT_NO_SCROLL};

    if (theMenu) {
        long            naturalWidth = 0;
        PangoLayout *   fontMeasurer = nil;
        for (long k=0; k<widgetList.lLength; k+=2) {
            GtkWidget * dropWidget = GTK_WIDGET (widgetList(k));
            if (!fontMeasurer) {
                fontMeasurer = pango_layout_new (gtk_widget_get_pango_context (dropWidget));
            }

            pango_layout_set_text(fontMeasurer,GetMenuItem(k/2)->sData ,GetMenuItem(k/2)->sLength);
            PangoRectangle extents,
                           log_ext;
            pango_layout_get_pixel_extents (fontMeasurer,&extents,nil);
            if (extents.width > naturalWidth) {
                naturalWidth = extents.width;
            }
        }
        if (fontMeasurer) {
            g_object_unref (fontMeasurer);
        }

        res.right = res.left = naturalWidth+25;
    }

    return res;
}
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);
}
Пример #16
0
// Get Gtk needed elements, if we have not them yet.
void wxTextMeasure::BeginMeasuring()
{
    if ( m_dc )
    {
#ifndef __WXGTK3__
        m_wdc = wxDynamicCast(m_dc->GetImpl(), wxWindowDCImpl);
        if ( m_wdc )
        {
            m_context = m_wdc->m_context;
            m_layout = m_wdc->m_layout;
        }
#endif // GTK+ < 3
    }
    else if ( m_win )
    {
        m_context = gtk_widget_get_pango_context( m_win->GetHandle() );
        if ( m_context )
            m_layout = pango_layout_new(m_context);
    }

    // set the font to use
    if ( m_layout )
    {
        pango_layout_set_font_description(m_layout,
                                          GetFont().GetNativeFontInfo()->description);
    }
}
Пример #17
0
static void
gimp_scale_combo_box_style_set (GtkWidget *widget,
                                GtkStyle  *prev_style)
{
  GtkWidget  *entry;
  GtkRcStyle *rc_style;
  gint        font_size;
  gdouble     scale;

  GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);

  gtk_widget_style_get (widget, "label-scale", &scale, NULL);

  entry = gtk_bin_get_child (GTK_BIN (widget));

  rc_style = gtk_widget_get_modifier_style (GTK_WIDGET (entry));

  if (! rc_style->font_desc)
    {
      PangoContext         *context;
      PangoFontDescription *font_desc;

      context = gtk_widget_get_pango_context (widget);
      font_desc = pango_context_get_font_description (context);

      rc_style->font_desc = pango_font_description_copy (font_desc);
    }

  font_size = pango_font_description_get_size (rc_style->font_desc);
  pango_font_description_set_size (rc_style->font_desc, scale * font_size);

  gtk_widget_modify_style (GTK_WIDGET (entry), rc_style);
}
Пример #18
0
gint
gitg_label_renderer_width(GtkWidget *widget, PangoFontDescription *font, GSList *labels)
{
    gint width = 0;
    GSList *item;

    if (labels == NULL)
        return 0;

    PangoContext *ctx = gtk_widget_get_pango_context(widget);
    PangoLayout *layout = pango_layout_new(ctx);
    pango_layout_set_font_description(layout, font);

    for (item = labels; item; item = item->next)
    {
        gint w;
        GitgRef *ref = (GitgRef *)item->data;
        gchar *smaller = g_strdup_printf("<span size='smaller'>%s</span>", ref->shortname);
        pango_layout_set_markup(layout, smaller, -1);

        pango_layout_get_pixel_size(layout, &w, NULL);

        width += w + PADDING * 2 + MARGIN;
        g_free(smaller);
    }

    g_object_unref(layout);
    //g_object_unref(ctx);

    return width + MARGIN;
}
	static void
	fill_font_families_combo (MucharmapMiniFontSelection *fontsel)
	{
	  GtkComboBox *combo = GTK_COMBO_BOX (fontsel->family);
	  PangoFontFamily **families;
	  int n_families, i;

	  fontsel->family_store = gtk_list_store_new (1, G_TYPE_STRING);

	  pango_context_list_families (
		      gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
		      &families, &n_families);

	  for (i = 0;  i < n_families;  i++)
		{
		  PangoFontFamily *family = families[i];
		  GtkTreeIter iter;

		  gtk_list_store_insert_with_values (fontsel->family_store,
		                                     &iter,
		                                     -1,
		                                     COL_FAMILIY, pango_font_family_get_name (family),
		                                     -1);
		}

	  g_free (families);

	  /* Now turn on sorting in the combo box */
	  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (fontsel->family_store),
		                                    COL_FAMILIY,
		                                    GTK_SORT_ASCENDING);

	  gtk_combo_box_set_model (combo, GTK_TREE_MODEL (fontsel->family_store));
	  g_object_unref (fontsel->family_store);
	}
Пример #20
0
void GtkPaintContext::updatePixmap(GtkWidget *area, int w, int h) {
	if ((myPixmap != 0) && ((myWidth != w) || (myHeight != h))) {
		gdk_pixmap_unref(myPixmap);
		myPixmap = 0;
		if (myTextGC != 0) {
			gdk_gc_unref(myTextGC);
			gdk_gc_unref(myFillGC);
			gdk_gc_unref(myBackGC);
			myTextGC = 0;
			myFillGC = 0;
			myBackGC = 0;
		}
	}

	if (myPixmap == 0) {
		myWidth = w;
		myHeight = h;
		myPixmap = gdk_pixmap_new(area->window, myWidth, myHeight, gdk_drawable_get_depth(area->window));
	}

	if (myTextGC == 0) {
		myTextGC = gdk_gc_new(myPixmap);
		myFillGC = gdk_gc_new(myPixmap);
		myBackGC = gdk_gc_new(myPixmap);
	}

	if (myContext == 0) {
		myContext = gtk_widget_get_pango_context(area);
		if (myFontDescription != 0) {
			myAnalysis.font = pango_context_load_font(myContext, myFontDescription);
			myAnalysis.shape_engine = pango_font_find_shaper(myAnalysis.font, 0, 0);
		}
	}
}
Пример #21
0
/**
 * gwy_graph_label_new:
 *
 * Creates a new graph label.
 *
 * Returns: A new graph label widget as a #GtkWidget.
 **/
GtkWidget*
gwy_graph_label_new()
{
    GwyGraphLabel *label;
    PangoFontDescription *description;
    PangoContext *context;
    gint size;

    gwy_debug("");

    label = g_object_new(GWY_TYPE_GRAPH_LABEL, NULL);

    context = gtk_widget_get_pango_context(GTK_WIDGET(label));
    description = pango_context_get_font_description(context);

    /* Make major font a bit smaller */
    label->font_desc = pango_font_description_copy(description);
    size = pango_font_description_get_size(label->font_desc);
    size = MAX(1, size*10/11);
    pango_font_description_set_size(label->font_desc, size);

    gtk_widget_set_events(GTK_WIDGET(label), 0);

    return GTK_WIDGET(label);
}
Пример #22
0
static void set_app_font (const char *fontname)
{
    GtkSettings *settings;

    if (fontname != NULL && *fontname == 0) return;

    settings = gtk_settings_get_default();

    if (fontname == NULL) {
        g_object_set(G_OBJECT(settings), "gtk-font-name", appfontname, NULL);
    } else {
        GtkWidget *w;
        PangoFontDescription *pfd;
        PangoContext *pc;
        PangoFont *pfont;

        w = gtk_label_new(NULL);
        pfd = pango_font_description_from_string(fontname);
        pc = gtk_widget_get_pango_context(w);
        pfont = pango_context_load_font(pc, pfd);

        if (pfont != NULL) {
            strcpy(appfontname, fontname);
            g_object_set(G_OBJECT(settings), "gtk-font-name", appfontname,
                NULL);
        }

        gtk_widget_destroy(w);
        pango_font_description_free(pfd);
    }
}
Пример #23
0
void
gtk_plot_gdk_construct(GtkPlotGdk *pc, GtkWidget *widget)
{
  pc->window = widget->window;
  pc->context = gtk_widget_get_pango_context (widget);
  g_object_ref(G_OBJECT(pc->context));
  pc->layout = pango_layout_new(pc->context);
}
Пример #24
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);
}
Пример #25
0
static GdkPixbuf* accessx_status_applet_get_glyph_pixbuf(AccessxStatusApplet* sapplet, GtkWidget* widget, GdkPixbuf* base, GdkColor* fg, GdkColor* bg, gchar* glyphstring)
{
    GdkPixbuf* glyph_pixbuf;
#if GTK_CHECK_VERSION (3, 0, 0)
    cairo_surface_t *surface;
#else
    GdkPixbuf *alpha_pixbuf;
    GdkPixmap* pixmap;
#endif
    PangoLayout* layout;
    PangoRectangle ink, logic;
    PangoContext* pango_context;
    gint w = gdk_pixbuf_get_width(base);
    gint h = gdk_pixbuf_get_height(base);
    cairo_t *cr;

#if GTK_CHECK_VERSION (3, 0, 0)
    surface = gdk_window_create_similar_surface (gdk_get_default_root_window (), CAIRO_CONTENT_COLOR_ALPHA, w, h);
#else
    pixmap = gdk_pixmap_new(gdk_get_default_root_window (),w, h, -1);
#endif
    pango_context = gtk_widget_get_pango_context(widget);
    layout = pango_layout_new(pango_context);
    pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
    pango_layout_set_text(layout, glyphstring, -1);

#if GTK_CHECK_VERSION (3, 0, 0)
    cr = cairo_create (surface);
#else
    cr = gdk_cairo_create (pixmap);
#endif
    gdk_cairo_set_source_color (cr, bg);
    cairo_paint (cr);
    gdk_cairo_set_source_color (cr, fg);

    pango_layout_get_pixel_extents(layout, &ink, &logic);

    cairo_move_to (cr, (w - ink.x - ink.width)/2, (h - ink.y - ink.height)/2);
    pango_cairo_show_layout (cr, layout);
    cairo_destroy (cr);

    g_object_unref(layout);
#if GTK_CHECK_VERSION (3, 0, 0)
    glyph_pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h);
    cairo_surface_destroy (surface);

    return glyph_pixbuf;
#else
    glyph_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0, w, h);
    g_object_unref(pixmap);
    alpha_pixbuf = gdk_pixbuf_add_alpha(glyph_pixbuf, TRUE, bg->red >> 8, bg->green >> 8, bg->blue >> 8);
    g_object_unref(G_OBJECT(glyph_pixbuf));

    return alpha_pixbuf;
#endif
}
Пример #26
0
static void
gd_tagged_entry_tag_ensure_layout (GdTaggedEntryTag *tag,
                                   GdTaggedEntry *entry)
{
    if (tag->layout != NULL)
        return;

    tag->layout = pango_layout_new (gtk_widget_get_pango_context (GTK_WIDGET (entry)));
    pango_layout_set_text (tag->layout, tag->label, -1);
}
Пример #27
0
static void
gnm_font_button_update_font_data (GnmFontButton *font_button)
{
  GnmFontButtonPrivate *priv = font_button->priv;
  PangoFontFamily **families;
  PangoFontFace **faces;
  gint n_families, n_faces, i;
  const gchar *family;

  g_assert (priv->font_desc != NULL);

  priv->fontname = pango_font_description_to_string (priv->font_desc);

  family = pango_font_description_get_family (priv->font_desc);
  if (family == NULL)
    return;

  n_families = 0;
  families = NULL;
  pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (font_button)),
                               &families, &n_families);
  n_faces = 0;
  faces = NULL;
  for (i = 0; i < n_families; i++)
    {
      const gchar *name = pango_font_family_get_name (families[i]);

      if (!g_ascii_strcasecmp (name, family))
        {
          priv->font_family = g_object_ref (families[i]);

          pango_font_family_list_faces (families[i], &faces, &n_faces);
          break;
        }
    }
  g_free (families);

  for (i = 0; i < n_faces; i++)
    {
      PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]);

      if (font_description_style_equal (tmp_desc, priv->font_desc))
        {
          priv->font_face = g_object_ref (faces[i]);

          pango_font_description_free (tmp_desc);
          break;
        }
      else
        pango_font_description_free (tmp_desc);
    }

  g_free (faces);
}
Пример #28
0
PangoContext *
getUIPangoContext (GtkWidget * win)
{
    TRACE ("entering getUIPangoContext");

    g_return_val_if_fail (win != NULL, NULL);
    g_return_val_if_fail (GTK_IS_WIDGET (win), NULL);
    g_return_val_if_fail (GTK_WIDGET_REALIZED (win), NULL);

    return (gtk_widget_get_pango_context (win));
}
Пример #29
0
static int
get_text_height (GtkWidget *widget)
{
  GtkStyleContext *style;
  const PangoFontDescription *font_desc;

  style = gtk_widget_get_style_context (widget);
  font_desc = gtk_style_context_get_font (style, 0);
  return meta_pango_font_desc_get_text_height (font_desc,
                                               gtk_widget_get_pango_context (widget));
}
Пример #30
0
static void
update_hours_sidebar_size (GcalWeekView *self)
{
  GtkStyleContext *context;
  GtkStateFlags state;
  GtkSizeGroup *sidebar_sizegroup;
  GtkWidget *widget;
  GtkBorder padding;

  PangoLayout *layout;
  PangoFontDescription *font_desc;

  gint hours_12_width, hours_24_width, sidebar_width;
  gint hours_12_height, hours_24_height, cell_height;

  widget = GTK_WIDGET (self);
  context = gtk_widget_get_style_context (widget);
  state = gtk_style_context_get_state (context);

  gtk_style_context_save (context);
  gtk_style_context_add_class (context, "hours");

  gtk_style_context_get (context, state,
                         "font", &font_desc,
                         NULL);
  gtk_style_context_get_padding (context, state, &padding);

  layout = pango_layout_new (gtk_widget_get_pango_context (widget));
  pango_layout_set_font_description (layout, font_desc);

  pango_layout_set_text (layout, _("00 AM"), -1);
  pango_layout_get_pixel_size (layout, &hours_12_width, &hours_12_height);

  pango_layout_set_text (layout, _("00:00"), -1);
  pango_layout_get_pixel_size (layout, &hours_24_width, &hours_24_height);

  sidebar_width = MAX (hours_12_width, hours_24_width) + padding.left + padding.right;
  cell_height = MAX (hours_12_height, hours_24_height) + padding.top + padding.bottom + 1;

  gtk_style_context_restore (context);

  /* Update the size requests */
  gtk_widget_set_size_request (self->hours_bar,
                               sidebar_width,
                               48 * cell_height);

  /* Sync with the week header sidebar */
  sidebar_sizegroup = gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header));
  gtk_size_group_add_widget (sidebar_sizegroup, self->hours_bar);

  pango_font_description_free (font_desc);
  g_object_unref (layout);
}