diff options
author | Alexander Larsson <alla@lysator.liu.se> | 2001-11-18 16:06:02 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2001-11-18 16:06:02 +0000 |
commit | 0766534429b5830716e782418179ea63f8f1f65d (patch) | |
tree | 1ab6b8c50e572af8320c8f3623b8135276c010f6 /pango/pango-utils.c | |
parent | b12c0fb6263fd542bb03f8bb10076a0653694f12 (diff) | |
download | pango-0766534429b5830716e782418179ea63f8f1f65d.tar.gz |
Check for LEX and YACC. This will be made optional later, with the build
2001-11-17 Alexander Larsson <alla@lysator.liu.se>
* configure.in:
Check for LEX and YACC. This will be made optional later,
with the build sources checked in to cvs.
Generate pango/mini-xft/Makefile
* modules/basic/basic-ft2.c:
Use the new pangoft2 API.
* pango/Makefile.am:
Build mini-xft.
Add new files.
* pango/pango-context.[ch]:
Support only one fontmap per context.
Use pango_font_map_load_fontset() and PangoFontset instead
of internal fontset.
* pango/pango-fontmap.[ch]:
New virtual function pango_font_map_load_fontset() and
default implementation that uses pango_font_map_load_font().
* pango/pango-utils.[ch] (pango_lookup_aliases):
Utility function for looking up aliases. This can be
used by backend that has no backend specific aliases.
* pango/pangoft2-fontcache.c:
Removed file.
* pango/pangoft2-fontmap.c:
* pango/pangoft2-private.h:
* pango/pangoft2.c:
* pango/pangoft2.h:
Major rewrite. Doesn't handle fontsets. Uses mini-xft so that
it will always match the PangoXft backend. Simplified the
public API.
* pango/pangowin32.c:
* pango/pangox.c:
pango_context_add_font_map -> pango_context_set_font_map
* pango/pangoxft-font.c:
* pango/pangoxft-fontmap.c:
* pango/pangoxft-private.h:
New code to handle fontsets.
* pango/mini-xft/*:
Mini version of libXft from XFree86 in order to have
the pangoFT2 and pangXft backends have same config files and
generate the same fonts.
Diffstat (limited to 'pango/pango-utils.c')
-rw-r--r-- | pango/pango-utils.c | 244 |
1 files changed, 243 insertions, 1 deletions
diff --git a/pango/pango-utils.c b/pango/pango-utils.c index 866acd7b..1d81ee7f 100644 --- a/pango/pango-utils.c +++ b/pango/pango-utils.c @@ -48,6 +48,16 @@ #endif +struct PangoAlias +{ + char *alias; + int n_families; + char **families; + gboolean visible; /* Do we want/need this? */ +}; + +GHashTable *pango_aliases_ht = NULL; + /** * pango_trim_string: * @str: a string @@ -557,7 +567,7 @@ read_config_file (const char *filename, gboolean enoent_error) } if (ferror (file)) - errstring = g_strdup ("g_strerror(errno)"); + errstring = g_strdup (g_strerror(errno)); error: @@ -1250,3 +1260,235 @@ pango_get_mirror_char (gunichar ch, } #endif /* HAVE_FRIBIDI */ + + +guint +alias_hash (struct PangoAlias *alias) +{ + return g_str_hash (alias->alias); +} + +gboolean +alias_equal (struct PangoAlias *alias1, + struct PangoAlias *alias2) +{ + return g_str_equal (alias1->alias, + alias2->alias); +} + + +void +alias_free (struct PangoAlias *alias) +{ + int i; + g_free (alias->alias); + + for (i = 0; i < alias->n_families; i++) + g_free (alias->families[i]); + + g_free (alias->families); + + g_free (alias); +} + +static void +read_alias_file (const char *filename) +{ + FILE *file; + + GString *line_buffer; + GString *tmp_buffer1; + GString *tmp_buffer2; + char *errstring = NULL; + const char *pos; + int line = 0; + struct PangoAlias alias_key; + struct PangoAlias *alias; + char **new_families; + int n_new; + int i; + + file = fopen (filename, "r"); + if (!file) + return; + + line_buffer = g_string_new (NULL); + tmp_buffer1 = g_string_new (NULL); + tmp_buffer2 = g_string_new (NULL); + + while (pango_read_line (file, line_buffer)) + { + gboolean empty = FALSE; + gboolean append = FALSE; + line++; + + pos = line_buffer->str; + if (!pango_skip_space (&pos)) + continue; + + if (!pango_scan_word (&pos, tmp_buffer1) || + !pango_skip_space (&pos)) + { + errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE"); + goto error; + } + + if (*pos == '+') + { + append = TRUE; + pos++; + } + + if (*(pos++) != '=') + { + errstring = g_strdup ("Line is not of the form KEY=VALUE or KEY+=VALUE"); + goto error; + } + + if (!pango_skip_space (&pos)) + { + empty = TRUE; + } + else + { + if (!pango_scan_string (&pos, tmp_buffer2)) + { + errstring = g_strdup ("Error parsing value string"); + goto error; + } + if (pango_skip_space (&pos)) + { + errstring = g_strdup ("Junk after value string"); + goto error; + } + } + + alias_key.alias = g_ascii_strdown (tmp_buffer1->str, -1); + + /* Remove any existing values */ + alias = g_hash_table_lookup (pango_aliases_ht, &alias_key); + + if (!alias) + { + alias = g_new0 (struct PangoAlias, 1); + alias->alias = alias_key.alias; + + g_hash_table_insert (pango_aliases_ht, + alias, alias); + } + else + g_free (alias_key.alias); + + new_families = g_strsplit (tmp_buffer2->str, ",", -1); + + n_new = 0; + while (new_families[n_new]) + n_new++; + + if (alias->families && append) + { + alias->families = g_realloc (alias->families, + sizeof (char *) *(n_new + alias->n_families)); + for (i = 0; i < n_new; i++) + alias->families[alias->n_families + i] = new_families[i]; + g_free (new_families); + alias->n_families += n_new; + } + else + { + for (i = 0; i < alias->n_families; i++) + g_free (alias->families[i]); + g_free (alias->families); + + alias->families = new_families; + alias->n_families = n_new; + } + } + + if (ferror (file)) + errstring = g_strdup (g_strerror(errno)); + + error: + + if (errstring) + { + fprintf (stderr, "Pango:%s:%d: %s\n", filename, line, errstring); + g_free (errstring); + } + + g_string_free (line_buffer, TRUE); + g_string_free (tmp_buffer1, TRUE); + g_string_free (tmp_buffer2, TRUE); + + fclose (file); +} + +void +pango_load_aliases (void) +{ + char *filename; + const char *home; + + pango_aliases_ht = g_hash_table_new_full ((GHashFunc)alias_hash, + (GEqualFunc)alias_equal, + (GDestroyNotify)alias_free, + NULL); + + + filename = g_strconcat (pango_get_sysconf_subdirectory (), + G_DIR_SEPARATOR_S "pango.aliases", + NULL); + read_alias_file (filename); + g_free (filename); + + home = g_get_home_dir (); + if (home && *home) + { + filename = g_strconcat (home, + G_DIR_SEPARATOR_S ".pango.aliases", + NULL); + read_alias_file (filename); + g_free (filename); + } +} + + +/** + * pango_lookup_aliases: + * @fontname: an ascii string + * @families: will be set to an array of font family names. + * this array is owned by pango and should not be freed. + * + * Look up all user defined aliases for the alias #fontname. + * The resulting font family names will be stored in #families, + * and the number of families will be returned. + * + * Return value: the number of font famillies stored in the #families argument. + * This value is owned by Pango and must not be freed. + **/ +void +pango_lookup_aliases (const char *fontname, + char ***families, + int *n_families) +{ + struct PangoAlias alias_key; + struct PangoAlias *alias; + + if (pango_aliases_ht == NULL) + pango_load_aliases (); + + alias_key.alias = g_ascii_strdown (fontname, -1); + alias = g_hash_table_lookup (pango_aliases_ht, &alias_key); + g_free (alias_key.alias); + + if (alias) + { + *families = alias->families; + *n_families = alias->n_families; + } + else + { + *families = NULL; + *n_families = 0; + } +} |