void playlist_list_draw_string(PlayList_List *pl, GdkFont *font, gint line, gint width, gchar *text) { int len; char *tmp; if (cfg.convert_underscore) while ((tmp = strchr(text, '_')) != NULL) *tmp = ' '; if (cfg.convert_twenty) while ((tmp = strstr(text, "%20")) != NULL) { char *tmp2 = tmp + 3; *(tmp++) = ' '; while (*tmp2) *(tmp++) = *(tmp2++); *tmp = '\0'; } len = strlen(text); while (gdk_text_width(font, text, len) > width && len > 4) { len--; text[len - 3] = '.'; text[len - 2] = '.'; text[len - 1] = '.'; text[len] = '\0'; } gdk_draw_text(pl->pl_widget.parent, font, pl->pl_widget.gc, pl->pl_widget.x, pl->pl_widget.y + line * pl->pl_fheight + font->ascent, text, len); }
/* Determine the width of a given string. */ int clip_GDK_TEXTWIDTH(ClipMachine * cm) { C_object *cfont = _fetch_co_opt(cm); gchar * string = _clip_parc(cm,2); gint text_length = _clip_parni(cm,3); CHECKCOBJOPT(cfont,GDK_IS_FONT(cfont)); CHECKARG(2,CHARACTER_t); CHECKOPT(3,NUMERIC_t); if (_clip_parinfo(cm,3)==UNDEF_t) text_length = strlen(string); LOCALE_TO_UTF(string); _clip_retni(cm,gdk_text_width(GDK_FONT(cfont->object), string, text_length)); FREE_TEXT(string); return 0; err: return 1; }
void DrawColorText_Raw (GdkPixmap * pixmap, int fontsize, GdkGC * colorGC, gdouble x, gdouble y, char *text, int alignX, int alignY, int textLength) { if (!text) return; if (textLength == -1) textLength = strlen (text); GdkFont *font = GetFontForSize (fontsize); if (!font) return; int sizeX = gdk_text_width (font, text, textLength); int sizeY = gdk_text_height (font, text, textLength); switch (alignX) { case 0: break; case 1: x -= sizeX / 2; break; case 2: x -= sizeX; break; } switch (alignY) { case 0: break; case 1: y += sizeY / 2; break; case 2: y += sizeY; break; case 2 + 1: y += sizeY + 1; break; } gdk_draw_text (pixmap, font, colorGC, x, y, text, textLength); }
static void *font_gtk_get_glyph(unsigned char *str) { agsurface_t *dst; int h, w, l; BYTE *conv; GdkPixmap *pix_gdk; GdkGC *gc_gdk; GdkImage *img_gdk; GdkColor col_gdk; /* convert string code from sjis to euc (or LANG) */ conv = sjis2lang(str); l = strlen(conv); w = gdk_text_width(fontset, conv, l); if (w == 0) { free(conv); return NULL; } #ifdef GTKV12 h = gdk_text_height(fontset, conv, l); #else h = font_ascent + fontset->ascent; #endif if (w > GLYPH_PIXMAP_WIDTH) w = GLYPH_PIXMAP_WIDTH; if (h > GLYPH_PIXMAP_HEIGHT) h = GLYPH_PIXMAP_HEIGHT; pix_gdk = gdk_pixmap_new(mainwin->window, w, h, gdk_depth); gc_gdk = gdk_gc_new(pix_gdk); /* color */ col_gdk.pixel = 0; gdk_gc_set_foreground(gc_gdk, &col_gdk); // gdk_gc_set_background(gc_gdk, &col_gdk); gdk_draw_rectangle(pix_gdk, gc_gdk, TRUE, 0, 0, w, h); col_gdk.pixel = 1; gdk_gc_set_foreground(gc_gdk, &col_gdk); gdk_draw_text(pix_gdk, fontset, gc_gdk, 0, fontset->ascent, conv, l); gdk_gc_destroy(gc_gdk); img_gdk = gdk_image_get(&((GdkWindowPrivate *)pix_gdk)->window, 0, 0, w, h); gdk_pixmap_unref(pix_gdk); dst = g_new(agsurface_t, 1); dst->width = w; dst->height = h; dst->bytes_per_pixel = (img_gdk->bpp+1)/8; /* むーん */ dst->bytes_per_line = img_gdk->bpl; dst->pixel = img_gdk->mem; image_get_glyph(dst, &img_glyph); if (this->antialiase_on) { aa_make(img_glyph.pixel, w, dst->height, img_glyph.bytes_per_line); } img_glyph.width = w; img_glyph.height = h; g_free(dst); g_free(conv); gdk_image_destroy(img_gdk); return &img_glyph; }
void playlist_list_draw(Widget * w) { PlayList_List *pl = (PlayList_List *) w; GList *list; GdkGC *gc; GdkPixmap *obj; int width, height; char *text, *title; int i, tw, max_first; gc = pl->pl_widget.gc; width = pl->pl_widget.width; height = pl->pl_widget.height; obj = pl->pl_widget.parent; gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_NORMALBG)); gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, pl->pl_widget.y, width, height); if (playlist_list_font == NULL) { g_log(NULL, G_LOG_LEVEL_CRITICAL, "Couldn't open playlist font"); return; } PL_LOCK(); list = get_playlist(); pl->pl_fheight = playlist_list_font->ascent + playlist_list_font->descent + 1; pl->pl_num_visible = height / pl->pl_fheight; max_first = g_list_length(list) - pl->pl_num_visible; if (max_first < 0) max_first = 0; if (pl->pl_first >= max_first) pl->pl_first = max_first; if (pl->pl_first < 0) pl->pl_first = 0; for (i = 0; i < pl->pl_first; i++) list = g_list_next(list); for (i = pl->pl_first; list && i < pl->pl_first + pl->pl_num_visible; list = list->next, i++) { char qstr[20] = "", length[40] = ""; int pos; PlaylistEntry *entry = (PlaylistEntry *) list->data; if (entry->selected) { gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_SELECTEDBG)); gdk_draw_rectangle(obj, gc, TRUE, pl->pl_widget.x, pl->pl_widget.y + ((i - pl->pl_first) * pl->pl_fheight), width, pl->pl_fheight); } if (i == __get_playlist_position()) gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_CURRENT)); else gdk_gc_set_foreground(gc, get_skin_color(SKIN_PLEDIT_NORMAL)); if (entry->title) title = entry->title; else title = g_basename(entry->filename); pos = playlist_get_queue_position(entry); if (pos != -1) sprintf(qstr, "|%d|%s", pos + 1, entry->length != -1 ? " " : ""); if (entry->length != -1) sprintf(length, "%d:%-2.2d", entry->length / 60000, (entry->length / 1000) % 60); if (pos != -1 || entry->length != -1) { int x, y; char tail[60]; sprintf(tail, "%s%s", qstr, length); x = pl->pl_widget.x + width - gdk_text_width(playlist_list_font, tail, strlen(tail)) - 2; y = pl->pl_widget.y + (i - pl->pl_first) * pl->pl_fheight + playlist_list_font->ascent; gdk_draw_text(obj, playlist_list_font, gc, x, y, tail, strlen(tail)); tw = width - gdk_text_width(playlist_list_font, tail, strlen(tail)) - 5; } else tw = width; if (cfg.show_numbers_in_pl) text = g_strdup_printf("%d. %s", i + 1, title); else text = g_strdup_printf("%s", title); if (cfg.use_fontsets) playlist_list_draw_string_wc(pl, playlist_list_font, i - pl->pl_first, tw, text); else playlist_list_draw_string(pl, playlist_list_font, i - pl->pl_first, tw, text); g_free(text); } PL_UNLOCK(); }