Changeset 8 for trunk/src/kernel/qfontdatabase.cpp
- Timestamp:
- Nov 16, 2005, 8:36:46 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel/qfontdatabase.cpp
r7 r8 71 71 #endif 72 72 73 #define SMOOTH_SCALABLE 0xffff 74 73 75 static int ucstricmp( const QString &as, const QString &bs ) 74 76 { … … 138 140 unsigned short pixelSize; 139 141 142 #ifdef Q_WS_PM 143 unsigned short pointSize; // in deca-points 144 LONG lMatch; 145 #endif 140 146 #ifdef Q_WS_X11 141 147 int count; … … 206 212 fakeOblique( FALSE ), count( 0 ), pixelSizes( 0 ) 207 213 { 208 #if defined(Q_WS_X11) 214 #if defined(Q_WS_PM) 215 szFacename[0] = 0; 216 #elif defined(Q_WS_X11) 209 217 weightName = setwidthName = 0; 210 #endif // Q_WS_X11218 #endif 211 219 } 212 220 … … 228 236 QtFontSize *pixelSizes; 229 237 238 #ifdef Q_WS_PM 239 CHAR szFacename [FACESIZE]; 240 #endif 230 241 #ifdef Q_WS_X11 231 242 const char *weightName; … … 233 244 #endif // Q_WS_X11 234 245 246 #ifdef Q_WS_PM 247 QtFontSize *pixelSize( 248 unsigned short size, bool = FALSE, unsigned short pointSize = 0 ); 249 #else 235 250 QtFontSize *pixelSize( unsigned short size, bool = FALSE ); 251 #endif 236 252 }; 237 253 … … 247 263 } 248 264 265 #ifdef Q_WS_PM 266 QtFontSize *QtFontStyle::pixelSize( 267 unsigned short size, bool add, unsigned short pointSize ) 268 #else 249 269 QtFontSize *QtFontStyle::pixelSize( unsigned short size, bool add ) 270 #endif 250 271 { 251 272 for ( int i = 0; i < count; i++ ) { 273 #ifdef Q_WS_PM 274 if ( 275 pixelSizes[i].pixelSize == size && 276 ( 277 size == SMOOTH_SCALABLE || 278 !pointSize || 279 pixelSizes[i].pointSize == pointSize 280 ) 281 ) 282 #else 252 283 if ( pixelSizes[i].pixelSize == size ) 284 #endif 253 285 return pixelSizes + i; 254 286 } … … 261 293 (((count+8) >> 3 ) << 3) * sizeof(QtFontSize) ); 262 294 pixelSizes[count].pixelSize = size; 295 #ifdef Q_WS_PM 296 pixelSizes[count].pointSize = pointSize; 297 pixelSizes[count].lMatch = 0; 298 #endif 263 299 #ifdef Q_WS_X11 264 300 pixelSizes[count].count = 0; … … 336 372 name( n ), count( 0 ), foundries( 0 ) { 337 373 memset( scripts, 0, sizeof( scripts ) ); 374 #ifdef Q_WS_PM 375 //@@TODO (dmik): temporary solution to let QFontDialog work: 376 // at least UnknownScript is supported. 377 scripts[QFont::UnknownScript] = Supported; 378 #endif 338 379 } 339 380 ~QtFontFamily() { … … 357 398 bool fullyLoaded : 1; 358 399 QString name; 400 #ifndef Q_WS_X11 359 401 QString rawName; 402 #endif 360 403 #ifdef Q_WS_X11 361 404 QCString fontFilename; … … 393 436 class QFontDatabasePrivate { 394 437 public: 395 QFontDatabasePrivate() : count( 0 ), families( 0 ) { } 438 QFontDatabasePrivate() : 439 count( 0 ), families( 0 ) { } 396 440 ~QFontDatabasePrivate() { 441 #ifdef Q_WS_PM 442 cleanup(); 443 #else 397 444 while ( count-- ) 398 445 delete families[count]; 399 446 free( families ); 447 #endif 400 448 } 401 449 QtFontFamily *family( const QString &f, bool = FALSE ); … … 403 451 int count; 404 452 QtFontFamily **families; 453 454 #ifdef Q_WS_PM 455 static QFontDatabasePrivate* instance(); 456 private: 457 void cleanup() { 458 while ( count ) 459 delete families[--count]; 460 free( families ); 461 families = 0; 462 } 463 void reload(); 464 #endif 405 465 }; 406 466 … … 627 687 628 688 static QSingleCleanupHandler<QFontDatabasePrivate> qfontdatabase_cleanup; 689 #ifdef Q_WS_PM 690 QFontDatabasePrivate* QFontDatabasePrivate::instance() 691 { 692 static QFontDatabasePrivate *db = 0; 693 if ( !db ) { 694 db = new QFontDatabasePrivate; 695 qfontdatabase_cleanup.set(&db); 696 db->reload(); 697 } 698 return db; 699 } 700 #else 629 701 static QFontDatabasePrivate *db=0; 630 # define SMOOTH_SCALABLE 0xffff702 #endif 631 703 632 704 #if defined( Q_WS_X11 ) … … 636 708 #elif defined( Q_WS_WIN ) 637 709 # include "qfontdatabase_win.cpp" 710 #elif defined( Q_WS_PM ) 711 # include "qfontdatabase_pm.cpp" 638 712 #elif defined( Q_WS_QWS ) 639 713 # include "qfontdatabase_qws.cpp" … … 643 717 644 718 645 #if defined(Q_WS_X11) || defined(Q_WS_WIN) 719 #if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_PM) 646 720 static 647 721 unsigned int bestFoundry( QFont::Script script, unsigned int score, int styleStrategy, … … 650 724 QtFontFoundry **best_foundry, QtFontStyle **best_style, 651 725 QtFontSize **best_size 652 #if def Q_WS_X11726 #if defined(Q_WS_X11) 653 727 , QtFontEncoding **best_encoding, int force_encoding_id 728 #elif defined(Q_WS_PM) 729 , int pointSize 654 730 #endif 655 731 ) … … 711 787 // 1. see if we have an exact matching size 712 788 if (! (styleStrategy & QFont::ForceOutline)) { 789 #if defined(Q_WS_PM) 790 size = style->pixelSize(pixelSize, FALSE, pointSize); 791 #else 713 792 size = style->pixelSize(pixelSize); 793 #endif 714 794 if (size) px = size->pixelSize; 715 795 } … … 843 923 #endif 844 924 925 #ifdef Q_WS_PM 926 QFontDatabasePrivate *db = QFontDatabasePrivate::instance(); 927 #else 845 928 if ( !db ) 846 929 initializeDb(); 930 #endif 847 931 848 932 QFontEngine *fe = 0; 849 933 if ( fp ) { 934 #ifndef Q_WS_PM 850 935 if ( fp->rawMode ) { 851 936 fe = loadEngine( script, fp, request, 0, 0, 0 … … 859 944 return fe; 860 945 } 946 #endif // !Q_WS_PM 861 947 862 948 QFontCache::Key key( request, script, 863 #if def Q_WS_WIN949 #if defined(Q_WS_WIN) || defined(Q_WS_PM) 864 950 (int)fp->paintdevice 865 951 #else … … 880 966 parseFontName( request.family, foundry_name, family_name ); 881 967 968 #ifdef Q_WS_PM 969 // the "System VIO" PM font is broken in such way that its real pixel 970 // sizes do not correspond to their nominal point sizes specified in the 971 // font header (i.e. pixelSize is not equal to (pointSize * dpi) / 720). 972 // therefore we use the special table to convert pointSize to pixelSize 973 // in order to let bestFoundry() select the proper font with its nominal 974 // point size corresponding to the requested one. 975 // NOTE: this will produce incorrect results if "System VIO" is NOT 976 // an OS/2 standatd supplied bitmap font. 977 if( !ucstricmp( family_name, "System VIO") ) { 978 // possible sizes of the "System VIO" font ("pixel, point" pairs), 979 // sorted by point size 980 static const short SystemVIO_sz[] = { 981 12, 20, 16, 30, 982 8, 40, 13, 50, 983 15, 60, 24, 70, 984 8, 80, 10, 90, 985 12, 100, 14, 110, 986 16, 120, 18, 130, 987 16, 140, 12, 150, 988 20, 160, 21, 170, 989 29, 180, 990 }; 991 const int SystemVIO_sz_len = sizeof(SystemVIO_sz) / sizeof(SystemVIO_sz[0]); 992 int pt = request.pointSize; 993 pt = QMAX( pt, SystemVIO_sz [1] ); // min limit 994 pt = QMIN( pt, SystemVIO_sz [SystemVIO_sz_len - 1] ); // max limit 995 int i = 1; 996 while ( SystemVIO_sz[i] < pt ) i += 2; 997 if ( SystemVIO_sz[i] > pt ) { 998 int prev = SystemVIO_sz[i-2]; 999 int mid = prev + (SystemVIO_sz[i] - prev + 1) / 2; 1000 if ( pt < mid ) i -= 2; 1001 } 1002 ((QFontDef&)request).pixelSize = SystemVIO_sz[i-1]; 1003 ((QFontDef&)request).pointSize = SystemVIO_sz[i]; 1004 } 1005 #endif 1006 882 1007 #ifdef Q_WS_X11 883 1008 if (family_name.isEmpty() && script == QFont::Han) { … … 905 1030 " stretch: %d\n" 906 1031 " pixelSize: %d\n" 1032 " pointSize: %d\n" 907 1033 " pitch: %c", 908 1034 family_name.isEmpty() ? "-- first in script --" : family_name.latin1(), 909 1035 foundry_name.isEmpty() ? "-- any --" : foundry_name.latin1(), 910 1036 script, scriptName( script ).latin1(), 911 request.weight, request.italic, request.stretch, request.pixelSize, pitch ); 1037 request.weight, request.italic, request.stretch, 1038 request.pixelSize, request.pointSize, 1039 pitch ); 912 1040 913 1041 #ifdef QT_XFT2 … … 944 1072 uint score_adjust = 0; 945 1073 QFont::Script override_script = script; 1074 #ifndef Q_WS_PM 946 1075 if ( ! ( try_family->scripts[script] & QtFontFamily::Supported ) 947 1076 && script != QFont::Unicode) { … … 978 1107 } 979 1108 } 1109 #endif // !Q_WS_PM 980 1110 981 1111 QtFontFoundry *try_foundry = 0; … … 992 1122 try_family, foundry_name, styleKey, request.pixelSize, pitch, 993 1123 &try_foundry, &try_style, &try_size 994 #if def Q_WS_X111124 #if defined(Q_WS_X11) 995 1125 , &try_encoding, force_encoding_id 1126 #elif defined(Q_WS_PM) 1127 , request.pointSize 996 1128 #endif 997 1129 ); … … 1002 1134 QString::null, styleKey, request.pixelSize, 1003 1135 pitch, &try_foundry, &try_style, &try_size 1004 #if def Q_WS_X111136 #if defined(Q_WS_X11) 1005 1137 , &try_encoding, force_encoding_id 1138 #elif defined(Q_WS_PM) 1139 , request.pointSize 1006 1140 #endif 1007 1141 ); … … 1047 1181 1048 1182 fe = loadEngine( script, fp, request, best_family, best_foundry, best_style 1049 #ifdef Q_WS_X11 1183 #if defined(Q_WS_PM) 1184 , best_size 1185 #elif defined(Q_WS_X11) 1050 1186 , best_size, best_encoding, ( force_encoding_id >= 0 ) 1051 1187 #endif … … 1060 1196 } 1061 1197 1198 #ifdef Q_WS_PM 1199 // On OS/2, fontDef.pixelSize and fontDef.pointSize are filled 1200 // by QFontEnginePM constructor 1201 #else 1062 1202 if ( best_style->smoothScalable ) 1063 1203 fe->fontDef.pixelSize = request.pixelSize; … … 1082 1222 fe->fontDef.pointSize = request.pointSize; 1083 1223 } 1224 #endif 1084 1225 fe->fontDef.styleHint = request.styleHint; 1085 1226 fe->fontDef.styleStrategy = request.styleStrategy; … … 1094 1235 1095 1236 if ( fe ) { 1237 #ifdef Q_WS_PM 1238 ///@@TODO (dmik): should do something here? 1239 #else 1096 1240 if ( script != QFont::Unicode && !canRender( fe, script ) ) { 1097 1241 FM_DEBUG( " WARN: font loaded cannot render sample 0x%04x", … … 1117 1261 return fe; 1118 1262 } 1263 #endif // !Q_WS_PM 1119 1264 1120 1265 if ( fp ) { 1121 1266 QFontCache::Key key( request, script, 1122 #if def Q_WS_WIN1267 #if defined(Q_WS_WIN) || defined(Q_WS_PM) 1123 1268 (int)fp->paintdevice 1124 1269 #else … … 1128 1273 QFontCache::instance->insertEngine( key, fe ); 1129 1274 1275 #ifndef Q_WS_PM 1130 1276 for ( int i = 0; i < QFont::NScripts; ++i ) { 1131 1277 if ( i == script ) continue; … … 1137 1283 QFontCache::instance->insertEngine( key, fe ); 1138 1284 } 1285 #endif // !Q_WS_PM 1139 1286 } 1140 1287 } else { 1141 1288 if ( request.family.isEmpty() ) { 1289 #ifdef Q_WS_PM 1290 //@@TODO (dmik): what to return in such case? 1291 qFatal( "QFontDatabase::findFont: request.family is empty and nothing is found, should it ever happen?" ); 1292 #else 1142 1293 FM_DEBUG( "returning box engine" ); 1143 1294 … … 1146 1297 if ( fp ) { 1147 1298 QFontCache::Key key( request, script, 1148 #if def Q_WS_WIN1299 #if defined(Q_WS_WIN) || defined(Q_WS_PM) 1149 1300 (int)fp->paintdevice 1150 1301 #else … … 1154 1305 QFontCache::instance->insertEngine( key, fe ); 1155 1306 } 1307 #endif // Q_WS_PM 1156 1308 } 1157 1309 } … … 1159 1311 return fe; 1160 1312 } 1161 #endif // Q_WS_X11 || Q_WS_WIN 1313 #endif // Q_WS_X11 || Q_WS_WIN || Q_WS_PM 1162 1314 1163 1315 … … 1355 1507 QFontDatabase::QFontDatabase() 1356 1508 { 1509 #ifdef Q_WS_PM 1510 d = QFontDatabasePrivate::instance(); 1511 #else 1357 1512 createDatabase(); 1358 1513 1359 1514 d = db; 1515 #endif 1360 1516 } 1361 1517 … … 1635 1791 1636 1792 if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) { 1637 #if def Q_WS_X111793 #if defined(Q_WS_X11) 1638 1794 const uint pointSize = qRound(qt_pointSize(size->pixelSize, 0, -1)); 1795 #elif defined(Q_WS_PM) 1796 //@@TODO (dmik): some bitmap fonts (i.e. System VIO) have point sizes 1797 // that do not really correlate with their actual pixel sizes (i.e. 1798 // their pointsize != pixelsizde * DPI / 72), What to return in that case? 1799 const uint pointSize = size->pointSize / 10; 1639 1800 #else 1640 1801 const uint pointSize = size->pixelSize; // embedded uses 72dpi … … 1740 1901 1741 1902 if ( size->pixelSize != 0 && size->pixelSize != USHRT_MAX ) { 1742 #if def Q_WS_X111903 #if defined(Q_WS_X11) 1743 1904 const uint pointSize = qRound(qt_pointSize(size->pixelSize, 0, -1)); 1905 #elif defined(Q_WS_PM) 1906 //@@TODO (dmik): some bitmap fonts (i.e. System VIO) have point sizes 1907 // that do not really correlate with their actual pixel sizes (i.e. 1908 // their pointsize != pixelsizde * DPI / 72), What to return in that case? 1909 const uint pointSize = size->pointSize / 10; 1744 1910 #else 1745 1911 const uint pointSize = size->pixelSize; // embedded uses 72dpi
Note:
See TracChangeset
for help on using the changeset viewer.