wasm: support setting the font DPI from JS
We have not really been able to determine what the default DPI should be, so make it configurable with API on qtloader.js: qtLoader.setFontDpi(72); Also lowers the default DPI to the standard value of 96 (down from Qt default 100). Task-number: QTBUG-75510 Change-Id: Ica1164c8d80bb06519233adebf2c9e400c0991ce Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
parent
ffdcad9e40
commit
56acf089c7
|
|
@ -124,6 +124,8 @@
|
|||
// Remove canvas at run-time. Removes the corresponding QScreen.
|
||||
// resizeCanvasElement
|
||||
// Signals to the application that a canvas has been resized.
|
||||
// setFontDpi
|
||||
// Sets the logical font dpi for the application.
|
||||
|
||||
|
||||
var Module = {}
|
||||
|
|
@ -237,6 +239,8 @@ function QtLoader(config)
|
|||
publicAPI.addCanvasElement = addCanvasElement;
|
||||
publicAPI.removeCanvasElement = removeCanvasElement;
|
||||
publicAPI.resizeCanvasElement = resizeCanvasElement;
|
||||
publicAPI.setFontDpi = setFontDpi;
|
||||
publicAPI.fontDpi = fontDpi;
|
||||
|
||||
restartCount = 0;
|
||||
|
||||
|
|
@ -557,6 +561,16 @@ function QtLoader(config)
|
|||
Module.qtResizeCanvasElement(element);
|
||||
}
|
||||
|
||||
function setFontDpi(dpi) {
|
||||
Module.qtFontDpi = dpi;
|
||||
if (publicAPI.status == "Running")
|
||||
Module.qtSetFontDpi(dpi);
|
||||
}
|
||||
|
||||
function fontDpi() {
|
||||
return Module.qtFontDpi;
|
||||
}
|
||||
|
||||
setStatus("Created");
|
||||
|
||||
return publicAPI;
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@
|
|||
#include <QtCore/qcoreapplication.h>
|
||||
|
||||
#include <emscripten/bind.h>
|
||||
#include <emscripten/val.h>
|
||||
|
||||
// this is where EGL headers are pulled in, make sure it is last
|
||||
#include "qwasmscreen.h"
|
||||
|
|
@ -80,12 +81,18 @@ static void resizeCanvasElement(emscripten::val canvas)
|
|||
QWasmIntegration::get()->resizeScreen(canvasId);
|
||||
}
|
||||
|
||||
static void qtUpdateDpi()
|
||||
{
|
||||
QWasmIntegration::get()->updateDpi();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(qtQWasmIntegraton)
|
||||
{
|
||||
function("qtBrowserBeforeUnload", &browserBeforeUnload);
|
||||
function("qtAddCanvasElement", &addCanvasElement);
|
||||
function("qtRemoveCanvasElement", &removeCanvasElement);
|
||||
function("qtResizeCanvasElement", &resizeCanvasElement);
|
||||
function("qtUpdateDpi", &qtUpdateDpi);
|
||||
}
|
||||
|
||||
QWasmIntegration *QWasmIntegration::s_instance;
|
||||
|
|
@ -245,4 +252,14 @@ void QWasmIntegration::resizeScreen(const QString &canvasId)
|
|||
m_screens.value(canvasId)->updateQScreenAndCanvasRenderSize();
|
||||
}
|
||||
|
||||
void QWasmIntegration::updateDpi()
|
||||
{
|
||||
emscripten::val dpi = emscripten::val::module_property("qtFontDpi");
|
||||
if (dpi.isUndefined())
|
||||
return;
|
||||
qreal dpiValue = dpi.as<qreal>();
|
||||
for (QWasmScreen *screen : m_screens)
|
||||
QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen->screen(), dpiValue, dpiValue);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ public:
|
|||
void addScreen(const QString &canvasId);
|
||||
void removeScreen(const QString &canvasId);
|
||||
void resizeScreen(const QString &canvasId);
|
||||
void updateDpi();
|
||||
|
||||
private:
|
||||
mutable QWasmFontDatabase *m_fontDb;
|
||||
|
|
@ -89,6 +90,7 @@ private:
|
|||
|
||||
QHash<QString, QWasmScreen *> m_screens;
|
||||
mutable QWasmClipboard *m_clipboard;
|
||||
qreal m_fontDpi = -1;
|
||||
static QWasmIntegration *s_instance;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "qwasmwindow.h"
|
||||
#include "qwasmeventtranslator.h"
|
||||
#include "qwasmcompositor.h"
|
||||
#include "qwasmintegration.h"
|
||||
#include <emscripten/bind.h>
|
||||
#include <emscripten/val.h>
|
||||
|
||||
|
|
@ -100,6 +101,17 @@ QImage::Format QWasmScreen::format() const
|
|||
return m_format;
|
||||
}
|
||||
|
||||
QDpi QWasmScreen::logicalDpi() const
|
||||
{
|
||||
emscripten::val dpi = emscripten::val::module_property("qtFontDpi");
|
||||
if (!dpi.isUndefined()) {
|
||||
qreal dpiValue = dpi.as<qreal>();
|
||||
return QDpi(dpiValue, dpiValue);
|
||||
}
|
||||
const qreal defaultDpi = 96;
|
||||
return QDpi(defaultDpi, defaultDpi);
|
||||
}
|
||||
|
||||
qreal QWasmScreen::devicePixelRatio() const
|
||||
{
|
||||
// FIXME: The effective device pixel ratio may be different from the
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ public:
|
|||
QRect geometry() const override;
|
||||
int depth() const override;
|
||||
QImage::Format format() const override;
|
||||
QDpi logicalDpi() const override;
|
||||
qreal devicePixelRatio() const override;
|
||||
QString name() const override;
|
||||
QPlatformCursor *cursor() const override;
|
||||
|
|
|
|||
Loading…
Reference in New Issue