summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2003-09-23 23:11:59 +0000
committerOwen Taylor <otaylor@src.gnome.org>2003-09-23 23:11:59 +0000
commit0f36f55ee0e7c9bf224fabbaf31843b3868f213c (patch)
treea8446856f4dce9b792f5e2ca1c3f9d25bbc40b76 /tools
parent8fa8e29cd61c802c6b100b3cca800784e3a9de20 (diff)
downloadpango-0f36f55ee0e7c9bf224fabbaf31843b3868f213c.tar.gz
Modules now declare a list of scripts that they cover instead of a list of
Tue Sep 23 18:03:57 2003 Owen Taylor <otaylor@redhat.com> * pango/pango-engines.[ch] pango/pango-engines-private.h: Modules now declare a list of scripts that they cover instead of a list of code point ranges. Also, there is now a ->covers() virtual function that allows a module to decide live whether the font covers a particular codepoint; remove old get_coverage() method. * pango/pango-fontset.[ch]: Add a foreach() function to iterate over all the fonts in a fontset (with a true return stopping iteration). * pango/pango-context.c: Complete rewrite using script-run information to improve language tags. Switch to an approach where we handle one run at a time rather than computing information for each character individually then later breaking the result into runs. * pango/pango-fontset.[ch]: Switch over to using pango-impl-utils.h. * modules/basic/basic-x.c pango/pangox-fontmap.c: Adapt to the change from get_coverage => covers. * pango/pango-modules.h pango/modules.c: Switch PangoMap over to being based on script rather than being based on codepoint. Remove the no longer needed pango_map_get_entry(). * pango/modules.c: Handle new script-based modules. * pango/pango-fc-fontmap.c pango/pango-win32-fontmap.c pango/pang-fontmap.[ch]: Add a shape_engine_type field to PangoFontmapClass, pango_font_map_get_shape_engine_type(); this allows generic code to find a shaper for a particular fontmap. * pango/pango-script.[ch]: Add pango_script_get_sample_language(), pango_language_includes_script(); functions for determining the relationship between scripts and language. * tools/gen-script-for-lang.c: Modify to spit out a useful table. * pango/pango-script-lang-table.h: Version of table generated from current fontconfig data. * pango/pangox.c: Remove complicated code to compute coverages; no longer useful now that we just have the basic shaper as a legacy thing. * modules/*/*.c: Adapt to identifying shape engines by language range. * modules/thai/thai-fc.c modules/thai/thai-shaper.[ch]: Remove now unused "has_glyph" function and XTIS support. * modules/thai/thai-fc.c: Handle non-Thai characters as well, since the Thai module now gets spaces, punctuation, and so forth.
Diffstat (limited to 'tools')
-rw-r--r--tools/gen-script-for-lang.c151
1 files changed, 107 insertions, 44 deletions
diff --git a/tools/gen-script-for-lang.c b/tools/gen-script-for-lang.c
index 1f774ea7..0eb8e7ad 100644
--- a/tools/gen-script-for-lang.c
+++ b/tools/gen-script-for-lang.c
@@ -8,8 +8,16 @@
#include <pango/pango-types.h>
#include <pango/pango-utils.h>
-PangoScript script_for_file (const char *base_dir,
- const char *file_part);
+#define MAX_SCRIPTS 3
+
+typedef struct {
+ PangoLanguage *lang;
+ PangoScript scripts[MAX_SCRIPTS];
+} LangInfo;
+
+static void scripts_for_file (const char *base_dir,
+ const char *file_part,
+ LangInfo *info);
const char *get_script_name (PangoScript script)
{
@@ -55,14 +63,15 @@ void warn_mismatch (const char *file_part,
file_part, get_script_name (script1), get_script_name (script2));
}
-PangoScript script_for_line (const char *base_dir,
- const char *file_part,
- const char *str)
+static void
+scripts_for_line (const char *base_dir,
+ const char *file_part,
+ const char *str,
+ LangInfo *info)
{
gunichar start_char;
gunichar end_char;
gunichar ch;
- PangoScript result = PANGO_SCRIPT_COMMON;
const char *p = str;
if (g_str_has_prefix (str, "include"))
@@ -77,10 +86,10 @@ PangoScript script_for_line (const char *base_dir,
pango_skip_space (&str))
goto err;
- result = script_for_file (base_dir, file_part->str);
+ scripts_for_file (base_dir, file_part->str, info);
g_string_free (file_part, TRUE);
- return result;
+ return;
}
/* Format is HEX_DIGITS or HEX_DIGITS-HEX_DIGITS */
@@ -107,30 +116,39 @@ PangoScript script_for_line (const char *base_dir,
if (script != PANGO_SCRIPT_COMMON &&
script != PANGO_SCRIPT_INHERITED)
{
- if (result != PANGO_SCRIPT_COMMON && script != result)
+ int j;
+ for (j = 0; j < MAX_SCRIPTS; j++)
{
- warn_mismatch (file_part, script, result);
- return PANGO_SCRIPT_INVALID_CODE;
+ if (info->scripts[j] == script)
+ break;
+ if (info->scripts[j] == PANGO_SCRIPT_INVALID_CODE)
+ {
+ info->scripts[j] = script;
+ break;
+ }
}
- result = script;
+
+ if (j == MAX_SCRIPTS)
+ fail ("More than %d scripts found for %s\n", MAX_SCRIPTS, file_part);
}
}
- return result;
+ return;
err:
fail ("While processing '%s', cannot parse line: '%s'\n", file_part, str);
- return PANGO_SCRIPT_INVALID_CODE; /* Not reached */
+ return; /* Not reached */
}
-PangoScript script_for_file (const char *base_dir,
- const char *file_part)
+static void
+scripts_for_file (const char *base_dir,
+ const char *file_part,
+ LangInfo *info)
{
GError *error = NULL;
char *filename = g_build_filename (base_dir, file_part, NULL);
GIOChannel *channel = g_io_channel_new_file (filename, "r", &error);
GIOStatus status = G_IO_STATUS_NORMAL;
- PangoScript result = PANGO_SCRIPT_COMMON;
if (!channel)
fail ("Error opening '%s': %s\n", filename, error);
@@ -155,21 +173,7 @@ PangoScript script_for_file (const char *base_dir,
*comment = '\0';
g_strstrip (str);
if (str[0] != '\0') /* Empty */
- {
- PangoScript script = script_for_line (base_dir, file_part, str);
- if (script != PANGO_SCRIPT_COMMON &&
- script != PANGO_SCRIPT_INHERITED)
- {
- if (result != PANGO_SCRIPT_COMMON && script != result)
- {
- warn_mismatch (file_part, script, result);
- result = PANGO_SCRIPT_INVALID_CODE;
- status = G_IO_STATUS_EOF;
- }
- else
- result = script;
- }
- }
+ scripts_for_line (base_dir, file_part, str, info);
g_free (str);
break;
case G_IO_STATUS_EOF:
@@ -187,14 +191,47 @@ PangoScript script_for_file (const char *base_dir,
fail ("Error closing '%s': %s\n", channel, error);
g_free (filename);
+}
+
+static void
+do_file (GArray *script_array,
+ const char *base_dir,
+ const char *file_part)
+{
+ char *langpart;
+ LangInfo info;
+ int j;
+
+ langpart = g_strndup (file_part, strlen (file_part) - strlen (".orth"));
+ info.lang = pango_language_from_string (langpart);
+ g_free (langpart);
- return result;
+ for (j = 0; j < MAX_SCRIPTS; j++)
+ info.scripts[j] = PANGO_SCRIPT_INVALID_CODE;
+
+ scripts_for_file (base_dir, file_part, &info);
+
+ g_array_append_val (script_array, info);
+}
+
+static int
+compare_lang (gconstpointer a,
+ gconstpointer b)
+{
+ const LangInfo *info_a = a;
+ const LangInfo *info_b = a;
+
+ return strcmp (pango_language_to_string (info_a->lang),
+ pango_language_to_string (info_b->lang));
}
int main (int argc, char **argv)
{
GDir *dir;
GError *error = NULL;
+ GArray *script_array;
+ int i, j;
+ int max_lang_len = 0;
g_type_init ();
@@ -205,6 +242,8 @@ int main (int argc, char **argv)
if (!dir)
fail ("%s\n", error->message);
+ script_array = g_array_new (FALSE, FALSE, sizeof (LangInfo));
+
while (TRUE)
{
const char *name = g_dir_read_name (dir);
@@ -212,22 +251,46 @@ int main (int argc, char **argv)
break;
if (g_str_has_suffix (name, ".orth"))
+ do_file (script_array, argv[1], name);
+ }
+
+ g_array_sort (script_array, compare_lang);
+
+ for (i = 0; i < script_array->len; i++)
+ {
+ LangInfo *info = &g_array_index (script_array, LangInfo, i);
+
+ max_lang_len = MAX (max_lang_len,
+ 1 + strlen (pango_language_to_string (info->lang)));
+ }
+
+ g_print ("typedef struct {\n"
+ " const char lang[%d];\n"
+ " PangoScript scripts[%d];\n"
+ "} PangoScriptForLang;\n"
+ "\n"
+ "PangoScriptForLang pango_script_for_lang[] = {\n",
+ max_lang_len,
+ MAX_SCRIPTS);
+
+ for (i = 0; i < script_array->len; i++)
+ {
+ LangInfo *info = &g_array_index (script_array, LangInfo, i);
+
+ g_print (" { \"%s\", { ", pango_language_to_string (info->lang));
+ for (j = 0; j < MAX_SCRIPTS; j++)
{
- char *langpart = g_strndup (name,
- strlen (name) - strlen (".orth"));
- PangoLanguage *lang = pango_language_from_string (langpart);
- PangoScript script;
-
- script = script_for_file (argv[1], name);
- g_print ("%s - %s\n",
- pango_language_to_string (lang),
- get_script_name (script));
- g_free (langpart);
+ if (j != 0)
+ g_print (", ");
+ g_print ("%s", get_script_name (info->scripts[j]));
}
+ g_print (" } },\n");
}
+ g_print ("};\n");
+
+
g_dir_close (dir);
return 0;
}
-