44 #include <private/qapplication_p.h> 48 #include <private/qsystemlibrary_p.h> 52 #if !defined(QT_NO_DIRECTWRITE) 58 # include <QTemporaryFile> 69 #define MAKE_TAG(ch1, ch2, ch3, ch4) (\ 70 (((quint32)(ch4)) << 24) | \ 71 (((quint32)(ch3)) << 16) | \ 72 (((quint32)(ch2)) << 8) | \ 81 for(
int i = 0; i < name.
length(); ++i) {
82 if(c[i].unicode() >= 0x100)
103 MS_LangIdEnglish = 0x009
109 const unsigned char *names;
111 int microsoft_id = -1;
122 if(string_offset >= bytes || 6 + count*NameRecordSize > string_offset)
125 for(
int i = 0; i < count; ++i) {
133 if(name_id != FamilyId)
137 PlatformId_Unicode = 0,
138 PlatformId_Apple = 1,
139 PlatformId_Microsoft = 3
144 if(DWORD(string_offset + offset + length) >= bytes)
147 if ((platform_id == PlatformId_Microsoft
148 && (encoding_id == 0 || encoding_id == 1))
149 && (language_id & 0x3ff) == MS_LangIdEnglish
150 && microsoft_id == -1)
153 else if(platform_id == PlatformId_Unicode && encoding_id < 4 && unicode_id == -1)
155 else if(platform_id == PlatformId_Apple && encoding_id == 0 && language_id == 0)
159 bool unicode =
false;
161 if(microsoft_id != -1) {
164 }
else if(apple_id != -1) {
167 }
else if (unicode_id != -1) {
180 const unsigned char *
string = table + string_offset + offset;
181 for(
int i = 0; i < length; ++i)
188 const unsigned char *
string = table + string_offset + offset;
189 for(
int i = 0; i < length; ++i)
203 HDC hdc = GetDC( 0 );
205 memset(&lf, 0,
sizeof(LOGFONT));
206 memcpy(lf.lfFaceName, familyName.
utf16(),
qMin(LF_FACESIZE, familyName.
length()) *
sizeof(
wchar_t));
207 lf.lfCharSet = DEFAULT_CHARSET;
208 HFONT hfont = CreateFontIndirect(&lf);
215 HGDIOBJ oldobj = SelectObject( hdc, hfont );
217 const DWORD name_tag =
MAKE_TAG(
'n',
'a',
'm',
'e' );
220 unsigned char *table = 0;
222 DWORD bytes = GetFontData( hdc, name_tag, 0, 0, 0 );
223 if ( bytes == GDI_ERROR ) {
229 table =
new unsigned char[bytes];
230 GetFontData(hdc, name_tag, 0, table, bytes);
231 if ( bytes == GDI_ERROR )
237 SelectObject( hdc, oldobj );
238 DeleteObject( hfont );
249 TEXTMETRIC *textmetric,
250 const FONTSIGNATURE *signature,
267 NEWTEXTMETRIC *
tm = (NEWTEXTMETRIC *)textmetric;
268 fixed = !(tm->tmPitchAndFamily & TMPF_FIXED_PITCH);
269 ttf = (tm->tmPitchAndFamily & TMPF_TRUETYPE);
270 scalable = tm->tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE);
272 italic = tm->tmItalic;
273 weight = tm->tmWeight;
281 QtFontFamily *family = privateDb()->family(familyName,
true);
319 signature->fsUsb[0], signature->fsUsb[1],
320 signature->fsUsb[2], signature->fsUsb[3]
323 if (signature->fsUsb[0] == 0) {
327 unicodeRange[0] = 0xbfffffff;
328 unicodeRange[1] = 0xffffffff;
329 unicodeRange[2] = 0xffffffff;
330 unicodeRange[3] = 0xffffffff;
334 signature->fsCsb[0], signature->fsCsb[1]
338 for (
int i = 0; i < systems.
count(); ++i) {
391 FONTSIGNATURE signature = textmetric->ntmFontSig;
396 addFontToDatabase(familyName, script, (TEXTMETRIC *)textmetric, &signature, type);
411 if(family && family->
loaded)
413 }
else if (d->
count) {
417 HDC dummy = GetDC(0);
420 lf.lfCharSet = DEFAULT_CHARSET;
422 lf.lfFaceName[0] = 0;
424 memcpy(lf.lfFaceName, fam.
utf16(),
sizeof(wchar_t) *
qMin(fam.
length() + 1, 32));
426 lf.lfPitchAndFamily = 0;
428 EnumFontFamiliesEx(dummy, &lf,
429 (FONTENUMPROC)
storeFont, (LPARAM)privateDb(), 0);
441 memset(&lf, 0,
sizeof(LOGFONT));
442 memcpy(lf.lfFaceName, familyName.
utf16(),
sizeof(wchar_t) *
qMin(LF_FACESIZE, familyName.
size()));
443 lf.lfCharSet = DEFAULT_CHARSET;
444 HFONT hfont = CreateFontIndirect(&lf);
445 HGDIOBJ oldobj = SelectObject(hdc, hfont);
447 TEXTMETRIC textMetrics;
448 GetTextMetrics(hdc, &textMetrics);
455 SelectObject(hdc, oldobj);
474 if (!db || db->
count)
479 #ifdef QFONTDATABASE_DEBUG 481 for (
int f = 0; f < db->
count; f++) {
487 qDebug(
" scripts supported:");
491 for (
int fd = 0; fd < family->
count; fd++) {
494 for (
int s = 0; s < foundry->
count; s++) {
499 for(
int i = 0; i < style->
count; ++i) {
507 #endif // QFONTDATABASE_DEBUG 531 SelectObject(dc, fe->
hfont);
533 GetTextFace(dc, 64, n);
543 #if !defined(QT_NO_DIRECTWRITE) 545 int dpi, IDWriteFont *font)
549 IDWriteFontFamily *fontFamily = NULL;
550 HRESULT hr = font->GetFontFamily(&fontFamily);
552 IDWriteLocalizedStrings *familyNames = NULL;
554 hr = fontFamily->GetFamilyNames(&familyNames);
559 wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
562 int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);
564 if (defaultLocaleSuccess)
565 hr = familyNames->FindLocaleName(localeName, &index, &exists);
567 if (SUCCEEDED(hr) && !exists)
568 hr = familyNames->FindLocaleName(L
"en-us", &index, &exists);
576 hr = familyNames->GetStringLength(index, &length);
578 wchar_t *
name =
new (std::nothrow)
wchar_t[length+1];
584 hr = familyNames->GetString(index, name, length + 1);
590 if (familyNames != NULL)
591 familyNames->Release();
594 qErrnoWarning(hr,
"initFontInfo: Failed to get family name");
655 #if !defined(QT_NO_DIRECTWRITE) 658 QLatin1String key(
"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\" 671 #if !defined(DEFAULT_GUI_FONT) 672 #define DEFAULT_GUI_FONT 17 676 HDC fontHdc,
int dpi,
bool rawMode,
681 memset(&lf, 0,
sizeof(LOGFONT));
690 font_name = request.
family;
693 bool stockFont =
false;
694 bool preferClearTypeAA =
false;
699 #if !defined(QT_NO_DIRECTWRITE) 702 IDWriteFont *directWriteFont = 0;
704 bool useDirectWrite =
false;
708 int f, deffnt = SYSTEM_FONT;
716 f = SYSTEM_FIXED_FONT;
722 f = DEVICE_DEFAULT_FONT;
730 hfont = (HFONT)GetStockObject(f);
732 qErrnoWarning(
"QFontEngine::loadEngine: GetStockObject failed");
738 int hint = FF_DONTCARE;
750 hint = FF_DECORATIVE;
762 lf.lfOrientation = 0;
764 lf.lfWeight = FW_DONTCARE;
768 lf.lfCharSet = DEFAULT_CHARSET;
770 int strat = OUT_DEFAULT_PRECIS;
772 strat = OUT_RASTER_PRECIS;
775 strat = OUT_DEVICE_PRECIS;
777 strat = OUT_OUTLINE_PRECIS;
779 strat = OUT_TT_ONLY_PRECIS;
783 lf.lfOutPrecision = strat;
785 int qual = DEFAULT_QUALITY;
788 qual = DRAFT_QUALITY;
791 qual = PROOF_QUALITY;
797 preferClearTypeAA =
true;
799 qual = ANTIALIASED_QUALITY;
802 qual = NONANTIALIASED_QUALITY;
807 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
808 lf.lfPitchAndFamily = DEFAULT_PITCH | hint;
822 memcpy(lf.lfFaceName, fam.
utf16(),
sizeof(wchar_t) *
qMin(fam.
length() + 1, 32));
824 hfont = CreateFontIndirect(&lf);
826 qErrnoWarning(
"QFontEngine::loadEngine: CreateFontIndirect failed");
828 stockFont = (hfont == 0);
832 HGDIOBJ oldObj = SelectObject(hdc, hfont);
835 res = GetTextMetrics(hdc, &tm);
836 avWidth = tm.tmAveCharWidth;
837 ttf = tm.tmPitchAndFamily & TMPF_TRUETYPE;
838 SelectObject(hdc, oldObj);
840 if (!ttf || !useDirectWrite) {
841 useDirectWrite =
false;
843 if (hfont && (!ttf || request.
stretch != 100)) {
846 qErrnoWarning(
"QFontEngine::loadEngine: GetTextMetrics failed");
847 lf.lfWidth = avWidth * request.
stretch/100;
848 hfont = CreateFontIndirect(&lf);
850 qErrnoWarning(
"QFontEngine::loadEngine: CreateFontIndirect with stretch failed");
860 hfont = (HFONT)GetStockObject(SYSTEM_FONT);
867 #if !defined(QT_NO_DIRECTWRITE) 871 useDirectWrite =
false;
875 HRESULT hr = DWriteCreateFactory(
876 DWRITE_FACTORY_TYPE_SHARED,
877 __uuidof(IDWriteFactory),
881 qErrnoWarning(
"QFontEngine::loadEngine: DWriteCreateFactory failed");
885 qErrnoWarning(
"QFontEngine::loadEngine: GetGdiInterop failed");
891 memcpy(lf.lfFaceName, nameSubstitute.
utf16(),
892 sizeof(wchar_t) *
qMin(nameSubstitute.
length() + 1, LF_FACESIZE));
899 qErrnoWarning(
"QFontEngine::loadEngine: CreateFontFromLOGFONT failed " 905 useDirectWrite =
true;
914 if (!useDirectWrite) {
916 if (preferClearTypeAA)
925 if (!hbFace || !hbFace->supported_scripts[script]) {
926 FM_DEBUG(
" OpenType support missing for script\n");
936 #if !defined(QT_NO_DIRECTWRITE) 940 IDWriteFontFace *directWriteFontFace = NULL;
941 HRESULT hr = directWriteFont->CreateFontFace(&directWriteFontFace);
951 qErrnoWarning(hr,
"QFontEngine::loadEngine: CreateFontFace failed");
955 if (directWriteFont != 0)
956 directWriteFont->Release();
964 LANGID lid = GetUserDefaultLangID();
1014 const char *stylehint = 0;
1017 stylehint =
"Arial";
1020 stylehint =
"Times New Roman";
1023 stylehint =
"Courier New";
1027 stylehint =
"Courier New";
1047 if (! family_list.
contains(defaultFamily))
1048 family_list << defaultFamily;
1062 for (
int i = 0; i < family_list.
size(); ++i) {
1063 QString family, foundry;
1083 qWarning(
"QFontDatabase::load: Must construct QApplication first");
1117 if (!privateDb()->count)
1131 #if !defined(FR_PRIVATE) 1132 #define FR_PRIVATE 0x10 1143 const quint32 headerTag = *
reinterpret_cast<const quint32 *
>(fontData);
1144 if (headerTag !=
MAKE_TAG(
't',
't',
'c',
'f')) {
1145 if (headerTag !=
MAKE_TAG(0, 1, 0, 0)
1146 && headerTag !=
MAKE_TAG(
'O',
'T',
'T',
'O')
1147 && headerTag !=
MAKE_TAG(
't',
'r',
'u',
'e')
1148 && headerTag !=
MAKE_TAG(
't',
'y',
'p',
'1'))
1154 for (
uint i = 0; i < numFonts; ++i) {
1155 offsets << qFromBigEndian<quint32>(fontData + 12 + i * 4);
1163 for (
uint i = 0; i < numTables; ++i) {
1164 const quint32 offset = 12 + 16 * i;
1165 if (*reinterpret_cast<const quint32 *>(data + offset) == tag) {
1184 for (
int i = 0; i < offsets.
count(); ++i) {
1196 FONTSIGNATURE signature;
1198 if (table && length >= 86) {
1208 memset(&signature, 0,
sizeof(signature));
1219 "AddFontMemResourceEx");
1220 if (!ptrAddFontMemResourceEx)
1231 #ifdef QT_NO_TEMPORARYFILE 1232 wchar_t lpBuffer[MAX_PATH];
1233 GetTempPath(MAX_PATH, lpBuffer);
1239 if (!tempfile.
open())
1245 #ifndef QT_NO_TEMPORARYFILE 1246 tempfile.setAutoRemove(
false);
1261 #endif // Q_OS_WINCE 1281 "AddFontResourceExW");
1282 if (!ptrAddFontResourceExW
1285 #endif // Q_OS_WINCE 1303 bool removeSucceeded = RemoveFontResource((LPCWSTR)font.
fileName.
utf16());
1306 if (!removeSucceeded)
1310 "RemoveFontMemResourceEx");
1311 if (!ptrRemoveFontMemResourceEx
1314 #endif // Q_OS_WINCE 1321 "RemoveFontResourceExW");
1322 if (!ptrRemoveFontResourceExW
1325 #endif // Q_OS_WINCE static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
static bool removeAllApplicationFonts()
Removes all application-local fonts previously added using addApplicationFont() and addApplicationFon...
QString fileName() const
Returns the name set by setFileName() or to the QFile constructors.
static void initFontInfo(QFontEngineWin *fe, const QFontDef &request, HDC fontHdc, int dpi)
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.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
char * data()
Returns a pointer to the data stored in the byte array.
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
int(WINAPI * PtrAddFontResourceExW)(LPCWSTR, DWORD, PVOID)
static PtrAddFontMemResourceEx ptrAddFontMemResourceEx
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
The QSettings class provides persistent platform-independent application settings.
The QByteArray class provides an array of bytes.
int length() const
Returns the number of characters in this string.
The QTemporaryFile class is an I/O device that operates on temporary files.
static const char * ch_TW_tryFonts[]
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
void insertEngine(const Key &key, QFontEngine *engine)
static bool match(const uchar *found, const char *target, uint len)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString absoluteFilePath() const
Returns an absolute path including the file name.
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...
int count(const T &t) const
Returns the number of occurrences of value in the list.
quint32 qFromBigEndian< quint32 >(const uchar *src)
bool ref()
Atomically increments the value of this QAtomicInt.
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
The QString class provides a Unicode character string.
static const char * ch_CN_tryFonts[]
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
static void parseFontName(const QString &name, QString &foundry, QString &family)
This makes sense of the font family name:
The QChar class provides a 16-bit Unicode character.
static QList< quint32 > getTrueTypeFontOffsets(const uchar *fontData)
static const char * kr_tryFonts[]
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
static QFontEngine * loadWin(const QFontPrivate *d, int script, const QFontDef &req)
static QFontCache * instance()
static QFont font()
Returns the default application font.
static QString getEnglishName(const uchar *table, quint32 bytes)
#define MAKE_TAG(ch1, ch2, ch3, ch4)
Q_CORE_EXPORT void qDebug(const char *,...)
static void getFontTable(const uchar *fileBegin, const uchar *data, quint32 tag, const uchar **table, quint32 *length)
void append(const T &t)
Inserts value at the end of the list.
static void getEngineData(const QFontPrivate *d, const QFontCache::Key &key)
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QFontDatabase class provides information about the fonts available in the underlying window syste...
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.
static const char * jp_tryFonts[]
static HFONT stock_sysfont
int size() const
Returns the number of characters in this string.
const QChar * unicode() const
Returns a '\0'-terminated Unicode representation of the string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QTextStream & fixed(QTextStream &stream)
Calls QTextStream::setRealNumberNotation(QTextStream::FixedNotation) on stream and returns stream...
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
static int toInt(const QByteArray &str)
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
const char * styleHint(const QFontDef &request)
Q_CORE_EXPORT void qWarning(const char *,...)
BOOL(WINAPI * PtrRemoveFontMemResourceEx)(HANDLE)
static const char * data(const QByteArray &arr)
static bool supportsThreadedFontRendering()
Returns true if font rendering is supported outside the GUI thread, false otherwise.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
BOOL(WINAPI * PtrRemoveFontResourceExW)(LPCWSTR, DWORD, PVOID)
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
static void populate_database(const QString &fam)
QtFontFoundry ** foundries
static bool removeApplicationFont(int id)
Removes the previously loaded application font identified by id.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
const T & at(int i) const
Returns the item at index position i in the vector.
QtFontFamily * family(const QString &f, bool=false)
static quint16 getUShort(const unsigned char *p)
quint16 qFromBigEndian< quint16 >(const uchar *src)
#define TRUE
Synonym for true.
void resize(int size)
Sets the size of the string to size characters.
const char * constData() const
Returns a pointer to the data stored in the byte array.
static void load(const QString &family=QString(), int=-1)
static void addFontToDatabase(QString familyName, const QString &scriptName, TEXTMETRIC *textmetric, const FONTSIGNATURE *signature, int type)
bool isNull() const
Returns true if this string is null; otherwise returns false.
static QString fontNameSubstitute(const QString &familyName)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
void * resolve(const char *symbol)
#define CLEARTYPE_QUALITY
The QFile class provides an interface for reading from and writing to files.
static bool scriptRequiresOpenType(int script)
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QtFontSize * pixelSize(unsigned short size, bool=false)
static QFontEngine * loadEngine(int script, const QFontDef &request, HDC fontHdc, int dpi, bool rawMode, const QtFontDesc *desc, const QStringList &family_list)
QString family() const
Returns the requested font family name, i.e.
Q_GUI_EXPORT int qt_defaultDpi()
QVector< FONTSIGNATURE > signatures
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
QFont::Weight weightFromInteger(int weight)
int size() const
Returns the number of items in the list.
static HFONT systemFont()
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
int size() const
Returns the number of bytes in this byte array.
bool remove()
Removes the file specified by fileName().
static int CALLBACK storeFont(ENUMLOGFONTEX *f, NEWTEXTMETRICEX *textmetric, int type, LPARAM)
QString defaultFamily() const
Returns the family name that corresponds to the current style hint.
static void initializeDb()
static const char * other_tryFonts[]
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QFontEngine * findEngine(const Key &key)
static void getFamiliesAndSignatures(const QByteArray &fontData, QFontDatabasePrivate::ApplicationFont *appFont)
QVector< ApplicationFont > applicationFonts
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
QtFontFoundry * foundry(const QString &f, bool=false)
IDWriteGdiInterop * directWriteGdiInterop
The QFileInfo class provides system-independent file information.
static const char ** tryFonts
QFontEngineData * engineData
virtual void close()
Calls QFile::flush() and closes the file.
#define qPrintable(string)
IDWriteFactory * directWriteFactory
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
HANDLE(WINAPI * PtrAddFontMemResourceEx)(PVOID, DWORD, PVOID, DWORD *)
Q_DECL_CONSTEXPR int qRound(qreal d)
QFontEngine * qt_load_font_engine_win(const QFontDef &request)
static bool localizedName(const QString &name)
QList< QFontDatabase::WritingSystem > qt_determine_writing_systems_from_truetype_bits(quint32 unicodeRange[4], quint32 codePageRange[2])
static PtrRemoveFontMemResourceEx ptrRemoveFontMemResourceEx
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
void qErrnoWarning(const char *msg,...)
HB_Face harfbuzzFace() const