Debian Codegraph @

lib/json/font-manager-orthography.c

raw
1 /* font-manager-orthography.c
2 *
3 * Copyright (C) 2009-2023 Jerry Casiano
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.
17 *
18 * If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
19 */
20
21 #include "font-manager-orthography.h"
22
23 /**
24 * SECTION: font-manager-orthography
25 * @short_description: Font language support
26 * @title: Orthography
27 * @include: font-manager-orthography.h
28 *
29 * A #FontManagerOrthography holds information about the extent to which a
30 * font supports a particular language.
31 *
32 * In addition to the english name, it includes the untranslated name of the
33 * orthography along with a pangram or sample string for the language, if available.
34 *
35 * |[
36 * {
37 * "name" : string,
38 * "native" : string,
39 * "sample" : string,
40 * "coverage" : double,
41 * "filter" : [ ]
42 * }
43 * ]|
44 *
45 * filter is a #JsonArray of available codepoints
46 */
47
48 struct _FontManagerOrthography
49 {
50 FontManagerJsonProxy parent;
51 };
52
53 G_DEFINE_TYPE(FontManagerOrthography, font_manager_orthography, FONT_MANAGER_TYPE_JSON_PROXY)
54
55 static void
56 font_manager_orthography_class_init (FontManagerOrthographyClass *klass)
57 {
58 GObjectClass *object_class = G_OBJECT_CLASS(klass);
59 GObjectClass *parent_class = G_OBJECT_CLASS(font_manager_orthography_parent_class);
60 FontManagerJsonProxyClass *proxy_class = FONT_MANAGER_JSON_PROXY_CLASS(klass);
61 object_class->get_property = parent_class->get_property;
62 object_class->set_property = parent_class->set_property;
63 proxy_class->properties = OrthographyProperties;
64 proxy_class->n_properties = G_N_ELEMENTS(OrthographyProperties);
65 font_manager_json_proxy_install_properties(proxy_class);
66 return;
67 }
68
69 static void
70 font_manager_orthography_init (G_GNUC_UNUSED FontManagerOrthography *self)
71 {
72 g_return_if_fail(self != NULL);
73 }
74
75 /**
76 * font_manager_orthography_get_filter:
77 * @self: (nullable): #FontManagerOrthography
78 *
79 * Returns: (element-type uint) (transfer container) (nullable): #GList containing codepoints.
80 * Free the returned #GList using #g_list_free().
81 */
82 GList *
83 font_manager_orthography_get_filter (FontManagerOrthography *self)
84 {
85 if (self == NULL)
86 return NULL;
87 GList *charlist = NULL;
88 g_autoptr(JsonObject) source = NULL;
89 g_object_get(self, FONT_MANAGER_JSON_PROXY_SOURCE, &source, NULL);
90 g_return_val_if_fail(source != NULL, charlist);
91 if (json_object_has_member(source, "filter")) {
92 JsonArray *arr = json_object_get_array_member(source, "filter");
93 guint arr_length = json_array_get_length(arr);
94 for (guint index = 0; index < arr_length; index++) {
95 gunichar uc = (gunichar) json_array_get_int_element(arr, index);
96 charlist = g_list_prepend(charlist, GINT_TO_POINTER(uc));
97 }
98 charlist = g_list_reverse(charlist);
99 }
100 return charlist;
101 }
102
103 /**
104 * font_manager_orthography_new:
105 * @orthography: #JsonObject containing orthography results
106 *
107 * @orthography should be one of the members of the object returned
108 * by #font_manager_get_orthography_results()
109 *
110 * Returns: (transfer full): A newly created #FontManagerOrthography.
111 * Free the returned object using #g_object_unref().
112 */
113 FontManagerOrthography *
114 font_manager_orthography_new (JsonObject *orthography)
115 {
116 return g_object_new(FONT_MANAGER_TYPE_ORTHOGRAPHY,
117 FONT_MANAGER_JSON_PROXY_SOURCE, orthography,
118 NULL);
119 }