diff --git a/tests/manual/wasm/CMakeLists.txt b/tests/manual/wasm/CMakeLists.txt index f625defb21e..b13f6781b86 100644 --- a/tests/manual/wasm/CMakeLists.txt +++ b/tests/manual/wasm/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(a11y) if(QT_FEATURE_widgets) add_subdirectory(cursors) add_subdirectory(localfiles) +add_subdirectory(localfonts) add_subdirectory(qstdweb) add_subdirectory(clipboard) endif() diff --git a/tests/manual/wasm/localfonts/CMakeLists.txt b/tests/manual/wasm/localfonts/CMakeLists.txt new file mode 100644 index 00000000000..b5df4ad9fa6 --- /dev/null +++ b/tests/manual/wasm/localfonts/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +add_subdirectory(fontloading) diff --git a/tests/manual/wasm/localfonts/fontloading/CMakeLists.txt b/tests/manual/wasm/localfonts/fontloading/CMakeLists.txt new file mode 100644 index 00000000000..c3dc37d27dc --- /dev/null +++ b/tests/manual/wasm/localfonts/fontloading/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +qt_internal_add_manual_test(fontloading + GUI + SOURCES + main.cpp + LIBRARIES + Qt::Core + Qt::Gui + Qt::Widgets +) + +add_custom_command( + TARGET fontloading POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/fontloading.html + ${CMAKE_CURRENT_BINARY_DIR}/fontloading.html) +#add_custom_target(html DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fontloading.html) +#add_dependencies(fontloading html) diff --git a/tests/manual/wasm/localfonts/fontloading/fontloading.html b/tests/manual/wasm/localfonts/fontloading/fontloading.html new file mode 100644 index 00000000000..619217205be --- /dev/null +++ b/tests/manual/wasm/localfonts/fontloading/fontloading.html @@ -0,0 +1,167 @@ + + + + + + + + + + +

Local Font Loading Test

+

Click "Load" button below to load the Qt test app with the specified settings. This test provides additional logs on the JavaScript console.

+ +
+
+ Browser supports the Local Font Access API:
+ Local Font Access permission status:
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + Startup time:
+ Font family count:
+ Font families:
+
+ + +
+
+ +
+ +
+
+ + diff --git a/tests/manual/wasm/localfonts/fontloading/main.cpp b/tests/manual/wasm/localfonts/fontloading/main.cpp new file mode 100644 index 00000000000..fb8f8e268ba --- /dev/null +++ b/tests/manual/wasm/localfonts/fontloading/main.cpp @@ -0,0 +1,78 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include +#include + +#include +#include + +using namespace emscripten; + +class FontViewer : public QWidget +{ +public: + FontViewer() { + QTextEdit *edit = new QTextEdit; + edit->setPlainText("The quick brown fox jumps over the lazy dog\nHow quickly daft jumping zebras vex\nPack my box with five dozen liquor jugs"); + + QComboBox *combo = new QComboBox; + combo->addItems(QFontDatabase::families()); + + connect(combo, &QComboBox::currentTextChanged, [=](const QString &family) { + QFont font(family); + edit->setFont(font); + }); + + QObject::connect(qApp, &QGuiApplication::fontDatabaseChanged, [=]() { + QStringList families = QFontDatabase::families(); + combo->clear(); + combo->addItems(families); + }); + + QLayout *layout = new QVBoxLayout; + layout->addWidget(edit); + layout->addWidget(combo); + setLayout(layout); + } +}; + +FontViewer *g_viewer = nullptr; +QApplication *g_app = nullptr; + +void deleteapp() { + delete g_viewer; + delete g_app; +}; + +EMSCRIPTEN_BINDINGS(fonloading) { + function("deleteapp", &deleteapp); +} + +int main(int argc, char **argv) +{ + qDebug() << "C++ main: Creating application"; + g_app = new QApplication(argc, argv); + + // Make sure there is one call to fontFamiliesLoaded at startup, + // even if no further fonts are loaded. + QTimer::singleShot(0, [=]() { + emscripten::val window = emscripten::val::global("window"); + window.call("fontFamiliesLoaded", QFontDatabase::families().count()); + }); + + g_viewer = new FontViewer(); + g_viewer->show(); + + QObject::connect(g_app, &QGuiApplication::fontDatabaseChanged, [=]() { + QStringList families = QFontDatabase::families(); + + emscripten::val window = emscripten::val::global("window"); + + window.call("fontFamiliesLoaded", families.count()); + for (int i = 0; i < families.count(); ++i) { + window.call("fontFamilyLoaded", families[i].toStdString()); + } + }); +} +