lunasvg
lunasvg copied to clipboard
After calling the function Document::rotate() the original SVG canvas is not recalculated
After calling the function Document::rotate() the original SVG canvas is not recalculated, this leads to a wrong bitmap size calling this function: auto bitmap = document->renderToBitmap();
If it could be possible to inflate the SVG canvas accordingly with its rotation, the two parameters (cx & cy) to translate the image in ::rotate() wouldn’t make sense.
remark: even using the two parameters called cx and cy it is not possible to arrange certain images after a rotation.
Regards Rossano
Use Document::render
instead.
Example :
Original
Rotate
Matrix matrix;
matrix.rotate(45, document->width() / 2, document->height() / 2);
Box box(0, 0, document->width(), document->height());
box.transform(matrix);
Bitmap bitmap(box.w, box.h);
bitmap.clear(0x8080FFFF);
document->render(bitmap, matrix * Matrix::translated(-box.x, -box.y));
Flip X
Matrix matrix;
matrix.scale(-1, 1);
Box box(0, 0, document->width(), document->height());
box.transform(matrix);
Bitmap bitmap(box.w, box.h);
bitmap.clear(0x8080FFFF);
document->render(bitmap, matrix * Matrix::translated(-box.x, -box.y));
Flip Y
Matrix matrix;
matrix.scale(1, -1);
Box box(0, 0, document->width(), document->height());
box.transform(matrix);
Bitmap bitmap(box.w, box.h);
bitmap.clear(0x8080FFFF);
document->render(bitmap, matrix * Matrix::translated(-box.x, -box.y));
Skew
Matrix matrix;
matrix.shear(45, 0);
Box box(0, 0, document->width(), document->height());
box.transform(matrix);
Bitmap bitmap(box.w, box.h);
bitmap.clear(0x8080FFFF);
document->render(bitmap, matrix * Matrix::translated(-box.x, -box.y));
Scale
Matrix matrix;
matrix.scale(2, 2);
Box box(0, 0, document->width(), document->height());
box.transform(matrix);
Bitmap bitmap(box.w, box.h);
bitmap.clear(0x8080FFFF);
document->render(bitmap, matrix * Matrix::translated(-box.x, -box.y));
Thank you @sammycage for your examples They work well !