comparison gtk3/dw.c @ 2248:4fb54b9fcf78

GTK3: Switch to using CSS syntax for specifying fonts from Pango. Apparently the theme warnings produced on GTK3 were from using Pango syntax for specifying fonts, instead of CSS syntax. Can't find any information about when CSS syntax was introduced... So hopefully it works through the entire GTK3 series. Also fix some GCC warnings in the new dwtest code.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 24 Jan 2021 19:27:16 +0000
parents 8f9ffba67b7c
children 5f1677cc32e9
comparison
equal deleted inserted replaced
2247:703023e1a644 2248:4fb54b9fcf78
2685 2685
2686 if(oldfont) 2686 if(oldfont)
2687 free(oldfont); 2687 free(oldfont);
2688 } 2688 }
2689 2689
2690 /* Convert DW style font to pango style */ 2690 /* Convert DW style font to CSS syntax:
2691 void _convert_font(char *font) 2691 * font: font-style font-variant font-weight font-size/line-height font-family
2692 { 2692 */
2693 char *name = strchr(font, '.'); 2693 char *_convert_font(const char *font)
2694 2694 {
2695 /* Detect Dynamic Windows style font name... 2695 char *newfont = NULL;
2696 * Format: ##.Fontname 2696
2697 * and convert to a Pango name 2697 if(font)
2698 */ 2698 {
2699 if(name && isdigit(*font)) 2699 char *name = strchr(font, '.');
2700 { 2700 char *Italic = strstr(font, " Italic");
2701 int size = atoi(font); 2701 char *Bold = strstr(font, " Bold");
2702 *name = 0; 2702
2703 name++; 2703 /* Detect Dynamic Windows style font name...
2704 sprintf(font, "%s %d", name, size); 2704 * Format: ##.Fontname
2705 } 2705 * and convert to a Pango name
2706 */
2707 if(name && (name++) && isdigit(*font))
2708 {
2709 int size = atoi(font);
2710 newfont = g_strdup_printf("%s normal %s %dpx %s", Italic ? "italic " : "normal",
2711 Bold ? "bold " : "normal", size, name);
2712 }
2713 }
2714 return newfont;
2706 } 2715 }
2707 2716
2708 /* Internal functions to convert to GTK3 style CSS */ 2717 /* Internal functions to convert to GTK3 style CSS */
2709 static void _dw_override_color(GtkWidget *widget, const char *element, GdkRGBA *color) 2718 static void _dw_override_color(GtkWidget *widget, const char *element, GdkRGBA *color)
2710 { 2719 {
2769 * fontname: Name and size of the font in the form "size.fontname" 2778 * fontname: Name and size of the font in the form "size.fontname"
2770 */ 2779 */
2771 int dw_window_set_font(HWND handle, const char *fontname) 2780 int dw_window_set_font(HWND handle, const char *fontname)
2772 { 2781 {
2773 GtkWidget *handle2 = handle; 2782 GtkWidget *handle2 = handle;
2774 char *font = strdup(fontname); 2783 char *font = _convert_font(fontname);
2775 int _locked_by_me = FALSE; 2784 int _locked_by_me = FALSE;
2776 gpointer data; 2785 gpointer data;
2777 2786
2778 DW_MUTEX_LOCK; 2787 DW_MUTEX_LOCK;
2779 if(GTK_IS_SCROLLED_WINDOW(handle)) 2788 if(GTK_IS_SCROLLED_WINDOW(handle))
2793 { 2802 {
2794 GtkWidget *tmp = gtk_bin_get_child(GTK_BIN(handle)); 2803 GtkWidget *tmp = gtk_bin_get_child(GTK_BIN(handle));
2795 if(tmp) 2804 if(tmp)
2796 handle2 = tmp; 2805 handle2 = tmp;
2797 } 2806 }
2798
2799 _convert_font(font);
2800 2807
2801 /* Free old font name if one is allocated */ 2808 /* Free old font name if one is allocated */
2802 data = g_object_get_data(G_OBJECT(handle2), "_dw_fontname"); 2809 data = g_object_get_data(G_OBJECT(handle2), "_dw_fontname");
2803 g_object_set_data(G_OBJECT(handle2), "_dw_fontname", (gpointer)font); 2810 g_object_set_data(G_OBJECT(handle2), "_dw_fontname", (gpointer)font);
2804 if(data) 2811 if(data)
7985 * Returns: 7992 * Returns:
7986 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. 7993 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure.
7987 */ 7994 */
7988 int API dw_pixmap_set_font(HPIXMAP pixmap, const char *fontname) 7995 int API dw_pixmap_set_font(HPIXMAP pixmap, const char *fontname)
7989 { 7996 {
7990 if(pixmap && fontname && *fontname) 7997 if(pixmap)
7991 { 7998 {
7992 char *oldfont = pixmap->font; 7999 char *oldfont = pixmap->font;
7993 pixmap->font = strdup(fontname); 8000
7994 _convert_font(pixmap->font); 8001 pixmap->font = _convert_font(fontname);
8002
7995 if(oldfont) 8003 if(oldfont)
7996 free(oldfont); 8004 free(oldfont);
7997 return DW_ERROR_NONE; 8005 return DW_ERROR_NONE;
7998 } 8006 }
7999 return DW_ERROR_GENERAL; 8007 return DW_ERROR_GENERAL;