wasm: pass mimetype on loading and store original size

This patch adds the mimetype parameter for load() function and adds storing of
an original size after successful loading. Added function originalSize().
This commit is contained in:
Michal Maciola 2021-09-08 17:05:10 +02:00 committed by Hermet Park
parent 79933d9efa
commit f732479acc

View file

@ -48,7 +48,7 @@ public:
return defaultData; return defaultData;
} }
bool load(string data, int width, int height) bool load(string data, string mimetype, int width, int height)
{ {
mErrorMsg = "None"; mErrorMsg = "None";
@ -66,7 +66,7 @@ public:
mSwCanvas->clear(); mSwCanvas->clear();
if (data.empty()) data = defaultData; if (data.empty()) data = defaultData;
if (mPicture->load(data.c_str(), data.size()) != Result::Success) { if (mPicture->load(data.c_str(), data.size(), mimetype, false) != Result::Success) {
/* mPicture is not handled as unique_ptr yet, so delete here */ /* mPicture is not handled as unique_ptr yet, so delete here */
delete(mPicture); delete(mPicture);
mPicture = nullptr; mPicture = nullptr;
@ -75,6 +75,8 @@ public:
return false; return false;
} }
mPicture->size(&mOriginalSize[0], &mOriginalSize[1]);
/* need to reset size to calculate scale in Picture.size internally /* need to reset size to calculate scale in Picture.size internally
before calling updateSize */ before calling updateSize */
mWidth = 0; mWidth = 0;
@ -131,6 +133,11 @@ public:
return val(typed_memory_view(mWidth * mHeight * 4, mBuffer.get())); return val(typed_memory_view(mWidth * mHeight * 4, mBuffer.get()));
} }
val originalSize()
{
return val(typed_memory_view(2, mOriginalSize));
}
bool saveTvg() bool saveTvg()
{ {
mErrorMsg = "None"; mErrorMsg = "None";
@ -184,6 +191,7 @@ private:
uint32_t mWidth{0}; uint32_t mWidth{0};
uint32_t mHeight{0}; uint32_t mHeight{0};
float mOriginalSize[2];
}; };
// Binding code // Binding code
@ -195,6 +203,7 @@ EMSCRIPTEN_BINDINGS(thorvg_bindings) {
.function("load", &ThorvgWasm::load) .function("load", &ThorvgWasm::load)
.function("update", &ThorvgWasm::update) .function("update", &ThorvgWasm::update)
.function("render", &ThorvgWasm::render) .function("render", &ThorvgWasm::render)
.function("originalSize", &ThorvgWasm::originalSize)
.function("saveTvg", &ThorvgWasm::saveTvg); .function("saveTvg", &ThorvgWasm::saveTvg);
} }