summaryrefslogtreecommitdiffstats
path: root/ksvg/impl/libs/libtext2path/src/QtUnicode.h
blob: 41008500fa91dfd49a2675bbaae5f11392197939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
    Copyright (C) 2003 Nikolas Zimmermann <wildfox@kde.org>
    This file is part of the KDE project

    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
    aint with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef T2P_QT_UNICODE_H
#define T2P_QT_UNICODE_H

namespace T2P
{
	enum Script 
	{
		// European Alphabetic Scripts
		Latin,
		Greek,
		Cyrillic,
		Armenian,
		Georgian,
		Runic,
		Ogham,
		SpacingModifiers,
		CombiningMarks,

		// Middle Eastern Scripts
		Hebrew,
		Arabic,
		Syriac,
		Thaana,

		// South and Southeast Asian Scripts
		Devanagari,
		Bengali,
		Gurmukhi,
		Gujarati,
		Oriya,
		Tamil,
		Telugu,
		Kannada,
		Malayalam,
		Sinhala,
		Thai,
		Lao,
		Tibetan,
		Myanmar,
		Khmer,

		// East Asian Scripts
		Han,
		Hiragana,
		Katakana,
		Hangul,
		Bopomofo,
		Yi,

		// Additional Scripts
		Ethiopic,
		Cherokee,
		CanadianAboriginal,
		Mongolian,

		// Symbols
		CurrencySymbols,
		LetterlikeSymbols,
		NumberForms,
		MathematicalOperators,
		TechnicalSymbols,
		GeometricSymbols,
		MiscellaneousSymbols,
		EnclosedAndSquare,
		Braille,

		Unicode,

		// some scripts added in Unicode 3.2
		Tagalog,
		Hanunoo,
		Buhid,
		Tagbanwa,

		KatakanaHalfWidth,

		// End
		NScripts,
		UnknownScript = NScripts
	};

	class QtUnicode
	{
	public:
		QtUnicode() { }
		~QtUnicode() { }

		static int scriptForChar(unsigned short uc)
		{
			unsigned char script = QtUnicode::scriptTable[(uc >> 8)];
			if(script >= QtUnicode::SCRIPTS_INDIC)
			{
				if(script == QtUnicode::SCRIPTS_INDIC)
					script = QtUnicode::indicScripts[(uc - 0x0900) >> 7];
				else
				{
					// 0x80 + SCRIPTS_xx
					unsigned char index = script - 0x80;
					unsigned char cell = uc & 0xff;
					while(QtUnicode::otherScripts[index++] < cell)
						index++;
					script = QtUnicode::otherScripts[index];
				}
			}
	
			return script;
		}

	private:
	    enum
		{
			SCRIPTS_INDIC = 0x7e
		};

		static const unsigned char otherScripts[];
		static const unsigned char indicScripts[];
		static const unsigned char scriptTable[];
	};
}

#define SCRIPT_FOR_CHAR(script, c) \
if(c < 0x100) \
	script = T2P::Latin; \
else \
	script = (T2P::Script) QtUnicode::scriptForChar(c); 

#endif

// vim:ts=4:noet