wasm: use public API for converting from Uint8Array

Use the new QByteAaray::fromUint8Array() function.

Change-Id: I7bb7a8184e1bfde2a89af2efb331db64f0b4d285
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
This commit is contained in:
Morten Sørvig 2022-10-12 14:25:18 +02:00
parent 3c24bb026e
commit b36e624c89

View File

@ -12,21 +12,6 @@
#include <emscripten/val.h>
#include <emscripten/bind.h>
// FIXME: replace with shared implementation from qstdweb
QByteArray fromUint8Array(emscripten::val uint8array)
{
qstdweb::ArrayBuffer arrayBuffer(uint8array);
using qstdweb::Uint8Array;
Uint8Array sourceArray(arrayBuffer);
if (sourceArray.length() > std::numeric_limits<qsizetype>::max())
return QByteArray();
QByteArray destinationArray;
destinationArray.resize(sourceArray.length());
sourceArray.copyTo(destinationArray.data());
return destinationArray;
}
QT_BEGIN_NAMESPACE
using namespace emscripten;
@ -121,7 +106,7 @@ void QWasmFontDatabase::populateFamily(const QString &familyName)
.thenFunc = [](val status) {
qCDebug(lcQpaFonts) << "onArrayBuffer" ;
QByteArray fontByteArray = fromUint8Array(status);
QByteArray fontByteArray = QByteArray::fromUint8Array(status);
QFreeTypeFontDatabase::addTTFile(fontByteArray, QByteArray());