summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-13 13:41:22 (GMT)
committerMartin T. H. Sandsmark <martin.sandsmark@kde.org>2016-07-13 13:41:22 (GMT)
commitc110c65401a97877eb8b1cd3c6be04e2bdcbc5ec (patch)
treece2789e9d438e9102788a98355e7c368d0390c8b
parent7490f37291b3424ee08d2a19f330e173792803bf (diff)
Improve page breaks and batch up cursor edits in epub generator
Patch by Guillaume Maudoux (layus). CCBUG: 359932
-rw-r--r--generators/epub/converter.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/generators/epub/converter.cpp b/generators/epub/converter.cpp
index 9b28323..5ec1d32 100644
--- a/generators/epub/converter.cpp
+++ b/generators/epub/converter.cpp
@@ -175,6 +175,7 @@ QTextDocument* Converter::convert( const QString &fileName )
mTextDocument = newDocument;
QTextCursor *_cursor = new QTextCursor( mTextDocument );
+ _cursor->beginEditBlock();
mLocalLinks.clear();
mSectionMap.clear();
@@ -346,19 +347,21 @@ QTextDocument* Converter::convert( const QString &fileName )
_handle_anchors(before, link);
- const int page = mTextDocument->pageCount();
-
- // it will clear the previous format
+ // Force a page break.
+ // The new format will also clear the previous one,
// useful when the last line had a bullet
- _cursor->insertBlock(QTextBlockFormat());
-
- while(mTextDocument->pageCount() == page)
- _cursor->insertText(QStringLiteral("\n"));
+ QTextBlockFormat pageBreak;
+ pageBreak.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
+ _cursor->insertBlock(pageBreak);
}
} while (epub_it_get_next(it));
epub_free_iterator(it);
+ // Clear the previous format
+ // In particular, clear the last page break.
+ _cursor->insertBlock(QTextBlockFormat());
+
// handle toc
struct titerator *tit;
@@ -397,10 +400,8 @@ QTextDocument* Converter::convert( const QString &fileName )
_handle_anchors(block, link);
}
- // Start new file in a new page
- int page = mTextDocument->pageCount();
- while(mTextDocument->pageCount() == page)
- _cursor->insertText(QStringLiteral("\n"));
+ // start a new page.
+ _cursor->block().blockFormat().setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
}
free(data);
@@ -447,6 +448,8 @@ QTextDocument* Converter::convert( const QString &fileName )
}
}
+ _cursor->endEditBlock();
+
delete _cursor;
return mTextDocument;