Changeset 220 for trunk/src/gui/text/qfontdatabase_pm.cpp
- Timestamp:
- Oct 12, 2009, 11:37:39 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/text/qfontdatabase_pm.cpp
r125 r220 48 48 QT_BEGIN_NAMESPACE 49 49 50 static void populateDatabase(const QString& fam) 51 { 52 QFontDatabasePrivate *db = privateDb(); 53 if (!db) 54 return; 55 56 QtFontFamily *family = 0; 57 if(!fam.isEmpty()) { 58 family = db->family(fam); 59 if(family) 60 return; 61 } else if (db->count) { 62 return; 63 } 64 65 // we don't recognize foundries on OS/2, use an empty one 66 const QString foundryName; 67 68 int hps = qt_display_ps(); 69 70 LONG cFonts = 0; 71 cFonts = GpiQueryFonts(hps, QF_PUBLIC, NULL, &cFonts, 0, NULL); 72 PFONTMETRICS afm = new FONTMETRICS[cFonts]; 73 GpiQueryFonts(hps, QF_PUBLIC, NULL, &cFonts, sizeof(FONTMETRICS), afm); 74 75 LONG info[2]; 76 DevQueryCaps(GpiQueryDevice(hps), CAPS_HORIZONTAL_FONT_RES, 2, info); 77 LONG xRes = info[0], yRes = info[1]; 78 79 for (PFONTMETRICS fm = afm ; cFonts ; cFonts--, fm++) { 80 // ignore the default (lMatch = 0) GPI font, since it is always 81 // present with non-zero lMatch in the list 82 if (!fm->lMatch) 83 continue; 84 85 QString familyName = QString::fromLocal8Bit(fm->szFamilyname); 86 bool italic = fm->fsSelection & FM_SEL_ITALIC; 87 bool fixed = fm->fsType & FM_TYPE_FIXED; 88 bool scalable = fm->fsDefn & FM_DEFN_OUTLINE; 89 USHORT weight = fm->usWeightClass; 90 USHORT width = fm->usWidthClass; 91 92 // ignore bitmap fonts that do not match the current device resolution 93 if (!scalable && (fm->sXDeviceRes != xRes || fm->sYDeviceRes != yRes)) 94 continue; 95 96 // the "@family" fonts are just the same as "family". Ignore them. 97 if (familyName[0] == '@') 98 continue; 99 100 QtFontStyle::Key styleKey; 101 styleKey.style = italic ? QFont::StyleItalic : QFont::StyleNormal; 102 103 if (weight < 4) 104 styleKey.weight = QFont::Light; 105 else if (weight < 6) 106 styleKey.weight = QFont::Normal; 107 else if (weight < 7) 108 styleKey.weight = QFont::DemiBold; 109 else if (weight < 8) 110 styleKey.weight = QFont::Bold; 111 else 112 styleKey.weight = QFont::Black; 113 114 switch (width) { 115 case 1: styleKey.stretch = QFont::UltraCondensed; break; 116 case 2: styleKey.stretch = QFont::ExtraCondensed; break; 117 case 3: styleKey.stretch = QFont::Condensed; break; 118 case 4: styleKey.stretch = QFont::SemiCondensed; break; 119 case 5: styleKey.stretch = QFont::Unstretched; break; 120 case 6: styleKey.stretch = QFont::SemiExpanded; break; 121 case 7: styleKey.stretch = QFont::Expanded; break; 122 case 8: styleKey.stretch = QFont::ExtraExpanded; break; 123 case 9: styleKey.stretch = QFont::UltraExpanded; break; 124 default: styleKey.stretch = QFont::Unstretched; break; 125 } 126 127 // @todo why? 128 familyName.replace('-', ' '); 129 130 QtFontFamily *family = privateDb()->family(familyName, true); 131 // @todo is it possible that the same family is both fixed and not? 132 family->fixedPitch = fixed; 133 134 QtFontFoundry *foundry = family->foundry(foundryName, true); 135 QtFontStyle *style = foundry->style(styleKey, true); 136 137 // add new scalable style only if it hasn't been already added -- 138 // the first one of two duplicate (in Qt terms) non-bitmap font 139 // styles wins. 140 if (scalable && style->smoothScalable) 141 continue; 142 143 if (style->faceName[0]) { 144 // if a duplicate (having the same style in Qt terms) bitmap 145 // font is encountered but it has the different facename, ignore 146 // it (we have only one facename field per style -- it should be 147 // the same for all sizes otherwise we will not be able to create 148 // a font with some sizes later). 149 if (strcmp(style->faceName, fm->szFacename)) 150 continue; 151 } else { 152 strcpy(style->faceName, fm->szFacename); 153 } 154 155 if (scalable) { 156 style->smoothScalable = TRUE; 157 QtFontSize *size = 158 style->pixelSize(SMOOTH_SCALABLE, TRUE, fm->sNominalPointSize); 159 size->lMatch = fm->lMatch; 160 } else { 161 QtFontSize *size = 162 style->pixelSize(fm->lEmHeight, TRUE, fm->sNominalPointSize); 163 // the first bitmap style with a given pixel and point size wins 164 if (size->lMatch) 165 continue; 166 size->lMatch = fm->lMatch; 167 } 168 } 169 170 delete[] afm; 171 } 172 50 173 static void initializeDb() 51 174 { 175 QFontDatabasePrivate *db = privateDb(); 176 if (!db || db->count) 177 return; 178 179 populateDatabase(QString()); 180 181 #ifdef QFONTDATABASE_DEBUG 182 // print the database 183 for (int f = 0; f < db->count; f++) { 184 QtFontFamily *family = db->families[f]; 185 qDebug(" %s: %p", qPrintable(family->name), family); 186 populateDatabase(family->name); 187 188 #if 1 189 qDebug(" scripts supported:"); 190 for (int i = 0; i < QUnicodeTables::ScriptCount; i++) 191 if(family->writingSystems[i] & QtFontFamily::Supported) 192 qDebug(" %d", i); 193 for (int fd = 0; fd < family->count; fd++) { 194 QtFontFoundry *foundry = family->foundries[fd]; 195 qDebug(" %s", qPrintable(foundry->name)); 196 for (int s = 0; s < foundry->count; s++) { 197 QtFontStyle *style = foundry->styles[s]; 198 qDebug(" style: style=%d weight=%d smooth=%d", style->key.style, 199 style->key.weight, style->smoothScalable); 200 if(!style->smoothScalable) { 201 for(int i = 0; i < style->count; ++i) { 202 qDebug(" %d", style->pixelSizes[i].pixelSize); 203 } 204 } 205 } 206 } 207 #endif 208 } 209 #endif // QFONTDATABASE_DEBUG 210 } 211 212 static inline void load(const QString &family = QString(), int = -1) 213 { 214 populateDatabase(family); 215 } 216 217 static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) 218 { 52 219 // @todo implement 53 220 } 54 221 55 static inline void load(const QString &family = QString(), int = -1) 56 { 57 // @todo implement 58 } 59 60 static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) 61 { 62 // @todo implement 222 static QFontEngine *loadPM(const QFontPrivate *d, int script, const QFontDef &req) 223 { 224 // @todo initializeDb() and stuff, get the engine 225 QFontDef fd = req; 226 QFontEngine *fe = new QFontEnginePMFT(fd); 227 return fe; 63 228 } 64 229 … … 95 260 fe->fontDef = req; 96 261 } else { 97 // @todo initializeDb() and stuff, get the engine 98 QFontDef fd = req; 99 fe = new QFontEnginePMFT(fd); 262 QMutexLocker locker(fontDatabaseMutex()); 263 if (!privateDb()->count) 264 initializeDb(); 265 fe = loadPM(d, script, req); 100 266 } 101 267 if (!fe) {
Note:
See TracChangeset
for help on using the changeset viewer.