wasm: add fixedPitch font
Also define our default font so as to return something we actually have Task-number: QTBUG-75587 Change-Id: I26e3c62921d369c3017af9796c0a20f7ac06d07c Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
8ea0a82a6a
commit
050e7bafad
BIN
src/3rdparty/wasm/DejaVuSansMono.ttf
vendored
Normal file
BIN
src/3rdparty/wasm/DejaVuSansMono.ttf
vendored
Normal file
Binary file not shown.
2
src/3rdparty/wasm/qt_attribution.json
vendored
2
src/3rdparty/wasm/qt_attribution.json
vendored
@ -20,7 +20,7 @@
|
|||||||
"Name": "DejaVu Fonts",
|
"Name": "DejaVu Fonts",
|
||||||
"QDocModule": "qtgui",
|
"QDocModule": "qtgui",
|
||||||
"QtUsage": "Used for WebAssembly platform.",
|
"QtUsage": "Used for WebAssembly platform.",
|
||||||
"Files": "DejaVuSans.ttf",
|
"Files": "DejaVuSans.ttf, DejaVuSansMono.ttf",
|
||||||
"Description": "The DejaVu fonts are a font family based on the Vera Fonts.",
|
"Description": "The DejaVu fonts are a font family based on the Vera Fonts.",
|
||||||
|
|
||||||
"Homepage": "https://dejavu-fonts.github.io/",
|
"Homepage": "https://dejavu-fonts.github.io/",
|
||||||
|
@ -142,7 +142,6 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q
|
|||||||
weight = QFont::Bold;
|
weight = QFont::Bold;
|
||||||
|
|
||||||
bool fixedPitch = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH);
|
bool fixedPitch = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH);
|
||||||
|
|
||||||
QSupportedWritingSystems writingSystems;
|
QSupportedWritingSystems writingSystems;
|
||||||
// detect symbol fonts
|
// detect symbol fonts
|
||||||
for (int i = 0; i < face->num_charmaps; ++i) {
|
for (int i = 0; i < face->num_charmaps; ++i) {
|
||||||
|
@ -38,9 +38,9 @@ void QWasmFontDatabase::populateFontDatabase()
|
|||||||
// Load font file from resources. Currently
|
// Load font file from resources. Currently
|
||||||
// all fonts needs to be bundled with the nexe
|
// all fonts needs to be bundled with the nexe
|
||||||
// as Qt resources.
|
// as Qt resources.
|
||||||
QStringList fontFileNames = QStringList() << QStringLiteral(":/fonts/Vera.ttf")
|
QStringList fontFileNames = QStringList() << QStringLiteral(":/fonts/DejaVuSansMono.ttf")
|
||||||
|
<< QStringLiteral(":/fonts/Vera.ttf")
|
||||||
<< QStringLiteral(":/fonts/DejaVuSans.ttf");
|
<< QStringLiteral(":/fonts/DejaVuSans.ttf");
|
||||||
|
|
||||||
foreach (const QString &fontFileName, fontFileNames) {
|
foreach (const QString &fontFileName, fontFileNames) {
|
||||||
QFile theFont(fontFileName);
|
QFile theFont(fontFileName);
|
||||||
if (!theFont.open(QIODevice::ReadOnly))
|
if (!theFont.open(QIODevice::ReadOnly))
|
||||||
@ -82,5 +82,9 @@ void QWasmFontDatabase::releaseHandle(void *handle)
|
|||||||
QFreeTypeFontDatabase::releaseHandle(handle);
|
QFreeTypeFontDatabase::releaseHandle(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFont QWasmFontDatabase::defaultFont() const
|
||||||
|
{
|
||||||
|
return QFont(QLatin1String("Bitstream Vera Sans"));
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -44,6 +44,7 @@ public:
|
|||||||
QChar::Script script) const override;
|
QChar::Script script) const override;
|
||||||
QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName) override;
|
QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName) override;
|
||||||
void releaseHandle(void *handle) override;
|
void releaseHandle(void *handle) override;
|
||||||
|
QFont defaultFont() const override;
|
||||||
};
|
};
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,15 +29,22 @@
|
|||||||
|
|
||||||
#include "qwasmtheme.h"
|
#include "qwasmtheme.h"
|
||||||
#include <QtCore/qvariant.h>
|
#include <QtCore/qvariant.h>
|
||||||
|
#include <QFontDatabase>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
QWasmTheme::QWasmTheme()
|
QWasmTheme::QWasmTheme()
|
||||||
{
|
{
|
||||||
|
QFontDatabase fdb;
|
||||||
|
for (auto family : fdb.families())
|
||||||
|
if (fdb.isFixedPitch(family))
|
||||||
|
fixedFont = new QFont(family);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWasmTheme::~QWasmTheme()
|
QWasmTheme::~QWasmTheme()
|
||||||
{
|
{
|
||||||
|
if (fixedFont)
|
||||||
|
delete fixedFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant QWasmTheme::themeHint(ThemeHint hint) const
|
QVariant QWasmTheme::themeHint(ThemeHint hint) const
|
||||||
@ -47,4 +54,12 @@ QVariant QWasmTheme::themeHint(ThemeHint hint) const
|
|||||||
return QPlatformTheme::themeHint(hint);
|
return QPlatformTheme::themeHint(hint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QFont *QWasmTheme::font(Font type) const
|
||||||
|
{
|
||||||
|
if (type == QPlatformTheme::FixedFont) {
|
||||||
|
return fixedFont;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#define QWASMTHEME_H
|
#define QWASMTHEME_H
|
||||||
|
|
||||||
#include <qpa/qplatformtheme.h>
|
#include <qpa/qplatformtheme.h>
|
||||||
|
#include <QtGui/QFont>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -49,6 +50,8 @@ public:
|
|||||||
~QWasmTheme();
|
~QWasmTheme();
|
||||||
|
|
||||||
QVariant themeHint(ThemeHint hint) const override;
|
QVariant themeHint(ThemeHint hint) const override;
|
||||||
|
const QFont *font(Font type) const override;
|
||||||
|
QFont *fixedFont = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -39,7 +39,8 @@ HEADERS = \
|
|||||||
|
|
||||||
wasmfonts.files = \
|
wasmfonts.files = \
|
||||||
../../../3rdparty/wasm/Vera.ttf \
|
../../../3rdparty/wasm/Vera.ttf \
|
||||||
../../../3rdparty/wasm/DejaVuSans.ttf
|
../../../3rdparty/wasm/DejaVuSans.ttf \
|
||||||
|
../../../3rdparty/wasm/DejaVuSansMono.ttf
|
||||||
wasmfonts.prefix = /fonts
|
wasmfonts.prefix = /fonts
|
||||||
wasmfonts.base = ../../../3rdparty/wasm
|
wasmfonts.base = ../../../3rdparty/wasm
|
||||||
RESOURCES += wasmfonts
|
RESOURCES += wasmfonts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user