1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:expandtab:shiftwidth=2:tabstop=2:
4
/* ***** BEGIN LICENSE BLOCK *****
5
** Version: MPL 1.1/GPL 2.0/LGPL 2.1
7
** The contents of this file are subject to the Mozilla Public License Version
8
** 1.1 (the "License"); you may not use this file except in compliance with
9
** the License. You may obtain a copy of the License at
10
** http://www.mozilla.org/MPL/
12
** Software distributed under the License is distributed on an "AS IS" basis,
13
** WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14
** for the specific language governing rights and limitations under the
17
** The Original Code is Mozilla Communicator client code.
19
** The Initial Developer of the Original Code is
20
** Netscape Communications Corp.
21
** Portions created by the Initial Developer are Copyright (C) 2003
22
** the Initial Developer. All Rights Reserved.
24
** XXX : for the table included below. check how to credit...
25
** Copyright (C) 1999 Red Hat Software
26
** Author: Owen Taylor <otaylor@redhat.com>
28
** Copyright (C) 2002 NECTEC
29
** Author: Theppitak Karoonboonyanan <thep@links.nectec.or.th>
31
** Copyright (c) 1996-2000 by Sun Microsystems, Inc.
32
** Author: Chookij Vanatham <Chookij.Vanatham@Eng.Sun.COM>
35
** Jungshik Shin <jshin@mailaps.org>
37
** Alternatively, the contents of this file may be used under the terms of
38
** either the GNU General Public License Version 2 or later (the "GPL"), or
39
** the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
40
** in which case the provisions of the GPL or the LGPL are applicable instead
41
** of those above. If you wish to allow use of your version of this file only
42
** under the terms of either the GPL or the LGPL, and not to allow others to
43
** use your version of this file under the terms of the MPL, indicate your
44
** decision by deleting the provisions above and replace them with the notice
45
** and other provisions required by the GPL or the LGPL. If you do not delete
46
** the provisions above, a recipient may use your version of this file under
47
** the terms of any one of the MPL, the GPL or the LGPL.
49
** ***** END LICENSE BLOCK ***** */
52
#include "nsUnicodeToThaiTTF.h"
54
// tis620-2 to Thai TTF 'custom' font encoding. Actually, most positions
55
// are regular code points for Thai and general punctuation marks around
56
// U+2000. Only about one and half dozens of PUA code points are used.
57
// Copied from Pango Thai shaper (thai-xft.c)
59
const static PRUnichar gTIS620ToUnicode[] = {
60
0xf700, 0xf701, 0xf702, 0xf703, 0xf704, 0x2026, 0xf705, 0xf706,
61
0xf707, 0xf708, 0xf709, 0xf70a, 0xf70b, 0xf70c, 0xf70d, 0xf70e,
62
0xf70f, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014,
63
0xf710, 0xf711, 0xf712, 0xf713, 0xf714, 0xf715, 0xf716, 0xf717,
64
0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07,
65
0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f,
66
0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17,
67
0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f,
68
0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27,
69
0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f,
70
0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37,
71
0x0e38, 0x0e39, 0x0e3a, 0, 0, 0, 0, 0x0e3f,
72
0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47,
73
0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f,
74
0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57,
75
0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0xf718, 0xf719, 0xf71a, 0
78
//----------------------------------------------------------------------
79
// Class nsUnicodeToThaiTTF [implementation]
81
NS_IMPL_ISUPPORTS_INHERITED0(nsUnicodeToThaiTTF, nsUnicodeToTIS620)
85
nsUnicodeToThaiTTF::Convert(const PRUnichar * aSrc,
86
PRInt32 * aSrcLength, char * aDest,
87
PRInt32 * aDestLength)
93
GetMaxLength(aSrc, *aSrcLength, &medLen);
94
NS_ASSERTION(medLen <= *aDestLength, "Insufficient buffer size");
96
//intermediate encoder(TIS620) is a single byte converter taking half
97
//the space taken by ThaiTTF encoder.
99
if (medLen > CHAR_BUFFER_SIZE)
101
med = (char *) nsMemory::Alloc(*aDestLength);
103
return NS_ERROR_OUT_OF_MEMORY;
108
nsresult rv = nsUnicodeToTIS620::Convert(aSrc, aSrcLength, med, &medLen);
111
if (med != mStaticBuffer)
118
for (i = 0, j = 0; i < medLen; i++)
120
PRUnichar ucs2 = (med[i] & 0x80) ? gTIS620ToUnicode[med[i] & 0x7f] : med[i];
121
aDest[j++] = PRUint8((ucs2 & 0xff00) >> 8);
122
aDest[j++] = PRUint8(ucs2 & 0x00ff);
127
if (med != mStaticBuffer)
134
nsUnicodeToThaiTTF::GetMaxLength(const PRUnichar * aSrc, PRInt32 aSrcLength, PRInt32 * aDestLength)
136
// Each Thai character can generate at most two presentation forms,
137
// but we're 'extending' them to 16bit shorts, which accounts for
138
// additional factor of 2.
139
*aDestLength = (aSrcLength + 1) * 4;
145
nsUnicodeToThaiTTF::SetOutputErrorBehavior(PRInt32 aBehavior,
146
nsIUnicharEncoder *aEncoder,
149
if (aBehavior == kOnError_CallBack && aEncoder == nsnull)
150
return NS_ERROR_NULL_POINTER;
151
NS_IF_RELEASE(aEncoder);
152
mErrEncoder = aEncoder;
153
NS_IF_ADDREF(aEncoder);
155
mErrBehavior = aBehavior;