mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 06:34:01 +00:00
examples/picture/svg: Adjust size ratio
Adjust the image size and position to fit the window size.
This commit is contained in:
parent
fb19e2cabd
commit
8e899df130
1 changed files with 14 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue