mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 04:24:28 +00:00
wasm: intoduce saveTvg via File System API
This patch adds saveTvg() function into thorvgwasm.cpp. Functions saves tvg using File System API. To enable fs, changed build flag: -s FORCE_FILESYSTEM=1. Increase in result thorvg-wasm.js size: about 68kB to about 125kB.
This commit is contained in:
parent
fe474856b9
commit
7be4bf4c4f
2 changed files with 24 additions and 3 deletions
|
@ -139,6 +139,25 @@ public:
|
||||||
return val(typed_memory_view(mWidth * mHeight * 4, mBuffer.get()));
|
return val(typed_memory_view(mWidth * mHeight * 4, mBuffer.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool saveTvg()
|
||||||
|
{
|
||||||
|
mErrorMsg = "None";
|
||||||
|
|
||||||
|
auto saver = tvg::Saver::gen();
|
||||||
|
auto duplicate = unique_ptr<tvg::Picture>(static_cast<tvg::Picture*>(mPicture->duplicate()));
|
||||||
|
if (!saver || !duplicate) {
|
||||||
|
mErrorMsg = "Saving initialization failed";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (saver->save(move(duplicate), "file.tvg") != tvg::Result::Success) {
|
||||||
|
mErrorMsg = "Tvg saving failed";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
saver->sync();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ThorvgWasm()
|
explicit ThorvgWasm()
|
||||||
{
|
{
|
||||||
|
@ -183,5 +202,7 @@ EMSCRIPTEN_BINDINGS(thorvg_bindings) {
|
||||||
.function("getDefaultData", &ThorvgWasm::getDefaultData, allow_raw_pointers())
|
.function("getDefaultData", &ThorvgWasm::getDefaultData, allow_raw_pointers())
|
||||||
.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("saveTvg", &ThorvgWasm::saveTvg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ ar = 'EMSDK:upstream/emscripten/emar.py'
|
||||||
|
|
||||||
[properties]
|
[properties]
|
||||||
root = 'EMSDK:upstream/emscripten/system'
|
root = 'EMSDK:upstream/emscripten/system'
|
||||||
cpp_args = ['--bind' , '-s' , 'WASM=1' , '-s' , 'ALLOW_MEMORY_GROWTH=1' , '-s' , 'FILESYSTEM=0' , '-O2']
|
cpp_args = ['--bind' , '-s' , 'WASM=1' , '-s' , 'ALLOW_MEMORY_GROWTH=1' , '-s' , 'FORCE_FILESYSTEM=1' , '-O2']
|
||||||
cpp_link_args = ['--bind' , '-s' , 'WASM=1' , '-s' , 'ALLOW_MEMORY_GROWTH=1' , '-s' , 'FILESYSTEM=0' , '-O2']
|
cpp_link_args = ['--bind' , '-s' , 'WASM=1' , '-s' , 'ALLOW_MEMORY_GROWTH=1' , '-s' , 'FORCE_FILESYSTEM=1' , '-O2']
|
||||||
shared_lib_suffix = 'js'
|
shared_lib_suffix = 'js'
|
||||||
static_lib_suffix = 'js'
|
static_lib_suffix = 'js'
|
||||||
shared_module_suffix = 'js'
|
shared_module_suffix = 'js'
|
||||||
|
|
Loading…
Add table
Reference in a new issue