summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2022-07-01 12:31:27 +0800
committerMatthias Clasen <mclasen@redhat.com>2022-07-04 11:24:16 -0400
commitc5bd2b4ceffb6550c5a16edc8ead122b7c46aada (patch)
tree303a0e07e584a25df882bcda3232bd0ae47823db
parent7b729c23ee7ddbe432b7df0a6916207a381a9874 (diff)
downloadpango-c5bd2b4ceffb6550c5a16edc8ead122b7c46aada.tar.gz
Windows: Split out code for aliases (and fallbacks)
We want to make this code shared between the DirectWrite code and the legacy GDI code, since we want to add aliases (and eventually, fallbacks) for all cases, at least on Windows (well, font family names do not differ between DirectWrite and GDI on a given Windows system :))
-rw-r--r--pango2/meson.build1
-rw-r--r--pango2/pangodwrite-fontmap.cpp35
-rw-r--r--pango2/pangowin32-utils-private.h29
-rw-r--r--pango2/pangowin32-utils.c59
4 files changed, 91 insertions, 33 deletions
diff --git a/pango2/meson.build b/pango2/meson.build
index 0a3e8d32..e0f0626d 100644
--- a/pango2/meson.build
+++ b/pango2/meson.build
@@ -170,6 +170,7 @@ if host_system == 'windows'
pango_sources += [
'pangodwrite-fontmap.cpp',
+ 'pangowin32-utils.c',
]
if cairo_dep.found()
diff --git a/pango2/pangodwrite-fontmap.cpp b/pango2/pangodwrite-fontmap.cpp
index 532c3a38..7f4ead15 100644
--- a/pango2/pangodwrite-fontmap.cpp
+++ b/pango2/pangodwrite-fontmap.cpp
@@ -29,13 +29,12 @@
#include <hb-directwrite.h>
#include "pangodwrite-fontmap.h"
-#include "pango-hbfamily-private.h"
#include "pango-fontmap-private.h"
#include "pango-hbface-private.h"
#include "pango-hbfont-private.h"
#include "pango-context.h"
-#include "pango-impl-utils.h"
#include "pango-trace-private.h"
+#include "pangowin32-utils-private.h"
/**
@@ -333,37 +332,7 @@ pango2_direct_write_font_map_populate (Pango2FontMap *map)
collection->Release ();
collection = NULL;
- /* Add 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", "Segoe UI" },
- { "Emoji", "Segoe UI Emoji" }
- };
-
-#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);
-
- if (family)
- {
- Pango2GenericFamily *alias_family;
-
- alias_family = pango2_generic_family_new (aliases[i].alias_name);
- pango2_generic_family_add_family (alias_family, family);
- pango2_font_map_add_family (map, PANGO2_FONT_FAMILY (alias_family));
- }
- }
+ pango2_win32_font_map_add_aliases_and_fallbacks (map);
}
/* }}} */
diff --git a/pango2/pangowin32-utils-private.h b/pango2/pangowin32-utils-private.h
new file mode 100644
index 00000000..9acebec9
--- /dev/null
+++ b/pango2/pangowin32-utils-private.h
@@ -0,0 +1,29 @@
+/* Pango
+ * pangowin32-utils-private.h: Miscellaneous Windows-related utils
+ *
+ * Copyright (C) 2022 the GTK team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "pango-fontmap-private.h"
+
+G_BEGIN_DECLS
+
+void
+pango2_win32_font_map_add_aliases_and_fallbacks (Pango2FontMap *map);
+
+G_END_DECLS
diff --git a/pango2/pangowin32-utils.c b/pango2/pangowin32-utils.c
new file mode 100644
index 00000000..b44bf476
--- /dev/null
+++ b/pango2/pangowin32-utils.c
@@ -0,0 +1,59 @@
+/* Pango
+ * pangowin32-utils.c: Miscellaneous Windows-related utils
+ *
+ * Copyright (C) 2022 the GTK team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "pango-impl-utils.h"
+#include "pangowin32-utils-private.h"
+
+void
+pango2_win32_font_map_add_aliases_and_fallbacks (Pango2FontMap *map)
+{
+ /* Add 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", "Segoe UI" },
+ { "Emoji", "Segoe UI Emoji" }
+ };
+
+#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);
+
+ if (family)
+ {
+ Pango2GenericFamily *alias_family;
+
+ alias_family = pango2_generic_family_new (aliases[i].alias_name);
+ pango2_generic_family_add_family (alias_family, family);
+ pango2_font_map_add_family (map, PANGO2_FONT_FAMILY (alias_family));
+ }
+ }
+}