Qt 4.8
Classes | Macros | Enumerations | Functions | Variables
qfontdatabase_x11.cpp File Reference
#include <qplatformdefs.h>
#include <qdebug.h>
#include <qpaintdevice.h>
#include <qelapsedtimer.h>
#include <private/qt_x11_p.h>
#include "qx11info_x11.h"
#include <qfile.h>
#include <qtemporaryfile.h>
#include <qabstractfileengine.h>
#include <qmath.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <private/qfontengine_x11_p.h>
#include <ft2build.h>
#include <FT_FREETYPE_H>

Go to the source code of this file.

Classes

struct  XlfdEncoding
 

Macros

#define FC_FAMILYLANG   "familylang"
 
#define FC_WIDTH   "width"
 
#define make_tag(c1, c2, c3, c4)
 

Enumerations

enum  { SpecialLanguageCount = sizeof(specialLanguages) / sizeof(const char *) }
 
enum  { SpecialCharCount = sizeof(specialChars) / sizeof(ushort) }
 
enum  { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char *) }
 
enum  { SampleCharCount = sizeof(sampleCharForWritingSystem) / sizeof(ushort) }
 
enum  { OpenTypeCount = sizeof(openType) / sizeof(const char *) }
 
enum  XLFDFieldNames {
  Foundry, Family, Weight, Slant,
  Width, AddStyle, PixelSize, PointSize,
  ResolutionX, ResolutionY, Spacing, AverageWidth,
  CharsetRegistry, CharsetEncoding, NFontFields
}
 

Functions

static void capitalize (char *s)
 
static void checkSymbolFont (QtFontFamily *family)
 
static void checkSymbolFonts (const QString &family=QString())
 
static void FcFontSetRemove (FcFontSet *fs, int at)
 
static FcPattern * getFcPattern (const QFontPrivate *fp, int script, const QFontDef &request)
 
static int getFCWeight (int fc_weight)
 
static QtFontStyle::Key getStyle (char **tokens)
 
static void initializeDb ()
 
static bool isFixedPitch (char **tokens)
 
static bool isScalable (char **tokens)
 
static bool isSmoothlyScalable (char **tokens)
 
static bool isZero (char *x)
 
static void load (const QString &family=QString(), int script=-1, bool forceXLFD=false)
 
static QFontEngineloadFc (const QFontPrivate *fp, int script, const QFontDef &request)
 
static void loadFontConfig ()
 
static QFontEngineloadRaw (const QFontPrivate *fp, const QFontDef &request)
 
static void loadXlfds (const char *reqFamily, int encoding_id)
 
static bool parseXFontName (char *fontName, char **tokens)
 
static bool preferScalable (const QFontDef &request)
 
void qt_addPatternProps (FcPattern *pattern, int screen, int script, const QFontDef &request)
 
int qt_encoding_id_for_mib (int mib)
 
QFontDef qt_FcPatternToQFontDef (FcPattern *pattern, const QFontDef &request)
 
bool qt_fillFontDef (const QByteArray &xlfd, QFontDef *fd, int dpi, QtFontDesc *desc)
 
static bool qt_fillFontDef (XFontStruct *fs, QFontDef *fd, int dpi, QtFontDesc *desc)
 
FcFontSet * qt_fontSetForPattern (FcPattern *pattern, const QFontDef &request)
 
int qt_mib_for_xlfd_encoding (const char *encoding)
 
double qt_pixelSize (double pointSize, int dpi)
 
double qt_pointSize (double pixelSize, int dpi)
 
int qt_xlfd_encoding_id (const char *encoding)
 
static FcPattern * queryFont (const FcChar8 *file, const QByteArray &data, int id, FcBlanks *blanks, int *count)
 
static void registerFont (QFontDatabasePrivate::ApplicationFont *fnt)
 
static const char * styleHint (const QFontDef &request)
 
static QFontEnginetryPatternLoad (FcPattern *match, int screen, const QFontDef &request, int script)
 
static const char * xlfd_for_id (int id)
 

Variables

static unsigned char encodingLoaded [numEncodings]
 
static const char * languageForWritingSystem []
 
const int numEncodings = sizeof(xlfd_encoding) / sizeof(XlfdEncoding) - 1
 
static const char * openType []
 
bool qt_is_gui_used
 
static const ushort sampleCharForWritingSystem []
 
static const ushort specialChars []
 
static const char * specialLanguages []
 
static const char writingSystems_for_xlfd_encoding [sizeof(xlfd_encoding)][QFontDatabase::WritingSystemsCount]
 
static const XlfdEncoding xlfd_encoding []
 
static bool xlfdsFullyLoaded = false
 

Macro Definition Documentation

◆ FC_FAMILYLANG

#define FC_FAMILYLANG   "familylang"

Definition at line 2006 of file qfontdatabase_x11.cpp.

Referenced by registerFont().

◆ FC_WIDTH

#define FC_WIDTH   "width"

◆ make_tag

#define make_tag (   c1,
  c2,
  c3,
  c4 
)
Value:
((((unsigned int)c1)<<24) | (((unsigned int)c2)<<16) | \
(((unsigned int)c3)<<8) | ((unsigned int)c4))

Definition at line 103 of file qfontdatabase_x11.cpp.

Referenced by qt_xlfd_encoding_id().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SpecialLanguageCount 

Definition at line 845 of file qfontdatabase_x11.cpp.

845 { SpecialLanguageCount = sizeof(specialLanguages) / sizeof(const char *) };
static const char * specialLanguages[]

◆ anonymous enum

anonymous enum
Enumerator
SpecialCharCount 

Definition at line 877 of file qfontdatabase_x11.cpp.

877 { SpecialCharCount = sizeof(specialChars) / sizeof(ushort) };
static const ushort specialChars[]
unsigned short ushort
Definition: qglobal.h:995

◆ anonymous enum

anonymous enum
Enumerator
LanguageCount 

Definition at line 917 of file qfontdatabase_x11.cpp.

917 { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char *) };
static const char * languageForWritingSystem[]

◆ anonymous enum

anonymous enum
Enumerator
SampleCharCount 

Definition at line 957 of file qfontdatabase_x11.cpp.

957 { SampleCharCount = sizeof(sampleCharForWritingSystem) / sizeof(ushort) };
unsigned short ushort
Definition: qglobal.h:995
static const ushort sampleCharForWritingSystem[]

◆ anonymous enum

anonymous enum
Enumerator
OpenTypeCount 

Definition at line 998 of file qfontdatabase_x11.cpp.

998 { OpenTypeCount = sizeof(openType) / sizeof(const char *) };
static const char * openType[]

◆ XLFDFieldNames

Enumerator
Foundry 
Family 
Weight 
Slant 
Width 
AddStyle 
PixelSize 
PointSize 
ResolutionX 
ResolutionY 
Spacing 
AverageWidth 
CharsetRegistry 
CharsetEncoding 
NFontFields 

Definition at line 420 of file qfontdatabase_x11.cpp.

Function Documentation

◆ capitalize()

static void capitalize ( char *  s)
inlinestatic

Definition at line 84 of file qfontdatabase_x11.cpp.

Referenced by loadXlfds(), and qt_fillFontDef().

85 {
86  bool space = true;
87  while(*s) {
88  if (space)
89  *s = toupper(*s);
90  space = (*s == ' ');
91  ++s;
92  }
93 }

◆ checkSymbolFont()

static void checkSymbolFont ( QtFontFamily family)
static

Definition at line 1268 of file qfontdatabase_x11.cpp.

Referenced by checkSymbolFonts().

1269 {
1270  if (!family || family->symbol_checked || family->fontFilename.isEmpty())
1271  return;
1272 // qDebug() << "checking " << family->rawName;
1273  family->symbol_checked = true;
1274 
1276  id.filename = family->fontFilename;
1277  id.index = family->fontFileIndex;
1279  if (!f) {
1280  qWarning("checkSymbolFonts: Couldn't open face %s (%s/%d)",
1281  qPrintable(family->name), family->fontFilename.data(), family->fontFileIndex);
1282  return;
1283  }
1284  for (int i = 0; i < f->face->num_charmaps; ++i) {
1285  FT_CharMap cm = f->face->charmaps[i];
1286  if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM
1287  || cm->encoding == FT_ENCODING_MS_SYMBOL) {
1288  for (int x = QFontDatabase::Latin; x < QFontDatabase::Other; ++x)
1290  family->writingSystems[QFontDatabase::Other] = QtFontFamily::Supported;
1291  break;
1292  }
1293  }
1294  f->release(id);
1295 }
static QFreetypeFace * getFace(const QFontEngine::FaceId &face_id, const QByteArray &fontData=QByteArray())
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QByteArray fontFilename
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
void release(const QFontEngine::FaceId &face_id)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
#define qPrintable(string)
Definition: qglobal.h:1750

◆ checkSymbolFonts()

static void checkSymbolFonts ( const QString family = QString())
static

Definition at line 1297 of file qfontdatabase_x11.cpp.

Referenced by QFontDatabase::families(), and QFontDatabase::writingSystems().

1298 {
1299 #ifndef QT_NO_FONTCONFIG
1300  QFontDatabasePrivate *d = privateDb();
1301 
1302  if (family.isEmpty()) {
1303  for (int i = 0; i < d->count; ++i)
1304  checkSymbolFont(d->families[i]);
1305  } else {
1306  checkSymbolFont(d->family(family));
1307  }
1308 #endif
1309 }
double d
Definition: qnumeric_p.h:62
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QtFontFamily ** families
QtFontFamily * family(const QString &f, bool=false)
static void checkSymbolFont(QtFontFamily *family)

◆ FcFontSetRemove()

static void FcFontSetRemove ( FcFontSet *  fs,
int  at 
)
static

Definition at line 1604 of file qfontdatabase_x11.cpp.

Referenced by qt_fontSetForPattern().

1605 {
1606  Q_ASSERT(at < fs->nfont);
1607  FcPatternDestroy(fs->fonts[at]);
1608  int len = (--fs->nfont - at) * sizeof(FcPattern *);;
1609  if (len > 0)
1610  memmove(fs->fonts + at, fs->fonts + at + 1, len);
1611 }
#define at(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ getFcPattern()

static FcPattern* getFcPattern ( const QFontPrivate fp,
int  script,
const QFontDef request 
)
static

Definition at line 1524 of file qfontdatabase_x11.cpp.

Referenced by loadFc().

1525 {
1526  if (!X11->has_fontconfig)
1527  return 0;
1528 
1529  FcPattern *pattern = FcPatternCreate();
1530  if (!pattern)
1531  return 0;
1532 
1533  FcValue value;
1534  value.type = FcTypeString;
1535 
1536  QtFontDesc desc;
1537  QStringList families_and_foundries = familyList(request);
1538  for (int i = 0; i < families_and_foundries.size(); ++i) {
1539  QString family, foundry;
1540  parseFontName(families_and_foundries.at(i), foundry, family);
1541  if (!family.isEmpty()) {
1542  QByteArray cs = family.toUtf8();
1543  value.u.s = (const FcChar8 *)cs.data();
1544  FcPatternAdd(pattern, FC_FAMILY, value, FcTrue);
1545  }
1546  if (i == 0) {
1547  QT_PREPEND_NAMESPACE(match)(script, request, family, foundry, -1, &desc);
1548  if (!foundry.isEmpty()) {
1549  QByteArray cs = foundry.toUtf8();
1550  value.u.s = (const FcChar8 *)cs.data();
1551  FcPatternAddWeak(pattern, FC_FOUNDRY, value, FcTrue);
1552  }
1553  }
1554  }
1555 
1556  const char *stylehint = styleHint(request);
1557  if (stylehint) {
1558  value.u.s = (const FcChar8 *)stylehint;
1559  FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
1560  }
1561 
1562  if (!request.ignorePitch) {
1563  char pitch_value = FC_PROPORTIONAL;
1564  if (request.fixedPitch || (desc.family && desc.family->fixedPitch))
1565  pitch_value = FC_MONO;
1566  FcPatternAddInteger(pattern, FC_SPACING, pitch_value);
1567  }
1568  FcPatternAddBool(pattern, FC_OUTLINE, !(request.styleStrategy & QFont::PreferBitmap));
1569  if (preferScalable(request) || (desc.style && desc.style->smoothScalable))
1570  FcPatternAddBool(pattern, FC_SCALABLE, true);
1571 
1572  qt_addPatternProps(pattern, fp->screen, script, request);
1573 
1574  FcConfigSubstitute(0, pattern, FcMatchPattern);
1575  FcDefaultSubstitute(pattern);
1576 
1577  // these should only get added to the pattern _after_ substitution
1578  // append the default fallback font for the specified script
1579  extern QString qt_fallback_font_family(int);
1581  if (!fallback.isEmpty()) {
1582  QByteArray cs = fallback.toUtf8();
1583  value.u.s = (const FcChar8 *)cs.data();
1584  FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
1585  }
1586 
1587  // add the default family
1588  QString defaultFamily = QApplication::font().family();
1589  QByteArray cs = defaultFamily.toUtf8();
1590  value.u.s = (const FcChar8 *)cs.data();
1591  FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
1592 
1593  // add QFont::defaultFamily() to the list, for compatibility with
1594  // previous versions
1595  defaultFamily = QApplication::font().defaultFamily();
1596  cs = defaultFamily.toUtf8();
1597  value.u.s = (const FcChar8 *)cs.data();
1598  FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
1599 
1600  return pattern;
1601 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QString qt_fallback_font_family(int script)
Definition: qfont_x11.cpp:114
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool match(const uchar *found, const char *target, uint len)
QtFontStyle * style
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define X11
Definition: qt_x11_p.h:724
static void parseFontName(const QString &name, QString &foundry, QString &family)
This makes sense of the font family name:
static QFont font()
Returns the default application font.
static QStringList familyList(const QFontDef &req)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
static const char * styleHint(const QFontDef &request)
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
QString family() const
Returns the requested font family name, i.e.
Definition: qfont.cpp:906
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QtFontFamily * family
QString defaultFamily() const
Returns the family name that corresponds to the current style hint.
Definition: qfont_mac.cpp:134
static bool preferScalable(const QFontDef &request)
int screen
Definition: qfont_p.h:181
void qt_addPatternProps(FcPattern *pattern, int screen, int script, const QFontDef &request)
static QMenuBar * fallback
Definition: qmenu_mac.mm:1617

◆ getFCWeight()

static int getFCWeight ( int  fc_weight)
static

Definition at line 729 of file qfontdatabase_x11.cpp.

Referenced by loadFontConfig(), and qt_FcPatternToQFontDef().

730 {
731  int qtweight = QFont::Black;
732  if (fc_weight <= (FC_WEIGHT_LIGHT + FC_WEIGHT_MEDIUM) / 2)
733  qtweight = QFont::Light;
734  else if (fc_weight <= (FC_WEIGHT_MEDIUM + FC_WEIGHT_DEMIBOLD) / 2)
735  qtweight = QFont::Normal;
736  else if (fc_weight <= (FC_WEIGHT_DEMIBOLD + FC_WEIGHT_BOLD) / 2)
737  qtweight = QFont::DemiBold;
738  else if (fc_weight <= (FC_WEIGHT_BOLD + FC_WEIGHT_BLACK) / 2)
739  qtweight = QFont::Bold;
740 
741  return qtweight;
742 }

◆ getStyle()

static QtFontStyle::Key getStyle ( char **  tokens)
static

Definition at line 569 of file qfontdatabase_x11.cpp.

Referenced by loadXlfds(), and QFormLayoutPrivate::~QFormLayoutPrivate().

570 {
572 
573  char slant0 = tolower((uchar) tokens[Slant][0]);
574 
575  if (slant0 == 'r') {
576  if (tokens[Slant][1]) {
577  char slant1 = tolower((uchar) tokens[Slant][1]);
578 
579  if (slant1 == 'o')
581  else if (slant1 == 'i')
583  }
584  } else if (slant0 == 'o')
586  else if (slant0 == 'i')
588 
589  key.weight = getFontWeight(QLatin1String(tokens[Weight]));
590 
591  if (qstrcmp(tokens[Width], "normal") == 0) {
592  key.stretch = 100;
593  } else if (qstrcmp(tokens[Width], "semi condensed") == 0 ||
594  qstrcmp(tokens[Width], "semicondensed") == 0) {
595  key.stretch = 90;
596  } else if (qstrcmp(tokens[Width], "condensed") == 0) {
597  key.stretch = 80;
598  } else if (qstrcmp(tokens[Width], "narrow") == 0) {
599  key.stretch = 60;
600  }
601 
602  return key;
603 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
unsigned char uchar
Definition: qglobal.h:994
static int getFontWeight(const QString &weightString)
int key

◆ initializeDb()

static void initializeDb ( )
static

Definition at line 1313 of file qfontdatabase_x11.cpp.

Referenced by load(), loadFontConfig(), and QFontDatabase::loadXlfd().

1314 {
1315  QFontDatabasePrivate *db = privateDb();
1316  if (!db || db->count)
1317  return;
1318 
1319  QElapsedTimer t;
1320  t.start();
1321 
1322 #ifndef QT_NO_FONTCONFIG
1323  if (db->reregisterAppFonts) {
1324  db->reregisterAppFonts = false;
1325  for (int i = 0; i < db->applicationFonts.count(); ++i)
1326  if (!db->applicationFonts.at(i).families.isEmpty()) {
1327  registerFont(&db->applicationFonts[i]);
1328  }
1329  }
1330 
1331  loadFontConfig();
1332  FD_DEBUG("QFontDatabase: loaded FontConfig: %d ms", int(t.elapsed()));
1333 #endif
1334 
1335  t.start();
1336 
1337 #ifndef QT_NO_FONTCONFIG
1338  for (int i = 0; i < db->count; i++) {
1339  for (int j = 0; j < db->families[i]->count; ++j) { // each foundry
1340  QtFontFoundry *foundry = db->families[i]->foundries[j];
1341  for (int k = 0; k < foundry->count; ++k) {
1342  QtFontStyle *style = foundry->styles[k];
1343  if (style->key.style != QFont::StyleNormal) continue;
1344 
1345  QtFontSize *size = style->pixelSize(SMOOTH_SCALABLE);
1346  if (! size) continue; // should not happen
1347  QtFontEncoding *enc = size->encodingID(-1, 0, 0, 0, 0, true);
1348  if (! enc) continue; // should not happen either
1349 
1350  QtFontStyle::Key key = style->key;
1351 
1352  // does this style have an italic equivalent?
1353  key.style = QFont::StyleItalic;
1354  QtFontStyle *equiv = foundry->style(key);
1355  if (equiv) continue;
1356 
1357  // does this style have an oblique equivalent?
1358  key.style = QFont::StyleOblique;
1359  equiv = foundry->style(key);
1360  if (equiv) continue;
1361 
1362  // let's fake one...
1363  equiv = foundry->style(key, QString(), true);
1364  equiv->styleName = styleStringHelper(key.weight, QFont::Style(key.style));
1365  equiv->smoothScalable = true;
1366 
1367  QtFontSize *equiv_size = equiv->pixelSize(SMOOTH_SCALABLE, true);
1368  QtFontEncoding *equiv_enc = equiv_size->encodingID(-1, 0, 0, 0, 0, true);
1369 
1370  // keep the same pitch
1371  equiv_enc->pitch = enc->pitch;
1372  }
1373  }
1374  }
1375 #endif
1376 
1377 
1378 #ifdef QFONTDATABASE_DEBUG
1379 #ifndef QT_NO_FONTCONFIG
1380  if (!X11->has_fontconfig)
1381 #endif
1382  // load everything at startup in debug mode.
1383  loadXlfds(0, -1);
1384 
1385  // print the database
1386  for (int f = 0; f < db->count; f++) {
1387  QtFontFamily *family = db->families[f];
1388  FD_DEBUG("'%s' %s fixed=%s", family->name.latin1(), (family->fixedPitch ? "fixed" : ""),
1389  (family->fixedPitch ? "yes" : "no"));
1390  for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
1392  FD_DEBUG("\t%s: %s", QFontDatabase::writingSystemName(ws).toLatin1().constData(),
1393  ((family->writingSystems[i] & QtFontFamily::Supported) ? "Supported" :
1394  (family->writingSystems[i] & QtFontFamily::Unsupported) == QtFontFamily::Unsupported ?
1395  "Unsupported" : "Unknown"));
1396  }
1397 
1398  for (int fd = 0; fd < family->count; fd++) {
1399  QtFontFoundry *foundry = family->foundries[fd];
1400  FD_DEBUG("\t\t'%s'", foundry->name.latin1());
1401  for (int s = 0; s < foundry->count; s++) {
1402  QtFontStyle *style = foundry->styles[s];
1403  FD_DEBUG("\t\t\tstyle: style=%d weight=%d (%s)\n"
1404  "\t\t\tstretch=%d (%s)",
1405  style->key.style, style->key.weight,
1406  style->weightName, style->key.stretch,
1407  style->setwidthName ? style->setwidthName : "nil");
1408  if (style->smoothScalable)
1409  FD_DEBUG("\t\t\t\tsmooth scalable");
1410  else if (style->bitmapScalable)
1411  FD_DEBUG("\t\t\t\tbitmap scalable");
1412  if (style->pixelSizes) {
1413  qDebug("\t\t\t\t%d pixel sizes", style->count);
1414  for (int z = 0; z < style->count; ++z) {
1415  QtFontSize *size = style->pixelSizes + z;
1416  for (int e = 0; e < size->count; ++e) {
1417  FD_DEBUG("\t\t\t\t size %5d pitch %c encoding %s",
1418  size->pixelSize,
1419  size->encodings[e].pitch,
1420  xlfd_for_id(size->encodings[e].encoding));
1421  }
1422  }
1423  }
1424  }
1425  }
1426  }
1427 #endif // QFONTDATABASE_DEBUG
1428 }
static void loadFontConfig()
unsigned short pixelSize
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
signed int count
QtFontStyle ** styles
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define X11
Definition: qt_x11_p.h:724
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
Q_CORE_EXPORT void qDebug(const char *,...)
#define SMOOTH_SCALABLE
static void loadXlfds(const char *reqFamily, int encoding_id)
#define FD_DEBUG
QtFontFamily ** families
static const char * xlfd_for_id(int id)
const char * setwidthName
QtFontFoundry ** foundries
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
signed int encoding
QTextStream & ws(QTextStream &stream)
Calls skipWhiteSpace() on stream and returns stream.
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QtFontSize * pixelSize(unsigned short size, bool=false)
int key
QtFontEncoding * encodingID(int id, uint xpoint=0, uint xres=0, uint yres=0, uint avgwidth=0, bool add=false)
static QString styleStringHelper(int weight, QFont::Style style)
unsigned short count
QtFontEncoding * encodings
QVector< ApplicationFont > applicationFonts
static QString writingSystemName(WritingSystem writingSystem)
Returns the names the writingSystem (e.g.
QString styleName
const char * weightName
void start()
Starts this timer.
QtFontSize * pixelSizes

◆ isFixedPitch()

static bool isFixedPitch ( char **  tokens)
inlinestatic

Definition at line 489 of file qfontdatabase_x11.cpp.

Referenced by loadXlfds().

490 {
491  return (tokens[Spacing][0] == 'm' ||
492  tokens[Spacing][0] == 'c' ||
493  tokens[Spacing][0] == 'M' ||
494  tokens[Spacing][0] == 'C');
495 }

◆ isScalable()

static bool isScalable ( char **  tokens)
inlinestatic

Definition at line 476 of file qfontdatabase_x11.cpp.

Referenced by loadXlfds().

477 {
478  return (isZero(tokens[PixelSize]) &&
479  isZero(tokens[PointSize]) &&
480  isZero(tokens[AverageWidth]));
481 }
static bool isZero(char *x)

◆ isSmoothlyScalable()

static bool isSmoothlyScalable ( char **  tokens)
inlinestatic

Definition at line 483 of file qfontdatabase_x11.cpp.

Referenced by QFontDatabase::isScalable(), and loadXlfds().

484 {
485  return (isZero(tokens[ResolutionX]) &&
486  isZero(tokens[ResolutionY]));
487 }
static bool isZero(char *x)

◆ isZero()

static bool isZero ( char *  x)
inlinestatic

Definition at line 471 of file qfontdatabase_x11.cpp.

Referenced by isScalable(), and isSmoothlyScalable().

472 {
473  return (x[0] == '0' && x[1] == 0);
474 }

◆ load()

static void load ( const QString family = QString(),
int  script = -1,
bool  forceXLFD = false 
)
static

Definition at line 1228 of file qfontdatabase_x11.cpp.

1229 {
1230  if (X11->has_fontconfig && !forceXLFD) {
1231  initializeDb();
1232  return;
1233  }
1234 
1235 #ifdef QFONTDATABASE_DEBUG
1236  QElapsedTimer t;
1237  t.start();
1238 #endif
1239 
1240  if (family.isNull() && script == -1) {
1241  loadXlfds(0, -1);
1242  } else {
1243  if (family.isNull()) {
1244  // load all families in all writing systems that match \a script
1245  for (int ws = 1; ws < QFontDatabase::WritingSystemsCount; ++ws) {
1247  continue;
1248  for (int i = 0; i < numEncodings; ++i) {
1250  loadXlfds(0, i);
1251  }
1252  }
1253  } else {
1254  QtFontFamily *f = privateDb()->family(family);
1255  // could reduce this further with some more magic:
1256  // would need to remember the encodings loaded for the family.
1257  if (!f || !f->xlfdLoaded)
1258  loadXlfds(family.toLatin1(), -1);
1259  }
1260  }
1261 
1262 #ifdef QFONTDATABASE_DEBUG
1263  FD_DEBUG("QFontDatabase: load(%s, %d) took %d ms",
1264  family.toLatin1().constData(), script, t.elapsed());
1265 #endif
1266 }
const int numEncodings
static void initializeDb()
#define X11
Definition: qt_x11_p.h:724
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
static void loadXlfds(const char *reqFamily, int encoding_id)
#define FD_DEBUG
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
QTextStream & ws(QTextStream &stream)
Calls skipWhiteSpace() on stream and returns stream.
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
static const char writingSystems_for_xlfd_encoding[sizeof(xlfd_encoding)][QFontDatabase::WritingSystemsCount]
static const int scriptForWritingSystem[]
void start()
Starts this timer.

◆ loadFc()

static QFontEngine* loadFc ( const QFontPrivate fp,
int  script,
const QFontDef request 
)
static

Definition at line 1702 of file qfontdatabase_x11.cpp.

Referenced by QFontDatabase::loadXlfd().

1703 {
1704  FM_DEBUG("===================== loadFc: script=%d family='%s'\n", script, request.family.toLatin1().data());
1705  FcPattern *pattern = getFcPattern(fp, script, request);
1706 
1707 #ifdef FONT_MATCH_DEBUG
1708  FM_DEBUG("\n\nfinal FcPattern contains:\n");
1709  FcPatternPrint(pattern);
1710 #endif
1711 
1712  QFontEngine *fe = 0;
1713  FcResult res;
1714  FcPattern *match = FcFontMatch(0, pattern, &res);
1715  fe = tryPatternLoad(match, fp->screen, request, script);
1716  if (!fe) {
1717  FcFontSet *fs = qt_fontSetForPattern(pattern, request);
1718 
1719  if (match) {
1720  FcPatternDestroy(match);
1721  match = 0;
1722  }
1723 
1724  if (fs) {
1725  for (int i = 0; !fe && i < fs->nfont; ++i) {
1726  match = FcFontRenderPrepare(NULL, pattern, fs->fonts[i]);
1727  fe = tryPatternLoad(match, fp->screen, request, script);
1728  if (fe)
1729  break;
1730  FcPatternDestroy(match);
1731  match = 0;
1732  }
1733  FcFontSetDestroy(fs);
1734  }
1735  FM_DEBUG("engine for script %d is %s\n", script, fe ? fe->fontDef.family.toLatin1().data(): "(null)");
1736  }
1737  if (fe
1739  && !(request.styleStrategy & QFont::NoFontMerging) && !fe->symbol) {
1740  fe = new QFontEngineMultiFT(fe, match, pattern, fp->screen, request);
1741  } else {
1742  FcPatternDestroy(pattern);
1743  }
1744  if (match)
1745  FcPatternDestroy(match);
1746  return fe;
1747 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
FcFontSet * qt_fontSetForPattern(FcPattern *pattern, const QFontDef &request)
static bool match(const uchar *found, const char *target, uint len)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
static QFontEngine * tryPatternLoad(FcPattern *match, int screen, const QFontDef &request, int script)
#define FM_DEBUG
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
int screen
Definition: qfont_p.h:181
static FcPattern * getFcPattern(const QFontPrivate *fp, int script, const QFontDef &request)
QFontDef fontDef
QString family
Definition: qfont_p.h:82
uint styleStrategy
Definition: qfont_p.h:92

◆ loadFontConfig()

static void loadFontConfig ( )
static

Definition at line 1001 of file qfontdatabase_x11.cpp.

Referenced by initializeDb().

1002 {
1003  Q_ASSERT_X(X11, "QFontDatabase",
1004  "A QApplication object needs to be constructed before FontConfig is used.");
1005  if (!X11->has_fontconfig)
1006  return;
1007 
1009  "QFontDatabase", "New scripts have been added.");
1011  "QFontDatabase", "New scripts have been added.");
1013  "QFontDatabase", "New writing systems have been added.");
1015  "QFontDatabase", "New writing systems have been added.");
1017  "QFontDatabase", "New writing systems have been added.");
1018 
1019  QFontDatabasePrivate *db = privateDb();
1020  FcFontSet *fonts;
1021 
1022  FcPattern *pattern = FcPatternCreate();
1023  FcDefaultSubstitute(pattern);
1024  FcChar8 *lang = 0;
1025  if (FcPatternGetString(pattern, FC_LANG, 0, &lang) == FcResultMatch)
1026  db->systemLang = QString::fromUtf8((const char *) lang);
1027  FcPatternDestroy(pattern);
1028 
1029  QString familyName;
1030  FcChar8 *value = 0;
1031  int weight_value;
1032  int slant_value;
1033  int spacing_value;
1034  FcChar8 *file_value;
1035  int index_value;
1036  FcChar8 *foundry_value;
1037  FcChar8 *style_value;
1038  FcBool scalable;
1039 
1040  {
1041  FcObjectSet *os = FcObjectSetCreate();
1042  FcPattern *pattern = FcPatternCreate();
1043  const char *properties [] = {
1044  FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT,
1045  FC_SPACING, FC_FILE, FC_INDEX,
1046  FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT,
1047  FC_WIDTH,
1048 #if FC_VERSION >= 20297
1049  FC_CAPABILITY,
1050 #endif
1051  (const char *)0
1052  };
1053  const char **p = properties;
1054  while (*p) {
1055  FcObjectSetAdd(os, *p);
1056  ++p;
1057  }
1058  fonts = FcFontList(0, pattern, os);
1059  FcObjectSetDestroy(os);
1060  FcPatternDestroy(pattern);
1061  }
1062 
1063  for (int i = 0; i < fonts->nfont; i++) {
1064  if (FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, &value) != FcResultMatch)
1065  continue;
1066  // capitalize(value);
1067  familyName = QString::fromUtf8((const char *)value);
1068  slant_value = FC_SLANT_ROMAN;
1069  weight_value = FC_WEIGHT_MEDIUM;
1070  spacing_value = FC_PROPORTIONAL;
1071  file_value = 0;
1072  index_value = 0;
1073  scalable = FcTrue;
1074 
1075  if (FcPatternGetInteger (fonts->fonts[i], FC_SLANT, 0, &slant_value) != FcResultMatch)
1076  slant_value = FC_SLANT_ROMAN;
1077  if (FcPatternGetInteger (fonts->fonts[i], FC_WEIGHT, 0, &weight_value) != FcResultMatch)
1078  weight_value = FC_WEIGHT_MEDIUM;
1079  if (FcPatternGetInteger (fonts->fonts[i], FC_SPACING, 0, &spacing_value) != FcResultMatch)
1080  spacing_value = FC_PROPORTIONAL;
1081  if (FcPatternGetString (fonts->fonts[i], FC_FILE, 0, &file_value) != FcResultMatch)
1082  file_value = 0;
1083  if (FcPatternGetInteger (fonts->fonts[i], FC_INDEX, 0, &index_value) != FcResultMatch)
1084  index_value = 0;
1085  if (FcPatternGetBool(fonts->fonts[i], FC_SCALABLE, 0, &scalable) != FcResultMatch)
1086  scalable = FcTrue;
1087  if (FcPatternGetString(fonts->fonts[i], FC_FOUNDRY, 0, &foundry_value) != FcResultMatch)
1088  foundry_value = 0;
1089  if (FcPatternGetString(fonts->fonts[i], FC_STYLE, 0, &style_value) != FcResultMatch)
1090  style_value = 0;
1091  QtFontFamily *family = db->family(familyName, true);
1092 
1093  FcLangSet *langset = 0;
1094  FcResult res = FcPatternGetLangSet(fonts->fonts[i], FC_LANG, 0, &langset);
1095  if (res == FcResultMatch) {
1096  for (int i = 1; i < LanguageCount; ++i) {
1097  const FcChar8 *lang = (const FcChar8*) languageForWritingSystem[i];
1098  if (!lang) {
1100  } else {
1101  FcLangResult langRes = FcLangSetHasLang(langset, lang);
1102  if (langRes != FcLangDifferentLang)
1104  else
1106  }
1107  }
1109  family->ftWritingSystemCheck = true;
1110  } else {
1111  // we set Other to supported for symbol fonts. It makes no
1112  // sense to merge these with other ones, as they are
1113  // special in a way.
1114  for (int i = 1; i < LanguageCount; ++i)
1117  }
1118 
1119  FcCharSet *cs = 0;
1120  res = FcPatternGetCharSet(fonts->fonts[i], FC_CHARSET, 0, &cs);
1121  if (res == FcResultMatch) {
1122  // some languages are not supported by FontConfig, we rather check the
1123  // charset to detect these
1124  for (int i = 1; i < SampleCharCount; ++i) {
1126  continue;
1127  if (FcCharSetHasChar(cs, sampleCharForWritingSystem[i]))
1129  }
1130  }
1131 
1132 #if FC_VERSION >= 20297
1133  for (int j = 1; j < LanguageCount; ++j) {
1134  if (family->writingSystems[j] == QtFontFamily::Supported && requiresOpenType(j) && openType[j]) {
1135  FcChar8 *cap;
1136  res = FcPatternGetString (fonts->fonts[i], FC_CAPABILITY, 0, &cap);
1137  if (res != FcResultMatch || !strstr((const char *)cap, openType[j]))
1139  }
1140  }
1141 #endif
1142 
1143  QByteArray file((const char *)file_value);
1144  family->fontFilename = file;
1145  family->fontFileIndex = index_value;
1146 
1147  QtFontStyle::Key styleKey;
1148  QString styleName = style_value ? QString::fromUtf8((const char *) style_value) : QString();
1149  styleKey.style = (slant_value == FC_SLANT_ITALIC)
1151  : ((slant_value == FC_SLANT_OBLIQUE)
1153  : QFont::StyleNormal);
1154  styleKey.weight = getFCWeight(weight_value);
1155  if (!scalable) {
1156  int width = 100;
1157  FcPatternGetInteger (fonts->fonts[i], FC_WIDTH, 0, &width);
1158  styleKey.stretch = width;
1159  }
1160 
1161  QtFontFoundry *foundry
1162  = family->foundry(foundry_value ? QString::fromUtf8((const char *)foundry_value) : QString(), true);
1163  QtFontStyle *style = foundry->style(styleKey, styleName, true);
1164 
1165  if (spacing_value < FC_MONO)
1166  family->fixedPitch = false;
1167 
1168  QtFontSize *size;
1169  if (scalable) {
1170  style->smoothScalable = true;
1171  size = style->pixelSize(SMOOTH_SCALABLE, true);
1172  } else {
1173  double pixel_size = 0;
1174  FcPatternGetDouble (fonts->fonts[i], FC_PIXEL_SIZE, 0, &pixel_size);
1175  size = style->pixelSize((int)pixel_size, true);
1176  }
1177  QtFontEncoding *enc = size->encodingID(-1, 0, 0, 0, 0, true);
1178  enc->pitch = (spacing_value >= FC_CHARCELL ? 'c' :
1179  (spacing_value >= FC_MONO ? 'm' : 'p'));
1180  }
1181 
1182  FcFontSetDestroy (fonts);
1183 
1184  struct FcDefaultFont {
1185  const char *qtname;
1186  const char *rawname;
1187  bool fixed;
1188  };
1189  const FcDefaultFont defaults[] = {
1190  { "Serif", "serif", false },
1191  { "Sans Serif", "sans-serif", false },
1192  { "Monospace", "monospace", true },
1193  { 0, 0, false }
1194  };
1195  const FcDefaultFont *f = defaults;
1196  while (f->qtname) {
1197  QtFontFamily *family = db->family(QLatin1String(f->qtname), true);
1198  family->fixedPitch = f->fixed;
1199  family->synthetic = true;
1200  QtFontFoundry *foundry = family->foundry(QString(), true);
1201 
1202  // aliases only make sense for 'common', not for any of the specials
1203  for (int i = 1; i < LanguageCount; ++i) {
1204  if (requiresOpenType(i))
1206  else
1208  }
1210 
1211  QtFontStyle::Key styleKey;
1212  for (int i = 0; i < 4; ++i) {
1213  styleKey.style = (i%2) ? QFont::StyleNormal : QFont::StyleItalic;
1214  styleKey.weight = (i > 1) ? QFont::Bold : QFont::Normal;
1215  QtFontStyle *style = foundry->style(styleKey, QString(), true);
1216  style->smoothScalable = true;
1217  QtFontSize *size = style->pixelSize(SMOOTH_SCALABLE, true);
1218  QtFontEncoding *enc = size->encodingID(-1, 0, 0, 0, 0, true);
1219  enc->pitch = (f->fixed ? 'm' : 'p');
1220  }
1221  ++f;
1222  }
1223 }
static const char * openType[]
static bool requiresOpenType(int writingSystem)
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define X11
Definition: qt_x11_p.h:724
static const char * languageForWritingSystem[]
QByteArray fontFilename
Q_CORE_EXPORT QTextStream & fixed(QTextStream &s)
#define SMOOTH_SCALABLE
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
static int getFCWeight(int fc_weight)
QtFontFamily * family(const QString &f, bool=false)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QtFontSize * pixelSize(unsigned short size, bool=false)
#define FC_WIDTH
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
QtFontEncoding * encodingID(int id, uint xpoint=0, uint xres=0, uint yres=0, uint avgwidth=0, bool add=false)
QtFontFoundry * foundry(const QString &f, bool=false)
static const ushort sampleCharForWritingSystem[]
bool ftWritingSystemCheck

◆ loadRaw()

static QFontEngine* loadRaw ( const QFontPrivate fp,
const QFontDef request 
)
static

Definition at line 1777 of file qfontdatabase_x11.cpp.

Referenced by QFontDatabase::loadXlfd().

1778 {
1779  Q_ASSERT(fp && fp->rawMode);
1780 
1781  QByteArray xlfd = request.family.toLatin1();
1782  FM_DEBUG("Loading XLFD (rawmode) '%s'", xlfd.data());
1783 
1784  QFontEngine *fe;
1785  XFontStruct *xfs;
1786  if (!(xfs = XLoadQueryFont(QX11Info::display(), xlfd.data())))
1787  if (!(xfs = XLoadQueryFont(QX11Info::display(), "fixed")))
1788  return 0;
1789 
1790  fe = new QFontEngineXLFD(xfs, xlfd, 0);
1791  if (! qt_fillFontDef(xfs, &fe->fontDef, fp->dpi, 0) &&
1792  ! qt_fillFontDef(xlfd, &fe->fontDef, fp->dpi, 0))
1793  fe->fontDef = QFontDef();
1794  return fe;
1795 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
uint rawMode
Definition: qfont_p.h:187
bool qt_fillFontDef(const QByteArray &xlfd, QFontDef *fd, int dpi, QtFontDesc *desc)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
#define FM_DEBUG
QString family
Definition: qfont_p.h:82
static Display * display()
Returns the default display for the application.

◆ loadXlfds()

static void loadXlfds ( const char *  reqFamily,
int  encoding_id 
)
static

Definition at line 609 of file qfontdatabase_x11.cpp.

Referenced by initializeDb(), and load().

610 {
611  QFontDatabasePrivate *db = privateDb();
612  QtFontFamily *fontFamily = reqFamily ? db->family(QLatin1String(reqFamily)) : 0;
613 
614  // make sure we don't load twice
615  if ((encoding_id == -1 && xlfdsFullyLoaded)
616  || (encoding_id != -1 && encodingLoaded[encoding_id]))
617  return;
618  if (fontFamily && fontFamily->xlfdLoaded)
619  return;
620 
621  int fontCount;
622  // force the X server to give us XLFDs
623  QByteArray xlfd_pattern("-*-");
624  xlfd_pattern += (reqFamily && reqFamily[0] != '\0') ? reqFamily : "*";
625  xlfd_pattern += "-*-*-*-*-*-*-*-*-*-*-";
626  xlfd_pattern += xlfd_for_id(encoding_id);
627 
628  char **fontList = XListFonts(QX11Info::display(),
629  xlfd_pattern,
630  0xffff, &fontCount);
631  // qDebug("requesting xlfd='%s', got %d fonts", xlfd_pattern.data(), fontCount);
632 
633 
634  char *tokens[NFontFields];
635 
636  for(int i = 0 ; i < fontCount ; i++) {
637  if (! parseXFontName(fontList[i], tokens))
638  continue;
639 
640  // get the encoding_id for this xlfd. we need to do this
641  // here, since we can pass -1 to this function to do full
642  // database population
643  *(tokens[CharsetEncoding] - 1) = '-';
644  int encoding_id = qt_xlfd_encoding_id(tokens[CharsetRegistry]);
645  if (encoding_id == -1)
646  continue;
647 
648  char *familyName = tokens[Family];
649  capitalize(familyName);
650  char *foundryName = tokens[Foundry];
651  capitalize(foundryName);
652  QtFontStyle::Key styleKey = getStyle(tokens);
653 
654  bool smooth_scalable = false;
655  bool bitmap_scalable = false;
656  if (isScalable(tokens)) {
657  if (isSmoothlyScalable(tokens))
658  smooth_scalable = true;
659  else
660  bitmap_scalable = true;
661  }
662  uint pixelSize = atoi(tokens[PixelSize]);
663  uint xpointSize = atoi(tokens[PointSize]);
664  uint xres = atoi(tokens[ResolutionX]);
665  uint yres = atoi(tokens[ResolutionY]);
666  uint avgwidth = atoi(tokens[AverageWidth]);
667  bool fixedPitch = isFixedPitch(tokens);
668 
669  if (avgwidth == 0 && pixelSize != 0) {
670  /*
671  Ignore bitmap scalable fonts that are automatically
672  generated by some X servers. We know they are bitmap
673  scalable because even though they have a specified pixel
674  size, the average width is zero.
675  */
676  continue;
677  }
678 
679  QtFontFamily *family = fontFamily ? fontFamily : db->family(QLatin1String(familyName), true);
680  family->fontFileIndex = -1;
681  family->symbol_checked = true;
682  QtFontFoundry *foundry = family->foundry(QLatin1String(foundryName), true);
683  QtFontStyle *style = foundry->style(styleKey, QString(), true);
684 
685  delete [] style->weightName;
686  style->weightName = qstrdup(tokens[Weight]);
687  delete [] style->setwidthName;
688  style->setwidthName = qstrdup(tokens[Width]);
689 
690  if (smooth_scalable) {
691  style->smoothScalable = true;
692  style->bitmapScalable = false;
693  pixelSize = SMOOTH_SCALABLE;
694  }
695  if (!style->smoothScalable && bitmap_scalable)
696  style->bitmapScalable = true;
697  if (!fixedPitch)
698  family->fixedPitch = false;
699 
700  QtFontSize *size = style->pixelSize(pixelSize, true);
701  QtFontEncoding *enc =
702  size->encodingID(encoding_id, xpointSize, xres, yres, avgwidth, true);
703  enc->pitch = *tokens[Spacing];
704  if (!enc->pitch) enc->pitch = '*';
705 
706  for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
707  if (writingSystems_for_xlfd_encoding[encoding_id][i])
709  }
710  }
711  if (!reqFamily) {
712  // mark encoding as loaded
713  if (encoding_id == -1)
714  xlfdsFullyLoaded = true;
715  else
716  encodingLoaded[encoding_id] = true;
717  }
718 
719  XFreeFontNames(fontList);
720 }
static bool xlfdsFullyLoaded
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static bool isScalable(char **tokens)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int qt_xlfd_encoding_id(const char *encoding)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define SMOOTH_SCALABLE
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
static const char * xlfd_for_id(int id)
const char * setwidthName
unsigned int uint
Definition: qglobal.h:996
static bool parseXFontName(char *fontName, char **tokens)
QtFontFamily * family(const QString &f, bool=false)
static bool isSmoothlyScalable(char **tokens)
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QtFontSize * pixelSize(unsigned short size, bool=false)
static QtFontStyle::Key getStyle(char **tokens)
static void capitalize(char *s)
QtFontEncoding * encodingID(int id, uint xpoint=0, uint xres=0, uint yres=0, uint avgwidth=0, bool add=false)
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
static const char writingSystems_for_xlfd_encoding[sizeof(xlfd_encoding)][QFontDatabase::WritingSystemsCount]
static unsigned char encodingLoaded[numEncodings]
QtFontFoundry * foundry(const QString &f, bool=false)
const char * weightName
static bool isFixedPitch(char **tokens)
static Display * display()
Returns the default display for the application.

◆ parseXFontName()

static bool parseXFontName ( char *  fontName,
char **  tokens 
)
static

Definition at line 439 of file qfontdatabase_x11.cpp.

Referenced by loadXlfds(), and qt_fillFontDef().

440 {
441  if (! fontName || fontName[0] == '0' || fontName[0] != '-') {
442  tokens[0] = 0;
443  return false;
444  }
445 
446  int i;
447  ++fontName;
448  for (i = 0; i < NFontFields && fontName && fontName[0]; ++i) {
449  tokens[i] = fontName;
450  for (;; ++fontName) {
451  if (*fontName == '-')
452  break;
453  if (! *fontName) {
454  fontName = 0;
455  break;
456  }
457  }
458 
459  if (fontName) *fontName++ = '\0';
460  }
461 
462  if (i < NFontFields) {
463  for (int j = i ; j < NFontFields; ++j)
464  tokens[j] = 0;
465  return false;
466  }
467 
468  return true;
469 }

◆ preferScalable()

static bool preferScalable ( const QFontDef request)
static

◆ qt_addPatternProps()

void qt_addPatternProps ( FcPattern *  pattern,
int  screen,
int  script,
const QFontDef request 
)

Definition at line 1458 of file qfontdatabase_x11.cpp.

Referenced by getFcPattern().

1459 {
1460  double size_value = qMax(qreal(1.), request.pixelSize);
1461  FcPatternDel(pattern, FC_PIXEL_SIZE);
1462  FcPatternAddDouble(pattern, FC_PIXEL_SIZE, size_value);
1463 
1464  if (X11->display && QX11Info::appDepth(screen) <= 8) {
1465  FcPatternDel(pattern, FC_ANTIALIAS);
1466  // can't do antialiasing on 8bpp
1467  FcPatternAddBool(pattern, FC_ANTIALIAS, false);
1468  } else if (request.styleStrategy & (QFont::PreferAntialias|QFont::NoAntialias)) {
1469  FcPatternDel(pattern, FC_ANTIALIAS);
1470  FcPatternAddBool(pattern, FC_ANTIALIAS,
1471  !(request.styleStrategy & QFont::NoAntialias));
1472  }
1473 
1474  if (script != QUnicodeTables::Common && *specialLanguages[script] != '\0') {
1476  FcLangSet *ls = FcLangSetCreate();
1477  FcLangSetAdd(ls, (const FcChar8*)specialLanguages[script]);
1478  FcPatternDel(pattern, FC_LANG);
1479  FcPatternAddLangSet(pattern, FC_LANG, ls);
1480  FcLangSetDestroy(ls);
1481  }
1482 
1483  if (!request.styleName.isEmpty()) {
1484  QByteArray cs = request.styleName.toUtf8();
1485  FcPatternAddString(pattern, FC_STYLE, (const FcChar8 *) cs.constData());
1486  return;
1487  }
1488 
1489  int weight_value = FC_WEIGHT_BLACK;
1490  if (request.weight == 0)
1491  weight_value = FC_WEIGHT_MEDIUM;
1492  else if (request.weight < (QFont::Light + QFont::Normal) / 2)
1493  weight_value = FC_WEIGHT_LIGHT;
1494  else if (request.weight < (QFont::Normal + QFont::DemiBold) / 2)
1495  weight_value = FC_WEIGHT_MEDIUM;
1496  else if (request.weight < (QFont::DemiBold + QFont::Bold) / 2)
1497  weight_value = FC_WEIGHT_DEMIBOLD;
1498  else if (request.weight < (QFont::Bold + QFont::Black) / 2)
1499  weight_value = FC_WEIGHT_BOLD;
1500  FcPatternDel(pattern, FC_WEIGHT);
1501  FcPatternAddInteger(pattern, FC_WEIGHT, weight_value);
1502 
1503  int slant_value = FC_SLANT_ROMAN;
1504  if (request.style == QFont::StyleItalic)
1505  slant_value = FC_SLANT_ITALIC;
1506  else if (request.style == QFont::StyleOblique)
1507  slant_value = FC_SLANT_OBLIQUE;
1508  FcPatternDel(pattern, FC_SLANT);
1509  FcPatternAddInteger(pattern, FC_SLANT, slant_value);
1510 
1511  int stretch = request.stretch;
1512  if (!stretch)
1513  stretch = 100;
1514  FcPatternDel(pattern, FC_WIDTH);
1515  FcPatternAddInteger(pattern, FC_WIDTH, stretch);
1516 }
double qreal
Definition: qglobal.h:1193
static int appDepth(int screen=-1)
Returns the color depth (bits per pixel) used by the application on the given screen.
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
uint weight
Definition: qfont_p.h:95
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
qreal pixelSize
Definition: qfont_p.h:90
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
uint style
Definition: qfont_p.h:97
QString styleName
Definition: qfont_p.h:83
uint stretch
Definition: qfont_p.h:98
#define FC_WIDTH
static const char * specialLanguages[]
uint styleStrategy
Definition: qfont_p.h:92

◆ qt_encoding_id_for_mib()

int qt_encoding_id_for_mib ( int  mib)

Definition at line 401 of file qfontdatabase_x11.cpp.

Referenced by qt_x11_set_fallback_font_family().

402 {
403  const XlfdEncoding *enc = xlfd_encoding;
404  for (; enc->name; ++enc) {
405  if (enc->mib == mib)
406  return enc->id;
407  }
408  return -1;
409 }
const char * name
int mib
static const XlfdEncoding xlfd_encoding[]

◆ qt_FcPatternToQFontDef()

QFontDef qt_FcPatternToQFontDef ( FcPattern *  pattern,
const QFontDef request 
)

Definition at line 744 of file qfontdatabase_x11.cpp.

Referenced by QFontEngineMultiFT::loadEngine(), and tryPatternLoad().

745 {
746  QFontDef fontDef;
747  fontDef.styleStrategy = request.styleStrategy;
748 
749  fontDef.hintingPreference = request.hintingPreference;
750  FcChar8 *value = 0;
751  if (FcPatternGetString(pattern, FC_FAMILY, 0, &value) == FcResultMatch) {
752  fontDef.family = QString::fromUtf8(reinterpret_cast<const char *>(value));
753  }
754 
755  double dpi;
756  if (FcPatternGetDouble(pattern, FC_DPI, 0, &dpi) != FcResultMatch) {
757  if (X11->display)
758  dpi = QX11Info::appDpiY();
759  else
760  dpi = qt_defaultDpiY();
761  }
762 
763  double size;
764  if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &size) == FcResultMatch)
765  fontDef.pixelSize = size;
766  else
767  fontDef.pixelSize = 12;
768 
769  fontDef.pointSize = qt_pointSize(fontDef.pixelSize, qRound(dpi));
770 
771  /* ###
772  fontDef.styleHint
773  */
774 
775  int weight;
776  if (FcPatternGetInteger(pattern, FC_WEIGHT, 0, &weight) != FcResultMatch)
777  weight = FC_WEIGHT_MEDIUM;
778  fontDef.weight = getFCWeight(weight);
779 
780  int slant;
781  if (FcPatternGetInteger(pattern, FC_SLANT, 0, &slant) != FcResultMatch)
782  slant = FC_SLANT_ROMAN;
783  fontDef.style = (slant == FC_SLANT_ITALIC)
785  : ((slant == FC_SLANT_OBLIQUE)
788 
789 
790  FcBool scalable;
791  if (FcPatternGetBool(pattern, FC_SCALABLE, 0, &scalable) != FcResultMatch)
792  scalable = false;
793  if (scalable) {
794  fontDef.stretch = request.stretch;
795  fontDef.style = request.style;
796  } else {
797  int width;
798  if (FcPatternGetInteger(pattern, FC_WIDTH, 0, &width) == FcResultMatch)
799  fontDef.stretch = width;
800  else
801  fontDef.stretch = 100;
802  }
803 
804  int spacing;
805  if (FcPatternGetInteger(pattern, FC_SPACING, 0, &spacing) == FcResultMatch) {
806  fontDef.fixedPitch = (spacing >= FC_MONO);
807  fontDef.ignorePitch = false;
808  } else {
809  fontDef.ignorePitch = true;
810  }
811 
812  return fontDef;
813 }
uint fixedPitch
Definition: qfont_p.h:96
double qt_pointSize(double pixelSize, int dpi)
Definition: qfont_x11.cpp:83
qreal pointSize
Definition: qfont_p.h:89
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
#define X11
Definition: qt_x11_p.h:724
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
uint weight
Definition: qfont_p.h:95
static int getFCWeight(int fc_weight)
uint ignorePitch
Definition: qfont_p.h:100
qreal pixelSize
Definition: qfont_p.h:90
uint style
Definition: qfont_p.h:97
uint stretch
Definition: qfont_p.h:98
#define FC_WIDTH
QString family
Definition: qfont_p.h:82
uint hintingPreference
Definition: qfont_p.h:101
uint styleStrategy
Definition: qfont_p.h:92
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...

◆ qt_fillFontDef() [1/2]

bool qt_fillFontDef ( const QByteArray xlfd,
QFontDef fd,
int  dpi,
QtFontDesc desc 
)

Definition at line 503 of file qfontdatabase_x11.cpp.

Referenced by loadRaw(), QFontDatabase::loadXlfd(), qt_fillFontDef(), and qt_x11_set_fallback_font_family().

504 {
505  char *tokens[NFontFields];
506  QByteArray buffer = xlfd;
507  if (! parseXFontName(buffer.data(), tokens))
508  return false;
509 
510  capitalize(tokens[Family]);
511  capitalize(tokens[Foundry]);
512 
514  fd->family = QString::fromLatin1(tokens[Family]);
515  QString foundry = QString::fromLatin1(tokens[Foundry]);
516  if (! foundry.isEmpty() && foundry != QLatin1String("*") && (!desc || desc->family->count > 1))
517  fd->family +=
518  QLatin1String(" [") + foundry + QLatin1Char(']');
519 
520  if (qstrlen(tokens[AddStyle]) > 0)
521  fd->addStyle = QString::fromLatin1(tokens[AddStyle]);
522  else
523  fd->addStyle.clear();
524 
525  fd->pointSize = atoi(tokens[PointSize])/10.;
526  fd->styleHint = QFont::AnyStyle; // ### any until we match families
527 
528  char slant = tolower((uchar) tokens[Slant][0]);
529  fd->style = (slant == 'o' ? QFont::StyleOblique : (slant == 'i' ? QFont::StyleItalic : QFont::StyleNormal));
530  char fixed = tolower((uchar) tokens[Spacing][0]);
531  fd->fixedPitch = (fixed == 'm' || fixed == 'c');
532  fd->weight = getFontWeight(QLatin1String(tokens[Weight]));
533 
534  int r = atoi(tokens[ResolutionY]);
535  fd->pixelSize = atoi(tokens[PixelSize]);
536  // not "0" or "*", or required DPI
537  if (r && fd->pixelSize && r != dpi) {
538  // calculate actual pointsize for display DPI
539  fd->pointSize = qt_pointSize(fd->pixelSize, dpi);
540  } else if (fd->pixelSize == 0 && fd->pointSize) {
541  // calculate pixel size from pointsize/dpi
542  fd->pixelSize = qRound(qt_pixelSize(fd->pointSize, dpi));
543  }
544 
545  return true;
546 }
uint fixedPitch
Definition: qfont_p.h:96
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
double qt_pointSize(double pixelSize, int dpi)
Definition: qfont_x11.cpp:83
qreal pointSize
Definition: qfont_p.h:89
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
unsigned char uchar
Definition: qglobal.h:994
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QTextStream & fixed(QTextStream &stream)
Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) on stream and returns stream...
uint weight
Definition: qfont_p.h:95
static bool parseXFontName(char *fontName, char **tokens)
qreal pixelSize
Definition: qfont_p.h:90
static int getFontWeight(const QString &weightString)
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
uint style
Definition: qfont_p.h:97
uint qstrlen(const char *str)
Definition: qbytearray.h:79
static void capitalize(char *s)
QtFontFamily * family
QString addStyle
Definition: qfont_p.h:86
QString family
Definition: qfont_p.h:82
uint styleHint
Definition: qfont_p.h:93
uint styleStrategy
Definition: qfont_p.h:92
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
double qt_pixelSize(double pointSize, int dpi)
Definition: qfont_x11.cpp:74

◆ qt_fillFontDef() [2/2]

static bool qt_fillFontDef ( XFontStruct *  fs,
QFontDef fd,
int  dpi,
QtFontDesc desc 
)
static

Definition at line 555 of file qfontdatabase_x11.cpp.

556 {
557  unsigned long value;
558  if (!fs || !XGetFontProperty(fs, XA_FONT, &value))
559  return false;
560 
561  char *n = XGetAtomName(QX11Info::display(), value);
562  QByteArray xlfd(n);
563  if (n)
564  XFree(n);
565  return qt_fillFontDef(xlfd.toLower(), fd, dpi, desc);
566 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool qt_fillFontDef(const QByteArray &xlfd, QFontDef *fd, int dpi, QtFontDesc *desc)
static Display * display()
Returns the default display for the application.

◆ qt_fontSetForPattern()

FcFontSet* qt_fontSetForPattern ( FcPattern *  pattern,
const QFontDef request 
)

Definition at line 1668 of file qfontdatabase_x11.cpp.

Referenced by QFontEngineMultiFT::loadEngine(), and loadFc().

1669 {
1670  FcResult result;
1671  FcFontSet *fs = FcFontSort(0, pattern, FcTrue, 0, &result);
1672 #ifdef FONT_MATCH_DEBUG
1673  FM_DEBUG("first font in fontset:\n");
1674  FcPatternPrint(fs->fonts[0]);
1675 #endif
1676 
1677  FcBool forceScalable = request.styleStrategy & QFont::ForceOutline;
1678 
1679  // remove fonts if they are not scalable (and should be)
1680  if (forceScalable && fs) {
1681  for (int i = 0; i < fs->nfont; ++i) {
1682  FcPattern *font = fs->fonts[i];
1683  FcResult res;
1684  FcBool scalable;
1685  res = FcPatternGetBool(font, FC_SCALABLE, 0, &scalable);
1686  if (res != FcResultMatch || !scalable) {
1687  FcFontSetRemove(fs, i);
1688 #ifdef FONT_MATCH_DEBUG
1689  FM_DEBUG("removing pattern:");
1690  FcPatternPrint(font);
1691 #endif
1692  --i; // go back one
1693  }
1694  }
1695  }
1696 
1697  FM_DEBUG("final pattern contains %d fonts\n", fs->nfont);
1698 
1699  return fs;
1700 }
#define FM_DEBUG
static void FcFontSetRemove(FcFontSet *fs, int at)
uint styleStrategy
Definition: qfont_p.h:92

◆ qt_mib_for_xlfd_encoding()

int qt_mib_for_xlfd_encoding ( const char *  encoding)

Definition at line 394 of file qfontdatabase_x11.cpp.

Referenced by fontFile().

395 {
396  int id = qt_xlfd_encoding_id(encoding);
397  if (id != -1) return xlfd_encoding[id].mib;
398  return 0;
399 }
int qt_xlfd_encoding_id(const char *encoding)
static const XlfdEncoding xlfd_encoding[]

◆ qt_pixelSize()

double qt_pixelSize ( double  pointSize,
int  dpi 
)

Definition at line 74 of file qfont_x11.cpp.

Referenced by QFontDatabase::loadXlfd(), and qt_fillFontDef().

75 {
76  if (pointSize < 0)
77  return -1.;
78  if (dpi == 75) // the stupid 75 dpi setting on X11
79  dpi = 72;
80  return (pointSize * dpi) /72.;
81 }
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90

◆ qt_pointSize()

double qt_pointSize ( double  pixelSize,
int  dpi 
)

Definition at line 83 of file qfont_x11.cpp.

Referenced by QFontDatabase::loadXlfd(), qt_FcPatternToQFontDef(), and qt_fillFontDef().

84 {
85  if (pixelSize < 0)
86  return -1.;
87  if (dpi == 75) // the stupid 75 dpi setting on X11
88  dpi = 72;
89  return pixelSize * 72. / ((double) dpi);
90 }
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80

◆ qt_xlfd_encoding_id()

int qt_xlfd_encoding_id ( const char *  encoding)

Definition at line 350 of file qfontdatabase_x11.cpp.

Referenced by fontFile(), loadXlfds(), and qt_mib_for_xlfd_encoding().

351 {
352  // qDebug("looking for encoding id for '%s'", encoding);
353  int len = strlen(encoding);
354  if (len < 4)
355  return -1;
356  unsigned int hash1 = make_tag(encoding[0], encoding[1], encoding[2], encoding[3]);
357  const char *ch = encoding + len - 4;
358  unsigned int hash2 = make_tag(ch[0], ch[1], ch[2], ch[3]);
359 
360  const XlfdEncoding *enc = xlfd_encoding;
361  for (; enc->name; ++enc) {
362  if ((enc->hash1 && enc->hash1 != hash1) ||
363  (enc->hash2 && enc->hash2 != hash2))
364  continue;
365  // hashes match, do a compare if strings match
366  // the enc->name can contain '*'s we have to interpret correctly
367  const char *n = enc->name;
368  const char *e = encoding;
369  while (1) {
370  // qDebug("bol: *e='%c', *n='%c'", *e, *n);
371  if (*e == '\0') {
372  if (*n)
373  break;
374  // qDebug("found encoding id %d", enc->id);
375  return enc->id;
376  }
377  if (*e == *n) {
378  ++e;
379  ++n;
380  continue;
381  }
382  if (*n != '*')
383  break;
384  ++n;
385  // qDebug("skip: *e='%c', *n='%c'", *e, *n);
386  while (*e && *e != *n)
387  ++e;
388  }
389  }
390  // qDebug("couldn't find encoding %s", encoding);
391  return -1;
392 }
unsigned int hash1
const char * name
#define make_tag(c1, c2, c3, c4)
static const XlfdEncoding xlfd_encoding[]
unsigned int hash2

◆ queryFont()

static FcPattern* queryFont ( const FcChar8 *  file,
const QByteArray data,
int  id,
FcBlanks *  blanks,
int *  count 
)
static

Definition at line 1749 of file qfontdatabase_x11.cpp.

Referenced by registerFont().

1750 {
1751 #if FC_VERSION < 20402
1752  Q_UNUSED(data)
1753  return FcFreeTypeQuery(file, id, blanks, count);
1754 #else
1755  if (data.isEmpty())
1756  return FcFreeTypeQuery(file, id, blanks, count);
1757 
1758  extern FT_Library qt_getFreetype();
1759  FT_Library lib = qt_getFreetype();
1760 
1761  FcPattern *pattern = 0;
1762 
1763  FT_Face face;
1764  if (!FT_New_Memory_Face(lib, (const FT_Byte *)data.constData(), data.size(), id, &face)) {
1765  *count = face->num_faces;
1766 
1767  pattern = FcFreeTypeQueryFace(face, file, id, blanks);
1768 
1769  FT_Done_Face(face);
1770  }
1771 
1772  return pattern;
1773 #endif
1774 }
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
FT_Library qt_getFreetype()
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ registerFont()

static void registerFont ( QFontDatabasePrivate::ApplicationFont fnt)
static

Definition at line 2009 of file qfontdatabase_x11.cpp.

Referenced by checkSymbolFonts(), and initializeDb().

2010 {
2011 #if defined(QT_NO_FONTCONFIG)
2012  return;
2013 #else
2014  if (!X11->has_fontconfig)
2015  return;
2016 
2017  FcConfig *config = FcConfigGetCurrent();
2018  if (!config)
2019  return;
2020 
2021  FcFontSet *set = FcConfigGetFonts(config, FcSetApplication);
2022  if (!set) {
2023  FcConfigAppFontAddFile(config, (const FcChar8 *)":/non-existent");
2024  set = FcConfigGetFonts(config, FcSetApplication); // try again
2025  if (!set)
2026  return;
2027  }
2028 
2029  QString fileNameForQuery = fnt->fileName;
2030 #if FC_VERSION < 20402
2031  QTemporaryFile tmp;
2032 
2033  if (!fnt->data.isEmpty()) {
2034  if (!tmp.open())
2035  return;
2036  tmp.write(fnt->data);
2037  tmp.flush();
2038  fileNameForQuery = tmp.fileName();
2039  }
2040 #endif
2041 
2042  int id = 0;
2043  FcBlanks *blanks = FcConfigGetBlanks(0);
2044  int count = 0;
2045 
2046  QStringList families;
2047  QFontDatabasePrivate *db = privateDb();
2048 
2049  FcPattern *pattern = 0;
2050  do {
2051  pattern = queryFont((const FcChar8 *)QFile::encodeName(fileNameForQuery).constData(),
2052  fnt->data, id, blanks, &count);
2053  if (!pattern)
2054  return;
2055 
2056  FcPatternDel(pattern, FC_FILE);
2057  QByteArray cs = fnt->fileName.toUtf8();
2058  FcPatternAddString(pattern, FC_FILE, (const FcChar8 *) cs.constData());
2059 
2060  FcChar8 *fam = 0, *familylang = 0;
2061  int i, n = 0;
2062  for (i = 0; ; i++) {
2063  if (FcPatternGetString(pattern, FC_FAMILYLANG, i, &familylang) != FcResultMatch)
2064  break;
2065  QString familyLang = QString::fromUtf8((const char *) familylang);
2066  if (familyLang.compare(db->systemLang, Qt::CaseInsensitive) == 0) {
2067  n = i;
2068  break;
2069  }
2070  }
2071 
2072  if (FcPatternGetString(pattern, FC_FAMILY, n, &fam) == FcResultMatch) {
2073  QString family = QString::fromUtf8(reinterpret_cast<const char *>(fam));
2074  families << family;
2075  }
2076 
2077  if (!FcFontSetAdd(set, pattern))
2078  return;
2079 
2080  ++id;
2081  } while (pattern && id < count);
2082 
2083  fnt->families = families;
2084 #endif
2085 }
#define FC_FAMILYLANG
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QTemporaryFile class is an I/O device that operates on temporary files.
static FcPattern * queryFont(const FcChar8 *file, const QByteArray &data, int id, FcBlanks *blanks, int *count)
bool open()
A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, this allows easy access to the d...
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define X11
Definition: qt_x11_p.h:724
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool flush()
Flushes any buffered data to the file.
Definition: qfile.cpp:1645
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int compare(const QString &s) const
Definition: qstring.cpp:5037
QString fileName() const
Returns the complete unique filename backing the QTemporaryFile object.
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ styleHint()

static const char* styleHint ( const QFontDef request)
static

Definition at line 1435 of file qfontdatabase_x11.cpp.

Referenced by getFcPattern(), and QFontDatabase::loadXlfd().

1436 {
1437  const char *stylehint = 0;
1438  switch (request.styleHint) {
1439  case QFont::SansSerif:
1440  stylehint = "sans-serif";
1441  break;
1442  case QFont::Serif:
1443  stylehint = "serif";
1444  break;
1445  case QFont::TypeWriter:
1446  stylehint = "monospace";
1447  break;
1448  default:
1449  if (request.fixedPitch)
1450  stylehint = "monospace";
1451  break;
1452  }
1453  return stylehint;
1454 }
uint fixedPitch
Definition: qfont_p.h:96
uint styleHint
Definition: qfont_p.h:93

◆ tryPatternLoad()

static QFontEngine* tryPatternLoad ( FcPattern *  match,
int  screen,
const QFontDef request,
int  script 
)
static

Definition at line 1613 of file qfontdatabase_x11.cpp.

Referenced by loadFc().

1615 {
1616 #ifdef FONT_MATCH_DEBUG
1617  FcChar8 *fam;
1618  FcPatternGetString(match, FC_FAMILY, 0, &fam);
1619  FM_DEBUG("==== trying %s\n", fam);
1620 #endif
1621  FM_DEBUG("passes charset test\n");
1622 
1623  QFontEngineX11FT *engine = 0;
1624  if (!match) // probably no fonts available.
1625  goto done;
1626 
1627  if (script != QUnicodeTables::Common) {
1628  // skip font if it doesn't support the language we want
1629  if (specialChars[script]) {
1630  // need to check the charset, as the langset doesn't work for these scripts
1631  FcCharSet *cs;
1632  if (FcPatternGetCharSet(match, FC_CHARSET, 0, &cs) != FcResultMatch)
1633  goto done;
1634  if (!FcCharSetHasChar(cs, specialChars[script]))
1635  goto done;
1636  } else if (*specialLanguages[script] != '\0'){
1637  FcLangSet *langSet = 0;
1638  if (FcPatternGetLangSet(match, FC_LANG, 0, &langSet) != FcResultMatch)
1639  goto done;
1640  if (FcLangSetHasLang(langSet, (const FcChar8*)specialLanguages[script]) != FcLangEqual)
1641  goto done;
1642  }
1643  }
1644 
1645  // enforce non-antialiasing if requested. the ft font engine looks at this property.
1646  if (request.styleStrategy & QFont::NoAntialias) {
1647  FcPatternDel(match, FC_ANTIALIAS);
1648  FcPatternAddBool(match, FC_ANTIALIAS, false);
1649  }
1650 
1651  engine = new QFontEngineX11FT(match, qt_FcPatternToQFontDef(match, request), screen);
1652  if (engine->invalid()) {
1653  FM_DEBUG(" --> invalid!\n");
1654  delete engine;
1655  engine = 0;
1656  } else if (scriptRequiresOpenType(script)) {
1657  HB_Face hbFace = engine->harfbuzzFace();
1658  if (!hbFace || !hbFace->supported_scripts[script]) {
1659  FM_DEBUG(" OpenType support missing for script\n");
1660  delete engine;
1661  engine = 0;
1662  }
1663  }
1664 done:
1665  return engine;
1666 }
QFontDef qt_FcPatternToQFontDef(FcPattern *pattern, const QFontDef &request)
static bool match(const uchar *found, const char *target, uint len)
static const ushort specialChars[]
#define FM_DEBUG
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
static bool scriptRequiresOpenType(int script)
static const char * specialLanguages[]
bool invalid() const
uint styleStrategy
Definition: qfont_p.h:92
HB_Face harfbuzzFace() const

◆ xlfd_for_id()

static const char* xlfd_for_id ( int  id)
static

Definition at line 411 of file qfontdatabase_x11.cpp.

Referenced by initializeDb(), QFontDatabase::loadXlfd(), and loadXlfds().

412 {
413  // special case: -1 returns the "*-*" encoding, allowing us to do full
414  // database population in a single X server round trip.
415  if (id < 0 || id > numEncodings)
416  return "*-*";
417  return xlfd_encoding[id].name;
418 }
const int numEncodings
const char * name
static const XlfdEncoding xlfd_encoding[]

Variable Documentation

◆ encodingLoaded

unsigned char encodingLoaded[numEncodings]
static

Definition at line 607 of file qfontdatabase_x11.cpp.

◆ languageForWritingSystem

const char* languageForWritingSystem[]
static

Definition at line 881 of file qfontdatabase_x11.cpp.

Referenced by initializeDb(), and initWritingSystems().

◆ numEncodings

const int numEncodings = sizeof(xlfd_encoding) / sizeof(XlfdEncoding) - 1

Definition at line 348 of file qfontdatabase_x11.cpp.

Referenced by load(), and xlfd_for_id().

◆ openType

const char* openType[]
static

Definition at line 962 of file qfontdatabase_x11.cpp.

◆ qt_is_gui_used

bool qt_is_gui_used

◆ sampleCharForWritingSystem

const ushort sampleCharForWritingSystem[]
static

Definition at line 921 of file qfontdatabase_x11.cpp.

◆ specialChars

const ushort specialChars[]
static
Initial value:
= {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0xc15,
0xc95,
0xd15,
0xd9a,
0,
0,
0,
0x1000,
0,
0,
0x1681,
0x16a0,
0,
0x7ca
}

Definition at line 847 of file qfontdatabase_x11.cpp.

◆ specialLanguages

const char* specialLanguages[]
static
Initial value:
= {
"en",
"el",
"ru",
"hy",
"he",
"ar",
"syr",
"div",
"hi",
"bn",
"pa",
"gu",
"or",
"ta",
"te",
"kn",
"ml",
"si",
"th",
"lo",
"bo",
"my",
"ka",
"ko",
"",
"",
"km",
""
}

Definition at line 815 of file qfontdatabase_x11.cpp.

◆ writingSystems_for_xlfd_encoding

const char writingSystems_for_xlfd_encoding[sizeof(xlfd_encoding)][QFontDatabase::WritingSystemsCount]
static

Definition at line 156 of file qfontdatabase_x11.cpp.

Referenced by findEncoding(), load(), and loadXlfds().

◆ xlfd_encoding

const XlfdEncoding xlfd_encoding[]
static

◆ xlfdsFullyLoaded

bool xlfdsFullyLoaded = false
static

Definition at line 606 of file qfontdatabase_x11.cpp.