lunasvg icon indicating copy to clipboard operation
lunasvg copied to clipboard

After calling the function Document::rotate() the original SVG canvas is not recalculated

Open rossanoparis opened this issue 2 years ago • 2 comments

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.

image

Regards Rossano

rossanoparis avatar Aug 18 '22 13:08 rossanoparis

Use Document::render instead.

Example :

Original

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));

rotate

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));

flipx

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));

flipy

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));

skew

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));

scale

sammycage avatar Aug 19 '22 06:08 sammycage

Thank you @sammycage for your examples They work well !

rossanoparis avatar Aug 19 '22 12:08 rossanoparis