Improve page breaks and batch up cursor edits in epub generator

Patch by Guillaume Maudoux (layus).

CCBUG: 359932
frameworks
Martin T. H. Sandsmark 10 years ago
parent 7490f37291
commit c110c65401
  1. 25
      generators/epub/converter.cpp

@ -175,6 +175,7 @@ QTextDocument* Converter::convert( const QString &fileName )
mTextDocument = newDocument; mTextDocument = newDocument;
QTextCursor *_cursor = new QTextCursor( mTextDocument ); QTextCursor *_cursor = new QTextCursor( mTextDocument );
_cursor->beginEditBlock();
mLocalLinks.clear(); mLocalLinks.clear();
mSectionMap.clear(); mSectionMap.clear();
@ -346,19 +347,21 @@ QTextDocument* Converter::convert( const QString &fileName )
_handle_anchors(before, link); _handle_anchors(before, link);
const int page = mTextDocument->pageCount(); // Force a page break.
// The new format will also clear the previous one,
// it will clear the previous format
// useful when the last line had a bullet // useful when the last line had a bullet
_cursor->insertBlock(QTextBlockFormat()); QTextBlockFormat pageBreak;
pageBreak.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
while(mTextDocument->pageCount() == page) _cursor->insertBlock(pageBreak);
_cursor->insertText(QStringLiteral("\n"));
} }
} while (epub_it_get_next(it)); } while (epub_it_get_next(it));
epub_free_iterator(it); epub_free_iterator(it);
// Clear the previous format
// In particular, clear the last page break.
_cursor->insertBlock(QTextBlockFormat());
// handle toc // handle toc
struct titerator *tit; struct titerator *tit;
@ -397,10 +400,8 @@ QTextDocument* Converter::convert( const QString &fileName )
_handle_anchors(block, link); _handle_anchors(block, link);
} }
// Start new file in a new page // start a new page.
int page = mTextDocument->pageCount(); _cursor->block().blockFormat().setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
while(mTextDocument->pageCount() == page)
_cursor->insertText(QStringLiteral("\n"));
} }
free(data); free(data);
@ -447,6 +448,8 @@ QTextDocument* Converter::convert( const QString &fileName )
} }
} }
_cursor->endEditBlock();
delete _cursor; delete _cursor;
return mTextDocument; return mTextDocument;

Loading…
Cancel
Save