[pango/pango2-windows] pangodwrite-fontmap.cpp: Add aliases as from Pango-1.x



commit db70b9ef7f8e2e3be7687f57570795c9139bc9e8
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Jun 29 12:04:34 2022 +0800

    pangodwrite-fontmap.cpp: Add aliases as from Pango-1.x
    
    This adds more font families for the PangoFontMap for the aliases that we are
    using, as per what we did in Pango-1.x.  Fallbacks, if used in Pango-2.x, would
    be added in a later commit.

 pango2/pangodwrite-fontmap.cpp | 113 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 102 insertions(+), 11 deletions(-)
---
diff --git a/pango2/pangodwrite-fontmap.cpp b/pango2/pangodwrite-fontmap.cpp
index 532c3a381..f6f86e583 100644
--- a/pango2/pangodwrite-fontmap.cpp
+++ b/pango2/pangodwrite-fontmap.cpp
@@ -270,6 +270,8 @@ util_create_pango2_hb_face (IDWriteFontFamily *family,
 /* }}} */
 /* {{{ Pango2FontMap implementation */
 
+#define MAX_ALIAS_LENTH 11
+#define MAX_FAMILY_LENTH 20
 static void
 pango2_direct_write_font_map_populate (Pango2FontMap *map)
 {
@@ -278,6 +280,23 @@ pango2_direct_write_font_map_populate (Pango2FontMap *map)
   UINT32 count;
   HRESULT hr;
 
+  /* list referred from Pango 1.x, from pangowin32-fontmap.c */
+  const char sans_families[][MAX_FAMILY_LENTH] =
+    {"dejavu", "sans", "arial", "tahoma",
+        "arial unicode ms", "lucida sans unicode",
+        "browallia new", "simhei"};
+  const char serif_families[][MAX_FAMILY_LENTH] =
+    {"dejavu serif", "times new roman", "georgia", "angsana new",  "simsun"};
+  const char mono_families[][MAX_FAMILY_LENTH] =
+    {"dejavu sans mono", "consolas", "courier new", "lucida console", "courier monothai"};
+  const char common_families[][MAX_FAMILY_LENTH] =
+    {"mingliu", "gulimche", "ms gothic", "sylfaen",
+        "kartika", "latha", "mangal", "raavi"};
+
+  const char sans_aliases [][MAX_ALIAS_LENTH] = {"Sans-serif", "Sans"};
+  const char mono_aliases [][MAX_ALIAS_LENTH] = {"Mono", "Monospace"};
+  const char common_aliases [][MAX_ALIAS_LENTH] = {"Sans-serif", "Sans", "Serif", "Monospace", "Mono"};
+
   hr = dwrite_map->dwrite_factory->GetSystemFontCollection (&collection, FALSE);
   if (FAILED (hr) || collection == NULL)
     g_error ("IDWriteFactory::GetSystemFontCollection failed with error code %x\n", (unsigned)hr);
@@ -333,24 +352,96 @@ pango2_direct_write_font_map_populate (Pango2FontMap *map)
   collection->Release ();
   collection = NULL;
 
-  /* Add generic aliases */
+  /* populate families for Sans and Sans-serif aliases */
+  for (gsize i = 0; i < G_N_ELEMENTS (sans_families); i++)
+    {
+      Pango2FontFamily *family = pango2_font_map_get_family (map, sans_families[i]);
+
+      if (family)
+        {
+          for (gsize j = 0; j < G_N_ELEMENTS (sans_aliases); j++)
+            {
+              Pango2GenericFamily *alias_family;
+
+              alias_family = pango2_generic_family_new (sans_aliases[j]);
+              pango2_generic_family_add_family (alias_family, family);
+              pango2_font_map_add_family (map, PANGO2_FONT_FAMILY (alias_family));
+            }
+        }
+    }
+
+  /* populate families for Serif aliases */
+  for (gsize i = 0; i < G_N_ELEMENTS (serif_families); i++)
+    {
+      Pango2FontFamily *family = pango2_font_map_get_family (map, serif_families[i]);
+
+      if (family)
+        {
+          Pango2GenericFamily *alias_family;
+
+          alias_family = pango2_generic_family_new ("Serif");
+          pango2_generic_family_add_family (alias_family, family);
+          pango2_font_map_add_family (map, PANGO2_FONT_FAMILY (alias_family));
+        }
+    }
+
+  /* populate families for Mono and Monospace aliases */
+  for (gsize i = 0; i < G_N_ELEMENTS (mono_families); i++)
+    {
+      Pango2FontFamily *family = pango2_font_map_get_family (map, mono_families[i]);
+
+      if (family)
+        {
+          for (gsize j = 0; j < G_N_ELEMENTS (mono_aliases); j++)
+            {
+              Pango2GenericFamily *alias_family;
+
+              alias_family = pango2_generic_family_new (mono_aliases[j]);
+              pango2_generic_family_add_family (alias_family, family);
+              pango2_font_map_add_family (map, PANGO2_FONT_FAMILY (alias_family));
+            }
+        }
+    }
+
+  /* populate common families for Sans, Sans-serif, Serif, Mono and Monospace aliases */
+  for (gsize i = 0; i < G_N_ELEMENTS (common_families); i++)
+    {
+      Pango2FontFamily *family = pango2_font_map_get_family (map, common_families[i]);
+
+      if (family)
+        {
+          for (gsize j = 0; j < G_N_ELEMENTS (common_aliases); j++)
+            {
+              Pango2GenericFamily *alias_family;
+
+              alias_family = pango2_generic_family_new (common_aliases[j]);
+              pango2_generic_family_add_family (alias_family, family);
+              pango2_font_map_add_family (map, PANGO2_FONT_FAMILY (alias_family));
+            }
+        }
+    }
+
+#if 0
+  if (IsWindows11OrLater ())
+    aliases[0].family_name = "Cascadia Mono";
+#endif
+
+  /* Add other generic aliases */
   struct {
     const char *alias_name;
     const char *family_name;
   } aliases[] = {
-    { "Monospace",  "Consolas" },
-    { "Sans-serif", "Arial" },
-    { "Sans", "Arial" },
-    { "Serif",      "Times New Roman" },
+    { "System-ui",  "Yu Gothic UI" },
     { "System-ui",  "Segoe UI" },
-    { "Emoji",      "Segoe UI Emoji" }
+    { "System-ui",  "Meiryo" },
+    { "Emoji",      "Segoe UI Emoji" },
+    { "Emoji",      "Segoe UI Symbol" },
+    { "Emoji",      "Segoe UI" },
+    { "Cursive",    "Comic Sans MS" },
+    { "Fantasy",    "Gabriola" },
+    { "Fantasy",    "Impact" },
   };
 
-#if 0
-  if (IsWindows11OrLater ())
-    aliases[0].family_name = "Cascadia Mono";
-#endif
-
   for (gsize i = 0; i < G_N_ELEMENTS (aliases); i++)
     {
       Pango2FontFamily *family = pango2_font_map_get_family (map, aliases[i].family_name);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]