diff --git a/libimageviewer/unionimage/unionimage.cpp b/libimageviewer/unionimage/unionimage.cpp index a1b20520..f7705a38 100644 --- a/libimageviewer/unionimage/unionimage.cpp +++ b/libimageviewer/unionimage/unionimage.cpp @@ -117,7 +117,9 @@ class UnionImage_Private << "PPM" << "XPM" << "ICO" - << "ICNS"; + << "ICNS" + << "TIF" + << "TIFF"; } ~UnionImage_Private() { @@ -517,9 +519,13 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt erroMsg = "rotate load QImage failed, path:" + path + " ,format:+" + format; return false; } + const QSize rotatedSize = qAbs(angel / 90) % 2 == 0 + ? image_copy.size() + : QSize(image_copy.height(), image_copy.width()); QSvgGenerator generator; generator.setFileName(path); - generator.setViewBox(QRect(0, 0, image_copy.width(), image_copy.height())); + generator.setSize(rotatedSize); + generator.setViewBox(QRect(QPoint(0, 0), rotatedSize)); QPainter rotatePainter; rotatePainter.begin(&generator); rotatePainter.resetTransform(); @@ -527,18 +533,17 @@ UNIONIMAGESHARED_EXPORT bool rotateImageFIle(int angel, const QString &path, QSt int realangel = angel / 90; if (realangel > 0) { for (int i = 0; i < qAbs(realangel); i++) { - rotatePainter.translate(image_copy.width(), 0); + rotatePainter.translate(image_copy.height(), 0); rotatePainter.rotate(90 * (realangel / qAbs(realangel))); } } else { for (int i = 0; i < qAbs(realangel); i++) { - rotatePainter.translate(0, image_copy.height()); + rotatePainter.translate(0, image_copy.width()); rotatePainter.rotate(90 * (realangel / qAbs(realangel))); } } rotatePainter.drawImage(image_copy.rect(), image_copy.scaled(image_copy.width(), image_copy.height())); rotatePainter.resetTransform(); - generator.setSize(QSize(image_copy.width(), image_copy.height())); rotatePainter.end(); return true; } else if (union_image_private.m_qtrotate.contains(format)) { diff --git a/tests/test_unionimage.cpp b/tests/test_unionimage.cpp index 9706d13b..d099d764 100644 --- a/tests/test_unionimage.cpp +++ b/tests/test_unionimage.cpp @@ -5,6 +5,7 @@ #include "gtestview.h" #include "accessibility/ac-desktop-define.h" #include +#include #include "imageviewer.h" #include "imageengine.h" #include "service/imagedataservice.h" @@ -75,6 +76,22 @@ TEST_F(gtestview, image_rotateNormal45) EXPECT_EQ(false, bRet); } +TEST_F(gtestview, image_rotateTiff) +{ + bool bRet = Libutils::image::rotate(m_TIFPath, 90); + EXPECT_EQ(true, bRet); +} + +TEST_F(gtestview, image_rotateSvg) +{ + bool bRet = Libutils::image::rotate(m_SVGPath, 90); + EXPECT_EQ(true, bRet); + + QSvgRenderer renderer(m_SVGPath); + EXPECT_EQ(3610, renderer.defaultSize().width()); + EXPECT_EQ(2761, renderer.defaultSize().height()); +} + TEST_F(gtestview, image_thumbnailExist) { bool bRet = Libutils::image::thumbnailExist(QApplication::applicationDirPath() + "/test/jpg170.jpg");