44 #include <QtCore/QList> 45 #include <QtGui/private/qfont_p.h> 47 #include <QtCore/QElapsedTimer> 49 #include <QtGui/private/qapplication_p.h> 50 #include <QtGui/QPlatformScreen> 52 #include <QtGui/private/qfontengine_ft_p.h> 53 #include <QtGui/private/qfontengine_p.h> 58 #include FT_TRUETYPE_TABLES_H 60 #include <fontconfig/fontconfig.h> 62 #define SimplifiedChineseCsbBit 18 63 #define TraditionalChineseCsbBit 20 64 #define JapaneseCsbBit 17 65 #define KoreanCsbBit 21 81 if (fc_weight <= (FC_WEIGHT_LIGHT + FC_WEIGHT_MEDIUM) / 2)
83 else if (fc_weight <= (FC_WEIGHT_MEDIUM + FC_WEIGHT_DEMIBOLD) / 2)
85 else if (fc_weight <= (FC_WEIGHT_DEMIBOLD + FC_WEIGHT_BOLD) / 2)
87 else if (fc_weight <= (FC_WEIGHT_BOLD + FC_WEIGHT_BLACK) / 2)
279 const char *stylehint = 0;
282 stylehint =
"sans-serif";
288 stylehint =
"monospace";
307 FcChar8 *foundry_value;
312 FcObjectSet *os = FcObjectSetCreate();
313 FcPattern *pattern = FcPatternCreate();
315 FC_FAMILY, FC_WEIGHT, FC_SLANT,
316 FC_SPACING, FC_FILE, FC_INDEX,
317 FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE,
319 #if FC_VERSION >= 20297 326 FcObjectSetAdd(os, *p);
329 fonts = FcFontList(0, pattern, os);
330 FcObjectSetDestroy(os);
331 FcPatternDestroy(pattern);
334 for (
int i = 0; i < fonts->nfont; i++) {
335 if (FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, &value) != FcResultMatch)
339 slant_value = FC_SLANT_ROMAN;
340 weight_value = FC_WEIGHT_MEDIUM;
341 spacing_value = FC_PROPORTIONAL;
347 if (FcPatternGetInteger (fonts->fonts[i], FC_SLANT, 0, &slant_value) != FcResultMatch)
348 slant_value = FC_SLANT_ROMAN;
349 if (FcPatternGetInteger (fonts->fonts[i], FC_WEIGHT, 0, &weight_value) != FcResultMatch)
350 weight_value = FC_WEIGHT_MEDIUM;
351 if (FcPatternGetInteger (fonts->fonts[i], FC_SPACING, 0, &spacing_value) != FcResultMatch)
352 spacing_value = FC_PROPORTIONAL;
353 if (FcPatternGetString (fonts->fonts[i], FC_FILE, 0, &file_value) != FcResultMatch)
355 if (FcPatternGetInteger (fonts->fonts[i], FC_INDEX, 0, &indexValue) != FcResultMatch)
357 if (FcPatternGetBool(fonts->fonts[i], FC_SCALABLE, 0, &scalable) != FcResultMatch)
359 if (FcPatternGetString(fonts->fonts[i], FC_FOUNDRY, 0, &foundry_value) != FcResultMatch)
361 if(FcPatternGetBool(fonts->fonts[i],FC_ANTIALIAS,0,&antialias) != FcResultMatch)
365 FcLangSet *langset = 0;
366 FcResult res = FcPatternGetLangSet(fonts->fonts[i], FC_LANG, 0, &langset);
367 if (res == FcResultMatch) {
371 FcLangResult langRes = FcLangSetHasLang(langset, lang);
372 if (langRes != FcLangDifferentLang)
384 res = FcPatternGetCharSet(fonts->fonts[i], FC_CHARSET, 0, &cs);
385 if (res == FcResultMatch) {
396 #if FC_VERSION >= 20297 401 res = FcPatternGetString (fonts->fonts[i], FC_CAPABILITY, 0, &cap);
402 if (res != FcResultMatch || !strstr((
const char *)cap,
openType[j]))
414 : ((slant_value == FC_SLANT_OBLIQUE)
419 double pixel_size = 0;
421 FcPatternGetDouble (fonts->fonts[i], FC_PIXEL_SIZE, 0, &pixel_size);
423 int width = FC_WIDTH_NORMAL;
424 FcPatternGetInteger(fonts->fonts[i],
FC_WIDTH, 0, &width);
444 FcFontSetDestroy (fonts);
446 struct FcDefaultFont {
451 const FcDefaultFont defaults[] = {
452 {
"Serif",
"serif",
false },
453 {
"Sans Serif",
"sans-serif",
false },
454 {
"Monospace",
"monospace",
true },
457 const FcDefaultFont *f = defaults;
492 FcPattern *pattern = FcPatternCreate();
500 value.type = FcTypeString;
502 value.u.s = (
const FcChar8 *)cs.
data();
503 FcPatternAdd(pattern,FC_FAMILY,value,
true);
507 FcPatternAdd(pattern,FC_FILE,value,
true);
509 value.type = FcTypeInteger;
510 value.u.i = fid.
index;
511 FcPatternAdd(pattern,FC_INDEX,value,
true);
515 if (FcConfigSubstitute(0,pattern,FcMatchPattern)) {
519 if (FcPatternGetInteger (pattern, FC_HINT_STYLE, 0, &hint_style) == FcResultNoMatch)
521 switch (hint_style) {
538 if (!engine->
init(fid,antialias,format)) {
548 if (!hbFace || !hbFace->supported_scripts[script]) {
560 FcPattern *pattern = FcPatternCreate();
565 value.type = FcTypeString;
567 value.u.s = (
const FcChar8 *)cs.
data();
568 FcPatternAdd(pattern,FC_FAMILY,value,
true);
570 int slant_value = FC_SLANT_ROMAN;
572 slant_value = FC_SLANT_ITALIC;
574 slant_value = FC_SLANT_OBLIQUE;
575 FcPatternAddInteger(pattern, FC_SLANT, slant_value);
579 FcLangSet *ls = FcLangSetCreate();
581 FcPatternAddLangSet(pattern, FC_LANG, ls);
582 FcLangSetDestroy(ls);
587 value.u.s = (
const FcChar8 *)stylehint;
588 FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
591 FcConfigSubstitute(0, pattern, FcMatchPattern);
592 FcDefaultSubstitute(pattern);
594 FcResult result = FcResultMatch;
595 FcFontSet *fontSet = FcFontSort(0,pattern,FcFalse,0,&result);
596 FcPatternDestroy(pattern);
600 for (
int i = 0; i < fontSet->nfont; i++) {
602 if (FcPatternGetString(fontSet->fonts[i], FC_FAMILY, 0, &value) != FcResultMatch)
607 fallbackFamilies << familyName;
610 FcFontSetDestroy(fontSet);
void setSupported(QFontDatabase::WritingSystem, bool supported=true)
Sets the supported state of the writing system given by writingSystem to the value specified by suppo...
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
char * data()
Returns a pointer to the data stored in the byte array.
static const char * getFcFamilyForStyleHint(const QFont::StyleHint style)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
The QByteArray class provides an array of bytes.
static const char * languageForWritingSystem[]
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
Weight
Qt uses a weighting scale from 0 to 99 similar to, but not the same as, the scales used in Windows or...
The QString class provides a Unicode character string.
QFontEngine * fontEngine(const QFontDef &fontDef, QUnicodeTables::Script script, void *handle)
Returns the font engine that can be used to render the font described by the font definition...
Stretch
Predefined stretch values that follow the CSS naming convention.
bool supported(QFontDatabase::WritingSystem) const
Returns true if the writing system given by writingSystem is supported; otherwise returns false...
Q_CORE_EXPORT QTextStream & fixed(QTextStream &s)
bool init(FaceId faceId, bool antiaalias, GlyphFormat defaultFormat=Format_None, const QByteArray &fontData=QByteArray())
static const ushort specialChars[]
static const char * openType[]
static QFontEngine::FaceId fontFile(const QByteArray &_xname, QFreetypeFace **freetype, int *synth)
static const ushort sampleCharForWritingSystem[]
The QStringList class provides a list of strings.
The QSupportedWritingSystems class is used when registering fonts with the internal Qt fontdatabase...
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
const char * styleHint(const QFontDef &request)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
void populateFontDatabase()
This function is called once at startup by Qts internal fontdatabase.
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Style
This enum describes the different styles of glyphs that are used to display text. ...
static const char * specialLanguages[]
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
StyleHint
Style hints are used by the font matching algorithm to find an appropriate default family if a select...
static bool scriptRequiresOpenType(int script)
void setDefaultHintStyle(HintStyle style)
QStringList fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const
Returns a list of alternative fonts for the specified family and style and script using the styleHint...
static bool requiresOpenType(int writingSystem)
static const QCssKnownValue properties[NumProperties - 1]
static int getFCWeight(int fc_weight)
HB_Face harfbuzzFace() const
static QStringList fallbackFamilies(const QString &family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script)