Qt 4.8
qfontdatabase.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qdir.h>
43 #include "qfontdatabase.h"
44 #include "qdebug.h"
45 #include "qalgorithms.h"
46 #include "qapplication.h"
47 #include "qvarlengtharray.h" // here or earlier - workaround for VC++6
48 #include "qthread.h"
49 #include "qmutex.h"
50 #include "private/qunicodetables_p.h"
51 #include "qfontengine_p.h"
52 
53 #ifdef Q_WS_QPA
54 #include <QtGui/private/qapplication_p.h>
55 #include <QtGui/qplatformfontdatabase_qpa.h>
56 #include "qabstractfileengine.h"
57 #endif
58 
59 #ifdef Q_WS_X11
60 #include <locale.h>
61 #endif
62 #include <stdlib.h>
63 #include <limits.h>
64 
65 #if (defined(Q_WS_QWS)|| defined(Q_OS_SYMBIAN)) && !defined(QT_NO_FREETYPE)
66 # include <ft2build.h>
67 # include FT_TRUETYPE_TABLES_H
68 #endif
69 
70 // #define QFONTDATABASE_DEBUG
71 #ifdef QFONTDATABASE_DEBUG
72 # define FD_DEBUG qDebug
73 #else
74 # define FD_DEBUG if (false) qDebug
75 #endif
76 
77 // #define FONT_MATCH_DEBUG
78 #ifdef FONT_MATCH_DEBUG
79 # define FM_DEBUG qDebug
80 #else
81 # define FM_DEBUG if (false) qDebug
82 #endif
83 
84 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECTWRITE)
85 # include <dwrite.h>
86 #endif
87 
89 
90 #define SMOOTH_SCALABLE 0xffff
91 
92 bool qt_enable_test_font = false;
93 
94 static QString styleStringHelper(int weight, QFont::Style style);
95 
97 {
98  qt_enable_test_font = value;
99 }
100 
101 static int getFontWeight(const QString &weightString)
102 {
103  QString s = weightString.toLower();
104 
105  // Test in decreasing order of commonness
106  if (s == QLatin1String("medium") ||
107  s == QLatin1String("normal")
108  || s.compare(QApplication::translate("QFontDatabase", "Normal"), Qt::CaseInsensitive) == 0)
109  return QFont::Normal;
110  if (s == QLatin1String("bold")
111  || s.compare(QApplication::translate("QFontDatabase", "Bold"), Qt::CaseInsensitive) == 0)
112  return QFont::Bold;
113  if (s == QLatin1String("demibold") || s == QLatin1String("demi bold")
114  || s.compare(QApplication::translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0)
115  return QFont::DemiBold;
116  if (s == QLatin1String("black")
117  || s.compare(QApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
118  return QFont::Black;
119  if (s == QLatin1String("light"))
120  return QFont::Light;
121 
122  if (s.contains(QLatin1String("bold"))
123  || s.contains(QApplication::translate("QFontDatabase", "Bold"), Qt::CaseInsensitive)) {
124  if (s.contains(QLatin1String("demi"))
125  || s.compare(QApplication::translate("QFontDatabase", "Demi"), Qt::CaseInsensitive) == 0)
126  return (int) QFont::DemiBold;
127  return (int) QFont::Bold;
128  }
129 
130  if (s.contains(QLatin1String("light"))
131  || s.compare(QApplication::translate("QFontDatabase", "Light"), Qt::CaseInsensitive) == 0)
132  return (int) QFont::Light;
133 
134  if (s.contains(QLatin1String("black"))
135  || s.compare(QApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
136  return (int) QFont::Black;
137 
138  return (int) QFont::Normal;
139 }
140 
141 // convert 0 ~ 1000 integer to QFont::Weight
143 {
144  if (weight < 400)
145  return QFont::Light;
146  else if (weight < 600)
147  return QFont::Normal;
148  else if (weight < 700)
149  return QFont::DemiBold;
150  else if (weight < 800)
151  return QFont::Bold;
152  else
153  return QFont::Black;
154 }
155 
157 {
158  signed int encoding : 16;
159 
160  uint xpoint : 16;
161  uint xres : 8;
162  uint yres : 8;
165 };
166 
168 {
169 #ifdef Q_WS_X11
171  QtFontEncoding *encodingID(int id, uint xpoint = 0, uint xres = 0,
172  uint yres = 0, uint avgwidth = 0, bool add = false);
173  unsigned short count : 16;
174 #endif // Q_WS_X11
175 
176 #if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
179 #endif // defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_OS_SYMBIAN)
180 #if defined(Q_WS_QPA)
181  void *handle;
182 #endif
183 
184  unsigned short pixelSize : 16;
185 };
186 
187 
188 #ifdef Q_WS_X11
190  uint yres, uint avgwidth, bool add)
191 {
192  // we don't match using the xpoint, xres and yres parameters, only the id
193  for (int i = 0; i < count; ++i) {
194  if (encodings[i].encoding == id)
195  return encodings + i;
196  }
197 
198  if (!add) return 0;
199 
200  if (!(count % 4)) {
201  QtFontEncoding *newEncodings = (QtFontEncoding *)
202  realloc(encodings,
203  (((count+4) >> 2) << 2) * sizeof(QtFontEncoding));
204  Q_CHECK_PTR(newEncodings);
205  encodings = newEncodings;
206  }
207  encodings[count].encoding = id;
208  encodings[count].xpoint = xpoint;
209  encodings[count].xres = xres;
210  encodings[count].yres = yres;
211  encodings[count].avgwidth = avgwidth;
212  encodings[count].pitch = '*';
213  return encodings + count++;
214 }
215 #endif // Q_WS_X11
216 
218 {
219  struct Key {
220  Key(const QString &styleString);
221  Key() : style(QFont::StyleNormal),
222  weight(QFont::Normal), stretch(0) { }
223  Key(const Key &o) : style(o.style), weight(o.weight), stretch(o.stretch) { }
224  uint style : 2;
225  signed int weight : 8;
226  signed int stretch : 12;
227 
228  bool operator==(const Key & other) {
229  return (style == other.style && weight == other.weight &&
230  (stretch == 0 || other.stretch == 0 || stretch == other.stretch));
231  }
232  bool operator!=(const Key &other) {
233  return !operator==(other);
234  }
235  bool operator <(const Key &o) {
236  int x = (style << 12) + (weight << 14) + stretch;
237  int y = (o.style << 12) + (o.weight << 14) + o.stretch;
238  return (x < y);
239  }
240  };
241 
242  QtFontStyle(const Key &k)
243  : key(k), bitmapScalable(false), smoothScalable(false),
244  count(0), pixelSizes(0)
245  {
246 #if defined(Q_WS_X11)
247  weightName = setwidthName = 0;
248 #endif // Q_WS_X11
249  }
250 
252 #ifdef Q_WS_X11
253  delete [] weightName;
254  delete [] setwidthName;
255 #endif
256 #if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_OS_SYMBIAN)
257  while (count) {
258  // bitfield count-- in while condition does not work correctly in mwccsym2
259  count--;
260 #ifdef Q_WS_X11
261  free(pixelSizes[count].encodings);
262 #endif
263 #if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
264  pixelSizes[count].fileName.~QByteArray();
265 #endif
266 #if defined (Q_WS_QPA)
267  QPlatformIntegration *integration = QApplicationPrivate::platformIntegration();
268  if (integration) { //on shut down there will be some that we don't release.
269  integration->fontDatabase()->releaseHandle(pixelSizes[count].handle);
270  }
271 #endif
272  }
273 #endif
274  free(pixelSizes);
275  }
276 
278  bool bitmapScalable : 1;
279  bool smoothScalable : 1;
280  signed int count : 30;
283 
284 #ifdef Q_WS_X11
285  const char *weightName;
286  const char *setwidthName;
287 #endif // Q_WS_X11
288 #if defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_OS_SYMBIAN)
290 #endif
291 
292  QtFontSize *pixelSize(unsigned short size, bool = false);
293 };
294 
295 QtFontStyle::Key::Key(const QString &styleString)
296  : style(QFont::StyleNormal), weight(QFont::Normal), stretch(0)
297 {
298  weight = getFontWeight(styleString);
299 
300  if (styleString.contains(QLatin1String("Italic"))
301  || styleString.contains(QApplication::translate("QFontDatabase", "Italic")))
303  else if (styleString.contains(QLatin1String("Oblique"))
304  || styleString.contains(QApplication::translate("QFontDatabase", "Oblique")))
306 }
307 
308 QtFontSize *QtFontStyle::pixelSize(unsigned short size, bool add)
309 {
310  for (int i = 0; i < count; i++) {
311  if (pixelSizes[i].pixelSize == size)
312  return pixelSizes + i;
313  }
314  if (!add)
315  return 0;
316 
317  if (!pixelSizes) {
318  // Most style have only one font size, we avoid waisting memory
319  QtFontSize *newPixelSizes = (QtFontSize *)malloc(sizeof(QtFontSize));
320  Q_CHECK_PTR(newPixelSizes);
321  pixelSizes = newPixelSizes;
322  } else if (!(count % 8) || count == 1) {
323  QtFontSize *newPixelSizes = (QtFontSize *)
324  realloc(pixelSizes,
325  (((count+8) >> 3) << 3) * sizeof(QtFontSize));
326  Q_CHECK_PTR(newPixelSizes);
327  pixelSizes = newPixelSizes;
328  }
329  pixelSizes[count].pixelSize = size;
330 #ifdef Q_WS_X11
331  pixelSizes[count].count = 0;
333 #endif
334 #if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
337 #endif
338 #if defined(Q_WS_QPA)
339  pixelSizes[count].handle = 0;
340 #endif
341  return pixelSizes + (count++);
342 }
343 
345 {
346  QtFontFoundry(const QString &n) : name(n), count(0), styles(0) {}
348  while (count--)
349  delete styles[count];
350  free(styles);
351  }
352 
354 
355  int count;
357  QtFontStyle *style(const QtFontStyle::Key &, const QString & = QString(), bool = false);
358 };
359 
361 {
362  int pos = 0;
363  for (; pos < count; pos++) {
364  bool hasStyleName = !styleName.isEmpty(); // search styleName first if available
365  if (hasStyleName && !styles[pos]->styleName.isEmpty()) {
366  if (styles[pos]->styleName == styleName)
367  return styles[pos];
368  } else {
369  if (styles[pos]->key == key)
370  return styles[pos];
371  }
372  }
373  if (!create)
374  return 0;
375 
376  // qDebug("adding key (weight=%d, style=%d, stretch=%d) at %d", key.weight, key.style, key.stretch, pos);
377  if (!(count % 8)) {
378  QtFontStyle **newStyles = (QtFontStyle **)
379  realloc(styles, (((count+8) >> 3) << 3) * sizeof(QtFontStyle *));
380  Q_CHECK_PTR(newStyles);
381  styles = newStyles;
382  }
383 
384  QtFontStyle *style = new QtFontStyle(key);
385  style->styleName = styleName;
386  styles[pos] = style;
387  count++;
388  return styles[pos];
389 }
390 
392 {
394  Unknown = 0,
395  Supported = 1,
396  UnsupportedFT = 2,
397  UnsupportedXLFD = 4,
398  Unsupported = UnsupportedFT | UnsupportedXLFD
399  };
400 
402  :
403 #ifdef Q_WS_X11
404  fixedPitch(true), ftWritingSystemCheck(false),
405  xlfdLoaded(false), synthetic(false), symbol_checked(false),
406 #else
407  fixedPitch(false),
408 #endif
409 #ifdef Q_WS_WIN
410  writingSystemCheck(false),
411  loaded(false),
412 #endif
413 #if !defined(QWS) && defined(Q_OS_MAC)
414  fixedPitchComputed(false),
415 #endif
416  name(n), count(0), foundries(0)
417 #if defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
418  , bogusWritingSystems(false)
419 #endif
420 #if defined(Q_WS_QPA)
421  , askedForFallback(false)
422 #endif
423  {
424  memset(writingSystems, 0, sizeof(writingSystems));
425  }
427  while (count--)
428  delete foundries[count];
429  free(foundries);
430  }
431 
432  bool fixedPitch : 1;
433 #ifdef Q_WS_X11
435  bool xlfdLoaded : 1;
436  bool synthetic : 1;
437 #endif
438 #ifdef Q_WS_WIN
440  bool loaded : 1;
441 #endif
442 #if !defined(QWS) && defined(Q_OS_MAC)
444 #endif
445 #ifdef Q_WS_X11
446  bool symbol_checked : 1;
447 #endif
448 
450 #if defined(Q_WS_X11) || defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
453 #endif
454 #ifdef Q_WS_WIN
456 #endif
457  int count;
459 
460 #if defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
463 #endif
464 #if defined (Q_WS_QPA)
465  bool askedForFallback;
466 #endif
467  unsigned char writingSystems[QFontDatabase::WritingSystemsCount];
468 
469  QtFontFoundry *foundry(const QString &f, bool = false);
470 };
471 
472 #if !defined(QWS) && defined(Q_OS_MAC)
473 inline static void qt_mac_get_fixed_pitch(QtFontFamily *f)
474 {
475  if(f && !f->fixedPitchComputed) {
476  QFontMetrics fm(f->name);
477  f->fixedPitch = fm.width(QLatin1Char('i')) == fm.width(QLatin1Char('m'));
478  f->fixedPitchComputed = true;
479  }
480 }
481 #endif
482 
483 
485 {
486  if (f.isNull() && count == 1)
487  return foundries[0];
488 
489  for (int i = 0; i < count; i++) {
490  if (foundries[i]->name.compare(f, Qt::CaseInsensitive) == 0)
491  return foundries[i];
492  }
493  if (!create)
494  return 0;
495 
496  if (!(count % 8)) {
497  QtFontFoundry **newFoundries = (QtFontFoundry **)
498  realloc(foundries,
499  (((count+8) >> 3) << 3) * sizeof(QtFontFoundry *));
500  Q_CHECK_PTR(newFoundries);
501  foundries = newFoundries;
502  }
503 
504  foundries[count] = new QtFontFoundry(f);
505  return foundries[count++];
506 }
507 
508 // ### copied to tools/makeqpf/qpf2.cpp
509 
510 // see the Unicode subset bitfields in the MSDN docs
512  // Any,
513  { 127, 127 },
514  // Latin,
515  { 0, 127 },
516  // Greek,
517  { 7, 127 },
518  // Cyrillic,
519  { 9, 127 },
520  // Armenian,
521  { 10, 127 },
522  // Hebrew,
523  { 11, 127 },
524  // Arabic,
525  { 13, 127 },
526  // Syriac,
527  { 71, 127 },
528  //Thaana,
529  { 72, 127 },
530  //Devanagari,
531  { 15, 127 },
532  //Bengali,
533  { 16, 127 },
534  //Gurmukhi,
535  { 17, 127 },
536  //Gujarati,
537  { 18, 127 },
538  //Oriya,
539  { 19, 127 },
540  //Tamil,
541  { 20, 127 },
542  //Telugu,
543  { 21, 127 },
544  //Kannada,
545  { 22, 127 },
546  //Malayalam,
547  { 23, 127 },
548  //Sinhala,
549  { 73, 127 },
550  //Thai,
551  { 24, 127 },
552  //Lao,
553  { 25, 127 },
554  //Tibetan,
555  { 70, 127 },
556  //Myanmar,
557  { 74, 127 },
558  // Georgian,
559  { 26, 127 },
560  // Khmer,
561  { 80, 127 },
562  // SimplifiedChinese,
563  { 126, 127 },
564  // TraditionalChinese,
565  { 126, 127 },
566  // Japanese,
567  { 126, 127 },
568  // Korean,
569  { 56, 127 },
570  // Vietnamese,
571  { 0, 127 }, // same as latin1
572  // Other,
573  { 126, 127 },
574  // Ogham,
575  { 78, 127 },
576  // Runic,
577  { 79, 127 },
578  // Nko,
579  { 14, 127 },
580 };
581 
582 #define SimplifiedChineseCsbBit 18
583 #define TraditionalChineseCsbBit 20
584 #define JapaneseCsbBit 17
585 #define KoreanCsbBit 21
586 
588 {
590  bool hasScript = false;
591 
592  int i;
593  for(i = 0; i < QFontDatabase::WritingSystemsCount; i++) {
594  int bit = requiredUnicodeBits[i][0];
595  int index = bit/32;
596  int flag = 1 << (bit&31);
597  if (bit != 126 && unicodeRange[index] & flag) {
598  bit = requiredUnicodeBits[i][1];
599  index = bit/32;
600 
601  flag = 1 << (bit&31);
602  if (bit == 127 || unicodeRange[index] & flag) {
603  writingSystems.append(QFontDatabase::WritingSystem(i));
604  hasScript = true;
605  // qDebug("font %s: index=%d, flag=%8x supports script %d", familyName.latin1(), index, flag, i);
606  }
607  }
608  }
609  if(codePageRange[0] & (1 << SimplifiedChineseCsbBit)) {
611  hasScript = true;
612  //qDebug("font %s supports Simplified Chinese", familyName.latin1());
613  }
614  if(codePageRange[0] & (1 << TraditionalChineseCsbBit)) {
616  hasScript = true;
617  //qDebug("font %s supports Traditional Chinese", familyName.latin1());
618  }
619  if(codePageRange[0] & (1 << JapaneseCsbBit)) {
620  writingSystems.append(QFontDatabase::Japanese);
621  hasScript = true;
622  //qDebug("font %s supports Japanese", familyName.latin1());
623  }
624  if(codePageRange[0] & (1 << KoreanCsbBit)) {
625  writingSystems.append(QFontDatabase::Korean);
626  hasScript = true;
627  //qDebug("font %s supports Korean", familyName.latin1());
628  }
629  if (!hasScript)
630  writingSystems.append(QFontDatabase::Symbol);
631 
632  return writingSystems;
633 }
634 
635 #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
636 // class with virtual destructor, derived in qfontdatabase_s60.cpp
637 class QSymbianFontDatabaseExtras
638 {
639 public:
640  virtual ~QSymbianFontDatabaseExtras() {}
641 };
642 #endif
643 
645 {
646 public:
648  : count(0), families(0), reregisterAppFonts(false)
649 #if defined(Q_WS_QWS)
650  , stream(0)
651 #endif
652 #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
653  , symbianExtras(0)
654 #endif
655 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECTWRITE)
656  , directWriteFactory(0)
657  , directWriteGdiInterop(0)
658 #endif
659  { }
660 
662  free();
663 #if defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
664  if (symbianExtras)
665  delete symbianExtras;
666 #endif
667 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECTWRITE)
668  if (directWriteGdiInterop)
669  directWriteGdiInterop->Release();
670  if (directWriteFactory != 0)
671  directWriteFactory->Release();
672 #endif
673  }
674  QtFontFamily *family(const QString &f, bool = false);
675  void free() {
676  while (count--)
677  delete families[count];
678  ::free(families);
679  families = 0;
680  count = 0;
681  // don't clear the memory fonts!
682  }
683 
684  int count;
685 #if defined(Q_WS_X11) && !defined(QT_NO_FONTCONFIG)
687 #endif
689 
690 #if defined(Q_WS_WIN) && !defined(QT_NO_DIRECTWRITE)
691  IDWriteFactory *directWriteFactory;
692  IDWriteGdiInterop *directWriteGdiInterop;
693 #endif
694 
695 
699 #if defined(Q_OS_WIN)
703 #elif defined(Q_WS_MAC)
704  ATSFontContainerRef handle;
705 #elif defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
706  QString temporaryFileName;
707  TInt screenDeviceFontFileId;
708  TUid fontStoreFontFileUid;
709 #endif
711  };
713  int addAppFont(const QByteArray &fontData, const QString &fileName);
715  bool isApplicationFont(const QString &fileName);
716 
717  void invalidate();
718 
719 #if defined(Q_WS_QWS)
720  bool loadFromCache(const QString &fontPath);
721  void addQPF2File(const QByteArray &file);
722 #endif // Q_WS_QWS
723 #if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
724  void addFont(const QString &familyname, const char *foundryname, int weight,
725  bool italic, int pixelSize, const QByteArray &file, int fileIndex,
726  bool antialiased,
728 #ifndef QT_NO_FREETYPE
729  QStringList addTTFile(const QByteArray &file, const QByteArray &fontData = QByteArray());
730 #endif // QT_NO_FREETYPE
731 #endif
732 #if defined(Q_WS_QWS)
734 #elif defined(Q_OS_SYMBIAN) && defined(QT_NO_FREETYPE)
735  QSymbianFontDatabaseExtras *symbianExtras;
736 #endif
737 #if defined(Q_WS_QWS) || defined(Q_WS_QPA)
739 #endif
740 };
741 
743 {
745  free();
746  emit static_cast<QApplication *>(QApplication::instance())->fontDatabaseChanged();
747 }
748 
750 {
751  int low = 0;
752  int high = count;
753  int pos = count / 2;
754  int res = 1;
755  if (count) {
756  while ((res = families[pos]->name.compare(f, Qt::CaseInsensitive)) && pos != low) {
757  if (res > 0)
758  high = pos;
759  else
760  low = pos;
761  pos = (high + low) / 2;
762  }
763  if (!res)
764  return families[pos];
765  }
766  if (!create)
767  return 0;
768 
769  if (res < 0)
770  pos++;
771 
772  // qDebug() << "adding family " << f.toLatin1() << " at " << pos << " total=" << count;
773  if (!(count % 8)) {
774  QtFontFamily **newFamilies = (QtFontFamily **)
775  realloc(families,
776  (((count+8) >> 3) << 3) * sizeof(QtFontFamily *));
777  Q_CHECK_PTR(newFamilies);
778  families = newFamilies;
779  }
780 
781  QtFontFamily *family = new QtFontFamily(f);
782  memmove(families + pos + 1, families + pos, (count-pos)*sizeof(QtFontFamily *));
783  families[pos] = family;
784  count++;
785  return families[pos];
786 }
787 
788 #if defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
789 void QFontDatabasePrivate::addFont(const QString &familyname, const char *foundryname, int weight, bool italic, int pixelSize,
790  const QByteArray &file, int fileIndex, bool antialiased,
791  const QList<QFontDatabase::WritingSystem> &writingSystems)
792 {
793 // qDebug() << "Adding font" << familyname << weight << italic << pixelSize << file << fileIndex << antialiased;
794  QtFontStyle::Key styleKey;
795  styleKey.style = italic ? QFont::StyleItalic : QFont::StyleNormal;
796  styleKey.weight = weight;
797  styleKey.stretch = 100;
798  QtFontFamily *f = family(familyname, true);
799 
800  if (writingSystems.isEmpty()) {
801  for (int ws = 1; ws < QFontDatabase::WritingSystemsCount; ++ws) {
803  }
804  f->bogusWritingSystems = true;
805  } else {
806  for (int i = 0; i < writingSystems.count(); ++i) {
807  f->writingSystems[writingSystems.at(i)] = QtFontFamily::Supported;
808  }
809  }
810 
811  QtFontFoundry *foundry = f->foundry(QString::fromLatin1(foundryname), true);
812  QtFontStyle *style = foundry->style(styleKey, QString(), true);
813  style->smoothScalable = (pixelSize == 0);
814  style->antialiased = antialiased;
815  QtFontSize *size = style->pixelSize(pixelSize?pixelSize:SMOOTH_SCALABLE, true);
816  size->fileName = file;
817  size->fileIndex = fileIndex;
818 
819 #if defined(Q_WS_QWS)
820  if (stream) {
821  *stream << familyname << foundry->name << weight << quint8(italic) << pixelSize
822  << file << fileIndex << quint8(antialiased);
823  *stream << quint8(writingSystems.count());
824  for (int i = 0; i < writingSystems.count(); ++i)
825  *stream << quint8(writingSystems.at(i));
826  }
827 #else // ..in case of defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
828  f->fontFilename = file;
829  f->fontFileIndex = fileIndex;
830 #endif
831 }
832 #endif
833 
834 #if (defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)) && !defined(QT_NO_FREETYPE)
836 {
837  QStringList families;
838  extern FT_Library qt_getFreetype();
839  FT_Library library = qt_getFreetype();
840 
841  int index = 0;
842  int numFaces = 0;
843  do {
844  FT_Face face;
845  FT_Error error;
846  if (!fontData.isEmpty()) {
847  error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face);
848  } else {
849  error = FT_New_Face(library, file, index, &face);
850  }
851  if (error != FT_Err_Ok) {
852  qDebug() << "FT_New_Face failed with index" << index << ":" << hex << error;
853  break;
854  }
855  numFaces = face->num_faces;
856 
857  int weight = QFont::Normal;
858  bool italic = face->style_flags & FT_STYLE_FLAG_ITALIC;
859 
860  if (face->style_flags & FT_STYLE_FLAG_BOLD)
861  weight = QFont::Bold;
862 
864  // detect symbol fonts
865  for (int i = 0; i < face->num_charmaps; ++i) {
866  FT_CharMap cm = face->charmaps[i];
867  if (cm->encoding == ft_encoding_adobe_custom
868  || cm->encoding == ft_encoding_symbol) {
869  writingSystems.append(QFontDatabase::Symbol);
870  break;
871  }
872  }
873  if (writingSystems.isEmpty()) {
874  TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2);
875  if (os2) {
876  quint32 unicodeRange[4] = {
877  static_cast<quint32>(os2->ulUnicodeRange1), static_cast<quint32>(os2->ulUnicodeRange2), static_cast<quint32>(os2->ulUnicodeRange3), static_cast<quint32>(os2->ulUnicodeRange4)
878  };
879  quint32 codePageRange[2] = {
880  static_cast<quint32>(os2->ulCodePageRange1), static_cast<quint32>(os2->ulCodePageRange2)
881  };
882 
883  writingSystems = qt_determine_writing_systems_from_truetype_bits(unicodeRange, codePageRange);
884  //for (int i = 0; i < writingSystems.count(); ++i)
885  // qDebug() << QFontDatabase::writingSystemName(writingSystems.at(i));
886  }
887  }
888 
889  QString family = QString::fromAscii(face->family_name);
890  families.append(family);
891  addFont(family, /*foundry*/ "", weight, italic,
892  /*pixelsize*/ 0, file, index, /*antialias*/ true, writingSystems);
893 
894  FT_Done_Face(face);
895  ++index;
896  } while (index < numFaces);
897  return families;
898 }
899 #endif
900 
901 static const int scriptForWritingSystem[] = {
902  QUnicodeTables::Common, // Any
903  QUnicodeTables::Latin, // Latin
904  QUnicodeTables::Greek, // Greek
905  QUnicodeTables::Cyrillic, // Cyrillic
906  QUnicodeTables::Armenian, // Armenian
907  QUnicodeTables::Hebrew, // Hebrew
908  QUnicodeTables::Arabic, // Arabic
909  QUnicodeTables::Syriac, // Syriac
910  QUnicodeTables::Thaana, // Thaana
911  QUnicodeTables::Devanagari, // Devanagari
912  QUnicodeTables::Bengali, // Bengali
913  QUnicodeTables::Gurmukhi, // Gurmukhi
914  QUnicodeTables::Gujarati, // Gujarati
915  QUnicodeTables::Oriya, // Oriya
916  QUnicodeTables::Tamil, // Tamil
917  QUnicodeTables::Telugu, // Telugu
918  QUnicodeTables::Kannada, // Kannada
919  QUnicodeTables::Malayalam, // Malayalam
920  QUnicodeTables::Sinhala, // Sinhala
921  QUnicodeTables::Thai, // Thai
922  QUnicodeTables::Lao, // Lao
923  QUnicodeTables::Tibetan, // Tibetan
924  QUnicodeTables::Myanmar, // Myanmar
925  QUnicodeTables::Georgian, // Georgian
926  QUnicodeTables::Khmer, // Khmer
927  QUnicodeTables::Common, // SimplifiedChinese
928  QUnicodeTables::Common, // TraditionalChinese
929  QUnicodeTables::Common, // Japanese
930  QUnicodeTables::Hangul, // Korean
931  QUnicodeTables::Common, // Vietnamese
932  QUnicodeTables::Common, // Symbol
933  QUnicodeTables::Ogham, // Ogham
934  QUnicodeTables::Runic, // Runic
935  QUnicodeTables::Nko // Nko
936 };
937 
939 {
940  return scriptForWritingSystem[writingSystem];
941 }
942 
943 
944 #if defined Q_WS_QWS || (defined(Q_WS_X11) && !defined(QT_NO_FONTCONFIG)) || defined(Q_WS_WIN)
945 static inline bool requiresOpenType(int writingSystem)
946 {
947  return ((writingSystem >= QFontDatabase::Syriac && writingSystem <= QFontDatabase::Sinhala)
948  || writingSystem == QFontDatabase::Khmer || writingSystem == QFontDatabase::Nko);
949 }
950 static inline bool scriptRequiresOpenType(int script)
951 {
952  return ((script >= QUnicodeTables::Syriac && script <= QUnicodeTables::Sinhala)
953  || script == QUnicodeTables::Khmer || script == QUnicodeTables::Nko);
954 }
955 #endif
956 
957 
970 static void parseFontName(const QString &name, QString &foundry, QString &family)
971 {
972  int i = name.indexOf(QLatin1Char('['));
973  int li = name.lastIndexOf(QLatin1Char(']'));
974  if (i >= 0 && li >= 0 && i < li) {
975  foundry = name.mid(i + 1, li - i - 1);
976  if (i > 0 && name[i - 1] == QLatin1Char(' '))
977  i--;
978  family = name.left(i);
979  } else {
980  foundry.clear();
981  family = name;
982  }
983 
984  // capitalize the family/foundry names
985  bool space = true;
986  QChar *s = family.data();
987  int len = family.length();
988  while(len--) {
989  if (space) *s = s->toUpper();
990  space = s->isSpace();
991  ++s;
992  }
993 
994  space = true;
995  s = foundry.data();
996  len = foundry.length();
997  while(len--) {
998  if (space) *s = s->toUpper();
999  space = s->isSpace();
1000  ++s;
1001  }
1002 }
1003 
1004 
1006 {
1007  inline QtFontDesc() : family(0), foundry(0), style(0), size(0), encoding(0), familyIndex(-1) {}
1014 };
1015 
1016 #if !defined(Q_WS_MAC)
1017 static void match(int script, const QFontDef &request,
1018  const QString &family_name, const QString &foundry_name, int force_encoding_id,
1019  QtFontDesc *desc, const QList<int> &blacklistedFamilies = QList<int>(), bool forceXLFD=false);
1020 
1021 #if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_QPA)
1022 static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDef *fontDef)
1023 {
1024  fontDef->family = desc.family->name;
1025  if (! desc.foundry->name.isEmpty() && desc.family->count > 1) {
1026  fontDef->family += QString::fromLatin1(" [");
1027  fontDef->family += desc.foundry->name;
1028  fontDef->family += QLatin1Char(']');
1029  }
1030 
1031  if (desc.style->smoothScalable)
1032  fontDef->pixelSize = request.pixelSize;
1033  else if ((desc.style->bitmapScalable && (request.styleStrategy & QFont::PreferMatch)))
1034  fontDef->pixelSize = request.pixelSize;
1035  else
1036  fontDef->pixelSize = desc.size->pixelSize;
1037 
1038  fontDef->styleHint = request.styleHint;
1039  fontDef->styleStrategy = request.styleStrategy;
1040 
1041  fontDef->weight = desc.style->key.weight;
1042  fontDef->style = desc.style->key.style;
1043  fontDef->fixedPitch = desc.family->fixedPitch;
1044  fontDef->stretch = desc.style->key.stretch;
1045  fontDef->ignorePitch = false;
1046 }
1047 #endif
1048 #endif
1049 
1050 #if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) || defined(Q_WS_QPA)
1051 static void getEngineData(const QFontPrivate *d, const QFontCache::Key &key)
1052 {
1053  // look for the requested font in the engine data cache
1055  if (!d->engineData) {
1056  // create a new one
1057  d->engineData = new QFontEngineData;
1059  } else {
1060  d->engineData->ref.ref();
1061  }
1062 }
1063 #endif
1064 
1065 static QStringList familyList(const QFontDef &req)
1066 {
1067  // list of families to try
1068  QStringList family_list;
1069  if (req.family.isEmpty())
1070  return family_list;
1071 
1072  QStringList list = req.family.split(QLatin1Char(','));
1073  for (int i = 0; i < list.size(); ++i) {
1074  QString str = list.at(i).trimmed();
1075  if ((str.startsWith(QLatin1Char('"')) && str.endsWith(QLatin1Char('"')))
1076  || (str.startsWith(QLatin1Char('\'')) && str.endsWith(QLatin1Char('\''))))
1077  str = str.mid(1, str.length() - 2);
1078  family_list << str;
1079  }
1080 
1081  // append the substitute list for each family in family_list
1082  QStringList subs_list;
1083  QStringList::ConstIterator it = family_list.constBegin(), end = family_list.constEnd();
1084  for (; it != end; ++it)
1085  subs_list += QFont::substitutes(*it);
1086 // qDebug() << "adding substs: " << subs_list;
1087 
1088  family_list += subs_list;
1089 
1090  return family_list;
1091 }
1092 
1094 Q_GLOBAL_STATIC_WITH_ARGS(QMutex, fontDatabaseMutex, (QMutex::Recursive))
1095 
1096 // used in qfontengine_x11.cpp
1098 {
1099  return fontDatabaseMutex();
1100 }
1101 
1103 #if defined(Q_WS_X11)
1104 # include "qfontdatabase_x11.cpp"
1105 #elif defined(Q_WS_MAC)
1106 # include "qfontdatabase_mac.cpp"
1107 #elif defined(Q_WS_WIN)
1108 # include "qfontdatabase_win.cpp"
1109 #elif defined(Q_WS_QWS)
1110 # include "qfontdatabase_qws.cpp"
1111 #elif defined(Q_WS_QPA)
1112 # include "qfontdatabase_qpa.cpp"
1113 #elif defined(Q_OS_SYMBIAN)
1114 # include "qfontdatabase_s60.cpp"
1115 #endif
1117 
1118 #if !defined(Q_WS_X11) && !defined(Q_WS_MAC)
1120 {
1121  return family;
1122 }
1123 #endif
1124 
1125 static QtFontStyle *bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &styleKey,
1126  const QString &styleName = QString())
1127 {
1128  int best = 0;
1129  int dist = 0xffff;
1130 
1131  for ( int i = 0; i < foundry->count; i++ ) {
1132  QtFontStyle *style = foundry->styles[i];
1133 
1134  if (!styleName.isEmpty() && styleName == style->styleName) {
1135  dist = 0;
1136  best = i;
1137  break;
1138  }
1139 
1140  int d = qAbs( styleKey.weight - style->key.weight );
1141 
1142  if ( styleKey.stretch != 0 && style->key.stretch != 0 ) {
1143  d += qAbs( styleKey.stretch - style->key.stretch );
1144  }
1145 
1146  if (styleKey.style != style->key.style) {
1147  if (styleKey.style != QFont::StyleNormal && style->key.style != QFont::StyleNormal)
1148  // one is italic, the other oblique
1149  d += 0x0001;
1150  else
1151  d += 0x1000;
1152  }
1153 
1154  if ( d < dist ) {
1155  best = i;
1156  dist = d;
1157  }
1158  }
1159 
1160  FM_DEBUG( " best style has distance 0x%x", dist );
1161  return foundry->styles[best];
1162 }
1163 
1164 #if defined(Q_WS_X11)
1165 static QtFontEncoding *findEncoding(int script, int styleStrategy,
1166  QtFontSize *size, int force_encoding_id)
1167 {
1168  QtFontEncoding *encoding = 0;
1169 
1170  if (force_encoding_id >= 0) {
1171  encoding = size->encodingID(force_encoding_id);
1172  if (!encoding)
1173  FM_DEBUG(" required encoding_id not available");
1174  return encoding;
1175  }
1176 
1177  if (styleStrategy & (QFont::OpenGLCompatible | QFont::PreferBitmap)) {
1178  FM_DEBUG(" PreferBitmap and/or OpenGL set, skipping Freetype");
1179  } else {
1180  encoding = size->encodingID(-1); // -1 == prefer Freetype
1181  if (encoding)
1182  return encoding;
1183  }
1184 
1185  // FT not available, find an XLFD font, trying the default encoding first
1186  encoding = size->encodingID(QFontPrivate::defaultEncodingID);
1187  if (encoding) {
1188  // does it support the requested script?
1189  bool supportsScript = false;
1190  for (int ws = 1; !supportsScript && ws < QFontDatabase::WritingSystemsCount; ++ws) {
1191  if (scriptForWritingSystem[ws] != script)
1192  continue;
1193  supportsScript = writingSystems_for_xlfd_encoding[encoding->encoding][ws];
1194  }
1195  if (!supportsScript)
1196  encoding = 0;
1197  }
1198  // find the first encoding that supports the requested script
1199  for (int ws = 1; !encoding && ws < QFontDatabase::WritingSystemsCount; ++ws) {
1200  if (scriptForWritingSystem[ws] != script)
1201  continue;
1202  for (int x = 0; !encoding && x < size->count; ++x) {
1203  const int enc = size->encodings[x].encoding;
1205  encoding = size->encodings + x;
1206  }
1207  }
1208 
1209  return encoding;
1210 }
1211 #endif // Q_WS_X11
1212 
1213 #if !defined(Q_WS_MAC)
1214 static
1215 unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
1216  const QtFontFamily *family, const QString &foundry_name,
1217  QtFontStyle::Key styleKey, int pixelSize, char pitch,
1218  QtFontDesc *desc, int force_encoding_id)
1219 {
1220  Q_UNUSED(force_encoding_id);
1221  Q_UNUSED(script);
1222  Q_UNUSED(pitch);
1223 
1224  desc->foundry = 0;
1225  desc->style = 0;
1226  desc->size = 0;
1227  desc->encoding = 0;
1228 
1229 
1230  FM_DEBUG(" REMARK: looking for best foundry for family '%s' [%d]", family->name.toLatin1().constData(), family->count);
1231 
1232  for (int x = 0; x < family->count; ++x) {
1233  QtFontFoundry *foundry = family->foundries[x];
1234  if (!foundry_name.isEmpty() && foundry->name.compare(foundry_name, Qt::CaseInsensitive) != 0)
1235  continue;
1236 
1237  FM_DEBUG(" looking for matching style in foundry '%s' %d",
1238  foundry->name.isEmpty() ? "-- none --" : foundry->name.toLatin1().constData(), foundry->count);
1239 
1240  QtFontStyle *style = bestStyle(foundry, styleKey);
1241 
1242  if (!style->smoothScalable && (styleStrategy & QFont::ForceOutline)) {
1243  FM_DEBUG(" ForceOutline set, but not smoothly scalable");
1244  continue;
1245  }
1246 
1247  int px = -1;
1248  QtFontSize *size = 0;
1249 
1250  // 1. see if we have an exact matching size
1251  if (!(styleStrategy & QFont::ForceOutline)) {
1252  size = style->pixelSize(pixelSize);
1253  if (size) {
1254  FM_DEBUG(" found exact size match (%d pixels)", size->pixelSize);
1255  px = size->pixelSize;
1256  }
1257  }
1258 
1259  // 2. see if we have a smoothly scalable font
1260  if (!size && style->smoothScalable && ! (styleStrategy & QFont::PreferBitmap)) {
1261  size = style->pixelSize(SMOOTH_SCALABLE);
1262  if (size) {
1263  FM_DEBUG(" found smoothly scalable font (%d pixels)", pixelSize);
1264  px = pixelSize;
1265  }
1266  }
1267 
1268  // 3. see if we have a bitmap scalable font
1269  if (!size && style->bitmapScalable && (styleStrategy & QFont::PreferMatch)) {
1270  size = style->pixelSize(0);
1271  if (size) {
1272  FM_DEBUG(" found bitmap scalable font (%d pixels)", pixelSize);
1273  px = pixelSize;
1274  }
1275  }
1276 
1277 #ifdef Q_WS_X11
1278  QtFontEncoding *encoding = 0;
1279 #endif
1280 
1281  // 4. find closest size match
1282  if (! size) {
1283  unsigned int distance = ~0u;
1284  for (int x = 0; x < style->count; ++x) {
1285 #ifdef Q_WS_X11
1286  encoding =
1287  findEncoding(script, styleStrategy, style->pixelSizes + x, force_encoding_id);
1288  if (!encoding) {
1289  FM_DEBUG(" size %3d does not support the script we want",
1290  style->pixelSizes[x].pixelSize);
1291  continue;
1292  }
1293 #endif
1294 
1295  unsigned int d;
1296  if (style->pixelSizes[x].pixelSize < pixelSize) {
1297  // penalize sizes that are smaller than the
1298  // requested size, due to truncation from floating
1299  // point to integer conversions
1300  d = pixelSize - style->pixelSizes[x].pixelSize + 1;
1301  } else {
1302  d = style->pixelSizes[x].pixelSize - pixelSize;
1303  }
1304 
1305  if (d < distance) {
1306  distance = d;
1307  size = style->pixelSizes + x;
1308  FM_DEBUG(" best size so far: %3d (%d)", size->pixelSize, pixelSize);
1309  }
1310  }
1311 
1312  if (!size) {
1313  FM_DEBUG(" no size supports the script we want");
1314  continue;
1315  }
1316 
1317  if (style->bitmapScalable && ! (styleStrategy & QFont::PreferQuality) &&
1318  (distance * 10 / pixelSize) >= 2) {
1319  // the closest size is not close enough, go ahead and
1320  // use a bitmap scaled font
1321  size = style->pixelSize(0);
1322  px = pixelSize;
1323  } else {
1324  px = size->pixelSize;
1325  }
1326  }
1327 
1328 #ifdef Q_WS_X11
1329  if (size) {
1330  encoding = findEncoding(script, styleStrategy, size, force_encoding_id);
1331  if (!encoding) size = 0;
1332  }
1333  if (! encoding) {
1334  FM_DEBUG(" foundry doesn't support the script we want");
1335  continue;
1336  }
1337 #endif // Q_WS_X11
1338 
1339  unsigned int this_score = 0x0000;
1340  enum {
1341  PitchMismatch = 0x4000,
1342  StyleMismatch = 0x2000,
1343  BitmapScaledPenalty = 0x1000,
1344  EncodingMismatch = 0x0002,
1345  XLFDPenalty = 0x0001
1346  };
1347 #ifdef Q_WS_X11
1348  if (encoding->encoding != -1) {
1349  this_score += XLFDPenalty;
1350  if (encoding->encoding != QFontPrivate::defaultEncodingID)
1351  this_score += EncodingMismatch;
1352  }
1353  if (pitch != '*') {
1354  if (!(pitch == 'm' && encoding->pitch == 'c') && pitch != encoding->pitch)
1355  this_score += PitchMismatch;
1356  }
1357 #else
1358  if (pitch != '*') {
1359 #if !defined(QWS) && defined(Q_OS_MAC)
1360  qt_mac_get_fixed_pitch(const_cast<QtFontFamily*>(family));
1361 #endif
1362  if ((pitch == 'm' && !family->fixedPitch)
1363  || (pitch == 'p' && family->fixedPitch))
1364  this_score += PitchMismatch;
1365  }
1366 #endif
1367  if (styleKey != style->key)
1368  this_score += StyleMismatch;
1369  if (!style->smoothScalable && px != size->pixelSize) // bitmap scaled
1370  this_score += BitmapScaledPenalty;
1371  if (px != pixelSize) // close, but not exact, size match
1372  this_score += qAbs(px - pixelSize);
1373 
1374  if (this_score < score) {
1375  FM_DEBUG(" found a match: score %x best score so far %x",
1376  this_score, score);
1377 
1378  score = this_score;
1379  desc->foundry = foundry;
1380  desc->style = style;
1381  desc->size = size;
1382 #ifdef Q_WS_X11
1383  desc->encoding = encoding;
1384 #endif // Q_WS_X11
1385  } else {
1386  FM_DEBUG(" score %x no better than best %x", this_score, score);
1387  }
1388  }
1389 
1390  return score;
1391 }
1392 #endif
1393 
1394 #if !defined(Q_WS_MAC)
1395 
1400 static void match(int script, const QFontDef &request,
1401  const QString &family_name, const QString &foundry_name, int force_encoding_id,
1402  QtFontDesc *desc, const QList<int> &blacklistedFamilies, bool forceXLFD)
1403 {
1404  Q_UNUSED(force_encoding_id);
1405 
1406  QtFontStyle::Key styleKey;
1407  styleKey.style = request.style;
1408  styleKey.weight = request.weight;
1409  styleKey.stretch = request.stretch;
1410  char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p';
1411 
1412 
1413  FM_DEBUG("QFontDatabase::match\n"
1414  " request:\n"
1415  " family: %s [%s], script: %d\n"
1416  " weight: %d, style: %d\n"
1417  " stretch: %d\n"
1418  " pixelSize: %g\n"
1419  " pitch: %c",
1420  family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(),
1421  foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(),
1422  script, request.weight, request.style, request.stretch, request.pixelSize, pitch);
1423 #if defined(FONT_MATCH_DEBUG) && defined(Q_WS_X11)
1424  if (force_encoding_id >= 0) {
1425  FM_DEBUG(" required encoding: %d", force_encoding_id);
1426  }
1427 #endif
1428 
1429  desc->family = 0;
1430  desc->foundry = 0;
1431  desc->style = 0;
1432  desc->size = 0;
1433  desc->encoding = 0;
1434  desc->familyIndex = -1;
1435 
1436  unsigned int score = ~0u;
1437 
1438 #ifdef Q_WS_X11
1439  load(family_name, script, forceXLFD);
1440 #else
1441  Q_UNUSED(forceXLFD);
1442  load(family_name, script);
1443 #endif
1444 
1445  QFontDatabasePrivate *db = privateDb();
1446  for (int x = 0; x < db->count; ++x) {
1447  if (blacklistedFamilies.contains(x))
1448  continue;
1449  QtFontDesc test;
1450  test.family = db->families[x];
1451  test.familyIndex = x;
1452 
1453  if (!family_name.isEmpty()
1454  && test.family->name.compare(family_name, Qt::CaseInsensitive) != 0
1455 #ifdef Q_WS_WIN
1456  && test.family->english_name.compare(family_name, Qt::CaseInsensitive) != 0
1457 #endif
1458  )
1459  continue;
1460 
1461  if (family_name.isEmpty())
1462  load(test.family->name, script);
1463 
1464  uint score_adjust = 0;
1465 
1466  bool supported = (script == QUnicodeTables::Common);
1467  for (int ws = 1; !supported && ws < QFontDatabase::WritingSystemsCount; ++ws) {
1468  if (scriptForWritingSystem[ws] != script)
1469  continue;
1471  supported = true;
1472  }
1473  if (!supported) {
1474  // family not supported in the script we want
1475  continue;
1476  }
1477 
1478  // as we know the script is supported, we can be sure
1479  // to find a matching font here.
1480  unsigned int newscore =
1481  bestFoundry(script, score, request.styleStrategy,
1482  test.family, foundry_name, styleKey, request.pixelSize, pitch,
1483  &test, force_encoding_id);
1484  if (test.foundry == 0) {
1485  // the specific foundry was not found, so look for
1486  // any foundry matching our requirements
1487  newscore = bestFoundry(script, score, request.styleStrategy, test.family,
1488  QString(), styleKey, request.pixelSize,
1489  pitch, &test, force_encoding_id);
1490  }
1491  newscore += score_adjust;
1492 
1493  if (newscore < score) {
1494  score = newscore;
1495  *desc = test;
1496  }
1497  if (newscore < 10) // xlfd instead of FT... just accept it
1498  break;
1499  }
1500 }
1501 #endif
1502 
1504 {
1505  QString result;
1506  if (weight >= QFont::Black)
1507  result = QApplication::translate("QFontDatabase", "Black");
1508  else if (weight >= QFont::Bold)
1509  result = QApplication::translate("QFontDatabase", "Bold");
1510  else if (weight >= QFont::DemiBold)
1511  result = QApplication::translate("QFontDatabase", "Demi Bold");
1512  else if (weight < QFont::Normal)
1513  result = QApplication::translate("QFontDatabase", "Light");
1514 
1515  if (style == QFont::StyleItalic)
1516  result += QLatin1Char(' ') + QApplication::translate("QFontDatabase", "Italic");
1517  else if (style == QFont::StyleOblique)
1518  result += QLatin1Char(' ') + QApplication::translate("QFontDatabase", "Oblique");
1519 
1520  if (result.isEmpty())
1521  result = QApplication::translate("QFontDatabase", "Normal");
1522 
1523  return result.simplified();
1524 }
1525 
1532 {
1533  return font.styleName().isEmpty() ? styleStringHelper(font.weight(), font.style())
1534  : font.styleName();
1535 }
1536 
1543 {
1544  return fontInfo.styleName().isEmpty() ? styleStringHelper(fontInfo.weight(), fontInfo.style())
1545  : fontInfo.styleName();
1546 }
1547 
1548 
1607 {
1608  QMutexLocker locker(fontDatabaseMutex());
1609  createDatabase();
1610  d = privateDb();
1611 }
1612 
1663 {
1664  QMutexLocker locker(fontDatabaseMutex());
1665 
1667 #ifdef Q_WS_X11
1668  checkSymbolFonts();
1669 #endif
1670 
1671  QList<WritingSystem> list;
1672  for (int i = 0; i < d->count; ++i) {
1673  QtFontFamily *family = d->families[i];
1674  if (family->count == 0)
1675  continue;
1676  for (int x = Latin; x < WritingSystemsCount; ++x) {
1677  const WritingSystem writingSystem = WritingSystem(x);
1678  if (!(family->writingSystems[writingSystem] & QtFontFamily::Supported))
1679  continue;
1680  if (!list.contains(writingSystem))
1681  list.append(writingSystem);
1682  }
1683  }
1684  qSort(list);
1685  return list;
1686 }
1687 
1688 
1696 {
1697  QString familyName, foundryName;
1698  parseFontName(family, foundryName, familyName);
1699 
1700  QMutexLocker locker(fontDatabaseMutex());
1701 
1703 #ifdef Q_WS_X11
1704  checkSymbolFonts(familyName);
1705 #endif
1706 
1707  QList<WritingSystem> list;
1708  QtFontFamily *f = d->family(familyName);
1709  if (!f || f->count == 0)
1710  return list;
1711 
1712  for (int x = Latin; x < WritingSystemsCount; ++x) {
1713  const WritingSystem writingSystem = WritingSystem(x);
1714  if (f->writingSystems[writingSystem] & QtFontFamily::Supported)
1715  list.append(writingSystem);
1716  }
1717  return list;
1718 }
1719 
1720 
1732 {
1733  QMutexLocker locker(fontDatabaseMutex());
1734 
1736 #ifdef Q_WS_X11
1737  if (writingSystem != Any)
1738  checkSymbolFonts();
1739 #endif
1740 
1741  QStringList flist;
1742  for (int i = 0; i < d->count; i++) {
1743  QtFontFamily *f = d->families[i];
1744  if (f->count == 0)
1745  continue;
1746  if (writingSystem != Any && (f->writingSystems[writingSystem] != QtFontFamily::Supported))
1747  continue;
1748  if (f->count == 1) {
1749  flist.append(f->name);
1750  } else {
1751  for (int j = 0; j < f->count; j++) {
1752  QString str = f->name;
1753  QString foundry = f->foundries[j]->name;
1754  if (!foundry.isEmpty()) {
1755  str += QLatin1String(" [");
1756  str += foundry;
1757  str += QLatin1Char(']');
1758  }
1759  flist.append(str);
1760  }
1761  }
1762  }
1763  return flist;
1764 }
1765 
1774 {
1775  QString familyName, foundryName;
1776  parseFontName(family, foundryName, familyName);
1777 
1778  QMutexLocker locker(fontDatabaseMutex());
1779 
1780  QT_PREPEND_NAMESPACE(load)(familyName);
1781 
1782  QStringList l;
1783  QtFontFamily *f = d->family(familyName);
1784  if (!f)
1785  return l;
1786 
1787  QtFontFoundry allStyles(foundryName);
1788  for (int j = 0; j < f->count; j++) {
1789  QtFontFoundry *foundry = f->foundries[j];
1790  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
1791  for (int k = 0; k < foundry->count; k++) {
1792  QtFontStyle::Key ke(foundry->styles[k]->key);
1793  ke.stretch = 0;
1794  allStyles.style(ke, foundry->styles[k]->styleName, true);
1795  }
1796  }
1797  }
1798 
1799  for (int i = 0; i < allStyles.count; i++) {
1800  l.append(allStyles.styles[i]->styleName.isEmpty() ?
1801  styleStringHelper(allStyles.styles[i]->key.weight,
1802  (QFont::Style)allStyles.styles[i]->key.style) :
1803  allStyles.styles[i]->styleName);
1804  }
1805  return l;
1806 }
1807 
1814  const QString &style) const
1815 {
1816  Q_UNUSED(style);
1817 
1818  QString familyName, foundryName;
1819  parseFontName(family, foundryName, familyName);
1820 
1821  QMutexLocker locker(fontDatabaseMutex());
1822 
1823  QT_PREPEND_NAMESPACE(load)(familyName);
1824 
1825  QtFontFamily *f = d->family(familyName);
1826 #if !defined(QWS) && defined(Q_OS_MAC)
1828 #endif
1829  return (f && f->fixedPitch);
1830 }
1831 
1843  const QString &style) const
1844 {
1845  bool bitmapScalable = false;
1846  QString familyName, foundryName;
1847  parseFontName(family, foundryName, familyName);
1848 
1849  QMutexLocker locker(fontDatabaseMutex());
1850 
1851  QT_PREPEND_NAMESPACE(load)(familyName);
1852 
1853  QtFontStyle::Key styleKey(style);
1854 
1855  QtFontFamily *f = d->family(familyName);
1856  if (!f) return bitmapScalable;
1857 
1858  for (int j = 0; j < f->count; j++) {
1859  QtFontFoundry *foundry = f->foundries[j];
1860  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
1861  for (int k = 0; k < foundry->count; k++)
1862  if ((style.isEmpty() ||
1863  foundry->styles[k]->styleName == style ||
1864  foundry->styles[k]->key == styleKey)
1865  && foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) {
1866  bitmapScalable = true;
1867  goto end;
1868  }
1869  }
1870  }
1871  end:
1872  return bitmapScalable;
1873 }
1874 
1875 
1884 bool QFontDatabase::isSmoothlyScalable(const QString &family, const QString &style) const
1885 {
1886  bool smoothScalable = false;
1887  QString familyName, foundryName;
1888  parseFontName(family, foundryName, familyName);
1889 
1890  QMutexLocker locker(fontDatabaseMutex());
1891 
1892  QT_PREPEND_NAMESPACE(load)(familyName);
1893 
1894  QtFontStyle::Key styleKey(style);
1895 
1896  QtFontFamily *f = d->family(familyName);
1897  if (!f) return smoothScalable;
1898 
1899  for (int j = 0; j < f->count; j++) {
1900  QtFontFoundry *foundry = f->foundries[j];
1901  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
1902  for (int k = 0; k < foundry->count; k++)
1903  if ((style.isEmpty() ||
1904  foundry->styles[k]->styleName == style ||
1905  foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) {
1906  smoothScalable = true;
1907  goto end;
1908  }
1909  }
1910  }
1911  end:
1912  return smoothScalable;
1913 }
1914 
1922  const QString &style) const
1923 {
1924  QMutexLocker locker(fontDatabaseMutex());
1925  if (isSmoothlyScalable(family, style))
1926  return true;
1927  return isBitmapScalable(family, style);
1928 }
1929 
1930 
1942  const QString &styleName)
1943 {
1944 #if defined(Q_WS_WIN)
1945  // windows and macosx are always smoothly scalable
1946  Q_UNUSED(family);
1947  Q_UNUSED(styleName);
1948  return standardSizes();
1949 #else
1950  bool smoothScalable = false;
1951  QString familyName, foundryName;
1952  parseFontName(family, foundryName, familyName);
1953 
1954  QMutexLocker locker(fontDatabaseMutex());
1955 
1956  QT_PREPEND_NAMESPACE(load)(familyName);
1957 
1958  QtFontStyle::Key styleKey(styleName);
1959 
1960  QList<int> sizes;
1961 
1962  QtFontFamily *fam = d->family(familyName);
1963  if (!fam) return sizes;
1964 
1965 
1966 #ifdef Q_WS_X11
1967  int dpi = QX11Info::appDpiY();
1968 #else
1969  const int dpi = qt_defaultDpiY(); // embedded
1970 #endif
1971 
1972  for (int j = 0; j < fam->count; j++) {
1973  QtFontFoundry *foundry = fam->foundries[j];
1974  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
1975  QtFontStyle *style = foundry->style(styleKey, styleName);
1976  if (!style) continue;
1977 
1978  if (style->smoothScalable) {
1979  smoothScalable = true;
1980  goto end;
1981  }
1982  for (int l = 0; l < style->count; l++) {
1983  const QtFontSize *size = style->pixelSizes + l;
1984 
1985  if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) {
1986  const uint pointSize = qRound(size->pixelSize * qreal(72.0) / dpi);
1987  if (! sizes.contains(pointSize))
1988  sizes.append(pointSize);
1989  }
1990  }
1991  }
1992  }
1993  end:
1994  if (smoothScalable)
1995  return standardSizes();
1996 
1997  qSort(sizes);
1998  return sizes;
1999 #endif
2000 }
2001 
2009  int pointSize) const
2010 {
2011  QString familyName, foundryName;
2012  parseFontName(family, foundryName, familyName);
2013 
2014  QMutexLocker locker(fontDatabaseMutex());
2015 
2016  QT_PREPEND_NAMESPACE(load)(familyName);
2017 
2018  QtFontFoundry allStyles(foundryName);
2019  QtFontFamily *f = d->family(familyName);
2020  if (!f) return QApplication::font();
2021 
2022  for (int j = 0; j < f->count; j++) {
2023  QtFontFoundry *foundry = f->foundries[j];
2024  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2025  for (int k = 0; k < foundry->count; k++)
2026  allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true);
2027  }
2028  }
2029 
2030  QtFontStyle::Key styleKey(style);
2031  QtFontStyle *s = bestStyle(&allStyles, styleKey, style);
2032 
2033  if (!s) // no styles found?
2034  return QApplication::font();
2035 
2036  QFont fnt(family, pointSize, s->key.weight);
2037  fnt.setStyle((QFont::Style)s->key.style);
2038  if (!s->styleName.isEmpty())
2039  fnt.setStyleName(s->styleName);
2040  return fnt;
2041 }
2042 
2043 
2057  const QString &styleName)
2058 {
2059 #ifdef Q_WS_WIN
2060  Q_UNUSED(family);
2061  Q_UNUSED(styleName);
2063 #else
2064  bool smoothScalable = false;
2065  QString familyName, foundryName;
2066  parseFontName(family, foundryName, familyName);
2067 
2068  QMutexLocker locker(fontDatabaseMutex());
2069 
2070  QT_PREPEND_NAMESPACE(load)(familyName);
2071 
2072  QtFontStyle::Key styleKey(styleName);
2073 
2074  QList<int> sizes;
2075 
2076  QtFontFamily *fam = d->family(familyName);
2077  if (!fam)
2078  return sizes;
2079 
2080 #ifdef Q_WS_X11
2081  int dpi = QX11Info::appDpiY();
2082 #else
2083  const int dpi = qt_defaultDpiY(); // embedded
2084 #endif
2085 
2086  for (int j = 0; j < fam->count; j++) {
2087  QtFontFoundry *foundry = fam->foundries[j];
2088  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2089  QtFontStyle *style = foundry->style(styleKey, styleName);
2090  if (!style) continue;
2091 
2092  if (style->smoothScalable) {
2093  smoothScalable = true;
2094  goto end;
2095  }
2096  for (int l = 0; l < style->count; l++) {
2097  const QtFontSize *size = style->pixelSizes + l;
2098 
2099  if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) {
2100  const uint pointSize = qRound(size->pixelSize * qreal(72.0) / dpi);
2101  if (! sizes.contains(pointSize))
2102  sizes.append(pointSize);
2103  }
2104  }
2105  }
2106  }
2107  end:
2108  if (smoothScalable)
2110 
2111  qSort(sizes);
2112  return sizes;
2113 #endif
2114 }
2115 
2116 
2123 {
2124  QList<int> ret;
2125  static const unsigned short standard[] =
2126  { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 0 };
2127  const unsigned short *sizes = standard;
2128  while (*sizes) ret << *sizes++;
2129  return ret;
2130 }
2131 
2132 
2139 bool QFontDatabase::italic(const QString &family, const QString &style) const
2140 {
2141  QString familyName, foundryName;
2142  parseFontName(family, foundryName, familyName);
2143 
2144  QMutexLocker locker(fontDatabaseMutex());
2145 
2146  QT_PREPEND_NAMESPACE(load)(familyName);
2147 
2148  QtFontFoundry allStyles(foundryName);
2149  QtFontFamily *f = d->family(familyName);
2150  if (!f) return false;
2151 
2152  for (int j = 0; j < f->count; j++) {
2153  QtFontFoundry *foundry = f->foundries[j];
2154  if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2155  for (int k = 0; k < foundry->count; k++)
2156  allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true);
2157  }
2158  }
2159 
2160  QtFontStyle::Key styleKey(style);
2161  QtFontStyle *s = allStyles.style(styleKey, style);
2162  return s && s->key.style == QFont::StyleItalic;
2163 }
2164 
2165 
2172 bool QFontDatabase::bold(const QString &family,
2173  const QString &style) const
2174 {
2175  QString familyName, foundryName;
2176  parseFontName(family, foundryName, familyName);
2177 
2178  QMutexLocker locker(fontDatabaseMutex());
2179 
2180  QT_PREPEND_NAMESPACE(load)(familyName);
2181 
2182  QtFontFoundry allStyles(foundryName);
2183  QtFontFamily *f = d->family(familyName);
2184  if (!f) return false;
2185 
2186  for (int j = 0; j < f->count; j++) {
2187  QtFontFoundry *foundry = f->foundries[j];
2188  if (foundryName.isEmpty() ||
2189  foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2190  for (int k = 0; k < foundry->count; k++)
2191  allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true);
2192  }
2193  }
2194 
2195  QtFontStyle::Key styleKey(style);
2196  QtFontStyle *s = allStyles.style(styleKey, style);
2197  return s && s->key.weight >= QFont::Bold;
2198 }
2199 
2200 
2208 int QFontDatabase::weight(const QString &family,
2209  const QString &style) const
2210 {
2211  QString familyName, foundryName;
2212  parseFontName(family, foundryName, familyName);
2213 
2214  QMutexLocker locker(fontDatabaseMutex());
2215 
2216  QT_PREPEND_NAMESPACE(load)(familyName);
2217 
2218  QtFontFoundry allStyles(foundryName);
2219  QtFontFamily *f = d->family(familyName);
2220  if (!f) return -1;
2221 
2222  for (int j = 0; j < f->count; j++) {
2223  QtFontFoundry *foundry = f->foundries[j];
2224  if (foundryName.isEmpty() ||
2225  foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
2226  for (int k = 0; k < foundry->count; k++)
2227  allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true);
2228  }
2229  }
2230 
2231  QtFontStyle::Key styleKey(style);
2232  QtFontStyle *s = allStyles.style(styleKey, style);
2233  return s ? s->key.weight : -1;
2234 }
2235 
2236 
2238 bool QFontDatabase::hasFamily(const QString &family) const
2239 {
2240  QString parsedFamily, foundry;
2241  parseFontName(family, foundry, parsedFamily);
2242  const QString familyAlias = resolveFontFamilyAlias(parsedFamily);
2243  return families().contains(familyAlias, Qt::CaseInsensitive);
2244 }
2245 
2246 
2252 {
2253  const char *name = 0;
2254  switch (writingSystem) {
2255  case Any:
2256  name = QT_TRANSLATE_NOOP("QFontDatabase", "Any");
2257  break;
2258  case Latin:
2259  name = QT_TRANSLATE_NOOP("QFontDatabase", "Latin");
2260  break;
2261  case Greek:
2262  name = QT_TRANSLATE_NOOP("QFontDatabase", "Greek");
2263  break;
2264  case Cyrillic:
2265  name = QT_TRANSLATE_NOOP("QFontDatabase", "Cyrillic");
2266  break;
2267  case Armenian:
2268  name = QT_TRANSLATE_NOOP("QFontDatabase", "Armenian");
2269  break;
2270  case Hebrew:
2271  name = QT_TRANSLATE_NOOP("QFontDatabase", "Hebrew");
2272  break;
2273  case Arabic:
2274  name = QT_TRANSLATE_NOOP("QFontDatabase", "Arabic");
2275  break;
2276  case Syriac:
2277  name = QT_TRANSLATE_NOOP("QFontDatabase", "Syriac");
2278  break;
2279  case Thaana:
2280  name = QT_TRANSLATE_NOOP("QFontDatabase", "Thaana");
2281  break;
2282  case Devanagari:
2283  name = QT_TRANSLATE_NOOP("QFontDatabase", "Devanagari");
2284  break;
2285  case Bengali:
2286  name = QT_TRANSLATE_NOOP("QFontDatabase", "Bengali");
2287  break;
2288  case Gurmukhi:
2289  name = QT_TRANSLATE_NOOP("QFontDatabase", "Gurmukhi");
2290  break;
2291  case Gujarati:
2292  name = QT_TRANSLATE_NOOP("QFontDatabase", "Gujarati");
2293  break;
2294  case Oriya:
2295  name = QT_TRANSLATE_NOOP("QFontDatabase", "Oriya");
2296  break;
2297  case Tamil:
2298  name = QT_TRANSLATE_NOOP("QFontDatabase", "Tamil");
2299  break;
2300  case Telugu:
2301  name = QT_TRANSLATE_NOOP("QFontDatabase", "Telugu");
2302  break;
2303  case Kannada:
2304  name = QT_TRANSLATE_NOOP("QFontDatabase", "Kannada");
2305  break;
2306  case Malayalam:
2307  name = QT_TRANSLATE_NOOP("QFontDatabase", "Malayalam");
2308  break;
2309  case Sinhala:
2310  name = QT_TRANSLATE_NOOP("QFontDatabase", "Sinhala");
2311  break;
2312  case Thai:
2313  name = QT_TRANSLATE_NOOP("QFontDatabase", "Thai");
2314  break;
2315  case Lao:
2316  name = QT_TRANSLATE_NOOP("QFontDatabase", "Lao");
2317  break;
2318  case Tibetan:
2319  name = QT_TRANSLATE_NOOP("QFontDatabase", "Tibetan");
2320  break;
2321  case Myanmar:
2322  name = QT_TRANSLATE_NOOP("QFontDatabase", "Myanmar");
2323  break;
2324  case Georgian:
2325  name = QT_TRANSLATE_NOOP("QFontDatabase", "Georgian");
2326  break;
2327  case Khmer:
2328  name = QT_TRANSLATE_NOOP("QFontDatabase", "Khmer");
2329  break;
2330  case SimplifiedChinese:
2331  name = QT_TRANSLATE_NOOP("QFontDatabase", "Simplified Chinese");
2332  break;
2333  case TraditionalChinese:
2334  name = QT_TRANSLATE_NOOP("QFontDatabase", "Traditional Chinese");
2335  break;
2336  case Japanese:
2337  name = QT_TRANSLATE_NOOP("QFontDatabase", "Japanese");
2338  break;
2339  case Korean:
2340  name = QT_TRANSLATE_NOOP("QFontDatabase", "Korean");
2341  break;
2342  case Vietnamese:
2343  name = QT_TRANSLATE_NOOP("QFontDatabase", "Vietnamese");
2344  break;
2345  case Symbol:
2346  name = QT_TRANSLATE_NOOP("QFontDatabase", "Symbol");
2347  break;
2348  case Ogham:
2349  name = QT_TRANSLATE_NOOP("QFontDatabase", "Ogham");
2350  break;
2351  case Runic:
2352  name = QT_TRANSLATE_NOOP("QFontDatabase", "Runic");
2353  break;
2354  case Nko:
2355  name = QT_TRANSLATE_NOOP("QFontDatabase", "N'Ko");
2356  break;
2357  default:
2358  Q_ASSERT_X(false, "QFontDatabase::writingSystemName", "invalid 'writingSystem' parameter");
2359  break;
2360  }
2361  return QApplication::translate("QFontDatabase", name);
2362 }
2363 
2364 
2369 {
2370  QString sample;
2371  switch (writingSystem) {
2372  case Any:
2373  case Symbol:
2374  // show only ascii characters
2375  sample += QLatin1String("AaBbzZ");
2376  break;
2377  case Latin:
2378  // This is cheating... we only show latin-1 characters so that we don't
2379  // end up loading lots of fonts - at least on X11...
2380  sample = QLatin1String("Aa");
2381  sample += QChar(0x00C3);
2382  sample += QChar(0x00E1);
2383  sample += QLatin1String("Zz");
2384  break;
2385  case Greek:
2386  sample += QChar(0x0393);
2387  sample += QChar(0x03B1);
2388  sample += QChar(0x03A9);
2389  sample += QChar(0x03C9);
2390  break;
2391  case Cyrillic:
2392  sample += QChar(0x0414);
2393  sample += QChar(0x0434);
2394  sample += QChar(0x0436);
2395  sample += QChar(0x044f);
2396  break;
2397  case Armenian:
2398  sample += QChar(0x053f);
2399  sample += QChar(0x054f);
2400  sample += QChar(0x056f);
2401  sample += QChar(0x057f);
2402  break;
2403  case Hebrew:
2404  sample += QChar(0x05D0);
2405  sample += QChar(0x05D1);
2406  sample += QChar(0x05D2);
2407  sample += QChar(0x05D3);
2408  break;
2409  case Arabic:
2410  sample += QChar(0x0628);
2411  sample += QChar(0x0629);
2412  sample += QChar(0x062A);
2413  sample += QChar(0x063A);
2414  break;
2415  case Syriac:
2416  sample += QChar(0x0715);
2417  sample += QChar(0x0725);
2418  sample += QChar(0x0716);
2419  sample += QChar(0x0726);
2420  break;
2421  case Thaana:
2422  sample += QChar(0x0784);
2423  sample += QChar(0x0794);
2424  sample += QChar(0x078c);
2425  sample += QChar(0x078d);
2426  break;
2427  case Devanagari:
2428  sample += QChar(0x0905);
2429  sample += QChar(0x0915);
2430  sample += QChar(0x0925);
2431  sample += QChar(0x0935);
2432  break;
2433  case Bengali:
2434  sample += QChar(0x0986);
2435  sample += QChar(0x0996);
2436  sample += QChar(0x09a6);
2437  sample += QChar(0x09b6);
2438  break;
2439  case Gurmukhi:
2440  sample += QChar(0x0a05);
2441  sample += QChar(0x0a15);
2442  sample += QChar(0x0a25);
2443  sample += QChar(0x0a35);
2444  break;
2445  case Gujarati:
2446  sample += QChar(0x0a85);
2447  sample += QChar(0x0a95);
2448  sample += QChar(0x0aa5);
2449  sample += QChar(0x0ab5);
2450  break;
2451  case Oriya:
2452  sample += QChar(0x0b06);
2453  sample += QChar(0x0b16);
2454  sample += QChar(0x0b2b);
2455  sample += QChar(0x0b36);
2456  break;
2457  case Tamil:
2458  sample += QChar(0x0b89);
2459  sample += QChar(0x0b99);
2460  sample += QChar(0x0ba9);
2461  sample += QChar(0x0bb9);
2462  break;
2463  case Telugu:
2464  sample += QChar(0x0c05);
2465  sample += QChar(0x0c15);
2466  sample += QChar(0x0c25);
2467  sample += QChar(0x0c35);
2468  break;
2469  case Kannada:
2470  sample += QChar(0x0c85);
2471  sample += QChar(0x0c95);
2472  sample += QChar(0x0ca5);
2473  sample += QChar(0x0cb5);
2474  break;
2475  case Malayalam:
2476  sample += QChar(0x0d05);
2477  sample += QChar(0x0d15);
2478  sample += QChar(0x0d25);
2479  sample += QChar(0x0d35);
2480  break;
2481  case Sinhala:
2482  sample += QChar(0x0d90);
2483  sample += QChar(0x0da0);
2484  sample += QChar(0x0db0);
2485  sample += QChar(0x0dc0);
2486  break;
2487  case Thai:
2488  sample += QChar(0x0e02);
2489  sample += QChar(0x0e12);
2490  sample += QChar(0x0e22);
2491  sample += QChar(0x0e32);
2492  break;
2493  case Lao:
2494  sample += QChar(0x0e8d);
2495  sample += QChar(0x0e9d);
2496  sample += QChar(0x0ead);
2497  sample += QChar(0x0ebd);
2498  break;
2499  case Tibetan:
2500  sample += QChar(0x0f00);
2501  sample += QChar(0x0f01);
2502  sample += QChar(0x0f02);
2503  sample += QChar(0x0f03);
2504  break;
2505  case Myanmar:
2506  sample += QChar(0x1000);
2507  sample += QChar(0x1001);
2508  sample += QChar(0x1002);
2509  sample += QChar(0x1003);
2510  break;
2511  case Georgian:
2512  sample += QChar(0x10a0);
2513  sample += QChar(0x10b0);
2514  sample += QChar(0x10c0);
2515  sample += QChar(0x10d0);
2516  break;
2517  case Khmer:
2518  sample += QChar(0x1780);
2519  sample += QChar(0x1790);
2520  sample += QChar(0x17b0);
2521  sample += QChar(0x17c0);
2522  break;
2523  case SimplifiedChinese:
2524  sample += QChar(0x4e2d);
2525  sample += QChar(0x6587);
2526  sample += QChar(0x8303);
2527  sample += QChar(0x4f8b);
2528  break;
2529  case TraditionalChinese:
2530  sample += QChar(0x4e2d);
2531  sample += QChar(0x6587);
2532  sample += QChar(0x7bc4);
2533  sample += QChar(0x4f8b);
2534  break;
2535  case Japanese:
2536  sample += QChar(0x30b5);
2537  sample += QChar(0x30f3);
2538  sample += QChar(0x30d7);
2539  sample += QChar(0x30eb);
2540  sample += QChar(0x3067);
2541  sample += QChar(0x3059);
2542  break;
2543  case Korean:
2544  sample += QChar(0xac00);
2545  sample += QChar(0xac11);
2546  sample += QChar(0xac1a);
2547  sample += QChar(0xac2f);
2548  break;
2549  case Vietnamese:
2550  {
2551  static const char vietnameseUtf8[] = {
2552  char(0xef), char(0xbb), char(0xbf), char(0xe1), char(0xbb), char(0x97),
2553  char(0xe1), char(0xbb), char(0x99),
2554  char(0xe1), char(0xbb), char(0x91),
2555  char(0xe1), char(0xbb), char(0x93),
2556  };
2557  sample += QString::fromUtf8(vietnameseUtf8, sizeof(vietnameseUtf8));
2558  break;
2559  }
2560  case Ogham:
2561  sample += QChar(0x1681);
2562  sample += QChar(0x1682);
2563  sample += QChar(0x1683);
2564  sample += QChar(0x1684);
2565  break;
2566  case Runic:
2567  sample += QChar(0x16a0);
2568  sample += QChar(0x16a1);
2569  sample += QChar(0x16a2);
2570  sample += QChar(0x16a3);
2571  break;
2572  case Nko:
2573  sample += QChar(0x7ca);
2574  sample += QChar(0x7cb);
2575  sample += QChar(0x7cc);
2576  sample += QChar(0x7cd);
2577  break;
2578  default:
2579  break;
2580  }
2581  return sample;
2582 }
2583 
2584 
2585 void QFontDatabase::parseFontName(const QString &name, QString &foundry, QString &family)
2586 {
2587  QT_PREPEND_NAMESPACE(parseFontName)(name, foundry, family);
2588 }
2589 
2591 { initializeDb(); }
2592 
2593 // used from qfontengine_ft.cpp
2595 {
2596  QMutexLocker locker(fontDatabaseMutex());
2597  return privateDb()->applicationFonts.value(index).data;
2598 }
2599 
2601 {
2603  font.data = fontData;
2604  font.fileName = fileName;
2605 
2606  int i;
2607  for (i = 0; i < applicationFonts.count(); ++i)
2608  if (applicationFonts.at(i).families.isEmpty())
2609  break;
2610  if (i >= applicationFonts.count()) {
2611  applicationFonts.append(ApplicationFont());
2612  i = applicationFonts.count() - 1;
2613  }
2614 
2615  if (font.fileName.isEmpty() && !fontData.isEmpty())
2616  font.fileName = QString::fromLatin1(":qmemoryfonts/") + QString::number(i);
2617 
2618  registerFont(&font);
2619  if (font.families.isEmpty())
2620  return -1;
2621 
2622  applicationFonts[i] = font;
2623 
2624  invalidate();
2625  return i;
2626 }
2627 
2629 {
2630  for (int i = 0; i < applicationFonts.count(); ++i)
2631  if (applicationFonts.at(i).fileName == fileName)
2632  return true;
2633  return false;
2634 }
2635 
2660 {
2661  QByteArray data;
2662  QFile f(fileName);
2664  if (!f.open(QIODevice::ReadOnly))
2665  return -1;
2666  data = f.readAll();
2667  }
2668  QMutexLocker locker(fontDatabaseMutex());
2669  return privateDb()->addAppFont(data, fileName);
2670 }
2671 
2695 {
2696  QMutexLocker locker(fontDatabaseMutex());
2697  return privateDb()->addAppFont(fontData, QString() /* fileName */);
2698 }
2699 
2712 {
2713  QMutexLocker locker(fontDatabaseMutex());
2714  return privateDb()->applicationFonts.value(id).families;
2715 }
2716 
2765 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
uint fixedPitch
Definition: qfont_p.h:96
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
double d
Definition: qnumeric_p.h:62
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const
This function should return the set of OR&#39;d flags that are true for the file engine&#39;s file...
static QList< int > standardSizes()
Returns a list of standard font sizes.
QtFontFamily(const QString &n)
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
bool operator==(const Key &other)
QFont font(const QString &family, const QString &style, int pointSize) const
Returns a QFont object that has family family, style style and point size pointSize.
unsigned short pixelSize
Q_GUI_EXPORT QByteArray qt_fontdata_from_index(int index)
double qreal
Definition: qglobal.h:1193
QByteArray fileName
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
QStringList styles(const QString &family) const
Returns a list of the styles available for the font family family.
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
static bool requiresOpenType(int writingSystem)
#define add(aName)
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
#define it(className, varName)
static int addApplicationFont(const QString &fileName)
Loads the font from the file specified by fileName and makes it available to the application.
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
int weight() const
Returns the weight of the matched window system font.
Definition: qfont.cpp:2758
signed int count
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
static int requiredUnicodeBits[QFontDatabase::WritingSystemsCount][2]
QtFontStyle ** styles
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
#define error(msg)
QtFontSize * size
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static QStringList fontPath()
#define Q_WS_WIN
Defined on Windows.
Definition: qglobal.h:921
Style style() const
Returns the style of the font.
Definition: qfont.cpp:1223
virtual QAbstractFileEngine * fileEngine() const
Returns the QIOEngine for this QFile object.
Definition: qfile.cpp:1965
static bool match(const uchar *found, const char *target, uint len)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QtFontStyle * style
static int defaultEncodingID
Definition: qfont_p.h:167
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QStringList fallbackFamilies
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
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...
Definition: qfont.h:103
quint16 u
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
unsigned char quint8
Definition: qglobal.h:934
bool ref()
Atomically increments the value of this QAtomicInt.
bool isApplicationFont(const QString &fileName)
static void parseFontName(const QString &name, QString &foundry, QString &family)
QList< WritingSystem > writingSystems() const
Returns a sorted list of the available writing systems.
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual QPlatformFontDatabase * fontDatabase() const
Accessor for the platform integrations fontdatabase.
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
bool bogusWritingSystems
bool operator<(int priority, const QPair< QRunnable *, int > &p)
Definition: qthreadpool.cpp:50
bool bold(const QString &family, const QString &style) const
Returns true if the font that has family family and style style is bold; otherwise returns false...
QFontDatabase()
Creates a font database object.
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static void parseFontName(const QString &name, QString &foundry, QString &family)
This makes sense of the font family name:
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
int weight(const QString &family, const QString &style) const
Returns the weight of the font that has family family and style style.
QString styleName() const
Returns the requested font style name, it will be used to match the font with irregular styles (that ...
Definition: qfont.cpp:950
QStringList addTTFile(const QByteArray &file, const QByteArray &fontData=QByteArray())
Q_CORE_EXPORT QTextStream & hex(QTextStream &s)
QString styleName() const
Returns the style name of the matched window system font on system that supports it.
Definition: qfont.cpp:2686
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
static QFontCache * instance()
Definition: qfont.cpp:2919
QByteArray fontFilename
static QFont font()
Returns the default application font.
QtFontFoundry * foundry
Q_CORE_EXPORT void qDebug(const char *,...)
#define Q_OS_MAC
Defined on MAC OS (synonym for Darwin).
Definition: qglobal.h:274
Q_AUTOTEST_EXPORT void qt_setQtEnableTestFont(bool value)
unsigned char uchar
Definition: qglobal.h:994
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static void getEngineData(const QFontPrivate *d, const QFontCache::Key &key)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define SMOOTH_SCALABLE
QStringList fallbackFamilies
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
static FILE * stream
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
static QStringList familyList(const QFontDef &req)
QStringList families(WritingSystem writingSystem=Any) const
Returns a sorted list of the available font families which support the writingSystem.
QMutex * qt_fontdatabase_mutex()
QtFontEncoding * encoding
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int addAppFont(const QByteArray &fontData, const QString &fileName)
bool italic(const QString &family, const QString &style) const
Returns true if the font that has family family and style style is italic; otherwise returns false...
QtFontFamily ** families
const char * name
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
void insertEngineData(const Key &key, QFontEngineData *engineData)
Definition: qfont.cpp:3046
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const char * setwidthName
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
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
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QList< int > pointSizes(const QString &family, const QString &style=QString())
Returns a list of the point sizes available for the font with the given family and style...
static void qt_mac_get_fixed_pitch(QtFontFamily *f)
static QtFontEncoding * findEncoding(int script, int styleStrategy, QtFontSize *size, int force_encoding_id)
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
static void initializeDb()
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static int distance(QWidget *source, QWidget *target, QAccessible::RelationFlag relation)
uint weight
Definition: qfont_p.h:95
bool qt_enable_test_font
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1287
static QString resolveFontFamilyAlias(const QString &family)
bool hasFamily(const QString &family) const
QtFontStyle(const Key &k)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QAtomicInt ref
Definition: qfont_p.h:152
uint ignorePitch
Definition: qfont_p.h:100
void * HANDLE
Definition: qnamespace.h:1671
QtFontFoundry(const QString &n)
static QtFontStyle * bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &styleKey, const QString &styleName=QString())
QtFontFoundry ** foundries
#define FM_DEBUG
The QFontInfo class provides general information about fonts.
Definition: qfontinfo.h:54
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
bool isBitmapScalable(const QString &family, const QString &style=QString()) const
Returns true if the font that has family family and style style is a scalable bitmap font; otherwise ...
QFont::Style style() const
Returns the style value of the matched window system font.
Definition: qfont.cpp:2746
signed int encoding
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
qreal pixelSize
Definition: qfont_p.h:90
#define QT_NO_FREETYPE
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QtFontFamily * family(const QString &f, bool=false)
static QString writingSystemSample(WritingSystem writingSystem)
Returns a string with sample characters from writingSystem.
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
static int getFontWeight(const QString &weightString)
virtual void releaseHandle(void *handle)
Releases the font handle and deletes any associated data loaded from a file.
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
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
Key(const Key &o)
void addFont(const QString &familyname, const char *foundryname, int weight, bool italic, int pixelSize, const QByteArray &file, int fileIndex, bool antialiased, const QList< QFontDatabase::WritingSystem > &writingSystems=QList< QFontDatabase::WritingSystem >())
static void checkSymbolFonts(const QString &family=QString())
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QStringList substitutes(const QString &)
Returns a list of family names to be used whenever familyName is specified.
Definition: qfont.cpp:2139
int compare(const QString &s) const
Definition: qstring.cpp:5037
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
static bool isSmoothlyScalable(char **tokens)
static bool scriptRequiresOpenType(int script)
#define load(x)
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QtFontSize * pixelSize(unsigned short size, bool=false)
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
#define SimplifiedChineseCsbBit
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
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
static int addApplicationFontFromData(const QByteArray &fontData)
Loads the font from binary data specified by fontData and makes it available to the application...
uint style
Definition: qfont_p.h:97
QVector< FONTSIGNATURE > signatures
static QStringList applicationFontFamilies(int id)
Returns a list of font families for the given application font identified by id.
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isScalable(const QString &family, const QString &style=QString()) const
Returns true if the font that has family family and style style is scalable; otherwise returns false...
void setStyleName(const QString &)
Sets the style name of the font to the given styleName.
Definition: qfont.cpp:967
QString styleString(const QFont &font)
Returns a string that describes the style of the font.
if(void) toggleToolbarShown
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QFactoryLoader * l
int weight() const
Returns the weight of the font which is one of the enumerated values from QFont::Weight.
Definition: qfont.cpp:1248
uint stretch
Definition: qfont_p.h:98
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool operator!=(const Key &other)
int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem)
QtFontFamily * family
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)
quint16 index
bool isFixedPitch(const QString &family, const QString &style=QString()) const
Returns true if the font that has family family and style style is fixed pitch; otherwise returns fal...
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
QList< int > smoothSizes(const QString &family, const QString &style)
Returns the point sizes of a font with the given family and style that will look attractive.
unsigned short count
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
#define JapaneseCsbBit
QFontEngineData * findEngineData(const Key &key) const
Definition: qfont.cpp:3036
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
static const char writingSystems_for_xlfd_encoding[sizeof(xlfd_encoding)][QFontDatabase::WritingSystemsCount]
QString english_name
FT_Library qt_getFreetype()
QFont::Weight weightFromInteger(int weight)
QtFontEncoding * encodings
static const int scriptForWritingSystem[]
QVector< ApplicationFont > applicationFonts
QtFontFoundry * foundry(const QString &f, bool=false)
static QString writingSystemName(WritingSystem writingSystem)
Returns the names the writingSystem (e.g.
QString styleName
QString family
Definition: qfont_p.h:82
IDWriteGdiInterop * directWriteGdiInterop
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
static void createDatabase()
static const KeyPair *const end
QFontEngineData * engineData
Definition: qfont_p.h:179
bool isSmoothlyScalable(const QString &family, const QString &style=QString()) const
Returns true if the font that has family family and style style is smoothly scalable; otherwise retur...
void clear()
Definition: qfont.cpp:2981
uint styleHint
Definition: qfont_p.h:93
#define KoreanCsbBit
IDWriteFactory * directWriteFactory
uint styleStrategy
Definition: qfont_p.h:92
#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
static QString fileName(const QString &fileUrl)
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
const char * weightName
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
Declares a global static variable with the specified type and name.
Definition: qglobal.h:1982
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
QtFontSize * pixelSizes
#define TraditionalChineseCsbBit
void setStyle(Style style)
Sets the style of the font to style.
Definition: qfont.cpp:1234
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
QList< QFontDatabase::WritingSystem > qt_determine_writing_systems_from_truetype_bits(quint32 unicodeRange[4], quint32 codePageRange[2])
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...
bool ftWritingSystemCheck