Skip to content

Commit

Permalink
* Fix: use system DPI
Browse files Browse the repository at this point in the history
  • Loading branch information
bylee20 committed Jan 1, 2015
1 parent 87e45ec commit a7e6632
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions generator_mupdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void MuPDFGenerator::loadPages(QVector<Okular::Page *> &pages)

for (int i = 0; i < pages.count(); ++i) {
QMuPDF::Page *page = m_pdfdoc.page(i);
const QSizeF s = page->size();
const QSizeF s = page->size(dpi());
const Okular::Rotation rot = Okular::Rotation0;
Okular::Page* new_ = new Okular::Page(i, s.width(), s.height(), rot);
new_->setDuration(page->duration());
Expand Down Expand Up @@ -395,8 +395,8 @@ Okular::TextPage* MuPDFGenerator::textPage(Okular::Page *page)
{
userMutex()->lock();
QMuPDF::Page *mp = m_pdfdoc.page(page->number());
const QVector<QMuPDF::TextBox *> boxes = mp->textBoxes();
const QSizeF s = mp->size();
const QVector<QMuPDF::TextBox *> boxes = mp->textBoxes(dpi());
const QSizeF s = mp->size(dpi());
userMutex()->unlock();
delete mp;

Expand Down
17 changes: 10 additions & 7 deletions page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ extern "C" {

namespace QMuPDF {

QRectF convert_fz_rect(const fz_rect &rect)
QRectF convert_fz_rect(const fz_rect &rect, const QSizeF &dpi)
{
return QRectF(QPointF(rect.x0, rect.y0), QPointF(rect.x1, rect.y1));
return QRectF(QPointF(rect.x0, rect.y0)*dpi.width()/72.,
QPointF(rect.x1, rect.y1)*dpi.height()/72.);
}

QImage convert_fz_pixmap(fz_context *ctx, fz_pixmap *image)
Expand Down Expand Up @@ -76,11 +77,13 @@ int Page::number() const
return d->pageNum;
}

QSizeF Page::size() const
QSizeF Page::size(const QSizeF &dpi) const
{
fz_rect rect;
fz_bound_page(d->doc, d->page, &rect);
return QSizeF(rect.x1 - rect.x0, rect.y1 - rect.y0);
// MuPDF always assumes 72dpi
return QSizeF((rect.x1 - rect.x0)*dpi.width()/72.,
(rect.y1 - rect.y0)*dpi.height()/72.);
}

qreal Page::duration() const
Expand All @@ -92,7 +95,7 @@ qreal Page::duration() const

QImage Page::render(qreal width, qreal height) const
{
const QSizeF s = size();
const QSizeF s = size(QSizeF(72, 72));

fz_matrix ctm;
fz_scale(&ctm, width / s.width(), height / s.height());
Expand All @@ -112,7 +115,7 @@ QImage Page::render(qreal width, qreal height) const
return img;
}

QVector<TextBox *> Page::textBoxes() const
QVector<TextBox *> Page::textBoxes(const QSizeF &dpi) const
{
fz_cookie cookie = { 0, 0, 0, 0, 0, 0 };
fz_text_page *page = fz_new_text_page(d->ctx);
Expand Down Expand Up @@ -140,7 +143,7 @@ QVector<TextBox *> Page::textBoxes() const
for (int i_char = 0; i_char < span.len; ++i_char) {
fz_rect bbox; fz_text_char_bbox(&bbox, s, i_char);
const int text = span.text[i_char].c;
TextBox *box = new TextBox(text, convert_fz_rect(bbox));
TextBox *box = new TextBox(text, convert_fz_rect(bbox, dpi));
boxes.append(box);
hasText = true;
}
Expand Down
4 changes: 2 additions & 2 deletions page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Page {
public:
~Page();
int number() const;
QSizeF size() const;
QSizeF size(const QSizeF &dpi) const;
qreal duration() const;
QImage render(qreal width, qreal height) const;
QVector<TextBox *> textBoxes() const;
QVector<TextBox *> textBoxes(const QSizeF &dpi) const;
static Page *make(fz_document_s *doc, fz_context_s *ctx, int num);
private:
Page();
Expand Down

0 comments on commit a7e6632

Please sign in to comment.