diff options
author | Owen Taylor <otaylor@redhat.com> | 2001-04-16 23:22:20 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2001-04-16 23:22:20 +0000 |
commit | 682ff5ed998809507a412220fbd4a62038b84229 (patch) | |
tree | 6bff11d353ff3de74e5f3957f855428bec1fa122 /modules | |
parent | 41dfa1affadf9f34f38c2769a28b035afeda7ce6 (diff) | |
download | pango-682ff5ed998809507a412220fbd4a62038b84229.tar.gz |
Remove warning when using fallback shaping.
Mon Apr 16 19:20:12 2001 Owen Taylor <otaylor@redhat.com>
* modules/tamil/tamil-x.c: Remove warning when using fallback
shaping.
Mon Apr 16 19:14:00 2001 Owen Taylor <otaylor@redhat.com>
[ Patches from Vikram Subramanian to update Tamil shapers ]
* configure.in modules/tamil/tamil-xft.c modules/tamil/Makefile.am:
Xft/TT based Tamil rendering engine. Uses glyphs in the
private-use-area instead of proper OpenType tables.
* examples/HELLO.utf8: Add Tamil line
* examples/pangox.aliases: Add tamil fonts
* modules/tamil/tadefs.h modules/tamil/tamil-x.c: Update
to use PANGO_LIGATURE_HACK ligatures from BDF files instead
of a fixed encoding.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/tamil/Makefile.am | 56 | ||||
-rw-r--r-- | modules/tamil/tadefs.h | 131 | ||||
-rw-r--r-- | modules/tamil/tamil-x.c | 395 |
3 files changed, 372 insertions, 210 deletions
diff --git a/modules/tamil/Makefile.am b/modules/tamil/Makefile.am index fc84f81c..a0bf102f 100644 --- a/modules/tamil/Makefile.am +++ b/modules/tamil/Makefile.am @@ -1,21 +1,59 @@ ## Process this file with automake to create Makefile.in. -sources = tamil-x.c taconv.c taconv.h tadefs.h +if HAVE_XFT +XFT_MODULES=pango-tamil-xft.la +if INCLUDE_TAMIL_XFT +XFT_INCLUDED=libpango-tamil-xft.la +XFT_PREFIX=-DXFT_MODULE_PREFIX +else +XFT_INCLUDED= +XFT_PREFIX= +endif +else +XFT_MODULES= +XFT_INCLUDED= +XFT_PREFIX= +endif + +x_sources = \ + tamil-x.c \ + tadefs.h + +xft_sources = \ + tamil-xft.c \ + tadefs.h if HAVE_X if INCLUDE_TAMIL_X -noinst_LTLIBRARIES = libpango-tamil-x.la -moddefine = -DX_MODULE_PREFIX +X_MODULES= +X_INCLUDED=libpango-tamil-x.la +X_PREFIX=-DX_MODULE_PREFIX else -moduledir = $(libdir)/pango/modules -module_LTLIBRARIES = pango-tamil-x.la -moduleflags=-rpath $(libdir) +X_MODULES=pango-tamil-x.la +X_INCLUDED= +X_PREFIX= endif +else +X_MODULES= +X_INCLUDED= +X_PREFIX= endif -INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/pango/ $(moddefine) $(X_CFLAGS) +noinst_LTLIBRARIES = $(X_INCLUDED) $(XFT_INCLUDED) +module_LTLIBRARIES = $(X_MODULES) $(XFT_MODULES) +moddefine = $(X_PREFIX) $(XFT_PREFIX) +moduledir = $(libdir)/pango/modules +moduleflags=-rpath $(libdir) + +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/pango/ $(moddefine) $(X_CFLAGS) $(FREETYPE_CFLAGS) pango_tamil_x_la_LDFLAGS = $(moduleflags) -export-dynamic -avoid-version -module -pango_tamil_x_la_SOURCES = $(sources) +pango_tamil_x_la_SOURCES = $(x_sources) + +libpango_tamil_x_la_SOURCES = $(x_sources) + +pango_tamil_xft_la_LDFLAGS = -rpath $(libdir) -export-dynamic -avoid-version -module +pango_tamil_xft_la_LIBADD = +pango_tamil_xft_la_SOURCES = $(xft_sources) -libpango_tamil_x_la_SOURCES = $(sources) +libpango_tamil_xft_la_SOURCES = $(xft_sources) diff --git a/modules/tamil/tadefs.h b/modules/tamil/tadefs.h index 5e587471..bad92aec 100644 --- a/modules/tamil/tadefs.h +++ b/modules/tamil/tadefs.h @@ -1,39 +1,25 @@ -/* Author: Sivaraj D (sivaraj@tamil.net) - * Date : 4-Jan-2000 +/* Pango + * tadefs.h: + * + * Authors: Sivaraj D (sivaraj@tamil.net) + * Vikram Subramanian (upender@vsnl.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, 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 License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ -/* Defining Unicode unsigned characters */ - -unsigned int -u_uyir[] = { 0x0B85, 0x0B86, 0x0B87, 0x0B88, - 0x0B89, 0x0B8A, 0x0B8E, 0x0B8F, - 0x0B90, 0x0B92, 0x0B93, 0x0B94, - 0x0B83, 0x00A9, - 0x2018, 0x2019, 0x201c, 0x201D, - 0x0BE7, 0x0BE8, 0x0BE9, 0x0BEA, - 0x0BEB, 0x0BEC, 0x0BED, 0x0BEE, - 0x0BEF, 0x0BF0, 0x0BF1, 0x0BF2, - 0x0000 }; - -/* akaramEriya mey */ -unsigned int -u_amey[] = { 0x0B95, 0x0B99, 0x0B9A, 0x0B9E, - 0x0B9F, 0x0BA3, 0x0BA4, 0x0BA8, - 0x0BAA, 0x0BAE, 0x0BAF, 0x0BB0, - 0x0BB2, 0x0BB5, 0x0BB4, 0x0BB3, - 0x0BB1, 0x0BA9, 0x0B9C, 0x0BB7, - 0x0BB8, 0x0BB9, 0x0000 }; - -unsigned int -u_modi[] = { 0x0BBE, 0x0BBF, 0x0BC0, 0x0BC1, - 0x0BC2, 0x0BC6, 0x0BC7, 0x0BC8, - 0x0BCA, 0x0BCB, 0x0BCC, 0x0BCD, - 0x0BD7, 0x0000 }; - -unsigned int -u_grantha[] = { 0x0B9C, 0x0BB7, 0x0BB8, 0x0BB9, - 0x0000 }; - #define U_KAAL 0x0BBE #define U_KOKKI1 0x0BBF #define U_KOKKI2 0x0BC0 @@ -47,86 +33,15 @@ u_grantha[] = { 0x0B9C, 0x0BB7, 0x0BB8, 0x0BB9, #define U_AUMODI 0x0BCC #define U_AUMARK 0x0BD7 #define U_PULLI 0x0BCD - -#define U_SPACE 0x0020 -#define U_ZWSP 0x200B -#define U_LSQUOT 0x2018 -#define U_RSQUOT 0x2019 -#define U_LDQUOT 0x201C -#define U_RDQUOT 0x201D - -/* Defining TSCII unsigned characters - we define only those unsigned characters - * that are useful in Unicode */ - -#define SPACE 0x20 -/* Vowel modifiers */ -#define TSC_KAAL 0xA1 -#define TSC_KOKKI1 0xA2 -#define TSC_KOKKI2 0xA3 -#define TSC_UMODI1 0xA4 -#define TSC_UMODI2 0xA5 -#define TSC_KOMBU1 0xA6 -#define TSC_KOMBU2 0xA7 -#define TSC_AIMODI 0xA8 -#define TSC_AUMODI 0xAA +#define U_KA 0x0B95 -unsigned char -tsc_modi[] = { 0xA1, 0xA2, 0xA3, 0xA4, - 0xA5, 0xA6, 0xA7, 0xA8, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xAA, 0x00 }; - -/* all uyirs & aaytham: these convert directly to unicode */ -unsigned char -tsc_uyir[] = { 0xAB, 0xAC, 0xAD, 0xAE, /* a, aa, i, ii */ - 0xAF, 0xB0, 0xB1, 0xB2, /* u, uu, e, ee */ - 0xB3, 0xB4, 0xB5, 0xB6, /* ai, o, oo, au */ - 0xB7, 0xA9, /* aaytham, copyright*/ - 0x91, 0x92, 0x93, 0x94, /* quotes */ - 0x81, 0x8D, 0x8E, 0x8F, - 0x90, 0x95, 0x96, 0x97, - 0x98, 0x9D, 0x9E, 0x9F, - 0x00 }; +#define U_SPACE 0x0020 +#define U_ZWSP 0x200B -/* all mey */ -unsigned char -tsc_mey[] = { 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, - 0xF4, 0xF5, 0xF6, 0xF7, - 0xF8, 0xF9, 0xFA, 0xFB, - 0xFC, 0xFD, 0x88, 0x89, - 0x8A, 0x8B, 0x00 }; - -/* akaramEriya mey */ -unsigned char -tsc_amey[] = { 0xB8, 0xB9, 0xBA, 0xBB, - 0xBC, 0xBD, 0xBE, 0xBF, - 0xC0, 0xC1, 0xC2, 0xC3, - 0xC4, 0xC5, 0xC6, 0xC7, - 0xC8, 0xC9, 0x83, 0x84, - 0x85, 0x86, 0x00 }; -/* ikaram, iikaaram for T */ -#define TSC_TI 0xCA -#define TSC_TII 0xCB -/* ukaram, uukaaram & grantha ameys*/ -unsigned char -tsc_ukaram[] = { 0xCC, 0x99, 0xCD, 0x9A, - 0xCE, 0xCF, 0xD0, 0xD1, - 0xD2, 0xD3, 0xD4, 0xD5, - 0xD6, 0xD7, 0xD8, 0xD9, - 0xDA, 0xDB, 0x00 }; -unsigned char -tsc_uukaaram[] = { 0xDC, 0x9B, 0xDD, 0x9C, - 0xDE, 0xDF, 0xE0, 0xE1, - 0xE2, 0xE3, 0xE4, 0xE5, - 0xE6, 0xE7, 0xE8, 0xE9, - 0xEA, 0xEB, 0x00 }; -unsigned char -tsc_grantha[] = { 0x83, 0x84, 0x85, 0x86, 0x00 }; diff --git a/modules/tamil/tamil-x.c b/modules/tamil/tamil-x.c index db9bef4d..76cd7c25 100644 --- a/modules/tamil/tamil-x.c +++ b/modules/tamil/tamil-x.c @@ -1,19 +1,46 @@ -/* Pango - Tamil module - * tamil.c: +/* Pango + * tamil-x.c: * - * Copyright (C) 2000 Sivaraj D + * Authors: Sivaraj D (sivaraj@tamil.net) + * Vikram Subramanian (upender@vsnl.com) * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, 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 License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ +/* A version using Unicode based font with ligature information in it + * + * Vikram Subramanian <upender@vsnl.com> + */ #include <stdio.h> +#include <string.h> #include <glib.h> -#include "pangox.h" -#include "taconv.h" #include "pango-engine.h" -#include <string.h> +#include "pangox.h" +#include "tadefs.h" #define SCRIPT_ENGINE_NAME "TamilScriptEngineX" + +/* The charset for the font */ +static char *default_charset = "iso10646-tam"; + +/* Bitmap to test whether a char is a consonant */ +/** Remember to change this when adding KSHA later **/ +static const char cons_map[] = {0xB1, 0xC6, 0x38, 0xFE, 0x1D}; + static PangoEngineRange tamil_range[] = { { 0x0b80, 0x0bff, "*" }, }; @@ -29,50 +56,144 @@ static PangoEngineInfo script_engines[] = { static gint n_script_engines = G_N_ELEMENTS (script_engines); -/* - * X window system script engine portion - */ -/* We will need some type of kerning support for use with ikaram/iikaaram. - * But we can live with this for time being +/* Return non-zero if c is a akara mey, 0 otherwise */ -static void -set_glyph (PangoGlyphString *glyphs, int i, int cluster_start, - PangoFont *font, PangoXSubfont subfont, guint16 gindex) +int is_consonant (unsigned int c) { - PangoRectangle logical_rect; + /* Too many gaps between consonants - So use a bit map */ + /** KSHA might come at 0xBBA later ?? **/ + return ((c >= 0x0B95 && c <= 0x0BB9) && + (cons_map[(c - 0x0B95) >> 3] & (1 << ((c - 0xB95) & 7)))); +} - glyphs->glyphs[i].glyph = PANGO_X_MAKE_GLYPH (subfont, gindex); - - glyphs->glyphs[i].geometry.x_offset = 0; - glyphs->glyphs[i].geometry.y_offset = 0; +/* Return 1 if c is a modifier, 0 otherwise + */ +int is_modifier (unsigned int c) +{ + if ((c >= 0x0BBE && c <= 0x0BC2) || + (c >= 0x0BC6 && c <= 0x0BC8) || + (c >= 0x0BCA && c <= 0x0BCD) || + (c == 0x0BD7)) + return 1; + else + return 0; +} - glyphs->log_clusters[i] = cluster_start; - pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, NULL, &logical_rect); - glyphs->glyphs[i].geometry.width = logical_rect.width; +/* Remove unwanted U+0000 */ +void +tamil_compact (gunichar *chars, + int *num, + 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 PangoXSubfont -find_tscii_font (PangoFont *font) + +/* Apply the modifier to the base character to get the string of glyph + * indices + */ +void +apply_modifier (gunichar base, + gunichar modifier, + gunichar *glyph_str, + int *num_glyphs) { - char *charsets[] = { "tscii-0" }; - PangoXSubfont *subfonts; - int *subfont_charsets; - int n_subfonts; - PangoXSubfont result = 0; + + /* Modifier which appears as suffix */ + if ((modifier >= U_KAAL && modifier <= U_UMODI2) || + (modifier == U_PULLI)) + { + glyph_str[0] = base; + glyph_str[1] = modifier; + *num_glyphs = 2; + return; + } - n_subfonts = pango_x_list_subfonts (font, charsets, 1, &subfonts, &subfont_charsets); + /* Modifiers which appear as prefix */ + if (modifier >= U_KOMBU1 && modifier <= U_AIMODI) + { + glyph_str[0] = modifier; + glyph_str[1] = base; + *num_glyphs = 2; + return; + } + + /* Modifiers appearing as both suffix and prefix */ + if (modifier == U_OMODI1) + { + glyph_str[0] = U_KOMBU1; + glyph_str[1] = base; + glyph_str[2] = U_KAAL; + *num_glyphs = 3; + return; + } + + if (modifier == U_OMODI2) + { + glyph_str[0] = U_KOMBU2; + glyph_str[1] = base; + glyph_str[2] = U_KAAL; + *num_glyphs = 3; + return; + } + + if (modifier == U_AUMODI) + { + glyph_str[0] = U_KOMBU1; + glyph_str[1] = base; + glyph_str[2] = U_AUMARK; + *num_glyphs = 3; + return; + } + + /* U_AUMARK after a consonant?? */ + glyph_str[0] = base; + *num_glyphs = 1; +} - if (n_subfonts > 0) - result = subfonts[0]; - g_free (subfonts); - g_free (subfont_charsets); +/* + * X window system script engine portion + */ - return result; +/* Find a font of the reqd. charset + */ +static PangoXSubfont +find_tamil_font (PangoFont *font) +{ + PangoXSubfont result; + + if (pango_x_find_first_subfont (font, &default_charset, 1, &result)) + return result; + else + return 0; /* Could not find a font */ } + +/* Convert UTF-8 to glyph string + */ static void tamil_engine_shape (PangoFont *font, const char *text, @@ -81,72 +202,160 @@ tamil_engine_shape (PangoFont *font, PangoGlyphString *glyphs) { int n_chars, n_glyph; - int i, j; + int i; const char *cluster_start; const char *p; - gunichar *wc, *uni_str; - int res; - unsigned char tsc_str[6]; - int ntsc, nuni; - - PangoXSubfont tscii_font; - + gunichar *wc, prevchar,currchar; + int complete; /* Whether the prev char is gauranteed to be complete + i.e not modified by modifiers */ + int nuni; /* No. of unicode characters in a cluster */ + + PangoXSubfont tamil_font; + + g_return_if_fail (font != NULL); g_return_if_fail (text != NULL); g_return_if_fail (length >= 0); g_return_if_fail (analysis != NULL); - - tscii_font = find_tscii_font (font); - if (!tscii_font) - { - g_warning ("Cannot find a tscii font!\n"); - return; - } n_chars = g_utf8_strlen (text, length); - - /* temporarily set the size to 3 times the number of unicode chars */ - pango_glyph_string_set_size (glyphs, n_chars * 3); - - wc = (gunichar *)g_malloc(sizeof(gunichar)*n_chars); - - p = text; - for (i=0; i < n_chars; i++) + + tamil_font = find_tamil_font (font); + if (!tamil_font) { - wc[i] = g_utf8_get_char (p); - p = g_utf8_next_char (p); + pango_x_fallback_shape (font, glyphs, text, n_chars); + return; } + /* temporarily set the size to 2 times the number of unicode chars */ + pango_glyph_string_set_size (glyphs, n_chars * 2); + wc = (gunichar *)g_malloc (sizeof(gunichar) * n_chars * 2); + + p = text; + prevchar = 0;complete = 1;/* One character look behind */ n_glyph = 0; - uni_str = wc; - cluster_start = text; - j = 0; - while (j < n_chars) + + /* The following loop is similar to the indic engine's split out chars */ + for (i=0; i < n_chars; i++) { + + currchar = g_utf8_get_char (p); + + /* Two classes - Modifiers and Non-Modifiers */ + if (is_modifier (currchar)) + { + if (complete){ /* The previous char has been tagged complete already */ + + /* Leave the vowel sign itself in wc */ + /* Useful in lessons */ + wc[n_glyph] = currchar; + glyphs->log_clusters[n_glyph] = cluster_start - text; + + n_glyph++; + nuni = 1; + } + else + { /* Modify the previous char */ + int num_glyphs; + gunichar glyph_str[3]; + int k; + + /* Modify the previous char and get a glyph string */ + apply_modifier (prevchar,currchar,glyph_str,&num_glyphs); + + for (k = 0;k < num_glyphs;k++) + { + wc[n_glyph] = glyph_str[k]; + glyphs->log_clusters[n_glyph] = cluster_start - text; + + n_glyph++; + } + + /* 2 unicode chars in this just written cluster */ + nuni = 2; + } + complete = 1; /* A character has ended */ + + /* NOTE : Double modifiers are not handled but the display will be + * correct since the vowel sign is appended.However cluster info + * will be wrong. + */ + } + else + { /* Non-modifiers */ + + /* Write out the previous char which is waiting to get completed */ + if (!complete) + { + wc[n_glyph] = prevchar; + glyphs->log_clusters[n_glyph] = cluster_start - text; + + n_glyph++; + + /* Set the cluster start properly for the current char */ + cluster_start = g_utf8_next_char (cluster_start); + } + + /* Check the type of the current char further */ + if (is_consonant (currchar)) + { + prevchar = currchar; /* Store this consonant */ + complete = 0; /* May get modified */ + nuni = 0; /* NO unicode character written */ + + } + else + { + /* Vowels, numerals and other unhandled stuff come here */ + + /* Write it out then and there */ + wc[n_glyph] = currchar; + glyphs->log_clusters[n_glyph] = cluster_start - text; + + n_glyph++; + nuni = 1; + + complete = 1; /* A character has ended */ + } + } + + /* Set the beginning for the next cluster */ + while (nuni-- > 0) + cluster_start = g_utf8_next_char (cluster_start); + + p = g_utf8_next_char (p); + } + + /* Flush out the last char if waiting to get completed */ + if (!complete) { - res = uni2tsc(uni_str, tsc_str, &nuni, &ntsc, n_chars - j, 6); - - uni_str = uni_str + nuni; - /* We need to differentiate between different return codes later */ - if (res != TA_SUCCESS) - { - set_glyph (glyphs, n_glyph, cluster_start - text, font, tscii_font, ' '); - n_glyph++; - j = j + nuni; - continue; - } - for (i = 0; i < ntsc; i++) - { - set_glyph (glyphs, n_glyph, cluster_start - text, font, tscii_font, (PangoGlyph) tsc_str[i]); - n_glyph++; - } - j = j + nuni; - while (nuni--) - cluster_start = g_utf8_next_char (cluster_start); + wc[n_glyph] = currchar; + glyphs->log_clusters[n_glyph] = cluster_start - text; + + n_glyph++; } - + + /* Apply ligatures as specified in the X Font */ + pango_x_apply_ligatures (font, tamil_font, &wc, &n_glyph, + &glyphs->log_clusters); + + /* Remove unwanted U+0000 */ + tamil_compact (wc, &n_glyph, glyphs->log_clusters); + + /* Make glyphs */ pango_glyph_string_set_size (glyphs, n_glyph); - + + for (i = 0;i < n_glyph;i++) + { + PangoRectangle logical_rect; + glyphs->glyphs[i].glyph = PANGO_X_MAKE_GLYPH (tamil_font, wc[i]); + pango_font_get_glyph_extents (font, glyphs->glyphs[i].glyph, + NULL, &logical_rect); + glyphs->glyphs[i].geometry.x_offset = 0; + glyphs->glyphs[i].geometry.y_offset = 0; + glyphs->glyphs[i].geometry.width = logical_rect.width; + } + g_free(wc); } @@ -155,32 +364,33 @@ tamil_engine_get_coverage (PangoFont *font, const char *lang) { PangoCoverage *result = pango_coverage_new (); - - PangoXSubfont tscii_font = find_tscii_font (font); - if (tscii_font) + + PangoXSubfont tamil_font = find_tamil_font (font); + if (tamil_font) { gunichar i; - + for (i = 0xb80; i <= 0xbff; i++) pango_coverage_set (result, i, PANGO_COVERAGE_EXACT); } - + return result; } + static PangoEngine * tamil_engine_x_new () { PangoEngineShape *result; result = g_new (PangoEngineShape, 1); - + result->engine.id = SCRIPT_ENGINE_NAME; result->engine.type = PANGO_ENGINE_TYPE_SHAPE; result->engine.length = sizeof (result); result->script_shape = tamil_engine_shape; result->get_coverage = tamil_engine_get_coverage; - + return (PangoEngine *)result; } @@ -214,4 +424,3 @@ void MODULE_ENTRY(script_engine_unload) (PangoEngine *engine) { } - |