static void
match_label_color (GstyleColorWidget *self,
                   GstyleColor       *color)
{
  PangoLayout *layout;
  PangoAttrList *attr_list;
  PangoAttribute *attr;
  GdkRGBA rgba;
  GdkRGBA dst_rgba;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (GSTYLE_IS_COLOR (color));

  layout = gtk_label_get_layout (self->label);
  attr_list = pango_layout_get_attributes (layout);
  if (attr_list == NULL)
    {
      attr_list = pango_attr_list_new ();
      gtk_label_set_attributes (self->label, attr_list);
      pango_attr_list_unref (attr_list);
    }

  gstyle_color_fill_rgba (color, &rgba);
  gstyle_utils_get_contrasted_rgba (rgba, &dst_rgba);
  attr = pango_attr_foreground_new (dst_rgba.red * 0xffff, dst_rgba.green * 0xffff, dst_rgba.blue * 0xffff);
  pango_attr_list_change (attr_list, attr);
  attr = pango_attr_background_new (rgba.red * 0xffff, rgba.green * 0xffff, rgba.blue * 0xffff);
  pango_attr_list_change (attr_list, attr);
}
示例#2
0
void iupgtkFontUpdatePangoLayout(Ihandle* ih, PangoLayout* layout)
{
  IgtkFont* gtkfont;
  PangoAttrList *attrs;

  if (!layout)
    return;

  gtkfont = gtkFontGet(ih);
  if (!gtkfont)
    return;

  attrs = pango_layout_get_attributes(layout);
  if (!attrs) 
  {
    attrs = pango_attr_list_new();
    pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->strikethrough));
    pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->underline));
    pango_layout_set_attributes(layout, attrs);
  }
  else
  {
    pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->strikethrough));
    pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->underline));
  }
}
示例#3
0
static gboolean vi_list_item_enter_notify_event(GtkWidget *widget,
	GdkEventCrossing *event, struct vi_list_item_t *item)
{
	GdkColor color;

	PangoAttrList *attrs;
	PangoAttribute *underline_attr;

	GdkWindow *window;
	GdkCursor *cursor;

	GtkStyle *style;

	style = gtk_widget_get_style(item->label);
	item->label_color = style->fg[GTK_STATE_NORMAL];

	gdk_color_parse("red", &color);
	gtk_widget_modify_fg(item->label, GTK_STATE_NORMAL, &color);

	attrs = gtk_label_get_attributes(GTK_LABEL(item->label));
	underline_attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
	pango_attr_list_change(attrs, underline_attr);

	cursor = gdk_cursor_new(GDK_HAND1);
	window = gtk_widget_get_parent_window(widget);
	gdk_window_set_cursor(window, cursor);
	g_object_unref(cursor);

	return FALSE;
}
示例#4
0
文件: x11cood.c 项目: htrb/ngraph-gtk
void
CoordWinSetFont(const char *font)
{
#if GTK_CHECK_VERSION(3, 16, 0)
  if (NgraphApp.CoordWin.data.text && font) {
    set_widget_font(NgraphApp.CoordWin.data.text, font);
  }
#else  /* GTK_CHECK_VERSION(3, 16, 0) */
  const char *ptr;
  PangoAttrList *pattr;
  PangoFontDescription *desc;
  GtkLabel *label;

  label = GTK_LABEL(NgraphApp.CoordWin.data.text);

  if (label == NULL)
    return;

  pattr = gtk_label_get_attributes(label);
  if (pattr == NULL) {
    pattr = pango_attr_list_new();
    gtk_label_set_attributes(GTK_LABEL(label), pattr);
  }

  ptr = (font) ? font : "Monospace";

  desc = pango_font_description_from_string(ptr);
  pango_attr_list_change(pattr, pango_attr_font_desc_new(desc));
  pango_font_description_free(desc);
#endif
}
示例#5
0
文件: im-nimf.c 项目: janghe11/nimf
static void
nimf_gtk_im_context_get_preedit_string (GtkIMContext   *context,
                                        gchar         **str,
                                        PangoAttrList **attrs,
                                        gint           *cursor_pos)
{
  g_debug (G_STRLOC ": %s", G_STRFUNC);

  PangoAttribute *attr;

  nimf_im_get_preedit_string (NIMF_GTK_IM_CONTEXT (context)->im,
                              str, cursor_pos);

  if (attrs)
  {
    *attrs = pango_attr_list_new ();

    attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);

    if (str)
    {
      attr->start_index = 0;
      attr->end_index   = strlen (*str);
    }

    pango_attr_list_change (*attrs, attr);
  }
}
示例#6
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;
}
示例#7
0
JNIEXPORT void JNICALL
Java_org_gnome_pango_PangoAttrList_pango_1attr_1list_1change
(
	JNIEnv* env,
	jclass cls,
	jlong _self,
	jlong _attr
)
{
	PangoAttrList* self;
	PangoAttribute* attr;

	// convert parameter self
	self = (PangoAttrList*) _self;

	// convert parameter attr
	attr = (PangoAttribute*) _attr;

	// call function
	pango_attr_list_change(self, attr);

	// cleanup parameter self

	// cleanup parameter attr
}
示例#8
0
static gboolean
append_txorun (PangoAttribute *src, TXORun *run)
{
	PangoAttribute *dst = pango_attribute_copy (src);
	dst->start_index = run->first;	/* inclusive */
	dst->end_index = run->last;	/* exclusive */
	pango_attr_list_change (run->accum, dst);
	return FALSE;
}
示例#9
0
static void gtkFontUpdate(IgtkFont* gtkfont)
{
  PangoAttrList *attrs;

  pango_layout_set_font_description(gtkfont->layout, gtkfont->fontdesc);

  attrs = pango_layout_get_attributes(gtkfont->layout);
  if (!attrs) 
  {
    attrs = pango_attr_list_new();
    pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->strikethrough));
    pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->underline));
    pango_layout_set_attributes(gtkfont->layout, attrs);
  }
  else
  {
    pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->strikethrough));
    pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->underline));
  }
}
示例#10
0
void iupgtkFontUpdateObjectPangoLayout(Ihandle* ih, gpointer object)
{
  PangoAttrList *attrs;

  IgtkFont* gtkfont = gtkFontGet(ih);
  if (!gtkfont)
    return;

  g_object_get(object, "attributes", &attrs, NULL);
  if (!attrs) 
  {
    attrs = pango_attr_list_new();
    pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->strikethrough));
    pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->underline));
    g_object_set(object, "attributes", attrs, NULL);
  }
  else
  {
    pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->strikethrough));
    pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->underline));
  }
}
示例#11
0
static void
set_fade (AboutRenderer *r, AboutState *state, double f)
{
	GtkStyleContext *ctxt = gtk_widget_get_style_context (state->anim_area);
	PangoAttrList *attrlist = pango_layout_get_attributes (r->layout);
	GdkRGBA col, bg, fg;
	PangoAttribute *attr;

	gtk_style_context_get_color (ctxt, GTK_STATE_FLAG_NORMAL, &fg);
	gtk_style_context_get_background_color (ctxt, GTK_STATE_FLAG_NORMAL, &bg);
	col = blend_colors (&bg, &fg, f);
	attr = pango_attr_foreground_new
		(col.red * 65535., col.green * 65535., col.blue * 65535.);
	pango_attr_list_change (attrlist, attr);
	pango_layout_set_attributes (r->layout, attrlist);
}
示例#12
0
/* Find the markup to be used for new characters.  */
static void
set_cur_fmt (WBCGtk *wbcg, int target_pos_in_bytes)
{
	PangoAttrList *new_list = pango_attr_list_new ();
	GSList *ptr, *attrs = attrs_at_byte (wbcg->edit_line.markup, target_pos_in_bytes);

	for (ptr = attrs; ptr != NULL ; ptr = ptr->next) {
		PangoAttribute *attr = ptr->data;
		attr->start_index = 0;
		attr->end_index = INT_MAX;
		pango_attr_list_change (new_list, attr);
	}
	g_slist_free (attrs);
	if (wbcg->edit_line.cur_fmt)
		pango_attr_list_unref (wbcg->edit_line.cur_fmt);
	wbcg->edit_line.cur_fmt = new_list;
}
示例#13
0
static void
set_or_unset (PangoAttrList *dst, const PangoAttribute *attr,
	      PangoAttrList *ref)
{
	struct cb_set_or_unset data;

	data.attr = attr;
	data.set_in_ref = FALSE;
	(void)pango_attr_list_filter (ref, cb_set_or_unset, &data);

	if (data.set_in_ref)
		go_pango_attr_list_unset (dst,
					  attr->start_index, attr->end_index,
					  attr->klass->type);
	else
		pango_attr_list_change (dst, pango_attribute_copy (attr));
}
示例#14
0
static gboolean vi_list_item_leave_notify_event(GtkWidget *widget,
	GdkEventCrossing *event, struct vi_list_item_t *item)
{
	PangoAttrList *attrs;
	PangoAttribute *underline_attr;

	GdkWindow *window;

	window = gtk_widget_get_parent_window(widget);
	gdk_window_set_cursor(window, NULL);

	attrs = gtk_label_get_attributes(GTK_LABEL(item->label));
	underline_attr = pango_attr_underline_new(PANGO_UNDERLINE_NONE);
	pango_attr_list_change(attrs, underline_attr);
	gtk_widget_modify_fg(item->label, GTK_STATE_NORMAL, &item->label_color);

	return FALSE;
}
void QPushButton::setFont(const QFont &font)
{
    //g_warning("QPushButton::setFont: size:%d, family:%s, text: %s", font.pixelSize(), font.family().latin1(),text().latin1());
    QButton::setFont(font);

#if 0
    GtkWidget *button = getGtkWidget();

    if (button) {
        PangoFontDescription *fd;
        GtkWidget *child,*newchild;
        PangoAttrList* al;
        PangoAttribute* afd;

        child = gtk_bin_get_child(GTK_BIN(button));
        newchild = gtk_label_new(text().utf8());
        fd = createPangoFontDescription(&font);
        gtk_widget_modify_font(button, fd);
        gtk_widget_modify_font(child, fd);
        gtk_container_remove(GTK_CONTAINER(button),child);
        gtk_container_add(GTK_CONTAINER(button),newchild);
        child = newchild;



        afd  = pango_attr_font_desc_new(fd);

        al = gtk_label_get_attributes( GTK_LABEL(child) );
        if (al == NULL)
        {
            al = pango_attr_list_new();
            pango_attr_list_insert(al,afd);
        } else
        {
            pango_attr_list_change(al,afd);
        }

        gtk_label_set_attributes( GTK_LABEL(child), al );
        gtk_widget_show( child );
        //g_warning("child:%x fd,%x",child,fd);
        pango_font_description_free(fd);
    }
#endif
}
/**
 * terminal_tab_label_set_bold:
 * @tab_label: a #TerminalTabLabel
 * @bold: whether to enable label bolding
 *
 * Sets the tab label text bold, or unbolds it.
 */
void
terminal_tab_label_set_bold (TerminalTabLabel *tab_label,
                             gboolean bold)
{
  TerminalTabLabelPrivate *priv = tab_label->priv;
  PangoAttrList *attr_list;
  PangoAttribute *weight_attr;
  gboolean free_list = FALSE;

  bold = bold != FALSE;
  if (priv->bold == bold)
    return;

  priv->bold = bold;

  attr_list = gtk_label_get_attributes (GTK_LABEL (priv->label));
  if (!attr_list) {
    attr_list = pango_attr_list_new ();
    free_list = TRUE;
  }

  if (bold)
    weight_attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
  else
    weight_attr = pango_attr_weight_new (PANGO_WEIGHT_NORMAL);

  /* gtk_label_get_attributes() returns the label's internal list,
   * which we're probably not supposed to modify directly. 
   * It seems to work ok however.
   */
  pango_attr_list_change (attr_list, weight_attr);

  gtk_label_set_attributes (GTK_LABEL (priv->label), attr_list);

  if (free_list)
    pango_attr_list_unref (attr_list);
}
示例#17
0
/**
 * anaconda_apply_language:
 * @label: (transfer none): The widget to which to apply the language
 * @language: The language to apply to the widget
 *
 * Apply a Pango language attribute to a label.
 *
 * For some formatting decisions, in particular the font choice, the language
 * of the text being rendered needs to be known. This is especially the case
 * for the Chinese, Japanese and Korean translations, since Unicode uses a
 * single codepoint for the CJK characters across languages, even when the
 * particular language may render the character very differently. For example,
 * U+76F4 (直) shows up a good bit in the translations, it is rendered differently
 * in Chinese and Japanese, and it is considered unreadable between the two.
 *
 * This function applies a #PangoAttrLanguage attribute to the label so that
 * the underlying renderer can do the right thing.
 *
 * Since: 3.4
 */
void anaconda_apply_language(GtkLabel *label, const gchar *language) {
    PangoLanguage *pango_language;
    PangoAttribute *attr;
    PangoAttrList *attrlist;
    gboolean attrlist_unref = FALSE;

    pango_language = pango_language_from_string(language);
    attr = pango_attr_language_new(pango_language);

    /* If the label already has an attribute list, modify it, otherwise create a new one. */
    attrlist = gtk_label_get_attributes(label);
    if (!attrlist) {
        attrlist = pango_attr_list_new();
        attrlist_unref = TRUE;
    }

    pango_attr_list_change(attrlist, attr);
    gtk_label_set_attributes(label, attrlist);

    /* Drop the local attrlist reference if there is one */
    if (attrlist_unref) {
        pango_attr_list_unref(attrlist);
    }
}
示例#18
0
static void
text_handler           (GMarkupParseContext *context,
			const gchar         *text,
			gsize                text_len,
			gpointer             user_data,
			GError             **error)
{
  MarkupData *md = user_data;

  if (md->accel_marker == 0)
    {
      /* Just append all the text */

      md->index += text_len;

      g_string_append_len (md->text, text, text_len);
    }
  else
    {
      /* Parse the accelerator */
      const gchar *p;
      const gchar *end;
      const gchar *range_start;
      const gchar *range_end;
      gssize uline_index = -1;
      gsize uline_len = 0;	/* Quiet GCC */

      range_end = NULL;
      range_start = text;
      p = text;
      end = text + text_len;

      while (p != end)
	{
	  gunichar c;

	  c = g_utf8_get_char (p);

	  if (range_end)
	    {
	      if (c == md->accel_marker)
		{
		  /* escaped accel marker; move range_end
		   * past the accel marker that came before,
		   * append the whole thing
		   */
		  range_end = g_utf8_next_char (range_end);
		  g_string_append_len (md->text,
				       range_start,
				       range_end - range_start);
		  md->index += range_end - range_start;

		  /* set next range_start, skipping accel marker */
		  range_start = g_utf8_next_char (p);
		}
	      else
		{
		  /* Don't append the accel marker (leave range_end
		   * alone); set the accel char to c; record location for
		   * underline attribute
		   */
		  if (md->accel_char == 0)
		    md->accel_char = c;

		  g_string_append_len (md->text,
				       range_start,
				       range_end - range_start);
		  md->index += range_end - range_start;

		  /* The underline should go underneath the char
		   * we're setting as the next range_start
		   */
		  uline_index = md->index;
		  uline_len = g_utf8_next_char (p) - p;

		  /* set next range_start to include this char */
		  range_start = p;
		}

	      /* reset range_end */
	      range_end = NULL;
	    }
	  else if (c == md->accel_marker)
	    {
	      range_end = p;
	    }

	  p = g_utf8_next_char (p);
	}

      if (range_end)
	{
	  g_string_append_len (md->text,
			       range_start,
			       range_end - range_start);
	  md->index += range_end - range_start;
	}
      else
	{
	  g_string_append_len (md->text,
			       range_start,
			       end - range_start);
	  md->index += end - range_start;
	}

      if (md->attr_list != NULL && uline_index >= 0)
	{
	  /* Add the underline indicating the accelerator */
	  PangoAttribute *attr;

	  attr = pango_attr_underline_new (PANGO_UNDERLINE_LOW);

	  attr->start_index = uline_index;
	  attr->end_index = uline_index + uline_len;

	  pango_attr_list_change (md->attr_list, attr);
	}
    }
}
示例#19
0
static gboolean
text_item_renderer (AboutRenderer *r, AboutState *state)
{
	PangoLayout *layout = r->layout;
	int age = state->now - r->start_time;
	double rage = CLAMP (age / (double)r->duration, 0.0, 1.0);
	GtkWidget *widget = state->anim_area;
	GtkStyleContext *ctxt;
	const int fade = 500;
	int x, y, width, height;
	cairo_t *cr;
	GtkAllocation wa;
	GdkRGBA color;
	double alpha = 1;

	if (age >= r->duration)
		return FALSE;

	if (r->fade_in && age < fade)
		alpha = age / (double)fade;
	else if (r->fade_out && r->duration - age < fade)
		alpha = (r->duration - age) / (double)fade;

	ctxt = gtk_widget_get_style_context (widget);

	gtk_widget_get_allocation (widget, &wa);
	x = (int)(PANGO_SCALE * wa.width *
		  (r->start.x + rage * (r->end.x - r->start.x)));
	y = (int)(PANGO_SCALE * wa.height *
		  (r->start.y + rage * (r->end.y - r->start.y)));

	if (r->expansion.count) {
		PangoAttrList *attrlist = pango_layout_get_attributes (layout);
		const char *p, *text = pango_layout_get_text (layout);
		PangoRectangle ink, logical;

		memset (&ink, 0, sizeof (ink));
		logical = ink;

		logical.width = (int)(rage * r->expansion.rate * r->natural_width / r->expansion.count);

		p = text;
		while (*p) {
			const char *next = g_utf8_next_char (p);
			gunichar uc = g_utf8_get_char (p);
			PangoAttribute *attr;

			if (uc == UNICODE_ZERO_WIDTH_SPACE_C) {
				attr = pango_attr_shape_new (&ink, &logical);
				attr->start_index = p - text;
				attr->end_index = next - text;
				pango_attr_list_change (attrlist, attr);
			}
			p = next;
		}
		pango_layout_set_attributes (layout, attrlist);
	}

	pango_layout_get_size (layout, &width, &height);
	x -= width / 2;
	y -= height / 2;

	cr = r->cr;
	gnm_style_context_get_color (ctxt, GTK_STATE_FLAG_NORMAL, &color);
	color.alpha = alpha;
	gdk_cairo_set_source_rgba (cr, &color);
	cairo_move_to (cr, x / (double)PANGO_SCALE, y / (double)PANGO_SCALE);
	pango_cairo_show_layout (cr, layout);

	return TRUE;
}
示例#20
0
static void
decorate_text (GimpAboutDialog *dialog,
               gint             anim_type,
               gdouble          time)
{
  GtkStyle       *style = gtk_widget_get_style (dialog->anim_area);
  const gchar    *text;
  const gchar    *ptr;
  gint            letter_count = 0;
  gint            text_length  = 0;
  gint            text_bytelen = 0;
  gint            cluster_start, cluster_end;
  gunichar        unichr;
  PangoAttrList  *attrlist = NULL;
  PangoAttribute *attr;
  PangoRectangle  irect = {0, 0, 0, 0};
  PangoRectangle  lrect = {0, 0, 0, 0};
  GdkColor        mix;

  mix_colors (style->bg + GTK_STATE_NORMAL,
              style->fg + GTK_STATE_NORMAL, &mix, time);

  text = pango_layout_get_text (dialog->layout);
  g_return_if_fail (text != NULL);

  text_length = g_utf8_strlen (text, -1);
  text_bytelen = strlen (text);

  attrlist = pango_attr_list_new ();

  dialog->textrange[0] = 0;
  dialog->textrange[1] = text_bytelen;

  switch (anim_type)
    {
    case 0: /* Fade in */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_insert (attrlist, attr);
      break;

    case 1: /* Fade in, spread */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_change (attrlist, attr);

      ptr = text;

      cluster_start = 0;
      while ((unichr = g_utf8_get_char (ptr)))
        {
          ptr = g_utf8_next_char (ptr);
          cluster_end = (ptr - text);

          if (unichr == 0x200b)
            {
              lrect.width = (1.0 - time) * 15.0 * PANGO_SCALE + 0.5;
              attr = pango_attr_shape_new (&irect, &lrect);
              attr->start_index = cluster_start;
              attr->end_index = cluster_end;
              pango_attr_list_change (attrlist, attr);
            }
          cluster_start = cluster_end;
        }
      break;

    case 2: /* Fade in, sinewave */
      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
      attr->start_index = 0;
      attr->end_index = text_bytelen;
      pango_attr_list_change (attrlist, attr);

      ptr = text;

      cluster_start = 0;

      while ((unichr = g_utf8_get_char (ptr)))
        {
          if (unichr == 0x200b)
            {
              cluster_end = ptr - text;
              attr = pango_attr_rise_new ((1.0 -time) * 18000 *
                                          sin (4.0 * time +
                                               (float) letter_count * 0.7));
              attr->start_index = cluster_start;
              attr->end_index = cluster_end;
              pango_attr_list_change (attrlist, attr);

              letter_count++;
              cluster_start = cluster_end;
            }

          ptr = g_utf8_next_char (ptr);
        }
      break;

    case 3: /* letterwise Fade in */
      ptr = text;

      letter_count  = 0;
      cluster_start = 0;

      while ((unichr = g_utf8_get_char (ptr)))
        {
          gint    border = (text_length + 15) * time - 15;
          gdouble pos;

          if (letter_count < border)
            pos = 0;
          else if (letter_count > border + 15)
            pos = 1;
          else
            pos = ((gdouble) (letter_count - border)) / 15;

          mix_colors (style->fg + GTK_STATE_NORMAL,
                      style->bg + GTK_STATE_NORMAL,
                      &mix, pos);

          ptr = g_utf8_next_char (ptr);

          cluster_end = ptr - text;

          attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
          attr->start_index = cluster_start;
          attr->end_index = cluster_end;
          pango_attr_list_change (attrlist, attr);

          if (pos < 1.0)
            dialog->textrange[1] = cluster_end;

          letter_count++;
          cluster_start = cluster_end;
        }

      break;

    default:
      g_printerr ("Unknown animation type %d\n", anim_type);
    }

  pango_layout_set_attributes (dialog->layout, attrlist);
  pango_attr_list_unref (attrlist);
}