tvg_format: save/restore default view size in the data.
authorHermet Park <chuneon.park@samsung.com>
Thu, 29 Jul 2021 06:51:00 +0000 (15:51 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Fri, 30 Jul 2021 00:43:30 +0000 (09:43 +0900)
current bounding box of the paint is the default view size...

Do we have any better information of that?

src/examples/PictureTvg.cpp
src/examples/images/test.tvg
src/loaders/tvg/tvgTvgLoadParser.cpp
src/loaders/tvg/tvgTvgLoadParser.h
src/loaders/tvg/tvgTvgLoader.cpp
src/savers/tvg/tvgTvgSaver.cpp
src/savers/tvg/tvgTvgSaver.h

index 4fdbce7..a7593cf 100644 (file)
@@ -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));
 }
 
index 997d9aa..80e5576 100644 (file)
Binary files a/src/examples/images/test.tvg and b/src/examples/images/test.tvg differ
index 535cf21..6636472 100644 (file)
@@ -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;
     }
index cadd45e..437670e 100644 (file)
@@ -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_
index c56fbbd..5b83442 100644 (file)
@@ -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);
 }
 
 
index 82ea37f..d7c3855 100644 (file)
@@ -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;
 }
index eecd8e1..495d926 100644 (file)
@@ -40,6 +40,7 @@ private:
     void reserveCount();
 
     bool writeHeader();
+    bool writeViewSize();
     void writeTag(TvgBinTag tag);
     void writeCount(TvgBinCounter cnt);
     void writeReservedCount(TvgBinCounter cnt);