From f15aefa5dc1e48d97cea1316cb38dd3888a021de Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 30 Jul 2020 20:40:12 +0900 Subject: [PATCH] test: updated svg sample also revise size() method of Picture for proper aligning. Change-Id: I58a0886968f6058e65a062477e2a873224d8ea8f --- inc/thorvg.h | 2 +- src/lib/tvgPicture.cpp | 4 +- src/lib/tvgPictureImpl.h | 4 +- test/svgs/batman1.svg | 3 + test/svgs/eee.svg | 4 + test/svgs/favorite_on.svg | 11 + test/svgs/google.svg | 4 + test/svgs/ibm.svg | 44 ++ test/svgs/scion.svg | 9 + test/svgs/tiger.svg | 829 ++++++++++++++++++++++++++++++++++++++ test/svgs/wikimedia.svg | 5 - test/svgs/yadis.svg | 16 + test/testSvg.cpp | 32 +- 13 files changed, 951 insertions(+), 16 deletions(-) create mode 100644 test/svgs/batman1.svg create mode 100644 test/svgs/eee.svg create mode 100644 test/svgs/favorite_on.svg create mode 100644 test/svgs/google.svg create mode 100644 test/svgs/ibm.svg create mode 100644 test/svgs/scion.svg create mode 100644 test/svgs/tiger.svg delete mode 100644 test/svgs/wikimedia.svg create mode 100644 test/svgs/yadis.svg diff --git a/inc/thorvg.h b/inc/thorvg.h index 622c302e..c738a0ee 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -282,7 +282,7 @@ public: ~Picture(); Result load(const std::string& path) noexcept; - Result size(float* w, float* h) const noexcept; + Result viewbox(float* x, float* y, float* w, float* h) const noexcept; static std::unique_ptr gen() noexcept; diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index 6d6ae473..03701636 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -48,9 +48,9 @@ Result Picture::load(const std::string& path) noexcept } -Result Picture::size(float* w, float* h) const noexcept +Result Picture::viewbox(float* x, float* y, float* w, float* h) const noexcept { - if (IMPL->size(w, h)) return Result::Success; + if (IMPL->viewbox(x, y, w, h)) return Result::Success; return Result::InsufficientCondition; } diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index 098176d2..ed1c678d 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -60,9 +60,11 @@ struct Picture::Impl return paint->IMPL->render(renderer); } - bool size(float* w, float* h) + bool viewbox(float* x, float* y, float* w, float* h) { if (!loader) return false; + if (x) *x = loader->vx; + if (y) *y = loader->vy; if (w) *w = loader->vw; if (h) *h = loader->vh; return true; diff --git a/test/svgs/batman1.svg b/test/svgs/batman1.svg new file mode 100644 index 00000000..7a9d2291 --- /dev/null +++ b/test/svgs/batman1.svg @@ -0,0 +1,3 @@ + + + diff --git a/test/svgs/eee.svg b/test/svgs/eee.svg new file mode 100644 index 00000000..c23875ee --- /dev/null +++ b/test/svgs/eee.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/test/svgs/favorite_on.svg b/test/svgs/favorite_on.svg new file mode 100644 index 00000000..c34b3209 --- /dev/null +++ b/test/svgs/favorite_on.svg @@ -0,0 +1,11 @@ + + + + + + diff --git a/test/svgs/google.svg b/test/svgs/google.svg new file mode 100644 index 00000000..3e51a42e --- /dev/null +++ b/test/svgs/google.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/test/svgs/ibm.svg b/test/svgs/ibm.svg new file mode 100644 index 00000000..c87ad116 --- /dev/null +++ b/test/svgs/ibm.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/svgs/scion.svg b/test/svgs/scion.svg new file mode 100644 index 00000000..24fa109f --- /dev/null +++ b/test/svgs/scion.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/test/svgs/tiger.svg b/test/svgs/tiger.svg new file mode 100644 index 00000000..a59da8d3 --- /dev/null +++ b/test/svgs/tiger.svg @@ -0,0 +1,829 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/svgs/wikimedia.svg b/test/svgs/wikimedia.svg deleted file mode 100644 index ad2c2115..00000000 --- a/test/svgs/wikimedia.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/test/svgs/yadis.svg b/test/svgs/yadis.svg new file mode 100644 index 00000000..7bcbad8b --- /dev/null +++ b/test/svgs/yadis.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/testSvg.cpp b/test/testSvg.cpp index 5f053701..e16f19b1 100644 --- a/test/testSvg.cpp +++ b/test/testSvg.cpp @@ -4,11 +4,10 @@ /* Drawing Commands */ /************************************************************************/ -#define NUM_PER_LINE 3 +#define NUM_PER_LINE 4 +#define SIZE 200 -int x = 30; -int y = 30; -int count = 0; +static int count = 0; void svgDirCallback(const char* name, const char* path, void* data) { @@ -21,12 +20,31 @@ void svgDirCallback(const char* name, const char* path, void* data) if (picture->load(buf) != tvg::Result::Success) return; - picture->translate(((WIDTH - (x * 2)) / NUM_PER_LINE) * (count % NUM_PER_LINE) + x, ((HEIGHT - (y * 2))/ NUM_PER_LINE) * (int)((float)count / (float)NUM_PER_LINE) + y); + float x, y, w, h; + picture->viewbox(&x, &y, &w, &h); + + float rate = (SIZE/(w > h ? w : h)); + picture->scale(rate); + + x *= rate; + y *= rate; + w *= rate; + h *= rate; + + //Center Align ? + if (w > h) { + y -= (SIZE - h) * 0.5f; + } else { + x -= (SIZE - w) * 0.5f; + } + + picture->translate((count % NUM_PER_LINE) * SIZE - x, SIZE * (count / NUM_PER_LINE) - y); + canvas->push(move(picture)); - count++; - cout << "SVG: " << buf << endl; + + count++; } void tvgDrawCmds(tvg::Canvas* canvas)