inline void LoadDBC(uint32& availableDbcLocales, StoreProblemList& errors, DBCStorage<T>& storage, std::string const& dbcPath, std::string const& filename, std::string const* customFormat = NULL, std::string const* customIndexName = NULL) { // compatibility format and C++ structure sizes ASSERT(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T), "Size of '%s' set by format string (%u) not equal size of C++ structure (%u).", filename.c_str(), DBCFileLoader::GetFormatRecordSize(storage.GetFormat()), uint32(sizeof(T))); ++DBCFileCount; std::string dbcFilename = dbcPath + filename; SqlDbc * sql = NULL; if (customFormat) sql = new SqlDbc(&filename, customFormat, customIndexName, storage.GetFormat()); if (storage.Load(dbcFilename.c_str(), sql)) { for (uint8 i = 0; i < TOTAL_LOCALES; ++i) { if (!(availableDbcLocales & (1 << i))) continue; std::string localizedName(dbcPath); localizedName.append(localeNames[i]); localizedName.push_back('/'); localizedName.append(filename); if (!storage.LoadStringsFrom(localizedName.c_str())) availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks } } else { // sort problematic dbc to (1) non compatible and (2) non-existed if (FILE* f = fopen(dbcFilename.c_str(), "rb")) { std::ostringstream stream; stream << dbcFilename << " exists, and has " << storage.GetFieldCount() << " field(s) (expected " << strlen(storage.GetFormat()) << "). Extracted file might be from wrong client version or a database-update has been forgotten."; std::string buf = stream.str(); errors.push_back(buf); fclose(f); } else errors.push_back(dbcFilename); } delete sql; }
inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, DB2Storage<T>& storage, std::string const& db2_path, std::string const& filename) { // compatibility format and C++ structure sizes if (!(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDB2_assert_print(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename))) return; ++DB2FilesCount; std::string db2_filename = db2_path + filename; if (storage.Load(db2_filename.c_str(), uint32(sWorld->GetDefaultDbcLocale()))) { for (uint32 i = 0; i < TOTAL_LOCALES; ++i) { if (!(availableDb2Locales & (1 << i))) continue; if (uint32(sWorld->GetDefaultDbcLocale()) == i) continue; std::string localizedName(db2_path); localizedName.append(localeNames[i]); localizedName.push_back('/'); localizedName.append(filename); if (!storage.LoadStringsFrom(localizedName.c_str(), i)) availableDb2Locales &= ~(1<<i); // mark as not available for speedup next checks } } else { // sort problematic db2 to (1) non compatible and (2) nonexistent if (FILE* f = fopen(db2_filename.c_str(), "rb")) { char buf[100]; snprintf(buf, 100,"(exist, but have %d fields instead " SIZEFMTD ") Wrong client version DBC file?", storage.GetFieldCount(), strlen(storage.GetFormat())); errlist.push_back(db2_filename + buf); fclose(f); } else errlist.push_back(db2_filename); } DB2Stores[storage.GetHash()] = &storage; }
inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, DB2Storage<T>& storage, std::string const& db2_path, std::string const& filename) { // compatibility format and C++ structure sizes ASSERT(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDB2_assert_print(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename)); ++DB2FilesCount; std::string db2_filename = db2_path + filename; if (storage.Load(db2_filename.c_str(), uint32(sWorld->GetDefaultDbcLocale()))) { for (uint32 i = 0; i < TOTAL_LOCALES; ++i) { if (!(availableDb2Locales & (1 << i))) continue; if (uint32(sWorld->GetDefaultDbcLocale()) == i) continue; std::string localizedName(db2_path); localizedName.append(localeNames[i]); localizedName.push_back('/'); localizedName.append(filename); if (!storage.LoadStringsFrom(localizedName.c_str(), i)) availableDb2Locales &= ~(1<<i); // mark as not available for speedup next checks } } else { // sort problematic db2 to (1) non compatible and (2) nonexistent if (FILE* f = fopen(db2_filename.c_str(), "rb")) { std::ostringstream stream; stream << db2_filename << " exists, and has " << storage.GetFieldCount() << " field(s) (expected " << strlen(storage.GetFormat()) << "). Extracted file might be from wrong client version or a database-update has been forgotten."; std::string buf = stream.str(); errlist.push_back(buf); fclose(f); } else errlist.push_back(db2_filename); } DB2Stores[storage.GetHash()] = &storage; }
inline void LoadDBC(uint32& availableDbcLocales, StoreProblemList& errors, DBCStorage<T>& storage, std::string const& dbcPath, std::string const& filename, char const* dbTable = nullptr, char const* dbFormat = nullptr, char const* dbIndexName = nullptr) { // compatibility format and C++ structure sizes ASSERT(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename)); ++DBCFileCount; std::string dbcFilename = dbcPath + filename; if (storage.Load(dbcFilename.c_str())) { for (uint8 i = 0; i < TOTAL_LOCALES; ++i) { if (!(availableDbcLocales & (1 << i))) continue; std::string localizedName(dbcPath); localizedName.append(localeNames[i]); localizedName.push_back('/'); localizedName.append(filename); if (!storage.LoadStringsFrom(localizedName.c_str())) availableDbcLocales &= ~(1 << i); // mark as not available for speedup next checks } if (dbTable) storage.LoadFromDB(dbTable, dbFormat, dbIndexName); } else { // sort problematic dbc to (1) non compatible and (2) non-existed if (FILE* f = fopen(dbcFilename.c_str(), "rb")) { std::ostringstream stream; stream << dbcFilename << " exists, and has " << storage.GetFieldCount() << " field(s) (expected " << strlen(storage.GetFormat()) << "). Extracted file might be from wrong client version or a database-update has been forgotten. Search on forum for TCE00008 for more info."; std::string buf = stream.str(); errors.push_back(buf); fclose(f); } else errors.push_back(dbcFilename); } }
inline void LoadDBC(uint32& availableDbcLocales, StoreProblemList& errors, DBCStorage<T>& storage, std::string const& dbcPath, std::string const& filename, std::string const* customFormat = NULL, std::string const* customIndexName = NULL) { // compatibility format and C++ structure sizes ASSERT(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename)); ++DBCFileCount; std::string dbcFilename = dbcPath + filename; SqlDbc * sql = NULL; if (customFormat) sql = new SqlDbc(&filename, customFormat, customIndexName, storage.GetFormat()); if (storage.Load(dbcFilename.c_str(), sql)) { for (uint8 i = 0; i < TOTAL_LOCALES; ++i) { if (!(availableDbcLocales & (1 << i))) continue; std::string localizedName(dbcPath); localizedName.append(localeNames[i]); localizedName.push_back('/'); localizedName.append(filename); if (!storage.LoadStringsFrom(localizedName.c_str())) availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks } } else { // sort problematic dbc to (1) non compatible and (2) non-existed if (FILE* f = fopen(dbcFilename.c_str(), "rb")) { char buf[100]; snprintf(buf, 100, " (exists, but has %u fields instead of " SIZEFMTD ") Possible wrong client version.", storage.GetFieldCount(), strlen(storage.GetFormat())); errors.push_back(dbcFilename + buf); fclose(f); } else errors.push_back(dbcFilename); } delete sql; }
static void addFontToDatabase(QString familyName, const QString &scriptName, TEXTMETRIC *textmetric, const FONTSIGNATURE *signature, int type) { const int script = -1; const QString foundryName; Q_UNUSED(script); bool italic = false; int weight; bool fixed; bool ttf; bool scalable; int size; // QString escript = QString::fromWCharArray(f->elfScript); // qDebug("script=%s", escript.latin1()); NEWTEXTMETRIC *tm = (NEWTEXTMETRIC *)textmetric; fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH); ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE); scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE); size = scalable ? SMOOTH_SCALABLE : tm->tmHeight; italic = tm->tmItalic; weight = tm->tmWeight; // the "@family" fonts are just the same as "family". Ignore them. if (familyName[0] != QLatin1Char('@') && !familyName.startsWith(QLatin1String("WST_"))) { QtFontStyle::Key styleKey; styleKey.style = italic ? QFont::StyleItalic : QFont::StyleNormal; styleKey.weight = weightFromInteger(weight); QtFontFamily *family = privateDb()->family(familyName, true); if(ttf && localizedName(familyName) && family->english_name.isEmpty()) family->english_name = getEnglishName(familyName); QtFontFoundry *foundry = family->foundry(foundryName, true); QtFontStyle *style = foundry->style(styleKey, QString(), true); style->smoothScalable = scalable; style->pixelSize( size, TRUE); // add fonts windows can generate for us: if (styleKey.weight <= QFont::DemiBold) { QtFontStyle::Key key(styleKey); key.weight = QFont::Bold; QtFontStyle *style = foundry->style(key, QString(), true); style->smoothScalable = scalable; style->pixelSize( size, TRUE); } if (styleKey.style != QFont::StyleItalic) { QtFontStyle::Key key(styleKey); key.style = QFont::StyleItalic; QtFontStyle *style = foundry->style(key, QString(), true); style->smoothScalable = scalable; style->pixelSize( size, TRUE); } if (styleKey.weight <= QFont::DemiBold && styleKey.style != QFont::StyleItalic) { QtFontStyle::Key key(styleKey); key.weight = QFont::Bold; key.style = QFont::StyleItalic; QtFontStyle *style = foundry->style(key, QString(), true); style->smoothScalable = scalable; style->pixelSize( size, TRUE); } family->fixedPitch = fixed; if (!family->writingSystemCheck && type & TRUETYPE_FONTTYPE) { quint32 unicodeRange[4] = { signature->fsUsb[0], signature->fsUsb[1], signature->fsUsb[2], signature->fsUsb[3] }; #ifdef Q_WS_WINCE if (signature->fsUsb[0] == 0) { // If the unicode ranges bit mask is zero then // EnumFontFamiliesEx failed to determine it properly. // In this case we just pretend that the font supports all languages. unicodeRange[0] = 0xbfffffff; // second most significant bit must be zero unicodeRange[1] = 0xffffffff; unicodeRange[2] = 0xffffffff; unicodeRange[3] = 0xffffffff; } #endif quint32 codePageRange[2] = { signature->fsCsb[0], signature->fsCsb[1] }; QList<QFontDatabase::WritingSystem> systems = qt_determine_writing_systems_from_truetype_bits(unicodeRange, codePageRange); for (int i = 0; i < systems.count(); ++i) { QFontDatabase::WritingSystem writingSystem = systems.at(i); // ### Hack to work around problem with Thai text on Windows 7. Segoe UI contains // the symbol for Baht, and Windows thus reports that it supports the Thai script. // Since it's the default UI font on this platform, most widgets will be unable to // display Thai text by default. As a temporary work around, we special case Segoe UI // and remove the Thai script from its list of supported writing systems. if (writingSystem != QFontDatabase::Thai || familyName != QLatin1String("Segoe UI")) family->writingSystems[writingSystem] = QtFontFamily::Supported; } } else if (!family->writingSystemCheck) { //qDebug("family='%s' script=%s", family->name.latin1(), script.latin1()); if (scriptName == QLatin1String("Western") || scriptName == QLatin1String("Baltic") || scriptName == QLatin1String("Central European") || scriptName == QLatin1String("Turkish") || scriptName == QLatin1String("Vietnamese")) family->writingSystems[QFontDatabase::Latin] = QtFontFamily::Supported; else if (scriptName == QLatin1String("Thai")) family->writingSystems[QFontDatabase::Thai] = QtFontFamily::Supported; else if (scriptName == QLatin1String("Symbol") || scriptName == QLatin1String("Other")) family->writingSystems[QFontDatabase::Symbol] = QtFontFamily::Supported; else if (scriptName == QLatin1String("OEM/Dos")) family->writingSystems[QFontDatabase::Latin] = QtFontFamily::Supported; else if (scriptName == QLatin1String("CHINESE_GB2312")) family->writingSystems[QFontDatabase::SimplifiedChinese] = QtFontFamily::Supported; else if (scriptName == QLatin1String("CHINESE_BIG5")) family->writingSystems[QFontDatabase::TraditionalChinese] = QtFontFamily::Supported; else if (scriptName == QLatin1String("Cyrillic")) family->writingSystems[QFontDatabase::Cyrillic] = QtFontFamily::Supported; else if (scriptName == QLatin1String("Hangul")) family->writingSystems[QFontDatabase::Korean] = QtFontFamily::Supported; else if (scriptName == QLatin1String("Hebrew")) family->writingSystems[QFontDatabase::Hebrew] = QtFontFamily::Supported; else if (scriptName == QLatin1String("Greek")) family->writingSystems[QFontDatabase::Greek] = QtFontFamily::Supported; else if (scriptName == QLatin1String("Japanese")) family->writingSystems[QFontDatabase::Japanese] = QtFontFamily::Supported; else if (scriptName == QLatin1String("Arabic")) family->writingSystems[QFontDatabase::Arabic] = QtFontFamily::Supported; } } }
static bool addFontToDatabase(QString familyName, const QString &scriptName, const TEXTMETRIC *textmetric, const FONTSIGNATURE *signature, int type) { typedef QPair<QString, QStringList> FontKey; // the "@family" fonts are just the same as "family". Ignore them. if (familyName.at(0) == QLatin1Char('@') || familyName.startsWith(QStringLiteral("WST_"))) return false; const int separatorPos = familyName.indexOf(QStringLiteral("::")); const QString faceName = separatorPos != -1 ? familyName.left(separatorPos) : familyName; const QString fullName = separatorPos != -1 ? familyName.mid(separatorPos + 2) : QString(); static const int SMOOTH_SCALABLE = 0xffff; const QString foundryName; // No such concept. const NEWTEXTMETRIC *tm = (NEWTEXTMETRIC *)textmetric; const bool fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH); const bool ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE); const bool scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE); const int size = scalable ? SMOOTH_SCALABLE : tm->tmHeight; const QFont::Style style = tm->tmItalic ? QFont::StyleItalic : QFont::StyleNormal; const bool antialias = false; const QFont::Weight weight = weightFromInteger(tm->tmWeight); const QFont::Stretch stretch = QFont::Unstretched; #ifndef QT_NO_DEBUG_OUTPUT if (QWindowsContext::verboseFonts > 2) { QDebug nospace = qDebug().nospace(); nospace << __FUNCTION__ << faceName << fullName << scriptName << "TTF=" << ttf; if (type & DEVICE_FONTTYPE) nospace << " DEVICE"; if (type & RASTER_FONTTYPE) nospace << " RASTER"; if (type & TRUETYPE_FONTTYPE) nospace << " TRUETYPE"; nospace << " scalable=" << scalable << " Size=" << size << " Style=" << style << " Weight=" << weight << " stretch=" << stretch; } #endif QString englishName; if (ttf && localizedName(faceName)) englishName = getEnglishName(faceName); QSupportedWritingSystems writingSystems; if (type & TRUETYPE_FONTTYPE) { quint32 unicodeRange[4] = { signature->fsUsb[0], signature->fsUsb[1], signature->fsUsb[2], signature->fsUsb[3] }; quint32 codePageRange[2] = { signature->fsCsb[0], signature->fsCsb[1] }; writingSystems = QBasicFontDatabase::determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange); // ### Hack to work around problem with Thai text on Windows 7. Segoe UI contains // the symbol for Baht, and Windows thus reports that it supports the Thai script. // Since it's the default UI font on this platform, most widgets will be unable to // display Thai text by default. As a temporary work around, we special case Segoe UI // and remove the Thai script from its list of supported writing systems. if (writingSystems.supported(QFontDatabase::Thai) && faceName == QStringLiteral("Segoe UI")) writingSystems.setSupported(QFontDatabase::Thai, false); } else { const QFontDatabase::WritingSystem ws = writingSystemFromScript(scriptName); if (ws != QFontDatabase::Any) writingSystems.setSupported(ws); } #ifndef Q_OS_WINCE const QSettings fontRegistry(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"), QSettings::NativeFormat); static QVector<FontKey> allFonts; if (allFonts.isEmpty()) { const QStringList allKeys = fontRegistry.allKeys(); allFonts.reserve(allKeys.size()); const QString trueType = QStringLiteral("(TrueType)"); const QRegExp sizeListMatch(QStringLiteral("\\s(\\d+,)+\\d+")); foreach (const QString &key, allKeys) { QString realKey = key; realKey.remove(trueType); realKey.remove(sizeListMatch); QStringList fonts; const QStringList fontNames = realKey.trimmed().split(QLatin1Char('&')); foreach (const QString &fontName, fontNames) fonts.push_back(fontName.trimmed()); allFonts.push_back(FontKey(key, fonts)); } }