[pango/simple-fontmap: 5/22] Add PangoLanguageSet
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/simple-fontmap: 5/22] Add PangoLanguageSet
- Date: Wed, 29 Dec 2021 20:14:59 +0000 (UTC)
commit 5a85a10c966338f54c8152d4bd90c9d8e03bd2c7
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Dec 25 17:43:31 2021 -0500
Add PangoLanguageSet
PangoLanguageSet is an internal type used to
represent languages that are supported by a
font, similar to FcLangSet.
pango/meson.build | 2 +
pango/pango-language-set-private.h | 29 +++++++
pango/pango-language-set-simple-private.h | 19 +++++
pango/pango-language-set-simple.c | 126 ++++++++++++++++++++++++++++++
pango/pango-language-set.c | 87 +++++++++++++++++++++
5 files changed, 263 insertions(+)
---
diff --git a/pango/meson.build b/pango/meson.build
index 8e1e6976..c8713582 100644
--- a/pango/meson.build
+++ b/pango/meson.build
@@ -19,6 +19,8 @@ pango_sources = [
'pango-gravity.c',
'pango-item.c',
'pango-language.c',
+ 'pango-language-set.c',
+ 'pango-language-set-simple.c',
'pango-layout.c',
'pango-markup.c',
'pango-matrix.c',
diff --git a/pango/pango-language-set-private.h b/pango/pango-language-set-private.h
new file mode 100644
index 00000000..a72982b3
--- /dev/null
+++ b/pango/pango-language-set-private.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "pango-language.h"
+
+G_BEGIN_DECLS
+
+#define PANGO_TYPE_LANGUAGE_SET (pango_language_set_get_type ())
+
+PANGO_AVAILABLE_IN_1_52
+G_DECLARE_DERIVABLE_TYPE (PangoLanguageSet, pango_language_set, PANGO, LANGUAGE_SET, GObject)
+
+struct _PangoLanguageSetClass
+{
+ GObjectClass parent_class;
+
+ gboolean (* matches_language) (PangoLanguageSet *set,
+ PangoLanguage *language);
+
+ PangoLanguage ** (* get_languages) (PangoLanguageSet *set);
+};
+
+gboolean pango_language_set_matches_language (PangoLanguageSet *set,
+ PangoLanguage *language);
+
+PangoLanguage ** pango_language_set_get_languages (PangoLanguageSet *set);
+
+char * pango_language_set_to_string (PangoLanguageSet *set);
+
+G_END_DECLS
diff --git a/pango/pango-language-set-simple-private.h b/pango/pango-language-set-simple-private.h
new file mode 100644
index 00000000..167ccd8b
--- /dev/null
+++ b/pango/pango-language-set-simple-private.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "pango-language-set-private.h"
+
+G_BEGIN_DECLS
+
+#define PANGO_TYPE_LANGUAGE_SET_SIMPLE (pango_language_set_simple_get_type ())
+
+PANGO_AVAILABLE_IN_1_52
+G_DECLARE_FINAL_TYPE (PangoLanguageSetSimple, pango_language_set_simple, PANGO, LANGUAGE_SET_SIMPLE,
PangoLanguageSet)
+
+PANGO_AVAILABLE_IN_1_52
+PangoLanguageSetSimple *pango_language_set_simple_new (void);
+
+PANGO_AVAILABLE_IN_1_52
+void pango_language_set_simple_add_language (PangoLanguageSetSimple *self,
+ PangoLanguage *language);
+
+G_END_DECLS
diff --git a/pango/pango-language-set-simple.c b/pango/pango-language-set-simple.c
new file mode 100644
index 00000000..233905c7
--- /dev/null
+++ b/pango/pango-language-set-simple.c
@@ -0,0 +1,126 @@
+/* Pango
+ *
+ * Copyright (C) 2021 Red Hat, Inc.
+ *
+ * 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 "config.h"
+
+#include <gio/gio.h>
+
+#include "pango-language-set-simple-private.h"
+
+struct _PangoLanguageSetSimple
+{
+ PangoLanguageSet parent_instance;
+
+ GHashTable *languages;
+ PangoLanguage **list;
+};
+
+G_DEFINE_TYPE (PangoLanguageSetSimple, pango_language_set_simple, PANGO_TYPE_LANGUAGE_SET)
+
+static void
+pango_language_set_simple_init (PangoLanguageSetSimple *self)
+{
+ self->languages = g_hash_table_new (g_direct_hash, g_direct_equal);
+}
+
+static void
+pango_language_set_simple_finalize (GObject *object)
+{
+ PangoLanguageSetSimple *self = PANGO_LANGUAGE_SET_SIMPLE (object);
+
+ g_hash_table_unref (self->languages);
+ g_free (self->list);
+
+ G_OBJECT_CLASS (pango_language_set_simple_parent_class)->finalize (object);
+}
+
+static gboolean
+pango_language_set_simple_matches_language (PangoLanguageSet *set,
+ PangoLanguage *language)
+{
+ PangoLanguageSetSimple *self = PANGO_LANGUAGE_SET_SIMPLE (set);
+ const char *s;
+
+ if (g_hash_table_contains (self->languages, language))
+ return TRUE;
+
+ if (language == pango_language_from_string ("c") ||
+ language == pango_language_from_string ("xx"))
+ return TRUE;
+
+ s = pango_language_to_string (language);
+ if (strchr (s, '-'))
+ {
+ char buf[10];
+
+ for (int i = 0; i < 10; i++)
+ {
+ buf[i] = s[i];
+ if (buf[i] == '-')
+ {
+ buf[i] = '\0';
+ break;
+ }
+ }
+ buf[9] = '\0';
+
+ if (g_hash_table_contains (self->languages, pango_language_from_string (buf)))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static PangoLanguage **
+pango_language_set_simple_get_languages (PangoLanguageSet *set)
+{
+ PangoLanguageSetSimple *self = PANGO_LANGUAGE_SET_SIMPLE (set);
+
+ if (!self->list)
+ self->list = (PangoLanguage **) g_hash_table_get_keys_as_array (self->languages, NULL);
+
+ return self->list;
+}
+
+static void
+pango_language_set_simple_class_init (PangoLanguageSetSimpleClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PangoLanguageSetClass *language_set_class = PANGO_LANGUAGE_SET_CLASS (class);
+
+ object_class->finalize = pango_language_set_simple_finalize;
+ language_set_class->matches_language = pango_language_set_simple_matches_language;
+ language_set_class->get_languages = pango_language_set_simple_get_languages;
+}
+
+PangoLanguageSetSimple *
+pango_language_set_simple_new (void)
+{
+ return g_object_new (PANGO_TYPE_LANGUAGE_SET_SIMPLE, NULL);
+}
+
+void
+pango_language_set_simple_add_language (PangoLanguageSetSimple *self,
+ PangoLanguage *language)
+{
+ g_return_if_fail (self->list == NULL);
+
+ g_hash_table_add (self->languages, language);
+}
diff --git a/pango/pango-language-set.c b/pango/pango-language-set.c
new file mode 100644
index 00000000..b0dc87a8
--- /dev/null
+++ b/pango/pango-language-set.c
@@ -0,0 +1,87 @@
+/* Pango
+ *
+ * Copyright (C) 2021 Red Hat, Inc.
+ *
+ * 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 "config.h"
+
+#include <gio/gio.h>
+
+#include "pango-language-set-private.h"
+
+
+G_DEFINE_ABSTRACT_TYPE (PangoLanguageSet, pango_language_set, G_TYPE_OBJECT)
+
+static void
+pango_language_set_init (PangoLanguageSet *set)
+{
+}
+
+static gboolean
+pango_language_set_default_matches_language (PangoLanguageSet *set,
+ PangoLanguage *language)
+{
+ return FALSE;
+}
+
+static PangoLanguage **
+pango_language_set_default_get_languages (PangoLanguageSet *set)
+{
+ return NULL;
+}
+
+static void
+pango_language_set_class_init (PangoLanguageSetClass *class)
+{
+ PangoLanguageSetClass *language_set_class = PANGO_LANGUAGE_SET_CLASS (class);
+
+ language_set_class->matches_language = pango_language_set_default_matches_language;
+ language_set_class->get_languages = pango_language_set_default_get_languages;
+}
+
+gboolean
+pango_language_set_matches_language (PangoLanguageSet *set,
+ PangoLanguage *language)
+{
+ return PANGO_LANGUAGE_SET_GET_CLASS (set)->matches_language (set, language);
+}
+
+PangoLanguage **
+pango_language_set_get_languages (PangoLanguageSet *set)
+{
+ return PANGO_LANGUAGE_SET_GET_CLASS (set)->get_languages (set);
+}
+
+char *
+pango_language_set_to_string (PangoLanguageSet *set)
+{
+ PangoLanguage **languages;
+ GString *s;
+
+ s = g_string_new ("");
+
+ languages = pango_language_set_get_languages (set);
+ for (int i = 0; languages[i]; i++)
+ {
+ if (s->len > 0)
+ g_string_append (s, "|");
+ g_string_append (s, pango_language_to_string (languages[i]));
+ }
+
+ return g_string_free (s, FALSE);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]