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




commit a6cbe3b60a44bb5678f22049df94b86c59de2bbd
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, sans the families that we share for
    different Unicode needs, which would be used in fallback fontmaps.
    
    Fallbacks would be added in a later commit, when it is clearer for how to
    create a PangoFontMap for that purpose.

 pango2/pangodwrite-fontmap.cpp | 104 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 98 insertions(+), 6 deletions(-)
---
diff --git a/pango2/pangodwrite-fontmap.cpp b/pango2/pangodwrite-fontmap.cpp
index 532c3a381..235740a41 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,25 @@ 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" };
+  const char serif_families[][MAX_FAMILY_LENTH] =
+    {"dejavu serif", "times new roman", "georgia", "angsana new"};
+  const char mono_families[][MAX_FAMILY_LENTH] =
+    {"dejavu sans mono", "consolas", "courier new", "lucida console", "courier monothai"};
+
+  /* TODO: Add when how to populate fallback fontmap is clearer */
+  const char fallback_families[][MAX_FAMILY_LENTH] =
+    {"simsun", "simhei", "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"};
+
   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,17 +354,88 @@ 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));
+            }
+        }
+    }
+
+  /* TODO: populate fallback fontmap */
+#if 0
+  for (gsize i = 0; i < G_N_ELEMENTS (fallback_families); i++)
+    {
+      Pango2FontFamily *family = pango2_font_map_get_family (map->fallback, fallback_families[i]);
+
+      if (family)
+        {
+          Pango2GenericFamily *alias_family;
+
+          alias_family = pango2_generic_family_new (fallback_families[i]);
+          pango2_generic_family_add_family (alias_family, family);
+          pango2_font_map_add_family (map->fallback, PANGO2_FONT_FAMILY (alias_family));
+        }
+    }
+#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


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