[pango/simple-fontmap: 13/23] Add PangoFcLanguageSet
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/simple-fontmap: 13/23] Add PangoFcLanguageSet
- Date: Fri, 31 Dec 2021 20:31:23 +0000 (UTC)
commit f380b6a42401dcbf63ac3020fbdfd2bce13fa983
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Dec 25 22:34:23 2021 -0500
Add PangoFcLanguageSet
This is an implementation of PangoLanguageSet
that is wrapping FcLangSet.
pango/meson.build | 1 +
pango/pangofc-language-set-private.h | 30 +++++++++
pango/pangofc-language-set.c | 115 +++++++++++++++++++++++++++++++++++
3 files changed, 146 insertions(+)
---
diff --git a/pango/meson.build b/pango/meson.build
index 8251bada..79bc313f 100644
--- a/pango/meson.build
+++ b/pango/meson.build
@@ -212,6 +212,7 @@ if build_pangoft2
pangofc_public_sources = [
'pangofc-font.c',
'pangofc-fontmap.c',
+ 'pangofc-language-set.c',
'pangofc-decoder.c',
'pango-trace.c',
]
diff --git a/pango/pangofc-language-set-private.h b/pango/pangofc-language-set-private.h
new file mode 100644
index 00000000..7a957d82
--- /dev/null
+++ b/pango/pangofc-language-set-private.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "pango-language-set-private.h"
+#include <fontconfig/fontconfig.h>
+
+G_BEGIN_DECLS
+
+#define PANGO_TYPE_FC_LANGUAGE_SET (pango_fc_language_set_get_type ())
+
+G_DECLARE_FINAL_TYPE (PangoFcLanguageSet, pango_fc_language_set, PANGO, FC_LANGUAGE_SET, PangoLanguageSet)
+
+struct _PangoFcLanguageSet
+{
+ PangoLanguageSet parent_instance;
+
+ FcLangSet *langs;
+};
+
+struct _PangoFcLanguageSetClass
+{
+ PangoLanguageSetClass parent_class;
+};
+
+PangoFcLanguageSet * pango_fc_language_set_new (FcLangSet *langs);
+
+guint pango_fc_language_set_hash (const PangoFcLanguageSet *self);
+gboolean pango_fc_language_set_equal (const PangoFcLanguageSet *a,
+ const PangoFcLanguageSet *b);
+
+G_END_DECLS
diff --git a/pango/pangofc-language-set.c b/pango/pangofc-language-set.c
new file mode 100644
index 00000000..59df3990
--- /dev/null
+++ b/pango/pangofc-language-set.c
@@ -0,0 +1,115 @@
+/* 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 "pangofc-language-set-private.h"
+
+
+G_DEFINE_TYPE (PangoFcLanguageSet, pango_fc_language_set, PANGO_TYPE_LANGUAGE_SET)
+
+static void
+pango_fc_language_set_init (PangoFcLanguageSet *self)
+{
+}
+
+static void
+pango_fc_language_set_finalize (GObject *object)
+{
+ PangoFcLanguageSet *self = PANGO_FC_LANGUAGE_SET (object);
+
+ FcLangSetDestroy (self->langs);
+
+ G_OBJECT_CLASS (pango_fc_language_set_parent_class)->finalize (object);
+}
+
+static gboolean
+pango_fc_language_set_matches_language (PangoLanguageSet *set,
+ PangoLanguage *language)
+{
+ PangoFcLanguageSet *self = PANGO_FC_LANGUAGE_SET (set);
+
+ return FcLangSetHasLang (self->langs, (FcChar8 *) pango_language_to_string (language)) !=
FcLangDifferentLang;
+}
+
+static PangoLanguage **
+pango_fc_language_set_get_languages (PangoLanguageSet *set)
+{
+ PangoFcLanguageSet *self = PANGO_FC_LANGUAGE_SET (set);
+ FcStrSet *strset;
+ FcStrList *list;
+ FcChar8 *s;
+ GPtrArray *langs;
+
+ langs = g_ptr_array_new ();
+
+ strset = FcLangSetGetLangs (self->langs);
+ list = FcStrListCreate (strset);
+
+ FcStrListFirst (list);
+ while ((s = FcStrListNext (list)))
+ g_ptr_array_add (langs, pango_language_from_string ((const char *)s));
+
+ FcStrListDone (list);
+ FcStrSetDestroy (strset);
+
+ g_ptr_array_add (langs, NULL);
+
+ return (PangoLanguage **) g_ptr_array_free (langs, FALSE);
+}
+
+static void
+pango_fc_language_set_class_init (PangoFcLanguageSetClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PangoLanguageSetClass *language_set_class = PANGO_LANGUAGE_SET_CLASS (class);
+
+ object_class->finalize = pango_fc_language_set_finalize;
+
+ language_set_class->matches_language = pango_fc_language_set_matches_language;
+ language_set_class->get_languages = pango_fc_language_set_get_languages;
+}
+
+PangoFcLanguageSet *
+pango_fc_language_set_new (FcLangSet *langs)
+{
+ PangoFcLanguageSet *self;
+
+ self = g_object_new (PANGO_TYPE_FC_LANGUAGE_SET, NULL);
+
+ self->langs = FcLangSetCopy (langs);
+
+ return self;
+}
+
+guint
+pango_fc_language_set_hash (const PangoFcLanguageSet *self)
+{
+ return (guint) FcLangSetHash (self->langs);
+}
+
+gboolean
+pango_fc_language_set_equal (const PangoFcLanguageSet *a,
+ const PangoFcLanguageSet *b)
+{
+ return FcLangSetEqual (a->langs, b->langs);
+}
+
+/* vim:set foldmethod=marker expandtab: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]