mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
examples: updated svg.
revised the logic to align svg images in the center of the grids.
this is the subsequent changes to 3939b61770
.
This commit is contained in:
parent
93b88370ad
commit
e2057d10f1
1 changed files with 16 additions and 2 deletions
|
@ -48,8 +48,22 @@ void svgDirCallback(const char* name, const char* path, void* data)
|
|||
|
||||
if (picture->load(buf) != tvg::Result::Success) return;
|
||||
|
||||
picture->size(SIZE, SIZE);
|
||||
picture->translate((count % NUM_PER_ROW) * SIZE, (count / NUM_PER_ROW) * (HEIGHT / NUM_PER_COL));
|
||||
//image scaling preserving its aspect ratio
|
||||
float scale;
|
||||
float shiftX = 0.0f, shiftY = 0.0f;
|
||||
float w, h;
|
||||
picture->size(&w, &h);
|
||||
|
||||
if (w > h) {
|
||||
scale = SIZE / w;
|
||||
shiftY = (SIZE - h * scale) * 0.5f;
|
||||
} else {
|
||||
scale = SIZE / h;
|
||||
shiftX = (SIZE - w * scale) * 0.5f;
|
||||
}
|
||||
|
||||
picture->scale(scale);
|
||||
picture->translate((count % NUM_PER_ROW) * SIZE + shiftX, (count / NUM_PER_ROW) * (HEIGHT / NUM_PER_COL) + shiftY);
|
||||
|
||||
pictures.push_back(move(picture));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue