Drop libkscreen dependency

Drops the x11 fallback. We were falling back to QX11Extras that were in
fact using QScreen internally.
Also remove the QDesktopWidget fallbacks for the same reason.
Drops some API for fetching the dpi and unifies it with ::realDpi(QWidget).

Based on Sebas's patch.
Reviewed by Albert.

REVIEW: 126913
frameworks
Aleix Pol 10 years ago
parent 1b2de0d1d0
commit f42a3bad65
  1. 12
      CMakeLists.txt
  2. 2
      config-okular.h.cmake
  3. 184
      core/utils.cpp
  4. 32
      core/utils.h
  5. 5
      generators/ooo/converter.cpp
  6. 8
      generators/tiff/generator_tiff.cpp
  7. 2
      ui/annotwindow.cpp
  8. 2
      ui/pagepainter.cpp

@ -65,13 +65,6 @@ find_package(ZLIB REQUIRED)
# TYPE RECOMMENDED # TYPE RECOMMENDED
# PURPOSE "Required to build Okular.") # PURPOSE "Required to build Okular.")
find_package(KF5Screen)
set_package_properties("LibKScreen" PROPERTIES
DESCRIPTION "KDE screen management library"
URL "https://projects.kde.org/projects/kdereview/libkscreen"
TYPE RECOMMENDED
PURPOSE "DPI detection support")
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
add_definitions(-DTRANSLATION_DOMAIN="okular") add_definitions(-DTRANSLATION_DOMAIN="okular")
@ -223,11 +216,6 @@ PUBLIC # these are included from the installed headers
Qt5::Widgets Qt5::Widgets
) )
if(LibKScreen_FOUND)
message("KF5: port code to KScreen")
#target_link_libraries(okularcore KF5::LibKScreen)
endif(LibKScreen_FOUND)
set_target_properties(okularcore PROPERTIES VERSION 6.0.0 SOVERSION 6 OUTPUT_NAME Okular5Core EXPORT_NAME Core) set_target_properties(okularcore PROPERTIES VERSION 6.0.0 SOVERSION 6 OUTPUT_NAME Okular5Core EXPORT_NAME Core)
install(TARGETS okularcore EXPORT Okular5Targets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(TARGETS okularcore EXPORT Okular5Targets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})

@ -1,5 +1,3 @@
/* Defines if force the use DRM in okular */ /* Defines if force the use DRM in okular */
#define OKULAR_FORCE_DRM ${_OKULAR_FORCE_DRM} #define OKULAR_FORCE_DRM ${_OKULAR_FORCE_DRM}
/* Defines if LibKScreen is present */
#define HAVE_LIBKSCREEN ${LibKScreen_FOUND}

@ -11,6 +11,7 @@
#include "utils.h" #include "utils.h"
#include "utils_p.h" #include "utils_p.h"
#include "debug_p.h"
#include "settings_core.h" #include "settings_core.h"
#include <QtCore/QRect> #include <QtCore/QRect>
@ -18,15 +19,8 @@
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QImage> #include <QImage>
#include <QIODevice> #include <QIODevice>
#include <QWindow>
#ifdef Q_WS_X11 #include <QScreen>
#include "config-okular.h"
#if HAVE_LIBKSCREEN
#include <kscreen/config.h>
#include <kscreen/edid.h>
#endif
#include <QX11Info>
#endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
@ -64,133 +58,29 @@ QRect Utils::rotateRect( const QRect & source, int width, int height, int orient
return ret; return ret;
} }
#if defined(Q_WS_X11) #if !defined(Q_OS_MAC)
double Utils::dpiX()
{
return QX11Info::appDpiX();
}
double Utils::dpiY()
{
return QX11Info::appDpiY();
}
double Utils::realDpiX()
{
const QDesktopWidget* w = QApplication::desktop();
if (w->width() > 0 && w->widthMM() > 0) {
qCDebug(OkularCoreDebug) << "Pix:" << w->width() << "MM:" << w->widthMM();
return (double(w->width()) * 25.4) / double(w->widthMM());
} else {
return dpiX();
}
}
double Utils::realDpiY()
{
const QDesktopWidget* w = QApplication::desktop();
if (w->height() > 0 && w->heightMM() > 0) {
qCDebug(OkularCoreDebug) << "Pix:" << w->height() << "MM:" << w->heightMM();
return (double(w->height()) * 25.4) / double(w->heightMM());
} else {
return dpiY();
}
}
QSizeF Utils::realDpi(QWidget* widgetOnScreen) QSizeF Utils::realDpi(QWidget* widgetOnScreen)
{ {
if (widgetOnScreen) const QScreen* screen = widgetOnScreen && widgetOnScreen->window() && widgetOnScreen->window()->windowHandle()
{ ? widgetOnScreen->window()->windowHandle()->screen()
// Firstly try to retrieve DPI via LibKScreen : qGuiApp->primaryScreen();
#if HAVE_LIBKSCREEN
KScreen::Config* config = KScreen::Config::current();
if (config) {
KScreen::OutputList outputs = config->outputs();
QPoint globalPos = widgetOnScreen->parentWidget() ?
widgetOnScreen->mapToGlobal(widgetOnScreen->pos()):
widgetOnScreen->pos();
QRect widgetRect(globalPos, widgetOnScreen->size());
KScreen::Output* selectedOutput = 0;
int maxArea = 0;
Q_FOREACH(KScreen::Output *output, outputs)
{
if (output->currentMode())
{
QRect outputRect(output->pos(),output->currentMode()->size());
QRect intersection = outputRect.intersected(widgetRect);
int area = intersection.width()*intersection.height();
if (area > maxArea)
{
maxArea = area;
selectedOutput = output;
}
}
}
if (selectedOutput) if (screen)
{ {
qCDebug(OkularCoreDebug) << "Found widget at output #" << selectedOutput->id(); const QSizeF res(screen->physicalDotsPerInchX(), screen->physicalDotsPerInchY());
QRect outputRect(selectedOutput->pos(),selectedOutput->currentMode()->size()); if (res.width() > 0 && res.height() > 0) {
QSize szMM = selectedOutput->sizeMm(); if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
qCDebug(OkularCoreDebug) << "Output size is (mm) " << szMM; return res;
qCDebug(OkularCoreDebug) << "Output rect is " << outputRect; } else {
if (selectedOutput->edid()) { qCDebug(OkularCoreDebug) << "QScreen calculation returned a non square dpi." << res << ". Falling back";
qCDebug(OkularCoreDebug) << "EDID WxH (cm): " << selectedOutput->edid()->width() << 'x' << selectedOutput->edid()->height();
}
if (szMM.width() > 0 && szMM.height() > 0 && outputRect.width() > 0 && outputRect.height() > 0
&& selectedOutput->edid()
&& qAbs(static_cast<int>(selectedOutput->edid()->width()*10) - szMM.width()) < 10
&& qAbs(static_cast<int>(selectedOutput->edid()->height()*10) - szMM.height()) < 10)
{
// sizes in EDID seem to be consistent
QSizeF res(static_cast<qreal>(outputRect.width())*25.4/szMM.width(),
static_cast<qreal>(outputRect.height())*25.4/szMM.height());
if (!selectedOutput->isHorizontal())
{
qCDebug(OkularCoreDebug) << "Output is vertical, transposing DPI rect";
res.transpose();
}
if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
return res;
} else {
qCDebug(OkularCoreDebug) << "KScreen calculation returned a non square dpi." << res << ". Falling back";
}
}
}
else
{
qCDebug(OkularCoreDebug) << "Didn't find a KScreen selectedOutput to calculate DPI. Falling back";
} }
} }
else
{
qCDebug(OkularCoreDebug) << "Didn't find a KScreen config to calculate DPI. Falling back";
}
#endif
}
// this is also fallback for LibKScreen branch if KScreen::Output
// for particular widget was not found
QSizeF res = QSizeF(realDpiX(), realDpiY());
if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
return res;
} else {
qCDebug(OkularCoreDebug) << "QDesktopWidget calculation returned a non square dpi." << res << ". Falling back";
}
res = QSizeF(dpiX(), dpiY());
if (qAbs(res.width() - res.height()) / qMin(res.height(), res.width()) < 0.05) {
return res;
} else {
qCDebug(OkularCoreDebug) << "QX11Info returned a non square dpi." << res << ". Falling back";
} }
return QSizeF(72, 72);
res = QSizeF(72, 72);
return res;
} }
#elif defined(Q_OS_MAC) #else
/* /*
* Code copied from http://developer.apple.com/qa/qa2001/qa1217.html * Code copied from http://developer.apple.com/qa/qa2001/qa1217.html
*/ */
@ -244,7 +134,7 @@ QSizeF Utils::realDpi(QWidget* widgetOnScreen)
return err; return err;
} }
double Utils::dpiX() double Utils::realDpiX()
{ {
double x,y; double x,y;
CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay), CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay),
@ -254,7 +144,7 @@ double Utils::dpiX()
return err == CGDisplayNoErr ? x : 72.0; return err == CGDisplayNoErr ? x : 72.0;
} }
double Utils::dpiY() double Utils::realDpiY()
{ {
double x,y; double x,y;
CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay), CGDisplayErr err = GetDisplayDPI( CGDisplayCurrentMode(kCGDirectMainDisplay),
@ -264,42 +154,6 @@ double Utils::dpiY()
return err == CGDisplayNoErr ? y : 72.0; return err == CGDisplayNoErr ? y : 72.0;
} }
double Utils::realDpiX()
{
return dpiX();
}
double Utils::realDpiY()
{
return dpiY();
}
QSizeF Utils::realDpi(QWidget*)
{
return QSizeF(realDpiX(), realDpiY());
}
#else
double Utils::dpiX()
{
return QDesktopWidget().physicalDpiX();
}
double Utils::dpiY()
{
return QDesktopWidget().physicalDpiY();
}
double Utils::realDpiX()
{
return dpiX();
}
double Utils::realDpiY()
{
return dpiY();
}
QSizeF Utils::realDpi(QWidget*) QSizeF Utils::realDpi(QWidget*)
{ {
return QSizeF(realDpiX(), realDpiY()); return QSizeF(realDpiX(), realDpiY());

@ -34,38 +34,6 @@ class OKULARCORE_EXPORT Utils
*/ */
static QRect rotateRect( const QRect & source, int width, int height, int orientation ); static QRect rotateRect( const QRect & source, int width, int height, int orientation );
/**
* Return the horizontal DPI of the main display
*/
static double dpiX();
/**
* Return the vertical DPI of the main display
*/
static double dpiY();
/**
* Return the real horizontal DPI of the main display.
*
* On X11, it can indicate the real horizontal DPI value without any Xrdb
* setting. Otherwise, returns the same as dpiX(),
*
* @since 0.9 (KDE 4.3)
* @deprecated Can not work with multi-monitor configurations
*/
static double realDpiX();
/**
* Return the real vertical DPI of the main display
*
* On X11, it can indicate the real horizontal DPI value without any Xrdb
* setting. Otherwise, returns the same as dpiX(),
*
* @since 0.9 (KDE 4.3)
* @deprecated Can not work with multi-monitor configurations
*/
static double realDpiY();
/** /**
* Return the real DPI of the display containing given widget * Return the real DPI of the display containing given widget
* *

@ -132,8 +132,9 @@ Okular::Document::OpenResult Converter::convertWithPassword( const QString &file
const QString masterLayout = mStyleInformation->masterPageName(); const QString masterLayout = mStyleInformation->masterPageName();
const PageFormatProperty property = mStyleInformation->pageProperty( masterLayout ); const PageFormatProperty property = mStyleInformation->pageProperty( masterLayout );
int pageWidth = qRound(property.width() / 72.0 * Okular::Utils::dpiX()); const QSizeF dpi = Okular::Utils::realDpi(nullptr);
int pageHeight = qRound(property.height() / 72.0 * Okular::Utils::dpiY()); int pageWidth = qRound(property.width() / 72.0 * dpi.width());
int pageHeight = qRound(property.height() / 72.0 * dpi.height());
if ( pageWidth == 0 ) if ( pageWidth == 0 )
pageWidth = 600; pageWidth = 600;

@ -344,9 +344,7 @@ void TIFFGenerator::loadPages( QVector<Okular::Page*> & pagesVector )
uint32 width = 0; uint32 width = 0;
uint32 height = 0; uint32 height = 0;
const double dpiX = Okular::Utils::dpiX(); const QSizeF dpi = Okular::Utils::realDpi(nullptr);
const double dpiY = Okular::Utils::dpiY();
for ( tdir_t i = 0; i < dirs; ++i ) for ( tdir_t i = 0; i < dirs; ++i )
{ {
if ( !TIFFSetDirectory( d->tiff, i ) ) if ( !TIFFSetDirectory( d->tiff, i ) )
@ -356,8 +354,8 @@ void TIFFGenerator::loadPages( QVector<Okular::Page*> & pagesVector )
TIFFGetField( d->tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 ) TIFFGetField( d->tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 )
continue; continue;
adaptSizeToResolution( d->tiff, TIFFTAG_XRESOLUTION, dpiX, &width ); adaptSizeToResolution( d->tiff, TIFFTAG_XRESOLUTION, dpi.width(), &width );
adaptSizeToResolution( d->tiff, TIFFTAG_YRESOLUTION, dpiY, &height ); adaptSizeToResolution( d->tiff, TIFFTAG_YRESOLUTION, dpi.height(), &height );
Okular::Page * page = new Okular::Page( realdirs, width, height, readTiffRotation( d->tiff ) ); Okular::Page * page = new Okular::Page( realdirs, width, height, readTiffRotation( d->tiff ) );
pagesVector[ realdirs ] = page; pagesVector[ realdirs ] = page;

@ -345,7 +345,7 @@ void AnnotWindow::renderLatex( bool render )
QColor fontColor = textEdit->textColor(); QColor fontColor = textEdit->textColor();
int fontSize = textEdit->fontPointSize(); int fontSize = textEdit->fontPointSize();
QString latexOutput; QString latexOutput;
GuiUtils::LatexRenderer::Error errorCode = m_latexRenderer->renderLatexInHtml( contents, fontColor, fontSize, Okular::Utils::dpiX(), latexOutput ); GuiUtils::LatexRenderer::Error errorCode = m_latexRenderer->renderLatexInHtml( contents, fontColor, fontSize, Okular::Utils::realDpi(nullptr).width(), latexOutput );
switch ( errorCode ) switch ( errorCode )
{ {
case GuiUtils::LatexRenderer::LatexNotFound: case GuiUtils::LatexRenderer::LatexNotFound:

@ -766,7 +766,7 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula
if ( geom->style().width() || geom->geometricalInnerColor().isValid() ) if ( geom->style().width() || geom->geometricalInnerColor().isValid() )
{ {
mixedPainter->save(); mixedPainter->save();
const double width = geom->style().width() * Okular::Utils::dpiX() / ( 72.0 * 2.0 ) * scaledWidth / page->width(); const double width = geom->style().width() * Okular::Utils::realDpi(nullptr).width() / ( 72.0 * 2.0 ) * scaledWidth / page->width();
QRectF r( .0, .0, annotBoundary.width(), annotBoundary.height() ); QRectF r( .0, .0, annotBoundary.width(), annotBoundary.height() );
r.adjust( width, width, -width, -width ); r.adjust( width, width, -width, -width );
r.translate( annotBoundary.topLeft() ); r.translate( annotBoundary.topLeft() );

Loading…
Cancel
Save