fix for epubs with non-white background color

remotes/origin/KDE/4.12
Jaydeep Solanki 13 years ago committed by Albert Astals Cid
parent bdcc7d3eb1
commit c0cc3af9be
  1. 50
      generators/epub/converter.cpp
  2. 5
      generators/epub/epubdocument.cpp
  3. 4
      generators/epub/epubdocument.h

@ -111,16 +111,8 @@ QTextDocument* Converter::convert( const QString &fileName )
}
mTextDocument = newDocument;
mTextDocument->setPageSize(QSizeF(600, 800));
QTextCursor *_cursor = new QTextCursor( mTextDocument );
QTextFrameFormat frameFormat;
frameFormat.setMargin( 20 );
QTextFrame *rootFrame = mTextDocument->rootFrame();
rootFrame->setFrameFormat( frameFormat );
mLocalLinks.clear();
mSectionMap.clear();
@ -142,32 +134,46 @@ QTextDocument* Converter::convert( const QString &fileName )
// iterate over the book
it = epub_get_iterator(mTextDocument->getEpub(), EITERATOR_SPINE, 0);
do {
if (epub_it_get_curr(it)) {
// insert block for links
_cursor->insertBlock();
QString link = QString::fromUtf8(epub_it_get_curr_url(it));
// if the background color of the document is non-white it will be handled by QTextDocument::setHtml()
bool firstPage = true;
do{
if(epub_it_get_curr(it)) {
const QString link = QString::fromUtf8(epub_it_get_curr_url(it));
mTextDocument->setCurrentSubDocument(link);
QString htmlContent = QString::fromUtf8(epub_it_get_curr(it));
QTextBlock before;
if(firstPage) {
// preHtml & postHtml make it possible to have a margin around the content of the page
const QString preHtml = QString("<html><head></head><body>"
"<table style=\"-qt-table-type: root; margin-top:%1px; margin-bottom:%1px; margin-left:%1px; margin-right:%1px;\">"
"<tr>"
"<td style=\"border: none;\">").arg(mTextDocument->padding);
const QString postHtml = "</tr></table></body></html>";
mTextDocument->setHtml(preHtml + htmlContent + postHtml);
firstPage = false;
before = mTextDocument->begin();
} else {
before = _cursor->block();
_cursor->insertHtml(htmlContent);
}
// Pass on all the anchor since last block
const QTextBlock &before = _cursor->block();
mSectionMap.insert(link, before);
_cursor->insertHtml(QString::fromUtf8(epub_it_get_curr(it)));
// Add anchors to hashes
_handle_anchors(before, link);
// Start new file in a new page
int page = mTextDocument->pageCount();
const int page = mTextDocument->pageCount();
// it will clear the previous format
// useful when the last line had a bullet
_cursor->insertBlock(QTextBlockFormat());
while(mTextDocument->pageCount() == page)
_cursor->insertText("\n");
}
} while (epub_it_get_next(it));
epub_free_iterator(it);
mTextDocument->setCurrentSubDocument(QString());
// handle toc
struct titerator *tit;

@ -23,9 +23,12 @@ QString resourceUrl(const KUrl &baseUrl, const QString &u)
}
EpubDocument::EpubDocument(const QString &fileName) : QTextDocument()
EpubDocument::EpubDocument(const QString &fileName) : QTextDocument(),
padding(20)
{
mEpub = epub_open(qPrintable(fileName), 3);
setPageSize(QSizeF(600, 800));
}
bool EpubDocument::isValid()

@ -34,6 +34,10 @@ namespace Epub {
private:
struct epub *mEpub;
KUrl mCurrentSubDocument;
int padding;
friend class Converter;
};
}

Loading…
Cancel
Save