Debian Codegraph @

lib/fontconfig/font-manager-fontconfig.c

raw
1 /* font-manager-fontconfig.c
2 *
3 * Copyright (C) 2009-2025 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-fontconfig.h"
22
23 /**
24 * SECTION: font-manager-fontconfig
25 * @short_description: Fontconfig related utility functions
26 * @title: Fontconfig Utility Functions
27 * @include: font-manager-fontconfig.h
28 * @see_also:
29 * #FontManagerFont
30 * #FontManagerFamily
31 * https://www.freedesktop.org/software/fontconfig/fontconfig-devel/
32 */
33
34 G_DEFINE_QUARK(font-manager-fontconfig-error-quark, font_manager_fontconfig_error)
35
36 static const gchar *DEFAULT_VARIANTS[5] = {
37 "Regular",
38 "Roman",
39 "Medium",
40 "Normal",
41 "Book"
42 };
43
44 static void
45 set_error (const gchar *message, GError **error)
46 {
47 g_return_if_fail(error == NULL || *error == NULL);
48 const gchar *msg_format = "Fontconfig Error : (%s)";
49 g_debug(msg_format, message);
50 g_set_error(error,
51 FONT_MANAGER_FONTCONFIG_ERROR,
52 FONT_MANAGER_FONTCONFIG_ERROR_FAILED,
53 msg_format, message);
54 return;
55 }
56
57 #define PANGO_1_44 PANGO_VERSION_ENCODE(1, 44, 0)
58
59 /* Note : Bitmap font support was dropped in Pango 1.44 */
60 gboolean
61 is_legacy_format (FcPattern *pat)
62 {
63 FcChar8 *format;
64 g_assert(FcPatternGetString(pat, FC_FONTFORMAT, 0, &format) == FcResultMatch);
65 return (g_strcmp0((const gchar *) format, "CFF") != 0 &&
66 g_strcmp0((const gchar *) format, "TrueType") != 0);
67 }
68
69 static void
70 process_fontset (const FcFontSet *fontset, JsonObject *json_obj)
71 {
72 int pango = pango_version();
73 for (int i = 0; i < fontset->nfont; i++) {
74 if (pango >= PANGO_1_44 && is_legacy_format(fontset->fonts[i]))
75 continue;
76 JsonObject *font_obj = font_manager_get_attributes_from_fontconfig_pattern(fontset->fonts[i]);
77 if (!json_object_has_member(font_obj, "active"))
78 json_object_set_boolean_member(font_obj, "active", TRUE);
79 const gchar *family = json_object_get_string_member(font_obj, "family");
80 const gchar *style = json_object_get_string_member(font_obj, "style");
81 if (!json_object_get_member(json_obj, family))
82 json_object_set_object_member(json_obj, family, json_object_new());
83 JsonObject *family_obj = json_object_get_object_member(json_obj, family);
84 json_object_set_object_member(family_obj, style, font_obj);
85 }
86 return;
87 }
88
89 /**
90 * font_manager_update_font_configuration:
91 *
92 * Returns: %TRUE on success
93 */
94 gboolean
95 font_manager_update_font_configuration (void) {
96 return (FcConfigDestroy(FcConfigGetCurrent()), FcInitReinitialize());
97 }
98
99 /**
100 * font_manager_add_application_font:
101 * @filepath: full path to font file to add to configuration
102 *
103 * Equivalent to FcConfigAppFontAddFile
104 *
105 * Returns: %TRUE on success
106 */
107 gboolean
108 font_manager_add_application_font (const gchar *filepath)
109 {
110 return FcConfigAppFontAddFile(FcConfigGetCurrent(), (FcChar8 *) filepath);
111 }
112
113 /**
114 * font_manager_add_application_font_directory:
115 * @dir: full path to directory to add to application specific configuration
116 *
117 * Equivalent to FcConfigAppFontAddDir
118 *
119 * Returns: %TRUE on success
120 */
121 gboolean
122 font_manager_add_application_font_directory (const gchar *dir)
123 {
124 return FcConfigAppFontAddDir(FcConfigGetCurrent(), (FcChar8 *) dir);
125 }
126
127 /**
128 * font_manager_clear_application_fonts:
129 *
130 * Equivalent to FcConfigAppFontClear
131 */
132 void
133 font_manager_clear_application_fonts (void)
134 {
135 FcConfigAppFontClear(FcConfigGetCurrent());
136 return;
137 }
138
139 /**
140 * font_manager_list_available_font_files:
141 *
142 * Returns: (element-type utf8) (transfer full) (nullable):
143 * a newly created #GSList containing filepaths or %NULL.
144 * Free the returned list using #g_slist_free_full(list, #g_free)
145 */
146 GList *
147 font_manager_list_available_font_files (void)
148 {
149 FcPattern *pattern = FcPatternBuild(NULL,NULL);
150 FcObjectSet *objectset = FcObjectSetBuild (FC_FILE, FC_FONTFORMAT, NULL);
151 g_assert(FcPatternAddBool(pattern, FC_VARIABLE, FcFalse));
152 FcFontSet *fontset = FcFontList(FcConfigGetCurrent(), pattern, objectset);
153 GList *result = NULL;
154
155 for (int i = 0; i < fontset->nfont; i++) {
156 FcChar8 *file;
157 if (FcPatternGetString(fontset->fonts[i], FC_FILE, 0, &file) == FcResultMatch) {
158 if (pango_version() >= PANGO_1_44 && is_legacy_format(fontset->fonts[i]))
159 continue;
160 result = g_list_prepend(result, g_strdup_printf("%s", file));
161 }
162 }
163
164 FcObjectSetDestroy(objectset);
165 FcPatternDestroy(pattern);
166 FcFontSetDestroy(fontset);
167 return result;
168 }
169
170 /**
171 * font_manager_list_available_font_families:
172 *
173 * Returns: (transfer full) (nullable):
174 * a newly created #FontManagerStringSet containing filepaths or %NULL.
175 * Free the returned object using #g_object_unref
176 */
177 FontManagerStringSet *
178 font_manager_list_available_font_families (void)
179 {
180 FcPattern *pattern = FcPatternBuild(NULL,NULL);
181 g_assert(FcPatternAddBool(pattern, FC_VARIABLE, FcFalse));
182 FcObjectSet *objectset = FcObjectSetBuild(FC_FAMILY, FC_FONTFORMAT, NULL);
183 FcFontSet *fontset = FcFontList(FcConfigGetCurrent(), pattern, objectset);
184
185 FontManagerStringSet * result = font_manager_string_set_new();
186
187 for (int i = 0; i < fontset->nfont; i++) {
188 FcChar8 *family;
189 if (FcPatternGetString(fontset->fonts[i], FC_FAMILY, 0, &family) == FcResultMatch) {
190 if (pango_version() >= PANGO_1_44 && is_legacy_format(fontset->fonts[i]))
191 continue;
192 font_manager_string_set_add(result, (const gchar *) family);
193 }
194 }
195
196 FcObjectSetDestroy(objectset);
197 FcPatternDestroy(pattern);
198 FcFontSetDestroy(fontset);
199 font_manager_string_set_sort(result);
200 return result;
201 }
202
203 /**
204 * font_manager_get_available_fonts:
205 * @family_name: (nullable): family name or %NULL
206 *
207 * If @family_name is not %NULL, only information for fonts belonging to
208 * specified family will be returned.
209 *
210 * The returned #JsonObject will have the following structure:
211 *
212 * |[
213 * {
214 * "family" : {
215 * "variation" : {
216 * "filepath" : string,
217 * "findex" : int,
218 * "family" : string,
219 * "style" : string,
220 * "spacing" : int,
221 * "slant" : int,
222 * "weight" : int,
223 * "width" : int,
224 * "description" : string,
225 * },
226 * ...
227 * },
228 * ...
229 * }
230 *]|
231 *
232 * Returns: (transfer full): A newly created #JsonObject which should be
233 * freed using #json_object_unref() when no longer needed.
234 */
235 JsonObject *
236 font_manager_get_available_fonts (const gchar *family_name)
237 {
238 FcPattern *pattern = NULL;
239
240 if (family_name)
241 pattern = FcPatternBuild (NULL,
242 FC_FAMILY, FcTypeString, family_name,
243 FC_VARIABLE, FcTypeBool, FcFalse,
244 NULL);
245 else
246 pattern = FcPatternBuild (NULL,
247 FC_VARIABLE, FcTypeBool, FcFalse,
248 NULL);
249
250 FcObjectSet *objectset = FcObjectSetBuild(FC_FILE,
251 FC_INDEX,
252 FC_FAMILY,
253 FC_STYLE,
254 FC_SLANT,
255 FC_WEIGHT,
256 FC_WIDTH,
257 FC_SPACING,
258 FC_LANG,
259 FC_FONTFORMAT,
260 NULL);
261
262 FcFontSet *fontset = FcFontList(FcConfigGetCurrent(), pattern, objectset);
263 JsonObject *result = json_object_new();
264 process_fontset(fontset, result);
265 FcObjectSetDestroy(objectset);
266 FcPatternDestroy(pattern);
267 FcFontSetDestroy(fontset);
268 return result;
269 }
270
271 /**
272 * font_manager_get_available_fonts_for_chars:
273 * @chars: string of characters to search for
274 *
275 * See #font_manager_get_available_fonts for a description of the
276 * #JsonObject returned by this function.
277 *
278 * The returned object will only contain those fonts which contain all
279 * the characters in @chars.
280 *
281 * Returns: (transfer full): A newly created #JsonObject which should be
282 * freed using #json_object_unref() when no longer needed.
283 */
284 JsonObject *
285 font_manager_get_available_fonts_for_chars (const gchar *chars)
286 {
287 FcObjectSet *objectset = FcObjectSetBuild(FC_FILE,
288 FC_INDEX,
289 FC_FAMILY,
290 FC_STYLE,
291 FC_SLANT,
292 FC_WEIGHT,
293 FC_WIDTH,
294 FC_SPACING,
295 FC_CHARSET,
296 FC_FONTFORMAT,
297 NULL);
298
299 gunichar wc;
300 const gchar *p = chars;
301 glong n_chars = g_utf8_strlen(p, -1);
302 JsonObject *result = json_object_new();
303
304 FcPattern *pattern = FcPatternCreate();
305 FcCharSet *charset = FcCharSetCreate();
306
307 g_assert(FcPatternAddBool(pattern, FC_VARIABLE, FcFalse));
308
309 for (int i = 0; i < n_chars; i++) {
310 wc = g_utf8_get_char(p);
311 g_assert(FcCharSetAddChar(charset, wc));
312 p = g_utf8_next_char(p);
313 }
314
315 g_assert(FcPatternAddCharSet(pattern, FC_CHARSET, charset));
316 FcFontSet *fontset = FcFontList(FcConfigGetCurrent(), pattern, objectset);
317 process_fontset(fontset, result);
318 FcFontSetDestroy(fontset);
319 FcCharSetDestroy(charset);
320 FcPatternDestroy(pattern);
321 FcObjectSetDestroy(objectset);
322 return result;
323 }
324
325 /**
326 * font_manager_get_langs_from_fontconfig_pattern: (skip)
327 * @pattern: FcPattern to examine
328 *
329 * Supplied FcPattern must contain an FcLangSet.
330 *
331 * Returns: (element-type utf8) (transfer full) (nullable):
332 * a newly created #GSList or %NULL
333 * The returned list contains dynamically allocated strings and should be
334 * freed using #g_slist_free_full(slist, #g_free) when no longer needed.
335 */
336 GList *
337 font_manager_get_langs_from_fontconfig_pattern (FcPattern *pattern)
338 {
339 GList *result = NULL;
340 FcLangSet *lang_set = NULL;
341
342 if (FcPatternGetLangSet(pattern, FC_LANG, 0, &lang_set) == FcResultMatch) {
343 FcChar8 *lang = NULL;
344 FcStrSet *_lang_set = FcLangSetGetLangs(lang_set);
345 FcStrList *langs = FcStrListCreate(_lang_set);
346 while ((lang = FcStrListNext(langs)))
347 result = g_list_prepend(result, g_strdup((const gchar *) lang));
348 FcStrSetDestroy(_lang_set);
349 FcStrListDone(langs);
350 }
351
352 return g_list_reverse(result);
353 }
354
355 /**
356 * font_manager_get_attributes_from_fontconfig_pattern: (skip)
357 * @pattern: FcPattern to examine
358 *
359 * The supplied FcPattern must supply file and family information,
360 * otherwise this function will fail.
361 * It is also expected to contain index, style, slant, weight, width, language,
362 * character set and spacing information, however default values will be used
363 * if those fields are missing. All other fields are ignored.
364 *
365 * See #FontManagerFont for a description of the #JsonObject returned by this function.
366 *
367 * Returns: (transfer full): A newly created #JsonObject which should be
368 * freed using #json_object_unref() when no longer needed.
369 */
370 JsonObject *
371 font_manager_get_attributes_from_fontconfig_pattern (FcPattern *pattern)
372 {
373 int index;
374 int slant;
375 int weight;
376 int width;
377 int spacing;
378 FcChar8 *file;
379 FcChar8 *family;
380 FcChar8 *style;
381
382 JsonObject *json_obj = json_object_new();
383
384 /* These should never fail. If they do, we're screwed */
385 g_assert(FcPatternGetString(pattern, FC_FILE, 0, &file) == FcResultMatch);
386 json_object_set_string_member(json_obj, "filepath", (const gchar *) file);
387 g_assert(FcPatternGetString(pattern, FC_FAMILY, 0, &family) == FcResultMatch);
388 json_object_set_string_member(json_obj, "family", (const gchar *) family);
389
390 /* If any of these fail, just set a sane default and continue on */
391 if (FcPatternGetInteger(pattern, FC_INDEX, 0, &index) != FcResultMatch)
392 index = 0;
393
394 if (FcPatternGetInteger(pattern, FC_SPACING, 0, &spacing) != FcResultMatch)
395 spacing = FC_PROPORTIONAL;
396
397 if (FcPatternGetInteger(pattern, FC_SLANT, 0, &slant) != FcResultMatch)
398 slant = FC_SLANT_ROMAN;
399
400 if (FcPatternGetInteger(pattern, FC_WEIGHT, 0, &weight) != FcResultMatch)
401 weight = FC_WEIGHT_MEDIUM;
402
403 if (FcPatternGetInteger(pattern, FC_WIDTH, 0, &width) != FcResultMatch)
404 width = FC_WIDTH_NORMAL;
405
406 json_object_set_int_member(json_obj, "findex", index);
407 json_object_set_int_member(json_obj, "spacing", spacing);
408 json_object_set_int_member(json_obj, "slant", slant);
409 json_object_set_int_member(json_obj, "weight", weight);
410 json_object_set_int_member(json_obj, "width", width);
411
412 if (FcPatternGetString (pattern, FC_STYLE, 0, &style) == FcResultMatch) {
413 json_object_set_string_member(json_obj, "style", (const gchar *) style);
414 } else {
415 /* Use the same style Pango would if none is given */
416 if (weight <= FC_WEIGHT_MEDIUM) {
417 if (slant == FC_SLANT_ROMAN)
418 json_object_set_string_member(json_obj, "style", "Regular");
419 else
420 json_object_set_string_member(json_obj, "style", "Italic");
421 } else {
422 if (slant == FC_SLANT_ROMAN)
423 json_object_set_string_member(json_obj, "style", "Bold");
424 else
425 json_object_set_string_member(json_obj, "style", "Bold Italic");
426 }
427 }
428
429 PangoFontDescription *descr = pango_fc_font_description_from_pattern(pattern, FALSE);
430 g_autofree gchar *font_desc = pango_font_description_to_string(descr);
431 pango_font_description_free(descr);
432 json_object_set_string_member(json_obj, "description", font_desc);
433 json_object_set_boolean_member(json_obj, "active", TRUE);
434 return json_obj;
435 }
436
437 /**
438 * font_manager_get_attributes_from_filepath:
439 * @filepath: full path to font file to query
440 * @error: #GError or %NULL to ignore errors
441 *
442 * See #FontManagerFamily for a description of the #JsonObject returned by this function.
443 *
444 * Returns: (transfer full): A newly created #JsonObject which should be
445 * freed using #json_object_unref() when no longer needed or %NULL if there was an error.
446 */
447 JsonObject *
448 font_manager_get_attributes_from_filepath (const gchar *filepath, GError **error)
449 {
450 g_return_val_if_fail(filepath != NULL, NULL);
451 g_return_val_if_fail((error == NULL || *error == NULL), NULL);
452
453 JsonObject *source = json_object_new();
454 FcFontSet *fontset = FcFontSetCreate();
455
456 if (FcFileScan(fontset, NULL, NULL, NULL, (FcChar8 *) filepath, FcTrue))
457 process_fontset(fontset, source);
458 else {
459 set_error("Failed to create FontConfig patterns for file", error);
460 FcFontSetDestroy(fontset);
461 return NULL;
462 }
463
464 g_autoptr(JsonArray) source_arr = font_manager_sort_json_font_listing(source);
465 JsonObject *result = json_array_get_object_element(source_arr, 0);
466 FcFontSetDestroy(fontset);
467 return json_object_ref(result);
468 }
469
470 /**
471 * font_manager_sort_json_font_listing:
472 * @json_obj: #JsonObject returned from #font_manager_get_available_fonts*
473 *
474 * The returned #JsonArray has the following structure:
475 *|[
476 * [
477 * {
478 * "family" : string,
479 * "n_variations" : int,
480 * "variations" : [
481 * {
482 * "filepath" : string,
483 * "findex" : int,
484 * "family" : string,
485 * "style" : string,
486 * "spacing" : int,
487 * "slant" : int,
488 * "weight" : int,
489 * "width" : int,
490 * "description" : string,
491 * },
492 * ...
493 * ],
494 * "active" : bool,
495 * "description" : string,
496 * },
497 * ...
498 * ]
499 *]|
500 * Returns: (transfer full): #JsonArray
501 */
502 JsonArray *
503 font_manager_sort_json_font_listing (JsonObject *json_obj)
504 {
505 GList *members = json_object_get_members(json_obj);
506 members = g_list_sort(members, (GCompareFunc) font_manager_natural_sort);
507 JsonArray *result = json_array_sized_new(g_list_length(members));
508 gint index = 0;
509 GList *iter;
510 for (iter = members; iter != NULL; iter = iter->next) {
511 JsonObject *family_obj = json_object_get_object_member(json_obj, iter->data);
512 GList *variations = json_object_get_values(family_obj);
513 gint n_variations = g_list_length(variations);
514 JsonArray *_variations = json_array_sized_new(n_variations);
515 JsonObject *_family_obj = json_object_new();
516 json_object_set_string_member(_family_obj, "family", iter->data);
517 json_object_set_int_member(_family_obj, "n-variations", n_variations);
518 json_object_set_array_member(_family_obj, "variations", _variations);
519 json_object_set_boolean_member(_family_obj, "active", TRUE);
520 json_object_set_int_member(_family_obj, "_index", index);
521 variations = g_list_sort(variations, (GCompareFunc) font_manager_compare_json_font_node);
522 gint _index = 0;
523 GList *_iter;
524 for (_iter = variations; _iter != NULL; _iter = _iter->next) {
525 JsonObject *style_obj = json_node_dup_object(_iter->data);
526 json_object_set_int_member(style_obj, "_index", _index);
527 json_array_add_object_element(_variations, style_obj);
528 /* Try to find "default" variation for this family */
529 if (!json_object_get_member(_family_obj, "description")) {
530 const gchar *style = json_object_get_string_member(style_obj, "style");
531 for (guint i = 0; i < G_N_ELEMENTS(DEFAULT_VARIANTS); i++) {
532 if (g_strcmp0(style, DEFAULT_VARIANTS[i]) == 0) {
533 const gchar *font_desc = json_object_get_string_member(style_obj, "description");
534 json_object_set_string_member(_family_obj, "description", font_desc);
535 break;
536 }
537 }
538 }
539 _index++;
540 }
541 /* No suitable "default" found for this family, set the first result as default */
542 if (!json_object_get_member(_family_obj, "description")) {
543 JsonObject *_default_ = json_array_get_object_element(_variations, 0);
544 const gchar *fallback = json_object_get_string_member(_default_, "description");
545 json_object_set_string_member(_family_obj, "description", fallback);
546 }
547 json_array_add_object_element(result, _family_obj);
548 g_list_free(variations);
549 index++;
550 }
551 g_list_free(members);
552 return result;
553 }
554
555 /**
556 * font_manager_weight_to_string:
557 * @weight: #FontManagerWeight
558 *
559 * Returns: (transfer none) (nullable): @weight as a string
560 */
561 const gchar *
562 font_manager_weight_to_string (FontManagerWeight weight)
563 {
564 switch (weight) {
565 case FONT_MANAGER_WEIGHT_THIN:
566 return _("Thin");
567 case FONT_MANAGER_WEIGHT_ULTRALIGHT:
568 return _("Ultra-Light");
569 case FONT_MANAGER_WEIGHT_LIGHT:
570 return _("Light");
571 case FONT_MANAGER_WEIGHT_SEMILIGHT:
572 return _("Semi-Light");
573 case FONT_MANAGER_WEIGHT_BOOK:
574 return _("Book");
575 case FONT_MANAGER_WEIGHT_MEDIUM:
576 return _("Medium");
577 case FONT_MANAGER_WEIGHT_SEMIBOLD:
578 return _("Semi-Bold");
579 case FONT_MANAGER_WEIGHT_BOLD:
580 return _("Bold");
581 case FONT_MANAGER_WEIGHT_ULTRABOLD:
582 return _("Ultra-Bold");
583 case FONT_MANAGER_WEIGHT_HEAVY:
584 return _("Heavy");
585 case FONT_MANAGER_WEIGHT_ULTRABLACK:
586 return _("Ultra-Heavy");
587 default:
588 return NULL;
589 }
590 }
591
592 /**
593 * font_manager_weight_defined:
594 * @weight: #FontManagerWeight
595 *
596 * Returns: %TRUE if @weight is valid.
597 */
598 gboolean
599 font_manager_weight_defined (FontManagerWeight weight)
600 {
601 switch (weight) {
602 case FONT_MANAGER_WEIGHT_THIN:
603 case FONT_MANAGER_WEIGHT_ULTRALIGHT:
604 case FONT_MANAGER_WEIGHT_LIGHT:
605 case FONT_MANAGER_WEIGHT_SEMILIGHT:
606 case FONT_MANAGER_WEIGHT_BOOK:
607 case FONT_MANAGER_WEIGHT_REGULAR:
608 case FONT_MANAGER_WEIGHT_MEDIUM:
609 case FONT_MANAGER_WEIGHT_SEMIBOLD:
610 case FONT_MANAGER_WEIGHT_BOLD:
611 case FONT_MANAGER_WEIGHT_ULTRABOLD:
612 case FONT_MANAGER_WEIGHT_HEAVY:
613 case FONT_MANAGER_WEIGHT_ULTRABLACK:
614 return TRUE;
615 default:
616 return FALSE;
617 }
618 }
619
620 GType
621 font_manager_weight_get_type (void)
622 {
623 static gsize g_define_type_id__volatile = 0;
624
625 if (g_once_init_enter (&g_define_type_id__volatile))
626 {
627 static const GEnumValue values[] = {
628 { FONT_MANAGER_WEIGHT_THIN, "FONT_MANAGER_WEIGHT_THIN", "thin" },
629 { FONT_MANAGER_WEIGHT_ULTRALIGHT, "FONT_MANAGER_WEIGHT_ULTRALIGHT", "ultralight" },
630 { FONT_MANAGER_WEIGHT_LIGHT, "FONT_MANAGER_WEIGHT_LIGHT", "light" },
631 { FONT_MANAGER_WEIGHT_SEMILIGHT, "FONT_MANAGER_WEIGHT_SEMILIGHT", "semilight" },
632 { FONT_MANAGER_WEIGHT_BOOK, "FONT_MANAGER_WEIGHT_BOOK", "book" },
633 { FONT_MANAGER_WEIGHT_REGULAR, "FONT_MANAGER_WEIGHT_REGULAR", "regular" },
634 { FONT_MANAGER_WEIGHT_MEDIUM, "FONT_MANAGER_WEIGHT_MEDIUM", "medium" },
635 { FONT_MANAGER_WEIGHT_SEMIBOLD, "FONT_MANAGER_WEIGHT_SEMIBOLD", "semibold" },
636 { FONT_MANAGER_WEIGHT_BOLD, "FONT_MANAGER_WEIGHT_BOLD", "bold" },
637 { FONT_MANAGER_WEIGHT_ULTRABOLD, "FONT_MANAGER_WEIGHT_ULTRABOLD", "ultrabold" },
638 { FONT_MANAGER_WEIGHT_HEAVY, "FONT_MANAGER_WEIGHT_HEAVY", "heavy" },
639 { FONT_MANAGER_WEIGHT_ULTRABLACK, "FONT_MANAGER_WEIGHT_ULTRABLACK", "ultrablack" },
640 { 0, NULL, NULL }
641 };
642 GType g_define_type_id =
643 g_enum_register_static (g_intern_static_string ("FontManagerWeight"), values);
644 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
645 }
646
647 return g_define_type_id__volatile;
648 }
649
650 /**
651 * font_manager_slant_to_string:
652 * @slant: #FontManagerSlant
653 *
654 * Returns: (transfer none) (nullable): @slant as a string
655 */
656 const gchar *
657 font_manager_slant_to_string (FontManagerSlant slant)
658 {
659 switch (slant) {
660 case FONT_MANAGER_SLANT_ITALIC:
661 return _("Italic");
662 case FONT_MANAGER_SLANT_OBLIQUE:
663 return _("Oblique");
664 default:
665 return NULL;
666 }
667 }
668
669 GType
670 font_manager_slant_get_type (void)
671 {
672 static gsize g_define_type_id__volatile = 0;
673
674 if (g_once_init_enter (&g_define_type_id__volatile))
675 {
676 static const GEnumValue values[] = {
677 { FONT_MANAGER_SLANT_ROMAN, "FONT_MANAGER_SLANT_ROMAN", "roman" },
678 { FONT_MANAGER_SLANT_ITALIC, "FONT_MANAGER_SLANT_ITALIC", "italic" },
679 { FONT_MANAGER_SLANT_OBLIQUE, "FONT_MANAGER_SLANT_OBLIQUE", "oblique" },
680 { 0, NULL, NULL }
681 };
682 GType g_define_type_id =
683 g_enum_register_static (g_intern_static_string ("FontManagerSlant"), values);
684 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
685 }
686
687 return g_define_type_id__volatile;
688 }
689
690 /**
691 * font_manager_width_to_string:
692 * @width: #FontManagerWidth
693 *
694 * Returns: (transfer none) (nullable): @width as a string
695 */
696 const gchar *
697 font_manager_width_to_string (FontManagerWidth width)
698 {
699 switch (width) {
700 case FONT_MANAGER_WIDTH_ULTRACONDENSED:
701 return _("Ultra-Condensed");
702 case FONT_MANAGER_WIDTH_EXTRACONDENSED:
703 return _("Extra-Condensed");
704 case FONT_MANAGER_WIDTH_CONDENSED:
705 return _("Condensed");
706 case FONT_MANAGER_WIDTH_SEMICONDENSED:
707 return _("Semi-Condensed");
708 case FONT_MANAGER_WIDTH_SEMIEXPANDED:
709 return _("Semi-Expanded");
710 case FONT_MANAGER_WIDTH_EXPANDED:
711 return _("Expanded");
712 case FONT_MANAGER_WIDTH_EXTRAEXPANDED:
713 return _("Extra-Expanded");
714 case FONT_MANAGER_WIDTH_ULTRAEXPANDED:
715 return _("Ultra-Expanded");
716 default:
717 return NULL;
718 }
719 }
720
721 /**
722 * font_manager_width_defined:
723 * @width: #FontManagerWidth
724 *
725 * Returns: %TRUE if @weight is valid.
726 */
727 gboolean
728 font_manager_width_defined (FontManagerWidth width)
729 {
730 switch (width) {
731 case FONT_MANAGER_WIDTH_NORMAL:
732 case FONT_MANAGER_WIDTH_ULTRACONDENSED:
733 case FONT_MANAGER_WIDTH_EXTRACONDENSED:
734 case FONT_MANAGER_WIDTH_CONDENSED:
735 case FONT_MANAGER_WIDTH_SEMICONDENSED:
736 case FONT_MANAGER_WIDTH_SEMIEXPANDED:
737 case FONT_MANAGER_WIDTH_EXPANDED:
738 case FONT_MANAGER_WIDTH_EXTRAEXPANDED:
739 case FONT_MANAGER_WIDTH_ULTRAEXPANDED:
740 return TRUE;
741 default:
742 return FALSE;
743 }
744 }
745
746 GType
747 font_manager_width_get_type (void)
748 {
749 static gsize g_define_type_id__volatile = 0;
750
751 if (g_once_init_enter (&g_define_type_id__volatile))
752 {
753 static const GEnumValue values[] = {
754 { FONT_MANAGER_WIDTH_ULTRACONDENSED, "FONT_MANAGER_WIDTH_ULTRACONDENSED", "ultracondensed" },
755 { FONT_MANAGER_WIDTH_EXTRACONDENSED, "FONT_MANAGER_WIDTH_EXTRACONDENSED", "extracondensed" },
756 { FONT_MANAGER_WIDTH_CONDENSED, "FONT_MANAGER_WIDTH_CONDENSED", "condensed" },
757 { FONT_MANAGER_WIDTH_SEMICONDENSED, "FONT_MANAGER_WIDTH_SEMICONDENSED", "semicondensed" },
758 { FONT_MANAGER_WIDTH_NORMAL, "FONT_MANAGER_WIDTH_NORMAL", "normal" },
759 { FONT_MANAGER_WIDTH_SEMIEXPANDED, "FONT_MANAGER_WIDTH_SEMIEXPANDED", "semiexpanded" },
760 { FONT_MANAGER_WIDTH_EXPANDED, "FONT_MANAGER_WIDTH_EXPANDED", "expanded" },
761 { FONT_MANAGER_WIDTH_EXTRAEXPANDED, "FONT_MANAGER_WIDTH_EXTRAEXPANDED", "extraexpanded" },
762 { FONT_MANAGER_WIDTH_ULTRAEXPANDED, "FONT_MANAGER_WIDTH_ULTRAEXPANDED", "ultraexpanded" },
763 { 0, NULL, NULL }
764 };
765 GType g_define_type_id =
766 g_enum_register_static (g_intern_static_string ("FontManagerWidth"), values);
767 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
768 }
769
770 return g_define_type_id__volatile;
771 }
772
773 /**
774 * font_manager_spacing_to_string:
775 * @spacing: #FontManagerSpacing
776 *
777 * Returns: (transfer none) (nullable): @spacing as a string
778 */
779 const gchar *
780 font_manager_spacing_to_string (FontManagerSpacing spacing)
781 {
782 switch (spacing) {
783 case FONT_MANAGER_SPACING_PROPORTIONAL:
784 return _("Proportional");
785 case FONT_MANAGER_SPACING_DUAL:
786 return _("Dual Width");
787 case FONT_MANAGER_SPACING_MONO:
788 return _("Monospace");
789 case FONT_MANAGER_SPACING_CHARCELL:
790 return _("Charcell");
791 default:
792 return NULL;
793 }
794 }
795
796 GType
797 font_manager_spacing_get_type (void)
798 {
799 static gsize g_define_type_id__volatile = 0;
800
801 if (g_once_init_enter (&g_define_type_id__volatile))
802 {
803 static const GEnumValue values[] = {
804 { FONT_MANAGER_SPACING_PROPORTIONAL, "FONT_MANAGER_SPACING_PROPORTIONAL", "proportional" },
805 { FONT_MANAGER_SPACING_DUAL, "FONT_MANAGER_SPACING_DUAL", "dual" },
806 { FONT_MANAGER_SPACING_MONO, "FONT_MANAGER_SPACING_MONO", "mono" },
807 { FONT_MANAGER_SPACING_CHARCELL, "FONT_MANAGER_SPACING_CHARCELL", "charcell" },
808 { 0, NULL, NULL }
809 };
810 GType g_define_type_id =
811 g_enum_register_static (g_intern_static_string ("FontManagerSpacing"), values);
812 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
813 }
814
815 return g_define_type_id__volatile;
816 }
817
818 /**
819 * font_manager_subpixel_order_to_string:
820 * @rgba: #FontManagerSubpixelOrder
821 *
822 * Returns: (transfer none) (nullable): @rgba as a string
823 */
824 const gchar *
825 font_manager_subpixel_order_to_string (FontManagerSubpixelOrder rgba)
826 {
827 switch (rgba) {
828 case FONT_MANAGER_SUBPIXEL_ORDER_UNKNOWN:
829 return _("Unknown");
830 case FONT_MANAGER_SUBPIXEL_ORDER_RGB:
831 return _("RGB");
832 case FONT_MANAGER_SUBPIXEL_ORDER_BGR:
833 return _("BGR");
834 case FONT_MANAGER_SUBPIXEL_ORDER_VRGB:
835 return _("VRGB");
836 case FONT_MANAGER_SUBPIXEL_ORDER_VBGR:
837 return _("VBGR");
838 default:
839 return _("None");
840 }
841 }
842
843 GType
844 font_manager_subpixel_order_get_type (void)
845 {
846 static gsize g_define_type_id__volatile = 0;
847
848 if (g_once_init_enter (&g_define_type_id__volatile))
849 {
850 static const GEnumValue values[] = {
851 { FONT_MANAGER_SUBPIXEL_ORDER_UNKNOWN, "FONT_MANAGER_SUBPIXEL_ORDER_UNKNOWN", "unknown" },
852 { FONT_MANAGER_SUBPIXEL_ORDER_RGB, "FONT_MANAGER_SUBPIXEL_ORDER_RGB", "rgb" },
853 { FONT_MANAGER_SUBPIXEL_ORDER_BGR, "FONT_MANAGER_SUBPIXEL_ORDER_BGR", "bgr" },
854 { FONT_MANAGER_SUBPIXEL_ORDER_VRGB, "FONT_MANAGER_SUBPIXEL_ORDER_VRGB", "vrgb" },
855 { FONT_MANAGER_SUBPIXEL_ORDER_VBGR, "FONT_MANAGER_SUBPIXEL_ORDER_VBGR", "vbgr" },
856 { FONT_MANAGER_SUBPIXEL_ORDER_NONE, "FONT_MANAGER_SUBPIXEL_ORDER_NONE", "none" },
857 { 0, NULL, NULL }
858 };
859 GType g_define_type_id =
860 g_enum_register_static (g_intern_static_string ("FontManagerSubpixelOrder"), values);
861 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
862 }
863
864 return g_define_type_id__volatile;
865 }
866
867 /**
868 * font_manager_hint_style_to_string:
869 * @hinting: #FontManagerHintStyle
870 *
871 * Returns: (transfer none) (nullable): @hinting as a string
872 */
873 const gchar *
874 font_manager_hint_style_to_string (FontManagerHintStyle hinting)
875 {
876 switch (hinting) {
877 case FONT_MANAGER_HINT_STYLE_SLIGHT:
878 return _("Slight");
879 case FONT_MANAGER_HINT_STYLE_MEDIUM:
880 return _("Medium");
881 case FONT_MANAGER_HINT_STYLE_FULL:
882 return _("Full");
883 default:
884 return _("None");
885 }
886 }
887
888 GType
889 font_manager_hint_style_get_type (void)
890 {
891 static gsize g_define_type_id__volatile = 0;
892
893 if (g_once_init_enter (&g_define_type_id__volatile))
894 {
895 static const GEnumValue values[] = {
896 { FONT_MANAGER_HINT_STYLE_NONE, "FONT_MANAGER_HINT_STYLE_NONE", "none" },
897 { FONT_MANAGER_HINT_STYLE_SLIGHT, "FONT_MANAGER_HINT_STYLE_SLIGHT", "slight" },
898 { FONT_MANAGER_HINT_STYLE_MEDIUM, "FONT_MANAGER_HINT_STYLE_MEDIUM", "medium" },
899 { FONT_MANAGER_HINT_STYLE_FULL, "FONT_MANAGER_HINT_STYLE_FULL", "full" },
900 { 0, NULL, NULL }
901 };
902 GType g_define_type_id =
903 g_enum_register_static (g_intern_static_string ("FontManagerHintStyle"), values);
904 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
905 }
906
907 return g_define_type_id__volatile;
908 }
909
910 /**
911 * font_manager_lcd_filter_to_string:
912 * @filter: #FontManagerLCDFilter
913 *
914 * Returns: (transfer none) (nullable): @filter as a string
915 */
916 const gchar *
917 font_manager_lcd_filter_to_string (FontManagerLCDFilter filter)
918 {
919 switch (filter) {
920 case FONT_MANAGER_LCD_FILTER_DEFAULT:
921 return _("Default");
922 case FONT_MANAGER_LCD_FILTER_LIGHT:
923 return _("Light");
924 case FONT_MANAGER_LCD_FILTER_LEGACY:
925 return _("Legacy");
926 default:
927 return _("None");
928 }
929 }
930
931 GType
932 font_manager_lcd_filter_get_type (void)
933 {
934 static gsize g_define_type_id__volatile = 0;
935
936 if (g_once_init_enter (&g_define_type_id__volatile))
937 {
938 static const GEnumValue values[] = {
939 { FONT_MANAGER_LCD_FILTER_NONE, "FONT_MANAGER_LCD_FILTER_NONE", "none" },
940 { FONT_MANAGER_LCD_FILTER_DEFAULT, "FONT_MANAGER_LCD_FILTER_DEFAULT", "default" },
941 { FONT_MANAGER_LCD_FILTER_LIGHT, "FONT_MANAGER_LCD_FILTER_LIGHT", "light" },
942 { FONT_MANAGER_LCD_FILTER_LEGACY, "FONT_MANAGER_LCD_FILTER_LEGACY", "legacy" },
943 { 0, NULL, NULL }
944 };
945 GType g_define_type_id =
946 g_enum_register_static (g_intern_static_string ("FontManagerLCDFilter"), values);
947 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
948 }
949
950 return g_define_type_id__volatile;
951 }
952