Changeset 561 for trunk/src/gui/text/qfontdatabase_win.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/text/qfontdatabase_win.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 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 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 41 41 42 42 #include "qt_windows.h" 43 #include <qmath.h> 43 44 #include <private/qapplication_p.h> 44 45 #include "qfont_p.h" … … 196 197 197 198 HDC hdc = GetDC( 0 ); 198 HFONT hfont; 199 QT_WA( { 200 LOGFONTW lf; 201 memset( &lf, 0, sizeof( LOGFONTW ) ); 202 memcpy( lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.length())*sizeof(QChar) ); 203 lf.lfCharSet = DEFAULT_CHARSET; 204 hfont = CreateFontIndirectW( &lf ); 205 }, { 206 LOGFONTA lf; 207 memset( &lf, 0, sizeof( LOGFONTA ) ); 208 QByteArray lfam = familyName.toLocal8Bit(); 209 memcpy( lf.lfFaceName, lfam, qMin(LF_FACESIZE, lfam.size()) ); 210 lf.lfCharSet = DEFAULT_CHARSET; 211 hfont = CreateFontIndirectA( &lf ); 212 } ); 199 LOGFONT lf; 200 memset(&lf, 0, sizeof(LOGFONT)); 201 memcpy(lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.length()) * sizeof(wchar_t)); 202 lf.lfCharSet = DEFAULT_CHARSET; 203 HFONT hfont = CreateFontIndirect(&lf); 204 213 205 if(!hfont) { 214 206 ReleaseDC(0, hdc); … … 246 238 } 247 239 248 static void getFontSignature(const QString &familyName,249 NEWTEXTMETRICEX *textmetric,250 FONTSIGNATURE *signature)251 {252 QT_WA({253 Q_UNUSED(familyName);254 *signature = textmetric->ntmFontSig;255 }, {256 // the textmetric structure we get from EnumFontFamiliesEx on Win9x has257 // a FONTSIGNATURE, but that one is uninitialized and doesn't work. Have to go258 // the hard way and load the font to find out.259 HDC hdc = GetDC(0);260 LOGFONTA lf;261 memset(&lf, 0, sizeof(LOGFONTA));262 QByteArray lfam = familyName.toLocal8Bit();263 memcpy(lf.lfFaceName, lfam.data(), qMin(LF_FACESIZE, lfam.length()));264 lf.lfCharSet = DEFAULT_CHARSET;265 HFONT hfont = CreateFontIndirectA(&lf);266 HGDIOBJ oldobj = SelectObject(hdc, hfont);267 GetTextCharsetInfo(hdc, signature, 0);268 SelectObject(hdc, oldobj);269 DeleteObject(hfont);270 ReleaseDC(0, hdc);271 });272 }273 274 240 static 275 241 void addFontToDatabase(QString familyName, const QString &scriptName, … … 289 255 int size; 290 256 291 // QString escript = QString::from Utf16((ushort *)f->elfScript);257 // QString escript = QString::fromWCharArray(f->elfScript); 292 258 // qDebug("script=%s", escript.latin1()); 293 259 294 QT_WA({ 295 NEWTEXTMETRIC *tm = (NEWTEXTMETRIC *)textmetric; 296 fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH); 297 ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE); 298 scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE); 299 size = scalable ? SMOOTH_SCALABLE : tm->tmHeight; 300 italic = tm->tmItalic; 301 weight = tm->tmWeight; 302 } , { 303 NEWTEXTMETRICA *tm = (NEWTEXTMETRICA *)textmetric; 304 fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH); 305 ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE); 306 scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE); 307 size = scalable ? SMOOTH_SCALABLE : tm->tmHeight; 308 italic = tm->tmItalic; 309 weight = tm->tmWeight; 310 }); 260 NEWTEXTMETRIC *tm = (NEWTEXTMETRIC *)textmetric; 261 fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH); 262 ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE); 263 scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE); 264 size = scalable ? SMOOTH_SCALABLE : tm->tmHeight; 265 italic = tm->tmItalic; 266 weight = tm->tmWeight; 267 311 268 // the "@family" fonts are just the same as "family". Ignore them. 312 269 if (familyName[0] != QLatin1Char('@') && !familyName.startsWith(QLatin1String("WST_"))) { … … 365 322 signature->fsUsb[2], signature->fsUsb[3] 366 323 }; 367 #ifdef Q_ OS_WINCE324 #ifdef Q_WS_WINCE 368 325 if (signature->fsUsb[0] == 0) { 369 326 // If the unicode ranges bit mask is zero then … … 421 378 storeFont(ENUMLOGFONTEX* f, NEWTEXTMETRICEX *textmetric, int type, LPARAM /*p*/) 422 379 { 423 QString familyName; 424 QT_WA({ 425 familyName = QString::fromUtf16((ushort*)f->elfLogFont.lfFaceName); 426 },{ 427 ENUMLOGFONTEXA *fa = (ENUMLOGFONTEXA *)f; 428 familyName = QString::fromLocal8Bit(fa->elfLogFont.lfFaceName); 429 }); 430 QString script = QT_WA_INLINE(QString::fromUtf16((const ushort *)f->elfScript), 431 QString::fromLocal8Bit((const char *)((ENUMLOGFONTEXA *)f)->elfScript)); 432 433 FONTSIGNATURE signature; 434 getFontSignature(familyName, textmetric, &signature); 380 QString familyName = QString::fromWCharArray(f->elfLogFont.lfFaceName); 381 QString script = QString::fromWCharArray(f->elfScript); 382 383 FONTSIGNATURE signature = textmetric->ntmFontSig; 435 384 436 385 // NEWTEXTMETRICEX is a NEWTEXTMETRIC, which according to the documentation is … … 460 409 HDC dummy = GetDC(0); 461 410 462 QT_WA({ 463 LOGFONT lf; 464 lf.lfCharSet = DEFAULT_CHARSET; 465 if (fam.isNull()) { 466 lf.lfFaceName[0] = 0; 467 } else { 468 memcpy(lf.lfFaceName, fam.utf16(), sizeof(TCHAR)*qMin(fam.length()+1,32)); // 32 = Windows hard-coded 469 } 470 lf.lfPitchAndFamily = 0; 471 472 EnumFontFamiliesEx(dummy, &lf, 473 (FONTENUMPROC)storeFont, (LPARAM)privateDb(), 0); 474 } , { 475 LOGFONTA lf; 476 lf.lfCharSet = DEFAULT_CHARSET; 477 if (fam.isNull()) { 478 lf.lfFaceName[0] = 0; 479 } else { 480 QByteArray lname = fam.toLocal8Bit(); 481 memcpy(lf.lfFaceName,lname.data(), 482 qMin(lname.length()+1,32)); // 32 = Windows hard-coded 483 } 484 lf.lfPitchAndFamily = 0; 485 486 EnumFontFamiliesExA(dummy, &lf, 487 (FONTENUMPROCA)storeFont, (LPARAM)privateDb(), 0); 488 }); 411 LOGFONT lf; 412 lf.lfCharSet = DEFAULT_CHARSET; 413 if (fam.isNull()) { 414 lf.lfFaceName[0] = 0; 415 } else { 416 memcpy(lf.lfFaceName, fam.utf16(), sizeof(wchar_t) * qMin(fam.length() + 1, 32)); // 32 = Windows hard-coded 417 } 418 lf.lfPitchAndFamily = 0; 419 420 EnumFontFamiliesEx(dummy, &lf, 421 (FONTENUMPROC)storeFont, (LPARAM)privateDb(), 0); 489 422 490 423 ReleaseDC(0, dummy); … … 497 430 const QString familyName = fnt.families.at(j); 498 431 HDC hdc = GetDC(0); 499 HFONT hfont; 500 QT_WA({ 501 LOGFONTW lf; 502 memset(&lf, 0, sizeof(LOGFONTW)); 503 memcpy(lf.lfFaceName, familyName.utf16(), qMin(LF_FACESIZE, familyName.size())); 504 lf.lfCharSet = DEFAULT_CHARSET; 505 hfont = CreateFontIndirectW(&lf); 506 } , { 507 LOGFONTA lf; 508 memset(&lf, 0, sizeof(LOGFONTA)); 509 QByteArray lfam = familyName.toLocal8Bit(); 510 memcpy(lf.lfFaceName, lfam.data(), qMin(LF_FACESIZE, lfam.length())); 511 lf.lfCharSet = DEFAULT_CHARSET; 512 hfont = CreateFontIndirectA(&lf); 513 }); 432 LOGFONT lf; 433 memset(&lf, 0, sizeof(LOGFONT)); 434 memcpy(lf.lfFaceName, familyName.utf16(), sizeof(wchar_t) * qMin(LF_FACESIZE, familyName.size())); 435 lf.lfCharSet = DEFAULT_CHARSET; 436 HFONT hfont = CreateFontIndirect(&lf); 514 437 HGDIOBJ oldobj = SelectObject(hdc, hfont); 515 438 … … 550 473 for (int f = 0; f < db->count; f++) { 551 474 QtFontFamily *family = db->families[f]; 552 qDebug(" %s: %p", family->name.latin1(), family);475 qDebug(" %s: %p", qPrintable(family->name), family); 553 476 populate_database(family->name); 554 477 … … 599 522 HDC dc = ((request.styleStrategy & QFont::PreferDevice) && fp->hdc) ? fp->hdc : shared_dc(); 600 523 SelectObject(dc, fe->hfont); 601 QT_WA({ 602 TCHAR n[64]; 603 GetTextFaceW(dc, 64, n); 604 fe->fontDef.family = QString::fromUtf16((ushort*)n); 605 fe->fontDef.fixedPitch = !(fe->tm.w.tmPitchAndFamily & TMPF_FIXED_PITCH); 606 } , { 607 char an[64]; 608 GetTextFaceA(dc, 64, an); 609 fe->fontDef.family = QString::fromLocal8Bit(an); 610 fe->fontDef.fixedPitch = !(fe->tm.a.tmPitchAndFamily & TMPF_FIXED_PITCH); 611 }); 524 wchar_t n[64]; 525 GetTextFace(dc, 64, n); 526 fe->fontDef.family = QString::fromWCharArray(n); 527 fe->fontDef.fixedPitch = !(fe->tm.tmPitchAndFamily & TMPF_FIXED_PITCH); 612 528 if (fe->fontDef.pointSize < 0) { 613 529 fe->fontDef.pointSize = fe->fontDef.pixelSize * 72. / fp->dpi; … … 700 616 701 617 bool stockFont = false; 618 bool preferClearTypeAA = false; 702 619 703 620 HFONT hfont = 0; 704 621 705 622 if (fp->rawMode) { // will choose a stock font 706 int f, deffnt; 707 // ### why different? 708 if ((QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) || QSysInfo::WindowsVersion == QSysInfo::WV_32s) 709 deffnt = SYSTEM_FONT; 710 else 711 deffnt = DEFAULT_GUI_FONT; 623 int f, deffnt = SYSTEM_FONT; 712 624 QString fam = desc->family->name.toLower(); 713 625 if (fam == QLatin1String("default")) … … 715 627 else if (fam == QLatin1String("system")) 716 628 f = SYSTEM_FONT; 717 #ifndef Q_ OS_WINCE629 #ifndef Q_WS_WINCE 718 630 else if (fam == QLatin1String("system_fixed")) 719 631 f = SYSTEM_FIXED_FONT; … … 760 672 } 761 673 762 lf.lfHeight = - request.pixelSize;674 lf.lfHeight = -qRound(request.pixelSize); 763 675 lf.lfWidth = 0; 764 676 lf.lfEscapement = 0; … … 774 686 if (request.styleStrategy & QFont::PreferBitmap) { 775 687 strat = OUT_RASTER_PRECIS; 776 #ifndef Q_ OS_WINCE688 #ifndef Q_WS_WINCE 777 689 } else if (request.styleStrategy & QFont::PreferDevice) { 778 690 strat = OUT_DEVICE_PRECIS; 779 691 } else if (request.styleStrategy & QFont::PreferOutline) { 780 QT_WA({ 781 strat = OUT_OUTLINE_PRECIS; 782 } , { 783 strat = OUT_TT_PRECIS; 784 }); 692 strat = OUT_OUTLINE_PRECIS; 785 693 } else if (request.styleStrategy & QFont::ForceOutline) { 786 694 strat = OUT_TT_ONLY_PRECIS; … … 794 702 if (request.styleStrategy & QFont::PreferMatch) 795 703 qual = DRAFT_QUALITY; 796 #ifndef Q_ OS_WINCE704 #ifndef Q_WS_WINCE 797 705 else if (request.styleStrategy & QFont::PreferQuality) 798 706 qual = PROOF_QUALITY; … … 800 708 801 709 if (request.styleStrategy & QFont::PreferAntialias) { 802 if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) 803 qual = 5; // == CLEARTYPE_QUALITY; 804 else 710 if (QSysInfo::WindowsVersion >= QSysInfo::WV_XP) { 711 qual = CLEARTYPE_QUALITY; 712 preferClearTypeAA = true; 713 } else { 805 714 qual = ANTIALIASED_QUALITY; 715 } 806 716 } else if (request.styleStrategy & QFont::NoAntialias) { 807 717 qual = NONANTIALIASED_QUALITY; … … 825 735 fam = QLatin1String("Courier New"); 826 736 827 QT_WA({ 828 memcpy(lf.lfFaceName, fam.utf16(), sizeof(TCHAR)*qMin(fam.length()+1,32)); // 32 = Windows hard-coded 829 hfont = CreateFontIndirect(&lf); 830 } , { 831 // LOGFONTA and LOGFONTW are binary compatible 832 QByteArray lname = fam.toLocal8Bit(); 833 memcpy(lf.lfFaceName,lname.data(), 834 qMin(lname.length()+1,32)); // 32 = Windows hard-coded 835 hfont = CreateFontIndirectA((LOGFONTA*)&lf); 836 }); 737 memcpy(lf.lfFaceName, fam.utf16(), sizeof(wchar_t) * qMin(fam.length() + 1, 32)); // 32 = Windows hard-coded 738 hfont = CreateFontIndirect(&lf); 837 739 if (!hfont) 838 740 qErrnoWarning("QFontEngine::loadEngine: CreateFontIndirect failed"); … … 843 745 BOOL res; 844 746 HGDIOBJ oldObj = SelectObject(hdc, hfont); 845 QT_WA({ 846 TEXTMETRICW tm; 847 res = GetTextMetricsW(hdc, &tm); 848 avWidth = tm.tmAveCharWidth; 849 ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE; 850 } , { 851 TEXTMETRICA tm; 852 res = GetTextMetricsA(hdc, &tm); 853 avWidth = tm.tmAveCharWidth; 854 ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE; 855 }); 747 748 TEXTMETRIC tm; 749 res = GetTextMetrics(hdc, &tm); 750 avWidth = tm.tmAveCharWidth; 751 ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE; 752 856 753 SelectObject(hdc, oldObj); 857 754 … … 861 758 qErrnoWarning("QFontEngine::loadEngine: GetTextMetrics failed"); 862 759 lf.lfWidth = avWidth * request.stretch/100; 863 QT_WA({ 864 hfont = CreateFontIndirect(&lf); 865 } , { 866 hfont = CreateFontIndirectA((LOGFONTA*)&lf); 867 }); 760 hfont = CreateFontIndirect(&lf); 868 761 if (!hfont) 869 762 qErrnoWarning("QFontEngine::loadEngine: CreateFontIndirect with stretch failed"); 870 763 } 871 764 872 #ifndef Q_ OS_WINCE765 #ifndef Q_WS_WINCE 873 766 if (hfont == 0) { 874 767 hfont = (HFONT)GetStockObject(ANSI_VAR_FONT); … … 884 777 } 885 778 QFontEngineWin *few = new QFontEngineWin(font_name, hfont, stockFont, lf); 779 780 if (preferClearTypeAA) 781 few->glyphFormat = QFontEngineGlyphCache::Raster_RGBMask; 886 782 887 783 // Also check for OpenType tables when using complex scripts … … 964 860 QStringList family_list = familyList(req); 965 861 966 if(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based && req.family.toLower() == QLatin1String("ms sans serif")) {967 // small hack for Dos based machines to get the right font for non968 // latin text when using the default font.969 family_list << QLatin1String("Arial");970 }971 972 862 const char *stylehint = styleHint(d->request); 973 863 if (stylehint) … … 1011 901 } 1012 902 1013 1014 903 void QFontDatabase::load(const QFontPrivate *d, int script) 1015 904 { … … 1022 911 QFontDef req = d->request; 1023 912 if (req.pixelSize <= 0) 1024 req.pixelSize = qMax(1, qRound(req.pointSize * d->dpi / 72.)); 1025 req.pointSize = 0; 913 req.pixelSize = qreal((req.pointSize * d->dpi) / 72.); 914 if (req.pixelSize < 1) 915 req.pixelSize = 1; 1026 916 if (req.weight == 0) 1027 917 req.weight = QFont::Normal; … … 1040 930 1041 931 // set it to the actual pointsize, so QFontInfo will do the right thing 1042 req.pointSize = req.pixelSize*72./d->dpi; 932 if (req.pointSize < 0) 933 req.pointSize = req.pixelSize*72./d->dpi; 1043 934 1044 935 if (!fe) { … … 1135 1026 signature.fsUsb[2] = qFromBigEndian<quint32>(table + 50); 1136 1027 signature.fsUsb[3] = qFromBigEndian<quint32>(table + 54); 1137 1028 1138 1029 signature.fsCsb[0] = qFromBigEndian<quint32>(table + 78); 1139 1030 signature.fsCsb[1] = qFromBigEndian<quint32>(table + 82); 1031 } else { 1032 memset(&signature, 0, sizeof(signature)); 1140 1033 } 1141 1034 appFont->signatures << signature; … … 1160 1053 1161 1054 { 1162 #ifdef 1163 TCHARlpBuffer[MAX_PATH];1055 #ifdef QT_NO_TEMPORARYFILE 1056 wchar_t lpBuffer[MAX_PATH]; 1164 1057 GetTempPath(MAX_PATH, lpBuffer); 1165 QString s = QString::from Utf16((const ushort *)lpBuffer);1058 QString s = QString::fromWCharArray(lpBuffer); 1166 1059 QFile tempfile(s + QLatin1String("/font") + QString::number(GetTickCount()) + QLatin1String(".ttf")); 1167 1060 if (!tempfile.open(QIODevice::ReadWrite)) … … 1169 1062 QTemporaryFile tempfile(QLatin1String("XXXXXXXX.ttf")); 1170 1063 if (!tempfile.open()) 1171 #endif 1064 #endif // QT_NO_TEMPORARYFILE 1172 1065 return; 1173 1066 if (tempfile.write(fnt->data) == -1) 1174 1067 return; 1175 1068 1176 #ifndef 1069 #ifndef QT_NO_TEMPORARYFILE 1177 1070 tempfile.setAutoRemove(false); 1178 1071 #endif … … 1186 1079 #else 1187 1080 DWORD dummy = 0; 1188 HANDLE handle = ptrAddFontMemResourceEx((void *)fnt->data.constData(), 1189 fnt->data.size(), 1190 0, 1191 &dummy); 1081 HANDLE handle = ptrAddFontMemResourceEx((void *)fnt->data.constData(), fnt->data.size(), 0, 1082 &dummy); 1192 1083 if (handle == 0) 1193 1084 return; 1194 #endif 1085 #endif // Q_OS_WINCE 1195 1086 1196 1087 fnt->handle = handle; … … 1214 1105 PtrAddFontResourceExW ptrAddFontResourceExW = (PtrAddFontResourceExW)QLibrary::resolve(QLatin1String("gdi32"), 1215 1106 "AddFontResourceExW"); 1216 if (!ptrAddFontResourceExW) 1107 if (!ptrAddFontResourceExW 1108 || ptrAddFontResourceExW((wchar_t*)fnt->fileName.utf16(), FR_PRIVATE, 0) == 0) 1217 1109 return; 1218 1219 if (ptrAddFontResourceExW((LPCWSTR)fnt->fileName.utf16(), FR_PRIVATE, 0) == 0) 1220 return; 1221 #endif 1110 #endif // Q_OS_WINCE 1222 1111 1223 1112 fnt->memoryFont = false; … … 1245 1134 PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx = (PtrRemoveFontMemResourceEx)QLibrary::resolve(QLatin1String("gdi32"), 1246 1135 "RemoveFontMemResourceEx"); 1247 if (!ptrRemoveFontMemResourceEx) 1136 if (!ptrRemoveFontMemResourceEx 1137 || !ptrRemoveFontMemResourceEx(font.handle)) 1248 1138 return false; 1249 1250 if (!ptrRemoveFontMemResourceEx(font.handle)) 1251 return false; 1252 #endif 1139 #endif // Q_OS_WINCE 1253 1140 } else { 1254 1141 #ifdef Q_OS_WINCE … … 1258 1145 PtrRemoveFontResourceExW ptrRemoveFontResourceExW = (PtrRemoveFontResourceExW)QLibrary::resolve(QLatin1String("gdi32"), 1259 1146 "RemoveFontResourceExW"); 1260 if (!ptrRemoveFontResourceExW) 1147 if (!ptrRemoveFontResourceExW 1148 || !ptrRemoveFontResourceExW((LPCWSTR)font.fileName.utf16(), FR_PRIVATE, 0)) 1261 1149 return false; 1262 1263 if (!ptrRemoveFontResourceExW((LPCWSTR)font.fileName.utf16(), FR_PRIVATE, 0)) 1264 return false; 1265 #endif 1150 #endif // Q_OS_WINCE 1266 1151 } 1267 1152
Note:
See TracChangeset
for help on using the changeset viewer.