| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qtextengine_p.h"
|
|---|
| 43 |
|
|---|
| 44 | QT_BEGIN_NAMESPACE
|
|---|
| 45 |
|
|---|
| 46 | // set the glyph attributes heuristically. Assumes a 1 to 1 relationship between chars and glyphs
|
|---|
| 47 | // and no reordering.
|
|---|
| 48 | // also computes logClusters heuristically
|
|---|
| 49 | static void heuristicSetGlyphAttributes(const QChar *uc, int length, QGlyphLayout *glyphs, unsigned short *logClusters, int num_glyphs)
|
|---|
| 50 | {
|
|---|
| 51 | // ### zeroWidth and justification are missing here!!!!!
|
|---|
| 52 |
|
|---|
| 53 | Q_UNUSED(num_glyphs);
|
|---|
| 54 |
|
|---|
| 55 | // qDebug("QScriptEngine::heuristicSetGlyphAttributes, num_glyphs=%d", item->num_glyphs);
|
|---|
| 56 |
|
|---|
| 57 | const bool symbolFont = false; // ####
|
|---|
| 58 | glyphs->attributes[0].mark = false;
|
|---|
| 59 | glyphs->attributes[0].clusterStart = true;
|
|---|
| 60 | glyphs->attributes[0].dontPrint = (!symbolFont && uc[0].unicode() == 0x00ad) || qIsControlChar(uc[0].unicode());
|
|---|
| 61 |
|
|---|
| 62 | int pos = 0;
|
|---|
| 63 | int lastCat = QChar::category(uc[0].unicode());
|
|---|
| 64 | for (int i = 1; i < length; ++i) {
|
|---|
| 65 | if (logClusters[i] == pos)
|
|---|
| 66 | // same glyph
|
|---|
| 67 | continue;
|
|---|
| 68 | ++pos;
|
|---|
| 69 | while (pos < logClusters[i]) {
|
|---|
| 70 | ++pos;
|
|---|
| 71 | }
|
|---|
| 72 | // hide soft-hyphens by default
|
|---|
| 73 | if ((!symbolFont && uc[i].unicode() == 0x00ad) || qIsControlChar(uc[i].unicode()))
|
|---|
| 74 | glyphs->attributes[pos].dontPrint = true;
|
|---|
| 75 | const QUnicodeTables::Properties *prop = QUnicodeTables::properties(uc[i].unicode());
|
|---|
| 76 | int cat = prop->category;
|
|---|
| 77 |
|
|---|
| 78 | // one gets an inter character justification point if the current char is not a non spacing mark.
|
|---|
| 79 | // as then the current char belongs to the last one and one gets a space justification point
|
|---|
| 80 | // after the space char.
|
|---|
| 81 | if (lastCat == QChar::Separator_Space)
|
|---|
| 82 | glyphs->attributes[pos-1].justification = HB_Space;
|
|---|
| 83 | else if (cat != QChar::Mark_NonSpacing)
|
|---|
| 84 | glyphs->attributes[pos-1].justification = HB_Character;
|
|---|
| 85 | else
|
|---|
| 86 | glyphs->attributes[pos-1].justification = HB_NoJustification;
|
|---|
| 87 |
|
|---|
| 88 | lastCat = cat;
|
|---|
| 89 | }
|
|---|
| 90 | pos = logClusters[length-1];
|
|---|
| 91 | if (lastCat == QChar::Separator_Space)
|
|---|
| 92 | glyphs->attributes[pos].justification = HB_Space;
|
|---|
| 93 | else
|
|---|
| 94 | glyphs->attributes[pos].justification = HB_Character;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | struct QArabicProperties {
|
|---|
| 98 | unsigned char shape;
|
|---|
| 99 | unsigned char justification;
|
|---|
| 100 | };
|
|---|
| 101 | Q_DECLARE_TYPEINFO(QArabicProperties, Q_PRIMITIVE_TYPE);
|
|---|
| 102 |
|
|---|
| 103 | enum QArabicShape {
|
|---|
| 104 | XIsolated,
|
|---|
| 105 | XFinal,
|
|---|
| 106 | XInitial,
|
|---|
| 107 | XMedial,
|
|---|
| 108 | // intermediate state
|
|---|
| 109 | XCausing
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | // these groups correspond to the groups defined in the Unicode standard.
|
|---|
| 114 | // Some of these groups are equal with regards to both joining and line breaking behaviour,
|
|---|
| 115 | // and thus have the same enum value
|
|---|
| 116 | //
|
|---|
| 117 | // I'm not sure the mapping of syriac to arabic enums is correct with regards to justification, but as
|
|---|
| 118 | // I couldn't find any better document I'll hope for the best.
|
|---|
| 119 | enum ArabicGroup {
|
|---|
| 120 | // NonJoining
|
|---|
| 121 | ArabicNone,
|
|---|
| 122 | ArabicSpace,
|
|---|
| 123 | // Transparent
|
|---|
| 124 | Transparent,
|
|---|
| 125 | // Causing
|
|---|
| 126 | Center,
|
|---|
| 127 | Kashida,
|
|---|
| 128 |
|
|---|
| 129 | // Arabic
|
|---|
| 130 | // Dual
|
|---|
| 131 | Beh,
|
|---|
| 132 | Noon,
|
|---|
| 133 | Meem = Noon,
|
|---|
| 134 | Heh = Noon,
|
|---|
| 135 | KnottedHeh = Noon,
|
|---|
| 136 | HehGoal = Noon,
|
|---|
| 137 | SwashKaf = Noon,
|
|---|
| 138 | Yeh,
|
|---|
| 139 | Hah,
|
|---|
| 140 | Seen,
|
|---|
| 141 | Sad = Seen,
|
|---|
| 142 | Tah,
|
|---|
| 143 | Kaf = Tah,
|
|---|
| 144 | Gaf = Tah,
|
|---|
| 145 | Lam = Tah,
|
|---|
| 146 | Ain,
|
|---|
| 147 | Feh = Ain,
|
|---|
| 148 | Qaf = Ain,
|
|---|
| 149 | // Right
|
|---|
| 150 | Alef,
|
|---|
| 151 | Waw,
|
|---|
| 152 | Dal,
|
|---|
| 153 | TehMarbuta = Dal,
|
|---|
| 154 | Reh,
|
|---|
| 155 | HamzaOnHehGoal,
|
|---|
| 156 | YehWithTail = HamzaOnHehGoal,
|
|---|
| 157 | YehBarre = HamzaOnHehGoal,
|
|---|
| 158 |
|
|---|
| 159 | // Syriac
|
|---|
| 160 | // Dual
|
|---|
| 161 | Beth = Beh,
|
|---|
| 162 | Gamal = Ain,
|
|---|
| 163 | Heth = Noon,
|
|---|
| 164 | Teth = Hah,
|
|---|
| 165 | Yudh = Noon,
|
|---|
| 166 | Kaph = Noon,
|
|---|
| 167 | Lamadh = Lam,
|
|---|
| 168 | Mim = Noon,
|
|---|
| 169 | Nun = Noon,
|
|---|
| 170 | Semakh = Noon,
|
|---|
| 171 | FinalSemakh = Noon,
|
|---|
| 172 | SyriacE = Ain,
|
|---|
| 173 | Pe = Ain,
|
|---|
| 174 | ReversedPe = Hah,
|
|---|
| 175 | Qaph = Noon,
|
|---|
| 176 | Shin = Noon,
|
|---|
| 177 | Fe = Ain,
|
|---|
| 178 |
|
|---|
| 179 | // Right
|
|---|
| 180 | Alaph = Alef,
|
|---|
| 181 | Dalath = Dal,
|
|---|
| 182 | He = Dal,
|
|---|
| 183 | SyriacWaw = Waw,
|
|---|
| 184 | Zain = Alef,
|
|---|
| 185 | YudhHe = Waw,
|
|---|
| 186 | Sadhe = HamzaOnHehGoal,
|
|---|
| 187 | Taw = Dal,
|
|---|
| 188 |
|
|---|
| 189 | // Compiler bug? Otherwise ArabicGroupsEnd would be equal to Dal + 1.
|
|---|
| 190 | Dummy = HamzaOnHehGoal,
|
|---|
| 191 | ArabicGroupsEnd
|
|---|
| 192 | };
|
|---|
| 193 |
|
|---|
| 194 | static const unsigned char arabic_group[0x150] = {
|
|---|
| 195 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 196 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 197 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 198 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 199 |
|
|---|
| 200 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 201 | Transparent, Transparent, ArabicNone, ArabicNone,
|
|---|
| 202 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 203 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 204 |
|
|---|
| 205 | ArabicNone, ArabicNone, Alef, Alef,
|
|---|
| 206 | Waw, Alef, Yeh, Alef,
|
|---|
| 207 | Beh, TehMarbuta, Beh, Beh,
|
|---|
| 208 | Hah, Hah, Hah, Dal,
|
|---|
| 209 |
|
|---|
| 210 | Dal, Reh, Reh, Seen,
|
|---|
| 211 | Seen, Sad, Sad, Tah,
|
|---|
| 212 | Tah, Ain, Ain, ArabicNone,
|
|---|
| 213 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 214 |
|
|---|
| 215 | // 0x640
|
|---|
| 216 | Kashida, Feh, Qaf, Kaf,
|
|---|
| 217 | Lam, Meem, Noon, Heh,
|
|---|
| 218 | Waw, Yeh, Yeh, Transparent,
|
|---|
| 219 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 220 |
|
|---|
| 221 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 222 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 223 | Transparent, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 224 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 225 |
|
|---|
| 226 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 227 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 228 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 229 | ArabicNone, ArabicNone, Beh, Qaf,
|
|---|
| 230 |
|
|---|
| 231 | Transparent, Alef, Alef, Alef,
|
|---|
| 232 | ArabicNone, Alef, Waw, Waw,
|
|---|
| 233 | Yeh, Beh, Beh, Beh,
|
|---|
| 234 | Beh, Beh, Beh, Beh,
|
|---|
| 235 |
|
|---|
| 236 | // 0x680
|
|---|
| 237 | Beh, Hah, Hah, Hah,
|
|---|
| 238 | Hah, Hah, Hah, Hah,
|
|---|
| 239 | Dal, Dal, Dal, Dal,
|
|---|
| 240 | Dal, Dal, Dal, Dal,
|
|---|
| 241 |
|
|---|
| 242 | Dal, Reh, Reh, Reh,
|
|---|
| 243 | Reh, Reh, Reh, Reh,
|
|---|
| 244 | Reh, Reh, Seen, Seen,
|
|---|
| 245 | Seen, Sad, Sad, Tah,
|
|---|
| 246 |
|
|---|
| 247 | Ain, Feh, Feh, Feh,
|
|---|
| 248 | Feh, Feh, Feh, Qaf,
|
|---|
| 249 | Qaf, Gaf, SwashKaf, Gaf,
|
|---|
| 250 | Kaf, Kaf, Kaf, Gaf,
|
|---|
| 251 |
|
|---|
| 252 | Gaf, Gaf, Gaf, Gaf,
|
|---|
| 253 | Gaf, Lam, Lam, Lam,
|
|---|
| 254 | Lam, Noon, Noon, Noon,
|
|---|
| 255 | Noon, Noon, KnottedHeh, Hah,
|
|---|
| 256 |
|
|---|
| 257 | // 0x6c0
|
|---|
| 258 | TehMarbuta, HehGoal, HamzaOnHehGoal, HamzaOnHehGoal,
|
|---|
| 259 | Waw, Waw, Waw, Waw,
|
|---|
| 260 | Waw, Waw, Waw, Waw,
|
|---|
| 261 | Yeh, YehWithTail, Yeh, Waw,
|
|---|
| 262 |
|
|---|
| 263 | Yeh, Yeh, YehBarre, YehBarre,
|
|---|
| 264 | ArabicNone, TehMarbuta, Transparent, Transparent,
|
|---|
| 265 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 266 | Transparent, ArabicNone, ArabicNone, Transparent,
|
|---|
| 267 |
|
|---|
| 268 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 269 | Transparent, ArabicNone, ArabicNone, Transparent,
|
|---|
| 270 | Transparent, ArabicNone, Transparent, Transparent,
|
|---|
| 271 | Transparent, Transparent, Dal, Reh,
|
|---|
| 272 |
|
|---|
| 273 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 274 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 275 | ArabicNone, ArabicNone, Seen, Sad,
|
|---|
| 276 | Ain, ArabicNone, ArabicNone, KnottedHeh,
|
|---|
| 277 |
|
|---|
| 278 | // 0x700
|
|---|
| 279 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 280 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 281 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 282 | ArabicNone, ArabicNone, ArabicNone, ArabicNone,
|
|---|
| 283 |
|
|---|
| 284 | Alaph, Transparent, Beth, Gamal,
|
|---|
| 285 | Gamal, Dalath, Dalath, He,
|
|---|
| 286 | SyriacWaw, Zain, Heth, Teth,
|
|---|
| 287 | Teth, Yudh, YudhHe, Kaph,
|
|---|
| 288 |
|
|---|
| 289 | Lamadh, Mim, Nun, Semakh,
|
|---|
| 290 | FinalSemakh, SyriacE, Pe, ReversedPe,
|
|---|
| 291 | Sadhe, Qaph, Dalath, Shin,
|
|---|
| 292 | Taw, Beth, Gamal, Dalath,
|
|---|
| 293 |
|
|---|
| 294 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 295 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 296 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 297 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 298 |
|
|---|
| 299 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 300 | Transparent, Transparent, Transparent, Transparent,
|
|---|
| 301 | Transparent, Transparent, Transparent, ArabicNone,
|
|---|
| 302 | ArabicNone, Zain, Kaph, Fe,
|
|---|
| 303 | };
|
|---|
| 304 |
|
|---|
| 305 | static inline ArabicGroup arabicGroup(unsigned short uc)
|
|---|
| 306 | {
|
|---|
| 307 | if (uc >= 0x0600 && uc < 0x750)
|
|---|
| 308 | return (ArabicGroup) arabic_group[uc-0x600];
|
|---|
| 309 | else if (uc == 0x200d)
|
|---|
| 310 | return Center;
|
|---|
| 311 | else if (QChar::category(uc) == QChar::Separator_Space)
|
|---|
| 312 | return ArabicSpace;
|
|---|
| 313 | else
|
|---|
| 314 | return ArabicNone;
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 | /*
|
|---|
| 319 | Arabic shaping obeys a number of rules according to the joining classes (see Unicode book, section on
|
|---|
| 320 | arabic).
|
|---|
|
|---|