mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-13 13:11:41 +00:00
Fixes url whitespaces in epub documents
Summary: libepub can't handle whitespace url encodings. This is why epub documents containing whitespaces urls aren't displayed correctly. Since libepub doesn't seem to be maintained anymore, it might be better to fix this issue here. BUG: 334711 Test Plan: Example epubs are in the ticket. Reviewers: #okular, aacid Reviewed By: #okular, aacid Subscribers: ngraham, aacid, okular-devel Tags: #okular Differential Revision: https://phabricator.kde.org/D14310
This commit is contained in:
parent
a7aa8a46e1
commit
fcf148b75b
|
@ -20,6 +20,16 @@ okular_add_generator(okularGenerator_epub ${okularGenerator_epub_PART_SRCS})
|
|||
|
||||
target_link_libraries(okularGenerator_epub okularcore ${EPUB_LIBRARIES} KF5::I18n Qt5::Widgets Qt5::Xml)
|
||||
|
||||
|
||||
########### autotests ###############
|
||||
|
||||
add_definitions( -DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" )
|
||||
ecm_add_test(autotests/epubgeneratortest.cpp
|
||||
TEST_NAME "epubgeneratortest"
|
||||
LINK_LIBRARIES Qt5::Test KF5::CoreAddons okularcore
|
||||
)
|
||||
|
||||
|
||||
########### install files ###############
|
||||
install( FILES okularEPub.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )
|
||||
install( PROGRAMS okularApplication_epub.desktop org.kde.mobile.okular_epub.desktop DESTINATION ${KDE_INSTALL_APPDIR} )
|
||||
|
|
BIN
generators/epub/autotests/data/test.epub
Normal file
BIN
generators/epub/autotests/data/test.epub
Normal file
Binary file not shown.
84
generators/epub/autotests/epubgeneratortest.cpp
Normal file
84
generators/epub/autotests/epubgeneratortest.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2017 by Gilbert Assaf <gassaf@gmx.de> *
|
||||
* *
|
||||
* 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/page.h"
|
||||
#include "settings_core.h"
|
||||
#include "core/textpage.h"
|
||||
|
||||
|
||||
class EpubGeneratorTest
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void testDocumentStructure();
|
||||
void testDocumentContent();
|
||||
void cleanupTestCase();
|
||||
|
||||
private:
|
||||
Okular::Document *m_document;
|
||||
};
|
||||
|
||||
void EpubGeneratorTest::initTestCase()
|
||||
{
|
||||
Okular::SettingsCore::instance( QStringLiteral("EpubGeneratorTest") );
|
||||
m_document = new Okular::Document( 0 );
|
||||
const QString testFile = QStringLiteral(KDESRCDIR "autotests/data/test.epub");
|
||||
QMimeDatabase db;
|
||||
const QMimeType mime = db.mimeTypeForFile( testFile );
|
||||
QCOMPARE( m_document->openDocument(testFile, QUrl(), mime), Okular::Document::OpenSuccess );
|
||||
}
|
||||
|
||||
|
||||
void EpubGeneratorTest::cleanupTestCase()
|
||||
{
|
||||
m_document->closeDocument();
|
||||
delete m_document;
|
||||
}
|
||||
|
||||
void EpubGeneratorTest::testDocumentStructure()
|
||||
{
|
||||
unsigned int expectedPageNr = 3;
|
||||
QCOMPARE( m_document->pages(), expectedPageNr);
|
||||
QCOMPARE( m_document->metaData(QLatin1String("DocumentTitle")).toString(), QStringLiteral("Okular Test") );
|
||||
|
||||
const Okular::DocumentSynopsis *docSyn = m_document->documentSynopsis();
|
||||
QDomElement heading1 = docSyn->documentElement();
|
||||
QCOMPARE( heading1.tagName(), QStringLiteral("Lorem ipsum Section 1") );
|
||||
|
||||
QDomElement heading2 = heading1.nextSiblingElement();
|
||||
QCOMPARE( heading2.tagName(), QStringLiteral("Lorem ipsum Section 2") );
|
||||
}
|
||||
|
||||
void EpubGeneratorTest::testDocumentContent()
|
||||
{
|
||||
const Okular::Page *page0 = m_document->page(0);
|
||||
QCOMPARE( page0->number(), 0);
|
||||
m_document->requestTextPage( page0->number() );
|
||||
QVERIFY( page0->hasTextPage() );
|
||||
QCOMPARE( page0->text().trimmed(), QStringLiteral("Lorem ipsum Section 1\n\u2029This is an example Text.\n\uFFFC") );
|
||||
|
||||
const Okular::Page *page1 = m_document->page(1);
|
||||
QCOMPARE( page1->number(), 1);
|
||||
m_document->requestTextPage( page1->number() );
|
||||
QVERIFY( page1->hasTextPage() );
|
||||
QCOMPARE( page1->text().trimmed(), QStringLiteral("Lorem ipsum Section 2\n\u2029This is an example Text.") );
|
||||
|
||||
}
|
||||
|
||||
QTEST_MAIN( EpubGeneratorTest )
|
||||
#include "epubgeneratortest.moc"
|
||||
|
||||
/* kate: replace-tabs on; tab-width 4; */
|
||||
|
|
@ -379,7 +379,11 @@ QTextDocument* Converter::convert( const QString &fileName )
|
|||
block = mSectionMap.value(link);
|
||||
} else { // load missing resource
|
||||
char *data = 0;
|
||||
int size = epub_get_data(mTextDocument->getEpub(), clink, &data);
|
||||
//epub_get_data can't handle whitespace url encodings
|
||||
QByteArray ba = link.replace("%20", " ").toLatin1();
|
||||
const char *clinkClean = ba.data();
|
||||
int size = epub_get_data(mTextDocument->getEpub(), clinkClean, &data);
|
||||
|
||||
if (data) {
|
||||
_cursor->insertBlock();
|
||||
|
||||
|
|
Loading…
Reference in a new issue