Beispiel #1
0
void
tViewer::set_text(gchar * str_w, gchar * str_m)
{
	str1 = str_w;
	str2 = str_m;
	if (layout_w)
		pango_layout_set_text(layout_w,str1,-1);
	else {
		layout_w=gtk_widget_create_pango_layout (text_area, str1);
		pango_layout_set_font_description(layout_w,Skin->reciteword.b_font);
	}
	if (layout_m) {
		if (str2) {
			pango_layout_set_text(layout_m,str2,-1);
		} else {
			pango_layout_set_text(layout_m,"",-1);
		}
	}
	else
		layout_m=gtk_widget_create_pango_layout (text_area, str2);
	if (g_pReciteWord->revise_skim->readword_ckbutton.status)
		readword(str_w);
	if (str1[0]!='\0')
	{
		gchar aa[5];
		sprintf(aa,"%2d",now_count+1);
		gtk_label_set_text (GTK_LABEL (g_pReciteWord->revise_skim->word_index_label),
					aa);
	}
}
Beispiel #2
0
void tree_view_column_set_default_width (GtkTreeView *view,
                                         GtkTreeViewColumn *column,
                                         const gchar *sizing_text)
{
    PangoLayout* layout;
    int default_width, title_width;
    const gchar *column_title;

    /* Default size is the larger of the column title and the sizing text */
    column_title = gtk_tree_view_column_get_title (column);
    layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), column_title);
    pango_layout_get_pixel_size(layout, &title_width, NULL);
    g_object_unref(layout);
    layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), sizing_text);
    pango_layout_get_pixel_size(layout, &default_width, NULL);
    g_object_unref(layout);
    default_width = MAX(default_width, title_width);
    if (default_width)
    {
        default_width += 10; /* add some padding */
        g_object_set(G_OBJECT(column),
                     "sizing",      GTK_TREE_VIEW_COLUMN_FIXED,
                     "fixed-width", default_width,
                     NULL);
    }
}
void sarl_lattice_view_interp_recalc_labels_for(
  SarlLatticeView                       *view, 
  sarl_lattice_view_interp_t            *view_interp,
  sarl_contingent_interp_t              *cont_interp,
  SarlLabelKind                          kind,
  sarl_signed_int                        ox, 
  sarl_signed_int                        oy
)
{
  sarl_power_map_t   *cont_map = cont_interp->contingents;
  sarl_bit_set_t     *cont;

  sarl_label_t*       label;
  sarl_point_t*       p;
  sarl_unsigned_int   ob, concept;

  GtkWidget *widget = GTK_WIDGET(view);

  SARL_POWER_MAP_FOR_EACH(concept, cont, cont_map);
    if ( sarl_bit_set_count(cont) > 0 ) {
      p = sarl_diagram_get_concept_pos(view->p->diagram, concept);
      label = sarl_label_new(concept, kind, ox, oy);
      sarl_array_push(view_interp->labels, label);
      SARL_BIT_SET_FOR_EACH(ob, cont);
      sarl_array_push(label->layouts, 
        gtk_widget_create_pango_layout(widget, 
          sarl_string_table_get(cont_interp->names, ob)
      ));
      label->before = gtk_widget_create_pango_layout(widget, "... %d before");
      label->after = gtk_widget_create_pango_layout(widget, "... %d after");
      SARL_BIT_SET_END;
    }
  SARL_POWER_MAP_END;
};
Beispiel #4
0
static void
gnm_notebook_button_ensure_layout (GnmNotebookButton *nbb)
{
	const char *text = gtk_label_get_text (GTK_LABEL (nbb));

	if (nbb->layout) {
		if (strcmp (text, pango_layout_get_text (nbb->layout)) == 0)
			return;
		pango_layout_set_text (nbb->layout, text, -1);
		pango_layout_set_text (nbb->layout_active, text, -1);
	} else {
		PangoAttrList *attrs, *attrs_active;
		PangoAttribute *attr;
		PangoFontDescription *desc;
		GtkWidget *widget = GTK_WIDGET (nbb);
		GtkStyleContext *context =
			gtk_widget_get_style_context (widget);

		nbb->layout = gtk_widget_create_pango_layout (widget, text);
		nbb->layout_active = gtk_widget_create_pango_layout (widget, text);

		/* Common */
		attrs = pango_attr_list_new ();
		if (nbb->bg) {
			attr = go_color_to_pango
				(go_color_from_gdk_rgba (nbb->bg, NULL),
				 FALSE);
			attr->start_index = 0;
			attr->end_index = -1;
			pango_attr_list_insert (attrs, attr);
		}
		attrs_active = pango_attr_list_copy (attrs);

		/* Normal */
		gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL,
				       "font", &desc, NULL);
		attr = pango_attr_font_desc_new (desc);
		attr->start_index = 0;
		attr->end_index = -1;
		pango_attr_list_insert (attrs, attr);
		pango_font_description_free (desc);
		pango_layout_set_attributes (nbb->layout, attrs);
		pango_attr_list_unref (attrs);

		/* Active */
		gtk_style_context_get (context, GTK_STATE_FLAG_ACTIVE,
				       "font", &desc, NULL);
		attr = pango_attr_font_desc_new (desc);
		attr->start_index = 0;
		attr->end_index = -1;
		pango_attr_list_insert (attrs_active, attr);
		pango_font_description_free (desc);
		pango_layout_set_attributes (nbb->layout_active, attrs_active);
		pango_attr_list_unref (attrs_active);
	}

	pango_layout_get_extents (nbb->layout, NULL, &nbb->logical);
	pango_layout_get_extents (nbb->layout_active, NULL, &nbb->logical_active);
}
static void 
i7_cell_renderer_transcript_get_size(GtkCellRenderer *self, GtkWidget *widget, GdkRectangle *cell_area, int *x_offset, int *y_offset, int *width, int *height) 
{
	I7_CELL_RENDERER_TRANSCRIPT_USE_PRIVATE;

	PangoRectangle command_rect, transcript_rect, expected_rect;
	PangoLayout *layout;
	unsigned xpad, ypad, transcript_width, calc_width, calc_height;
	
	g_object_get(self, "xpad", &xpad, "ypad", &ypad, NULL);
	transcript_width = (priv->default_width / 2) - xpad;

	/* Get size of command */
	layout = gtk_widget_create_pango_layout(widget, priv->command);
	pango_layout_get_pixel_extents(layout, NULL, &command_rect);
	g_object_unref(layout);

	/* Get size of transcript text */
	layout = gtk_widget_create_pango_layout(widget, priv->transcript_text);
	pango_layout_set_width(layout, (int)(transcript_width - priv->text_padding * 2) * PANGO_SCALE);
	pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
	pango_layout_get_pixel_extents(layout, NULL, &transcript_rect);
	g_object_unref(layout);

	/* Get size of expected text */
	layout = gtk_widget_create_pango_layout(widget, priv->expected_text);
	pango_layout_set_width(layout, (int)(transcript_width - priv->text_padding * 2) * PANGO_SCALE);
	pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
	pango_layout_get_pixel_extents(layout, NULL, &expected_rect);
	g_object_unref (layout);

	/* Calculate the required width and height for the cell */
	calc_width = priv->default_width;
	calc_height = (unsigned)(command_rect.height + MAX(transcript_rect.height, expected_rect.height)) + ypad * 2 + priv->text_padding * 4;

	/* Set the passed-in parameters; if the available cell area is larger than
	 the required width and height, just use that instead */
	if(cell_area) {
		if(width)
			*width = MAX(cell_area->width, (int)calc_width);
		if(height)
			*height = MAX(cell_area->height, (int)calc_height);
	} else {
		if(width)
			*width = (int)calc_width;
		if(height)
			*height = (int)calc_height;
	}
	if(x_offset)
		*x_offset = 0;
	if(y_offset)
		*y_offset = 0;
}
Beispiel #6
0
/* {EV_GTK_DEPENDENT_APPLICATION_IMP}.pango_layout */
static EIF_POINTER F791_8093_body (EIF_REFERENCE Current)
{
	GTCX
	RTEX;
	EIF_POINTER tp1;
	EIF_POINTER tp2;
	EIF_POINTER tp3;
	RTLD;
	

	RTLI(1);
	RTLR(0,Current);
	
	RTEV;
	RTGC;
	RTOSP (8093);
#define Result RTOSR(8093)
	tp1 = RTOSCF(13642,F1049_13642,(Current));
	{
	/* INLINED CODE (default_pointer) */
	tp2 = (EIF_POINTER)  0;
	/* END INLINED CODE */
	}
	tp3 = tp2;
	Result = (EIF_POINTER) gtk_widget_create_pango_layout((GtkWidget*) tp1, (gchar*) tp3);
	RTOSE (8093);
	RTLE;
	RTEE;
	return Result;
#undef Result
}
GdkPixbuf *
pixbuf_render_text(GtkWidget *da, const char *str, int point_size, int r, int g, int b,
                   int *w, int *h)
{
    int width;
    int height;
    PangoLayout *layout = gtk_widget_create_pango_layout(da, NULL);
    PangoFontDescription *desc = pango_font_description_new();
    pango_font_description_set_size(desc, point_size * PANGO_SCALE);
    pango_layout_set_font_description(layout, desc);
    pango_font_description_free(desc);
    pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
    pango_layout_set_text(layout, str, -1);
    pango_layout_get_pixel_size(layout, &width, &height);

    GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
    pixbuf_set_rect_fill(pixbuf, 0, 0, width, height, 0, 0, 0, 0);
    pixbuf_draw_layout(pixbuf, layout, da, 0, 0, r, g, b, 255);
    //gdk_draw_layout(da->window, da->style->fg_gc[GTK_STATE_NORMAL], 0, 0, layout);
    g_object_unref(G_OBJECT(layout));

    *w = width;
    *h = height;
    return pixbuf;
}
Beispiel #8
0
void LeftMargin::setupMargin(GtkTextView *textView)
    {
    if(!mMarginLayout)
        {
        GtkWidget *widget = GTK_WIDGET(textView);

        mMarginLayout = gtk_widget_create_pango_layout(widget, "");
        updateTextInfo(textView);

        pango_layout_set_width(mMarginLayout, mTextWidth);
        pango_layout_set_alignment(mMarginLayout, PANGO_ALIGN_RIGHT);

        GtkStyleContext *widgetStyle = gtk_widget_get_style_context(widget);
        GdkRGBA color;
        gtk_style_context_get_color(widgetStyle, GTK_STATE_FLAG_NORMAL, &color);
        mMarginAttr = pango_attr_foreground_new(convertGdkColorToPango(color.red),
                convertGdkColorToPango(color.green), convertGdkColorToPango(color.blue));
        mMarginAttrList = pango_attr_list_new();

        mMarginAttr->start_index = 0;
        mMarginAttr->end_index = G_MAXUINT;
        pango_attr_list_insert(mMarginAttrList, mMarginAttr);
        pango_layout_set_attributes(mMarginLayout, mMarginAttrList);
        }
    }
Beispiel #9
0
/**
 * gimp_canvas_draw_text:
 * @canvas:  a #GimpCanvas widget
 * @style:   one of the enumerated #GimpCanvasStyle's.
 * @x:       X coordinate of the left of the layout.
 * @y:       Y coordinate of the top of the layout.
 * @format:  a standard printf() format string.
 * @Varargs: the parameters to insert into the format string.
 *
 * Draws a layout, in the specified style.
 **/
void
gimp_canvas_draw_text (GimpCanvas      *canvas,
                       GimpCanvasStyle  style,
                       gint             x,
                       gint             y,
                       const gchar     *format,
                       ...)
{
  va_list  args;
  gchar   *text;

  if (! gimp_canvas_ensure_style (canvas, style))
    return;

  if (! canvas->layout)
    canvas->layout = gtk_widget_create_pango_layout (GTK_WIDGET (canvas),
                                                     NULL);

  va_start (args, format);
  text = g_strdup_vprintf (format, args);
  va_end (args);

  pango_layout_set_text (canvas->layout, text, -1);
  g_free (text);

  gdk_draw_layout (GTK_WIDGET (canvas)->window, canvas->gc[style],
                   x, y, canvas->layout);
}
Beispiel #10
0
static PangoLayout *
get_pango_layout (GtkNumerableIcon *self)
{
  PangoContext *context;
  GdkScreen *screen;
  PangoLayout *layout;

  if (self->priv->style != NULL)
    {
      screen = gtk_style_context_get_screen (self->priv->style);
      context = gdk_pango_context_get_for_screen (screen);
      layout = pango_layout_new (context);

      if (self->priv->font != NULL)
        pango_layout_set_font_description (layout, self->priv->font);

      pango_layout_set_text (layout, self->priv->rendered_string, -1);

      g_object_unref (context);
    }
  else
    {
      GtkWidget *fake;

      /* steal gtk text settings from the window */
      fake = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      layout = gtk_widget_create_pango_layout (fake, self->priv->rendered_string);
      gtk_widget_destroy (fake);
    }

  return layout;
}
Beispiel #11
0
/*!
  \brief draw_valtext() draws the dynamic values for the traces on 
  the left hand side of the logviewer. This is optimized so that if the value
  becomes temporarily static, it won't keep blindly updating the screen and
  wasting CPU time.
  \param force_draw when true to write the values to screen for
  all controls no matter if hte previous value is the same or not.
  */
G_MODULE_EXPORT void draw_valtext(gboolean force_draw)
{
	gint last_index = 0;
	gfloat val = 0.0;
	gfloat last_val = 0.0;
	gint val_x = 0;
	gint val_y = 0;
	gint info_ctr = 0;
	gint h = 0;
	gint i = 0;
	GArray *array = NULL;
	Viewable_Value *v_value = NULL;
	PangoLayout *layout;
	GdkPixmap *pixmap = lv_data->pixmap;
	GtkAllocation allocation;

	gtk_widget_get_allocation(lv_data->darea,&allocation);

	h = allocation.height;

	if (!lv_data->font_desc)
	{
		lv_data->font_desc = pango_font_description_from_string("courier");
		pango_font_description_set_size(lv_data->font_desc,(10)*PANGO_SCALE);
	}
	
	val_x = 7;
	for (i=0;i<lv_data->active_traces;i++)
	{
		v_value = (Viewable_Value *)g_list_nth_data(lv_data->tlist,i);
		info_ctr = (lv_data->spread * (i+1))- (lv_data->spread/2);
		val_y = info_ctr + 1;

		last_index = v_value->last_index;
		array = DATA_GET(v_value->object,v_value->data_source);
		val = g_array_index(array,gfloat,last_index);
		if (array->len > 1)
			last_val = g_array_index(array,gfloat,last_index-1);
		/* IF this value matches the last one,  don't bother
		 * updating the text as there's no point... */
		if ((val == last_val) && (!force_draw) && (!v_value->force_update))
			continue;
		
		v_value->force_update = FALSE;
		gdk_draw_rectangle(pixmap,
				gtk_widget_get_style(lv_data->darea)->black_gc,
				TRUE,
				v_value->ink_rect->x+val_x,
				v_value->ink_rect->y+val_y,
				lv_data->info_width-1-v_value->ink_rect->x-val_x,
				v_value->ink_rect->height);

		layout = gtk_widget_create_pango_layout(lv_data->darea,g_strdup_printf("%1$.*2$f",val,v_value->precision));

		pango_layout_set_font_description(layout,lv_data->font_desc);
		pango_layout_get_pixel_extents(layout,v_value->ink_rect,v_value->log_rect);
		gdk_draw_layout(pixmap,v_value->font_gc,val_x,val_y,layout);
	}

}
Beispiel #12
0
static void
gtk_source_map_get_preferred_width (GtkWidget *widget,
                                    gint      *mininum_width,
                                    gint      *natural_width)
{
	GtkSourceMap *map = GTK_SOURCE_MAP (widget);
	GtkSourceMapPrivate *priv;
	PangoLayout *layout;
	gint height;
	gint width;

	priv = gtk_source_map_get_instance_private (map);

	if (priv->font_desc == NULL)
	{
		*mininum_width = *natural_width = DEFAULT_WIDTH;
		return;
	}

	/*
	 * FIXME:
	 *
	 * This seems like the type of thing we should calculate when
	 * rebuilding our CSS since it gets used a bunch and changes
	 * very little.
	 */
	layout = gtk_widget_create_pango_layout (GTK_WIDGET (priv->child_view), "X");
	pango_layout_get_pixel_size (layout, &width, &height);
	g_object_unref (layout);

	width *= gtk_source_view_get_right_margin_position (priv->view);

	*mininum_width = *natural_width = width;
}
Beispiel #13
0
static void  _togglebutton_size_request(GtkWidget *widget,GtkRequisition *requisition)
{
  g_return_if_fail(widget != NULL);
  g_return_if_fail(DTGTK_IS_TOGGLEBUTTON(widget));
  g_return_if_fail(requisition != NULL);

  /* create pango text settings if label exists */
  GtkStyle *style = gtk_widget_get_style(widget);
  PangoLayout *layout = NULL;
  int pw=0,ph=0;
  const gchar *text=gtk_button_get_label (GTK_BUTTON (widget));
  if (text)
  {
    layout = gtk_widget_create_pango_layout (widget,NULL);
    pango_layout_set_font_description (layout,style->font_desc);
    pango_layout_set_text (layout,text,-1);
    pango_layout_get_pixel_size (layout,&pw,&ph);

    requisition->width = pw+4;
    requisition->height = ph+4;
  }
  else
  {
    requisition->width = 22;
    requisition->height = 17;
  }
}
Beispiel #14
0
static void
dma_sparse_view_update_adjustement (DmaSparseView *view)
{
	PangoLayout *layout;
	GdkRectangle text_area;
	int height;

	gtk_text_view_get_visible_rect(GTK_TEXT_VIEW (view), &text_area);
	layout = gtk_widget_create_pango_layout (GTK_WIDGET(view), "0123456789ABCDEFGHIJKLMNOPQRSTUVWWYZ,");
	pango_layout_get_pixel_size(layout, NULL, &height);
	g_object_unref (G_OBJECT (layout));
	
	view->priv->line_by_page = text_area.height / height;
	view->priv->char_by_line = 8;	

	if (view->priv->vadjustment != NULL)
	{
		GtkAdjustment *vadj = view->priv->vadjustment;
		gdouble step_increment, page_size;

		step_increment = view->priv->char_by_line;
		page_size = (view->priv->line_by_page - 1) * step_increment;
		
		gtk_adjustment_set_step_increment (vadj, step_increment);
		gtk_adjustment_set_page_size (vadj, page_size);
		gtk_adjustment_set_page_increment (vadj, page_size * 0.9);
		gtk_adjustment_changed (vadj); 
	}
}
Beispiel #15
0
static void _tristatebutton_size_request(GtkWidget *widget, GtkRequisition *requisition)
{
  g_return_if_fail(widget != NULL);
  g_return_if_fail(DTGTK_IS_TRISTATEBUTTON(widget));
  g_return_if_fail(requisition != NULL);

  /* create pango text settings if label exists */
  PangoLayout *layout = NULL;
  int pw = 0, ph = 0;
  const gchar *text = gtk_button_get_label(GTK_BUTTON(widget));
  if(text)
  {
    layout = gtk_widget_create_pango_layout(widget, NULL);
    pango_layout_set_font_description(layout, darktable.bauhaus->pango_font_desc);
    pango_cairo_context_set_resolution(pango_layout_get_context(layout), darktable.gui->dpi);
    pango_layout_set_text(layout, text, -1);
    pango_layout_get_pixel_size(layout, &pw, &ph);
    g_object_unref(layout);

    requisition->width = pw + DT_PIXEL_APPLY_DPI(4);
    requisition->height = ph + DT_PIXEL_APPLY_DPI(4);
  }
  else
  {
    requisition->width = requisition->height = DT_PIXEL_APPLY_DPI(24);
  }
}
Beispiel #16
0
static gint
get_tree_view_height (void)
{
  static gint height = -1;

  if (height < 0)
    {
      GtkWidget *label = gtk_label_new (NULL);
      PangoLayout *layout =
	gtk_widget_create_pango_layout (label, 
					"The quick\n"
					"brown fox\n"
					"jumped\n"
					"over\n"
					"the lazy\n"
					"dog");

      pango_layout_get_pixel_size (layout, NULL, &height);

      g_object_unref (layout);
      g_object_ref_sink (label);
      g_object_unref (label);
    }

  return height;
}
static void
measure_text (GtkSourceGutterRendererText *renderer,
              const gchar                 *markup,
              const gchar                 *text,
              gint                        *width,
              gint                        *height)
{
	GtkTextView *view;
	PangoLayout *layout;

	view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (renderer));

	layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), NULL);

	if (markup != NULL)
	{
		pango_layout_set_markup (layout, markup, -1);
	}
	else
	{
		pango_layout_set_text (layout, text, -1);
	}

	pango_layout_get_pixel_size (layout, width, height);

	g_object_unref (layout);
}
Beispiel #18
0
static VALUE
rg_create_pango_layout(int argc, VALUE *argv, VALUE self)
{
    VALUE text;
    rb_scan_args(argc, argv, "01", &text);
    return GOBJ2RVALU(gtk_widget_create_pango_layout(_SELF(self), RVAL2CSTR_ACCEPT_NIL(text)));
}
static void
gutter_renderer_text_begin (GtkSourceGutterRenderer *renderer,
			    cairo_t                 *cr,
			    GdkRectangle            *background_area,
			    GdkRectangle            *cell_area,
			    GtkTextIter             *start,
			    GtkTextIter             *end)
{
	GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
	GtkTextView *view;

	view = gtk_source_gutter_renderer_get_view (renderer);

	g_clear_object (&text->priv->cached_layout);
	text->priv->cached_layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), NULL);

	if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin != NULL)
	{
		GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin (renderer,
													cr,
													background_area,
													cell_area,
													start,
													end);
	}
}
Beispiel #20
0
static int draw_building_and_count(GdkGC * gc, GtkWidget * area,
				   gint offset, Polygon * poly, gint num)
{
	GdkRectangle rect;
	char buff[10];
	gint width, height;
	PangoLayout *layout;

	poly_bound_rect(poly, 0, &rect);
	poly_offset(poly,
		    offset - rect.x,
		    area->allocation.height - 5 - rect.y - rect.height);
	poly_draw_old(area->window, gc, FALSE, poly);

	offset += 5 + rect.width;

	sprintf(buff, "%d", num);
	layout = gtk_widget_create_pango_layout(area, buff);
	pango_layout_get_pixel_size(layout, &width, &height);
	gdk_draw_layout(area->window, gc, offset,
			area->allocation.height - height - 5, layout);
	g_object_unref(layout);

	offset += 5 + width;

	return offset;
}
Beispiel #21
0
static gboolean fm_list_view_draw(GtkWidget* view_, cairo_t* cr, FMListView* view)
{
    g_return_val_if_fail(FM_IS_LIST_VIEW(view), FALSE);

    GOFDirectoryAsync *dir = fm_directory_view_get_current_directory (FM_DIRECTORY_VIEW (view));

    if (gof_directory_async_is_empty (dir))
    {
        PangoLayout* layout = gtk_widget_create_pango_layout(GTK_WIDGET(view), NULL);
        gchar *str = g_strconcat("<span size='x-large'>", _("This folder is empty."), "</span>", NULL);
        pango_layout_set_markup (layout, str, -1);

        PangoRectangle extents;
        /* Get hayout height and width */
        pango_layout_get_extents(layout, NULL, &extents);
        gdouble width = pango_units_to_double(extents.width);
        gdouble height = pango_units_to_double(extents.height);
        gtk_render_layout(gtk_widget_get_style_context(GTK_WIDGET(view)), cr,
                (double)gtk_widget_get_allocated_width(GTK_WIDGET(view))/2 - width/2,
                (double)gtk_widget_get_allocated_height(GTK_WIDGET(view))/2 - height/2,
                layout);
    }

    return FALSE;
}
Beispiel #22
0
gboolean gaugebar_expose (GtkWidget *widget, GdkEventExpose *event,
    gpointer data)
{
  GList* it;
  GdkGC *gc;
  GdkColor black = {0, 0, 0, 0};
  PangoLayout *layout;

  GtkDrawingArea *gaugebar = GTK_DRAWING_AREA (widget);
  g_return_val_if_fail (gaugebar != NULL, FALSE);
  
  GAUGELIST *gl = (GAUGELIST *) g_object_get_data (GTK_OBJECT (gaugebar),
      "gaugelist");

  g_return_val_if_fail (gl != NULL, FALSE);

  int width = widget->allocation.width;
  int height = widget->allocation.height;
  
  gc = gdk_gc_new (widget->window);

  // clear the widget
  GdkColor bgc = gtk_widget_get_style (
      GTK_WIDGET (gl->sess->tab))->bg[GTK_STATE_NORMAL];
  gdk_gc_set_rgb_bg_color (gc, &bgc);
  gdk_gc_set_rgb_fg_color (gc, &bgc);
  gdk_gc_set_fill (gc, GDK_SOLID);
  gdk_draw_rectangle (widget->window, gc, TRUE, 0, 0, width+1, height+1);

  // paint the new widget ...
  int X = 2;
  for (it = g_list_first (gl->list); it; it = g_list_next (it))
  {
    GAUGE *g = (GAUGE *) it->data;

    // paint the text
    int xd;
    layout = gtk_widget_create_pango_layout (GTK_WIDGET (gaugebar),
                                             g->variable);
    gdk_gc_set_rgb_fg_color (gc, &black);
    gdk_draw_layout (widget->window, gc, X, 2, layout);
    pango_layout_get_pixel_size (layout, &xd, NULL);
    X += xd + 2;
    
    // paint the gauge
    int val = g->cur * 100 / (g->max ? g->max : 100);
    if (val > 100) val = 100;
    gdk_gc_set_line_attributes (gc, 1, GDK_LINE_SOLID, GDK_CAP_NOT_LAST,
                                GDK_JOIN_MITER);
    gdk_gc_set_rgb_fg_color (gc, &black);
    gdk_draw_rectangle (widget->window, gc, FALSE, X, 2, 102, 20);
    if (val) {
      gdk_gc_set_rgb_fg_color (gc, &g->color);
      gdk_draw_rectangle (widget->window, gc, TRUE, X+1, 3, val+1, 19);
    }
    g_object_unref (layout);
    X += 110;
  }

}
Beispiel #23
0
static void
dma_data_view_address_size_request (DmaDataView *view,
									GtkRequisition *requisition)
{
	PangoLayout *layout;
	char text[] = "0";
	int width;
	int height;
	
	layout = gtk_widget_create_pango_layout(view->address, text);
	pango_layout_get_pixel_size(layout, &(requisition->width), &(requisition->height));
	do
	{
		text[0]++;
		pango_layout_get_pixel_size(layout, &width, &height);
		if (width > requisition->width) requisition->width = width;
		if (height > requisition->height) requisition->height = height;
	} while (text[0] == '9');
	for (text[0] = 'A'; text[0] != 'G'; text[0]++)
	{
		pango_layout_get_pixel_size(layout, &width, &height);
		if (width > requisition->width) requisition->width = width;
		if (height > requisition->height) requisition->height = height;
	}
	g_object_unref(G_OBJECT(layout));
	
	requisition->width *= sizeof(view->start) * 2;
}
Beispiel #24
0
/* FIXME */
static void
get_string_area_size (GimvZAlbum *album, const gchar *str,
                      gint *width_ret, gint *height_ret, gint *lines_ret)
{
   PangoLayout *layout;
   gint i, width, height, lines = 1;

   for (i = 0; str && str[i]; i++)
      if (str[i] == '\n') lines++;

   layout = gtk_widget_create_pango_layout (GTK_WIDGET (album), "(NULL)");
   pango_layout_set_text (layout, str, -1);
   pango_layout_get_pixel_size (layout, &width, &height);

   if (width_ret)
      *width_ret = width;
   if (height_ret)
      *height_ret = height;

   if (lines_ret) {
      *lines_ret = lines;
   }

   g_object_unref (layout);
}
Beispiel #25
0
static AboutRenderer *
make_text_item (AboutState *state, const char *text, int duration)
{
	AboutRenderer *r = g_new0 (AboutRenderer, 1);
	PangoAttrList *attrlist;
	PangoAttribute *attr;

	duration = (int)(duration / SPEED_FACTOR);

	r->start_time = state->now;
	r->duration = duration;
	r->layout = gtk_widget_create_pango_layout (state->anim_area, NULL);
	r->renderer = text_item_renderer;
	r->fade_in = r->fade_out = TRUE;
	set_text_motion (r, 0.5, 0.5, 0.5, 0.5);

	pango_layout_set_text (r->layout, text, -1);
	pango_layout_get_size (r->layout, &r->natural_width, NULL);

	attrlist = pango_attr_list_new ();
	attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
	pango_attr_list_change (attrlist, attr);
	pango_layout_set_attributes (r->layout, attrlist);
	pango_attr_list_unref (attrlist);

	state->now += duration;

	return r;
}
Beispiel #26
0
/* *****************************************************************************
 * Draw Text (lat/lon) into Grid
 */
void
draw_grid_text (GtkWidget * widget, gdouble posx, gdouble posy, gchar * txt)
{
	/* prints in pango */
	PangoFontDescription *pfd;
	PangoLayout *grid_label_layout;
	gint width, height;

	grid_label_layout = gtk_widget_create_pango_layout (map_drawingarea, txt);

	pfd = pango_font_description_from_string ("Sans 8");

	pango_layout_set_font_description (grid_label_layout, pfd);
	pango_layout_get_pixel_size (grid_label_layout, &width, &height);
	gdk_gc_set_function (kontext_map, GDK_XOR);
	gdk_gc_set_background (kontext_map, &colors.white);
	gdk_gc_set_foreground (kontext_map, &colors.mygray);
	
	gdk_draw_layout_with_colors (drawable, kontext_map, posx - width / 2,
				     posy - height / 2, grid_label_layout, &colors.black,
				     NULL);

	if (grid_label_layout != NULL)
		g_object_unref (G_OBJECT (grid_label_layout));
	/* freeing PangoFontDescription, cause it has been copied by prev. call */
	pango_font_description_free (pfd);

}
static void
create_layout (GtkSourceGutterRendererText *renderer,
               GtkWidget                   *widget)
{
	PangoLayout *layout;
	PangoAttribute *attr;
	GtkStyleContext *context;
	GdkRGBA color;
	PangoAttrList *attr_list;

	layout = gtk_widget_create_pango_layout (widget, NULL);

	context = gtk_widget_get_style_context (widget);
	gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color);

	attr = pango_attr_foreground_new (color.red * 65535,
	                                  color.green * 65535,
	                                  color.blue * 65535);

	attr->start_index = 0;
	attr->end_index = G_MAXINT;

	attr_list = pango_attr_list_new ();
	pango_attr_list_insert (attr_list, attr);

	renderer->priv->fg_attr = attr;
	renderer->priv->cached_layout = layout;
	renderer->priv->cached_attr_list = attr_list;
}
Beispiel #28
0
/* FIXME: It seems to overestimate the height a bit, it's visible on labels
 * with many curves.  It also seems to strangely underestimate the width
 * for curve descriptions under certain length. */
static void
gwy_graph_label_calculate_size(GwyGraphLabel *label)
{
    gint i, nc;
    PangoLayout *layout;
    PangoRectangle rect;
    GwyGraphCurveModel *curvemodel;
    GwyGraphModel *model;

    label->reqheight = 0;
    label->reqwidth = 0;

    model = GWY_GRAPH_MODEL(label->graph_model);
    nc = gwy_graph_model_get_n_curves(model);
    for (i = 0; i < nc; i++) {
        curvemodel = gwy_graph_model_get_curve(model, i);

        layout = gtk_widget_create_pango_layout(GTK_WIDGET(label), NULL);

        pango_layout_set_font_description(layout, label->font_desc);
        pango_layout_set_markup(layout, curvemodel->description->str,
                                curvemodel->description->len);
        pango_layout_get_pixel_extents(layout, NULL, &rect);

        if (label->reqwidth < rect.width)
            label->reqwidth = rect.width + 30 + model->label_frame_thickness;
        label->reqheight += rect.height + 5 + model->label_frame_thickness;

        g_object_unref(layout);
    }
    if (label->reqwidth == 0)
        label->reqwidth = 30;
    if (label->reqheight == 0)
        label->reqheight = 30;
}
Beispiel #29
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;
}
Beispiel #30
0
static void
overlay_draw (GtkDrawingArea *da,
              cairo_t        *cr,
              int             width,
              int             height,
              gpointer        data)
{
  GtkWidget *widget = GTK_WIDGET (da);
  PangoLayout *layout;
  const double dashes[] = { 6, 18 };
  GtkAllocation label_allocation;
  GtkRequisition minimum_size, natural_size;
  GtkWidget *label = data;
  gint x, y;

  cairo_translate (cr, -0.5, -0.5);
  cairo_set_line_width (cr, 1);

  cairo_set_source_rgb (cr, 1, 1, 1);
  cairo_rectangle (cr, 0, 0, width, height);
  cairo_fill (cr);

  gtk_widget_translate_coordinates (label, widget, 0, 0, &x, &y);
  layout = gtk_widget_create_pango_layout (widget, "");

  gtk_widget_get_preferred_size (label, &minimum_size, &natural_size); 

  pango_layout_set_markup (layout,
    "<span color='#c33'>\342\227\217 requisition</span>\n"
    "<span color='#3c3'>\342\227\217 natural size</span>\n"
    "<span color='#33c'>\342\227\217 allocation</span>", -1);

  pango_cairo_show_layout (cr, layout);
  g_object_unref (layout);

  gtk_widget_get_allocation (label, &label_allocation);

  cairo_rectangle (cr,
                   x + 0.5 * (label_allocation.width - minimum_size.width),
                   y + 0.5 * (label_allocation.height - minimum_size.height),
                   minimum_size.width, minimum_size.height);
  cairo_set_source_rgb (cr, 0.8, 0.2, 0.2);
  cairo_set_dash (cr, NULL, 0, 0);
  cairo_stroke (cr);

  cairo_rectangle (cr, x, y, label_allocation.width, label_allocation.height);
  cairo_set_source_rgb (cr, 0.2, 0.2, 0.8);
  cairo_set_dash (cr, dashes, 2, 0.5);
  cairo_stroke (cr);

  cairo_rectangle (cr,
                   x + 0.5 * (label_allocation.width - natural_size.width),
                   y + 0.5 * (label_allocation.height - natural_size.height),
                   natural_size.width, natural_size.height);
  cairo_set_source_rgb (cr, 0.2, 0.8, 0.2);
  cairo_set_dash (cr, dashes, 2, 12.5);
  cairo_stroke (cr);
}