Changeset 20 for trunk/src/kernel/qtextengine_pm.cpp
- Timestamp:
- Nov 17, 2005, 7:00:27 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel/qtextengine_pm.cpp
r19 r20 42 42 43 43 44 //@@TODO (dmik): remove? 45 //// these defines are from usp10.h 46 //typedef void *SCRIPT_CACHE; 47 //typedef struct tag_SCRIPT_CONTROL { 48 // DWORD uDefaultLanguage :16; 49 // DWORD fContextDigits :1; 50 // DWORD fInvertPreBoundDir :1; 51 // DWORD fInvertPostBoundDir :1; 52 // DWORD fLinkStringBefore :1; 53 // DWORD fLinkStringAfter :1; 54 // DWORD fNeutralOverride :1; 55 // DWORD fNumericOverride :1; 56 // DWORD fLegacyBidiClass :1; 57 // DWORD fReserved :8; 58 //} SCRIPT_CONTROL; 44 /// @todo (dmik) remove? 45 #if 0 46 // these defines are from usp10.h 47 typedef void *SCRIPT_CACHE; 48 typedef struct tag_SCRIPT_CONTROL { 49 DWORD uDefaultLanguage :16; 50 DWORD fContextDigits :1; 51 DWORD fInvertPreBoundDir :1; 52 DWORD fInvertPostBoundDir :1; 53 DWORD fLinkStringBefore :1; 54 DWORD fLinkStringAfter :1; 55 DWORD fNeutralOverride :1; 56 DWORD fNumericOverride :1; 57 DWORD fLegacyBidiClass :1; 58 DWORD fReserved :8; 59 } SCRIPT_CONTROL; 60 61 typedef struct tag_SCRIPT_STATE { 62 WORD uBidiLevel :5; 63 WORD fOverrideDirection :1; 64 WORD fInhibitSymSwap :1; 65 WORD fCharShape :1; 66 WORD fDigitSubstitute :1; 67 WORD fInhibitLigate :1; 68 WORD fDisplayZWG :1; 69 WORD fArabicNumContext :1; 70 WORD fGcpClusters :1; 71 WORD fReserved :1; 72 WORD fEngineReserved :2; 73 } SCRIPT_STATE; 74 75 typedef struct tag_SCRIPT_ITEM { 76 int iCharPos; 77 QScriptAnalysis a; 78 } SCRIPT_ITEM; 79 80 typedef GlyphAttributes SCRIPT_VISATTR; 81 typedef qoffset_t GOFFSET; 82 83 #define USP_E_SCRIPT_NOT_IN_FONT \ 84 MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,0x200) // Script doesn't exist in font 85 86 typedef struct { 87 DWORD langid :16; 88 DWORD fNumeric :1; 89 DWORD fComplex :1; 90 DWORD fNeedsWordBreaking :1; 91 DWORD fNeedsCaretInfo :1; 92 DWORD bCharSet :8; 93 DWORD fControl :1; 94 DWORD fPrivateUseArea :1; 95 DWORD fNeedsCharacterJustify :1; 96 DWORD fInvalidGlyph :1; 97 DWORD fInvalidLogAttr :1; 98 DWORD fCDM :1; 99 DWORD fAmbiguousCharSet :1; 100 DWORD fClusterSizeVaries :1; 101 DWORD fRejectInvalid :1; 102 } SCRIPT_PROPERTIES; 103 104 #if defined(Q_OS_TEMP) && UNDER_CE < 400 105 typedef struct _ABC { 106 int abcA; 107 UINT abcB; 108 int abcC; 109 } ABC; 110 #endif 111 112 typedef HRESULT (WINAPI *fScriptFreeCache)( SCRIPT_CACHE *); 113 typedef HRESULT (WINAPI *fScriptItemize)( const WCHAR *, int, int, const SCRIPT_CONTROL *, 114 const SCRIPT_STATE *, SCRIPT_ITEM *, int *); 115 typedef HRESULT (WINAPI *fScriptShape)( HDC hdc, SCRIPT_CACHE *, const WCHAR *, int, int, 116 QScriptAnalysis *, WORD *, WORD *, SCRIPT_VISATTR *, int *); 117 typedef HRESULT (WINAPI *fScriptPlace)( HDC, SCRIPT_CACHE *, const WORD *, int, const SCRIPT_VISATTR *, QScriptAnalysis *, int *, 118 GOFFSET *, ABC * ); 119 typedef HRESULT (WINAPI *fScriptTextOut)( const HDC, SCRIPT_CACHE *, int, int, UINT, const RECT *, const QScriptAnalysis *, 120 const WCHAR *, int, const WORD *, int, const int *, const int *, const GOFFSET *); 121 typedef HRESULT (WINAPI *fScriptBreak)( const WCHAR *, int, const QScriptAnalysis *, QCharAttributes * ); 122 //typedef HRESULT (WINAPI *fScriptGetFontProperties)( HDC, SCRIPT_CACHE *, SCRIPT_FONTPROPERTIES * ); 123 typedef HRESULT (WINAPI *fScriptGetProperties)( const SCRIPT_PROPERTIES ***, int *); 124 125 fScriptFreeCache ScriptFreeCache = 0; 126 static fScriptItemize ScriptItemize = 0; 127 static fScriptShape ScriptShape = 0; 128 static fScriptPlace ScriptPlace = 0; 129 fScriptTextOut ScriptTextOut = 0; 130 static fScriptBreak ScriptBreak = 0; 131 //static fScriptGetFontProperties ScriptGetFontProperties = 0; 132 static fScriptGetProperties ScriptGetProperties = 0; 133 134 static bool resolvedUsp10 = FALSE; 135 bool hasUsp10 = FALSE; 136 137 const SCRIPT_PROPERTIES **script_properties = 0; 138 int num_scripts = 0; 139 int usp_latin_script = 0; 140 141 142 const QFont::Script japanese_tryScripts[] = { 143 QFont::Latin, 144 QFont::Han_Japanese, 145 QFont::Hangul, 146 QFont::Han_SimplifiedChinese, 147 QFont::Han_TraditionalChinese 148 }; 149 150 const QFont::Script korean_tryScripts[] = { 151 QFont::Latin, 152 QFont::Hangul, 153 QFont::Han_Japanese, 154 QFont::Han_SimplifiedChinese, 155 QFont::Han_TraditionalChinese 156 }; 157 158 const QFont::Script simplifiedChinese_tryScripts[] = { 159 QFont::Latin, 160 QFont::Han_SimplifiedChinese, 161 QFont::Han_TraditionalChinese, 162 QFont::Han_Japanese, 163 QFont::Hangul 164 }; 165 166 const QFont::Script traditionalChinese_tryScripts[] = { 167 QFont::Latin, 168 QFont::Han_TraditionalChinese, 169 QFont::Han_SimplifiedChinese, 170 QFont::Han_Japanese, 171 QFont::Hangul 172 }; 173 174 const QFont::Script *tryScripts = japanese_tryScripts; 175 176 static void uspAppendItems(QTextEngine *engine, int &start, int &stop, BidiControl &control, QChar::Direction dir); 177 178 static void resolveUsp10() 179 { 180 #ifndef QT_NO_COMPONENT 181 if ( !resolvedUsp10 ) { 182 // need to resolve the security info functions 183 184 #ifdef QT_THREAD_SUPPORT 185 // protect initialization 186 QMutexLocker locker( qt_global_mutexpool ? 187 qt_global_mutexpool->get( (void*)&resolveUsp10 ) : 0 ); 188 // check triedResolve again, since another thread may have already 189 // done the initialization 190 if ( resolvedUsp10 ) { 191 // another thread did initialize the security function pointers, 192 // so we shouldn't do it again. 193 return; 194 } 195 #endif 196 197 resolvedUsp10 = TRUE; 198 QLibrary lib("usp10"); 199 lib.setAutoUnload( FALSE ); 200 201 ScriptFreeCache = (fScriptFreeCache) lib.resolve( "ScriptFreeCache" ); 202 ScriptItemize = (fScriptItemize) lib.resolve( "ScriptItemize" ); 203 ScriptShape = (fScriptShape) lib.resolve( "ScriptShape" ); 204 ScriptPlace = (fScriptPlace) lib.resolve( "ScriptPlace" ); 205 ScriptTextOut = (fScriptTextOut) lib.resolve( "ScriptTextOut" ); 206 ScriptBreak = (fScriptBreak) lib.resolve( "ScriptBreak" ); 207 ScriptGetProperties = (fScriptGetProperties) lib.resolve( "ScriptGetProperties" ); 208 209 if ( !ScriptFreeCache ) 210 return; 211 212 hasUsp10 = TRUE; 213 ScriptGetProperties( &script_properties, &num_scripts ); 214 215 // get the usp script for western 216 for( int i = 0; i < num_scripts; i++ ) { 217 if (script_properties[i]->langid == LANG_ENGLISH && 218 !script_properties[i]->fAmbiguousCharSet ) { 219 usp_latin_script = i; 220 break; 221 } 222 } 223 224 // initialize tryScripts according to locale 225 LANGID lid = GetUserDefaultLangID(); 226 switch( lid&0xff ) { 227 case LANG_CHINESE: // Chinese (Taiwan) 228 if ( lid == 0x0804 ) // Taiwan 229 tryScripts = traditionalChinese_tryScripts; 230 else 231 tryScripts = simplifiedChinese_tryScripts; 232 break; 233 case LANG_JAPANESE: 234 // japanese is already the default 235 break; 236 case LANG_KOREAN: 237 tryScripts = korean_tryScripts; 238 break; 239 default: 240 break; 241 } 242 243 appendItems = uspAppendItems; 244 } 245 #endif 246 } 247 248 static unsigned char script_for_win_language[ 0x80 ] = { 249 //0x00 LANG_NEUTRAL Neutral 250 QFont::Latin, 251 //0x01 LANG_ARABIC Arabic 252 QFont::Arabic, 253 //0x02 LANG_BULGARIAN Bulgarian 254 QFont::NScripts, 255 //0x03 LANG_CATALAN Catalan 256 QFont::NScripts, 257 //0x04 LANG_CHINESE Chinese 258 QFont::Han, 259 //0x05 LANG_CZECH Czech 260 QFont::NScripts, 261 //0x06 LANG_DANISH Danish 262 QFont::NScripts, 263 //0x07 LANG_GERMAN German 264 QFont::NScripts, 265 //0x08 LANG_GREEK Greek 266 QFont::Greek, 267 //0x09 LANG_ENGLISH English 268 QFont::Latin, 269 //0x0a LANG_SPANISH Spanish 270 QFont::NScripts, 271 //0x0b LANG_FINNISH Finnish 272 QFont::NScripts, 273 //0x0c LANG_FRENCH French 274 QFont::NScripts, 275 //0x0d LANG_HEBREW Hebrew 276 QFont::Hebrew, 277 //0x0e LANG_HUNGARIAN Hungarian 278 QFont::NScripts, 279 //0x0f LANG_ICELANDIC Icelandic 280 QFont::NScripts, 281 282 //0x10 LANG_ITALIAN Italian 283 QFont::NScripts, 284 //0x11 LANG_JAPANESE Japanese 285 QFont::Hiragana, 286 //0x12 LANG_KOREAN Korean 287 QFont::Hangul, 288 //0x13 LANG_DUTCH Dutch 289 QFont::NScripts, 290 //0x14 LANG_NORWEGIAN Norwegian 291 QFont::NScripts, 292 //0x15 LANG_POLISH Polish 293 QFont::NScripts, 294 //0x16 LANG_PORTUGUESE Portuguese 295 QFont::NScripts, 296 QFont::NScripts, 297 //0x18 LANG_ROMANIAN Romanian 298 QFont::NScripts, 299 //0x19 LANG_RUSSIAN Russian 300 QFont::Cyrillic, 301 //0x1a LANG_CROATIAN Croatian 302 //0x1a LANG_SERBIAN Serbian 303 QFont::NScripts, 304 //0x1b LANG_SLOVAK Slovak 305 QFont::NScripts, 306 //0x1c LANG_ALBANIAN Albanian 307 QFont::NScripts, 308 //0x1d LANG_SWEDISH Swedish 309 QFont::NScripts, 310 //0x1e LANG_THAI Thai 311 QFont::Thai, 312 //0x1f LANG_TURKISH Turkish 313 QFont::NScripts, 314 315 //0x20 LANG_URDU Urdu 316 QFont::NScripts, 317 //0x21 LANG_INDONESIAN Indonesian 318 QFont::NScripts, 319 //0x22 LANG_UKRAINIAN Ukrainian 320 QFont::NScripts, 321 //0x23 LANG_BELARUSIAN Belarusian 322 QFont::NScripts, 323 //0x24 LANG_SLOVENIAN Slovenian 324 QFont::NScripts, 325 //0x25 LANG_ESTONIAN Estonian 326 QFont::NScripts, 327 //0x26 LANG_LATVIAN Latvian 328 QFont::NScripts, 329 //0x27 LANG_LITHUANIAN Lithuanian 330 QFont::NScripts, 331 QFont::NScripts, 332 //0x29 LANG_FARSI Farsi 333 QFont::NScripts, 334 //0x2a LANG_VIETNAMESE Vietnamese 335 QFont::Latin, // ##### maybe use QFont::CombiningMarks instead? 336 //0x2b LANG_ARMENIAN Armenian 337 QFont::Armenian, 338 //0x2c LANG_AZERI Azeri 339 QFont::NScripts, 340 //0x2d LANG_BASQUE Basque 341 QFont::NScripts, 342 QFont::NScripts, 343 //0x2f LANG_MACEDONIAN FYRO Macedonian 344 QFont::NScripts, 345 346 QFont::NScripts, 347 QFont::NScripts, 348 QFont::NScripts, 349 QFont::NScripts, 350 QFont::NScripts, 351 QFont::NScripts, 352 //0x36 LANG_AFRIKAANS Afrikaans 353 QFont::NScripts, 354 //0x37 LANG_GEORGIAN Georgian 355 QFont::NScripts, 356 //0x38 LANG_FAEROESE Faeroese 357 QFont::NScripts, 358 //0x39 LANG_HINDI Hindi 359 QFont::Devanagari, 360 QFont::NScripts, 361 QFont::NScripts, 362 QFont::NScripts, 363 QFont::NScripts, 364 //0x3e LANG_MALAY Malay 365 QFont::NScripts, 366 //0x3f LANG_KAZAK Kazak 367 QFont::NScripts, 368 369 //0x40 LANG_KYRGYZ Kyrgyz 370 QFont::NScripts, 371 //0x41 LANG_SWAHILI Swahili 372 QFont::NScripts, 373 QFont::NScripts, 374 //0x43 LANG_UZBEK Uzbek 375 QFont::NScripts, 376 //0x44 LANG_TATAR Tatar 377 QFont::NScripts, 378 //0x45 LANG_BENGALI Not supported. 379 QFont::Bengali, 380 //0x46 LANG_PUNJABI Punjabi 381 QFont::Gurmukhi, 382 //0x47 LANG_GUJARATI Gujarati 383 QFont::Gujarati, 384 //0x48 LANG_ORIYA Not supported. 385 QFont::Oriya, 386 //0x49 LANG_TAMIL Tamil 387 QFont::Tamil, 388 //0x4a LANG_TELUGU Telugu 389 QFont::Telugu, 390 //0x4b LANG_KANNADA Kannada 391 QFont::Kannada, 392 //0x4c LANG_MALAYALAM Not supported. 393 QFont::Malayalam, 394 //0x4d LANG_ASSAMESE Not supported. 395 QFont::NScripts, 396 //0x4e LANG_MARATHI Marathi 397 QFont::NScripts, 398 //0x4f LANG_SANSKRIT Sanskrit 399 QFont::Devanagari, 400 401 //0x50 LANG_MONGOLIAN Mongolian 402 QFont::Mongolian, 403 QFont::NScripts, 404 QFont::NScripts, 405 QFont::NScripts, 406 QFont::NScripts, 407 QFont::NScripts, 408 //0x56 LANG_GALICIAN Galician 409 QFont::NScripts, 410 //0x57 LANG_KONKANI Konkani 411 QFont::NScripts, 412 //0x58 LANG_MANIPURI Not supported. 413 QFont::NScripts, 414 //0x59 LANG_SINDHI Not supported. 415 QFont::NScripts, 416 //0x5a LANG_SYRIAC Syriac 417 QFont::Syriac, 418 QFont::NScripts, 419 QFont::NScripts, 420 QFont::NScripts, 421 QFont::NScripts, 422 QFont::NScripts, 423 424 //0x60 LANG_KASHMIRI Not supported. 425 QFont::NScripts, 426 //0x61 LANG_NEPALI Not supported. 427 QFont::NScripts, 428 QFont::NScripts, 429 QFont::NScripts, 430 QFont::NScripts, 431 //0x65 LANG_DIVEHI Divehi 432 QFont::NScripts, 433 QFont::NScripts, 434 QFont::NScripts, 435 QFont::NScripts, 436 QFont::NScripts, 437 QFont::NScripts, 438 QFont::NScripts, 439 QFont::NScripts, 440 QFont::NScripts, 441 QFont::NScripts, 442 QFont::NScripts, 443 444 QFont::NScripts, 445 QFont::NScripts, 446 QFont::NScripts, 447 QFont::NScripts, 448 QFont::NScripts, 449 QFont::NScripts, 450 QFont::NScripts, 451 QFont::NScripts, 452 QFont::NScripts, 453 QFont::NScripts, 454 QFont::NScripts, 455 QFont::NScripts, 456 QFont::NScripts, 457 QFont::NScripts, 458 QFont::NScripts, 459 //0x7f LANG_INVARIANT 460 QFont::NScripts, 461 }; 462 463 static inline QFont::Script scriptForWinLanguage( DWORD langid ) 464 { 465 QFont::Script script = (QFont::Script)script_for_win_language[langid]; 466 if ( script == QFont::NScripts ) 467 qWarning( "Qt Uniscribe support: Encountered unhandled language id %x", (unsigned int)langid ); 468 return script; 469 } 470 471 static inline bool isAsian( unsigned short ch ) 472 { 473 return (ch > 0x2dff && ch < 0xfb00) || ((ch & 0xff00) == 0x1100); 474 } 475 476 477 // we're not using Uniscribe's BiDi algorithm, since it is (a) not 100% Unicode compliant and 478 // (b) seems to work wrongly when trying to use it with a base level != 0. 59 479 // 60 //typedef struct tag_SCRIPT_STATE { 61 // WORD uBidiLevel :5; 62 // WORD fOverrideDirection :1; 63 // WORD fInhibitSymSwap :1; 64 // WORD fCharShape :1; 65 // WORD fDigitSubstitute :1; 66 // WORD fInhibitLigate :1; 67 // WORD fDisplayZWG :1; 68 // WORD fArabicNumContext :1; 69 // WORD fGcpClusters :1; 70 // WORD fReserved :1; 71 // WORD fEngineReserved :2; 72 //} SCRIPT_STATE; 73 // 74 //typedef struct tag_SCRIPT_ITEM { 75 // int iCharPos; 76 // QScriptAnalysis a; 77 //} SCRIPT_ITEM; 78 // 79 //typedef GlyphAttributes SCRIPT_VISATTR; 80 //typedef qoffset_t GOFFSET; 81 // 82 //#define USP_E_SCRIPT_NOT_IN_FONT \ 83 // MAKE_HRESULT(SEVERITY_ERROR,FACILITY_ITF,0x200) // Script doesn't exist in font 84 // 85 //typedef struct { 86 // DWORD langid :16; 87 // DWORD fNumeric :1; 88 // DWORD fComplex :1; 89 // DWORD fNeedsWordBreaking :1; 90 // DWORD fNeedsCaretInfo :1; 91 // DWORD bCharSet :8; 92 // DWORD fControl :1; 93 // DWORD fPrivateUseArea :1; 94 // DWORD fNeedsCharacterJustify :1; 95 // DWORD fInvalidGlyph :1; 96 // DWORD fInvalidLogAttr :1; 97 // DWORD fCDM :1; 98 // DWORD fAmbiguousCharSet :1; 99 // DWORD fClusterSizeVaries :1; 100 // DWORD fRejectInvalid :1; 101 //} SCRIPT_PROPERTIES; 102 // 103 //#if defined(Q_OS_TEMP) && UNDER_CE < 400 104 //typedef struct _ABC { 105 // int abcA; 106 // UINT abcB; 107 // int abcC; 108 //} ABC; 109 //#endif 110 // 111 //typedef HRESULT (WINAPI *fScriptFreeCache)( SCRIPT_CACHE *); 112 //typedef HRESULT (WINAPI *fScriptItemize)( const WCHAR *, int, int, const SCRIPT_CONTROL *, 113 // const SCRIPT_STATE *, SCRIPT_ITEM *, int *); 114 //typedef HRESULT (WINAPI *fScriptShape)( HDC hdc, SCRIPT_CACHE *, const WCHAR *, int, int, 115 // QScriptAnalysis *, WORD *, WORD *, SCRIPT_VISATTR *, int *); 116 //typedef HRESULT (WINAPI *fScriptPlace)( HDC, SCRIPT_CACHE *, const WORD *, int, const SCRIPT_VISATTR *, QScriptAnalysis *, int *, 117 // GOFFSET *, ABC * ); 118 //typedef HRESULT (WINAPI *fScriptTextOut)( const HDC, SCRIPT_CACHE *, int, int, UINT, const RECT *, const QScriptAnalysis *, 119 // const WCHAR *, int, const WORD *, int, const int *, const int *, const GOFFSET *); 120 //typedef HRESULT (WINAPI *fScriptBreak)( const WCHAR *, int, const QScriptAnalysis *, QCharAttributes * ); 121 ////typedef HRESULT (WINAPI *fScriptGetFontProperties)( HDC, SCRIPT_CACHE *, SCRIPT_FONTPROPERTIES * ); 122 //typedef HRESULT (WINAPI *fScriptGetProperties)( const SCRIPT_PROPERTIES ***, int *); 123 // 124 //fScriptFreeCache ScriptFreeCache = 0; 125 //static fScriptItemize ScriptItemize = 0; 126 //static fScriptShape ScriptShape = 0; 127 //static fScriptPlace ScriptPlace = 0; 128 //fScriptTextOut ScriptTextOut = 0; 129 //static fScriptBreak ScriptBreak = 0; 130 ////static fScriptGetFontProperties ScriptGetFontProperties = 0; 131 //static fScriptGetProperties ScriptGetProperties = 0; 132 // 133 //static bool resolvedUsp10 = FALSE; 134 //bool hasUsp10 = FALSE; 135 // 136 //const SCRIPT_PROPERTIES **script_properties = 0; 137 //int num_scripts = 0; 138 //int usp_latin_script = 0; 139 // 140 // 141 //const QFont::Script japanese_tryScripts[] = { 142 // QFont::Latin, 143 // QFont::Han_Japanese, 144 // QFont::Hangul, 145 // QFont::Han_SimplifiedChinese, 146 // QFont::Han_TraditionalChinese 147 //}; 148 // 149 //const QFont::Script korean_tryScripts[] = { 150 // QFont::Latin, 151 // QFont::Hangul, 152 // QFont::Han_Japanese, 153 // QFont::Han_SimplifiedChinese, 154 // QFont::Han_TraditionalChinese 155 //}; 156 // 157 //const QFont::Script simplifiedChinese_tryScripts[] = { 158 // QFont::Latin, 159 // QFont::Han_SimplifiedChinese, 160 // QFont::Han_TraditionalChinese, 161 // QFont::Han_Japanese, 162 // QFont::Hangul 163 //}; 164 // 165 //const QFont::Script traditionalChinese_tryScripts[] = { 166 // QFont::Latin, 167 // QFont::Han_TraditionalChinese, 168 // QFont::Han_SimplifiedChinese, 169 // QFont::Han_Japanese, 170 // QFont::Hangul 171 //}; 172 // 173 //const QFont::Script *tryScripts = japanese_tryScripts; 174 // 175 //static void uspAppendItems(QTextEngine *engine, int &start, int &stop, BidiControl &control, QChar::Direction dir); 176 // 177 //static void resolveUsp10() 178 //{ 179 //#ifndef QT_NO_COMPONENT 180 // if ( !resolvedUsp10 ) { 181 // // need to resolve the security info functions 182 // 183 //#ifdef QT_THREAD_SUPPORT 184 // // protect initialization 185 // QMutexLocker locker( qt_global_mutexpool ? 186 // qt_global_mutexpool->get( (void*)&resolveUsp10 ) : 0 ); 187 // // check triedResolve again, since another thread may have already 188 // // done the initialization 189 // if ( resolvedUsp10 ) { 190 // // another thread did initialize the security function pointers, 191 // // so we shouldn't do it again. 192 // return; 193 // } 194 //#endif 195 // 196 // resolvedUsp10 = TRUE; 197 // QLibrary lib("usp10"); 198 // lib.setAutoUnload( FALSE ); 199 // 200 // ScriptFreeCache = (fScriptFreeCache) lib.resolve( "ScriptFreeCache" ); 201 // ScriptItemize = (fScriptItemize) lib.resolve( "ScriptItemize" ); 202 // ScriptShape = (fScriptShape) lib.resolve( "ScriptShape" ); 203 // ScriptPlace = (fScriptPlace) lib.resolve( "ScriptPlace" ); 204 // ScriptTextOut = (fScriptTextOut) lib.resolve( "ScriptTextOut" ); 205 // ScriptBreak = (fScriptBreak) lib.resolve( "ScriptBreak" ); 206 // ScriptGetProperties = (fScriptGetProperties) lib.resolve( "ScriptGetProperties" ); 207 // 208 // if ( !ScriptFreeCache ) 209 // return; 210 // 211 // hasUsp10 = TRUE; 212 // ScriptGetProperties( &script_properties, &num_scripts ); 213 // 214 // // get the usp script for western 215 // for( int i = 0; i < num_scripts; i++ ) { 216 // if (script_properties[i]->langid == LANG_ENGLISH && 217 // !script_properties[i]->fAmbiguousCharSet ) { 218 // usp_latin_script = i; 219 // break; 220 // } 221 // } 222 // 223 // // initialize tryScripts according to locale 224 // LANGID lid = GetUserDefaultLangID(); 225 // switch( lid&0xff ) { 226 // case LANG_CHINESE: // Chinese (Taiwan) 227 // if ( lid == 0x0804 ) // Taiwan 228 // tryScripts = traditionalChinese_tryScripts; 229 // else 230 // tryScripts = simplifiedChinese_tryScripts; 231 // break; 232 // case LANG_JAPANESE: 233 // // japanese is already the default 234 // break; 235 // case LANG_KOREAN: 236 // tryScripts = korean_tryScripts; 237 // break; 238 // default: 239 // break; 240 // } 241 // 242 // appendItems = uspAppendItems; 243 // } 244 //#endif 245 //} 246 // 247 //static unsigned char script_for_win_language[ 0x80 ] = { 248 // //0x00 LANG_NEUTRAL Neutral 249 // QFont::Latin, 250 // //0x01 LANG_ARABIC Arabic 251 // QFont::Arabic, 252 // //0x02 LANG_BULGARIAN Bulgarian 253 // QFont::NScripts, 254 // //0x03 LANG_CATALAN Catalan 255 // QFont::NScripts, 256 // //0x04 LANG_CHINESE Chinese 257 // QFont::Han, 258 // //0x05 LANG_CZECH Czech 259 // QFont::NScripts, 260 // //0x06 LANG_DANISH Danish 261 // QFont::NScripts, 262 // //0x07 LANG_GERMAN German 263 // QFont::NScripts, 264 // //0x08 LANG_GREEK Greek 265 // QFont::Greek, 266 // //0x09 LANG_ENGLISH English 267 // QFont::Latin, 268 // //0x0a LANG_SPANISH Spanish 269 // QFont::NScripts, 270 // //0x0b LANG_FINNISH Finnish 271 // QFont::NScripts, 272 // //0x0c LANG_FRENCH French 273 // QFont::NScripts, 274 // //0x0d LANG_HEBREW Hebrew 275 // QFont::Hebrew, 276 // //0x0e LANG_HUNGARIAN Hungarian 277 // QFont::NScripts, 278 // //0x0f LANG_ICELANDIC Icelandic 279 // QFont::NScripts, 280 // 281 // //0x10 LANG_ITALIAN Italian 282 // QFont::NScripts, 283 // //0x11 LANG_JAPANESE Japanese 284 // QFont::Hiragana, 285 // //0x12 LANG_KOREAN Korean 286 // QFont::Hangul, 287 // //0x13 LANG_DUTCH Dutch 288 // QFont::NScripts, 289 // //0x14 LANG_NORWEGIAN Norwegian 290 // QFont::NScripts, 291 // //0x15 LANG_POLISH Polish 292 // QFont::NScripts, 293 // //0x16 LANG_PORTUGUESE Portuguese 294 // QFont::NScripts, 295 // QFont::NScripts, 296 // //0x18 LANG_ROMANIAN Romanian 297 // QFont::NScripts, 298 // //0x19 LANG_RUSSIAN Russian 299 // QFont::Cyrillic, 300 // //0x1a LANG_CROATIAN Croatian 301 // //0x1a LANG_SERBIAN Serbian 302 // QFont::NScripts, 303 // //0x1b LANG_SLOVAK Slovak 304 // QFont::NScripts, 305 // //0x1c LANG_ALBANIAN Albanian 306 // QFont::NScripts, 307 // //0x1d LANG_SWEDISH Swedish 308 // QFont::NScripts, 309 // //0x1e LANG_THAI Thai 310 // QFont::Thai, 311 // //0x1f LANG_TURKISH Turkish 312 // QFont::NScripts, 313 // 314 // //0x20 LANG_URDU Urdu 315 // QFont::NScripts, 316 // //0x21 LANG_INDONESIAN Indonesian 317 // QFont::NScripts, 318 // //0x22 LANG_UKRAINIAN Ukrainian 319 // QFont::NScripts, 320 // //0x23 LANG_BELARUSIAN Belarusian 321 // QFont::NScripts, 322 // //0x24 LANG_SLOVENIAN Slovenian 323 // QFont::NScripts, 324 // //0x25 LANG_ESTONIAN Estonian 325 // QFont::NScripts, 326 // //0x26 LANG_LATVIAN Latvian 327 // QFont::NScripts, 328 // //0x27 LANG_LITHUANIAN Lithuanian 329 // QFont::NScripts, 330 // QFont::NScripts, 331 // //0x29 LANG_FARSI Farsi 332 // QFont::NScripts, 333 // //0x2a LANG_VIETNAMESE Vietnamese 334 // QFont::Latin, // ##### maybe use QFont::CombiningMarks instead? 335 // //0x2b LANG_ARMENIAN Armenian 336 // QFont::Armenian, 337 // //0x2c LANG_AZERI Azeri 338 // QFont::NScripts, 339 // //0x2d LANG_BASQUE Basque 340 // QFont::NScripts, 341 // QFont::NScripts, 342 // //0x2f LANG_MACEDONIAN FYRO Macedonian 343 // QFont::NScripts, 344 // 345 // QFont::NScripts, 346 // QFont::NScripts, 347 // QFont::NScripts, 348 // QFont::NScripts, 349 // QFont::NScripts, 350 // QFont::NScripts, 351 // //0x36 LANG_AFRIKAANS Afrikaans 352 // QFont::NScripts, 353 // //0x37 LANG_GEORGIAN Georgian 354 // QFont::NScripts, 355 // //0x38 LANG_FAEROESE Faeroese 356 // QFont::NScripts, 357 // //0x39 LANG_HINDI Hindi 358 // QFont::Devanagari, 359 // QFont::NScripts, 360 // QFont::NScripts, 361 // QFont::NScripts, 362 // QFont::NScripts, 363 // //0x3e LANG_MALAY Malay 364 // QFont::NScripts, 365 // //0x3f LANG_KAZAK Kazak 366 // QFont::NScripts, 367 // 368 // //0x40 LANG_KYRGYZ Kyrgyz 369 // QFont::NScripts, 370 // //0x41 LANG_SWAHILI Swahili 371 // QFont::NScripts, 372 // QFont::NScripts, 373 // //0x43 LANG_UZBEK Uzbek 374 // QFont::NScripts, 375 // //0x44 LANG_TATAR Tatar 376 // QFont::NScripts, 377 // //0x45 LANG_BENGALI Not supported. 378 // QFont::Bengali, 379 // //0x46 LANG_PUNJABI Punjabi 380 // QFont::Gurmukhi, 381 // //0x47 LANG_GUJARATI Gujarati 382 // QFont::Gujarati, 383 // //0x48 LANG_ORIYA Not supported. 384 // QFont::Oriya, 385 // //0x49 LANG_TAMIL Tamil 386 // QFont::Tamil, 387 // //0x4a LANG_TELUGU Telugu 388 // QFont::Telugu, 389 // //0x4b LANG_KANNADA Kannada 390 // QFont::Kannada, 391 // //0x4c LANG_MALAYALAM Not supported. 392 // QFont::Malayalam, 393 // //0x4d LANG_ASSAMESE Not supported. 394 // QFont::NScripts, 395 // //0x4e LANG_MARATHI Marathi 396 // QFont::NScripts, 397 // //0x4f LANG_SANSKRIT Sanskrit 398 // QFont::Devanagari, 399 // 400 // //0x50 LANG_MONGOLIAN Mongolian 401 // QFont::Mongolian, 402 // QFont::NScripts, 403 // QFont::NScripts, 404 // QFont::NScripts, 405 // QFont::NScripts, 406 // QFont::NScripts, 407 // //0x56 LANG_GALICIAN Galician 408 // QFont::NScripts, 409 // //0x57 LANG_KONKANI Konkani 410 // QFont::NScripts, 411 // //0x58 LANG_MANIPURI Not supported. 412 // QFont::NScripts, 413 // //0x59 LANG_SINDHI Not supported. 414 // QFont::NScripts, 415 // //0x5a LANG_SYRIAC Syriac 416 // QFont::Syriac, 417 // QFont::NScripts, 418 // QFont::NScripts, 419 // QFont::NScripts, 420 // QFont::NScripts, 421 // QFont::NScripts, 422 // 423 // //0x60 LANG_KASHMIRI Not supported. 424 // QFont::NScripts, 425 // //0x61 LANG_NEPALI Not supported. 426 // QFont::NScripts, 427 // QFont::NScripts, 428 // QFont::NScripts, 429 // QFont::NScripts, 430 // //0x65 LANG_DIVEHI Divehi 431 // QFont::NScripts, 432 // QFont::NScripts, 433 // QFont::NScripts, 434 // QFont::NScripts, 435 // QFont::NScripts, 436 // QFont::NScripts, 437 // QFont::NScripts, 438 // QFont::NScripts, 439 // QFont::NScripts, 440 // QFont::NScripts, 441 // QFont::NScripts, 442 // 443 // QFont::NScripts, 444 // QFont::NScripts, 445 // QFont::NScripts, 446 // QFont::NScripts, 447 // QFont::NScripts, 448 // QFont::NScripts, 449 // QFont::NScripts, 450 // QFont::NScripts, 451 // QFont::NScripts, 452 // QFont::NScripts, 453 // QFont::NScripts, 454 // QFont::NScripts, 455 // QFont::NScripts, 456 // QFont::NScripts, 457 // QFont::NScripts, 458 // //0x7f LANG_INVARIANT 459 // QFont::NScripts, 460 //}; 461 // 462 //static inline QFont::Script scriptForWinLanguage( DWORD langid ) 463 //{ 464 // QFont::Script script = (QFont::Script)script_for_win_language[langid]; 465 // if ( script == QFont::NScripts ) 466 // qWarning( "Qt Uniscribe support: Encountered unhandled language id %x", (unsigned int)langid ); 467 // return script; 468 //} 469 // 470 //static inline bool isAsian( unsigned short ch ) 471 //{ 472 // return (ch > 0x2dff && ch < 0xfb00) || ((ch & 0xff00) == 0x1100); 473 //} 474 // 475 // 476 //// we're not using Uniscribe's BiDi algorithm, since it is (a) not 100% Unicode compliant and 477 //// (b) seems to work wrongly when trying to use it with a base level != 0. 478 //// 479 //// This function does uses Uniscribe to do the script analysis and creates items from this. 480 //static void uspAppendItems(QTextEngine *engine, int &start, int &stop, BidiControl &control, QChar::Direction dir) 481 //{ 482 // QScriptItemArray &items = engine->items; 483 // const QChar *text = engine->string.unicode(); 484 // 485 // if ( start > stop ) { 486 // // #### the algorithm is currently not really safe against this. Still needs fixing. 487 //// qWarning( "Bidi: appendItems() internal error" ); 488 // return; 489 // } 490 // 491 // int level = control.level(); 492 // 493 // if(dir != QChar::DirON) { 494 // // add level of run (cases I1 & I2) 495 // if( level % 2 ) { 496 // if(dir == QChar::DirL || dir == QChar::DirAN || dir == QChar::DirEN ) 497 // level++; 498 // } else { 499 // if( dir == QChar::DirR ) 500 // level++; 501 // else if( dir == QChar::DirAN || dir == QChar::DirEN ) 502 // level += 2; 503 // } 504 // } 505 // 506 // SCRIPT_ITEM s_items[256]; 507 // SCRIPT_ITEM *usp_items = s_items; 508 // 509 // int numItems; 510 // HRESULT res = ScriptItemize( (WCHAR *)(text+start), stop-start+1, 255, 0, 0, usp_items, &numItems ); 511 // 512 // if ( res == E_OUTOFMEMORY ) { 513 // int alloc = 256; 514 // usp_items = 0; 515 // while( res == E_OUTOFMEMORY ) { 516 // alloc *= 2; 517 // usp_items = (SCRIPT_ITEM *)realloc( usp_items, alloc * sizeof( SCRIPT_ITEM ) ); 518 // res = ScriptItemize( (WCHAR *)(text+start), stop-start+1, alloc-1, 0, 0, usp_items, &numItems ); 519 // } 520 // } 521 // items.resize( items.size() + numItems ); 522 // int i; 523 // for( i = 0; i < numItems; i++ ) { 524 // QScriptItem item; 525 // item.analysis = usp_items[i].a; 526 // item.position = usp_items[i].iCharPos+start; 527 // item.analysis.bidiLevel = level; 528 // item.analysis.override = control.override(); 529 // 530 // int rstart = usp_items[i].iCharPos; 531 // int rstop = usp_items[i+1].iCharPos-1; 532 // bool b = TRUE; 533 // for ( int j = rstart; j <= rstop; j++ ) { 534 // 535 // unsigned short uc = text[j+start].unicode(); 536 // QChar::Category category = ::category( uc ); 537 // if ( uc == 0xfffcU || uc == 0x2028U ) { 538 // item.analysis.script = usp_latin_script; 539 // item.isObject = TRUE; 540 // b = TRUE; 541 // } else if ((uc >= 9 && uc <=13) || 542 // (category >= QChar::Separator_Space && category <= QChar::Separator_Paragraph)) { 543 // item.analysis.script = usp_latin_script; 544 // item.isSpace = TRUE; 545 // item.isTab = (uc == '\t'); 546 // if (item.isTab) 547 // item.analysis.bidiLevel = control.baseLevel(); 548 // b = TRUE; 549 // } else if (b) { 550 // b = FALSE; 551 // } else { 552 // continue; 553 // } 554 // 555 // item.position = j+start; 556 // items.append( item ); 557 // item.analysis = usp_items[i].a; 558 // item.analysis.bidiLevel = level; 559 // item.analysis.override = control.override(); 560 // item.isSpace = item.isTab = item.isObject = FALSE; 561 // } 562 // } 563 // 564 // if ( usp_items != s_items ) 565 // free( usp_items ); 566 // 567 // ++stop; 568 // start = stop; 569 //} 570 480 // This function does uses Uniscribe to do the script analysis and creates items from this. 481 static void uspAppendItems(QTextEngine *engine, int &start, int &stop, BidiControl &control, QChar::Direction dir) 482 { 483 QScriptItemArray &items = engine->items; 484 const QChar *text = engine->string.unicode(); 485 486 if ( start > stop ) { 487 // #### the algorithm is currently not really safe against this. Still needs fixing. 488 // qWarning( "Bidi: appendItems() internal error" ); 489 return; 490 } 491 492 int level = control.level(); 493 494 if(dir != QChar::DirON) { 495 // add level of run (cases I1 & I2) 496 if( level % 2 ) { 497 if(dir == QChar::DirL || dir == QChar::DirAN || dir == QChar::DirEN ) 498 level++; 499 } else { 500 if( dir == QChar::DirR ) 501 level++; 502 else if( dir == QChar::DirAN || dir == QChar::DirEN ) 503 level += 2; 504 } 505 } 506 507 SCRIPT_ITEM s_items[256]; 508 SCRIPT_ITEM *usp_items = s_items; 509 510 int numItems; 511 HRESULT res = ScriptItemize( (WCHAR *)(text+start), stop-start+1, 255, 0, 0, usp_items, &numItems ); 512 513 if ( res == E_OUTOFMEMORY ) { 514 int alloc = 256; 515 usp_items = 0; 516 while( res == E_OUTOFMEMORY ) { 517 alloc *= 2; 518 usp_items = (SCRIPT_ITEM *)realloc( usp_items, alloc * sizeof( SCRIPT_ITEM ) ); 519 res = ScriptItemize( (WCHAR *)(text+start), stop-start+1, alloc-1, 0, 0, usp_items, &numItems ); 520 } 521 } 522 items.resize( items.size() + numItems ); 523 int i; 524 for( i = 0; i < numItems; i++ ) { 525 QScriptItem item; 526 item.analysis = usp_items[i].a; 527 item.position = usp_items[i].iCharPos+start; 528 item.analysis.bidiLevel = level; 529 item.analysis.override = control.override(); 530 531 int rstart = usp_items[i].iCharPos; 532 int rstop = usp_items[i+1].iCharPos-1; 533 bool b = TRUE; 534 for ( int j = rstart; j <= rstop; j++ ) { 535 536 unsigned short uc = text[j+start].unicode(); 537 QChar::Category category = ::category( uc ); 538 if ( uc == 0xfffcU || uc == 0x2028U ) { 539 item.analysis.script = usp_latin_script; 540 item.isObject = TRUE; 541 b = TRUE; 542 } else if ((uc >= 9 && uc <=13) || 543 (category >= QChar::Separator_Space && category <= QChar::Separator_Paragraph)) { 544 item.analysis.script = usp_latin_script; 545 item.isSpace = TRUE; 546 item.isTab = (uc == '\t'); 547 if (item.isTab) 548 item.analysis.bidiLevel = control.baseLevel(); 549 b = TRUE; 550 } else if (b) { 551 b = FALSE; 552 } else { 553 continue; 554 } 555 556 item.position = j+start; 557 items.append( item ); 558 item.analysis = usp_items[i].a; 559 item.analysis.bidiLevel = level; 560 item.analysis.override = control.override(); 561 item.isSpace = item.isTab = item.isObject = FALSE; 562 } 563 } 564 565 if ( usp_items != s_items ) 566 free( usp_items ); 567 568 ++stop; 569 start = stop; 570 } 571 #endif // if 0 571 572 572 573 // -----------------------------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.