From e96dabc467e709a55e67a582da5cbab07ac1ae76 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Wed, 13 Aug 2014 18:54:30 +0200 Subject: [PATCH] Fix font size on high-DPI displays in ePub documents (but makes images small) --- core/generator.h | 12 ++++++------ generators/epub/converter.cpp | 4 +++- generators/epub/epubdocument.cpp | 9 +++++++-- generators/epub/epubdocument.h | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/generator.h b/core/generator.h index 9a1d7b26f..e006b9257 100644 --- a/core/generator.h +++ b/core/generator.h @@ -430,6 +430,12 @@ class OKULAR_EXPORT Generator : public QObject */ void setDPI(const QSizeF &dpi); + /** + * Returns DPI, previously set via setDPI() + * @since 0.19 (KDE 4.13) + */ + QSizeF dpi() const; + Q_SIGNALS: /** * This signal should be emitted whenever an error occurred in the generator. @@ -522,12 +528,6 @@ class OKULAR_EXPORT Generator : public QObject */ void updatePageBoundingBox( int page, const NormalizedRect & boundingBox ); - /** - * Returns DPI, previously set via setDPI() - * @since 0.19 (KDE 4.13) - */ - QSizeF dpi() const; - protected Q_SLOTS: /** * Gets the font data for the given font diff --git a/generators/epub/converter.cpp b/generators/epub/converter.cpp index 392947ea3..ddacfbe44 100644 --- a/generators/epub/converter.cpp +++ b/generators/epub/converter.cpp @@ -158,6 +158,7 @@ static QPoint calculateXYPosition( QTextDocument *document, int startPosition ) double x = startBoundingRect.x() ; double y = startBoundingRect.y() + startLine.y(); + //TODO: should this 800 be modified as in y = (int)y % 800; return QPoint(x,y); @@ -165,7 +166,8 @@ static QPoint calculateXYPosition( QTextDocument *document, int startPosition ) QTextDocument* Converter::convert( const QString &fileName ) { - EpubDocument *newDocument = new EpubDocument(fileName); + EpubDocument *newDocument = + new EpubDocument(fileName, generator()->dpi()); if (!newDocument->isValid()) { emit error(i18n("Error while opening the EPub document."), -1); delete newDocument; diff --git a/generators/epub/epubdocument.cpp b/generators/epub/epubdocument.cpp index 92fafbbfe..5efac7ee7 100644 --- a/generators/epub/epubdocument.cpp +++ b/generators/epub/epubdocument.cpp @@ -29,12 +29,17 @@ QString resourceUrl(const KUrl &baseUrl, const QString &u) } -EpubDocument::EpubDocument(const QString &fileName) : QTextDocument(), +EpubDocument::EpubDocument(const QString &fileName, QSizeF dpi) : + QTextDocument(), padding(20) { mEpub = epub_open(qPrintable(fileName), 3); - setPageSize(QSizeF(600, 800)); + //NOTE: the 600, 800 values may or may not be a good base. Scaling by DPI + // seems to produce reasonable results. + // Assume 96 is the base DPI + QSizeF size(600 * dpi.width() / 96.0f, 800 * dpi.height() / 96.0f); + setPageSize(size); } bool EpubDocument::isValid() diff --git a/generators/epub/epubdocument.h b/generators/epub/epubdocument.h index f0d55b0ea..8cb317b8a 100644 --- a/generators/epub/epubdocument.h +++ b/generators/epub/epubdocument.h @@ -22,7 +22,7 @@ namespace Epub { class EpubDocument : public QTextDocument { public: - EpubDocument(const QString &fileName); + EpubDocument(const QString &fileName, QSizeF dpi); bool isValid(); ~EpubDocument(); struct epub *getEpub();