Commit e96dabc4 authored by Diggory Hardy's avatar Diggory Hardy

Fix font size on high-DPI displays in ePub documents (but makes images small)

parent e9e3d4a4
......@@ -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
......
......@@ -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;
......
......@@ -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()
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment