diff options
Diffstat (limited to 'pango')
-rw-r--r-- | pango/meson.build | 2 | ||||
-rw-r--r-- | pango/pango-generic-family-private.h | 45 | ||||
-rw-r--r-- | pango/pango-generic-family.c | 210 | ||||
-rw-r--r-- | pango/pango-generic-family.h | 39 | ||||
-rw-r--r-- | pango/pango.h | 1 |
5 files changed, 297 insertions, 0 deletions
diff --git a/pango/meson.build b/pango/meson.build index 2b42c944..ef498d6b 100644 --- a/pango/meson.build +++ b/pango/meson.build @@ -36,6 +36,7 @@ pango_sources = [ 'json/gtkjsonprinter.c', 'pango-hbface.c', 'pango-hbfamily.c', + 'pango-generic-family.c', ] pango_headers = [ @@ -52,6 +53,7 @@ pango_headers = [ 'pango-fontmap.h', 'pango-fontset.h', 'pango-fontset-simple.h', + 'pango-generic-family.h', 'pango-glyph.h', 'pango-glyph-item.h', 'pango-gravity.h', diff --git a/pango/pango-generic-family-private.h b/pango/pango-generic-family-private.h new file mode 100644 index 00000000..4ba8c865 --- /dev/null +++ b/pango/pango-generic-family-private.h @@ -0,0 +1,45 @@ +/* Pango + * + * Copyright (C) 2022 Matthias Clasen + * + * 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. + */ + +#pragma once + +#include "pango-font.h" +#include "pango-hbface.h" +#include "pango-generic-family.h" +#include "pango-hbfamily-private.h" + + +struct _PangoGenericFamily +{ + PangoFontFamily parent_instance; + + PangoFontMap *map; + char *name; + GPtrArray *families; +}; + + +void pango_generic_family_set_font_map (PangoGenericFamily *self, + PangoFontMap *map); + +PangoHbFace * pango_generic_family_find_face (PangoGenericFamily *self, + PangoFontDescription *description, + PangoLanguage *language, + gunichar wc); diff --git a/pango/pango-generic-family.c b/pango/pango-generic-family.c new file mode 100644 index 00000000..ceca7399 --- /dev/null +++ b/pango/pango-generic-family.c @@ -0,0 +1,210 @@ +/* Pango + * + * Copyright (C) 2022 Matthias Clasen + * + * 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-generic-family-private.h" +#include "pango-impl-utils.h" +#include "pango-hbface-private.h" +#include "pango-font-private.h" + +/** + * PangoGenericFamily: + * + * An implementation of `PangoFontFamily` + * that provides faces from other families. + * + * `PangoGenericFamily can be used to e.g. assemble a + * generic 'sans-serif' family from a number of other + * font families. + */ + +/* {{{ PangoFontFamily implementation */ + +struct _PangoGenericFamilyClass +{ + PangoFontFamilyClass parent_class; +}; + +G_DEFINE_TYPE (PangoGenericFamily, pango_generic_family, PANGO_TYPE_FONT_FAMILY) + +static void +pango_generic_family_init (PangoGenericFamily *self) +{ + self->families = g_ptr_array_new_with_free_func (g_object_unref); +} + +static void +pango_generic_family_finalize (GObject *object) +{ + PangoGenericFamily *self = PANGO_GENERIC_FAMILY (object); + + g_free (self->name); + g_ptr_array_unref (self->families); + + G_OBJECT_CLASS (pango_generic_family_parent_class)->finalize (object); +} + +static const char * +pango_generic_family_get_name (PangoFontFamily *family) +{ + PangoGenericFamily *self = PANGO_GENERIC_FAMILY (family); + + return self->name; +} + +static gboolean +pango_generic_family_is_monospace (PangoFontFamily *family) +{ + return FALSE; +} + +static gboolean +pango_generic_family_is_variable (PangoFontFamily *family) +{ + return FALSE; +} + +static void +pango_generic_family_class_init (PangoGenericFamilyClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + PangoFontFamilyClass *family_class = PANGO_FONT_FAMILY_CLASS (class); + + object_class->finalize = pango_generic_family_finalize; + + family_class->get_name = pango_generic_family_get_name; + family_class->is_monospace = pango_generic_family_is_monospace; + family_class->is_variable = pango_generic_family_is_variable; +} + +/* }}} */ +/* {{{ Private API */ + +/*< private > + * pango_generic_family_set_font_map: + * @self: a `PangoGenericFamily` + * @map: (nullable): a `PangoFontMap` + * + * Sets the map of @self. + */ +void +pango_generic_family_set_font_map (PangoGenericFamily *self, + PangoFontMap *map) +{ + if (self->map) + g_object_remove_weak_pointer (G_OBJECT (self->map), (gpointer *)&self->map); + + self->map = map; + + if (self->map) + g_object_add_weak_pointer (G_OBJECT (self->map), (gpointer *)&self->map); +} + +/*< private > + * pango_generic_family_find_face: + * @family: a `PangoGenericFamily` + * @description: `PangoFontDescription` to match + * @language: (nullable): `PangoLanguage` to support + * @wc: a Unicode character, or 0 to ignore + * + * Finds the face that best matches the font description while + * also supporting the given language and character, from the first + * family in @family that has any matching faces. + * + * Returns: (transfer none) (nullable): the face + */ +PangoHbFace * +pango_generic_family_find_face (PangoGenericFamily *self, + PangoFontDescription *description, + PangoLanguage *language, + gunichar wc) +{ + PangoHbFace *face = NULL; + + for (int i = 0; i < self->families->len; i++) + { + PangoHbFamily *family = g_ptr_array_index (self->families, i); + + face = pango_hb_family_find_face (family, description, language, wc); + if (face) + break; + } + + return face; +} + +/* }}} */ +/* {{{ Public API */ + +/** + * pango_generic_family_new: + * @name: the family name + * + * Creates a new `PangoGenericFamily`. + * + * A generic family does not contain faces, but will return + * faces from other families that match a given query. + * + * Returns: a newly created `PangoGenericFamily` + * + * Since: 1.52 + */ +PangoGenericFamily * +pango_generic_family_new (const char *name) +{ + PangoGenericFamily *self; + + g_return_val_if_fail (name != NULL, NULL); + + self = g_object_new (PANGO_TYPE_GENERIC_FAMILY, NULL); + + self->name = g_strdup (name); + + return self; +} + +/** + * pango_generic_family_add_family: + * @self: a `PangoGenericFamily` + * @family: (transfer none): a `PangoFontFamily` to add + * + * Adds a `PangoFontFamily` to a `PangoGenericFamily`. + * + * It is an error to call this function more than + * once for the same family. + * + * Since: 1.52 + */ +void +pango_generic_family_add_family (PangoGenericFamily *self, + PangoFontFamily *family) +{ + g_return_if_fail (PANGO_IS_GENERIC_FAMILY (self)); + g_return_if_fail (PANGO_IS_FONT_FAMILY (family)); + + g_ptr_array_add (self->families, g_object_ref (family)); +} + +/* }}} */ + +/* vim:set foldmethod=marker expandtab: */ diff --git a/pango/pango-generic-family.h b/pango/pango-generic-family.h new file mode 100644 index 00000000..38dd27ea --- /dev/null +++ b/pango/pango-generic-family.h @@ -0,0 +1,39 @@ +/* Pango + * + * Copyright (C) 2022 Matthias Clasen + * + * 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. + */ + +#pragma once + +#include "pango-font.h" + +G_BEGIN_DECLS + +#define PANGO_TYPE_GENERIC_FAMILY (pango_generic_family_get_type ()) + +PANGO_AVAILABLE_IN_1_52 +G_DECLARE_FINAL_TYPE (PangoGenericFamily, pango_generic_family, PANGO, GENERIC_FAMILY, PangoFontFamily) + +PANGO_AVAILABLE_IN_1_52 +PangoGenericFamily * pango_generic_family_new (const char *name); + +PANGO_AVAILABLE_IN_1_52 +void pango_generic_family_add_family (PangoGenericFamily *self, + PangoFontFamily *family); + +G_END_DECLS diff --git a/pango/pango.h b/pango/pango.h index 917f9ffd..87036972 100644 --- a/pango/pango.h +++ b/pango/pango.h @@ -36,6 +36,7 @@ #include <pango/pango-fontmap.h> #include <pango/pango-fontset.h> #include <pango/pango-fontset-simple.h> +#include <pango/pango-generic-family.h> #include <pango/pango-glyph.h> #include <pango/pango-glyph-item.h> #include <pango/pango-gravity.h> |