summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorRobert Brady <rbrady@src.gnome.org>2000-11-08 19:09:32 +0000
committerRobert Brady <rbrady@src.gnome.org>2000-11-08 19:09:32 +0000
commit3d3be7b21de8ba776faffc560cab565a0d7d5022 (patch)
tree3bd7fe2622c90c477cf62a5a40f5aa93a66e6719 /pango
parent452359df74d9ab351b010a58693e597a53aa6362 (diff)
downloadpango-3d3be7b21de8ba776faffc560cab565a0d7d5022.tar.gz
Added missing files
Diffstat (limited to 'pango')
-rwxr-xr-xpango/pango-indic.c215
-rw-r--r--pango/pango-indic.h80
-rw-r--r--pango/pango-intset.c130
-rw-r--r--pango/pango-intset.h43
4 files changed, 468 insertions, 0 deletions
diff --git a/pango/pango-indic.c b/pango/pango-indic.c
new file mode 100755
index 00000000..a4e8d6bf
--- /dev/null
+++ b/pango/pango-indic.c
@@ -0,0 +1,215 @@
+/* Pango
+ * pango-indic.c: Library for Indic script rendering
+ *
+ * Copyright (C) 2000 SuSE Linux Ltd.
+ *
+ * Author: Robert Brady <rwb197@zepler.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * Licence as published by the Free Software Foundation; either
+ * version 2 of the Licence, 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 Licence for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * Licence along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "pango.h"
+#include "pango-indic.h"
+
+/**
+ * pango_indic_shift_vowels:
+ * @script: A #PangoIndicScript
+ * @chars: Array of #gunichar
+ * @end: Pointer to just after the end of @chars
+ *
+ * This causes the any vowels in @chars which are
+ * left-joining vowels to move to the start of @chars.
+ *
+ * It determines whether the vowels are left-joining
+ * by calling is_prefixing_vowel from @script.
+ */
+void
+pango_indic_shift_vowels (PangoIndicScript *script,
+ gunichar *chars,
+ gunichar *end)
+{
+ int length = end - chars;
+ int i, j;
+
+ for (i = 1 ; i < length ; i++)
+ {
+ if (script->is_prefixing_vowel (chars[i]))
+ {
+ gunichar tmp = chars[i];
+
+ for (j = 1; j < i; j++)
+ chars[j + 1] = chars[j];
+
+ chars[0] = tmp;
+ }
+ }
+}
+
+/**
+ * pango_indic_compact:
+ * @script: A #PangoIndicScript
+ * @num: The number of glyphs
+ * @chars: An array of glyphs/characters
+ * @clusters: The cluster array.
+ *
+ * This eliminates any blank space in the @chars
+ * array, updated @clusters and @num also.
+ * (Blank space is defines as U+0000)
+ */
+void
+pango_indic_compact (PangoIndicScript *script,
+ int *num,
+ gunichar *chars,
+ int *cluster)
+{
+ gunichar *dest = chars;
+ gunichar *end = chars + *num;
+ int *cluster_dest = cluster;
+ while (chars < end)
+ {
+ if (*chars)
+ {
+ *dest = *chars;
+ *cluster_dest = *cluster;
+ dest++;
+ chars++;
+ cluster++;
+ cluster_dest++;
+ }
+ else
+ {
+ chars++;
+ cluster++;
+ }
+ }
+ *num -= (chars - dest);
+}
+
+static gunichar
+default_vowel_sign_to_matra (gunichar a)
+{
+ return (a + 0xc000);
+}
+
+/**
+ * pango_indic_convert_vowels:
+ * @script: A #PangoIndicScript
+ * @in_middle: Whether vowels should be converted
+ * @num: The number of elements in @chars.
+ * @chars: An array of glyphs/characters
+ * @has_standalone_vowels: Whether the font has standalone vowels.
+ *
+ * This converts the second two vowel signs in a row
+ * in a string, to either a vowel letter or spacing forms
+ * of the combining vowel.
+ */
+void
+pango_indic_convert_vowels (PangoIndicScript *script,
+ gboolean in_middle,
+ int *num,
+ gunichar *chars,
+ gboolean has_standalone_vowels)
+{
+ /* goes along and converts vowel signs to vowel letters if needed. */
+ gunichar *end = chars + *num;
+ gunichar *start = chars;
+ gunichar (*vowel_sign_to_matra)(gunichar a) = script->vowel_sign_to_matra;
+ gboolean last_was_vowel_sign = 0;
+
+ vowel_sign_to_matra = FALSE;
+ if (!vowel_sign_to_matra || has_standalone_vowels)
+ vowel_sign_to_matra = default_vowel_sign_to_matra;
+
+ while (chars < end)
+ {
+ gboolean convert = FALSE;
+ gboolean is_vowel_sign = script->is_vowel_sign (chars[0]);
+ if (is_vowel_sign)
+ {
+ if (chars==start)
+ convert = TRUE;
+
+ if (chars > start && in_middle &&
+ (last_was_vowel_sign ||
+ (script->is_vowel_half && script->is_vowel_half (chars[-1]))))
+ convert = TRUE;
+ }
+
+ if (convert)
+ chars[0] = vowel_sign_to_matra (chars[0]);
+
+ last_was_vowel_sign = is_vowel_sign;
+
+ chars++;
+ }
+}
+
+/**
+ * pango_indic_split_out_characters
+ * @script: A #PangoIndicScript
+ * @text: A UTF-8 string
+ * @n_chars: The number of UTF-8 sequences in @text
+ * @wc: Pointer to array of #gunichar (output param)
+ * @n_glyph: Pointer to number of elements in @wc. (output param)
+ * @glyphs: A #PangoGlyphString.
+ *
+ * This splits out the string @text into characters. It will
+ * split out two-part vowels using @script->vowel_split if
+ * this function is available.
+ *
+ * *@n_chars is allocated with g_new, you must free it.
+ */
+void
+pango_indic_split_out_characters (PangoIndicScript *script,
+ const char *text,
+ int n_chars,
+ gunichar **wc,
+ int *n_glyph,
+ PangoGlyphString *glyphs)
+{
+ const char *p = text;
+ int i;
+ *n_glyph = n_chars;
+
+ if (script->vowel_split)
+ for (i = 0; i < n_chars; i++)
+ {
+ gunichar u = g_utf8_get_char (p);
+ if (script->vowel_split (u, NULL, NULL))
+ (*n_glyph)++;
+ p = g_utf8_next_char (p);
+ }
+
+ p = text;
+ *wc = (gunichar *) g_new (gunichar, *n_glyph);
+ pango_glyph_string_set_size (glyphs, *n_glyph);
+ for (i = 0; i < *n_glyph; i++)
+ {
+ (*wc)[i] = g_utf8_get_char (p);
+ glyphs->log_clusters[i] = p - text;
+
+ if (script->vowel_split)
+ if (script->vowel_split ((*wc)[i], &(*wc)[i], &(*wc)[i+1]))
+ {
+ i++;
+ glyphs->log_clusters[i] = p - text;
+ }
+
+ p = g_utf8_next_char (p);
+ }
+}
+
+
diff --git a/pango/pango-indic.h b/pango/pango-indic.h
new file mode 100644
index 00000000..35b7fb4b
--- /dev/null
+++ b/pango/pango-indic.h
@@ -0,0 +1,80 @@
+/* Pango
+ * pango-indic.h: Library for Indic script rendering
+ *
+ * Copyright (C) 2000 SuSE Linux Ltd.
+ *
+ * Author: Robert Brady <rwb197@zepler.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * Licence as published by the Free Software Foundation; either
+ * version 2 of the Licence, 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 Licence for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * Licence along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * This library is basically internal
+ *
+ * Don't use it, unless you are me, or are in contact with me,
+ * or like living dangerously.
+ */
+
+#ifndef __PANGO_PANGO_INDIC_H__
+#define __PANGO_PANGO_INDIC_H__
+
+#define ZERO_WIDTH_NON_JOINER 0x200c
+#define ZERO_WIDTH_JOINER 0x200d
+
+typedef struct _PangoIndicScript PangoIndicScript;
+
+struct _PangoIndicScript {
+ /* Compulsory */
+ gchar *name;
+ /* Compulsory */
+ gboolean (*is_prefixing_vowel) (gunichar what);
+ /* Compulsory */
+ gboolean (*is_vowel_sign) (gunichar what);
+ /* Optional */
+ gunichar (*vowel_sign_to_matra) (gunichar what);
+ /* Optional */
+ gboolean (*is_vowel_half) (gunichar what);
+
+ /* Optional */
+ gboolean (*vowel_split) (gunichar what,
+ gunichar *prefix,
+ gunichar *suffix);
+};
+
+void pango_indic_shift_vowels (PangoIndicScript *script,
+ gunichar *chars,
+ gunichar *end);
+
+void pango_indic_compact (PangoIndicScript *script,
+ int *num,
+ gunichar *chars,
+ int *cluster);
+
+void pango_indic_convert_vowels (PangoIndicScript *script,
+ gboolean in_middle,
+ int *num,
+ gunichar *chars,
+ gboolean has_standalone_vowels);
+
+void pango_indic_split_out_characters (PangoIndicScript *script,
+ const gchar *text,
+ int n_chars,
+ gunichar **wc,
+ int *n_glyph,
+ PangoGlyphString *glyphs);
+
+
+#endif
diff --git a/pango/pango-intset.c b/pango/pango-intset.c
new file mode 100644
index 00000000..9c0df6df
--- /dev/null
+++ b/pango/pango-intset.c
@@ -0,0 +1,130 @@
+/* Pango
+ * pango-intset.c: Integer set
+ *
+ * Copyright (C) 2000 SuSE Linux Ltd
+ *
+ * Author: Robert Brady <rwb197@zepler.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * Licence as published by the Free Software Foundation; either
+ * version 2 of the Licence, 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 Licence for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * Licence along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include <glib.h>
+
+#include "pango-intset.h"
+
+#define ELEMENT_BITS (sizeof (guint) * CHAR_BIT)
+
+#define OFF_MASK (ELEMENT_BITS-1)
+#define SEG_MASK (~(OFF_MASK))
+
+PangoIntSet *
+pango_int_set_new (void)
+{
+ PangoIntSet *p = g_new (PangoIntSet, 1);
+ p->start = 0;
+ p->size = 0;
+ p->bits = 0;
+ return p;
+}
+
+static void
+pango_int_set_expand (PangoIntSet *g, int value)
+{
+ if (!g->bits)
+ {
+ g->bits = g_new (guint, 1);
+ g->bits[0] = 0;
+ g->start = (value & SEG_MASK);
+ g->size = 1;
+ return;
+ }
+
+ if (value < g->start)
+ {
+ int extra_space = ((g->start - value) & OFF_MASK) + 1;
+ int new_start = (value & SEG_MASK);
+ guint *new_bits = g_new (guint, extra_space + g->size);
+ memcpy (new_bits + extra_space, g->bits, g->size * sizeof (guint));
+ g_free (g->bits);
+ g->bits = new_bits;
+ memset (new_bits, 0, extra_space * sizeof (guint));
+ g->start = new_start;
+ g->size += extra_space;
+ return;
+ }
+
+ if (value >= (g->start + g->size * ELEMENT_BITS))
+ {
+ int extra_space = (((value - (g->start + g->size * ELEMENT_BITS)) &
+ OFF_MASK)) + 1;
+ g->bits = g_realloc (g->bits, (g->size + extra_space) * sizeof (guint));
+ memset (g->bits + g->size, 0, extra_space * sizeof (guint));
+ g->size += extra_space;
+ return;
+ }
+}
+
+void
+pango_int_set_add (PangoIntSet *g, int value)
+{
+ int offset;
+ pango_int_set_expand (g, value);
+ offset = value - g->start;
+ g->bits[offset / ELEMENT_BITS] |= (1 << (offset & (OFF_MASK)));
+}
+
+void
+pango_int_set_add_range (PangoIntSet *g, int start, int end)
+{
+ int i;
+
+ pango_int_set_add (g, start);
+
+ if (start != end)
+ pango_int_set_add (g, end);
+
+ if ((end - start) != 1)
+ for (i = start; i < end; i++)
+ pango_int_set_add (g, i);
+}
+
+gboolean
+pango_int_set_contains (PangoIntSet *g, int member)
+{
+ if (!g->bits)
+ return 0;
+
+ if (member < g->start)
+ return 0;
+
+ if (member >= (g->start + (g->size * ELEMENT_BITS)))
+ return 0;
+
+ return (g->bits[((member - g->start) / ELEMENT_BITS)] >>
+ (member & (ELEMENT_BITS-1))) & 1;
+}
+
+void
+pango_int_set_destroy (PangoIntSet *g)
+{
+ g_free (g->bits);
+ g_free (g);
+}
+
diff --git a/pango/pango-intset.h b/pango/pango-intset.h
new file mode 100644
index 00000000..68c419bc
--- /dev/null
+++ b/pango/pango-intset.h
@@ -0,0 +1,43 @@
+/* Pango
+ * pango-intset.h: Integer set
+ *
+ * Copyright (C) 2000 SuSE Linux Ltd
+ *
+ * Author: Robert Brady <rwb197@zepler.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * Licence as published by the Free Software Foundation; either
+ * version 2 of the Licence, 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 Licence for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * Licence along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PANGO_INTSET_H__
+#define __PANGO_INTSET_H__
+
+typedef struct _PangoIntSet PangoIntSet;
+PangoIntSet *pango_int_set_new (void);
+void pango_int_set_add (PangoIntSet *g,
+ int glyph);
+void pango_int_set_destroy (PangoIntSet *g);
+void pango_int_set_add_range (PangoIntSet *g,
+ int start,
+ int end);
+gboolean pango_int_set_contains (PangoIntSet *g,
+ int member);
+struct _PangoIntSet
+{
+ int start, size;
+ guint *bits;
+};
+
+#endif