mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
tvg_format: save/restore default view size in the data.
current bounding box of the paint is the default view size... Do we have any better information of that?
This commit is contained in:
parent
eb810a92f2
commit
87c6ce1f7c
7 changed files with 32 additions and 7 deletions
|
@ -37,6 +37,11 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
cout << "TVG is not supported. Did you enable TVG Loader?" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
float w, h;
|
||||
picture->size(&w, &h);
|
||||
cout << "default tvg view size = " << w << " x " << h << endl;
|
||||
|
||||
canvas->push(move(picture));
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -66,7 +66,7 @@ static TvgBinBlock _readBlock(const char *ptr)
|
|||
return block;
|
||||
}
|
||||
|
||||
static bool _readTvgHeader(const char **ptr)
|
||||
static bool _readTvgHeader(const char **ptr, float* w, float* h)
|
||||
{
|
||||
if (!*ptr) return false;
|
||||
|
||||
|
@ -78,6 +78,14 @@ static bool _readTvgHeader(const char **ptr)
|
|||
if (memcmp(*ptr, TVG_HEADER_VERSION, TVG_HEADER_VERSION_LENGTH)) return false;
|
||||
*ptr += TVG_HEADER_VERSION_LENGTH;
|
||||
|
||||
//View width
|
||||
if (w) _read_tvg_float(w, *ptr);
|
||||
*ptr += sizeof(float);
|
||||
|
||||
//View height
|
||||
if (h) _read_tvg_float(h, *ptr);
|
||||
*ptr += sizeof(float);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -477,10 +485,10 @@ static Paint* _parsePaint(TvgBinBlock baseBlock)
|
|||
/* External Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
bool tvgValidateData(const char *ptr, uint32_t size)
|
||||
bool tvgValidateData(const char *ptr, uint32_t size, float* w, float* h)
|
||||
{
|
||||
auto end = ptr + size;
|
||||
if (!_readTvgHeader(&ptr) || ptr >= end) return false;
|
||||
if (!_readTvgHeader(&ptr, w, h) || ptr >= end) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -488,7 +496,7 @@ unique_ptr<Scene> tvgLoadData(const char *ptr, uint32_t size)
|
|||
{
|
||||
auto end = ptr + size;
|
||||
|
||||
if (!_readTvgHeader(&ptr) || ptr >= end) {
|
||||
if (!_readTvgHeader(&ptr, nullptr, nullptr) || ptr >= end) {
|
||||
TVGLOG("TVG", "Invalid TVG Data!");
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "tvgCommon.h"
|
||||
#include "tvgBinaryDesc.h"
|
||||
|
||||
bool tvgValidateData(const char *ptr, uint32_t size);
|
||||
bool tvgValidateData(const char *ptr, uint32_t size, float* w, float* h);
|
||||
unique_ptr<Scene> tvgLoadData(const char *ptr, uint32_t size);
|
||||
|
||||
#endif //_TVG_TVG_LOAD_PARSER_H_
|
||||
|
|
|
@ -82,7 +82,7 @@ bool TvgLoader::open(const string &path)
|
|||
|
||||
pointer = data;
|
||||
|
||||
return tvgValidateData(pointer, size);
|
||||
return tvgValidateData(pointer, size, &w, &h);
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,7 +100,7 @@ bool TvgLoader::open(const char *data, uint32_t size, bool copy)
|
|||
this->size = size;
|
||||
this->copy = copy;
|
||||
|
||||
return tvgValidateData(pointer, size);
|
||||
return tvgValidateData(pointer, size, &w, &h);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,6 +69,16 @@ bool TvgSaver::writeHeader()
|
|||
}
|
||||
|
||||
|
||||
bool TvgSaver::writeViewSize()
|
||||
{
|
||||
float var[2];
|
||||
paint->bounds(nullptr, nullptr, &var[0], &var[1]);
|
||||
writeData(var, sizeof(var));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void TvgSaver::writeTag(TvgBinTag tag)
|
||||
{
|
||||
buffer.grow(SIZE(TvgBinTag));
|
||||
|
@ -393,6 +403,7 @@ TvgBinCounter TvgSaver::serialize(const Paint* paint)
|
|||
void TvgSaver::run(unsigned tid)
|
||||
{
|
||||
if (!writeHeader()) return;
|
||||
if (!writeViewSize()) return;
|
||||
if (serialize(paint) == 0) return;
|
||||
if (!flushTo(path)) return;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ private:
|
|||
void reserveCount();
|
||||
|
||||
bool writeHeader();
|
||||
bool writeViewSize();
|
||||
void writeTag(TvgBinTag tag);
|
||||
void writeCount(TvgBinCounter cnt);
|
||||
void writeReservedCount(TvgBinCounter cnt);
|
||||
|
|
Loading…
Add table
Reference in a new issue