mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
wasm: Update size calculation logic
revised the logic to align svg images in the center of the view.
this is the subsequent changes to 3939b61770
.
This commit is contained in:
parent
67b48ab772
commit
91a6cdb9dc
1 changed files with 13 additions and 1 deletions
|
@ -255,7 +255,19 @@ private:
|
|||
mBuffer = make_unique<uint8_t[]>(mWidth * mHeight * 4);
|
||||
mSwCanvas->target((uint32_t *)mBuffer.get(), mWidth, mWidth, mHeight, SwCanvas::ARGB8888);
|
||||
|
||||
if (mPicture) mPicture->size(width, height);
|
||||
if (mPicture) {
|
||||
float scale;
|
||||
float shiftX = 0.0f, shiftY = 0.0f;
|
||||
if (mOriginalSize[0] > mOriginalSize[1]) {
|
||||
scale = width / mOriginalSize[0];
|
||||
shiftY = (height - mOriginalSize[1] * scale) * 0.5f;
|
||||
} else {
|
||||
scale = height / mOriginalSize[1];
|
||||
shiftX = (width - mOriginalSize[0] * scale) * 0.5f;
|
||||
}
|
||||
mPicture->scale(scale);
|
||||
mPicture->translate(shiftX, shiftY);
|
||||
}
|
||||
}
|
||||
|
||||
struct Layer
|
||||
|
|
Loading…
Add table
Reference in a new issue