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:
JunsuChoi 2022-09-14 13:23:20 +09:00 committed by Hermet Park
parent 67b48ab772
commit 91a6cdb9dc

View file

@ -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