From 81fcca06bc67f7fbb187cdf170c0e0eef80237d5 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Mon, 19 Feb 2024 19:09:25 +0900 Subject: [PATCH] examples/picture/svg: Adjust size ratio Adjust the image size and position to fit the window size. --- src/examples/PictureSvg.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/examples/PictureSvg.cpp b/src/examples/PictureSvg.cpp index f77ffc86..771a1e95 100644 --- a/src/examples/PictureSvg.cpp +++ b/src/examples/PictureSvg.cpp @@ -50,7 +50,20 @@ void tvgDrawCmds(tvg::Canvas* canvas) return; } - picture->size(WIDTH, HEIGHT); + float scale; + float shiftX = 0.0f, shiftY = 0.0f; + float w, h; + picture->size(&w, &h); + if (w > h) { + scale = WIDTH / w; + shiftY = (HEIGHT - h * scale) * 0.5f; + } else { + scale = HEIGHT / h; + shiftX = (WIDTH - w * scale) * 0.5f; + } + picture->translate(shiftX, shiftY); + picture->scale(scale); + if (canvas->push(std::move(picture)) != tvg::Result::Success) return; cout << "SVG: " << buf << endl; }