changeset 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 703023e1a644
children 14a1e07e8f4e
files dwtest.c gtk3/dw.c
diffstat 2 files changed, 32 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/dwtest.c	Sat Jan 23 00:48:12 2021 +0000
+++ b/dwtest.c	Sun Jan 24 19:27:16 2021 +0000
@@ -1333,7 +1333,6 @@
 int mle_fontsize_cb(HWND hwnd, int size, void *data)
 {
     HWND hbox = (HWND)data;
-    HWND fontsize = (HWND)dw_window_get_data(hbox, "fontsize");
     HWND fontname = (HWND)dw_window_get_data(hbox, "fontname");
     char *font = dw_window_get_text(fontname);
 
@@ -1389,8 +1388,8 @@
         dw_window_set_style(text, DW_DT_VCENTER, DW_DT_VCENTER);
         dw_box_pack_start(hbox, text, -1, -1, FALSE, TRUE, 1);
         fontsize = dw_spinbutton_new("9", 0);
-        dw_spinbutton_set_limits(fontsize, 5, 100);
-        dw_box_pack_start(hbox, fontname, 50, -1, TRUE, FALSE, 1);
+        dw_box_pack_start(hbox, fontsize, 50, -1, TRUE, FALSE, 1);
+        dw_spinbutton_set_limits(fontsize, 100, 5);
         fontname = dw_combobox_new("Default", 0);
         dw_listbox_append(fontname, "Default");
         dw_listbox_append(fontname, "Helv");
--- a/gtk3/dw.c	Sat Jan 23 00:48:12 2021 +0000
+++ b/gtk3/dw.c	Sun Jan 24 19:27:16 2021 +0000
@@ -2687,22 +2687,31 @@
       free(oldfont);
 }
 
-/* Convert DW style font to pango style */
-void _convert_font(char *font)
-{
-   char *name = strchr(font, '.');
-
-   /* Detect Dynamic Windows style font name...
-    * Format: ##.Fontname
-    * and convert to a Pango name
-    */
-   if(name && isdigit(*font))
-   {
-       int size = atoi(font);
-       *name = 0;
-       name++;
-       sprintf(font, "%s %d", name, size);
-   }
+/* Convert DW style font to CSS syntax:
+ * font: font-style font-variant font-weight font-size/line-height font-family
+ */
+char *_convert_font(const char *font)
+{
+   char *newfont = NULL;
+   
+   if(font)
+   {
+      char *name = strchr(font, '.');
+      char *Italic = strstr(font, " Italic");
+      char *Bold = strstr(font, " Bold");
+      
+      /* Detect Dynamic Windows style font name...
+       * Format: ##.Fontname
+       * and convert to a Pango name
+       */
+      if(name && (name++) && isdigit(*font))
+      {
+          int size = atoi(font);
+          newfont = g_strdup_printf("%s normal %s %dpx %s", Italic ? "italic " : "normal",
+                                    Bold ? "bold " : "normal", size, name);
+      }
+   }
+   return newfont;
 }
 
 /* Internal functions to convert to GTK3 style CSS */
@@ -2771,7 +2780,7 @@
 int dw_window_set_font(HWND handle, const char *fontname)
 {
    GtkWidget *handle2 = handle;
-   char *font = strdup(fontname);
+   char *font = _convert_font(fontname);
    int _locked_by_me = FALSE;
    gpointer data;
 
@@ -2796,8 +2805,6 @@
          handle2 = tmp;
    }
 
-   _convert_font(font);
-
    /* Free old font name if one is allocated */
    data = g_object_get_data(G_OBJECT(handle2), "_dw_fontname");
    g_object_set_data(G_OBJECT(handle2), "_dw_fontname", (gpointer)font);
@@ -7987,11 +7994,12 @@
  */
 int API dw_pixmap_set_font(HPIXMAP pixmap, const char *fontname)
 {
-    if(pixmap && fontname && *fontname)
+    if(pixmap)
     {
          char *oldfont = pixmap->font;
-         pixmap->font = strdup(fontname);
-         _convert_font(pixmap->font);
+
+         pixmap->font = _convert_font(fontname);
+
          if(oldfont)
              free(oldfont);
          return DW_ERROR_NONE;