diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-06-14 06:59:31 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-06-22 13:54:01 -0400 |
commit | 811e3a2b8da20f0fff3fc70f5c73cb1f5b50c6db (patch) | |
tree | d5d1dceba87a4c1f724c2ed0734e0d7198871e25 | |
parent | 2736a3113518945c5df780f35a57a5395b27ed2f (diff) | |
download | pango-811e3a2b8da20f0fff3fc70f5c73cb1f5b50c6db.tar.gz |
Rename PangoHbFontMap to PangoFontMap
And rename the backend subclasses too.
28 files changed, 1079 insertions, 1456 deletions
diff --git a/examples/cairoshape.c b/examples/cairoshape.c index a1501691..d3a90bd8 100644 --- a/examples/cairoshape.c +++ b/examples/cairoshape.c @@ -25,7 +25,7 @@ #include <string.h> #include <pango/pangocairo.h> -#include <pango/pangofc-hbfontmap.h> +#include <pango/pangofc-fontmap.h> static PangoFontMap *fontmap; @@ -271,7 +271,7 @@ render_cb (PangoUserFace *face, } static void -setup_fontmap (PangoHbFontMap *fontmap) +setup_fontmap (PangoFontMap *fontmap) { PangoFontDescription *desc; PangoUserFace *face; @@ -285,7 +285,7 @@ setup_fontmap (PangoHbFontMap *fontmap) NULL, render_cb, NULL, NULL, "Black", desc); - pango_hb_font_map_add_face (fontmap, PANGO_FONT_FACE (face)); + pango_font_map_add_face (fontmap, PANGO_FONT_FACE (face)); pango_font_description_free (desc); } @@ -307,8 +307,8 @@ main (int argc, char **argv) filename = argv[1]; - fontmap = PANGO_FONT_MAP (pango_fc_hb_font_map_new ()); - setup_fontmap (PANGO_HB_FONT_MAP (fontmap)); + fontmap = PANGO_FONT_MAP (pango_fc_font_map_new ()); + setup_fontmap (PANGO_FONT_MAP (fontmap)); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0); cr = cairo_create (surface); diff --git a/examples/userfont.c b/examples/userfont.c index e047d18e..eb5c504b 100644 --- a/examples/userfont.c +++ b/examples/userfont.c @@ -15,7 +15,7 @@ #include <stdio.h> #include <pango/pangocairo.h> -#include <pango/pangofc-hbfontmap.h> +#include <pango/pangofc-fontmap.h> static PangoFontMap *fontmap; @@ -285,7 +285,7 @@ render_cb (PangoUserFace *face, } static void -setup_fontmap (PangoHbFontMap *fontmap) +setup_fontmap (PangoFontMap *fontmap) { PangoFontDescription *desc; PangoUserFace *face; @@ -299,7 +299,7 @@ setup_fontmap (PangoHbFontMap *fontmap) render_cb, (gpointer) glyphs, NULL, "Black", desc); - pango_hb_font_map_add_face (fontmap, PANGO_FONT_FACE (face)); + pango_font_map_add_face (fontmap, PANGO_FONT_FACE (face)); pango_font_description_free (desc); } @@ -321,8 +321,8 @@ main (int argc, char **argv) filename = argv[1]; - fontmap = PANGO_FONT_MAP (pango_fc_hb_font_map_new ()); - setup_fontmap (PANGO_HB_FONT_MAP (fontmap)); + fontmap = PANGO_FONT_MAP (pango_fc_font_map_new ()); + setup_fontmap (PANGO_FONT_MAP (fontmap)); layout = get_layout (); diff --git a/pango/meson.build b/pango/meson.build index f65ef89d..ffec5cb2 100644 --- a/pango/meson.build +++ b/pango/meson.build @@ -48,7 +48,6 @@ pango_sources = [ 'pango-hbfamily.c', 'pango-generic-family.c', 'pango-hbfont.c', - 'pango-hbfontmap.c', 'pango-userface.c', 'pango-userfont.c', ] @@ -70,7 +69,6 @@ pango_headers = [ 'pango-font-metrics.h', 'pango-fontmap.h', 'pango-fontset.h', - 'pango-fontset-simple.h', 'pango-generic-family.h', 'pango-glyph.h', 'pango-glyph-item.h', @@ -92,7 +90,6 @@ pango_headers = [ 'pango-utils.h', 'pango-hbface.h', 'pango-hbfont.h', - 'pango-hbfontmap.h', 'pango-userface.h', 'pango-userfont.h', ] @@ -114,30 +111,28 @@ if cairo_dep.found() 'pangocairo-render.c', ] - if pango_font_backends.contains('win32') - pango_sources += [ - 'pangodwrite-hbfontmap.cpp', - ] - endif - - if pango_font_backends.contains('quartz') - pango_sources += [ - 'pangocoretext-hbfontmap.c', - ] - endif - pango_gir_includes += [ 'cairo-1.0', ] endif +if has_core_text + pango_headers += [ + 'pangocoretext-fontmap.h', + ] + + pango_sources += [ + 'pangocoretext-fontmap.c', + ] +endif + if build_pangoft2 pango_headers += [ - 'pangofc-hbfontmap.h', + 'pangofc-fontmap.h', ] pango_sources += [ - 'pangofc-hbfontmap.c', + 'pangofc-fontmap.c', 'pangofc-language-set.c', ] @@ -148,7 +143,11 @@ endif if host_system == 'windows' pango_headers += [ - 'pangodwrite-hbfontmap.h', + 'pangodwrite-fontmap.h', + ] + + pango_sources += [ + 'pangodwrite-fontmap.cpp', ] pango_deps += [ diff --git a/pango/pango-font.c b/pango/pango-font.c index c5428313..fbf1ddf5 100644 --- a/pango/pango-font.c +++ b/pango/pango-font.c @@ -75,9 +75,7 @@ pango_font_default_has_char (PangoFont *font, static PangoFontFace * pango_font_default_get_face (PangoFont *font) { - PangoFontMap *map = pango_font_get_font_map (font); - - return PANGO_FONT_MAP_GET_CLASS (map)->get_face (map,font); + return NULL; } static void diff --git a/pango/pango-fontmap-private.h b/pango/pango-fontmap-private.h index 2e2c39d2..47b0c34a 100644 --- a/pango/pango-fontmap-private.h +++ b/pango/pango-fontmap-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2000 Red Hat Software + * Copyright 2021 Red Hat, Inc. * * SPDX-License-Identifier: LGPL-2.1-or-later * @@ -19,39 +19,51 @@ #pragma once -#include <pango/pango-font-private.h> -#include <pango/pango-fontset.h> #include <pango/pango-fontmap.h> +#include <pango/pango-hbfamily-private.h> +#include <pango/pango-fontmap-private.h> -#define PANGO_FONT_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_FONT_MAP, PangoFontMapClass)) -#define PANGO_FONT_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_FONT_MAP, PangoFontMapClass)) - -typedef struct _PangoFontMapClass PangoFontMapClass; - struct _PangoFontMap { GObject parent_instance; + + GPtrArray *added_faces; + GPtrArray *added_families; + GHashTable *families_hash; + GPtrArray *families; + GHashTable *fontsets; + GQueue fontset_cache; + + double dpi; + gboolean in_populate; + guint serial; }; +/** + * PangoFontMapClass: + * @populate: Subclasses should call pango_font_map_add_face to populate + * the map with faces and families in this vfunc. + */ struct _PangoFontMapClass { GObjectClass parent_class; - PangoFont * (*load_font) (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc); - PangoFontset *(*load_fontset) (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc, - PangoLanguage *language); - - guint (*get_serial) (PangoFontMap *fontmap); - void (*changed) (PangoFontMap *fontmap); + PangoFont * (* load_font) (PangoFontMap *self, + PangoContext *context, + const PangoFontDescription *desc); + PangoFontset * (* load_fontset) (PangoFontMap *self, + PangoContext *context, + const PangoFontDescription *desc, + PangoLanguage *language); + guint (* get_serial) (PangoFontMap *self); + void (* changed) (PangoFontMap *self); + PangoFontFamily * (* get_family) (PangoFontMap *self, + const char *name); + void (* populate) (PangoFontMap *self); +}; - PangoFontFamily * (*get_family) (PangoFontMap *fontmap, - const char *name); +void pango_font_map_repopulate (PangoFontMap *self, + gboolean add_synthetic); - PangoFontFace * (*get_face) (PangoFontMap *fontmap, - PangoFont *font); -}; +void pango_font_map_changed (PangoFontMap *self); diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c index 41355608..c2058dfc 100644 --- a/pango/pango-fontmap.c +++ b/pango/pango-fontmap.c @@ -1,7 +1,6 @@ /* Pango - * pango-fontmap.c: Font handling * - * Copyright (C) 2000 Red Hat Software + * Copyright (C) 2021 Matthias Clasen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -10,7 +9,7 @@ * * 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 + * 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 @@ -20,51 +19,601 @@ */ #include "config.h" +#include <math.h> #include <gio/gio.h> #include "pango-fontmap-private.h" -#include "pango-fontset-simple.h" -#include "pango-impl-utils.h" -#include <stdlib.h> +#include "pango-hbfamily-private.h" +#include "pango-generic-family-private.h" +#include "pango-hbface-private.h" +#include "pango-hbfont-private.h" +#include "pango-fontset-cached-private.h" +#include "pango-userface-private.h" +#include "pango-userfont-private.h" +#include "pango-fontset.h" +#include "pango-font-face-private.h" +#include "pango-trace-private.h" +#include "pango-context.h" -static PangoFontset *pango_font_map_real_load_fontset (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc, - PangoLanguage *language); +#if defined (HAVE_CORE_TEXT) && defined (HAVE_CAIRO_QUARTZ) +#include "pangocoretext-fontmap.h" +#endif +#if defined (HAVE_CAIRO_WIN32) +#include "pangodwrite-fontmap.h" +#endif -static PangoFontFamily *pango_font_map_real_get_family (PangoFontMap *fontmap, - const char *name); +#if defined (HAVE_CAIRO_FREETYPE) +#include "pangofc-fontmap.h" +#endif -static void pango_font_map_real_changed (PangoFontMap *fontmap); +#include <hb-ot.h> -static void pango_font_map_list_model_init (GListModelInterface *iface); + +/** + * PangoFontMap: + * + * `PangoFontMap` is a `PangoFontMap` subclass for use with + * `PangoHbFace` and `PangoHbFont`. It handles caching and + * lookup of faces and fonts. + * + * Subclasses populate the fontmap using backend-specific APIs + * to enumerate the available fonts on the sytem, but it is + * also possible to create an instance of `PangoFontMap` and + * populate it manually using [method@Pango.FontMap.add_file] + * and [method@Pango.FontMap.add_face]. + * + * Note that to be fully functional, a fontmap needs to provide + * generic families for monospace and sans-serif. These can + * be added using [method@Pango.FontMap.add_family] and + * [ctor@Pango.GenericFamily.new]. + */ + + +/* The central api is load_fontset, which takes a font description + * and language, finds the matching faces, and creates a PangoFontset + * for them. To speed this operation up, the font map maintains a + * cache of fontsets (in the form of a GQueue) and has a hash table + * for looking up existing fontsets. + * + * The PangoFontsetCached object is the fontset subclass that is used + * here, and it contains the necessary data for the cashing and hashing. + * PangoFontsetCached also caches the character-to-font mapping that is + * used when itemizing text. + */ + + +/* {{{ GListModel implementation */ + +static GType +pango_font_map_get_item_type (GListModel *list) +{ + return PANGO_TYPE_FONT_FAMILY; +} + +static guint +pango_font_map_get_n_items (GListModel *list) +{ + PangoFontMap *self = PANGO_FONT_MAP (list); + + return self->families->len; +} + +static gpointer +pango_font_map_get_item (GListModel *list, + guint position) +{ + PangoFontMap *self = PANGO_FONT_MAP (list); + + if (position < self->families->len) + return g_object_ref (g_ptr_array_index (self->families, position)); + + return NULL; +} + +static void +pango_font_map_list_model_init (GListModelInterface *iface) +{ + iface->get_item_type = pango_font_map_get_item_type; + iface->get_n_items = pango_font_map_get_n_items; + iface->get_item = pango_font_map_get_item; +} + +/* }}} */ +/* {{{ Fontset caching */ + +/* The number of fontsets we keep in the fontset cache */ +#define FONTSET_CACHE_SIZE 256 + +#define FNV1_32_INIT ((guint32)0x811c9dc5) + +static guint +pango_fontset_cached_hash (const PangoFontsetCached *fontset) +{ + guint32 hash = FNV1_32_INIT; + + return (hash ^ + GPOINTER_TO_UINT (fontset->language) ^ + pango_font_description_hash (fontset->description)); +} + +static gboolean +pango_fontset_cached_equal (const PangoFontsetCached *a, + const PangoFontsetCached *b) +{ + return a->language == b->language && + pango_font_description_equal (a->description, b->description); +} + +static void +pango_fontset_cache (PangoFontsetCached *fontset, + PangoFontMap *self) +{ + GQueue *cache = &self->fontset_cache; + GList *link = &fontset->cache_link; + + if (link->data == fontset) + { + /* Already in cache, move to head */ + if (link == cache->head) + return; + + g_queue_unlink (cache, link); + } + else + { + /* Not in cache yet. Make room... */ + if (cache->length == FONTSET_CACHE_SIZE) + { + GList *old = g_queue_pop_tail_link (cache); + g_hash_table_remove (self->fontsets, old->data); + old->data = NULL; + } + } + + link->data = fontset; + link->prev = NULL; + link->next = NULL; + g_queue_push_head_link (cache, link); +} + +/* }}} */ +/* {{{ Utilities */ typedef struct { - guint n_families; -} PangoFontMapPrivate; + PangoFontFamily family; + PangoFontMap *map; + const char *name; +} FamilyKey; + +static guint +pango_family_hash (const FamilyKey *key) +{ + const char *p; + guint32 h = 5381; -G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PangoFontMap, pango_font_map, G_TYPE_OBJECT, - G_ADD_PRIVATE (PangoFontMap) - G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_font_map_list_model_init)) + for (p = (const char *)key->name; *p != '\0'; p++) + h = (h << 5) + h + g_ascii_tolower (*p); + + return h; +} + +static gboolean +pango_family_equal (const FamilyKey *a, + const FamilyKey *b) +{ + return g_ascii_strcasecmp (a->name, b->name) == 0; +} + +static PangoFontFamily * +find_family (PangoFontMap *self, + const char *family_name) +{ + FamilyKey lookup; + PangoFontFamily *family; + + lookup.name = family_name; + + family = PANGO_FONT_FAMILY (g_hash_table_lookup (self->families_hash, &lookup)); + + return family; +} static void -pango_font_map_class_init (PangoFontMapClass *class) +clear_caches (PangoFontMap *self) { - class->load_fontset = pango_font_map_real_load_fontset; - class->get_family = pango_font_map_real_get_family; - class->changed = pango_font_map_real_changed; + g_hash_table_remove_all (self->fontsets); + g_queue_init (&self->fontset_cache); } static void -pango_font_map_init (PangoFontMap *fontmap G_GNUC_UNUSED) +add_style_variation (PangoHbFamily *family, + PangoHbFace *face, + PangoStyle style, + PangoWeight weight) +{ + PangoMatrix italic_matrix = { 1, 0.2, 0, 1, 0, 0 }; + PangoFontDescription *desc; + PangoHbFace *variation; + + desc = pango_font_description_new (); + pango_font_description_set_family (desc, pango_font_family_get_name (PANGO_FONT_FAMILY (family))); + pango_font_description_set_style (desc, style); + pango_font_description_set_weight (desc, weight); + + variation = pango_hb_face_new_synthetic (face, + style == PANGO_STYLE_ITALIC ? &italic_matrix : NULL, + weight == PANGO_WEIGHT_BOLD, + NULL, + desc); + pango_hb_family_add_face (family, PANGO_FONT_FACE (variation)); + + pango_font_description_free (desc); +} + +static void +synthesize_bold_and_italic_faces (PangoFontMap *map) +{ + for (int i = 0; i < map->families->len; i++) + { + PangoFontFamily *family = g_ptr_array_index (map->families, i); + PangoHbFace *regular_face = NULL; + int regular_dist = G_MAXINT; + int bold_dist = G_MAXINT; + gboolean has_italic = FALSE; + gboolean has_bold = FALSE; + gboolean has_bold_italic = FALSE; + + if (PANGO_IS_GENERIC_FAMILY (family)) + continue; + + for (int j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++) + { + PangoHbFace *face = g_list_model_get_item (G_LIST_MODEL (family), j); + int weight; + PangoStyle style; + int dist; + + if (!PANGO_IS_HB_FACE (face)) + continue; + + weight = pango_font_description_get_weight (face->description); + style = pango_font_description_get_style (face->description); + + if (style == PANGO_STYLE_NORMAL) + { + dist = abs (weight - (int)PANGO_WEIGHT_NORMAL); + + if (dist < regular_dist) + { + regular_dist = dist; + if (dist < 150) + regular_face = face; + } + + dist = abs (weight - (int)PANGO_WEIGHT_BOLD); + + if (dist < bold_dist) + { + bold_dist = dist; + has_bold = dist < 150; + } + } + else + { + if (weight < PANGO_WEIGHT_SEMIBOLD) + has_italic = TRUE; + else + has_bold_italic = TRUE; + } + + g_object_unref (face); + } + + if (regular_face) + { + if (!has_italic) + add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_ITALIC, PANGO_WEIGHT_NORMAL); + + if (!has_bold) + add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_NORMAL, PANGO_WEIGHT_BOLD); + + if (!has_bold_italic) + add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_ITALIC, PANGO_WEIGHT_BOLD); + } + } +} + +/* }}} */ +/* {{{ PangoFontMap implementation */ + +G_DEFINE_TYPE_WITH_CODE (PangoFontMap, pango_font_map, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_font_map_list_model_init)) + + +static void +pango_font_map_init (PangoFontMap *self) +{ + self->added_faces = g_ptr_array_new_with_free_func (g_object_unref); + self->added_families = g_ptr_array_new_with_free_func (g_object_unref); + self->families = g_ptr_array_new_with_free_func (g_object_unref); + self->families_hash = g_hash_table_new_full ((GHashFunc) pango_family_hash, + (GEqualFunc) pango_family_equal, + NULL, + NULL); + self->fontsets = g_hash_table_new_full ((GHashFunc) pango_fontset_cached_hash, + (GEqualFunc) pango_fontset_cached_equal, + NULL, + (GDestroyNotify) g_object_unref); + g_queue_init (&self->fontset_cache); + self->dpi = 96.; +} + +static void +pango_font_map_finalize (GObject *object) +{ + PangoFontMap *self = PANGO_FONT_MAP (object); + + g_ptr_array_unref (self->added_faces); + g_ptr_array_unref (self->added_families); + g_hash_table_unref (self->families_hash); + g_ptr_array_unref (self->families); + g_hash_table_unref (self->fontsets); + + G_OBJECT_CLASS (pango_font_map_parent_class)->finalize (object); +} + +/* Load a font from the first matching family */ +static PangoFont * +pango_font_map_default_load_font (PangoFontMap *self, + PangoContext *context, + const PangoFontDescription *description) +{ + PangoFontsetCached *fontset; + PangoLanguage *language; + PangoFont *font = NULL; + + if (self->families->len == 0) + return NULL; + + if (context) + language = pango_context_get_language (context); + else + language = NULL; + + fontset = (PangoFontsetCached *)pango_font_map_load_fontset (self, context, description, language); + if (pango_fontset_cached_size (fontset) > 0) + font = pango_fontset_cached_get_first_font (fontset); + g_object_unref (fontset); + + return font; +} + +/* Add one font for each family we find */ +static PangoFontset * +pango_font_map_default_load_fontset (PangoFontMap *self, + PangoContext *context, + const PangoFontDescription *description, + PangoLanguage *language) +{ + PangoFontsetCached lookup; + PangoFontsetCached *fontset; + const PangoMatrix *matrix; + const char *family_name; + char **families; + PangoFontDescription *copy; + PangoFontFamily *family; + PangoFontFace *face; + gboolean has_generic = FALSE; + gint64 before G_GNUC_UNUSED; + + before = PANGO_TRACE_CURRENT_TIME; + + if (!language) + language = pango_context_get_language (context); + + family_name = pango_font_description_get_family (description); + + lookup.language = language; + lookup.description = (PangoFontDescription *)description; + fontset = g_hash_table_lookup (self->fontsets, &lookup); + + if (fontset) + goto done; + + matrix = pango_context_get_matrix (context); + + fontset = pango_fontset_cached_new (description, language, self->dpi, matrix); + + if (self->families->len == 0) + { + g_warning ("Font map contains no fonts!!!!"); + goto done_no_cache; + } + + families = g_strsplit (family_name ? family_name : "", ",", -1); + + /* Unset gravity and variant since PangoHbFace does not have these fields */ + copy = pango_font_description_copy_static (description); + pango_font_description_unset_fields (copy, PANGO_FONT_MASK_VARIATIONS | + PANGO_FONT_MASK_GRAVITY | + PANGO_FONT_MASK_VARIANT); + + for (int i = 0; families[i]; i++) + { + family = find_family (self, families[i]); + if (!family) + continue; + + if (PANGO_IS_GENERIC_FAMILY (family)) + { + pango_fontset_cached_add_family (fontset, PANGO_GENERIC_FAMILY (family)); + has_generic = TRUE; + } + else + { + face = pango_hb_family_find_face (PANGO_HB_FAMILY (family), copy, language, 0); + if (face) + pango_fontset_cached_add_face (fontset, face); + } + } + + g_strfreev (families); + + /* Returning an empty fontset leads to bad outcomes. + * + * We always include a generic family in order + * to produce fontsets with good coverage. + */ + if (!has_generic) + { + family = find_family (self, "sans-serif"); + if (PANGO_IS_GENERIC_FAMILY (family)) + pango_fontset_cached_add_family (fontset, PANGO_GENERIC_FAMILY (family)); + } + + pango_font_description_free (copy); + + g_hash_table_add (self->fontsets, fontset); + +done: + pango_fontset_cache (fontset, self); + + if (pango_fontset_cached_size (fontset) == 0) + { + char *s = pango_font_description_to_string (description); + g_warning ("All font fallbacks failed for \"%s\", in %s !!!!", s, pango_language_to_string (language)); + g_free (s); + } + +done_no_cache: + pango_trace_mark (before, "pango_hb_fontmap_load_fontset", "%s", family_name); + + return g_object_ref (PANGO_FONTSET (fontset)); +} + +static PangoFontFamily * +pango_font_map_default_get_family (PangoFontMap *self, + const char *name) +{ + return PANGO_FONT_FAMILY (find_family (self, name)); +} + +static void +pango_font_map_default_populate (PangoFontMap *self) +{ +} + +static guint +pango_font_map_default_get_serial (PangoFontMap *self) +{ + return self->serial; +} + +static void +pango_font_map_default_changed (PangoFontMap *self) +{ + self->serial++; + if (self->serial == 0) + self->serial++; +} + +static void +pango_font_map_class_init (PangoFontMapClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->finalize = pango_font_map_finalize; + + class->load_font = pango_font_map_default_load_font; + class->load_fontset = pango_font_map_default_load_fontset; + class->get_serial = pango_font_map_default_get_serial; + class->changed = pango_font_map_default_changed; + class->get_family = pango_font_map_default_get_family; + class->populate = pango_font_map_default_populate; +} + +/* }}} */ +/* {{{ Private API */ + +/*< private > + * pango_font_map_repopulate: + * @self: a `PangoFontMap` + * @add_synthetic: if `TRUE`, missing bold and italic faces will be synthesized + * + * Clear all cached information and repopulate the fontmap with + * families and faces. + * + * Subclasses should call this when their configuration changes + * in a way that requires recreating families and faces. + */ +void +pango_font_map_repopulate (PangoFontMap *self, + gboolean add_synthetic) { + int removed, added; + + clear_caches (self); + + removed = self->families->len; + + g_hash_table_remove_all (self->families_hash); + g_ptr_array_set_size (self->families, 0); + + self->in_populate = TRUE; + + PANGO_FONT_MAP_GET_CLASS (self)->populate (self); + + if (add_synthetic) + synthesize_bold_and_italic_faces (self); + + for (int i = 0; i < self->added_faces->len; i++) + { + PangoFontFace *face = g_ptr_array_index (self->added_faces, i); + pango_font_map_add_face (self, face); + } + + for (int i = 0; i < self->added_families->len; i++) + { + PangoFontFamily *family = PANGO_FONT_FAMILY (g_ptr_array_index (self->added_families, i)); + pango_font_map_add_family (self, family); + } + + self->in_populate = FALSE; + + added = self->families->len; + + g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added); + pango_font_map_changed (self); } +/*< private > + * pango_font_map_changed: + * @self: a `PangoFontMap` + * + * Forces a change in the context, which will cause any `PangoContext` + * using this fontmap to change. + * + * This function is only useful when implementing a new backend + * for Pango, something applications won't do. Backends should + * call this function if they have attached extra data to the + * context and such data is changed. + */ +void +pango_font_map_changed (PangoFontMap *self) +{ + g_return_if_fail (PANGO_IS_FONT_MAP (self)); + + PANGO_FONT_MAP_GET_CLASS (self)->changed (self); +} + +/* }}} */ +/* {{{ Public API */ + /** * pango_font_map_create_context: - * @fontmap: a `PangoFontMap` + * @self: a `PangoFontMap` * * Creates a `PangoContext` connected to @fontmap. * @@ -80,21 +629,22 @@ pango_font_map_init (PangoFontMap *fontmap G_GNUC_UNUSED) * which should be freed with g_object_unref(). */ PangoContext * -pango_font_map_create_context (PangoFontMap *fontmap) +pango_font_map_create_context (PangoFontMap *self) { PangoContext *context; - g_return_val_if_fail (fontmap != NULL, NULL); + g_return_val_if_fail (PANGO_IS_FONT_MAP (self), NULL); context = pango_context_new (); - pango_context_set_font_map (context, fontmap); + pango_context_set_font_map (context, self); return context; } + /** * pango_font_map_load_font: - * @fontmap: a `PangoFontMap` + * @self: a `PangoFontMap` * @context: the `PangoContext` the font will be used with * @desc: a `PangoFontDescription` describing the font to load * @@ -104,18 +654,18 @@ pango_font_map_create_context (PangoFontMap *fontmap) * loaded, or %NULL if no font matched. */ PangoFont * -pango_font_map_load_font (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc) +pango_font_map_load_font (PangoFontMap *self, + PangoContext *context, + const PangoFontDescription *desc) { - g_return_val_if_fail (fontmap != NULL, NULL); + g_return_val_if_fail (PANGO_IS_FONT_MAP (self), NULL); - return PANGO_FONT_MAP_GET_CLASS (fontmap)->load_font (fontmap, context, desc); + return PANGO_FONT_MAP_GET_CLASS (self)->load_font (self, context, desc); } /** * pango_font_map_load_fontset: - * @fontmap: a `PangoFontMap` + * @self: a `PangoFontMap` * @context: the `PangoContext` the font will be used with * @desc: a `PangoFontDescription` describing the font to load * @language: a `PangoLanguage` the fonts will be used for @@ -127,145 +677,21 @@ pango_font_map_load_font (PangoFontMap *fontmap, * `PangoFontset` loaded, or %NULL if no font matched. */ PangoFontset * -pango_font_map_load_fontset (PangoFontMap *fontmap, +pango_font_map_load_fontset (PangoFontMap *self, PangoContext *context, const PangoFontDescription *desc, PangoLanguage *language) { - g_return_val_if_fail (fontmap != NULL, NULL); + g_return_val_if_fail (PANGO_IS_FONT_MAP (self), NULL); - return PANGO_FONT_MAP_GET_CLASS (fontmap)->load_fontset (fontmap, context, desc, language); -} - -static void -pango_font_map_fontset_add_fonts (PangoFontMap *fontmap, - PangoContext *context, - PangoFontsetSimple *fonts, - PangoFontDescription *desc, - const char *family) -{ - PangoFont *font; - - pango_font_description_set_family_static (desc, family); - font = pango_font_map_load_font (fontmap, context, desc); - if (font) - pango_fontset_simple_append (fonts, font); -} - -static PangoFontset * -pango_font_map_real_load_fontset (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc, - PangoLanguage *language) -{ - PangoFontDescription *tmp_desc = pango_font_description_copy_static (desc); - const char *family; - char **families; - int i; - PangoFontsetSimple *fonts; - static GHashTable *warned_fonts = NULL; /* MT-safe */ - G_LOCK_DEFINE_STATIC (warned_fonts); - - family = pango_font_description_get_family (desc); - families = g_strsplit (family ? family : "", ",", -1); - - fonts = pango_fontset_simple_new (language); - - for (i = 0; families[i]; i++) - pango_font_map_fontset_add_fonts (fontmap, - context, - fonts, - tmp_desc, - families[i]); - - g_strfreev (families); - - /* The font description was completely unloadable, try with - * family == "Sans" - */ - if (pango_fontset_simple_size (fonts) == 0) - { - char *ctmp1, *ctmp2; - - pango_font_description_set_family_static (tmp_desc, - pango_font_description_get_family (desc)); - - ctmp1 = pango_font_description_to_string (desc); - pango_font_description_set_family_static (tmp_desc, "Sans"); - - G_LOCK (warned_fonts); - if (!warned_fonts || !g_hash_table_lookup (warned_fonts, ctmp1)) - { - if (!warned_fonts) - warned_fonts = g_hash_table_new (g_str_hash, g_str_equal); - - g_hash_table_insert (warned_fonts, g_strdup (ctmp1), GINT_TO_POINTER (1)); - - ctmp2 = pango_font_description_to_string (tmp_desc); - g_warning ("couldn't load font \"%s\", falling back to \"%s\", " - "expect ugly output.", ctmp1, ctmp2); - g_free (ctmp2); - } - G_UNLOCK (warned_fonts); - g_free (ctmp1); - - pango_font_map_fontset_add_fonts (fontmap, - context, - fonts, - tmp_desc, - "Sans"); - } - - /* We couldn't try with Sans and the specified style. Try Sans Normal - */ - if (pango_fontset_simple_size (fonts) == 0) - { - char *ctmp1, *ctmp2; - - pango_font_description_set_family_static (tmp_desc, "Sans"); - ctmp1 = pango_font_description_to_string (tmp_desc); - pango_font_description_set_style (tmp_desc, PANGO_STYLE_NORMAL); - pango_font_description_set_weight (tmp_desc, PANGO_WEIGHT_NORMAL); - pango_font_description_set_variant (tmp_desc, PANGO_VARIANT_NORMAL); - pango_font_description_set_stretch (tmp_desc, PANGO_STRETCH_NORMAL); - - G_LOCK (warned_fonts); - if (!warned_fonts || !g_hash_table_lookup (warned_fonts, ctmp1)) - { - g_hash_table_insert (warned_fonts, g_strdup (ctmp1), GINT_TO_POINTER (1)); - - ctmp2 = pango_font_description_to_string (tmp_desc); - - g_warning ("couldn't load font \"%s\", falling back to \"%s\", " - "expect ugly output.", ctmp1, ctmp2); - g_free (ctmp2); - } - G_UNLOCK (warned_fonts); - g_free (ctmp1); - - pango_font_map_fontset_add_fonts (fontmap, - context, - fonts, - tmp_desc, - "Sans"); - } - - pango_font_description_free (tmp_desc); - - /* Everything failed, we are screwed, there is no way to continue, - * but lets just not crash here. - */ - if (pango_fontset_simple_size (fonts) == 0) - g_warning ("All font fallbacks failed!!!!"); - - return PANGO_FONTSET (fonts); + return PANGO_FONT_MAP_GET_CLASS (self)->load_fontset (self, context, desc, language); } /** * pango_font_map_get_serial: - * @fontmap: a `PangoFontMap` + * @self: a `PangoFontMap` * - * Returns the current serial number of @fontmap. + * Returns the current serial number of @self. * * The serial number is initialized to an small number larger than zero * when a new fontmap is created and is increased whenever the fontmap @@ -281,115 +707,254 @@ pango_font_map_real_load_fontset (PangoFontMap *fontmap, * Return value: The current serial number of @fontmap. */ guint -pango_font_map_get_serial (PangoFontMap *fontmap) +pango_font_map_get_serial (PangoFontMap *self) { - g_return_val_if_fail (PANGO_IS_FONT_MAP (fontmap), 0); + g_return_val_if_fail (PANGO_IS_FONT_MAP (self), 0); - if (PANGO_FONT_MAP_GET_CLASS (fontmap)->get_serial) - return PANGO_FONT_MAP_GET_CLASS (fontmap)->get_serial (fontmap); - else - return 1; + return PANGO_FONT_MAP_GET_CLASS (self)->get_serial (self); } -static void -pango_font_map_real_changed (PangoFontMap *fontmap) +/** + * pango_font_map_get_family: + * @self: a `PangoFontMap` + * @name: a family name + * + * Gets a font family by name. + * + * Returns: (transfer none): the `PangoFontFamily` + */ +PangoFontFamily * +pango_font_map_get_family (PangoFontMap *self, + const char *name) { - PangoFontMapPrivate *priv = pango_font_map_get_instance_private (fontmap); - guint removed, added; + g_return_val_if_fail (PANGO_IS_FONT_MAP (self), NULL); - removed = priv->n_families; - added = g_list_model_get_n_items (G_LIST_MODEL (fontmap)); + return PANGO_FONT_MAP_GET_CLASS (self)->get_family (self, name); +} - g_list_model_items_changed (G_LIST_MODEL (fontmap), 0, removed, added); +/** + * pango_font_map_new: + * + * Creates a new `PangoFontMap`. + * + * Returns: A newly created `PangoFontMap + */ +PangoFontMap * +pango_font_map_new (void) +{ + return g_object_new (PANGO_TYPE_FONT_MAP, NULL); } /** - * pango_font_map_changed: - * @fontmap: a `PangoFontMap` + * pango_font_map_add_face: + * @self: a `PangoFontMap` + * @face: (transfer full): a `PangoFontFace` * - * Forces a change in the context, which will cause any `PangoContext` - * using this fontmap to change. + * Adds @face to the `PangoFontMap`. * - * This function is only useful when implementing a new backend - * for Pango, something applications won't do. Backends should - * call this function if they have attached extra data to the - * context and such data is changed. + * This is most useful for creating transformed faces or aliases. + * See [ctor@Pango.HbFace.new_synthetic] and [ctor@Pango.HbFace.new_instance]. */ void -pango_font_map_changed (PangoFontMap *fontmap) +pango_font_map_add_face (PangoFontMap *self, + PangoFontFace *face) { - g_return_if_fail (PANGO_IS_FONT_MAP (fontmap)); + const char *family_name; + PangoHbFamily *family; + const PangoFontDescription *description; - if (PANGO_FONT_MAP_GET_CLASS (fontmap)->changed) - PANGO_FONT_MAP_GET_CLASS (fontmap)->changed (fontmap); -} + g_return_if_fail (PANGO_IS_FONT_MAP (self)); + g_return_if_fail (PANGO_IS_HB_FACE (face) || PANGO_IS_USER_FACE (face)); -static PangoFontFamily * -pango_font_map_real_get_family (PangoFontMap *fontmap, - const char *name) -{ - PangoFontFamily *family; - int i; + description = ((CommonFace *)face)->description; + + if (pango_font_description_get_set_fields (description) & + (PANGO_FONT_MASK_VARIANT | PANGO_FONT_MASK_GRAVITY)) + g_warning ("Font description for PangoFontFace includes things that it shouldn't"); - family = NULL; + if (!self->in_populate) + g_ptr_array_add (self->added_faces, g_object_ref (face)); - for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (fontmap)); i++) + family_name = pango_font_description_get_family (description); + family = PANGO_HB_FAMILY (pango_font_map_get_family (self, family_name)); + if (!family) { - PangoFontFamily *fam = g_list_model_get_item (G_LIST_MODEL (fontmap), i); - g_object_unref (fam); - if (strcmp (name, pango_font_family_get_name (fam)) == 0) - { - family = fam; - break; - } + family = pango_hb_family_new (family_name); + pango_font_map_add_family (self, PANGO_FONT_FAMILY (family)); } - return family; + pango_hb_family_add_face (family, face); + + pango_font_map_changed (self); + + clear_caches (self); } /** - * pango_font_map_get_family: - * @fontmap: a `PangoFontMap` - * @name: a family name + * pango_font_map_remove_face: + * @self: a `PangoFontMap` + * @face: a `PangoFontFace` that belongs to @map * - * Gets a font family by name. + * Removes @face from the `PangoFontMap`. * - * Returns: (transfer none): the `PangoFontFamily` + * @face must have been added with [method@Pango.FontMap.add_face]. */ -PangoFontFamily * -pango_font_map_get_family (PangoFontMap *fontmap, - const char *name) +void +pango_font_map_remove_face (PangoFontMap *self, + PangoFontFace *face) { - g_return_val_if_fail (PANGO_IS_FONT_MAP (fontmap), NULL); + PangoHbFamily *family; + unsigned int position; + + g_return_if_fail (PANGO_IS_FONT_MAP (self)); + g_return_if_fail (PANGO_IS_HB_FACE (face) || PANGO_IS_USER_FACE (face)); + + if (!g_ptr_array_find (self->added_faces, face, &position)) + return; + + family = PANGO_HB_FAMILY (pango_font_face_get_family (face)); + + pango_hb_family_remove_face (family, face); + + if (family->faces->len == 0) + pango_font_map_remove_family (self, PANGO_FONT_FAMILY (family)); + + pango_font_map_changed (self); - return PANGO_FONT_MAP_GET_CLASS (fontmap)->get_family (fontmap, name); + clear_caches (self); + + g_ptr_array_remove_index (self->added_faces, position); } -static GType -pango_font_map_get_item_type (GListModel *list) +/** + * pango_font_map_add_file: + * @self: a `PangoFontMap` + * @file: font filename + * + * Creates a new `PangoHbFace` and adds it. + * + * If you need to specify an instance id or other + * parameters, use [ctor@Pango.HbFace.new_from_file]. + */ +void +pango_font_map_add_file (PangoFontMap *self, + const char *file) { - return PANGO_TYPE_FONT_FAMILY; + PangoHbFace *face; + + face = pango_hb_face_new_from_file (file, 0, -1, NULL, NULL); + pango_font_map_add_face (self, PANGO_FONT_FACE (face)); } -static guint -pango_font_map_get_n_items (GListModel *list) +/** + * pango_font_map_add_family: + * @self: a `PangoFontMap` + * @family: (transfer full): a `PangoFontFamily` + * + * Adds @family to @self. + * + * The fontmap must not contain a family with the + * same name as @family yet. + * + * This is mostly useful for adding generic families + * using [ctor@Pango.GenericFamily.new]. + */ +void +pango_font_map_add_family (PangoFontMap *self, + PangoFontFamily *family) { - g_assert_not_reached (); - return 0; + const char *name; + int position; + + g_return_if_fail (PANGO_IS_FONT_MAP (self)); + g_return_if_fail (PANGO_IS_HB_FAMILY (family) || PANGO_IS_GENERIC_FAMILY (family)); + g_return_if_fail (((CommonFamily *)family)->map == NULL); + + if (!self->in_populate) + g_ptr_array_add (self->added_families, g_object_ref (family)); + + name = ((CommonFamily *)family)->name; + + position = 0; + while (position < self->families->len) + { + PangoFontFamily *f = g_ptr_array_index (self->families, position); + if (g_ascii_strcasecmp (name, ((CommonFamily *)f)->name) < 0) + break; + position++; + } + + ((CommonFamily *)family)->map = self; + g_object_add_weak_pointer (G_OBJECT (self), (gpointer *)&((CommonFamily *)family)->map); + + g_ptr_array_insert (self->families, position, family); + g_hash_table_add (self->families_hash, family); + + if (!self->in_populate) + g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1); + + pango_font_map_changed (self); } -static gpointer -pango_font_map_get_item (GListModel *list, - guint position) +/** + * pango_font_map_remove_family: + * @self: a `PangoFontMap` + * @family: a `PangoFontFamily` that belongs to @self + * + * Removes a `PangoHbFamily` from a `PangoFontMap` + */ +void +pango_font_map_remove_family (PangoFontMap *self, + PangoFontFamily *family) { - g_assert_not_reached (); - return NULL; + unsigned int position; + + g_return_if_fail (PANGO_IS_FONT_MAP (self)); + g_return_if_fail (PANGO_IS_HB_FAMILY (family) || PANGO_IS_GENERIC_FAMILY (family)); + g_return_if_fail (((CommonFamily *)family)->map == self); + + if (!g_ptr_array_find (self->added_families, family, &position)) + return; + + g_hash_table_remove (self->families_hash, family); + g_ptr_array_remove_index (self->families, position); + + g_object_remove_weak_pointer (G_OBJECT (self), (gpointer *)&((CommonFamily *)family)->map); + ((CommonFamily *)family)->map = NULL; + + if (!self->in_populate) + g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0); + + pango_font_map_changed (self); + + g_ptr_array_remove_index (self->added_families, position); } -static void -pango_font_map_list_model_init (GListModelInterface *iface) +/** + * pango_font_map_set_resolution: + * @self: a `PangoFontMap` + * @dpi: the new resolution, in "dots per inch" + * + * Sets the resolution for the fontmap. + * + * This is a scale factor between points specified in a + * `PangoFontDescription` and Cairo units. The default value + * is 96, meaning that a 10 point font will be 13 units high. + * (10 * 96. / 72. = 13.3). + */ +void +pango_font_map_set_resolution (PangoFontMap *self, + double dpi) { - iface->get_item_type = pango_font_map_get_item_type; - iface->get_n_items = pango_font_map_get_n_items; - iface->get_item = pango_font_map_get_item; + g_return_if_fail (PANGO_IS_FONT_MAP (self)); + g_return_if_fail (dpi > 0); + + self->dpi = dpi; + + clear_caches (self); + pango_font_map_changed (self); } + +/* }}} */ + +/* vim:set foldmethod=marker expandtab: */ diff --git a/pango/pango-fontmap.h b/pango/pango-fontmap.h index d4e0a0b6..6b40cd13 100644 --- a/pango/pango-fontmap.h +++ b/pango/pango-fontmap.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000 Red Hat Software + * Copyright (C) 2021 Matthias Clasen * * SPDX-License-Identifier: LGPL-2.1-or-later * @@ -20,35 +20,58 @@ #pragma once #include <pango/pango-types.h> -#include <pango/pango-font.h> #include <pango/pango-fontset.h> +#include <pango/pango-hbface.h> G_BEGIN_DECLS -#define PANGO_TYPE_FONT_MAP (pango_font_map_get_type ()) +#define PANGO_TYPE_FONT_MAP (pango_font_map_get_type ()) PANGO_AVAILABLE_IN_ALL PANGO_DECLARE_INTERNAL_TYPE (PangoFontMap, pango_font_map, PANGO, FONT_MAP, GObject) PANGO_AVAILABLE_IN_ALL -PangoContext * pango_font_map_create_context (PangoFontMap *fontmap); +PangoContext * pango_font_map_create_context (PangoFontMap *self); PANGO_AVAILABLE_IN_ALL -PangoFont * pango_font_map_load_font (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc); +PangoFont * pango_font_map_load_font (PangoFontMap *self, + PangoContext *context, + const PangoFontDescription *desc); PANGO_AVAILABLE_IN_ALL -PangoFontset *pango_font_map_load_fontset (PangoFontMap *fontmap, - PangoContext *context, - const PangoFontDescription *desc, - PangoLanguage *language); +PangoFontset * pango_font_map_load_fontset (PangoFontMap *self, + PangoContext *context, + const PangoFontDescription *desc, + PangoLanguage *language); PANGO_AVAILABLE_IN_ALL -guint pango_font_map_get_serial (PangoFontMap *fontmap); +guint pango_font_map_get_serial (PangoFontMap *self); + +PANGO_AVAILABLE_IN_ALL +PangoFontFamily * pango_font_map_get_family (PangoFontMap *self, + const char *name); + PANGO_AVAILABLE_IN_ALL -void pango_font_map_changed (PangoFontMap *fontmap); +PangoFontMap * pango_font_map_new (void); PANGO_AVAILABLE_IN_ALL -PangoFontFamily *pango_font_map_get_family (PangoFontMap *fontmap, - const char *name); +void pango_font_map_add_file (PangoFontMap *self, + const char *file); +PANGO_AVAILABLE_IN_ALL +void pango_font_map_add_face (PangoFontMap *self, + PangoFontFace *face); + +PANGO_AVAILABLE_IN_ALL +void pango_font_map_remove_face (PangoFontMap *self, + PangoFontFace *face); + +PANGO_AVAILABLE_IN_ALL +void pango_font_map_add_family (PangoFontMap *self, + PangoFontFamily *family); +PANGO_AVAILABLE_IN_ALL +void pango_font_map_remove_family (PangoFontMap *self, + PangoFontFamily *family); + +PANGO_AVAILABLE_IN_ALL +void pango_font_map_set_resolution (PangoFontMap *self, + double dpi); G_END_DECLS diff --git a/pango/pango-fontset-simple-private.h b/pango/pango-fontset-simple-private.h index cf88100c..bae1ff75 100644 --- a/pango/pango-fontset-simple-private.h +++ b/pango/pango-fontset-simple-private.h @@ -19,10 +19,14 @@ #pragma once +#include <pango/pango-types.h> #include <pango/pango-fontset-private.h> -#include <pango/pango-fontset-simple.h> +#include <glib-object.h> +typedef struct _PangoFontsetSimple PangoFontsetSimple; +typedef struct _PangoFontsetSimpleClass PangoFontsetSimpleClass; + struct _PangoFontsetSimple { PangoFontset parent_instance; @@ -31,9 +35,19 @@ struct _PangoFontsetSimple PangoLanguage *language; }; -typedef struct _PangoFontsetSimpleClass PangoFontsetSimpleClass; - struct _PangoFontsetSimpleClass { PangoFontsetClass parent_class; }; + + +#define PANGO_TYPE_FONTSET_SIMPLE (pango_fontset_simple_get_type ()) +#define PANGO_FONTSET_SIMPLE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_FONTSET_SIMPLE, PangoFontsetSimple)) +#define PANGO_IS_FONTSET_SIMPLE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_FONTSET_SIMPLE)) + +GType pango_fontset_simple_get_type (void) G_GNUC_CONST; + +PangoFontsetSimple * pango_fontset_simple_new (PangoLanguage *language); +void pango_fontset_simple_append (PangoFontsetSimple *fontset, + PangoFont *font); +int pango_fontset_simple_size (PangoFontsetSimple *fontset); diff --git a/pango/pango-fontset-simple.h b/pango/pango-fontset-simple.h deleted file mode 100644 index 9548d587..00000000 --- a/pango/pango-fontset-simple.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2001 Red Hat Software - * - * SPDX-License-Identifier: LGPL-2.1-or-later - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <pango/pango-types.h> -#include <pango/pango-fontset.h> - -#include <glib-object.h> - -G_BEGIN_DECLS - -/** - * PangoFontsetSimple: - * - * `PangoFontsetSimple` is a implementation of the abstract - * `PangoFontset` base class as an array of fonts. - * - * When creating a `PangoFontsetSimple`, you have to provide - * the array of fonts that make up the fontset. - */ -#define PANGO_TYPE_FONTSET_SIMPLE (pango_fontset_simple_get_type ()) -#define PANGO_FONTSET_SIMPLE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_FONTSET_SIMPLE, PangoFontsetSimple)) -#define PANGO_IS_FONTSET_SIMPLE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_FONTSET_SIMPLE)) - -typedef struct _PangoFontsetSimple PangoFontsetSimple; - -PANGO_AVAILABLE_IN_ALL -GType pango_fontset_simple_get_type (void) G_GNUC_CONST; - -PANGO_AVAILABLE_IN_ALL -PangoFontsetSimple * pango_fontset_simple_new (PangoLanguage *language); -PANGO_AVAILABLE_IN_ALL -void pango_fontset_simple_append (PangoFontsetSimple *fontset, - PangoFont *font); -PANGO_AVAILABLE_IN_ALL -int pango_fontset_simple_size (PangoFontsetSimple *fontset); - - -G_END_DECLS diff --git a/pango/pango-hbfontmap-private.h b/pango/pango-hbfontmap-private.h deleted file mode 100644 index 6614a147..00000000 --- a/pango/pango-hbfontmap-private.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2021 Red Hat, Inc. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <pango/pango-hbfontmap.h> -#include <pango/pango-hbfamily-private.h> -#include <pango/pango-fontmap-private.h> - - -struct _PangoHbFontMap -{ - PangoFontMap parent_instance; - - GPtrArray *added_faces; - GPtrArray *added_families; - GHashTable *families_hash; - GPtrArray *families; - GHashTable *fontsets; - GQueue fontset_cache; - - double dpi; - gboolean in_populate; - guint serial; -}; - -/** - * PangoHbFontMapClass: - * @populate: Subclasses should call pango_hb_font_map_add_face to populate - * the map with faces and families in this vfunc. - */ -struct _PangoHbFontMapClass -{ - PangoFontMapClass parent_class; - - void (* populate) (PangoHbFontMap *self); - - gpointer reserved[10]; -}; - -void pango_hb_font_map_repopulate (PangoHbFontMap *self, - gboolean add_synthetic); diff --git a/pango/pango-hbfontmap.c b/pango/pango-hbfontmap.c deleted file mode 100644 index eef10b68..00000000 --- a/pango/pango-hbfontmap.c +++ /dev/null @@ -1,810 +0,0 @@ -/* Pango - * - * Copyright (C) 2021 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 <math.h> - -#include <gio/gio.h> - -#include "pango-hbfontmap-private.h" -#include "pango-hbfamily-private.h" -#include "pango-generic-family-private.h" -#include "pango-hbface-private.h" -#include "pango-hbfont-private.h" -#include "pango-fontset-cached-private.h" -#include "pango-userface-private.h" -#include "pango-userfont-private.h" -#include "pango-fontset.h" -#include "pango-font-face-private.h" -#include "pango-trace-private.h" -#include "pango-context.h" - -#include <hb-ot.h> - - -/** - * PangoHbFontMap: - * - * `PangoHbFontMap` is a `PangoFontMap` subclass for use with - * `PangoHbFace` and `PangoHbFont`. It handles caching and - * lookup of faces and fonts. - * - * Subclasses populate the fontmap using backend-specific APIs - * to enumerate the available fonts on the sytem, but it is - * also possible to create an instance of `PangoHbFontMap` and - * populate it manually using [method@Pango.HbFontMap.add_file] - * and [method@Pango.HbFontMap.add_face]. - * - * Note that to be fully functional, a fontmap needs to provide - * generic families for monospace and sans-serif. These can - * be added using [method@Pango.HbFontMap.add_family] and - * [ctor@Pango.GenericFamily.new]. - */ - - -/* The central api is load_fontset, which takes a font description - * and language, finds the matching faces, and creates a PangoFontset - * for them. To speed this operation up, the font map maintains a - * cache of fontsets (in the form of a GQueue) and has a hash table - * for looking up existing fontsets. - * - * The PangoFontsetCached object is the fontset subclass that is used - * here, and it contains the necessary data for the cashing and hashing. - * PangoFontsetCached also caches the character-to-font mapping that is - * used when itemizing text. - */ - -/* The number of fontsets we keep in the fontset cache */ - - -/* {{{ GListModel implementation */ - -static GType -pango_hb_font_map_get_item_type (GListModel *list) -{ - return PANGO_TYPE_FONT_FAMILY; -} - -static guint -pango_hb_font_map_get_n_items (GListModel *list) -{ - PangoHbFontMap *self = PANGO_HB_FONT_MAP (list); - - return self->families->len; -} - -static gpointer -pango_hb_font_map_get_item (GListModel *list, - guint position) -{ - PangoHbFontMap *self = PANGO_HB_FONT_MAP (list); - - if (position < self->families->len) - return g_object_ref (g_ptr_array_index (self->families, position)); - - return NULL; -} - -static void -pango_hb_font_map_list_model_init (GListModelInterface *iface) -{ - iface->get_item_type = pango_hb_font_map_get_item_type; - iface->get_n_items = pango_hb_font_map_get_n_items; - iface->get_item = pango_hb_font_map_get_item; -} - -/* }}} */ -/* {{{ Fontset caching */ - -#define FONTSET_CACHE_SIZE 256 -#define FNV1_32_INIT ((guint32)0x811c9dc5) - -static guint -pango_fontset_cached_hash (const PangoFontsetCached *fontset) -{ - guint32 hash = FNV1_32_INIT; - - return (hash ^ - GPOINTER_TO_UINT (fontset->language) ^ - pango_font_description_hash (fontset->description)); -} - -static gboolean -pango_fontset_cached_equal (const PangoFontsetCached *a, - const PangoFontsetCached *b) -{ - return a->language == b->language && - pango_font_description_equal (a->description, b->description); -} - -static void -pango_fontset_cache (PangoFontsetCached *fontset, - PangoHbFontMap *self) -{ - GQueue *cache = &self->fontset_cache; - GList *link = &fontset->cache_link; - - if (link->data == fontset) - { - /* Already in cache, move to head */ - if (link == cache->head) - return; - - g_queue_unlink (cache, link); - } - else - { - /* Not in cache yet. Make room... */ - if (cache->length == FONTSET_CACHE_SIZE) - { - GList *old = g_queue_pop_tail_link (cache); - g_hash_table_remove (self->fontsets, old->data); - old->data = NULL; - } - } - - link->data = fontset; - link->prev = NULL; - link->next = NULL; - g_queue_push_head_link (cache, link); -} - -/* }}} */ -/* {{{ Utilities */ - -typedef struct { - PangoFontFamily family; - PangoFontMap *map; - const char *name; -} FamilyKey; - -static guint -pango_family_hash (const FamilyKey *key) -{ - const char *p; - guint32 h = 5381; - - for (p = (const char *)key->name; *p != '\0'; p++) - h = (h << 5) + h + g_ascii_tolower (*p); - - return h; -} - -static gboolean -pango_family_equal (const FamilyKey *a, - const FamilyKey *b) -{ - return g_ascii_strcasecmp (a->name, b->name) == 0; -} - -static PangoFontFamily * -find_family (PangoHbFontMap *self, - const char *family_name) -{ - FamilyKey lookup; - PangoFontFamily *family; - - lookup.name = family_name; - - family = PANGO_FONT_FAMILY (g_hash_table_lookup (self->families_hash, &lookup)); - - return family; -} - -static void -clear_caches (PangoHbFontMap *self) -{ - g_hash_table_remove_all (self->fontsets); - g_queue_init (&self->fontset_cache); -} - -static void -add_style_variation (PangoHbFamily *family, - PangoHbFace *face, - PangoStyle style, - PangoWeight weight) -{ - PangoMatrix italic_matrix = { 1, 0.2, 0, 1, 0, 0 }; - PangoFontDescription *desc; - PangoHbFace *variation; - - desc = pango_font_description_new (); - pango_font_description_set_family (desc, pango_font_family_get_name (PANGO_FONT_FAMILY (family))); - pango_font_description_set_style (desc, style); - pango_font_description_set_weight (desc, weight); - - variation = pango_hb_face_new_synthetic (face, - style == PANGO_STYLE_ITALIC ? &italic_matrix : NULL, - weight == PANGO_WEIGHT_BOLD, - NULL, - desc); - pango_hb_family_add_face (family, PANGO_FONT_FACE (variation)); - - pango_font_description_free (desc); -} - -static void -synthesize_bold_and_italic_faces (PangoHbFontMap *map) -{ - for (int i = 0; i < map->families->len; i++) - { - PangoFontFamily *family = g_ptr_array_index (map->families, i); - PangoHbFace *regular_face = NULL; - int regular_dist = G_MAXINT; - int bold_dist = G_MAXINT; - gboolean has_italic = FALSE; - gboolean has_bold = FALSE; - gboolean has_bold_italic = FALSE; - - if (PANGO_IS_GENERIC_FAMILY (family)) - continue; - - for (int j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++) - { - PangoHbFace *face = g_list_model_get_item (G_LIST_MODEL (family), j); - int weight; - PangoStyle style; - int dist; - - if (!PANGO_IS_HB_FACE (face)) - continue; - - weight = pango_font_description_get_weight (face->description); - style = pango_font_description_get_style (face->description); - - if (style == PANGO_STYLE_NORMAL) - { - dist = abs (weight - (int)PANGO_WEIGHT_NORMAL); - - if (dist < regular_dist) - { - regular_dist = dist; - if (dist < 150) - regular_face = face; - } - - dist = abs (weight - (int)PANGO_WEIGHT_BOLD); - - if (dist < bold_dist) - { - bold_dist = dist; - has_bold = dist < 150; - } - } - else - { - if (weight < PANGO_WEIGHT_SEMIBOLD) - has_italic = TRUE; - else - has_bold_italic = TRUE; - } - - g_object_unref (face); - } - - if (regular_face) - { - if (!has_italic) - add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_ITALIC, PANGO_WEIGHT_NORMAL); - - if (!has_bold) - add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_NORMAL, PANGO_WEIGHT_BOLD); - - if (!has_bold_italic) - add_style_variation (PANGO_HB_FAMILY (family), regular_face, PANGO_STYLE_ITALIC, PANGO_WEIGHT_BOLD); - } - } -} - -/* }}} */ -/* {{{ PangoFontMap implementation */ - -G_DEFINE_TYPE_WITH_CODE (PangoHbFontMap, pango_hb_font_map, PANGO_TYPE_FONT_MAP, - G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_hb_font_map_list_model_init)) - - -static void -pango_hb_font_map_init (PangoHbFontMap *self) -{ - self->added_faces = g_ptr_array_new_with_free_func (g_object_unref); - self->added_families = g_ptr_array_new_with_free_func (g_object_unref); - self->families = g_ptr_array_new_with_free_func (g_object_unref); - self->families_hash = g_hash_table_new_full ((GHashFunc) pango_family_hash, - (GEqualFunc) pango_family_equal, - NULL, - NULL); - self->fontsets = g_hash_table_new_full ((GHashFunc) pango_fontset_cached_hash, - (GEqualFunc) pango_fontset_cached_equal, - NULL, - (GDestroyNotify) g_object_unref); - g_queue_init (&self->fontset_cache); - self->dpi = 96.; -} - -static void -pango_hb_font_map_finalize (GObject *object) -{ - PangoHbFontMap *self = PANGO_HB_FONT_MAP (object); - - g_ptr_array_unref (self->added_faces); - g_ptr_array_unref (self->added_families); - g_hash_table_unref (self->families_hash); - g_ptr_array_unref (self->families); - g_hash_table_unref (self->fontsets); - - G_OBJECT_CLASS (pango_hb_font_map_parent_class)->finalize (object); -} - -/* Load a font from the first matching family */ -static PangoFont * -pango_hb_font_map_load_font (PangoFontMap *map, - PangoContext *context, - const PangoFontDescription *description) -{ - PangoHbFontMap *self = PANGO_HB_FONT_MAP (map); - PangoFontsetCached *fontset; - PangoLanguage *language; - PangoFont *font = NULL; - - if (self->families->len == 0) - return NULL; - - if (context) - language = pango_context_get_language (context); - else - language = NULL; - - fontset = (PangoFontsetCached *)pango_font_map_load_fontset (map, context, description, language); - if (pango_fontset_cached_size (fontset) > 0) - font = pango_fontset_cached_get_first_font (fontset); - g_object_unref (fontset); - - return font; -} - -/* Add one font for each family we find */ -static PangoFontset * -pango_hb_font_map_load_fontset (PangoFontMap *map, - PangoContext *context, - const PangoFontDescription *description, - PangoLanguage *language) -{ - PangoHbFontMap *self = PANGO_HB_FONT_MAP (map); - PangoFontsetCached lookup; - PangoFontsetCached *fontset; - const PangoMatrix *matrix; - const char *family_name; - char **families; - PangoFontDescription *copy; - PangoFontFamily *family; - PangoFontFace *face; - gboolean has_generic = FALSE; - gint64 before G_GNUC_UNUSED; - - before = PANGO_TRACE_CURRENT_TIME; - - if (!language) - language = pango_context_get_language (context); - - family_name = pango_font_description_get_family (description); - - lookup.language = language; - lookup.description = (PangoFontDescription *)description; - fontset = g_hash_table_lookup (self->fontsets, &lookup); - - if (fontset) - goto done; - - matrix = pango_context_get_matrix (context); - - fontset = pango_fontset_cached_new (description, language, self->dpi, matrix); - - if (self->families->len == 0) - { - g_warning ("Font map contains no fonts!!!!"); - goto done_no_cache; - } - - families = g_strsplit (family_name ? family_name : "", ",", -1); - - /* Unset gravity and variant since PangoHbFace does not have these fields */ - copy = pango_font_description_copy_static (description); - pango_font_description_unset_fields (copy, PANGO_FONT_MASK_VARIATIONS | - PANGO_FONT_MASK_GRAVITY | - PANGO_FONT_MASK_VARIANT); - - for (int i = 0; families[i]; i++) - { - family = find_family (self, families[i]); - if (!family) - continue; - - if (PANGO_IS_GENERIC_FAMILY (family)) - { - pango_fontset_cached_add_family (fontset, PANGO_GENERIC_FAMILY (family)); - has_generic = TRUE; - } - else - { - face = pango_hb_family_find_face (PANGO_HB_FAMILY (family), copy, language, 0); - if (face) - pango_fontset_cached_add_face (fontset, face); - } - } - - g_strfreev (families); - - /* Returning an empty fontset leads to bad outcomes. - * - * We always include a generic family in order - * to produce fontsets with good coverage. - */ - if (!has_generic) - { - family = find_family (self, "sans-serif"); - if (PANGO_IS_GENERIC_FAMILY (family)) - pango_fontset_cached_add_family (fontset, PANGO_GENERIC_FAMILY (family)); - } - - pango_font_description_free (copy); - - g_hash_table_add (self->fontsets, fontset); - -done: - pango_fontset_cache (fontset, self); - - if (pango_fontset_cached_size (fontset) == 0) - { - char *s = pango_font_description_to_string (description); - g_warning ("All font fallbacks failed for \"%s\", in %s !!!!", s, pango_language_to_string (language)); - g_free (s); - } - -done_no_cache: - pango_trace_mark (before, "pango_hb_fontmap_load_fontset", "%s", family_name); - - return g_object_ref (PANGO_FONTSET (fontset)); -} - -static PangoFontFamily * -pango_hb_font_map_get_family (PangoFontMap *map, - const char *name) -{ - PangoHbFontMap *self = PANGO_HB_FONT_MAP (map); - - return PANGO_FONT_FAMILY (find_family (self, name)); -} - -static void -pango_hb_font_map_populate (PangoHbFontMap *self) -{ -} - -static guint -pango_hb_font_map_get_serial (PangoFontMap *map) -{ - PangoHbFontMap *self = PANGO_HB_FONT_MAP (map); - - return self->serial; -} - -static void -pango_hb_font_map_changed (PangoFontMap *map) -{ - PangoHbFontMap *self = PANGO_HB_FONT_MAP (map); - - self->serial++; - if (self->serial == 0) - self->serial++; -} - -static void -pango_hb_font_map_class_init (PangoHbFontMapClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - PangoFontMapClass *fontmap_class = PANGO_FONT_MAP_CLASS (class); - - object_class->finalize = pango_hb_font_map_finalize; - - fontmap_class->load_font = pango_hb_font_map_load_font; - fontmap_class->load_fontset = pango_hb_font_map_load_fontset; - fontmap_class->get_family = pango_hb_font_map_get_family; - fontmap_class->get_serial = pango_hb_font_map_get_serial; - fontmap_class->changed = pango_hb_font_map_changed; - - class->populate = pango_hb_font_map_populate; -} - -/* }}} */ -/* {{{ Private API */ - -/*< private > - * pango_hb_font_map_repopulate: - * @self: a `PangoHbFontMap` - * @add_synthetic: if `TRUE`, missing bold and italic faces will be synthesized - * - * Clear all cached information and repopulate the fontmap with - * families and faces. - * - * Subclasses should call this when their configuration changes - * in a way that requires recreating families and faces. - */ -void -pango_hb_font_map_repopulate (PangoHbFontMap *self, - gboolean add_synthetic) -{ - int removed, added; - - clear_caches (self); - - removed = self->families->len; - - g_hash_table_remove_all (self->families_hash); - g_ptr_array_set_size (self->families, 0); - - self->in_populate = TRUE; - - PANGO_HB_FONT_MAP_GET_CLASS (self)->populate (self); - - if (add_synthetic) - synthesize_bold_and_italic_faces (self); - - for (int i = 0; i < self->added_faces->len; i++) - { - PangoFontFace *face = g_ptr_array_index (self->added_faces, i); - pango_hb_font_map_add_face (self, face); - } - - for (int i = 0; i < self->added_families->len; i++) - { - PangoFontFamily *family = PANGO_FONT_FAMILY (g_ptr_array_index (self->added_families, i)); - pango_hb_font_map_add_family (self, family); - } - - self->in_populate = FALSE; - - added = self->families->len; - - g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added); - pango_font_map_changed (PANGO_FONT_MAP (self)); -} - -/* }}} */ -/* {{{ Public API */ - -/** - * pango_hb_font_map_new: - * - * Creates a new `PangoHbFontmMap`. - * - * Returns: A newly created `PangoHbFontMap - */ -PangoHbFontMap * -pango_hb_font_map_new (void) -{ - return g_object_new (PANGO_TYPE_HB_FONT_MAP, NULL); -} - -/** - * pango_hb_font_map_add_face: - * @self: a `PangoHbFontMap` - * @face: (transfer full): a `PangoFontFace` - * - * Adds @face to the `PangoHbFontMap`. - * - * This is most useful for creating transformed faces or aliases. - * See [ctor@Pango.HbFace.new_synthetic] and [ctor@Pango.HbFace.new_instance]. - */ -void -pango_hb_font_map_add_face (PangoHbFontMap *self, - PangoFontFace *face) -{ - PangoFontMap *map = PANGO_FONT_MAP (self); - const char *family_name; - PangoHbFamily *family; - const PangoFontDescription *description; - - g_return_if_fail (PANGO_IS_HB_FACE (face) || PANGO_IS_USER_FACE (face)); - - description = ((CommonFace *)face)->description; - - if (pango_font_description_get_set_fields (description) & - (PANGO_FONT_MASK_VARIANT | PANGO_FONT_MASK_GRAVITY)) - g_warning ("Font description for PangoFontFace includes things that it shouldn't"); - - if (!self->in_populate) - g_ptr_array_add (self->added_faces, g_object_ref (face)); - - family_name = pango_font_description_get_family (description); - family = PANGO_HB_FAMILY (pango_font_map_get_family (map, family_name)); - if (!family) - { - family = pango_hb_family_new (family_name); - pango_hb_font_map_add_family (self, PANGO_FONT_FAMILY (family)); - } - - pango_hb_family_add_face (family, face); - - pango_font_map_changed (PANGO_FONT_MAP (self)); - - clear_caches (self); -} - -/** - * pango_hb_font_map_remove_face: - * @self: a `PangoHbFontMap` - * @face: a `PangoFontFace` that belongs to @map - * - * Removes @face from the `PangoHbFontMap`. - * - * @face must have been added with [method@Pango.HbFontMap.add_face]. - */ -void -pango_hb_font_map_remove_face (PangoHbFontMap *self, - PangoFontFace *face) -{ - PangoHbFamily *family; - unsigned int position; - - g_return_if_fail (PANGO_IS_HB_FACE (face) || PANGO_IS_USER_FACE (face)); - - if (!g_ptr_array_find (self->added_faces, face, &position)) - return; - - family = PANGO_HB_FAMILY (pango_font_face_get_family (face)); - - pango_hb_family_remove_face (family, face); - - if (family->faces->len == 0) - pango_hb_font_map_remove_family (self, PANGO_FONT_FAMILY (family)); - - pango_font_map_changed (PANGO_FONT_MAP (self)); - - clear_caches (self); - - g_ptr_array_remove_index (self->added_faces, position); -} - -/** - * pango_hb_font_map_add_file: - * @self: a `PangoHbFontMap` - * @file: font filename - * - * Creates a new `PangoHbFace` and adds it. - * - * If you need to specify an instance id or other - * parameters, use [ctor@Pango.HbFace.new_from_file]. - */ -void -pango_hb_font_map_add_file (PangoHbFontMap *self, - const char *file) -{ - PangoHbFace *face; - - face = pango_hb_face_new_from_file (file, 0, -1, NULL, NULL); - pango_hb_font_map_add_face (self, PANGO_FONT_FACE (face)); -} - -/** - * pango_hb_font_map_add_family: - * @self: a `PangoHbFontMap` - * @family: (transfer full): a `PangoFontFamily` - * - * Adds @family to @self. - * - * The fontmap must not contain a family with the - * same name as @family yet. - * - * This is mostly useful for adding generic families - * using [ctor@Pango.GenericFamily.new]. - */ -void -pango_hb_font_map_add_family (PangoHbFontMap *self, - PangoFontFamily *family) -{ - const char *name; - int position; - - g_return_if_fail (PANGO_IS_HB_FAMILY (family) || PANGO_IS_GENERIC_FAMILY (family)); - g_return_if_fail (((CommonFamily *)family)->map == NULL); - - if (!self->in_populate) - g_ptr_array_add (self->added_families, g_object_ref (family)); - - name = ((CommonFamily *)family)->name; - - position = 0; - while (position < self->families->len) - { - PangoFontFamily *f = g_ptr_array_index (self->families, position); - if (g_ascii_strcasecmp (name, ((CommonFamily *)f)->name) < 0) - break; - position++; - } - - ((CommonFamily *)family)->map = PANGO_FONT_MAP (self); - g_object_add_weak_pointer (G_OBJECT (self), (gpointer *)&((CommonFamily *)family)->map); - - g_ptr_array_insert (self->families, position, family); - g_hash_table_add (self->families_hash, family); - - if (!self->in_populate) - g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1); - - pango_font_map_changed (PANGO_FONT_MAP (self)); -} - -/** - * pango_hb_font_map_remove_family: - * @self: a `PangoHbFontMap` - * @family: a `PangoFontFamily` that belongs to @self - * - * Removes a `PangoHbFamily` from a `PangoHbFontMap` - */ -void -pango_hb_font_map_remove_family (PangoHbFontMap *self, - PangoFontFamily *family) -{ - unsigned int position; - - g_return_if_fail (PANGO_IS_HB_FAMILY (family) || PANGO_IS_GENERIC_FAMILY (family)); - g_return_if_fail (((CommonFamily *)family)->map == (PangoFontMap *)self); - - if (!g_ptr_array_find (self->added_families, family, &position)) - return; - - g_hash_table_remove (self->families_hash, family); - g_ptr_array_remove_index (self->families, position); - - g_object_remove_weak_pointer (G_OBJECT (self), (gpointer *)&((CommonFamily *)family)->map); - ((CommonFamily *)family)->map = NULL; - - if (!self->in_populate) - g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0); - - pango_font_map_changed (PANGO_FONT_MAP (self)); - - g_ptr_array_remove_index (self->added_families, position); -} - -/** - * pango_hb_font_map_set_resolution: - * @self: a `PangoHbFontMap` - * @dpi: the new resolution, in "dots per inch" - * - * Sets the resolution for the fontmap. - * - * This is a scale factor between points specified in a - * `PangoFontDescription` and Cairo units. The default value - * is 96, meaning that a 10 point font will be 13 units high. - * (10 * 96. / 72. = 13.3). - */ -void -pango_hb_font_map_set_resolution (PangoHbFontMap *self, - double dpi) -{ - self->dpi = dpi; - clear_caches (self); - pango_font_map_changed (PANGO_FONT_MAP (self)); -} - -/* }}} */ - -/* vim:set foldmethod=marker expandtab: */ diff --git a/pango/pango-hbfontmap.h b/pango/pango-hbfontmap.h deleted file mode 100644 index ae456ad9..00000000 --- a/pango/pango-hbfontmap.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2021 Matthias Clasen - * - * SPDX-License-Identifier: LGPL-2.1-or-later - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <pango/pango-types.h> -#include <pango/pango-fontmap.h> -#include <pango/pango-hbface.h> - -G_BEGIN_DECLS - -#define PANGO_TYPE_HB_FONT_MAP (pango_hb_font_map_get_type ()) - -PANGO_AVAILABLE_IN_ALL -PANGO_DECLARE_INTERNAL_TYPE (PangoHbFontMap, pango_hb_font_map, PANGO, HB_FONT_MAP, PangoFontMap) - -PANGO_AVAILABLE_IN_ALL -PangoHbFontMap * pango_hb_font_map_new (void); - -PANGO_AVAILABLE_IN_ALL -void pango_hb_font_map_add_file (PangoHbFontMap *self, - const char *file); - -PANGO_AVAILABLE_IN_ALL -void pango_hb_font_map_add_face (PangoHbFontMap *self, - PangoFontFace *face); - -PANGO_AVAILABLE_IN_ALL -void pango_hb_font_map_remove_face (PangoHbFontMap *self, - PangoFontFace *face); - -PANGO_AVAILABLE_IN_ALL -void pango_hb_font_map_add_family (PangoHbFontMap *self, - PangoFontFamily *family); -PANGO_AVAILABLE_IN_ALL -void pango_hb_font_map_remove_family (PangoHbFontMap *self, - PangoFontFamily *family); - -PANGO_AVAILABLE_IN_ALL -void pango_hb_font_map_set_resolution (PangoHbFontMap *self, - double dpi); - -G_END_DECLS diff --git a/pango/pango.h b/pango/pango.h index e30a1c0f..f9065258 100644 --- a/pango/pango.h +++ b/pango/pango.h @@ -36,14 +36,12 @@ #include <pango/pango-font-metrics.h> #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> #include <pango/pango-hbface.h> #include <pango/pango-hbfont.h> -#include <pango/pango-hbfontmap.h> #include <pango/pango-item.h> #include <pango/pango-language.h> #include <pango/pango-layout.h> diff --git a/pango/pangocairo-fontmap.c b/pango/pangocairo-fontmap.c index d96f3198..67799c7d 100644 --- a/pango/pangocairo-fontmap.c +++ b/pango/pangocairo-fontmap.c @@ -32,7 +32,7 @@ # include "pangocairo-win32.h" #endif #if defined (HAVE_CAIRO_FREETYPE) -# include "pangofc-hbfontmap.h" +# include "pangofc-fontmap.h" #endif @@ -86,7 +86,7 @@ pango_cairo_font_map_new (void) #if defined(HAVE_CAIRO_FREETYPE) if (!backend || 0 == strcmp (backend, "fc") || 0 == strcmp (backend, "fontconfig")) - return (PangoFontMap *) pango_fc_hb_font_map_new (); + return (PangoFontMap *) pango_fc_font_map_new (); #endif { const char backends[] = "" diff --git a/pango/pangocoretext-hbfontmap.c b/pango/pangocoretext-fontmap.c index 86a32e0c..663a1dcc 100644 --- a/pango/pangocoretext-hbfontmap.c +++ b/pango/pangocoretext-fontmap.c @@ -23,9 +23,9 @@ #include <gio/gio.h> -#include "pangocoretext-hbfontmap.h" +#include "pangocoretext-fontmap.h" #include "pango-hbfamily-private.h" -#include "pango-hbfontmap-private.h" +#include "pango-fontmap-private.h" #include "pango-hbface-private.h" #include "pango-hbfont-private.h" #include "pango-context.h" @@ -38,21 +38,21 @@ /** - * PangoCoreTextHbFontMap: + * PangoCoreTextFontMap: * - * `PangoCoreTextHbFontMap` is a subclass of `PangoHbFontMap` that uses + * `PangoCoreTextFontMap` is a subclass of `PangoFontMap` that uses * CoreText to populate the fontmap with the available fonts. */ -struct _PangoCoreTextHbFontMap +struct _PangoCoreTextFontMap { - PangoHbFontMap parent_instance; + PangoFontMap parent_instance; }; -struct _PangoCoreTextHbFontMapClass +struct _PangoCoreTextFontMapClass { - PangoHbFontMapClass parent_class; + PangoFontMapClass parent_class; }; /* {{{ CoreText utilities */ @@ -357,12 +357,12 @@ face_from_ct_font_descriptor (CTFontDescriptorRef desc) } /* }}} */ -/* {{{ PangoHbFontMap implementation */ +/* {{{ PangoFontMap implementation */ static void -pango_core_text_hb_font_map_populate (PangoHbFontMap *map) +pango_core_text_font_map_populate (PangoFontMap *map) { - PangoCoreTextHbFontMap *self = PANGO_CORE_TEXT_HB_FONT_MAP (map); + PangoCoreTextFontMap *self = PANGO_CORE_TEXT_FONT_MAP (map); CTFontCollectionRef collection; CFArrayRef ctfaces; CFIndex count; @@ -375,7 +375,7 @@ pango_core_text_hb_font_map_populate (PangoHbFontMap *map) for (int i = 0; i < count; i++) { CTFontDescriptorRef desc = CFArrayGetValueAtIndex (ctfaces, i); - pango_hb_font_map_add_face (PANGO_HB_FONT_MAP (self), face_from_ct_font_descriptor (desc)); + pango_font_map_add_face (map, face_from_ct_font_descriptor (desc)); } /* Add generic aliases */ @@ -394,7 +394,7 @@ pango_core_text_hb_font_map_populate (PangoHbFontMap *map) for (int i = 0; i < G_N_ELEMENTS (aliases); i++) { - PangoFontFamily *family = pango_font_map_get_family (PANGO_FONT_MAP (map), aliases[i].family_name); + PangoFontFamily *family = pango_font_map_get_family (map, aliases[i].family_name); if (family) { @@ -402,55 +402,53 @@ pango_core_text_hb_font_map_populate (PangoHbFontMap *map) alias_family = pango_generic_family_new (aliases[i].alias_name); pango_generic_family_add_family (alias_family, family); - pango_hb_font_map_add_family (map, alias_family); + pango_font_map_add_family (map, alias_family); } } } /* }}} */ -/* {{{ PangoFontMap implementation */ +/* {{{ PangoCoreTextFontMap implementation */ -G_DEFINE_TYPE (PangoCoreTextHbFontMap, pango_core_text_hb_font_map, PANGO_TYPE_HB_FONT_MAP) +G_DEFINE_TYPE (PangoCoreTextFontMap, pango_core_text_font_map, PANGO_TYPE_FONT_MAP) static void -pango_core_text_hb_font_map_init (PangoCoreTextHbFontMap *self) +pango_core_text_font_map_init (PangoCoreTextFontMap *self) { - pango_hb_font_map_repopulate (PANGO_HB_FONT_MAP (self), TRUE); + pango_font_map_repopulate (PANGO_FONT_MAP (self), TRUE); } static void -pango_core_text_hb_font_map_finalize (GObject *object) +pango_core_text_font_map_finalize (GObject *object) { - //PangoCoreTextHbFontMap *self = PANGO_CORE_TEXT_HB_FONT_MAP (object); - - G_OBJECT_CLASS (pango_core_text_hb_font_map_parent_class)->finalize (object); + G_OBJECT_CLASS (pango_core_text_font_map_parent_class)->finalize (object); } static void -pango_core_text_hb_font_map_class_init (PangoCoreTextHbFontMapClass *class) +pango_core_text_font_map_class_init (PangoCoreTextFontMapClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); - PangoHbFontMapClass *hb_font_map_class = PANGO_HB_FONT_MAP_CLASS (class); + PangoFontMapClass *font_map_class = PANGO_FONT_MAP_CLASS (class); - object_class->finalize = pango_core_text_hb_font_map_finalize; + object_class->finalize = pango_core_text_font_map_finalize; - hb_font_map_class->populate = pango_core_text_hb_font_map_populate; + font_map_class->populate = pango_core_text_font_map_populate; } /* }}} */ /* {{{ Public API */ /** - * pango_core_text_hb_font_map_new: + * pango_core_text_font_map_new: * - * Creates a new `PangoCoreTextHbFontMap` object. + * Creates a new `PangoCoreTextFontMap` object. * - * Returns: a new `PangoCoreTextHbFontMap` + * Returns: a new `PangoCoreTextFontMap` */ -PangoCoreTextHbFontMap * -pango_core_text_hb_font_map_new (void) +PangoCoreTextFontMap * +pango_core_text_font_map_new (void) { - return g_object_new (PANGO_TYPE_CORE_TEXT_HB_FONT_MAP, NULL); + return g_object_new (PANGO_TYPE_CORE_TEXT_FONT_MAP, NULL); } /* }}} */ diff --git a/pango/pangocoretext-hbfontmap.h b/pango/pangocoretext-fontmap.h index aae7d5c3..5c96cf75 100644 --- a/pango/pangocoretext-hbfontmap.h +++ b/pango/pangocoretext-fontmap.h @@ -23,13 +23,13 @@ G_BEGIN_DECLS -#define PANGO_TYPE_CORE_TEXT_HB_FONT_MAP (pango_core_text_hb_font_map_get_type ()) +#define PANGO_TYPE_CORE_TEXT_FONT_MAP (pango_core_text_font_map_get_type ()) PANGO_AVAILABLE_IN_ALL -PANGO_DECLARE_INTERNAL_TYPE (PangoCoreTextHbFontMap, pango_core_text_hb_font_map, PANGO, CORE_TEXT_HB_FONT_MAP, PangoHbFontMap) +PANGO_DECLARE_INTERNAL_TYPE (PangoCoreTextFontMap, pango_core_text_font_map, PANGO, CORE_TEXT_FONT_MAP, PangoFontMap) PANGO_AVAILABLE_IN_ALL -PangoCoreTextHbFontMap * pango_core_text_hb_font_map_new (void); +PangoCoreTextFontMap * pango_core_text_font_map_new (void); G_END_DECLS diff --git a/pango/pangodwrite-hbfontmap.cpp b/pango/pangodwrite-fontmap.cpp index f0e05bcd..4ff6d323 100644 --- a/pango/pangodwrite-hbfontmap.cpp +++ b/pango/pangodwrite-fontmap.cpp @@ -1,5 +1,5 @@ /* Pango - * pangodwrite-hbfontmap.c: Fontmap using DirectWrite + * pangodwrite-fontmap.cpp: Fontmap using DirectWrite * * Copyright (C) 2022 the GTK team * @@ -27,9 +27,9 @@ #include <hb-ot.h> #include <hb-directwrite.h> -#include "pangodwrite-hbfontmap.h" +#include "pangodwrite-fontmap.h" #include "pango-hbfamily-private.h" -#include "pango-hbfontmap-private.h" +#include "pango-fontmap-private.h" #include "pango-hbface-private.h" #include "pango-hbfont-private.h" #include "pango-context.h" @@ -38,21 +38,21 @@ /** - * PangoDirectWriteHbFontMap: + * PangoDirectWriteFontMap: * - * `PangoDirectWriteHbFontMap` is a subclass of `PangoHbFontMap` that + * `PangoDirectWriteFontMap` is a subclass of `PangoFontMap` that * uses DirectWrite to populate the fontmap with the available fonts. */ -struct _PangoDirectWriteHbFontMap +struct _PangoDirectWriteFontMap { - PangoHbFontMap parent_instance; + PangoFontMap parent_instance; }; -struct _PangoDirectWriteHbFontMapClass +struct _PangoDirectWriteFontMapClass { - PangoHbFontMapClass parent_class; + PangoFontMapClass parent_class; }; #ifdef _MSC_VER @@ -226,10 +226,10 @@ util_create_pango_hb_face (IDWriteFontFamily *family, } /* }}} */ -/* {{{ PangoHbFontMap implementation */ +/* {{{ PangoFontMap implementation */ static void -pango_direct_write_hb_font_map_populate (PangoHbFontMap *map) +pango_direct_write_font_map_populate (PangoFontMap *map) { IDWriteFactory *factory = NULL; IDWriteFontCollection *collection = NULL; @@ -285,8 +285,7 @@ pango_direct_write_hb_font_map_populate (PangoHbFontMap *map) pango_face = util_create_pango_hb_face (family, font, face); if (pango_face) - pango_hb_font_map_add_face (PANGO_HB_FONT_MAP (self), - PANGO_FONT_FACE (pango_face)); + pango_font_map_add_face (map, PANGO_FONT_FACE (pango_face)); face->Release (); font->Release (); @@ -320,7 +319,7 @@ pango_direct_write_hb_font_map_populate (PangoHbFontMap *map) for (gsize i = 0; i < G_N_ELEMENTS (aliases); i++) { - PangoFontFamily *family = pango_font_map_get_family (PANGO_FONT_MAP (map), aliases[i].family_name); + PangoFontFamily *family = pango_font_map_get_family (map, aliases[i].family_name); if (family) { @@ -328,53 +327,53 @@ pango_direct_write_hb_font_map_populate (PangoHbFontMap *map) alias_family = pango_generic_family_new (aliases[i].alias_name); pango_generic_family_add_family (alias_family, family); - pango_hb_font_map_add_family (map, PANGO_FONT_FAMILY (alias_family)); + pango_font_map_add_family (map, PANGO_FONT_FAMILY (alias_family)); } } } /* }}} */ -/* {{{ PangoFontMap implementation */ +/* {{{ PangoDirctWriteFontMap implementation */ -G_DEFINE_TYPE (PangoDirectWriteHbFontMap, pango_direct_write_hb_font_map, PANGO_TYPE_HB_FONT_MAP) +G_DEFINE_TYPE (PangoDirectWriteFontMap, pango_direct_write_font_map, PANGO_TYPE_FONT_MAP) static void -pango_direct_write_hb_font_map_init (PangoDirectWriteHbFontMap *self) +pango_direct_write_font_map_init (PangoDirectWriteFontMap *self) { - pango_hb_font_map_repopulate (PANGO_HB_FONT_MAP (self), TRUE); + pango_font_map_repopulate (PANGO_FONT_MAP (self), TRUE); } static void -pango_direct_write_hb_font_map_finalize (GObject *object) +pango_direct_write_font_map_finalize (GObject *object) { - G_OBJECT_CLASS (pango_direct_write_hb_font_map_parent_class)->finalize (object); + G_OBJECT_CLASS (pango_direct_write_font_map_parent_class)->finalize (object); } static void -pango_direct_write_hb_font_map_class_init (PangoDirectWriteHbFontMapClass *class_) +pango_direct_write_font_map_class_init (PangoDirectWriteFontMapClass *class_) { GObjectClass *object_class = G_OBJECT_CLASS (class_); - PangoHbFontMapClass *hb_font_map_class = PANGO_HB_FONT_MAP_CLASS (class_); + PangoFontMapClass *font_map_class = PANGO_FONT_MAP_CLASS (class_); - object_class->finalize = pango_direct_write_hb_font_map_finalize; + object_class->finalize = pango_direct_write_font_map_finalize; - hb_font_map_class->populate = pango_direct_write_hb_font_map_populate; + font_map_class->populate = pango_direct_write_font_map_populate; } /* }}} */ /* {{{ Public API */ /** - * pango_direct_write_hb_font_map_new: + * pango_direct_write_font_map_new: * - * Creates a new `PangoDirectWriteHbFontMap` object. + * Creates a new `PangoDirectWriteFontMap` object. * - * Returns: a new `PangoDirectWriteHbFontMap` + * Returns: a new `PangoDirectWriteFontMap` */ -PangoDirectWriteHbFontMap * -pango_direct_write_hb_font_map_new (void) +PangoDirectWriteFontMap * +pango_direct_write_font_map_new (void) { - return (PangoDirectWriteHbFontMap *) g_object_new (PANGO_TYPE_DIRECT_WRITE_HB_FONT_MAP, NULL); + return (PangoDirectWriteFontMap *) g_object_new (PANGO_TYPE_DIRECT_WRITE_FONT_MAP, NULL); } /* }}} */ diff --git a/pango/pangodwrite-hbfontmap.h b/pango/pangodwrite-fontmap.h index 9ce8791e..ed18d866 100644 --- a/pango/pangodwrite-hbfontmap.h +++ b/pango/pangodwrite-fontmap.h @@ -1,5 +1,5 @@ /* Pango - * pangodwrite-hbfontmap.h: Fontmap using DirectWrite + * pangodwrite-fontmap.h: Fontmap using DirectWrite * * Copyright (C) 2022 the GTK team * @@ -25,16 +25,16 @@ G_BEGIN_DECLS -#define PANGO_TYPE_DIRECT_WRITE_HB_FONT_MAP (pango_direct_write_hb_font_map_get_type ()) +#define PANGO_TYPE_DIRECT_WRITE_FONT_MAP (pango_direct_write_font_map_get_type ()) PANGO_AVAILABLE_IN_ALL -PANGO_DECLARE_INTERNAL_TYPE (PangoDirectWriteHbFontMap, - pango_direct_write_hb_font_map, - PANGO, DIRECT_WRITE_HB_FONT_MAP, - PangoHbFontMap) +PANGO_DECLARE_INTERNAL_TYPE (PangoDirectWriteFontMap, + pango_direct_write_font_map, + PANGO, DIRECT_WRITE_FONT_MAP, + PangoFontMap) PANGO_AVAILABLE_IN_ALL -PangoDirectWriteHbFontMap * pango_direct_write_hb_font_map_new (void); +PangoDirectWriteFontMap * pango_direct_write_font_map_new (void); G_END_DECLS diff --git a/pango/pangofc-hbfontmap.c b/pango/pangofc-fontmap.c index c00a1a21..2d79be86 100644 --- a/pango/pangofc-hbfontmap.c +++ b/pango/pangofc-fontmap.c @@ -23,10 +23,10 @@ #include <gio/gio.h> -#include "pangofc-hbfontmap.h" +#include "pangofc-fontmap.h" #include "pango-hbfamily-private.h" #include "pango-generic-family-private.h" -#include "pango-hbfontmap-private.h" +#include "pango-fontmap-private.h" #include "pango-hbface-private.h" #include "pango-hbfont-private.h" #include "pango-context.h" @@ -39,23 +39,23 @@ /** - * PangoFcHbFontMap: + * PangoFcFontMap: * - * `PangoFcHbFontMap` is a subclass of `PangoHbFontMap` that uses + * `PangoFcFontMap` is a subclass of `PangoFontMap` that uses * fontconfig to populate the fontmap with the available fonts. */ -struct _PangoFcHbFontMap +struct _PangoFcFontMap { - PangoHbFontMap parent_instance; + PangoFontMap parent_instance; FcConfig *config; }; -struct _PangoFcHbFontMapClass +struct _PangoFcFontMapClass { - PangoHbFontMapClass parent_class; + PangoFontMapClass parent_class; }; /* {{{ Fontconfig utilities */ @@ -249,9 +249,9 @@ font_matrix_from_pattern (FcPattern *pattern, } static PangoHbFace * -pango_hb_face_from_pattern (PangoFcHbFontMap *self, - FcPattern *pattern, - GHashTable *lang_hash) +pango_hb_face_from_pattern (PangoFcFontMap *self, + FcPattern *pattern, + GHashTable *lang_hash) { const char *family_name, *file; int index; @@ -319,12 +319,12 @@ pango_hb_face_from_pattern (PangoFcHbFontMap *self, } /* }}} */ -/* {{{ PangoHbFontMap implementation */ +/* {{{ PangoFontMap implementation */ static void -pango_fc_hb_font_map_populate (PangoHbFontMap *map) +pango_fc_font_map_populate (PangoFontMap *map) { - PangoFcHbFontMap *self = PANGO_FC_HB_FONT_MAP (map); + PangoFcFontMap *self = PANGO_FC_FONT_MAP (map); FcPattern *pat; FcFontSet *fontset; int k; @@ -352,7 +352,7 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map) if (!face) continue; - pango_hb_font_map_add_face (PANGO_HB_FONT_MAP (self), PANGO_FONT_FACE (face)); + pango_font_map_add_face (PANGO_FONT_MAP (self), PANGO_FONT_FACE (face)); } g_hash_table_unref (lang_hash); @@ -372,7 +372,7 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map) FcResult res; const char *family_name; - if (pango_font_map_get_family (PANGO_FONT_MAP (self), alias_names[i])) + if (pango_font_map_get_family (map, alias_names[i])) continue; pattern = FcPatternCreate (); @@ -385,14 +385,14 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map) if (FcPatternGetString (ret, FC_FAMILY, 0, (FcChar8 **)(void*)&family_name) == FcResultMatch) { - PangoFontFamily *family = pango_font_map_get_family (PANGO_FONT_MAP (self), family_name); + PangoFontFamily *family = pango_font_map_get_family (map, family_name); if (family) { PangoGenericFamily *alias_family; alias_family = pango_generic_family_new (alias_names[i]); pango_generic_family_add_family (alias_family, family); - pango_hb_font_map_add_family (PANGO_HB_FONT_MAP (self), PANGO_FONT_FAMILY (alias_family)); + pango_font_map_add_family (map, PANGO_FONT_FAMILY (alias_family)); } } @@ -425,7 +425,7 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map) FcFontSet *ret; FcResult res; - if (pango_font_map_get_family (PANGO_FONT_MAP (self), generic_names[i])) + if (pango_font_map_get_family (map, generic_names[i])) continue; generic_family = pango_generic_family_new (generic_names[i]); @@ -479,7 +479,7 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map) index = index & 0xffff; - family = PANGO_HB_FAMILY (pango_font_map_get_family (PANGO_FONT_MAP (self), family_name)); + family = PANGO_HB_FAMILY (pango_font_map_get_family (map, family_name)); if (!family) continue; @@ -494,7 +494,7 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map) FcPatternDestroy (pattern); g_hash_table_unref (families_hash); - pango_hb_font_map_add_family (PANGO_HB_FONT_MAP (self), PANGO_FONT_FAMILY (generic_family)); + pango_font_map_add_family (map, PANGO_FONT_FAMILY (generic_family)); } FcLangSetDestroy (no_langs); @@ -502,36 +502,36 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map) FcObjectSetDestroy (os); - pango_trace_mark (before, "populate FcHbFontMap", NULL); + pango_trace_mark (before, "populate FcFontMap", NULL); } /* }}} */ -/* {{{ PangoFontMap implementation */ +/* {{{ PangoFcFontMap implementation */ -G_DEFINE_TYPE (PangoFcHbFontMap, pango_fc_hb_font_map, PANGO_TYPE_HB_FONT_MAP) +G_DEFINE_TYPE (PangoFcFontMap, pango_fc_font_map, PANGO_TYPE_FONT_MAP) static void -pango_fc_hb_font_map_init (PangoFcHbFontMap *self) +pango_fc_font_map_init (PangoFcFontMap *self) { - pango_hb_font_map_repopulate (PANGO_HB_FONT_MAP (self), TRUE); + pango_font_map_repopulate (PANGO_FONT_MAP (self), TRUE); } static void -pango_fc_hb_font_map_finalize (GObject *object) +pango_fc_font_map_finalize (GObject *object) { - PangoFcHbFontMap *self = PANGO_FC_HB_FONT_MAP (object); + PangoFcFontMap *self = PANGO_FC_FONT_MAP (object); if (self->config) FcConfigDestroy (self->config); - G_OBJECT_CLASS (pango_fc_hb_font_map_parent_class)->finalize (object); + G_OBJECT_CLASS (pango_fc_font_map_parent_class)->finalize (object); } static void -pango_fc_hb_font_map_class_init (PangoFcHbFontMapClass *class) +pango_fc_font_map_class_init (PangoFcFontMapClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); - PangoHbFontMapClass *hb_font_map_class = PANGO_HB_FONT_MAP_CLASS (class); + PangoFontMapClass *font_map_class = PANGO_FONT_MAP_CLASS (class); gint64 before G_GNUC_UNUSED; before = PANGO_TRACE_CURRENT_TIME; @@ -540,33 +540,33 @@ pango_fc_hb_font_map_class_init (PangoFcHbFontMapClass *class) pango_trace_mark (before, "FcInit", NULL); - object_class->finalize = pango_fc_hb_font_map_finalize; + object_class->finalize = pango_fc_font_map_finalize; - hb_font_map_class->populate = pango_fc_hb_font_map_populate; + font_map_class->populate = pango_fc_font_map_populate; } /* }}} */ /* {{{ Public API */ /** - * pango_fc_hb_font_map_new: + * pango_fc_font_map_new: * - * Creates a new `PangoFcHbFontMap` object. + * Creates a new `PangoFcFontMap` object. * - * Unless overridden by [method@PangoFc.HbFontMap.set_config], + * Unless overridden by [method@PangoFc.FontMap.set_config], * this font map uses the default fontconfig configuration. * - * Returns: a new `PangoFcHbFontMap` + * Returns: a new `PangoFcFontMap` */ -PangoFcHbFontMap * -pango_fc_hb_font_map_new (void) +PangoFcFontMap * +pango_fc_font_map_new (void) { - return g_object_new (PANGO_TYPE_FC_HB_FONT_MAP, NULL); + return g_object_new (PANGO_TYPE_FC_FONT_MAP, NULL); } /** - * pango_fc_hb_font_map_set_config: (skip) - * @self: a `PangoFcHbFontMap` + * pango_fc_font_map_set_config: (skip) + * @self: a `PangoFcFontMap` * @config: (nullable): the `FcConfig` to use, or `NULL` to use * the default configuration * @@ -576,10 +576,10 @@ pango_fc_hb_font_map_new (void) * removes all cached font families, faces and fonts. */ void -pango_fc_hb_font_map_set_config (PangoFcHbFontMap *self, - FcConfig *config) +pango_fc_font_map_set_config (PangoFcFontMap *self, + FcConfig *config) { - g_return_if_fail (PANGO_IS_FC_HB_FONT_MAP (self)); + g_return_if_fail (PANGO_IS_FC_FONT_MAP (self)); if (self->config == config && FcConfigUptoDate (config)) return; @@ -595,25 +595,25 @@ pango_fc_hb_font_map_set_config (PangoFcHbFontMap *self, FcConfigReference (self->config); } - pango_hb_font_map_repopulate (PANGO_HB_FONT_MAP (self), TRUE); + pango_font_map_repopulate (PANGO_FONT_MAP (self), TRUE); } /** - * pango_fc_hb_font_map_get_config: (skip) - * @self: a `PangoFcHbFontMap` + * pango_fc_font_map_get_config: (skip) + * @self: a `PangoFcFontMap` * * Fetches the `FcConfig` attached to a font map. * - * See also: [method@PangoFc.HbFontMap.set_config]. + * See also: [method@PangoFc.FontMap.set_config]. * * Returns: (nullable): the `FcConfig` object attached to * @self, which might be %NULL. The return value is * owned by Pango and should not be freed. */ FcConfig * -pango_fc_hb_font_map_get_config (PangoFcHbFontMap *self) +pango_fc_font_map_get_config (PangoFcFontMap *self) { - g_return_val_if_fail (PANGO_IS_FC_HB_FONT_MAP (self), NULL); + g_return_val_if_fail (PANGO_IS_FC_FONT_MAP (self), NULL); return self->config; } diff --git a/pango/pangofc-hbfontmap.h b/pango/pangofc-fontmap.h index 81fbc572..abe12d23 100644 --- a/pango/pangofc-hbfontmap.h +++ b/pango/pangofc-fontmap.h @@ -24,19 +24,19 @@ G_BEGIN_DECLS -#define PANGO_TYPE_FC_HB_FONT_MAP (pango_fc_hb_font_map_get_type ()) +#define PANGO_TYPE_FC_FONT_MAP (pango_fc_font_map_get_type ()) PANGO_AVAILABLE_IN_ALL -PANGO_DECLARE_INTERNAL_TYPE (PangoFcHbFontMap, pango_fc_hb_font_map, PANGO, FC_HB_FONT_MAP, PangoHbFontMap) +PANGO_DECLARE_INTERNAL_TYPE (PangoFcFontMap, pango_fc_font_map, PANGO, FC_FONT_MAP, PangoFontMap) PANGO_AVAILABLE_IN_ALL -PangoFcHbFontMap * pango_fc_hb_font_map_new (void); +PangoFcFontMap * pango_fc_font_map_new (void); PANGO_AVAILABLE_IN_ALL -void pango_fc_hb_font_map_set_config (PangoFcHbFontMap *self, - FcConfig *config); +void pango_fc_font_map_set_config (PangoFcFontMap *self, + FcConfig *config); PANGO_AVAILABLE_IN_ALL -FcConfig * pango_fc_hb_font_map_get_config (PangoFcHbFontMap *self); +FcConfig * pango_fc_font_map_get_config (PangoFcFontMap *self); G_END_DECLS diff --git a/tests/test-break.c b/tests/test-break.c index f7fd36ae..2531635b 100644 --- a/tests/test-break.c +++ b/tests/test-break.c @@ -29,7 +29,7 @@ #include "config.h" #include <pango/pangocairo.h> -#include <pango/pangofc-hbfontmap.h> +#include <pango/pangofc-fontmap.h> #include "test-common.h" #include "validate-log-attrs.h" @@ -380,8 +380,8 @@ install_fonts (const char *dir) g_free (path); FcConfigAppFontAddDir (config, (const FcChar8 *) dir); - map = PANGO_FONT_MAP (pango_fc_hb_font_map_new ()); - pango_fc_hb_font_map_set_config (PANGO_FC_HB_FONT_MAP (map), config); + map = PANGO_FONT_MAP (pango_fc_font_map_new ()); + pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (map), config); FcConfigDestroy (config); } diff --git a/tests/test-fonts.c b/tests/test-fonts.c index 98435abf..50bcb305 100644 --- a/tests/test-fonts.c +++ b/tests/test-fonts.c @@ -2,7 +2,7 @@ #include <locale.h> #include <pango/pango.h> -#include <pango/pangofc-hbfontmap.h> +#include <pango/pangofc-fontmap.h> #include "test-common.h" static PangoFontMap *map = NULL; @@ -27,8 +27,8 @@ install_fonts (const char *dir) g_free (path); FcConfigAppFontAddDir (config, (const FcChar8 *) dir); - map = PANGO_FONT_MAP (pango_fc_hb_font_map_new ()); - pango_fc_hb_font_map_set_config (PANGO_FC_HB_FONT_MAP (map), config); + map = PANGO_FONT_MAP (pango_fc_font_map_new ()); + pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (map), config); FcConfigDestroy (config); } diff --git a/tests/test-layout.c b/tests/test-layout.c index c91af6af..6dfc1d58 100644 --- a/tests/test-layout.c +++ b/tests/test-layout.c @@ -29,7 +29,7 @@ #include "config.h" #include <pango/pangocairo.h> -#include <pango/pangofc-hbfontmap.h> +#include <pango/pangofc-fontmap.h> #include "test-common.h" static PangoFontMap *map = NULL; @@ -120,8 +120,8 @@ install_fonts (const char *dir) FcConfigAppFontAddDir (config, (const FcChar8 *) dir); - map = PANGO_FONT_MAP (pango_fc_hb_font_map_new ()); - pango_fc_hb_font_map_set_config (PANGO_FC_HB_FONT_MAP (map), config); + map = PANGO_FONT_MAP (pango_fc_font_map_new ()); + pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (map), config); FcConfigDestroy (config); } diff --git a/tests/testhbfont.c b/tests/testhbfont.c index 1e4f847b..b93294ec 100644 --- a/tests/testhbfont.c +++ b/tests/testhbfont.c @@ -23,7 +23,7 @@ #include <glib.h> #include <gio/gio.h> #include <pango/pangocairo.h> -#include <pango/pangofc-hbfontmap.h> +#include <pango/pangofc-fontmap.h> #include <hb-ot.h> @@ -34,25 +34,25 @@ static void test_hbfont_monospace (void) { - PangoHbFontMap *map; + PangoFontMap *map; PangoFontFamily *family; char *path; - map = pango_hb_font_map_new (); + map = pango_font_map_new (); path = g_test_build_filename (G_TEST_DIST, "fonts", "Cantarell-VF.otf", NULL); - pango_hb_font_map_add_file (map, path); + pango_font_map_add_file (map, path); family = pango_font_map_get_family (PANGO_FONT_MAP (map), "Cantarell"); g_assert_nonnull (family); - pango_hb_font_map_add_face (map, PANGO_FONT_FACE (pango_hb_face_new_from_file (path, 0, -2, NULL, NULL))); + pango_font_map_add_face (map, PANGO_FONT_FACE (pango_hb_face_new_from_file (path, 0, -2, NULL, NULL))); g_free (path); path = g_test_build_filename (G_TEST_DIST, "fonts", "DejaVuSansMono.ttf", NULL); - pango_hb_font_map_add_file (map, path); + pango_font_map_add_file (map, path); g_free (path); family = pango_font_map_get_family (PANGO_FONT_MAP (map), "DejaVu Sans Mono"); @@ -367,7 +367,7 @@ test_hbfont_faceid (void) static void test_hbfont_load (void) { - PangoHbFontMap *map; + PangoFontMap *map; PangoContext *context; char *path; PangoFontDescription *desc; @@ -376,7 +376,7 @@ test_hbfont_load (void) PangoFont *font; /* Make a Cat family, with the two faces Fat and Wild */ - map = pango_hb_font_map_new (); + map = pango_font_map_new (); context = pango_font_map_create_context (PANGO_FONT_MAP (map)); path = g_test_build_filename (G_TEST_DIST, "fonts", "Cantarell-VF.otf", NULL); @@ -386,7 +386,7 @@ test_hbfont_load (void) pango_font_description_free (desc); g_free (path); - pango_hb_font_map_add_face (map, PANGO_FONT_FACE (face_fat)); + pango_font_map_add_face (map, PANGO_FONT_FACE (face_fat)); path = g_test_build_filename (G_TEST_DIST, "fonts", "DejaVuSans.ttf", NULL); desc = pango_font_description_new (); @@ -394,7 +394,7 @@ test_hbfont_load (void) face_wild = pango_hb_face_new_from_file (path, 0, -1, "Wild", desc); pango_font_description_free (desc); - pango_hb_font_map_add_face (map, PANGO_FONT_FACE (face_wild)); + pango_font_map_add_face (map, PANGO_FONT_FACE (face_wild)); desc = pango_font_face_describe (PANGO_FONT_FACE (face_wild)); pango_font_description_set_size (desc, 12 * PANGO_SCALE); @@ -429,7 +429,7 @@ test_hbfont_load (void) static void test_hbfont_load_variation (void) { - PangoHbFontMap *map; + PangoFontMap *map; PangoContext *context; char *path; PangoFontDescription *desc; @@ -442,7 +442,7 @@ test_hbfont_load_variation (void) unsigned int length; /* Make a Cat family, with the two faces Fat and Wild */ - map = pango_hb_font_map_new (); + map = pango_font_map_new (); context = pango_font_map_create_context (PANGO_FONT_MAP (map)); path = g_test_build_filename (G_TEST_DIST, "fonts", "Cantarell-VF.otf", NULL); @@ -452,7 +452,7 @@ test_hbfont_load_variation (void) pango_font_description_free (desc); g_free (path); - pango_hb_font_map_add_face (map, PANGO_FONT_FACE (face_fat)); + pango_font_map_add_face (map, PANGO_FONT_FACE (face_fat)); desc = pango_font_description_new (); pango_font_description_set_family (desc, "Cat"); @@ -461,7 +461,7 @@ test_hbfont_load_variation (void) face_wild = pango_hb_face_new_instance (face_fat, &v, 1, "Wild", desc); pango_font_description_free (desc); - pango_hb_font_map_add_face (map, PANGO_FONT_FACE (face_wild)); + pango_font_map_add_face (map, PANGO_FONT_FACE (face_wild)); desc = pango_font_face_describe (PANGO_FONT_FACE (face_wild)); @@ -506,7 +506,7 @@ get_font (PangoFontset *fontset, } static void -test_hbfontmap_language (void) +test_fontmap_language (void) { PangoFontMap *map; PangoContext *context; @@ -514,7 +514,7 @@ test_hbfontmap_language (void) PangoFontset *fonts; gboolean found; - map = PANGO_FONT_MAP (pango_fc_hb_font_map_new ()); + map = PANGO_FONT_MAP (pango_fc_font_map_new ()); context = pango_font_map_create_context (map); desc = pango_font_description_from_string ("serif 11"); @@ -545,7 +545,7 @@ main (int argc, char *argv[]) g_test_add_func ("/hbfont/faceid", test_hbfont_faceid); g_test_add_func ("/hbfont/load", test_hbfont_load); g_test_add_func ("/hbfont/load/variation", test_hbfont_load_variation); - g_test_add_func ("/hbfontmap/language", test_hbfontmap_language); + g_test_add_func ("/fontmap/language", test_fontmap_language); return g_test_run (); } diff --git a/tests/testmisc.c b/tests/testmisc.c index 7e99b0f0..42ea77c4 100644 --- a/tests/testmisc.c +++ b/tests/testmisc.c @@ -693,7 +693,7 @@ test_gravity_metrics (void) static void test_gravity_metrics2 (void) { - PangoHbFontMap *map; + PangoFontMap *map; PangoContext *context; PangoFontDescription *desc; PangoFont *font; @@ -703,9 +703,9 @@ test_gravity_metrics2 (void) PangoRectangle log[4]; char *path; - map = pango_hb_font_map_new (); + map = pango_font_map_new (); path = g_test_build_filename (G_TEST_DIST, "fonts", "Cantarell-VF.otf", NULL); - pango_hb_font_map_add_file (map, path); + pango_font_map_add_file (map, path); g_free (path); context = pango_font_map_create_context (PANGO_FONT_MAP (map)); diff --git a/tests/testserialize.c b/tests/testserialize.c index da1f674a..cd85add5 100644 --- a/tests/testserialize.c +++ b/tests/testserialize.c @@ -22,7 +22,7 @@ #include <glib.h> #include <pango/pangocairo.h> -#include <pango/pangofc-hbfontmap.h> +#include <pango/pangofc-fontmap.h> #include <gio/gio.h> static PangoFontMap *map = NULL; @@ -456,8 +456,8 @@ install_fonts (void) g_free (path); FcConfigAppFontAddDir (config, (const FcChar8 *) dir); - map = PANGO_FONT_MAP (pango_fc_hb_font_map_new ()); - pango_fc_hb_font_map_set_config (PANGO_FC_HB_FONT_MAP (map), config); + map = PANGO_FONT_MAP (pango_fc_font_map_new ()); + pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (map), config); FcConfigDestroy (config); g_free (dir); diff --git a/utils/pango-list.c b/utils/pango-list.c index 87bb77b8..c963e5e0 100644 --- a/utils/pango-list.c +++ b/utils/pango-list.c @@ -22,7 +22,7 @@ #include "config.h" #include <pango/pangocairo.h> -#include <pango/pangofc-hbfontmap.h> +#include <pango/pangofc-fontmap.h> #include <pango/pango-hbface-private.h> #include <hb-ot.h> #include <glib/gstdio.h> diff --git a/utils/viewer-pangocairo.c b/utils/viewer-pangocairo.c index af26c702..bcb8a75f 100644 --- a/utils/viewer-pangocairo.c +++ b/utils/viewer-pangocairo.c @@ -55,7 +55,7 @@ pangocairo_view_create (const PangoViewer *klass G_GNUC_UNUSED) if (PANGO_IS_CAIRO_FONT_MAP (instance->fontmap)) pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (instance->fontmap), opt_dpi); else - pango_hb_font_map_set_resolution (PANGO_HB_FONT_MAP (instance->fontmap), opt_dpi); + pango_font_map_set_resolution (PANGO_FONT_MAP (instance->fontmap), opt_dpi); instance->font_options = cairo_font_options_create (); if (opt_hinting != HINT_DEFAULT) |