void FApplication::registerFonts() { registerFont(":/resources/fonts/DroidSans.ttf", true); registerFont(":/resources/fonts/DroidSans-Bold.ttf", false); registerFont(":/resources/fonts/DroidSansMono.ttf", false); //registerFont(":/resources/fonts/ocra10.ttf", true); registerFont(":/resources/fonts/OCRA.otf", true); /* QFontDatabase database; QStringList families = database.families ( ); foreach (QString string, families) { DebugDialog::debug(string); // should print out the name of the fonts you loaded } */ }
CFont* CFonts::registerTextureFont(const string &fontName){ CFont *found = findFont(fontName); if(found)return found; CTextureFont *f = new CTextureFont(fontName); f->makeFont(); registerFont(f); return f; }
CFont* CFonts::registerFont(const string &fontName){ CFont *found = findFont(fontName); if(found)return found; found = new CFont(fontName); found->makeFont(); registerFont(found); return found; }
CFont* CFonts::registerBitmapFont(const string &fontName, S32 size){ char name[1024]; //sprintf(name, "%s_%d", fontName.c_str(), size); //gcon.printString(name); CFont *found = findFont(fontName); if(found)return found; CBitmapFont *f = new CBitmapFont(fontName, size); // Bitmap fonts are automaked on usage... //f->makeFont(); f->setName(fontName); registerFont(f); return f; }
static void initializeDb() { QFontDatabasePrivate *db = privateDb(); // init by asking for the platformfontdb for the first time or after invalidation if (!db->count) QApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase(); if (db->reregisterAppFonts) { for (int i = 0; i < db->applicationFonts.count(); i++) { if (!db->applicationFonts.at(i).families.isEmpty()) registerFont(&db->applicationFonts[i]); } db->reregisterAppFonts = false; } }
QStringList QBasicUnixFontDatabase::addTTFile(const QByteArray &fontData, const QByteArray &file) { extern FT_Library qt_getFreetype(); FT_Library library = qt_getFreetype(); int index = 0; int numFaces = 0; QStringList families; do { FT_Face face; FT_Error error; if (!fontData.isEmpty()) { error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face); } else { error = FT_New_Face(library, file.constData(), index, &face); } if (error != FT_Err_Ok) { qDebug() << "FT_New_Face failed with index" << index << ":" << hex << error; break; } numFaces = face->num_faces; QFont::Weight weight = QFont::Normal; QFont::Style style = QFont::StyleNormal; if (face->style_flags & FT_STYLE_FLAG_ITALIC) style = QFont::StyleItalic; if (face->style_flags & FT_STYLE_FLAG_BOLD) weight = QFont::Bold; QSupportedWritingSystems writingSystems; // detect symbol fonts for (int i = 0; i < face->num_charmaps; ++i) { FT_CharMap cm = face->charmaps[i]; if (cm->encoding == ft_encoding_adobe_custom || cm->encoding == ft_encoding_symbol) { writingSystems.setSupported(QFontDatabase::Symbol); break; } } TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); if (os2) { quint32 unicodeRange[4] = { os2->ulUnicodeRange1, os2->ulUnicodeRange2, os2->ulUnicodeRange3, os2->ulUnicodeRange4 }; quint32 codePageRange[2] = { os2->ulCodePageRange1, os2->ulCodePageRange2 }; writingSystems = determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange); } QString family = QString::fromAscii(face->family_name); if(family.isEmpty()) family = QString::fromLocal8Bit(file); FontFile *fontFile = new FontFile; fontFile->fileName = file; fontFile->indexValue = index; QFont::Stretch stretch = QFont::Unstretched; registerFont(family,"",weight,style,stretch,true,true,0,writingSystems,fontFile); families.append(family); FT_Done_Face(face); ++index; } while (index < numFaces); return families; }
void QFontconfigDatabase::populateFontDatabase() { FcFontSet *fonts; QString familyName; FcChar8 *value = 0; int weight_value; int slant_value; int spacing_value; FcChar8 *file_value; int indexValue; FcChar8 *foundry_value; FcChar8 *style_value; FcBool scalable; FcBool antialias; { FcObjectSet *os = FcObjectSetCreate(); FcPattern *pattern = FcPatternCreate(); const char *properties [] = { FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT, FC_SPACING, FC_FILE, FC_INDEX, FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT, FC_WIDTH, #if FC_VERSION >= 20297 FC_CAPABILITY, #endif (const char *)0 }; const char **p = properties; while (*p) { FcObjectSetAdd(os, *p); ++p; } fonts = FcFontList(0, pattern, os); FcObjectSetDestroy(os); FcPatternDestroy(pattern); } for (int i = 0; i < fonts->nfont; i++) { if (FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, &value) != FcResultMatch) continue; // capitalize(value); familyName = QString::fromUtf8((const char *)value); slant_value = FC_SLANT_ROMAN; weight_value = FC_WEIGHT_REGULAR; spacing_value = FC_PROPORTIONAL; file_value = 0; indexValue = 0; scalable = FcTrue; if (FcPatternGetInteger (fonts->fonts[i], FC_SLANT, 0, &slant_value) != FcResultMatch) slant_value = FC_SLANT_ROMAN; if (FcPatternGetInteger (fonts->fonts[i], FC_WEIGHT, 0, &weight_value) != FcResultMatch) weight_value = FC_WEIGHT_REGULAR; if (FcPatternGetInteger (fonts->fonts[i], FC_SPACING, 0, &spacing_value) != FcResultMatch) spacing_value = FC_PROPORTIONAL; if (FcPatternGetString (fonts->fonts[i], FC_FILE, 0, &file_value) != FcResultMatch) file_value = 0; if (FcPatternGetInteger (fonts->fonts[i], FC_INDEX, 0, &indexValue) != FcResultMatch) indexValue = 0; if (FcPatternGetBool(fonts->fonts[i], FC_SCALABLE, 0, &scalable) != FcResultMatch) scalable = FcTrue; if (FcPatternGetString(fonts->fonts[i], FC_FOUNDRY, 0, &foundry_value) != FcResultMatch) foundry_value = 0; if (FcPatternGetString(fonts->fonts[i], FC_STYLE, 0, &style_value) != FcResultMatch) style_value = 0; if(FcPatternGetBool(fonts->fonts[i],FC_ANTIALIAS,0,&antialias) != FcResultMatch) antialias = true; QSupportedWritingSystems writingSystems; FcLangSet *langset = 0; FcResult res = FcPatternGetLangSet(fonts->fonts[i], FC_LANG, 0, &langset); if (res == FcResultMatch) { bool hasLang = false; for (int j = 1; j < QFontDatabase::WritingSystemsCount; ++j) { const FcChar8 *lang = (const FcChar8*) languageForWritingSystem[j]; if (lang) { FcLangResult langRes = FcLangSetHasLang(langset, lang); if (langRes != FcLangDifferentLang) { writingSystems.setSupported(QFontDatabase::WritingSystem(j)); hasLang = true; } } } if (!hasLang) // none of our known languages, add it to the other set writingSystems.setSupported(QFontDatabase::Other); } else { // we set Other to supported for symbol fonts. It makes no // sense to merge these with other ones, as they are // special in a way. writingSystems.setSupported(QFontDatabase::Other); } #if FC_VERSION >= 20297 for (int j = 1; j < QFontDatabase::WritingSystemsCount; ++j) { if (writingSystems.supported(QFontDatabase::WritingSystem(j)) && requiresOpenType(j) && openType[j]) { FcChar8 *cap; res = FcPatternGetString (fonts->fonts[i], FC_CAPABILITY, 0, &cap); if (res != FcResultMatch || !strstr((const char *)cap, openType[j])) writingSystems.setSupported(QFontDatabase::WritingSystem(j),false); } } #endif FontFile *fontFile = new FontFile; fontFile->fileName = QLatin1String((const char *)file_value); fontFile->indexValue = indexValue; QFont::Style style = (slant_value == FC_SLANT_ITALIC) ? QFont::StyleItalic : ((slant_value == FC_SLANT_OBLIQUE) ? QFont::StyleOblique : QFont::StyleNormal); QFont::Weight weight = QFont::Weight(getFCWeight(weight_value)); double pixel_size = 0; if (!scalable) { int width = 100; FcPatternGetInteger (fonts->fonts[i], FC_WIDTH, 0, &width); FcPatternGetDouble (fonts->fonts[i], FC_PIXEL_SIZE, 0, &pixel_size); } bool fixedPitch = spacing_value >= FC_MONO; QFont::Stretch stretch = QFont::Unstretched; QString styleName = style_value ? QString::fromUtf8((const char *) style_value) : QString(); QPlatformFontDatabase::registerFont(familyName,styleName,QLatin1String((const char *)foundry_value),weight,style,stretch,antialias,scalable,pixel_size,fixedPitch,writingSystems,fontFile); // qDebug() << familyName << (const char *)foundry_value << weight << style << &writingSystems << scalable << true << pixel_size; for (int k = 1; FcPatternGetString(fonts->fonts[i], FC_FAMILY, k, &value) == FcResultMatch; ++k) QPlatformFontDatabase::registerAliasToFontFamily(familyName, QString::fromUtf8((const char *)value)); } FcFontSetDestroy (fonts); struct FcDefaultFont { const char *qtname; const char *rawname; bool fixed; }; const FcDefaultFont defaults[] = { { "Serif", "serif", false }, { "Sans Serif", "sans-serif", false }, { "Monospace", "monospace", true }, { 0, 0, false } }; const FcDefaultFont *f = defaults; // aliases only make sense for 'common', not for any of the specials QSupportedWritingSystems ws; ws.setSupported(QFontDatabase::Latin); while (f->qtname) { QString familyQtName = QString::fromLatin1(f->qtname); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleNormal,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleItalic,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleOblique,QFont::Unstretched,true,true,0,f->fixed,ws,0); ++f; } //Lighthouse has very lazy population of the font db. We want it to be initialized when //QApplication is constructed, so that the population procedure can do something like this to //set the default font // const FcDefaultFont *s = defaults; // QFont font("Sans Serif"); // font.setPointSize(9); // QApplication::setFont(font); }
void QFontconfigDatabase::populateFontDatabase() { FcInitReinitialize(); FcFontSet *fonts; { FcObjectSet *os = FcObjectSetCreate(); FcPattern *pattern = FcPatternCreate(); const char *properties [] = { FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT, FC_SPACING, FC_FILE, FC_INDEX, FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WIDTH, #if FC_VERSION >= 20297 FC_CAPABILITY, #endif (const char *)0 }; const char **p = properties; while (*p) { FcObjectSetAdd(os, *p); ++p; } fonts = FcFontList(0, pattern, os); FcObjectSetDestroy(os); FcPatternDestroy(pattern); } for (int i = 0; i < fonts->nfont; i++) populateFromPattern(fonts->fonts[i]); FcFontSetDestroy (fonts); struct FcDefaultFont { const char *qtname; const char *rawname; bool fixed; }; const FcDefaultFont defaults[] = { { "Serif", "serif", false }, { "Sans Serif", "sans-serif", false }, { "Monospace", "monospace", true }, { 0, 0, false } }; const FcDefaultFont *f = defaults; // aliases only make sense for 'common', not for any of the specials QSupportedWritingSystems ws; ws.setSupported(QFontDatabase::Latin); while (f->qtname) { QString familyQtName = QString::fromLatin1(f->qtname); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleNormal,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleItalic,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleOblique,QFont::Unstretched,true,true,0,f->fixed,ws,0); ++f; } //Lighthouse has very lazy population of the font db. We want it to be initialized when //QApplication is constructed, so that the population procedure can do something like this to //set the default font // const FcDefaultFont *s = defaults; // QFont font("Sans Serif"); // font.setPointSize(9); // QApplication::setFont(font); }
QStringList QBasicFontDatabase::addMMFile(const QByteArray &fontData, const QByteArray &file) { //! [1] FT_Library library = qt_getFreetype(); int index = 0; int numFaces = 0; QStringList families; do { FT_Face face; FT_Error error; if (!fontData.isEmpty()) { error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face); } else { error = FT_New_Face(library, file.constData(), index, &face); } if (error != FT_Err_Ok) { qDebug() << "FT_New_Face failed with index:MMF:" << index << ":" << hex << error; break; } /* #ifndef NO_FREETYPE_ARPHIC_MMF ////////////////////////// index = 0; char aaa[6]; int len=fontData.length(); memcpy(aaa, (const char *)(fontData.length()+len-9), 5); aaa[5]=0; fontData = atoi((const char *)aaa); qDebug()<<"LOG_qfontconfigdatabase_Ln765:addAppliction font id:"<<fontData; ///////////////////////// #endif */ numFaces = face->num_faces; QFont::Weight weight = QFont::Normal; QFont::Style style = QFont::StyleNormal; if (face->style_flags & FT_STYLE_FLAG_ITALIC) style = QFont::StyleItalic; if (face->style_flags & FT_STYLE_FLAG_BOLD) weight = QFont::Bold; bool fixedPitch = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH); QSupportedWritingSystems writingSystems; for (int i = 0; i < face->num_charmaps; ++i) { FT_CharMap cm = face->charmaps[i]; if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM || cm->encoding == FT_ENCODING_MS_SYMBOL) { writingSystems.setSupported(QFontDatabase::Symbol); break; } } /* //! [1] //! [2] TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); if (os2) { quint32 unicodeRange[4] = { quint32(os2->ulUnicodeRange1), quint32(os2->ulUnicodeRange2), quint32(os2->ulUnicodeRange3), quint32(os2->ulUnicodeRange4) }; quint32 codePageRange[2] = { quint32(os2->ulCodePageRange1), quint32(os2->ulCodePageRange2) }; writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange); if (os2->usWeightClass == 0) ; else if (os2->usWeightClass < 350) weight = QFont::Light; else if (os2->usWeightClass < 450) weight = QFont::Normal; else if (os2->usWeightClass < 650) weight = QFont::DemiBold; else if (os2->usWeightClass < 750) weight = QFont::Bold; #ifndef NO_ARPHIC_MULTI_WEIGHT else if (os2->usWeightClass < 810) weight = QFont::ExtraBold; #endif else if (os2->usWeightClass < 1000) weight = QFont::Black; if (os2->panose[2] >= 2) { int w = os2->panose[2]; if (w <= 3) weight = QFont::Light; else if (w <= 5) weight = QFont::Normal; else if (w <= 7) weight = QFont::DemiBold; else if (w <= 8) weight = QFont::Bold; #ifndef NO_ARPHIC_MULTI_WEIGHT else if (w <= 9) weight = QFont::ExtraBold; #endif else if (w <= 10) weight = QFont::Black; } } #ifndef NO_ARPHIC_MULTI_WEIGHT if (os2->usWeightClass == 0) ; else if (os2->usWeightClass < 350) weight = QFont::Light; else if (os2->usWeightClass < 450) weight = QFont::Normal; else if (os2->usWeightClass < 650) weight = QFont::DemiBold; else if (os2->usWeightClass < 750) weight = QFont::Bold; else if (os2->usWeightClass < 810) weight = QFont::ExtraBold; else if (os2->usWeightClass < 1000) weight = QFont::Black; #endif //! [2] */ //! [3] QString family = QString::fromLatin1(face->family_name); FontFile *fontFile = new FontFile; fontFile->fileName = QFile::decodeName(file); fontFile->indexValue = index; QFont::Stretch stretch = QFont::Unstretched; registerFont(family,QString::fromLatin1(face->style_name),QString(),weight,style,stretch,true,true,0,fixedPitch,writingSystems,fontFile); families.append(family); FT_Done_Face(face); ++index; } while (index < numFaces); return families; //! [3] }
QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByteArray &file) { FT_Library library = qt_getFreetype(); int index = 0; int numFaces = 0; QStringList families; do { FT_Face face; FT_Error error; if (!fontData.isEmpty()) { error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face); } else { error = FT_New_Face(library, file.constData(), index, &face); } if (error != FT_Err_Ok) { qDebug() << "FT_New_Face failed with index" << index << ':' << hex << error; break; } numFaces = face->num_faces; QFont::Weight weight = QFont::Normal; QFont::Style style = QFont::StyleNormal; if (face->style_flags & FT_STYLE_FLAG_ITALIC) style = QFont::StyleItalic; if (face->style_flags & FT_STYLE_FLAG_BOLD) weight = QFont::Bold; bool fixedPitch = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH); QSupportedWritingSystems writingSystems; // detect symbol fonts for (int i = 0; i < face->num_charmaps; ++i) { FT_CharMap cm = face->charmaps[i]; if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM || cm->encoding == FT_ENCODING_MS_SYMBOL) { writingSystems.setSupported(QFontDatabase::Symbol); break; } } TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); if (os2) { quint32 unicodeRange[4] = { quint32(os2->ulUnicodeRange1), quint32(os2->ulUnicodeRange2), quint32(os2->ulUnicodeRange3), quint32(os2->ulUnicodeRange4) }; quint32 codePageRange[2] = { quint32(os2->ulCodePageRange1), quint32(os2->ulCodePageRange2) }; writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange); if (os2->usWeightClass) { weight = QPlatformFontDatabase::weightFromInteger(os2->usWeightClass); } else if (os2->panose[2]) { int w = os2->panose[2]; if (w <= 1) weight = QFont::Thin; else if (w <= 2) weight = QFont::ExtraLight; else if (w <= 3) weight = QFont::Light; else if (w <= 5) weight = QFont::Normal; else if (w <= 6) weight = QFont::Medium; else if (w <= 7) weight = QFont::DemiBold; else if (w <= 8) weight = QFont::Bold; else if (w <= 9) weight = QFont::ExtraBold; else if (w <= 10) weight = QFont::Black; } } QString family = QString::fromLatin1(face->family_name); FontFile *fontFile = new FontFile; fontFile->fileName = QFile::decodeName(file); fontFile->indexValue = index; QFont::Stretch stretch = QFont::Unstretched; registerFont(family,QString::fromLatin1(face->style_name),QString(),weight,style,stretch,true,true,0,fixedPitch,writingSystems,fontFile); families.append(family); FT_Done_Face(face); ++index; } while (index < numFaces); return families; }
QStringList QWebOSFontDatabase::addTTFile(QWebOSFontDatabase* qwfdb, const QByteArray &fontData, const QByteArray &file, const QStringList &additionalFamilies) { if (qwfdb && qwfdb->m_debug) qDebug("addTTFile(fontData.size() = %d, file = '%s', additionalFamilies = '%s')", fontData.size(), qPrintable(file), qPrintable(additionalFamilies.join(","))); extern FT_Library qt_getFreetype(); FT_Library library = qt_getFreetype(); int numFaces = 0; int index = 0; QStringList families; FT_Face face; FT_Error error; if (!fontData.isEmpty()) { error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face); } else { error = FT_New_Face(library, file.constData(), index, &face); } if (error != FT_Err_Ok) { qDebug() << "FT_New_Face for " << qPrintable(file) << " failed with index" << index << ":" << hex << error; return families; } numFaces = face->num_faces; if (numFaces > 1) { qWarning() << "numFaces for " << qPrintable(file) << " is " << numFaces << ", expected just 1"; } QFont::Weight weight = QFont::Normal; QFont::Stretch stretch = QFont::Unstretched; QFont::Style style = QFont::StyleNormal; if (face->style_flags & FT_STYLE_FLAG_ITALIC) style = QFont::StyleItalic; if (face->style_flags & FT_STYLE_FLAG_BOLD) weight = QFont::Bold; QSupportedWritingSystems writingSystems; // detect symbol fonts for (int i = 0; i < face->num_charmaps; ++i) { FT_CharMap cm = face->charmaps[i]; if (cm->encoding == ft_encoding_adobe_custom || cm->encoding == ft_encoding_symbol) { writingSystems.setSupported(QFontDatabase::Symbol); break; } } TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); if (os2) { quint32 unicodeRange[4] = { os2->ulUnicodeRange1, os2->ulUnicodeRange2, os2->ulUnicodeRange3, os2->ulUnicodeRange4 }; quint32 codePageRange[2] = { os2->ulCodePageRange1, os2->ulCodePageRange2 }; writingSystems = determineWritingSystemsFromTrueTypeBits(unicodeRange, codePageRange); // If the OS2 struct is availabel read the weight from there and convert it // to a QFont::Weight. This fixes OWEBOS-1866 weight = weightFromInteger(os2->usWeightClass); stretch = determineStretchFromTrueTypeWidthClass(os2->usWidthClass); style = determineStyleFromTrueTypeSelection(os2->fsSelection); } QString family = QString::fromAscii(face->family_name); QStringList allFamilies(family); allFamilies << additionalFamilies; for (int i = 0; i < allFamilies.size(); ++i) { FontFile *fontFile = new FontFile; fontFile->fileName = file; fontFile->indexValue = index; fontFile->familyName = allFamilies.at(i); qDebug("registerFont(\"%s\",\"\",%s,%s,%s,true,true,0,\"%s\",fontFile = {fileName = \"%s\", indexValue = %d, familyName = %s})", qPrintable(allFamilies.at(i)), qPrintable(qWeightToQString(weight)), qPrintable(qStyleToQString(style)), qPrintable(qStretchToQString(stretch)), qPrintable(qSupportedWritingSystemsToQString(writingSystems)), qPrintable(fontFile->fileName), fontFile->indexValue, qPrintable(fontFile->familyName)); registerFont(allFamilies.at(i), "", weight, style, stretch, true, true, 0, writingSystems, fontFile); families.append(family); } FT_Done_Face(face); return families; }