コード例 #1
0
ファイル: playlist_list.c プロジェクト: sedwards/xmms3
void playlist_list_draw_string_wc(PlayList_List *pl, GdkFont *font, gint line, gint width, gchar *text)
{
	GdkWChar *wtext;
	int len, newlen;
	/*
	 * Convert the string to a wide character string to avoid
	 * destroying multibyte strings, when converting underscores,
	 * "%20" etc.
	 */
	/*
	 * Allocate some extra space, we might extend it by one
	 * character below
	 */
	wtext = g_malloc((strlen(text) + 3) * sizeof(GdkWChar));
	len = gdk_mbstowcs(wtext, text, strlen(text) + 1);
	if (len == -1)
	{
		/* Conversion failed */
		for (len = 0; text[len] != '\0'; len++)
			wtext[len] = text[len];
	}
	wtext[len] = L'\0';
	if (cfg.convert_underscore)
	{
		int i;
		for (i = 0; i < len; i++)
			if (wtext[i] == L'_')
				wtext[i] = L' ';
	}

	if (cfg.convert_twenty && len > 2)
	{
		GdkWChar *wtmp;
		while ((wtmp = find_in_wstr(wtext, "%20")) != NULL)
		{
			GdkWChar *wtmp2 = wtmp + 3;
			*(wtmp++) = L' ';
			while (*wtmp2)
				*(wtmp++) = *(wtmp2++);
			*wtmp = L'\0';
			len -= 2;
		}
	}
		
	newlen = len + 2;

	while (gdk_text_width_wc(font, wtext, len) > width && len > 4)
	{
		/*
		 * First check if the string gets short enough by
		 * extending it with one character and then convert
		 * three characters to dots.  If it's still too long,
		 * remove charaters, one by one.
		 */
		len = newlen--;
		wtext[len - 3] = L'.';
		wtext[len - 2] = L'.';
		wtext[len - 1] = L'.';
		wtext[len] = L'\0';
	}
	
	gdk_draw_text_wc(pl->pl_widget.parent, font, pl->pl_widget.gc,
			 pl->pl_widget.x,
			 pl->pl_widget.y + line * pl->pl_fheight + font->ascent,
			 wtext, len);
	g_free(wtext);
}
コード例 #2
0
ファイル: gtkplotgdk.c プロジェクト: deweerdt/TSP
/* subfunction of gtk_plot_gdk_draw_string(). */
static gint
drawstring(GtkPlotPC *pc,
	   GdkBitmap *dest,
	   GdkGC *gc,
	   GdkColor *black, GdkColor *white,
	   gint dx, gint dy,
	   GtkPSFont *psfont,
	   GdkFont *font,
	   GdkFont *latin_font,
	   GdkWChar wc)
{
  GdkBitmap *tmp;
  GdkFont *dfont;
  GdkImage *image;
  gint w, h, a, d, x, y, d2;
  guint32 pixel;

  if (psfont->i18n_latinfamily && psfont->vertical && (0 > wc || wc > 0x7f)) {
    /* vertical-writing CJK postscript fonts. */
    dfont = font;

    w = gdk_char_width_wc(dfont, wc);
    a = dfont->ascent;
    d = dfont->descent;
    h = a + d;
    d2 = w * d / h;

    tmp = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window, w, h, 1);

    gdk_gc_set_foreground(gc, white);
    gdk_draw_rectangle(tmp, gc, TRUE, 0, 0, -1, -1);
    gdk_gc_set_foreground(gc, black);

    gdk_draw_text_wc(tmp, dfont, gc, 0, a, &wc, 1);

    image = gdk_image_get(tmp, 0, 0, w, h);

    for (y = 0; y < h; y++) {
      for (x = 0; x < w; x++) {
	pixel = gdk_image_get_pixel(image, x, y);
	if (pixel == black->pixel)
	  gdk_draw_point(dest, gc, dx + y, dy + d2 - x);
      }
    }

    gdk_image_destroy(image);
    gdk_pixmap_unref(tmp);

    return h;
  } else {
    /* horizontal writing */
    if (psfont->i18n_latinfamily && 0 <= wc && wc <= 0x7f)
      dfont = latin_font;
    else
      dfont = font;

    gdk_draw_text_wc(dest, dfont, gc, dx, dy, &wc, 1);
    w = gdk_char_width_wc(dfont, wc);
    
    return w;
  }
}