Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions libimageviewer/unionimage/unionimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class UnionImage_Private
<< "PPM"
<< "XPM"
<< "ICO"
<< "ICNS";
<< "ICNS"
<< "TIF"
<< "TIFF";
}
~UnionImage_Private()
{
Expand Down Expand Up @@ -517,28 +519,31 @@ 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();
rotatePainter.setRenderHint(QPainter::HighQualityAntialiasing, true);
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)) {
Expand Down
17 changes: 17 additions & 0 deletions tests/test_unionimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "gtestview.h"
#include "accessibility/ac-desktop-define.h"
#include <DGuiApplicationHelper>
#include <QSvgRenderer>
#include "imageviewer.h"
#include "imageengine.h"
#include "service/imagedataservice.h"
Expand Down Expand Up @@ -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");
Expand Down
Loading