summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2003-08-03 21:57:35 +0000
committerOwen Taylor <otaylor@src.gnome.org>2003-08-03 21:57:35 +0000
commit2584212cd0976f5f95d9381e829917e7d2a10d28 (patch)
tree5773e9f6802f8316c5c7463aa55677babe67343c /tools
parent95a8d1788e884b7d8d29d4171a1adc51c61e880e (diff)
downloadpango-2584212cd0976f5f95d9381e829917e7d2a10d28.tar.gz
Make PangoEngine{,Lang,Shape} GObjects, and use a GTypeModule-based
Sat Aug 2 23:19:16 2003 Owen Taylor <otaylor@redhat.com> * pango/pango-engine.[ch] modules/*/*-{fc,win32,x}.c pango/modules.c pango/break.c pango/pango-context.c pango/pango-layout.c pango/pango-modules.h pango/querymodules.c pango/shape.c: Make PangoEngine{,Lang,Shape} GObjects, and use a GTypeModule-based module-loading system closely based on the one used for GtkIMContext and GtkThemeEngine. * pango/pango-impl-utils.h: OK, I'm tired of typing in get_type() functions. * pango/pango-script.[ch] pango/pango-script-table.h tests/testscript.c tools/gen-script-table.pl: Add port of script-range code from ICU in preparation for future use. (#91542) * tools/gen-script-for-lang.c: Utility program to determine the script for each fontconfig .orth file. * docs/tmpl/{scripts.sgml,pango-engine-lang.sgml, pango-engine-shape.sgml} docs/pango-sections.txt docs/pango-docs.sgml: Redo to go along with the above changes. * configure.in: chmod +x tests/runtests.sh
Diffstat (limited to 'tools')
-rw-r--r--tools/.cvsignore1
-rw-r--r--tools/Makefile.am12
-rw-r--r--tools/gen-script-for-lang.c232
-rwxr-xr-xtools/gen-script-table.pl70
4 files changed, 315 insertions, 0 deletions
diff --git a/tools/.cvsignore b/tools/.cvsignore
index c038ed78..24f67f13 100644
--- a/tools/.cvsignore
+++ b/tools/.cvsignore
@@ -1,2 +1,3 @@
+gen-script-for-lang
Makefile
Makefile.in \ No newline at end of file
diff --git a/tools/Makefile.am b/tools/Makefile.am
index d43cf4a6..2206e601 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,8 +1,20 @@
## Process this file with automake to create Makefile.in.
+INCLUDES = \
+ -I$(top_srcdir) \
+ $(GLIB_CFLAGS) \
+ -DG_DISABLE_DEPRECATED \
+ -DPANGO_DISABLE_DEPRECATED \
+ $(PANGO_DEBUG_FLAGS)
+
+noinst_PROGRAMS = gen-script-for-lang
+
EXTRA_DIST= \
add-copyright \
compress-table.pl \
make-table.sh \
maps/README \
maps/tis-620
+
+gen_script_for_lang_SOURCES = gen-script-for-lang.c
+gen_script_for_lang_LDADD = ../pango/libpango-$(PANGO_API_VERSION).la
diff --git a/tools/gen-script-for-lang.c b/tools/gen-script-for-lang.c
new file mode 100644
index 00000000..ee1580e2
--- /dev/null
+++ b/tools/gen-script-for-lang.c
@@ -0,0 +1,232 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <pango/pango-enum-types.h>
+#include <pango/pango-script.h>
+#include <pango/pango-types.h>
+#include <pango/pango-utils.h>
+
+PangoScript script_for_file (const char *base_dir,
+ const char *file_part);
+
+const char *get_script_name (PangoScript script)
+{
+ static GEnumClass *class = NULL;
+ if (!class)
+ class = g_type_class_ref (PANGO_TYPE_SCRIPT);
+
+ GEnumValue *value = g_enum_get_value (class, script);
+ g_assert (value);
+
+ return value->value_name;
+}
+
+int fail (char *format, ...)
+{
+ va_list vap;
+
+ va_start (vap, format);
+ vfprintf (stderr, format, vap);
+ va_end (vap);
+
+ exit (1);
+}
+
+gboolean scan_hex (const char **str, gunichar *result)
+{
+ const char *end;
+
+ *result = strtol (*str, (char **)&end, 16);
+ if (end == *str)
+ return FALSE;
+
+ *str = end;
+ return TRUE;
+}
+
+void warn_mismatch (const char *file_part,
+ PangoScript script1,
+ PangoScript script2)
+{
+ g_printerr ("%s has characters for both %s and %s\n",
+ 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)
+{
+ gunichar start_char;
+ gunichar end_char;
+ gunichar ch;
+ PangoScript result = PANGO_SCRIPT_COMMON;
+ const char *p = str;
+
+ if (g_str_has_prefix (str, "include"))
+ {
+ GString *file_part = g_string_new (NULL);
+
+ str += strlen ("include");
+ if (!pango_skip_space (&str))
+ goto err;
+
+ if (!pango_scan_string (&str, file_part) ||
+ pango_skip_space (&str))
+ goto err;
+
+ result = script_for_file (base_dir, file_part->str);
+ g_string_free (file_part, TRUE);
+
+ return result;
+ }
+
+ /* Format is HEX_DIGITS or HEX_DIGITS-HEX_DIGITS */
+ if (!scan_hex (&p, &start_char))
+ goto err;
+
+ end_char = start_char;
+
+ pango_skip_space (&p);
+ if (*p == '-')
+ {
+ p++;
+ if (!scan_hex (&p, &end_char))
+ goto err;
+
+ pango_skip_space (&p);
+ }
+ if (*p != '\0')
+ goto err;
+
+ for (ch = start_char; ch <= end_char; ch++)
+ {
+ PangoScript script = pango_script_for_unichar (ch);
+ if (script != PANGO_SCRIPT_COMMON &&
+ script != PANGO_SCRIPT_INHERITED)
+ {
+ if (result != PANGO_SCRIPT_COMMON && script != result)
+ {
+ warn_mismatch (file_part, script, result);
+ return PANGO_SCRIPT_INVALID_CODE;
+ }
+ result = script;
+ }
+ }
+
+ return result;
+
+ err:
+ fail ("While processing '%s', cannot parse line: '%s'\n", file_part, str);
+ return PANGO_SCRIPT_INVALID_CODE; /* Not reached */
+}
+
+PangoScript script_for_file (const char *base_dir,
+ const char *file_part)
+{
+ 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);
+
+ /* The files have ISO-8859-1 copyright signs in them */
+ if (!g_io_channel_set_encoding (channel, "ISO-8859-1", &error))
+ fail ("Cannot set encoding when reading '%s': %s\n", filename, error);
+
+ while (status == G_IO_STATUS_NORMAL)
+ {
+ char *str;
+ size_t term;
+ char *comment;
+
+ status = g_io_channel_read_line (channel, &str, NULL, &term, &error);
+ switch (status)
+ {
+ case G_IO_STATUS_NORMAL:
+ str[term] = '\0';
+ comment = strchr (str, '#');
+ if (comment)
+ *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;
+ }
+ }
+ g_free (str);
+ break;
+ case G_IO_STATUS_EOF:
+ break;
+ case G_IO_STATUS_ERROR:
+ fail ("Error reading '%s': %s\n", filename, error->message);
+ break;
+ case G_IO_STATUS_AGAIN:
+ g_assert_not_reached ();
+ break;
+ }
+ }
+
+ if (!g_io_channel_shutdown (channel, FALSE, &error))
+ fail ("Error closing '%s': %s\n", channel, error);
+
+ g_free (filename);
+
+ return result;
+}
+
+int main (int argc, char **argv)
+{
+ GDir *dir;
+ GError *error = NULL;
+
+ g_type_init ();
+
+ if (argc != 2)
+ fail ("Usage: gen-script-for-lang DIR > script-for-lang.h\n");
+
+ dir = g_dir_open (argv[1], 0, &error);
+ if (!dir)
+ fail ("%s\n", error->message);
+
+ while (TRUE)
+ {
+ const char *name = g_dir_read_name (dir);
+ if (!name)
+ break;
+
+ if (g_str_has_suffix (name, ".orth"))
+ {
+ 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);
+ }
+ }
+
+ g_dir_close (dir);
+
+ return 0;
+}
+
diff --git a/tools/gen-script-table.pl b/tools/gen-script-table.pl
new file mode 100755
index 00000000..6b524ef7
--- /dev/null
+++ b/tools/gen-script-table.pl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl -w
+#
+# Script to convert http://www.unicode.org/Public/UNIDATA/Scripts.txt
+# into a machine-readable table.
+#
+######################################################################
+
+if (@ARGV != 1) {
+ die "Usage: gen-script-table.pl Scripts.txt > pango-script-table.h\n";
+}
+
+open IN, $ARGV[0] || die "Cannot open $ARGV[0]: $!\n";
+
+my @ranges;
+my $file;
+
+while (<IN>) {
+ if (/^\#\s+(Scripts-.*.txt)/) {
+ $file = $1;
+ }
+
+ s/#.*//;
+ next if /^\s*$/;
+ if (!/^([0-9A-F]+)(?:\.\.([0-9A-F]+))?\s+;\s+([A-Z_]+)\s+$/) {
+ die "Cannot parse line: $_\n";
+ }
+
+ if (defined $2) {
+ push @ranges, [ hex $1, hex $2, $3 ];
+ } else {
+ push @ranges, [ hex $1, hex $1, $3 ];
+ }
+}
+
+$date = gmtime;
+
+print <<"EOT";
+/* pango-script-table.h: Generated by gen-script-table.pl
+ *
+ * Date: $date
+ * Source: $file
+ *
+ * Do not edit.
+ */
+static const struct {
+ gunichar start;
+ guint16 chars;
+ guint16 script; /* PangoScript */
+} pango_script_table[] = {
+EOT
+
+@ranges = sort { $a->[0] <=> $b->[0] } @ranges;
+
+for (my $i = 0; $i <= $#ranges; $i++) {
+ my $start = $ranges[$i]->[0];
+ my $end = $ranges[$i]->[1];
+ my $script = $ranges[$i]->[2];
+
+ while ($i <= $#ranges - 1 &&
+ $ranges[$i + 1]->[0] == $end + 1 &&
+ $ranges[$i + 1]->[2] eq $script) {
+ $i++;
+ $end = $ranges[$i]->[1];
+ }
+
+ printf " { %#06x, %5d, PANGO_SCRIPT_%s },\n", $start, $end - $start + 1, $script;
+}
+
+printf "};\n";
+