summaryrefslogtreecommitdiff
path: root/pango/pangox.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-02-16 22:05:43 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-02-16 22:05:43 +0000
commit7f846326d416e9ab3eadca9f02b9a0129095f30b (patch)
tree4b2812b858cd830ca1282e3697d029ca347df24a /pango/pangox.c
parent4f335d6e4a3f5b4e6ddd1cd78f919aa80c990262 (diff)
downloadpango-7f846326d416e9ab3eadca9f02b9a0129095f30b.tar.gz
Make refcounted.
Wed Feb 16 16:39:46 2000 Owen Taylor <otaylor@redhat.com> * libpango/pango-coverage.c (pango_coverage_get): Make refcounted. * libpango/modules.c (struct _PangoEnginePair): Since we don't currently unload engines, cache loaded engines. (Not really quite satisfactory, but should work OK) * libpango/pango-context.c (pango_context_get_font_description): Added a global font description. * libpango/modules.c (_pango_find_map): Allow NULL language tags. * libpango/pango-context.c (pango_itemize) examples/viewer.c: Switch itemize over to take a PangoAttrList. * examples/viewer.c: Conform to changes in itemization interface * libpango/font.[ch]: Add a compare function for FontDescription * libpango/pango-attributes.[ch]: Change the iteration iterface to be more convenient. * libpango/pango-context.[ch]: Add the ability to set a default font. * libpango/pango-context.[ch]: Take the font for itemization from the attributes on the text. * libpango/pangox.c: Cache currently loaded fonts, and cache coverages.
Diffstat (limited to 'pango/pangox.c')
-rw-r--r--pango/pangox.c91
1 files changed, 69 insertions, 22 deletions
diff --git a/pango/pangox.c b/pango/pangox.c
index bcc175d1..80b18395 100644
--- a/pango/pangox.c
+++ b/pango/pangox.c
@@ -49,6 +49,9 @@ struct _PangoXFontEntry
{
char *xlfd;
PangoFontDescription description;
+ PangoCoverage *coverage;
+
+ GSList *cached_fonts;
};
struct _PangoXFamilyEntry
@@ -81,6 +84,8 @@ struct _PangoXFont
int n_subfonts;
int max_subfonts;
+
+ PangoXFontEntry *entry; /* Used to remove cached fonts */
};
struct _PangoXFontMap
@@ -155,18 +160,18 @@ const struct {
{ "condensed", PANGO_STRETCH_CONDENSED },
};
-static void pango_x_font_map_destroy (PangoFontMap *fontmap);
-static PangoFont *pango_x_font_map_load_font (PangoFontMap *fontmap,
- PangoFontDescription *desc,
- double size);
-static void pango_x_font_map_list_fonts (PangoFontMap *fontmap,
- const gchar *family,
- PangoFontDescription ***descs,
- int *n_descs);
-static void pango_x_font_map_list_families (PangoFontMap *fontmap,
- gchar ***families,
- int *n_families);
-static void pango_x_font_map_read_aliases (PangoXFontMap *xfontmap);
+static void pango_x_font_map_destroy (PangoFontMap *fontmap);
+static PangoFont *pango_x_font_map_load_font (PangoFontMap *fontmap,
+ const PangoFontDescription *desc,
+ double size);
+static void pango_x_font_map_list_fonts (PangoFontMap *fontmap,
+ const gchar *family,
+ PangoFontDescription ***descs,
+ int *n_descs);
+static void pango_x_font_map_list_families (PangoFontMap *fontmap,
+ gchar ***families,
+ int *n_families);
+static void pango_x_font_map_read_aliases (PangoXFontMap *xfontmap);
static void pango_x_font_destroy (PangoFont *font);
static PangoFontDescription *pango_x_font_describe (PangoFont *font);
@@ -296,9 +301,9 @@ pango_x_get_family_entry (PangoXFontMap *xfontmap,
}
static PangoFont *
-pango_x_font_map_load_font (PangoFontMap *fontmap,
- PangoFontDescription *description,
- double size)
+pango_x_font_map_load_font (PangoFontMap *fontmap,
+ const PangoFontDescription *description,
+ double size)
{
PangoXFontMap *xfontmap = (PangoXFontMap *)fontmap;
PangoXFamilyEntry *family_entry;
@@ -339,8 +344,27 @@ pango_x_font_map_load_font (PangoFontMap *fontmap,
if (best_match)
{
- /* FIXME: cache fonts */
- result = pango_x_load_font_with_size (xfontmap->display, best_match->xlfd, size);
+ GSList *tmp_list = best_match->cached_fonts;
+
+ while (tmp_list)
+ {
+ PangoXFont *xfont = tmp_list->data;
+ if (xfont->size == size)
+ {
+ result = (PangoFont *)xfont;
+ pango_font_ref (result);
+ break;
+ }
+ tmp_list = tmp_list->next;
+ }
+
+ if (!result)
+ {
+ result = pango_x_load_font_with_size (xfontmap->display, best_match->xlfd, size);
+ ((PangoXFont *)result)->entry = best_match;
+ best_match->cached_fonts = g_slist_prepend (best_match->cached_fonts, result);
+ }
+
}
}
@@ -853,6 +877,8 @@ pango_x_font_map_read_alias_file (PangoXFontMap *xfontmap,
g_free (font_entry->description.family_name);
font_entry->description.family_name = family_entry->family_name;
+ font_entry->cached_fonts = NULL;
+ font_entry->coverage = NULL;
}
if (ferror (infile))
@@ -1137,6 +1163,8 @@ pango_x_insert_font (PangoXFontMap *xfontmap,
font_entry = g_new (PangoXFontEntry, 1);
font_entry->description = description;
font_entry->description.family_name = family_entry->family_name;
+ font_entry->cached_fonts = NULL;
+ font_entry->coverage = NULL;
font_entry->xlfd = g_strconcat ("-*-",
family_buffer,
@@ -1194,7 +1222,7 @@ pango_x_load_font (Display *display,
result->fonts = g_strsplit(spec, ",", -1);
for (result->n_fonts = 0; result->fonts[result->n_fonts]; result->n_fonts++)
- /* Nothing */
+ ; /* Nothing */
result->subfonts_by_charset = g_hash_table_new (g_str_hash, g_str_equal);
result->subfonts = g_new (PangoXSubfontInfo *, 1);
@@ -1203,6 +1231,7 @@ pango_x_load_font (Display *display,
result->max_subfonts = 1;
result->size = -1;
+ result->entry = NULL;
return (PangoFont *)result;
}
@@ -1238,7 +1267,7 @@ pango_x_load_font_with_size (Display *display,
result->fonts = g_strsplit(spec, ",", -1);
for (result->n_fonts = 0; result->fonts[result->n_fonts]; result->n_fonts++)
- /* Nothing */
+ ; /* Nothing */
result->subfonts_by_charset = g_hash_table_new (g_str_hash, g_str_equal);
result->subfonts = g_new (PangoXSubfontInfo *, 1);
@@ -1247,6 +1276,7 @@ pango_x_load_font_with_size (Display *display,
result->max_subfonts = 1;
result->size = size;
+ result->entry = NULL;
return (PangoFont *)result;
}
@@ -1637,7 +1667,7 @@ pango_x_make_matching_xlfd (PangoXFontMap *xfontmap, char *xlfd, const char *cha
}
}
- /* g_free (dash_charset); */
+ g_free (dash_charset);
return result;
}
@@ -1803,6 +1833,9 @@ pango_x_font_destroy (PangoFont *font)
g_hash_table_foreach (xfont->subfonts_by_charset, subfonts_foreach, NULL);
g_hash_table_destroy (xfont->subfonts_by_charset);
+ if (xfont->entry)
+ xfont->entry->cached_fonts = g_slist_remove (xfont->entry->cached_fonts, xfont);
+
g_strfreev (xfont->fonts);
g_free (font);
}
@@ -1819,7 +1852,7 @@ free_coverages_foreach (gpointer key,
gpointer value,
gpointer data)
{
- pango_coverage_destroy (value);
+ pango_coverage_unref (value);
}
static PangoCoverage *
@@ -1834,7 +1867,15 @@ pango_x_font_get_coverage (PangoFont *font,
PangoCoverage *result;
PangoCoverageLevel font_level;
GHashTable *coverage_hash;
-
+ PangoXFont *xfont = (PangoXFont *)font;
+
+ if (xfont->entry)
+ if (xfont->entry->coverage)
+ {
+ pango_coverage_ref (xfont->entry->coverage);
+ return xfont->entry->coverage;
+ }
+
result = pango_coverage_new ();
coverage_hash = g_hash_table_new (g_str_hash, g_str_equal);
@@ -1869,6 +1910,12 @@ pango_x_font_get_coverage (PangoFont *font,
g_hash_table_foreach (coverage_hash, free_coverages_foreach, NULL);
g_hash_table_destroy (coverage_hash);
+ if (xfont->entry)
+ {
+ xfont->entry->coverage = result;
+ pango_coverage_ref (result);
+ }
+
return result;
}