mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
parent
5c59c9aa71
commit
4082a13527
2 changed files with 33 additions and 4 deletions
|
@ -55,7 +55,22 @@ void tvgDrawCmds(tvg::Canvas* canvas, const char* path, const char* name)
|
|||
|
||||
if (picture->load(buf) != tvg::Result::Success) return;
|
||||
|
||||
picture->size(SIZE, SIZE);
|
||||
//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(shiftX, shiftY);
|
||||
|
||||
if (canvas->push(move(picture)) != tvg::Result::Success) return;
|
||||
|
||||
|
|
|
@ -52,14 +52,28 @@ void svgDirCallback(const char* name, const char* path, void* data)
|
|||
|
||||
if (picture->load(buf) != tvg::Result::Success) return;
|
||||
|
||||
picture->size(SIZE, SIZE);
|
||||
picture->translate((xCnt % NUM_PER_LINE) * SIZE, SIZE * (xCnt / NUM_PER_LINE));
|
||||
//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((xCnt % NUM_PER_LINE) * SIZE + shiftX, SIZE * (xCnt / NUM_PER_LINE) + shiftY);
|
||||
++xCnt;
|
||||
|
||||
//Duplicates
|
||||
for (int i = 0; i < NUM_PER_LINE - 1; i++) {
|
||||
tvg::Picture* dup = static_cast<tvg::Picture*>(picture->duplicate());
|
||||
dup->translate((xCnt % NUM_PER_LINE) * SIZE, SIZE * (xCnt / NUM_PER_LINE));
|
||||
dup->translate((xCnt % NUM_PER_LINE) * SIZE + shiftX, SIZE * (xCnt / NUM_PER_LINE) + shiftY);
|
||||
pictures.push_back(dup);
|
||||
++xCnt;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue