From 7977208460e03feacc1b621090ae66250c8e13e8 Mon Sep 17 00:00:00 2001 From: "jshin%mailaps.org" Date: Fri, 23 May 2003 06:31:25 +0000 Subject: [PATCH] bug 204039 : converter for TSCII fonts (r=prabhat, sr=rbs, a=asa) git-svn-id: svn://10.0.0.236/trunk@142803 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp | 7 + mozilla/gfx/src/gtk/nsFontMetricsXft.cpp | 1 + .../gfx/src/windows/fontEncoding.properties | 25 +- mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp | 7 + mozilla/intl/locale/src/langGroups.properties | 4 + mozilla/intl/uconv/src/charsetData.properties | 2 + mozilla/intl/uconv/src/nsUConvModule.cpp | 15 + mozilla/intl/uconv/ucvlatin/Makefile.in | 1 + mozilla/intl/uconv/ucvlatin/nsUCvLatinCID.h | 8 + .../intl/uconv/ucvlatin/nsUnicodeToTSCII.cpp | 535 ++++++++++++++++++ .../intl/uconv/ucvlatin/nsUnicodeToTSCII.h | 111 ++++ mozilla/intl/uconv/ucvlatin/tamil.h | 97 ++++ .../resources/content/pref-fonts.xul | 1 + .../resources/locale/en-US/pref-fonts.dtd | 1 + 14 files changed, 814 insertions(+), 1 deletion(-) create mode 100644 mozilla/intl/uconv/ucvlatin/nsUnicodeToTSCII.cpp create mode 100644 mozilla/intl/uconv/ucvlatin/nsUnicodeToTSCII.h create mode 100644 mozilla/intl/uconv/ucvlatin/tamil.h diff --git a/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp b/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp index 24b16e8ce56..d43b6832dba 100644 --- a/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp +++ b/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp @@ -352,6 +352,9 @@ static nsFontCharSetInfo JohabNoAscii = static nsFontCharSetInfo JamoTTF = { "x-koreanjamo-0", DoubleByteConvert, 1, TT_OS2_CPR1_KO_WANSUNG | TT_OS2_CPR1_KO_JOHAB, 0 }; +static nsFontCharSetInfo TamilTTF = + { "x-tamilttf-0", DoubleByteConvert, 0, + 0, 0 }; #ifdef SUNCTL /* Hindi range currently unsupported in FT2 range. Change TT* once we @@ -403,7 +406,10 @@ static nsFontLangGroup FLG_ZHCN = { "zh-CN", nsnull }; static nsFontLangGroup FLG_ZHTW = { "zh-TW", nsnull }; static nsFontLangGroup FLG_JA = { "ja", nsnull }; static nsFontLangGroup FLG_KO = { "ko", nsnull }; +#ifdef SUNCTL static nsFontLangGroup FLG_INDIC = { "x-devanagari", nsnull }; +#endif +static nsFontLangGroup FLG_TAMIL = { "x-tamil", nsnull }; static nsFontLangGroup FLG_NONE = { nsnull, nsnull }; /* @@ -552,6 +558,7 @@ static nsFontCharSetMap gCharSetMap[] = { "ucs2.cjk_korea-0", &FLG_KO, &ISO106461 }, { "ucs2.cjk_taiwan-0", &FLG_ZHTW, &ISO106461 }, { "ucs2.thai-0", &FLG_THAI, &ISO106461 }, + { "tamilttf-0", &FLG_TAMIL, &TamilTTF }, #ifdef SUNCTL { "sun.unicode.india-0",&FLG_INDIC, &SunIndic }, #endif /* SUNCTL */ diff --git a/mozilla/gfx/src/gtk/nsFontMetricsXft.cpp b/mozilla/gfx/src/gtk/nsFontMetricsXft.cpp index f3b127d0ed1..f4e538ee98e 100644 --- a/mozilla/gfx/src/gtk/nsFontMetricsXft.cpp +++ b/mozilla/gfx/src/gtk/nsFontMetricsXft.cpp @@ -104,6 +104,7 @@ static const MozXftLangGroup MozXftLangGroups[] = { { "x-cyrillic", 0x0411, (const FcChar8 *)"ru" }, { "x-baltic", 0x0104, (const FcChar8 *)"lv" }, { "x-devanagari", 0x0905, (const FcChar8 *)"hi" }, + { "x-tamil", 0x0B85, (const FcChar8 *)"ta" }, { "x-unicode", 0x0000, 0 }, { "x-user-def", 0x0000, 0 }, }; diff --git a/mozilla/gfx/src/windows/fontEncoding.properties b/mozilla/gfx/src/windows/fontEncoding.properties index 44af77c650e..138583cd513 100644 --- a/mozilla/gfx/src/windows/fontEncoding.properties +++ b/mozilla/gfx/src/windows/fontEncoding.properties @@ -79,10 +79,33 @@ encoding.math5monobold.ttf = x-mathematica5 # MathType Extra encoding.mtextra.ttf = x-mtextra -# Korean Jamo TTFs # The suffix '.wide' has to be added to encoding names to identify # these fonts as 'wide' non-Unicode fonts. + +# Korean Jamo TTFs encoding.unbatang.ttf = x-koreanjamo-0.wide # For the Korean locale, Korean family names have to be # listed in UTF-8. encoding.은바탕.ttf = x-koreanjamo-0.wide + +# Tamil fonts (TSCII encoding : see http://www.tamil.net/tscii) +# See also http://bugzilla.mozilla.org/show_bug.cgi?id=204039. +# These fonts have pseudo-Unicode cmap with TSCII interpreted as Windows-1252. +# On Win2k/XP, you may wish to comment all these out because the native +# OS support of Tamil script is superior to Mozilla's internal support. +# On Win9x/ME, there's no native OS support of Tamil script so that +# you need these lines definitely. +encoding.tsc_paranarpdf.ttf = x-tamilttf-0.wide +encoding.tsc_paranbold.ttf = x-tamilttf-0.wide +encoding.tsc_paranarho.ttf = x-tamilttf-0.wide +encoding.tsc_kannadaasan.ttf = x-tamilttf-0.wide +encoding.tscu_comic.ttf = x-tamilttf-0.wide +encoding.tscu_times.ttf = x-tamilttf-0.wide +encoding.tscu_paranar.ttf = x-tamilttf-0.wide +encoding.tscu_paranarbold.ttf = x-tamilttf-0.wide + + +# These two fonts don't have Unicode cmap but have pseudo-Apple Roman cmap +# with TSCII assignment. +encoding.tsc_aandaal.ttf = x-tscii +encoding.tsc_aparanarpdf.ttf = x-tscii diff --git a/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp b/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp index 7a4f12a7177..9ac1c49463a 100644 --- a/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp +++ b/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp @@ -420,6 +420,9 @@ static nsFontCharSetInfoXlib JohabNoAscii = static nsFontCharSetInfoXlib JamoTTF = { "x-koreanjamo-0", DoubleByteConvert, 1, TT_OS2_CPR1_KO_WANSUNG | TT_OS2_CPR1_KO_JOHAB, 0 }; +static nsFontCharSetInfoXlib TamilTTF = + { "x-tamilttf-0", DoubleByteConvert, 1, + 0, 0 }; #ifdef SUNCTL /* Hindi range currently unsupported in FT2 range. Change TT* once we @@ -471,7 +474,10 @@ static nsFontLangGroupXlib FLG_ZHCN = { "zh-CN", nsnull }; static nsFontLangGroupXlib FLG_ZHTW = { "zh-TW", nsnull }; static nsFontLangGroupXlib FLG_JA = { "ja", nsnull }; static nsFontLangGroupXlib FLG_KO = { "ko", nsnull }; +#ifdef SUNCTL static nsFontLangGroupXlib FLG_INDIC = { "x-devanagari", nsnull }; +#endif +static nsFontLangGroupXlib FLG_TAMIL = { "x-tamil", nsnull }; static nsFontLangGroupXlib FLG_NONE = { nsnull, nsnull }; /* @@ -620,6 +626,7 @@ static const nsFontCharSetMapXlib gConstCharSetMap[] = { "ucs2.cjk_korea-0", &FLG_KO, &ISO106461 }, { "ucs2.cjk_taiwan-0", &FLG_ZHTW, &ISO106461 }, { "ucs2.thai-0", &FLG_THAI, &ISO106461 }, + { "tamilttf-0", &FLG_TAMIL, &TamilTTF }, #ifdef SUNCTL { "sun.unicode.india-0",&FLG_INDIC, &SunIndic }, #endif /* SUNCTL */ diff --git a/mozilla/intl/locale/src/langGroups.properties b/mozilla/intl/locale/src/langGroups.properties index 41618a9d468..9f40237a4c0 100644 --- a/mozilla/intl/locale/src/langGroups.properties +++ b/mozilla/intl/locale/src/langGroups.properties @@ -55,6 +55,10 @@ sl=x-central-euro sq=x-western sr=x-cyrillic sv=x-western +ta=x-tamil +# to be remapped to x-tamil when bug 204586 is resolved and fontconfig +# with the revised ta.orth file is widely deployed (fontconfig bug #84) +#ta=x-unicode th=th tr=tr uk=x-cyrillic diff --git a/mozilla/intl/uconv/src/charsetData.properties b/mozilla/intl/uconv/src/charsetData.properties index 8642c9717d1..22de164db28 100644 --- a/mozilla/intl/uconv/src/charsetData.properties +++ b/mozilla/intl/uconv/src/charsetData.properties @@ -134,6 +134,8 @@ x-mac-arabic.LangGroup = ar x-iso-8859-6-8-x.LangGroup = ar x-iso-8859-6-16.LangGroup = ar x-sun-unicode-india-0.LangGroup = x-devanagari +x-tscii.LangGroup = x-tamil +x-tamilttf-0.LangGroup = x-tamil utf-8.MIMEHeaderEncodingMethod = B utf-8.MIMEMailCharset = utf-8 diff --git a/mozilla/intl/uconv/src/nsUConvModule.cpp b/mozilla/intl/uconv/src/nsUConvModule.cpp index f791676d152..ad683945cfc 100644 --- a/mozilla/intl/uconv/src/nsUConvModule.cpp +++ b/mozilla/intl/uconv/src/nsUConvModule.cpp @@ -203,6 +203,7 @@ #include "nsUnicodeToMacGujarati.h" #include "nsUnicodeToMacGurmukhi.h" #include "nsUnicodeToMacHebrew.h" +#include "nsUnicodeToTSCII.h" #ifdef MOZ_EXTRA_X11CONVERTERS #include "nsUnicodeToLangBoxArabic8.h" #include "nsUnicodeToLangBoxArabic16.h" @@ -374,6 +375,8 @@ NS_UCONV_REG_UNREG("x-mac-hebrew" , NS_MACHEBREWTOUNICODE_CID, NS_UNICODETOMACHE NS_UCONV_REG_UNREG_ENCODER("UTF-16" , NS_UNICODETOUTF16_CID) NS_UCONV_REG_UNREG_ENCODER("Adobe-Symbol-Encoding" , NS_UNICODETOSYMBOL_CID) NS_UCONV_REG_UNREG_ENCODER("x-zapf-dingbats" , NS_UNICODETOZAPFDINGBATS_CID) +NS_UCONV_REG_UNREG_ENCODER("x-tscii", NS_UNICODETOTSCII_CID) +NS_UCONV_REG_UNREG_ENCODER("x-tamilttf-0", NS_UNICODETOTAMILTTF_CID) #ifdef MOZ_EXTRA_X11CONVERTERS NS_UCONV_REG_UNREG_ENCODER("x-iso-8859-6-8-x" , NS_UNICODETOLANGBOXARABIC_CID) NS_UCONV_REG_UNREG_ENCODER("x-iso-8859-6-16" , NS_UNICODETOLANGBOXARABIC16_CID) @@ -471,6 +474,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToUTF16LE); NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToUTF16); NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToUTF32BE); NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToUTF32LE); +NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToTSCII); +NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToTamilTTF); #ifdef MOZ_EXTRA_X11CONVERTERS NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToLangBoxArabic8); NS_GENERIC_FACTORY_CONSTRUCTOR(nsUnicodeToLangBoxArabic16); @@ -1380,6 +1385,16 @@ static const nsModuleComponentInfo components[] = NS_UNICODEENCODER_CONTRACTID_BASE "x-mac-hebrew", nsUnicodeToMacHebrewConstructor, }, + { + ENCODER_NAME_BASE "x-tscii" , NS_UNICODETOTSCII_CID, + NS_UNICODEENCODER_CONTRACTID_BASE "x-tscii", + nsUnicodeToTSCIIConstructor, + }, + { + ENCODER_NAME_BASE "x-tamilttf-0" , NS_UNICODETOTAMILTTF_CID, + NS_UNICODEENCODER_CONTRACTID_BASE "x-tamilttf-0", + nsUnicodeToTamilTTFConstructor, + }, #ifdef MOZ_EXTRA_X11CONVERTERS { ENCODER_NAME_BASE "x-iso-8859-6-8-x" , NS_UNICODETOLANGBOXARABIC_CID, diff --git a/mozilla/intl/uconv/ucvlatin/Makefile.in b/mozilla/intl/uconv/ucvlatin/Makefile.in index bab664794af..e6d2298733a 100644 --- a/mozilla/intl/uconv/ucvlatin/Makefile.in +++ b/mozilla/intl/uconv/ucvlatin/Makefile.in @@ -159,6 +159,7 @@ CPPSRCS = \ nsUnicodeToSymbol.cpp \ nsUnicodeToZapfDingbat.cpp \ nsUnicodeToAdobeEuro.cpp \ + nsUnicodeToTSCII.cpp \ $(NULL) ifdef MOZ_EXTRA_X11CONVERTERS diff --git a/mozilla/intl/uconv/ucvlatin/nsUCvLatinCID.h b/mozilla/intl/uconv/ucvlatin/nsUCvLatinCID.h index 831e42346b2..77ad82b94c8 100644 --- a/mozilla/intl/uconv/ucvlatin/nsUCvLatinCID.h +++ b/mozilla/intl/uconv/ucvlatin/nsUCvLatinCID.h @@ -663,6 +663,14 @@ #define NS_UNICODETOMACGURMUKHI_CID \ { 0x6803cacf, 0x1e3b, 0x11d5, { 0xa1, 0x45, 0x0, 0x50, 0x4, 0x83, 0x21, 0x42 } } +// {d2800356-c2d7-4e05-a884-79fe566af1cf} +#define NS_UNICODETOTSCII_CID \ + { 0xd2800356, 0xc2d7, 0x4e05, { 0xa8, 0x84, 0x79, 0xfe, 0x56, 0x6a, 0xf1, 0xcf} } + +// {a431b276-f77d-4b83-9b37-872cf2fbcc2a} +#define NS_UNICODETOTAMILTTF_CID \ + { 0xa431b276, 0xf77d, 0x4b83, {0x9b, 0x37, 0x87, 0x2c, 0xf2, 0xfb, 0xcc, 0x2a } } + #ifdef MOZ_EXTRA_X11CONVERTERS // {4DBBD94F-0153-44cb-966A-7F39B9CB477D} #define NS_UNICODETOLANGBOXARABIC_CID \ diff --git a/mozilla/intl/uconv/ucvlatin/nsUnicodeToTSCII.cpp b/mozilla/intl/uconv/ucvlatin/nsUnicodeToTSCII.cpp new file mode 100644 index 00000000000..07aefaad18a --- /dev/null +++ b/mozilla/intl/uconv/ucvlatin/nsUnicodeToTSCII.cpp @@ -0,0 +1,535 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:expandtab:shiftwidth=2:tabstop=2: + */ +/* ***** BEGIN LICENSE BLOCK ***** + ** Version: MPL 1.1/GPL 2.0/LGPL 2.1 + ** + ** The contents of this file are subject to the Mozilla Public License Version + ** 1.1 (the "License"); you may not use this file except in compliance with + ** the License. You may obtain a copy of the License at + ** http://www.mozilla.org/MPL/ + ** + ** Software distributed under the License is distributed on an "AS IS" basis, + ** WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + ** for the specific language governing rights and limitations under the + ** License. + ** + ** The Original Code is GNU C Library code (http://www.gnu.org) + ** + ** The Initial Developer of the Original Code is + ** Bruno Haible . + ** Portions created by the Initial Developer are Copyright (C) 2002 + ** the Free Software Foundation. All Rights Reserved. + ** + ** Contributor(s): + ** Jungshik Shin + ** + ** Alternatively, the contents of this file may be used under the terms of + ** either the GNU General Public License Version 2 or later (the "GPL"), or + ** the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + ** in which case the provisions of the GPL or the LGPL are applicable instead + ** of those above. If you wish to allow use of your version of this file only + ** under the terms of either the GPL or the LGPL, and not to allow others to + ** use your version of this file under the terms of the MPL, indicate your + ** decision by deleting the provisions above and replace them with the notice + ** and other provisions required by the GPL or the LGPL. If you do not delete + ** the provisions above, a recipient may use your version of this file under + ** the terms of any one of the MPL, the GPL or the LGPL. + ** + ** ***** END LICENSE BLOCK ***** */ + +#include "nsUnicodeToTSCII.h" +#include "nsMemory.h" +#include "tamil.h" + +/* + * TSCII is an 8-bit encoding consisting of: + * 0x00..0x7F: ASCII + * 0x80..0x90, 0x95..0x9F, 0xAB..0xFE: + * Tamil letters and glyphs + * 0xA1..0xA5, 0xAA: Tamil combining letters (after the base character) + * 0xA6..0xA8: Tamil combining letters (before the base character) + * 0x91..0x94: Punctuation + * 0xA9: Symbols + */ + +//---------------------------------------------------------------------- +// Class nsUnicodeToTSCII [implementation] + +NS_IMPL_ISUPPORTS2(nsUnicodeToTSCII, nsIUnicodeEncoder, nsICharRepresentable); + +/* + * During UCS-4 to TSCII conversion, mState contains + * the last byte (or sometimes the last two bytes) to be output. + * This can be: + * 0x00 Nothing pending. + * 0xB8..0xC9, 0x83..0x86 A consonant. + * 0xEC, 0x8A A consonant with VIRAMA sign (final or joining). + * 0x87, 0xC38A Two consonants combined through a VIRAMA sign. + */ + +static const PRUint8 UnicharToTSCII[] = +{ + 0, 0, 0, 0xb7, 0, 0xab, 0xac, 0xfe, // 0x0B80..0x0B87 + 0xae, 0xaf, 0xb0, 0, 0, 0, 0xb1, 0xb2, // 0x0B88..0x0B8F + 0xb3, 0, 0xb4, 0xb5, 0xb6, 0xb8, 0, 0, // 0x0B90..0x0B97 + 0, 0xb9, 0xba, 0, 0x83, 0, 0xbb, 0xbc, // 0x0B98..0x0B9F + 0, 0, 0, 0xbd, 0xbe, 0, 0, 0, // 0x0BA0..0x0BA7 + 0xbf, 0xc9, 0xc0, 0, 0, 0, 0xc1, 0xc2, // 0x0BA8..0x0BAF + 0xc3, 0xc8, 0xc4, 0xc7, 0xc6, 0xc5, 0, 0x84, // 0x0BB0..0x0BB7 + 0x85, 0x86, 0, 0, 0, 0, 0xa1, 0xa2, // 0x0BB8..0x0BBF + 0xa3, 0xa4, 0xa5, 0, 0, 0, 0xa6, 0xa7, // 0x0BC0..0x0BC7 + 0xa8, 0, 0, 0, 0, 0, 0, 0, // 0x0BC8..0x0BCF + 0, 0, 0, 0, 0, 0, 0, 0xaa, // 0x0BD0..0x0BD7 + 0, 0, 0, 0, 0, 0, 0, 0, // 0x0BD8..0x0BDF + 0, 0, 0, 0, 0, 0, 0x80, 0x81, // 0x0BE0..0x0BE7 + 0x8d, 0x8e, 0x8f, 0x90, 0x95, 0x96, 0x97, 0x98, // 0x0BE8..0x0BEF + 0x9d, 0x9e, 0x9f, 0, 0, 0, 0, 0, // 0x0BF0..0x0BF7 + 0, 0, 0, 0, 0, 0, 0, 0 // 0x0BF8..0x0BFF +}; + +static const PRUint8 consonant_with_u[] = +{ + 0xcc, 0x99, 0xcd, 0x9a, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, + 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb +}; + +static const PRUint8 consonant_with_uu[] = +{ + 0xdc, 0x9b, 0xdd, 0x9c, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb +}; + +static const PRUint8 consonant_with_virama[18] = +{ + 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, + 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd +}; + + +// Modified implementation of Unicode to TSCII converter in glibc by +// Bruno Haible. My modifications are based on Unicode 3.0 chap. 9 and +// the code chart for Tamil. +NS_IMETHODIMP +nsUnicodeToTSCII::Convert(const PRUnichar * aSrc, PRInt32 * aSrcLength, + char * aDest, PRInt32 * aDestLength) +{ + const PRUnichar * src = aSrc; + const PRUnichar * srcEnd = aSrc + *aSrcLength; + char * dest = aDest; + char * destEnd = dest + *aDestLength; + + nsresult rv = NS_OK; + + while (src < srcEnd && dest < destEnd) { + PRUnichar ch = *src; + if (mBuffer) { + // Attempt to combine the last character with this one. + PRUint32 last = mBuffer; + + // last : consonant + if (IS_TSC_CONSONANT(last)) { + if (ch == UNI_VOWELSIGN_U && IS_TSC_CONSONANT1(last)) { + *dest++ = consonant_with_u[last - TSC_KA]; + mBuffer = 0; + ++src; + continue; + } + + if (ch == UNI_VOWELSIGN_UU && IS_TSC_CONSONANT1(last)) { + *dest++ = consonant_with_uu[last - TSC_KA]; + mBuffer = 0; + ++src; + continue; + } + + // reorder. vowel sign goes to the left of consonant + if (IS_UNI_LEFT_VOWELSIGN(ch)) { + if (dest + 2 > destEnd) + goto error_more_output; + *dest++ = TSC_LEFT_VOWELSIGN(ch); + *dest++ = last; + mBuffer = 0; + ++src; + continue; + } + + // split and reorder. consonant goes bet. two parts + if (IS_UNI_2PARTS_VOWELSIGN(ch)) { + if (dest + 3 > destEnd) + goto error_more_output; + *dest++ = TSC_LEFT_VOWEL_PART(ch); + *dest++ = last; + *dest++ = TSC_RIGHT_VOWEL_PART(ch); + mBuffer = 0; + ++src; + continue; + } + + // Virama + if (ch == UNI_VIRAMA) { + // consonant KA can form a conjunct with consonant SSA(SHA). + // buffer dead consonant 'K' for the now. + if (last == TSC_KA) { + mBuffer = TSC_KA_DEAD; + } + // SA can form a conjunct when followed by 'RA'. + // buffer dead consonant 'S' for the now. + else if (last == TSC_SA) { + mBuffer = TSC_SA_DEAD; + } + else { + *dest++ = IS_TSC_CONSONANT1(last) ? + consonant_with_virama[last - TSC_KA] : last + 5; + mBuffer = 0; + } + ++src; + continue; + } + + // consonant TA forms a ligature with vowel 'I' or 'II'. + if (last == TSC_TA && (ch == UNI_VOWELSIGN_I || ch == UNI_VOWELSIGN_II)) { + *dest++ = ch - (UNI_VOWELSIGN_I - TSC_TI_LIGA); + mBuffer = 0; + ++src; + continue; + } + } + else if (last == TSC_KA_DEAD) { + // Kd + SSA = K.SSA + if (ch == UNI_SSA) { + mBuffer = TSC_KSSA; + ++src; + continue; + } + } + else if (last == TSC_SA_DEAD) { + // Sd + RA = S.RA. Buffer RA + Sd. + if (ch == UNI_RA) { + mBuffer = 0xc38a; + ++src; + continue; + } + } + else if (last == TSC_KSSA) { + if (ch == UNI_VIRAMA) { + *dest++ = TSC_KSSA_DEAD; + mBuffer = 0; + ++src; + continue; + } + + // vowel splitting/reordering should be done around conjuncts as well. + // reorder. vowel sign goes to the left of consonant + if (IS_UNI_LEFT_VOWELSIGN(ch)) { + if (dest + 2 > destEnd) + goto error_more_output; + *dest++ = TSC_LEFT_VOWELSIGN(ch); + *dest++ = last; + mBuffer = 0; + ++src; + continue; + } + + // split and reorder. consonant goes bet. two parts + if (IS_UNI_2PARTS_VOWELSIGN(ch)) { + if (dest + 3 > destEnd) + goto error_more_output; + *dest++ = TSC_LEFT_VOWEL_PART(ch); + *dest++ = last; + *dest++ = TSC_RIGHT_VOWEL_PART(ch); + mBuffer = 0; + ++src; + continue; + } + } + else { + NS_ASSERTION(last == 0xc38a, "No other value can be buffered"); + if (ch == UNI_VOWELSIGN_II) { + *dest++ = TSC_SRII_LIGA; + mBuffer = 0; + ++src; + continue; + } + else { + // put back TSC_SA_DEAD and TSC_RA + *dest++ = TSC_SA_DEAD; + mBuffer = TSC_RA; + ++src; + continue; + } + } + + /* Output the buffered character. */ + if (last >> 8) { + if (dest + 2 > destEnd) + goto error_more_output; + *dest++ = last & 0xff; + *dest++ = (last >> 8) & 0xff; + } + else + *dest++ = last & 0xff; + mBuffer = 0; + continue; + } + + if (ch < 0x80) // Plain ASCII character. + *dest++ = ch; + else if (IS_UNI_TAMIL(ch)) { + PRUint8 t = UnicharToTSCII[ch - UNI_TAMIL_START]; + + if (t != 0) { + if (IS_TSC_CONSONANT(t)) + mBuffer = (PRUint32) t; + else + *dest++ = t; + } + else if (IS_UNI_2PARTS_VOWELSIGN(ch)) { + // actually this is an illegal sequence. + if (dest + 2 > destEnd) + goto error_more_output; + + *dest++ = TSC_LEFT_VOWEL_PART(ch); + *dest++ = TSC_RIGHT_VOWEL_PART(ch); + } + else { + *aDestLength = dest - aDest; + return NS_ERROR_UENC_NOMAPPING; + } + } + else if (ch == 0x00A9) + *dest++ = ch; + else if (IS_UNI_SINGLE_QUOTE(ch)) + *dest++ = ch - UNI_LEFT_SINGLE_QUOTE + TSC_LEFT_SINGLE_QUOTE; + else if (IS_UNI_DOUBLE_QUOTE(ch)) + *dest++ = ch - UNI_LEFT_DOUBLE_QUOTE + TSC_LEFT_DOUBLE_QUOTE; + else { + *aDestLength = dest - aDest; + return NS_ERROR_UENC_NOMAPPING; + } + + /* Now that we wrote the output increment the input pointer. */ + ++src; + } + + // flush the buffer + if (mBuffer >> 8) { + // Write out the last character, two bytes. + if (dest + 2 > destEnd) + goto error_more_output; + *dest++ = (mBuffer >> 8) & 0xff; + *dest++ = mBuffer & 0xff; + mBuffer = 0; + } + else if (mBuffer) { + // Write out the last character, a single byte. + if (dest >= destEnd) + goto error_more_output; + *dest++ = mBuffer & 0xff; + mBuffer = 0; + } + + *aSrcLength = src - aSrc; + *aDestLength = dest - aDest; + return rv; + +error_more_output: + *aSrcLength = src - aSrc; + *aDestLength = dest - aDest; + return NS_OK_UENC_MOREOUTPUT; +} + +NS_IMETHODIMP +nsUnicodeToTSCII::Finish(char* aDest, PRInt32* aDestLength) +{ + if (!mBuffer) { + *aDestLength = 0; + return NS_OK; + } + + if (mBuffer >> 8) { + // Write out the last character, two bytes. + if (*aDestLength < 2) { + *aDestLength = 0; + return NS_OK_UENC_MOREOUTPUT; + } + *aDest++ = (mBuffer >> 8) & 0xff; + *aDest++ = mBuffer & 0xff; + mBuffer = 0; + *aDestLength = 2; + } + else { + // Write out the last character, a single byte. + if (*aDestLength < 1) { + *aDestLength = 0; + return NS_OK_UENC_MOREOUTPUT; + } + *aDest++ = mBuffer & 0xff; + mBuffer = 0; + *aDestLength = 1; + } + return NS_OK; +} + +//================================================================ +NS_IMETHODIMP +nsUnicodeToTSCII::Reset() +{ + mBuffer = 0; + return NS_OK; +} + +NS_IMETHODIMP +nsUnicodeToTSCII::GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength, + PRInt32 * aDestLength) +{ + // Some Tamil letters can be decomposed into 2 glyphs in TSCII. + *aDestLength = aSrcLength * 2; + return NS_OK; +} + + +NS_IMETHODIMP +nsUnicodeToTSCII::FillInfo(PRUint32* aInfo) +{ + // Tamil block is so sparse. + static const PRUint8 coverage[] = { + 0xe8, // 11101000 U+0B87 - U+0B80 + 0xc7, // 11000111 U+0B8F - U+0B88 + 0x3d, // 00111101 U+0B97 - U+0B90 + 0xd6, // 11010110 U+0B9F - U+0B98 + 0x18, // 00011000 U+0BA7 - U+0BA0 + 0xc7, // 11000111 U+0BAF - U+0BA8 + 0xbf, // 10111111 U+0BB7 - U+0BB0 + 0xc7, // 11000111 U+0BBF - U+0BB8 + 0xc7, // 11000111 U+0BC7 - U+0BC0 + 0x3d, // 00111101 U+0BCF - U+0BC8 + 0x80, // 10000000 U+0BD7 - U+0BD0 + 0x00, // 00000000 U+0BDF - U+0BD8 + 0x80, // 10000000 U+0BE7 - U+0BE0 + 0xff, // 11111111 U+0BEF - U+0BE8 + 0x07, // 00000111 U+0BF7 - U+0BF0 + }; + + PRUnichar i; + for(i = 0; i < 0x78; i++) + if (coverage[i / 8] & (1 << (i % 8))) + SET_REPRESENTABLE(aInfo, i + UNI_TAMIL_START); + + // TSCII is a superset of US-ASCII. + for(i = 0x20; i < 0x7f; i++) + SET_REPRESENTABLE(aInfo, i); + + // additional characters in TSCII + SET_REPRESENTABLE(aInfo, 0xA9); // copyright sign + SET_REPRESENTABLE(aInfo, UNI_LEFT_SINGLE_QUOTE); + SET_REPRESENTABLE(aInfo, UNI_RIGHT_SINGLE_QUOTE); + SET_REPRESENTABLE(aInfo, UNI_LEFT_DOUBLE_QUOTE); + SET_REPRESENTABLE(aInfo, UNI_RIGHT_DOUBLE_QUOTE); + + return NS_OK; +} + +NS_IMETHODIMP +nsUnicodeToTSCII::SetOutputErrorBehavior(PRInt32 aBehavior, + nsIUnicharEncoder *aEncoder, + PRUnichar aChar) +{ + return NS_OK; +} + + +// same as the mapping of the C1(0x80-0x9f) part of Windows-1252 to Unicode +const static PRUnichar gTSCIIToTTF[] = { + 0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, + 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F, + 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, + 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178 +}; + +//---------------------------------------------------------------------- +// Class nsUnicodeToTamilTTF [implementation] +// +NS_IMPL_ISUPPORTS_INHERITED0(nsUnicodeToTamilTTF, nsUnicodeToTSCII) + +NS_IMETHODIMP +nsUnicodeToTamilTTF::Convert(const PRUnichar * aSrc, + PRInt32 * aSrcLength, char * aDest, + PRInt32 * aDestLength) +{ + + PRInt32 medLen, destLen; + char *med; + + GetMaxLength(aSrc, *aSrcLength, &destLen); + NS_ASSERTION(destLen <= *aDestLength, "insufficient dest. buffer size"); + + // TSCII converter is a single byte encoder and takes half the space + // taken by TamilTTF encoder. + medLen = destLen / 2; + + if (medLen > CHAR_BUFFER_SIZE) { + med = (char *) nsMemory::Alloc(medLen); + if (!med) + return NS_ERROR_OUT_OF_MEMORY; + } + else + med = mStaticBuffer; + + nsresult rv = nsUnicodeToTSCII::Convert(aSrc, aSrcLength, med, &medLen); + + if (NS_FAILED(rv)) { + if (med != mStaticBuffer) + nsMemory::Free(med); + return rv; + } + + PRInt32 i, j; + + // widen 8bit TSCII to pseudo-Unicode font encoding of TSCII-Tamil font + for (i = 0, j = 0; i < medLen; i++) { + // Only C1 part(0x80-0x9f) needs to be mapped as if they're CP1251. + PRUnichar ucs2 = (med[i] & 0xe0) == 0x80 ? + gTSCIIToTTF[med[i] & 0x7f] : PRUint8(med[i]); + // A lot of TSCII fonts are still based on TSCII 1.6 so that + // they have Tamil vowel 'I' at 0xad instead of 0xfe. + if (ucs2 == 0xfe) ucs2 = 0xad; + aDest[j++] = PRUint8((ucs2 & 0xff00) >> 8); + aDest[j++] = PRUint8(ucs2 & 0x00ff); + } + + *aDestLength = j; + + if (med != mStaticBuffer) + nsMemory::Free(med); + + return NS_OK; +} + +NS_IMETHODIMP +nsUnicodeToTamilTTF::GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength, PRInt32 * aDestLength) +{ + // Each Tamil character can generate at most two presentation forms, + // but we're 'extending' them to 16bit shorts, which accounts for + // additional factor of 2. + *aDestLength = (aSrcLength + 1) * 4; + + return NS_OK; +} + +NS_IMETHODIMP +nsUnicodeToTamilTTF::SetOutputErrorBehavior(PRInt32 aBehavior, + nsIUnicharEncoder *aEncoder, + PRUnichar aChar) +{ + if (aBehavior == kOnError_CallBack && aEncoder == nsnull) + return NS_ERROR_NULL_POINTER; + NS_IF_RELEASE(aEncoder); + mErrEncoder = aEncoder; + NS_IF_ADDREF(aEncoder); + + mErrBehavior = aBehavior; + mErrChar = aChar; + return NS_OK; +} + diff --git a/mozilla/intl/uconv/ucvlatin/nsUnicodeToTSCII.h b/mozilla/intl/uconv/ucvlatin/nsUnicodeToTSCII.h new file mode 100644 index 00000000000..ff1b6ecb1f1 --- /dev/null +++ b/mozilla/intl/uconv/ucvlatin/nsUnicodeToTSCII.h @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:expandtab:shiftwidth=2:tabstop=2: + */ +/* ***** BEGIN LICENSE BLOCK ***** + ** Version: MPL 1.1/GPL 2.0/LGPL 2.1 + ** + ** The contents of this file are subject to the Mozilla Public License Version + ** 1.1 (the "License"); you may not use this file except in compliance with + ** the License. You may obtain a copy of the License at + ** http://www.mozilla.org/MPL/ + ** + ** Software distributed under the License is distributed on an "AS IS" basis, + ** WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + ** for the specific language governing rights and limitations under the + ** License. + ** + ** The Original Code is Mozilla Communicator client code. + ** + ** The Initial Developer of the Original Code is + ** Netscape Communications Corp. + ** Portions created by the Initial Developer are Copyright (C) 1998, 2003 + ** the Initial Developer. All Rights Reserved. + ** + ** Contributor(s): + ** Jungshik Shin . + ** + ** Alternatively, the contents of this file may be used under the terms of + ** either the GNU General Public License Version 2 or later (the "GPL"), or + ** the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + ** in which case the provisions of the GPL or the LGPL are applicable instead + ** of those above. If you wish to allow use of your version of this file only + ** under the terms of either the GPL or the LGPL, and not to allow others to + ** use your version of this file under the terms of the MPL, indicate your + ** decision by deleting the provisions above and replace them with the notice + ** and other provisions required by the GPL or the LGPL. If you do not delete + ** the provisions above, a recipient may use your version of this file under + ** the terms of any one of the MPL, the GPL or the LGPL. + ** + ** ***** END LICENSE BLOCK ***** */ + +#ifndef nsUnicodeToTSCII_h___ +#define nsUnicodeToTSCII_h___ + +#include "nsISupports.h" +#include "nsIUnicodeEncoder.h" +#include "nsICharRepresentable.h" + +//---------------------------------------------------------------------- +// Class nsUnicodeToTSCII [declaration] + +class nsUnicodeToTSCII : public nsIUnicodeEncoder, public nsICharRepresentable +{ + +NS_DECL_ISUPPORTS + +public: + nsUnicodeToTSCII() { mBuffer = 0; }; + virtual ~nsUnicodeToTSCII() {}; + + NS_IMETHOD Convert(const PRUnichar * aSrc, PRInt32 * aSrcLength, + char * aDest, PRInt32 * aDestLength); + + NS_IMETHOD Finish(char * aDest, PRInt32 * aDestLength); + + NS_IMETHOD GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength, + PRInt32 * aDestLength); + + NS_IMETHOD Reset(); + + NS_IMETHOD SetOutputErrorBehavior(PRInt32 aBehavior, + nsIUnicharEncoder * aEncoder, + PRUnichar aChar); + + NS_IMETHOD FillInfo(PRUint32* aInfo); + +private: + PRUint32 mBuffer; // buffer for character(s) to be combined with the following + // character. Up to 4 single byte characters can be + // stored. +}; + +#define CHAR_BUFFER_SIZE 2048 + +//---------------------------------------------------------------------- +// Class nsUnicodeToTamilTTF [declaration] + +class nsUnicodeToTamilTTF : public nsUnicodeToTSCII +{ + NS_DECL_ISUPPORTS_INHERITED + +public: + nsUnicodeToTamilTTF() : nsUnicodeToTSCII() {}; + virtual ~nsUnicodeToTamilTTF() {}; + + NS_IMETHOD Convert (const PRUnichar * aSrc, PRInt32 * aSrcLength, + char * aDest, PRInt32 * aDestLength); + NS_IMETHOD GetMaxLength (const PRUnichar * aSrc, PRInt32 aSrcLength, + PRInt32 * aDestLength); + + NS_IMETHOD SetOutputErrorBehavior (PRInt32 aBehavior, + nsIUnicharEncoder *aEncoder, + PRUnichar aChar); + +private: + char mStaticBuffer[CHAR_BUFFER_SIZE]; + PRInt32 mErrBehavior; + PRUnichar mErrChar; + nsIUnicharEncoder* mErrEncoder; +}; + +#endif /* nsUnicodeToTSCII_h___ */ diff --git a/mozilla/intl/uconv/ucvlatin/tamil.h b/mozilla/intl/uconv/ucvlatin/tamil.h new file mode 100644 index 00000000000..46ed0974b89 --- /dev/null +++ b/mozilla/intl/uconv/ucvlatin/tamil.h @@ -0,0 +1,97 @@ +/* ***** BEGIN LICENSE BLOCK ***** + ** Version: MPL 1.1/GPL 2.0/LGPL 2.1 + ** + ** The contents of this file are subject to the Mozilla Public License Version + ** 1.1 (the "License"); you may not use this file except in compliance with + ** the License. You may obtain a copy of the License at + ** http://www.mozilla.org/MPL/ + ** + ** Software distributed under the License is distributed on an "AS IS" basis, + ** WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + ** for the specific language governing rights and limitations under the + ** License. + ** + ** The Original Code is Mozilla Communicator client code. + ** + ** The Initial Developer of the Original Code is + ** Jungshik Shin . + ** Portions created by the Initial Developer are Copyright (C) 2003 + ** the Initial Developer. All Rights Reserved. + ** + ** Contributor(s): + ** + ** Alternatively, the contents of this file may be used under the terms of + ** either the GNU General Public License Version 2 or later (the "GPL"), or + ** the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + ** in which case the provisions of the GPL or the LGPL are applicable instead + ** of those above. If you wish to allow use of your version of this file only + ** under the terms of either the GPL or the LGPL, and not to allow others to + ** use your version of this file under the terms of the MPL, indicate your + ** decision by deleting the provisions above and replace them with the notice + ** and other provisions required by the GPL or the LGPL. If you do not delete + ** the provisions above, a recipient may use your version of this file under + ** the terms of any one of the MPL, the GPL or the LGPL. + ** + ** ***** END LICENSE BLOCK ***** */ + +// Definitions to use in TSCII en/decoders. + +#define TSC_KA 0xb8 +#define TSC_NA 0xc9 +// akara varisai +#define IS_TSC_CONSONANT1(c) ((c) >= TSC_KA && (c) <= TSC_NA) +// grantha akara mey varisai +#define TSC_JA 0x83 +#define TSC_HA 0x86 +#define IS_TSC_CONSONANT2(c) ((c) >= TSC_JA && (c) <= TSC_HA) + +// union of two above +#define IS_TSC_CONSONANT(c) (IS_TSC_CONSONANT1(c) || IS_TSC_CONSONANT2(c)) + +#define TSC_SA 0x85 +#define TSC_TA 0xbc +#define TSC_RA 0xc3 +#define TSC_KSSA 0x87 // Consonant Conjunct K.SSA : live + +#define TSC_KA_DEAD 0xec // KA with virama/pulli +#define TSC_SA_DEAD 0x8a // SA with virama/pulli +#define TSC_KSSA_DEAD 0x8c // Consonant Conjunct K.SSA : dead + +#define TSC_TI_LIGA 0xca // Ligature of consonant TA and Vowel sign I +#define TSC_SRII_LIGA 0x82 // Ligature of SA + RA + II + +// Two part vowel signs +#define UNI_VOWELSIGN_E 0x0BC6 +#define TSC_VOWELSIGN_E 0xa6 +#define TSC_LEFT_VOWELSIGN(u) ((u) - UNI_VOWELSIGN_E + TSC_VOWELSIGN_E) +#define IS_UNI_LEFT_VOWELSIGN(u) ((u) >= UNI_VOWELSIGN_E && (u) <= 0x0BC8) +#define IS_UNI_2PARTS_VOWELSIGN(u) ((u) >= 0x0BCA && (u) <= 0x0BCC) + +#define UNI_TAMIL_START 0x0B80 +#define IS_UNI_TAMIL(u) (UNI_TAMIL_START <= (u) && (u) < UNI_TAMIL_START + 0x80) + +#define UNI_VIRAMA 0x0BCD +#define UNI_VOWELSIGN_I 0x0BBF +#define UNI_VOWELSIGN_II 0x0BC0 +#define UNI_VOWELSIGN_U 0x0BC1 +#define UNI_VOWELSIGN_UU 0x0BC2 +#define UNI_SSA 0x0BB7 +#define UNI_RA 0x0BB0 + +// Punctuation marks +#define UNI_LSQ 0x2018 +#define UNI_RSQ 0x2019 +#define UNI_LDQ 0x201C +#define UNI_RDQ 0x201D +#define UNI_LEFT_SINGLE_QUOTE UNI_LSQ +#define UNI_RIGHT_SINGLE_QUOTE UNI_RSQ +#define UNI_LEFT_DOUBLE_QUOTE UNI_LDQ +#define UNI_RIGHT_DOUBLE_QUOTE UNI_RDQ +#define IS_UNI_SINGLE_QUOTE(u) (UNI_LSQ <= (u) && (u) <= UNI_RSQ) +#define IS_UNI_DOUBLE_QUOTE(u) (UNI_LDQ <= (u) && (u) <= UNI_RDQ) + +#define TSC_LEFT_SINGLE_QUOTE 0x91 +#define TSC_LEFT_DOUBLE_QUOTE 0x93 + +#define TSC_LEFT_VOWEL_PART(u) (((u) % 2) ? 0xa7 : 0xa6) +#define TSC_RIGHT_VOWEL_PART(u) (((u) != 0x0BCC) ? 0xa1 : 0xaa) diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-fonts.xul b/mozilla/xpfe/components/prefwindow/resources/content/pref-fonts.xul index f289ebfc541..a7200682c23 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-fonts.xul +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-fonts.xul @@ -65,6 +65,7 @@ + diff --git a/mozilla/xpfe/components/prefwindow/resources/locale/en-US/pref-fonts.dtd b/mozilla/xpfe/components/prefwindow/resources/locale/en-US/pref-fonts.dtd index db8ecde9ca2..cf2e1029bef 100644 --- a/mozilla/xpfe/components/prefwindow/resources/locale/en-US/pref-fonts.dtd +++ b/mozilla/xpfe/components/prefwindow/resources/locale/en-US/pref-fonts.dtd @@ -42,6 +42,7 @@ +