comparison gtk/dw.c @ 1240:3bc6244279c0

Attempt at converting DW style font names on GTK for dw_pixmap_set_font().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 19 Oct 2011 02:41:55 +0000
parents db21c0081387
children 3a2ffe3a7eae
comparison
equal deleted inserted replaced
1239:7ec60b650e5b 1240:3bc6244279c0
2846 */ 2846 */
2847 void API dw_font_set_default(char *fontname) 2847 void API dw_font_set_default(char *fontname)
2848 { 2848 {
2849 } 2849 }
2850 2850
2851 /* Convert DW style font to pango style */
2852 void _convert_font(char *font)
2853 {
2854 char *name = strchr(font, '.');
2855
2856 /* Detect Dynamic Windows style font name...
2857 * Format: ##.Fontname
2858 * and convert to a Pango name
2859 */
2860 if(name && isdigit(*font))
2861 {
2862 int size = atoi(font);
2863 *name = 0;
2864 name++;
2865 sprintf(font, "%s %d", name, size);
2866 }
2867 }
2868
2851 /* 2869 /*
2852 * Sets the font used by a specified window (widget) handle. 2870 * Sets the font used by a specified window (widget) handle.
2853 * Parameters: 2871 * Parameters:
2854 * handle: The window (widget) handle. 2872 * handle: The window (widget) handle.
2855 * fontname: Name and size of the font in the form "size.fontname" 2873 * fontname: Name and size of the font in the form "size.fontname"
2861 #else 2879 #else
2862 GdkFont *gdkfont; 2880 GdkFont *gdkfont;
2863 #endif 2881 #endif
2864 GtkWidget *handle2 = handle; 2882 GtkWidget *handle2 = handle;
2865 char *font = strdup(fontname); 2883 char *font = strdup(fontname);
2866 char *name = strchr(font, '.');
2867 int _locked_by_me = FALSE; 2884 int _locked_by_me = FALSE;
2868 gpointer data; 2885 gpointer data;
2869 2886
2870 DW_MUTEX_LOCK; 2887 DW_MUTEX_LOCK;
2871 if(GTK_IS_SCROLLED_WINDOW(handle)) 2888 if(GTK_IS_SCROLLED_WINDOW(handle))
2890 gdkfont = gdk_font_load(fontname); 2907 gdkfont = gdk_font_load(fontname);
2891 if(!gdkfont) 2908 if(!gdkfont)
2892 gdkfont = gdk_font_load("fixed"); 2909 gdkfont = gdk_font_load("fixed");
2893 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_gdkfont", (gpointer)gdkfont); 2910 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_gdkfont", (gpointer)gdkfont);
2894 #else 2911 #else
2895 2912 _convert_font(font);
2896 /* Detect Dynamic Windows style font name...
2897 * Format: ##.Fontname
2898 * and convert to a Pango name
2899 */
2900 if(name && isdigit(*font))
2901 {
2902 int size = atoi(font);
2903 *name = 0;
2904 name++;
2905 sprintf(font, "%s %d", name, size);
2906 }
2907 #endif 2913 #endif
2908 2914
2909 /* Free old font name if one is allocated */ 2915 /* Free old font name if one is allocated */
2910 data = gtk_object_get_data(GTK_OBJECT(handle2), "_dw_fontname"); 2916 data = gtk_object_get_data(GTK_OBJECT(handle2), "_dw_fontname");
2917 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_fontname", (gpointer)font);
2911 if(data) 2918 if(data)
2912 free(data); 2919 free(data);
2913 2920
2914 gtk_object_set_data(GTK_OBJECT(handle2), "_dw_fontname", (gpointer)font);
2915 #if GTK_MAJOR_VERSION > 1 2921 #if GTK_MAJOR_VERSION > 1
2916 pfont = pango_font_description_from_string(fontname); 2922 pfont = pango_font_description_from_string(fontname);
2917 2923
2918 if(pfont) 2924 if(pfont)
2919 { 2925 {
8552 { 8558 {
8553 if(pixmap && fontname && *fontname) 8559 if(pixmap && fontname && *fontname)
8554 { 8560 {
8555 char *oldfont = pixmap->font; 8561 char *oldfont = pixmap->font;
8556 pixmap->font = strdup(fontname); 8562 pixmap->font = strdup(fontname);
8563 _convert_font(pixmap->font);
8557 if(oldfont) 8564 if(oldfont)
8558 free(oldfont); 8565 free(oldfont);
8559 return DW_ERROR_NONE; 8566 return DW_ERROR_NONE;
8560 } 8567 }
8561 return DW_ERROR_GENERAL; 8568 return DW_ERROR_GENERAL;