2
* KFontInst - KDE Font Installer
4
* Copyright 2003-2009 Craig Drummond <craig@kde.org>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; see the file COPYING. If not, write to
20
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
* Boston, MA 02110-1301, USA.
24
#include <KDE/KGlobal>
25
#include <QtGui/QFontDatabase>
26
#include <fontconfig/fontconfig.h>
27
#include "WritingSystems.h"
32
K_GLOBAL_STATIC(WritingSystems, theInstance)
34
WritingSystems * WritingSystems::instance()
41
QFontDatabase::WritingSystem ws;
43
} constLanguageForWritingSystem[]=
45
{ QFontDatabase::Latin, (const FcChar8 *)"en" },
46
{ QFontDatabase::Greek, (const FcChar8 *)"el" },
47
{ QFontDatabase::Cyrillic, (const FcChar8 *)"ru" },
48
{ QFontDatabase::Armenian, (const FcChar8 *)"hy" },
49
{ QFontDatabase::Hebrew, (const FcChar8 *)"he" },
50
{ QFontDatabase::Arabic, (const FcChar8 *)"ar" },
51
{ QFontDatabase::Syriac, (const FcChar8 *)"syr" },
52
{ QFontDatabase::Thaana, (const FcChar8 *)"div" },
53
{ QFontDatabase::Devanagari, (const FcChar8 *)"hi" },
54
{ QFontDatabase::Bengali, (const FcChar8 *)"bn" },
55
{ QFontDatabase::Gurmukhi, (const FcChar8 *)"pa" },
56
{ QFontDatabase::Gujarati, (const FcChar8 *)"gu" },
57
{ QFontDatabase::Oriya, (const FcChar8 *)"or" },
58
{ QFontDatabase::Tamil, (const FcChar8 *)"ta" },
59
{ QFontDatabase::Telugu, (const FcChar8 *)"te" },
60
{ QFontDatabase::Kannada, (const FcChar8 *)"kn" },
61
{ QFontDatabase::Malayalam, (const FcChar8 *)"ml" },
62
{ QFontDatabase::Sinhala, (const FcChar8 *)"si" },
63
{ QFontDatabase::Thai, (const FcChar8 *)"th" },
64
{ QFontDatabase::Lao, (const FcChar8 *)"lo" },
65
{ QFontDatabase::Tibetan, (const FcChar8 *)"bo" },
66
{ QFontDatabase::Myanmar, (const FcChar8 *)"my" },
67
{ QFontDatabase::Georgian, (const FcChar8 *)"ka" },
68
{ QFontDatabase::Khmer, (const FcChar8 *)"km" },
69
{ QFontDatabase::SimplifiedChinese, (const FcChar8 *)"zh-cn" },
70
{ QFontDatabase::TraditionalChinese, (const FcChar8 *)"zh-tw" },
71
{ QFontDatabase::Japanese, (const FcChar8 *)"ja" },
72
{ QFontDatabase::Korean, (const FcChar8 *)"ko" },
73
{ QFontDatabase::Vietnamese, (const FcChar8 *)"vi" },
74
{ QFontDatabase::Other, NULL },
76
// The following is only used to save writing system data for disabled fonts...
77
{ QFontDatabase::Telugu, (const FcChar8 *)"Qt-Telugu" },
78
{ QFontDatabase::Kannada, (const FcChar8 *)"Qt-Kannada" },
79
{ QFontDatabase::Malayalam, (const FcChar8 *)"Qt-Malayalam" },
80
{ QFontDatabase::Sinhala, (const FcChar8 *)"Qt-Sinhala" },
81
{ QFontDatabase::Myanmar, (const FcChar8 *)"Qt-Myanmar" },
82
{ QFontDatabase::Ogham, (const FcChar8 *)"Qt-Ogham" },
83
{ QFontDatabase::Runic, (const FcChar8 *)"Qt-Runic" },
85
{ QFontDatabase::Any, NULL }
89
inline qulonglong toBit(QFontDatabase::WritingSystem ws)
91
return ((qulonglong)1) << (int)ws;
94
//.........the following section is inspired by qfontdatabase_x11.cpp / loadFontConfig
96
// Unfortunately FontConfig doesn't know about some languages. We have to test these through the
97
// charset. The lists below contain the systems where we need to do this.
100
QFontDatabase::WritingSystem ws;
102
} sampleCharForWritingSystem[] =
104
{ QFontDatabase::Telugu, 0xc15 },
105
{ QFontDatabase::Kannada, 0xc95 },
106
{ QFontDatabase::Malayalam, 0xd15 },
107
{ QFontDatabase::Sinhala, 0xd9a },
108
{ QFontDatabase::Myanmar, 0x1000 },
109
{ QFontDatabase::Ogham, 0x1681 },
110
{ QFontDatabase::Runic, 0x16a0 },
111
{ QFontDatabase::Any, 0x0 }
114
qulonglong WritingSystems::get(FcPattern *pat) const
117
FcLangSet *langset(0);
119
if (FcResultMatch==FcPatternGetLangSet(pat, FC_LANG, 0, &langset))
121
for (int i = 0; constLanguageForWritingSystem[i].lang; ++i)
122
if (FcLangDifferentLang!=FcLangSetHasLang(langset, constLanguageForWritingSystem[i].lang))
123
ws|=toBit(constLanguageForWritingSystem[i].ws);
126
ws|=toBit(QFontDatabase::Other);
130
if (FcResultMatch == FcPatternGetCharSet(pat, FC_CHARSET, 0, &cs))
132
// some languages are not supported by FontConfig, we rather check the
133
// charset to detect these
134
for (int i = 0; QFontDatabase::Any!=sampleCharForWritingSystem[i].ws; ++i)
135
if (FcCharSetHasChar(cs, sampleCharForWritingSystem[i].ch))
136
ws|=toBit(sampleCharForWritingSystem[i].ws);
143
qulonglong WritingSystems::get(const QStringList &langs) const
147
QStringList::ConstIterator it(langs.begin()),
156
QStringList WritingSystems::getLangs(qulonglong ws) const
158
QMap<QString, qulonglong>::ConstIterator wit(itsMap.begin()),
162
for(; wit!=wend; ++wit)
168
WritingSystems::WritingSystems()
170
for(int i=0; QFontDatabase::Any!=constLanguageForWritingSystem[i].ws; ++i)
171
if(constLanguageForWritingSystem[i].lang)
172
itsMap[(const char *)constLanguageForWritingSystem[i].lang]=
173
((qulonglong)1)<<constLanguageForWritingSystem[i].ws;