mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-28 00:57:09 +00:00
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:
parent
79933d9efa
commit
f732479acc
1 changed files with 11 additions and 2 deletions
|
@ -48,7 +48,7 @@ public:
|
|||
return defaultData;
|
||||
}
|
||||
|
||||
bool load(string data, int width, int height)
|
||||
bool load(string data, string mimetype, int width, int height)
|
||||
{
|
||||
mErrorMsg = "None";
|
||||
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
mSwCanvas->clear();
|
||||
|
||||
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 */
|
||||
delete(mPicture);
|
||||
mPicture = nullptr;
|
||||
|
@ -75,6 +75,8 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
mPicture->size(&mOriginalSize[0], &mOriginalSize[1]);
|
||||
|
||||
/* need to reset size to calculate scale in Picture.size internally
|
||||
before calling updateSize */
|
||||
mWidth = 0;
|
||||
|
@ -131,6 +133,11 @@ public:
|
|||
return val(typed_memory_view(mWidth * mHeight * 4, mBuffer.get()));
|
||||
}
|
||||
|
||||
val originalSize()
|
||||
{
|
||||
return val(typed_memory_view(2, mOriginalSize));
|
||||
}
|
||||
|
||||
bool saveTvg()
|
||||
{
|
||||
mErrorMsg = "None";
|
||||
|
@ -184,6 +191,7 @@ private:
|
|||
|
||||
uint32_t mWidth{0};
|
||||
uint32_t mHeight{0};
|
||||
float mOriginalSize[2];
|
||||
};
|
||||
|
||||
// Binding code
|
||||
|
@ -195,6 +203,7 @@ EMSCRIPTEN_BINDINGS(thorvg_bindings) {
|
|||
.function("load", &ThorvgWasm::load)
|
||||
.function("update", &ThorvgWasm::update)
|
||||
.function("render", &ThorvgWasm::render)
|
||||
.function("originalSize", &ThorvgWasm::originalSize)
|
||||
|
||||
.function("saveTvg", &ThorvgWasm::saveTvg);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue