Apply a way to resolve the real location of resources to load.

When iterating through the document HTML files, set in the epub document the URL of the current file being loaded,
so it is possible to resolve the locations of resources based on the base URL of the current file.
This makes it possible to load resources like "foo.css", "somedir/foo.css", "../somedir/foo.css" and so on.

BUG: 198764
FIXED-IN: 4.6

svn path=/trunk/KDE/kdegraphics/okular/; revision=1182629
remotes/origin/KDE/4.6
Pino Toscano 16 years ago
parent 605c31e27c
commit f9424bbeee
  1. 2
      generators/epub/converter.cpp
  2. 19
      generators/epub/epubdocument.cpp
  3. 3
      generators/epub/epubdocument.h

@ -150,6 +150,7 @@ QTextDocument* Converter::convert( const QString &fileName )
_cursor->insertBlock();
QString link = QString::fromUtf8(epub_it_get_curr_url(it));
mTextDocument->setCurrentSubDocument(link);
// Pass on all the anchor since last block
const QTextBlock &before = _cursor->block();
@ -167,6 +168,7 @@ QTextDocument* Converter::convert( const QString &fileName )
} while (epub_it_get_next(it));
epub_free_iterator(it);
mTextDocument->setCurrentSubDocument(QString());
// handle toc

@ -10,6 +10,18 @@
using namespace Epub;
namespace {
QString resourceUrl(const KUrl &baseUrl, const QString &u)
{
KUrl newUrl(KUrl(baseUrl.directory(KUrl::AppendTrailingSlash)), u);
QString newDir = newUrl.toLocalFile();
newDir.remove(0, 1);
return newDir;
}
}
EpubDocument::EpubDocument(const QString &fileName) : QTextDocument()
{
mEpub = epub_open(qPrintable(fileName), 3);
@ -32,6 +44,11 @@ struct epub *EpubDocument::getEpub()
{
return mEpub;
}
void EpubDocument::setCurrentSubDocument(const QString &doc)
{
mCurrentSubDocument = KUrl::fromPath("/" + doc);
}
QVariant EpubDocument::loadResource(int type, const QUrl &name)
{
@ -39,7 +56,7 @@ QVariant EpubDocument::loadResource(int type, const QUrl &name)
char *data;
// Get the data from the epub file
size = epub_get_data(mEpub, name.toString().toUtf8(), &data);
size = epub_get_data(mEpub, resourceUrl(mCurrentSubDocument, name.toString()).toUtf8(), &data);
QVariant resource;

@ -13,6 +13,7 @@
#include <QUrl>
#include <QVariant>
#include <QImage>
#include <kurl.h>
#include <epub.h>
namespace Epub {
@ -24,12 +25,14 @@ namespace Epub {
bool isValid();
~EpubDocument();
struct epub *getEpub();
void setCurrentSubDocument(const QString &doc);
protected:
virtual QVariant loadResource(int type, const QUrl &name);
private:
struct epub *mEpub;
KUrl mCurrentSubDocument;
};

Loading…
Cancel
Save