Commit 4019ec56 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

comicbook: Obey autotransform of images

BUGS: 410778
parent 311cae2a
Pipeline #15993 passed with stage
in 12 minutes and 17 seconds
......@@ -9,25 +9,34 @@ include_directories(
set( okularGenerator_comicbook_PART_SRCS
document.cpp
generator_comicbook.cpp
directory.cpp
unrar.cpp qnatsort.cpp
unrarflavours.cpp
)
add_library(okular_comicbook STATIC ${okularGenerator_comicbook_PART_SRCS})
target_link_libraries(okular_comicbook okularcore KF5::KIOCore KF5::I18n KF5::Archive)
okular_add_generator(okularGenerator_comicbook ${okularGenerator_comicbook_PART_SRCS})
target_link_libraries(okularGenerator_comicbook okularcore KF5::KIOCore KF5::I18n KF5::Archive)
okular_add_generator(okularGenerator_comicbook generator_comicbook.cpp)
target_link_libraries(okularGenerator_comicbook okular_comicbook)
if (UNIX AND NOT ANDROID)
find_package(KF5Pty REQUIRED)
target_compile_definitions(okularGenerator_comicbook PRIVATE -DWITH_KPTY=1)
target_link_libraries(okularGenerator_comicbook KF5::Pty)
target_compile_definitions(okular_comicbook PRIVATE -DWITH_KPTY=1)
target_link_libraries(okular_comicbook KF5::Pty)
endif ()
if (KArchive_HAVE_LZMA)
target_compile_definitions(okularGenerator_comicbook PRIVATE -DWITH_K7ZIP=1)
target_compile_definitions(okular_comicbook PRIVATE -DWITH_K7ZIP=1)
endif()
########### autotests ###############
add_definitions( -DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" )
ecm_add_test(autotests/comicbooktest.cpp
TEST_NAME "comicbooktest"
LINK_LIBRARIES Qt5::Test KF5::CoreAddons okularcore okular_comicbook
)
########### install files ###############
install( FILES okularComicbook.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )
install( PROGRAMS okularApplication_comicbook.desktop org.kde.mobile.okular_comicbook.desktop DESTINATION ${KDE_INSTALL_APPDIR} )
......
/***************************************************************************
* Copyright (C) 2020 by Albert Astals Cid <aacid@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <QtTest>
#include "core/document.h"
#include "core/generator.h"
#include "core/observer.h"
#include "core/page.h"
#include "../document.h"
#include "settings_core.h"
class ComicBookGeneratorTest
: public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void testRotatedImage();
void cleanupTestCase();
};
void ComicBookGeneratorTest::initTestCase()
{
Okular::SettingsCore::instance( QStringLiteral("ComicBookGeneratorTest") );
}
void ComicBookGeneratorTest::cleanupTestCase()
{
}
void ComicBookGeneratorTest::testRotatedImage()
{
ComicBook::Document document;
const QString testFile = QStringLiteral(KDESRCDIR "autotests/data/rotated_cb.cbz");
QVERIFY( document.open(testFile) );
QVector<Okular::Page*> pagesVector;
document.pages( &pagesVector );
const Okular::Page *p = pagesVector[ 0 ];
QVERIFY(p->height() > p->width());
const QImage image = document.pageImage( 0 );
QVERIFY(image.height() > image.width());
}
QTEST_MAIN( ComicBookGeneratorTest )
#include "comicbooktest.moc"
/* kate: replace-tabs on; tab-width 4; */
......@@ -185,6 +185,7 @@ void Document::pages( QVector<Okular::Page*> * pagesVector )
pagesVector->clear();
pagesVector->resize( mEntries.size() );
QImageReader reader;
reader.setAutoTransform( true );
for (const QString &file : qAsConst(mEntries)) {
if ( mArchive ) {
const KArchiveFile *entry = static_cast<const KArchiveFile*>( mArchiveDir->entry( file ) );
......@@ -202,6 +203,9 @@ void Document::pages( QVector<Okular::Page*> * pagesVector )
if ( reader.canRead() )
{
QSize pageSize = reader.size();
if (reader.transformation() & QImageIOHandler::TransformationRotate90) {
pageSize.transpose();
}
if ( !pageSize.isValid() ) {
const QImage i = reader.read();
if ( !i.isNull() )
......@@ -229,8 +233,12 @@ QImage Document::pageImage( int page ) const
{
if ( mArchive ) {
const KArchiveFile *entry = static_cast<const KArchiveFile*>( mArchiveDir->entry( mPageMap[ page ] ) );
if ( entry )
return QImage::fromData( entry->data() );
if ( entry ) {
std::unique_ptr<QIODevice> dev(entry->createDevice());
QImageReader reader( dev.get() );
reader.setAutoTransform( true );
return reader.read();
}
} else if ( mDirectory ) {
return QImage( mPageMap[ page ] );
} else {
......@@ -245,3 +253,4 @@ QString Document::lastErrorString() const
return mLastErrorString;
}
Q_LOGGING_CATEGORY(OkularComicbookDebug, "org.kde.okular.generators.comicbook", QtWarningMsg)
......@@ -92,7 +92,5 @@ bool ComicBookGenerator::print( QPrinter& printer )
return true;
}
Q_LOGGING_CATEGORY(OkularComicbookDebug, "org.kde.okular.generators.comicbook", QtWarningMsg)
#include "generator_comicbook.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment