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",
|
||||
"QDocModule": "qtgui",
|
||||
"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.",
|
||||
|
||||
"Homepage": "https://dejavu-fonts.github.io/",
|
||||
|
@ -142,7 +142,6 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q
|
||||
weight = QFont::Bold;
|
||||
|
||||
bool fixedPitch = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH);
|
||||
|
||||
QSupportedWritingSystems writingSystems;
|
||||
// detect symbol fonts
|
||||
for (int i = 0; i < face->num_charmaps; ++i) {
|
||||
|
@ -38,9 +38,9 @@ void QWasmFontDatabase::populateFontDatabase()
|
||||
// Load font file from resources. Currently
|
||||
// all fonts needs to be bundled with the nexe
|
||||
// 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");
|
||||
|
||||
foreach (const QString &fontFileName, fontFileNames) {
|
||||
QFile theFont(fontFileName);
|
||||
if (!theFont.open(QIODevice::ReadOnly))
|
||||
@ -82,5 +82,9 @@ void QWasmFontDatabase::releaseHandle(void *handle)
|
||||
QFreeTypeFontDatabase::releaseHandle(handle);
|
||||
}
|
||||
|
||||
QFont QWasmFontDatabase::defaultFont() const
|
||||
{
|
||||
return QFont(QLatin1String("Bitstream Vera Sans"));
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
QChar::Script script) const override;
|
||||
QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName) override;
|
||||
void releaseHandle(void *handle) override;
|
||||
QFont defaultFont() const override;
|
||||
};
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
@ -29,15 +29,22 @@
|
||||
|
||||
#include "qwasmtheme.h"
|
||||
#include <QtCore/qvariant.h>
|
||||
#include <QFontDatabase>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QWasmTheme::QWasmTheme()
|
||||
{
|
||||
QFontDatabase fdb;
|
||||
for (auto family : fdb.families())
|
||||
if (fdb.isFixedPitch(family))
|
||||
fixedFont = new QFont(family);
|
||||
}
|
||||
|
||||
QWasmTheme::~QWasmTheme()
|
||||
{
|
||||
if (fixedFont)
|
||||
delete fixedFont;
|
||||
}
|
||||
|
||||
QVariant QWasmTheme::themeHint(ThemeHint hint) const
|
||||
@ -47,4 +54,12 @@ QVariant QWasmTheme::themeHint(ThemeHint hint) const
|
||||
return QPlatformTheme::themeHint(hint);
|
||||
}
|
||||
|
||||
const QFont *QWasmTheme::font(Font type) const
|
||||
{
|
||||
if (type == QPlatformTheme::FixedFont) {
|
||||
return fixedFont;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -31,6 +31,7 @@
|
||||
#define QWASMTHEME_H
|
||||
|
||||
#include <qpa/qplatformtheme.h>
|
||||
#include <QtGui/QFont>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -49,6 +50,8 @@ public:
|
||||
~QWasmTheme();
|
||||
|
||||
QVariant themeHint(ThemeHint hint) const override;
|
||||
const QFont *font(Font type) const override;
|
||||
QFont *fixedFont = nullptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -39,7 +39,8 @@ HEADERS = \
|
||||
|
||||
wasmfonts.files = \
|
||||
../../../3rdparty/wasm/Vera.ttf \
|
||||
../../../3rdparty/wasm/DejaVuSans.ttf
|
||||
../../../3rdparty/wasm/DejaVuSans.ttf \
|
||||
../../../3rdparty/wasm/DejaVuSansMono.ttf
|
||||
wasmfonts.prefix = /fonts
|
||||
wasmfonts.base = ../../../3rdparty/wasm
|
||||
RESOURCES += wasmfonts
|
||||
|
Loading…
x
Reference in New Issue
Block a user